-
Notifications
You must be signed in to change notification settings - Fork 556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Update to Tower to support Alt Frames like Terrain #1826
base: develop
Are you sure you want to change the base?
Changes from all commits
cd053f1
f039fa3
8919299
b17ac49
441c411
68243be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,12 @@ | |
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.AdapterView; | ||
import android.widget.Spinner; | ||
import android.widget.TextView; | ||
|
||
import com.o3dr.android.client.Drone; | ||
import com.o3dr.services.android.lib.coordinate.Frame; | ||
import com.o3dr.services.android.lib.coordinate.LatLong; | ||
import com.o3dr.services.android.lib.coordinate.LatLongAlt; | ||
import com.o3dr.services.android.lib.drone.attribute.AttributeEvent; | ||
|
@@ -166,8 +168,8 @@ public void onSpinnerItemSelected(Spinner spinner, int position) { | |
for (LatLong coordinate : polygonPoints) { | ||
MissionItem newItem = selectedType.getNewItem(); | ||
if (newItem instanceof MissionItem.SpatialItem) { | ||
((MissionItem.SpatialItem) newItem).setCoordinate(new LatLongAlt(coordinate | ||
.getLatitude(), coordinate.getLongitude(), altitude)); | ||
((MissionItem.SpatialItem) newItem).getCoordinate().set(coordinate); | ||
((MissionItem.SpatialItem) newItem).getCoordinate().setAltitude(altitude); | ||
} | ||
|
||
newItems.add(new MissionItemProxy(mMissionProxy, newItem)); | ||
|
@@ -206,11 +208,69 @@ public void onSpinnerItemSelected(Spinner spinner, int position) { | |
} | ||
}; | ||
|
||
private final Spinner.OnItemSelectedListener missionFrameListener = new Spinner.OnItemSelectedListener() { | ||
|
||
@Override | ||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | ||
frameSpinner = (Spinner) view.findViewById(R.id.frameSpinner); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @billbonney You should be able to remove this assignment since |
||
|
||
if (frameSpinner != null && mSelectedProxies.isEmpty()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @billbonney This has the effect that if |
||
return; | ||
|
||
MissionItemType selectedType = commandAdapter.getItem(position); | ||
List<Pair<MissionItemProxy, List<MissionItemProxy>>> updatedList = new ArrayList<>( | ||
mSelectedProxies.size()); | ||
|
||
for (MissionItemProxy missionItemProxy : mSelectedProxies) { | ||
|
||
MissionItem currentItem = missionItemProxy.getMissionItem(); | ||
|
||
List<MissionItemProxy> updatedItems = new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @billbonney Looks like there's at most one entry in the |
||
|
||
if (currentItem instanceof MissionItem.SpatialItem) { | ||
// Only items that have frames need to be updated | ||
MissionItem.SpatialItem spatialItem = ((MissionItem.SpatialItem) currentItem); | ||
|
||
boolean updated = false; | ||
switch (position) { | ||
case 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @billbonney Here and below, use java constants for the case labels. |
||
updated = spatialItem.getCoordinate().setFrame(Frame.GLOBAL_ABS); | ||
break; | ||
case 1: | ||
updated = spatialItem.getCoordinate().setFrame(Frame.GLOBAL_RELATIVE); | ||
break; | ||
case 2: | ||
updated = spatialItem.getCoordinate().setFrame(Frame.GLOBAL_TERRAIN); | ||
break; | ||
default: | ||
// Do Nothing | ||
break; | ||
} | ||
|
||
if (updated) { | ||
updatedItems.add(missionItemProxy); | ||
updatedList.add(Pair.create(missionItemProxy, updatedItems)); | ||
} | ||
} | ||
} | ||
if (!updatedList.isEmpty()) { | ||
mListener.onWaypointTypeChanged(selectedType, updatedList); | ||
dismiss(); // TODO:!BB! do we want to dismiss the dialog | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @billbonney I don't think so. It should auto dismiss after the user's selection. |
||
} | ||
} | ||
|
||
@Override | ||
public void onNothingSelected(AdapterView<?> parent) { | ||
|
||
} | ||
}; | ||
|
||
protected int getResource() { | ||
return R.layout.fragment_editor_detail_generic; | ||
} | ||
|
||
protected SpinnerSelfSelect typeSpinner; | ||
protected Spinner frameSpinner; | ||
protected AdapterMissionItems commandAdapter; | ||
private OnMissionDetailListener mListener; | ||
|
||
|
@@ -424,6 +484,8 @@ public void onApiConnected() { | |
typeSpinner = (SpinnerSelfSelect) view.findViewById(R.id.spinnerWaypointType); | ||
typeSpinner.setAdapter(commandAdapter); | ||
typeSpinner.setOnSpinnerItemSelectedListener(missionItemSpinnerListener); | ||
|
||
setupFrameSpinner(view); | ||
} | ||
|
||
public void onResume(){ | ||
|
@@ -497,6 +559,41 @@ private boolean hasSpatialOrComplexItems(List<MissionItemProxy> items) { | |
return false; | ||
} | ||
|
||
private void setupFrameSpinner(View view) { | ||
|
||
frameSpinner = (Spinner) view.findViewById(R.id.frameSpinner); | ||
|
||
if (frameSpinner == null) // no frame option just return | ||
return; | ||
|
||
for (MissionItemProxy itemProxy : mSelectedProxies) { | ||
MissionItem currentItem = itemProxy.getMissionItem(); | ||
|
||
if (currentItem instanceof MissionItem.SpatialItem) { | ||
Frame frame = ((MissionItem.SpatialItem) currentItem).getCoordinate().getFrame(); | ||
// List<String> strList = new ArrayList<>("@arrays/") // TODO !BB! Get List from array string | ||
switch (frame) { | ||
case GLOBAL_ABS: | ||
frameSpinner.setSelection(0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @billbonney Use java constants as arguments for the |
||
break; | ||
case LOCAL_NED: // TODO !BB! Fix to add NED | ||
break; | ||
case MISSION: // TODO !BB! Fix to add Mission | ||
break; | ||
case GLOBAL_RELATIVE: | ||
frameSpinner.setSelection(1); | ||
break; | ||
case LOCAL_ENU: // TODO !BB! Fix to add ENU | ||
break; | ||
case GLOBAL_TERRAIN: | ||
frameSpinner.setSelection(2); | ||
break; | ||
} | ||
} | ||
frameSpinner.setOnItemSelectedListener(missionFrameListener); | ||
} | ||
} | ||
|
||
@Override | ||
public void onApiDisconnected() { | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@billbonney Here and below,
Waypoint#getCoordinate()
is not guaranteed to be non-null, so this changes will result in several npe errors.