public static void buildComplexMissionItem(MavLinkDrone drone, Bundle itemBundle) { MissionItem missionItem = MissionItemType.restoreMissionItemFromBundle(itemBundle); if (missionItem == null || !(missionItem instanceof MissionItem.ComplexItem)) return; final MissionItemType itemType = missionItem.getType(); switch (itemType) { case SURVEY: Survey updatedSurvey = buildSurvey(drone, (Survey) missionItem); if (updatedSurvey != null) itemType.storeMissionItem(updatedSurvey, itemBundle); break; case SPLINE_SURVEY: Survey updatedSplineSurvey = buildSplineSurvey(drone, (Survey) missionItem); if (updatedSplineSurvey != null) itemType.storeMissionItem(updatedSplineSurvey, itemBundle); break; case STRUCTURE_SCANNER: StructureScanner updatedScanner = buildStructureScanner(drone, (StructureScanner) missionItem); if (updatedScanner != null) itemType.storeMissionItem(updatedScanner, itemBundle); break; default: Timber.w("Unrecognized complex mission item."); break; } }
@Override public void onSpinnerItemSelected(Spinner spinner, int position) { final MissionItemType selectedType = commandAdapter.getItem(position); try { if (mSelectedProxies.isEmpty()) return; final List<Pair<MissionItemProxy, MissionItemProxy>> updatesList = new ArrayList<Pair<MissionItemProxy, MissionItemProxy>>(mSelectedProxies.size()); for (MissionItemProxy missionItemProxy : mSelectedProxies) { final MissionItem oldItem = missionItemProxy.getMissionItem(); if (oldItem.getType() != selectedType) { final MissionItem newItem = selectedType.getNewItem(); if (oldItem instanceof MissionItem.SpatialItem && newItem instanceof MissionItem.SpatialItem) { ((MissionItem.SpatialItem) newItem) .setCoordinate(((MissionItem.SpatialItem) oldItem).getCoordinate()); } updatesList.add( Pair.create(missionItemProxy, new MissionItemProxy(mMissionProxy, newItem))); } } if (!updatesList.isEmpty()) { mListener.onWaypointTypeChanged(selectedType, updatesList); dismiss(); } } catch (IllegalArgumentException e) { e.printStackTrace(); } }