From b654d68ee64d6a353340f46c989821b4bcf23ec5 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Wed, 23 Mar 2011 11:37:20 -0500 Subject: [PATCH] Cleaner editor interface --- androidgcs/default.properties | 2 +- androidgcs/res/layout/object_browser.xml | 3 +- androidgcs/res/layout/object_edit.xml | 6 +- androidgcs/res/layout/object_editor.xml | 6 + androidgcs/res/values/strings.xml | 3 + .../androidgcs/OPTelemetryService.java | 5 +- .../openpilot/androidgcs/ObjectBrowser.java | 3 + .../openpilot/androidgcs/ObjectEditView.java | 114 ++++++++++++++++++ .../openpilot/androidgcs/ObjectEditor.java | 12 +- 9 files changed, 138 insertions(+), 16 deletions(-) create mode 100644 androidgcs/res/layout/object_editor.xml create mode 100644 androidgcs/src/org/openpilot/androidgcs/ObjectEditView.java diff --git a/androidgcs/default.properties b/androidgcs/default.properties index 728f51f97..fd1cedd24 100644 --- a/androidgcs/default.properties +++ b/androidgcs/default.properties @@ -8,4 +8,4 @@ # project structure. # Project target. -target=Google Inc.:Google APIs:11 +target=Google Inc.:Google APIs:10 diff --git a/androidgcs/res/layout/object_browser.xml b/androidgcs/res/layout/object_browser.xml index 880e276ff..9c7456915 100644 --- a/androidgcs/res/layout/object_browser.xml +++ b/androidgcs/res/layout/object_browser.xml @@ -2,5 +2,6 @@ - + + diff --git a/androidgcs/res/layout/object_edit.xml b/androidgcs/res/layout/object_edit.xml index 62a482be9..c161caa4c 100644 --- a/androidgcs/res/layout/object_edit.xml +++ b/androidgcs/res/layout/object_edit.xml @@ -3,7 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> - - - + + + diff --git a/androidgcs/res/layout/object_editor.xml b/androidgcs/res/layout/object_editor.xml new file mode 100644 index 000000000..d93b1a097 --- /dev/null +++ b/androidgcs/res/layout/object_editor.xml @@ -0,0 +1,6 @@ + + + diff --git a/androidgcs/res/values/strings.xml b/androidgcs/res/values/strings.xml index 7cef563e7..6d69e4126 100644 --- a/androidgcs/res/values/strings.xml +++ b/androidgcs/res/values/strings.xml @@ -21,4 +21,7 @@ S W Connected + Update + Save + Send diff --git a/androidgcs/src/org/openpilot/androidgcs/OPTelemetryService.java b/androidgcs/src/org/openpilot/androidgcs/OPTelemetryService.java index c2914f34a..ce90f5a48 100644 --- a/androidgcs/src/org/openpilot/androidgcs/OPTelemetryService.java +++ b/androidgcs/src/org/openpilot/androidgcs/OPTelemetryService.java @@ -74,7 +74,8 @@ public class OPTelemetryService extends Service { Toast.makeText(getApplicationContext(), "Attempting connection", Toast.LENGTH_SHORT).show(); terminate = false; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(OPTelemetryService.this); - int connection_type = Integer.decode(prefs.getString("connection_type", "")); + //int connection_type = Integer.decode(prefs.getString("connection_type", "")); + int connection_type = 1; switch(connection_type) { case 0: // No connection return; @@ -128,7 +129,7 @@ public class OPTelemetryService extends Service { mServiceHandler = new ServiceHandler(mServiceLooper); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(OPTelemetryService.this); - if(prefs.getBoolean("autoconnect", false)) { + if(prefs.getBoolean("autoconnect", false) || true) { Toast.makeText(getApplicationContext(), "Should auto connect", Toast.LENGTH_SHORT); Message msg = mServiceHandler.obtainMessage(); msg.arg1 = MSG_CONNECT; diff --git a/androidgcs/src/org/openpilot/androidgcs/ObjectBrowser.java b/androidgcs/src/org/openpilot/androidgcs/ObjectBrowser.java index df2d114a4..a6ed177a2 100644 --- a/androidgcs/src/org/openpilot/androidgcs/ObjectBrowser.java +++ b/androidgcs/src/org/openpilot/androidgcs/ObjectBrowser.java @@ -17,6 +17,7 @@ import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; +import android.widget.Spinner; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; @@ -46,6 +47,8 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref setContentView(R.layout.object_browser); prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(this); + + Spinner objectFilter = (Spinner) findViewById(R.id.object_list_filter); } @Override diff --git a/androidgcs/src/org/openpilot/androidgcs/ObjectEditView.java b/androidgcs/src/org/openpilot/androidgcs/ObjectEditView.java new file mode 100644 index 000000000..7b81ff18c --- /dev/null +++ b/androidgcs/src/org/openpilot/androidgcs/ObjectEditView.java @@ -0,0 +1,114 @@ +package org.openpilot.androidgcs; + +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; + +import org.openpilot.uavtalk.UAVObjectField; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; + +public class ObjectEditView extends LinearLayout { + + TextView objectName; + List fields; + + public ObjectEditView(Context context) { + super(context); + initObjectEditView(); + } + + public ObjectEditView(Context context, AttributeSet ats, int defaultStyle) { + super(context, ats); + initObjectEditView(); + } + + public ObjectEditView(Context context, AttributeSet ats) { + super(context, ats); + initObjectEditView(); + } + + public void initObjectEditView() { + // Set orientation of layout to vertical + setOrientation(LinearLayout.VERTICAL); + + objectName = new TextView(getContext()); + objectName.setText(""); + objectName.setTextSize(14); + + // Lay them out in the compound control. + int lHeight = LayoutParams.WRAP_CONTENT; + int lWidth = LayoutParams.FILL_PARENT; + addView(objectName, new LinearLayout.LayoutParams(lWidth, lHeight)); + + fields = new ArrayList(); + } + + public void setName(String name) { + objectName.setText(name); + } + + public void addField(UAVObjectField field) { + if(field.getNumElements() == 1) { + FieldValue fieldView = new FieldValue(getContext()); + fieldView.setName(field.getName()); + if(field.isNumeric()) { + fieldView.setValue(new Double(field.getDouble()).toString()); + } else { + fieldView.setValue(field.getValue().toString()); + } + fields.add(fieldView); + addView(fieldView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT)); + } + else { + ListIterator names = field.getElementNames().listIterator(); + int i = 0; + while(names.hasNext()) { + FieldValue fieldView = new FieldValue(getContext()); + fieldView.setName(field.getName() + "-" + names.next()); + if(field.isNumeric()) { + fieldView.setValue(new Double(field.getDouble(i)).toString()); + } else { + fieldView.setValue(field.getValue(i).toString()); + } + i++; + fields.add(fieldView); + addView(fieldView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT)); + + } + } + } + + public class FieldValue extends LinearLayout { + + TextView fieldName; + EditText fieldValue; + + public FieldValue(Context context) { + super(context); + setOrientation(LinearLayout.HORIZONTAL); + + fieldName = new TextView(getContext()); + fieldValue = new EditText(getContext()); + + // Lay them out in the compound control. + addView(fieldName, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT)); + fieldValue.setWidth(300); + addView(fieldValue, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); + } + + public void setName(String name) { + fieldName.setText(name); + } + + public void setValue(String value) { + fieldValue.setText(value); + } + } + +} diff --git a/androidgcs/src/org/openpilot/androidgcs/ObjectEditor.java b/androidgcs/src/org/openpilot/androidgcs/ObjectEditor.java index 33d0e2f8e..afbddb5e5 100644 --- a/androidgcs/src/org/openpilot/androidgcs/ObjectEditor.java +++ b/androidgcs/src/org/openpilot/androidgcs/ObjectEditor.java @@ -7,8 +7,6 @@ import org.openpilot.uavtalk.UAVObject; import org.openpilot.uavtalk.UAVObjectField; import android.os.Bundle; -import android.widget.LinearLayout; -import android.widget.TextView; import android.widget.Toast; public class ObjectEditor extends ObjectManagerActivity { @@ -35,17 +33,13 @@ public class ObjectEditor extends ObjectManagerActivity { UAVObject obj = objMngr.getObject(objectID, instID); Toast.makeText(getApplicationContext(), obj.toString(), Toast.LENGTH_SHORT); - TextView objectName = (TextView) findViewById(R.id.object_edit_name); - objectName.setText(obj.getName()); + ObjectEditView editView = (ObjectEditView) findViewById(R.id.object_edit_view); + editView.setName(obj.getName()); - LinearLayout fieldViewList = (LinearLayout) findViewById(R.id.object_edit_fields); List fields = obj.getFields(); ListIterator li = fields.listIterator(); while(li.hasNext()) { - UAVObjectField field = li.next(); - TextView fieldName = new TextView(this); - fieldName.setText(field.getName()); - fieldViewList.addView(fieldName); + editView.addField(li.next()); } }