package com.ubt.jimu.controller.data.widget; import android.text.TextUtils; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.ubt.jimu.base.data.CtrlMotionType; import com.ubt.jimu.controller.data.config.JockstickConfig; import com.ubt.jimu.controller.data.config.Wheel; import com.ubt.jimu.transport.model.TransportFile; import com.ubtech.utils.XLog; import java.util.List; /* loaded from: classes.dex */ public class JockstickDataConverter implements Converter { public static final String CONFIG_ID = "configID"; public static final String ID = "id"; public static final String MOTION_TYPE = "motionType"; public static final String POS = "pos"; public static final String REVERSE = "reverse"; public static final String TYPE = "type"; public static final String WHEEL = "wheel"; private void marshalConfig(HierarchicalStreamWriter hierarchicalStreamWriter, MarshallingContext marshallingContext, JockstickConfig jockstickConfig) { if (jockstickConfig != null) { JockstickConfig.JockType type = jockstickConfig.getType(); if (type != null) { hierarchicalStreamWriter.startNode("type"); hierarchicalStreamWriter.setValue(type.name()); hierarchicalStreamWriter.endNode(); } CtrlMotionType motionType = jockstickConfig.getMotionType(); if (motionType != null) { hierarchicalStreamWriter.startNode("motionType"); hierarchicalStreamWriter.setValue(motionType.name()); hierarchicalStreamWriter.endNode(); } List wheelList = jockstickConfig.getWheelList(); if (wheelList == null || wheelList.size() <= 0) { return; } for (Wheel wheel : wheelList) { hierarchicalStreamWriter.startNode(WHEEL); marshallingContext.convertAnother(wheel); hierarchicalStreamWriter.endNode(); } } } @Override // com.thoughtworks.xstream.converters.ConverterMatcher public boolean canConvert(Class cls) { return JockstickData.class.equals(cls); } @Override // com.thoughtworks.xstream.converters.Converter public void marshal(Object obj, HierarchicalStreamWriter hierarchicalStreamWriter, MarshallingContext marshallingContext) { JockstickData jockstickData = (JockstickData) obj; if (!TextUtils.isEmpty(jockstickData.getWidgetId())) { hierarchicalStreamWriter.addAttribute("widgetId", jockstickData.getWidgetId()); } JockstickConfig config = jockstickData.getConfig(); if (config != null && !TextUtils.isEmpty(config.getConfigID())) { hierarchicalStreamWriter.addAttribute("configID", config.getConfigID()); } hierarchicalStreamWriter.startNode("pos_x"); hierarchicalStreamWriter.setValue(String.valueOf(jockstickData.getPosX())); hierarchicalStreamWriter.endNode(); hierarchicalStreamWriter.startNode("pos_y"); hierarchicalStreamWriter.setValue(String.valueOf(jockstickData.getPosY())); hierarchicalStreamWriter.endNode(); } @Override // com.thoughtworks.xstream.converters.Converter public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext) { String attribute = hierarchicalStreamReader.getAttribute("widgetId"); if (TextUtils.isEmpty(attribute)) { attribute = hierarchicalStreamReader.getAttribute("widgetID"); } JockstickData jockstickData = new JockstickData(attribute); JockstickConfig jockstickConfig = new JockstickConfig(); String attribute2 = hierarchicalStreamReader.getAttribute("configID"); if (!TextUtils.isEmpty(attribute2)) { jockstickConfig.setConfigID(attribute2); } while (hierarchicalStreamReader.hasMoreChildren()) { hierarchicalStreamReader.moveDown(); switch (hierarchicalStreamReader.getNodeName()) { case "pos_x": jockstickData.setPosX(Float.valueOf(hierarchicalStreamReader.getValue()).floatValue()); break; case "pos_y": jockstickData.setPosY(Float.valueOf(hierarchicalStreamReader.getValue()).floatValue()); break; case "type": try { jockstickConfig.setType((JockstickConfig.JockType) unmarshallingContext.convertAnother(jockstickData, JockstickConfig.JockType.class)); break; } catch (Exception e) { XLog.b(TransportFile.TYPE_CONTROLLER, "unknown JockType"); e.printStackTrace(); jockstickConfig.setType(JockstickConfig.JockType.twoServo); break; } case "motionType": try { jockstickConfig.setMotionType((CtrlMotionType) unmarshallingContext.convertAnother(jockstickData, CtrlMotionType.class)); break; } catch (Exception e2) { e2.printStackTrace(); jockstickConfig.setMotionType(CtrlMotionType.servo); break; } case "leftUpID": Integer valueOf = Integer.valueOf(hierarchicalStreamReader.getValue()); if (valueOf != null && valueOf.intValue() > 0) { jockstickConfig.putWheel(1, new Wheel(valueOf.intValue(), 1)); break; } break; case "rightUpID": Integer valueOf2 = Integer.valueOf(hierarchicalStreamReader.getValue()); if (valueOf2 != null && valueOf2.intValue() > 0) { jockstickConfig.putWheel(2, new Wheel(valueOf2.intValue(), 2)); break; } break; case "leftBottomID": Integer valueOf3 = Integer.valueOf(hierarchicalStreamReader.getValue()); if (valueOf3 != null && valueOf3.intValue() > 0) { jockstickConfig.putWheel(3, new Wheel(valueOf3.intValue(), 3)); break; } break; case "rightBottomID": Integer valueOf4 = Integer.valueOf(hierarchicalStreamReader.getValue()); if (valueOf4 != null && valueOf4.intValue() > 0) { jockstickConfig.putWheel(4, new Wheel(valueOf4.intValue(), 4)); break; } break; case "wheel": Wheel wheel = (Wheel) unmarshallingContext.convertAnother(jockstickData, Wheel.class); jockstickConfig.putWheel(wheel.getPosition(), wheel); break; default: XLog.b("woo", "Unknown node name : %s", hierarchicalStreamReader.getNodeName()); break; } hierarchicalStreamReader.moveUp(); } jockstickData.setConfig(jockstickConfig); return jockstickData; } }