1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

More work on the object browser/editor. Hard to make it resize itself though.

This commit is contained in:
James Cotton 2011-03-21 18:33:47 -05:00
parent 247d3a7754
commit fd3a02eb92
7 changed files with 108 additions and 21 deletions

View File

@ -26,6 +26,7 @@
</activity>
<activity android:name="Preferences" android:label="@string/preference_title"/>
<activity android:name="ObjectEditor" android:label="ObjectEditor" android:theme="@android:style/Theme.Dialog"/>
<receiver android:name="TelemetryWidget">
<intent-filter>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_height="wrap_content" android:text="ObjectEditor: " android:id="@+id/object_edit_title" android:layout_alignParentTop="true" android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:textStyle="bold"></TextView>
<TextView android:text="" android:id="@+id/object_edit_name" android:layout_toRightOf="@+id/object_edit_title" android:layout_alignTop="@+id/textView1" android:layout_alignBottom="@+id/textView1" android:layout_height="wrap_content" android:layout_width="50dip"></TextView>
<LinearLayout android:id="@+id/object_edit_fields" android:layout_height="match_parent" android:layout_width="match_parent" android:layout_alignParentBottom="true" android:orientation="vertical"></LinearLayout>
</RelativeLayout>

View File

@ -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<UAVDataObject> adapter;
List<UAVDataObject> 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<List<UAVDataObject>> allobjects = objMngr.getDataObjects();
List<UAVDataObject> linearized = new ArrayList<UAVDataObject>();
allObjects = new ArrayList<UAVDataObject>();
ListIterator<List<UAVDataObject>> li = allobjects.listIterator();
while(li.hasNext()) {
linearized.addAll(li.next());
allObjects.addAll(li.next());
}
adapter = new ArrayAdapter<UAVDataObject>(this,R.layout.object_view, linearized);
adapter = new ArrayAdapter<UAVDataObject>(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
}
}

View File

@ -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<UAVObjectField> fields = obj.getFields();
ListIterator<UAVObjectField> li = fields.listIterator();
while(li.hasNext()) {
UAVObjectField field = li.next();
TextView fieldName = new TextView(this);
fieldName.setText(field.getName());
fieldViewList.addView(fieldName);
}
}
}

View File

@ -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();
}
};
}