From fd3a02eb92ddd89d6b1faefe8c2382f1570167a1 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Mon, 21 Mar 2011 18:33:47 -0500 Subject: [PATCH] More work on the object browser/editor. Hard to make it resize itself though. --- androidgcs/AndroidManifest.xml | 1 + androidgcs/Doc/.AndroidArchitecture.txt.swp | Bin 12288 -> 0 bytes .../layout/{main.xml => object_browser.xml} | 0 androidgcs/res/layout/object_edit.xml | 9 +++ .../openpilot/androidgcs/ObjectBrowser.java | 44 ++++++++------- .../openpilot/androidgcs/ObjectEditor.java | 52 ++++++++++++++++++ .../androidgcs/ObjectManagerActivity.java | 23 +++++++- 7 files changed, 108 insertions(+), 21 deletions(-) delete mode 100644 androidgcs/Doc/.AndroidArchitecture.txt.swp rename androidgcs/res/layout/{main.xml => object_browser.xml} (100%) create mode 100644 androidgcs/res/layout/object_edit.xml create mode 100644 androidgcs/src/org/openpilot/androidgcs/ObjectEditor.java diff --git a/androidgcs/AndroidManifest.xml b/androidgcs/AndroidManifest.xml index a791d0fbb..fe8c6ae9a 100644 --- a/androidgcs/AndroidManifest.xml +++ b/androidgcs/AndroidManifest.xml @@ -26,6 +26,7 @@ + diff --git a/androidgcs/Doc/.AndroidArchitecture.txt.swp b/androidgcs/Doc/.AndroidArchitecture.txt.swp deleted file mode 100644 index 167a072526a8207b396d71d6dd7d3e7a417cba19..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeHNzmFS56rMwnA3z`iK>^J`id>>QJ0S%T4RS8dVU#03?7Kh}jd#cP-0jXRGqdLy zB_JeP;2%IhK?4;OL^LQ=G-;^`1>rxSqu_h9yY}UZv?yp!`Qr2bn0fDe-}~N1+2N_J z-UffYb%x>RC}UrI^6`eazqIt*H;ip3#(SgBo~CmT`FUIA`E0F~nM7m{xr}`{U$A}N zBxNqOckRp8jIGFXrN`|{h18c-W_(-d)EbqJ6GxY}JJr{YO(x3A#FtjK{0;xG&EmPp zKxAOSK2dF}KmI(Y2WSN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27?lH&?XqC1*CKB2< zJRd2H4ssgICx|G+fTt48MX*tgmL`RI(p33h$kce^=a=@Oe8i7VUSI1!c$Bh$@MKO} z)yAt)QxAH8;9x{Ma{lmmg0?`p(M<5NMIcQCRwfb;P%hM!HY3^6{aAa>5fmB5hHtb? zVZnXGHoT4&hb!U1?v2pE^H6zZEvPGvF2pr&X_;cKVK49(?j|=txdk7|DGdht+4F>0 I9l+o0U$ht(TmS$7 diff --git a/androidgcs/res/layout/main.xml b/androidgcs/res/layout/object_browser.xml similarity index 100% rename from androidgcs/res/layout/main.xml rename to androidgcs/res/layout/object_browser.xml diff --git a/androidgcs/res/layout/object_edit.xml b/androidgcs/res/layout/object_edit.xml new file mode 100644 index 000000000..62a482be9 --- /dev/null +++ b/androidgcs/res/layout/object_edit.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/androidgcs/src/org/openpilot/androidgcs/ObjectBrowser.java b/androidgcs/src/org/openpilot/androidgcs/ObjectBrowser.java index f3cc56d47..df2d114a4 100644 --- a/androidgcs/src/org/openpilot/androidgcs/ObjectBrowser.java +++ b/androidgcs/src/org/openpilot/androidgcs/ObjectBrowser.java @@ -9,25 +9,16 @@ import java.util.Observer; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; -import android.database.DataSetObserver; import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; import android.util.Log; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; -import android.widget.Adapter; +import android.widget.AdapterView; import android.widget.ArrayAdapter; -import android.widget.ExpandableListAdapter; -import android.widget.ExpandableListView; import android.widget.ListView; -import android.widget.SimpleAdapter; -import android.widget.SimpleExpandableListAdapter; -import android.widget.TextView; import android.widget.Toast; +import android.widget.AdapterView.OnItemClickListener; import org.openpilot.uavtalk.UAVDataObject; import org.openpilot.uavtalk.UAVObject; @@ -38,6 +29,7 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref boolean connected; SharedPreferences prefs; ArrayAdapter adapter; + List allObjects; final Handler uavobjHandler = new Handler(); final Runnable updateText = new Runnable() { @@ -51,7 +43,7 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.main); + setContentView(R.layout.object_browser); prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(this); } @@ -60,18 +52,32 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref void onOPConnected() { Toast.makeText(this,"Telemetry estabilished",Toast.LENGTH_SHORT); Log.d(TAG, "onOPConnected()"); - + List> allobjects = objMngr.getDataObjects(); - List linearized = new ArrayList(); + allObjects = new ArrayList(); ListIterator> li = allobjects.listIterator(); while(li.hasNext()) { - linearized.addAll(li.next()); + allObjects.addAll(li.next()); } - - adapter = new ArrayAdapter(this,R.layout.object_view, linearized); + + adapter = new ArrayAdapter(this,R.layout.object_view, allObjects); ListView objects = (ListView) findViewById(R.id.object_list); objects.setAdapter(adapter); + objects.setOnItemClickListener(new OnItemClickListener() { + public void onItemClick(AdapterView parent, View view, + int position, long id) { + /*Toast.makeText(getApplicationContext(), ((TextView) view).getText(), + Toast.LENGTH_SHORT).show();*/ + Intent intent = new Intent(ObjectBrowser.this, ObjectEditor.class); + intent.putExtra("org.openpilot.androidgcs.ObjectName", allObjects.get(position).getName()); + intent.putExtra("org.openpilot.androidgcs.ObjectId", allObjects.get(position).getObjID()); + intent.putExtra("org.openpilot.androidgcs.InstId", allObjects.get(position).getInstID()); + startActivity(intent); + } + }); + + UAVObject obj = objMngr.getObject("SystemStats"); if(obj != null) obj.addUpdatedObserver(new Observer() { @@ -81,7 +87,7 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref }); } - + public void update() { adapter.notifyDataSetChanged(); } @@ -89,6 +95,6 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { // TODO Auto-generated method stub - + } } diff --git a/androidgcs/src/org/openpilot/androidgcs/ObjectEditor.java b/androidgcs/src/org/openpilot/androidgcs/ObjectEditor.java new file mode 100644 index 000000000..33d0e2f8e --- /dev/null +++ b/androidgcs/src/org/openpilot/androidgcs/ObjectEditor.java @@ -0,0 +1,52 @@ +package org.openpilot.androidgcs; + +import java.util.List; +import java.util.ListIterator; + +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 { + + String objectName; + int objectID; + int instID; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.object_edit); + + System.out.println("Started. Intent:" + getIntent()); + Bundle extras = getIntent().getExtras(); + if(extras != null){ + objectName = extras.getString("org.openpilot.androidgcs.ObjectName"); + objectID = extras.getInt("org.openpilot.androidgcs.ObjectId"); + instID = extras.getInt("org.openpilot.androidgcs.InstId"); + } + } + + public void onOPConnected() { + 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()); + + 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); + } + } + +} diff --git a/androidgcs/src/org/openpilot/androidgcs/ObjectManagerActivity.java b/androidgcs/src/org/openpilot/androidgcs/ObjectManagerActivity.java index d91946b92..5027d4d24 100644 --- a/androidgcs/src/org/openpilot/androidgcs/ObjectManagerActivity.java +++ b/androidgcs/src/org/openpilot/androidgcs/ObjectManagerActivity.java @@ -21,7 +21,7 @@ import android.view.MenuItem; public abstract class ObjectManagerActivity extends Activity { private final String TAG = "ObjectManagerActivity"; - private static int LOGLEVEL = 2; + private static int LOGLEVEL = 0; // private static boolean WARN = LOGLEVEL > 1; private static boolean DEBUG = LOGLEVEL > 0; @@ -106,19 +106,38 @@ public abstract class ObjectManagerActivity extends Activity { Intent intent = new Intent(this, OPTelemetryService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } + + public void onBind() { + + } /** Defines callbacks for service binding, passed to bindService() */ private ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName arg0, IBinder service) { // We've bound to LocalService, cast the IBinder and attempt to open a connection if (DEBUG) Log.d(TAG,"Service bound"); - binder = (LocalBinder) service; + mBound = true; + binder = (LocalBinder) service; + + if(binder.isConnected()) { + TelemTask task; + if((task = binder.getTelemTask(0)) != null) { + objMngr = task.getObjectManager(); + mConnected = true; + onOPConnected(); + } + + } } public void onServiceDisconnected(ComponentName name) { mBound = false; + binder = null; mConnected = false; objMngr = null; + objMngr = null; + mConnected = false; + onOPDisconnected(); } }; }