1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-30 15:52:12 +01:00

AndroidGCS: Refactor the UAVO browser to use a split view - objects names on

the side and content on the other side.  Add a filter for settings versus data.
This commit is contained in:
James Cotton 2012-08-04 21:02:05 -05:00
parent 8f98383fa5
commit c3b5f90b50
5 changed files with 151 additions and 36 deletions

View File

@ -2,6 +2,56 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner android:layout_alignParentTop="true" android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/object_list_filter"></Spinner>
<ListView android:id="@+id/object_list" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_below="@+id/spinner1" android:layout_alignLeft="@+id/spinner1" android:layout_alignRight="@+id/spinner1"></ListView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/settingsCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Settings" />
<CheckBox
android:id="@+id/dataCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Data" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ListView
android:id="@+id/object_list"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
<TextView
android:id="@+id/object_information"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>

View File

@ -1,8 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.openpilot.androidgcs.CompassView android:id="@+id/compass_view" android:layout_height="wrap_content" android:layout_width="wrap_content"></org.openpilot.androidgcs.CompassView>
<org.openpilot.androidgcs.AttitudeView android:id="@+id/attitude_view" android:layout_height="fill_parent" android:layout_width="fill_parent"></org.openpilot.androidgcs.AttitudeView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<org.openpilot.androidgcs.CompassView
android:id="@+id/compass_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<org.openpilot.androidgcs.AttitudeView
android:id="@+id/attitude_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<com.MobileAnarchy.Android.Widgets.Joystick.DualJoystickView
android:id="@+id/dualjoystickView"
android:layout_width="fill_parent"
android:layout_height="175dip"
android:layout_marginTop="5dip" >
</com.MobileAnarchy.Android.Widgets.Joystick.DualJoystickView>
</LinearLayout>

View File

@ -16,8 +16,12 @@ import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
@ -27,6 +31,7 @@ import org.openpilot.uavtalk.UAVObject;
public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPreferenceChangeListener {
private final String TAG = "ObjectBrower";
int selected_index = -1;
boolean connected;
SharedPreferences prefs;
ArrayAdapter<UAVDataObject> adapter;
@ -35,10 +40,15 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
final Handler uavobjHandler = new Handler();
final Runnable updateText = new Runnable() {
public void run() {
Log.d(TAG,"Update");
update();
updateObject();
}
};
private final Observer updatedObserver = new Observer() {
public void update(Observable observable, Object data) {
uavobjHandler.post(updateText);
}
};
/** Called when the activity is first created. */
@Override
@ -47,20 +57,48 @@ 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
void onOPConnected() {
Toast.makeText(this,"Telemetry estabilished",Toast.LENGTH_SHORT);
Log.d(TAG, "onOPConnected()");
OnCheckedChangeListener checkListener = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
updateList();
}
};
((CheckBox) findViewById(R.id.dataCheck)).setOnCheckedChangeListener(checkListener);
((CheckBox) findViewById(R.id.settingsCheck)).setOnCheckedChangeListener(checkListener);
updateList();
}
/**
* Populate the list of UAVO objects based on the selected filter
*/
private void updateList() {
// Disconnect any previous signals
if (selected_index > 0)
allObjects.get(selected_index).removeUpdatedObserver(updatedObserver);
selected_index = -1;
boolean includeData = ((CheckBox) findViewById(R.id.dataCheck)).isChecked();
boolean includeSettings = ((CheckBox) findViewById(R.id.settingsCheck)).isChecked();
List<List<UAVDataObject>> allobjects = objMngr.getDataObjects();
allObjects = new ArrayList<UAVDataObject>();
ListIterator<List<UAVDataObject>> li = allobjects.listIterator();
while(li.hasNext()) {
allObjects.addAll(li.next());
List<UAVDataObject> objects = li.next();
if(includeSettings && objects.get(0).isSettings())
allObjects.addAll(objects);
else if (includeData && !objects.get(0).isSettings())
allObjects.addAll(objects);
}
adapter = new ArrayAdapter<UAVDataObject>(this,R.layout.object_view, allObjects);
@ -70,29 +108,25 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
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);
if (selected_index > 0)
allObjects.get(selected_index).removeUpdatedObserver(updatedObserver);
selected_index = position;
allObjects.get(position).addUpdatedObserver(updatedObserver);
updateObject();
}
});
UAVObject obj = objMngr.getObject("SystemStats");
if(obj != null)
obj.addUpdatedObserver(new Observer() {
public void update(Observable observable, Object data) {
uavobjHandler.post(updateText);
}
});
}
public void update() {
adapter.notifyDataSetChanged();
private void updateObject() {
//adapter.notifyDataSetChanged();
TextView text = (TextView) findViewById(R.id.object_information);
if (selected_index >= 0 && selected_index < allObjects.size())
text.setText(allObjects.get(selected_index).toStringData());
else
Log.d(TAG,"Update called but invalid index: " + selected_index);
}
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,

View File

@ -52,6 +52,11 @@ public abstract class UAVObject {
}
private CallbackListener updatedListeners = new CallbackListener(this);
public void removeUpdatedObserver(Observer o) {
synchronized(updatedListeners) {
updatedListeners.deleteObserver(o);
}
}
public void addUpdatedObserver(Observer o) {
synchronized(updatedListeners) {
updatedListeners.addObserver(o);
@ -730,14 +735,14 @@ public abstract class UAVObject {
*/
@Override
public String toString() {
return toStringBrief() + toStringData();
return toStringBrief(); // + toStringData();
}
/**
* Return a string with the object information (only the header)
*/
public String toStringBrief() {
return getName() + " (" + Integer.toHexString(getObjID()) + " " + Integer.toHexString(getInstID()) + " " + getNumBytes() + ")\n";
return getName(); // + " (" + Integer.toHexString(getObjID()) + " " + Integer.toHexString(getInstID()) + " " + getNumBytes() + ")\n";
}
/**

View File

@ -469,7 +469,11 @@ public class UAVObjectField {
public String toString() {
String sout = new String();
sout += name + ": " + data.toString() + " (" + units + ")\n";
sout += name + ": " + getValue().toString();
if (units.length() > 0)
sout += " (" + units + ")\n";
else
sout += "\n";
return sout;
}