mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-12 02:54:15 +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:
parent
8f98383fa5
commit
c3b5f90b50
@ -2,6 +2,56 @@
|
|||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="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>
|
</RelativeLayout>
|
||||||
|
@ -1,8 +1,30 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:orientation="vertical" >
|
||||||
<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
|
||||||
|
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>
|
</LinearLayout>
|
||||||
|
@ -16,8 +16,12 @@ import android.util.Log;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
|
|
||||||
@ -27,6 +31,7 @@ import org.openpilot.uavtalk.UAVObject;
|
|||||||
public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPreferenceChangeListener {
|
public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
private final String TAG = "ObjectBrower";
|
private final String TAG = "ObjectBrower";
|
||||||
|
int selected_index = -1;
|
||||||
boolean connected;
|
boolean connected;
|
||||||
SharedPreferences prefs;
|
SharedPreferences prefs;
|
||||||
ArrayAdapter<UAVDataObject> adapter;
|
ArrayAdapter<UAVDataObject> adapter;
|
||||||
@ -35,8 +40,13 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
|
|||||||
final Handler uavobjHandler = new Handler();
|
final Handler uavobjHandler = new Handler();
|
||||||
final Runnable updateText = new Runnable() {
|
final Runnable updateText = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Log.d(TAG,"Update");
|
updateObject();
|
||||||
update();
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final Observer updatedObserver = new Observer() {
|
||||||
|
public void update(Observable observable, Object data) {
|
||||||
|
uavobjHandler.post(updateText);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -47,8 +57,6 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
|
|||||||
setContentView(R.layout.object_browser);
|
setContentView(R.layout.object_browser);
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
Spinner objectFilter = (Spinner) findViewById(R.id.object_list_filter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -56,11 +64,41 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
|
|||||||
Toast.makeText(this,"Telemetry estabilished",Toast.LENGTH_SHORT);
|
Toast.makeText(this,"Telemetry estabilished",Toast.LENGTH_SHORT);
|
||||||
Log.d(TAG, "onOPConnected()");
|
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();
|
List<List<UAVDataObject>> allobjects = objMngr.getDataObjects();
|
||||||
allObjects = new ArrayList<UAVDataObject>();
|
allObjects = new ArrayList<UAVDataObject>();
|
||||||
ListIterator<List<UAVDataObject>> li = allobjects.listIterator();
|
ListIterator<List<UAVDataObject>> li = allobjects.listIterator();
|
||||||
while(li.hasNext()) {
|
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);
|
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() {
|
objects.setOnItemClickListener(new OnItemClickListener() {
|
||||||
public void onItemClick(AdapterView<?> parent, View view,
|
public void onItemClick(AdapterView<?> parent, View view,
|
||||||
int position, long id) {
|
int position, long id) {
|
||||||
/*Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
|
|
||||||
Toast.LENGTH_SHORT).show();*/
|
if (selected_index > 0)
|
||||||
Intent intent = new Intent(ObjectBrowser.this, ObjectEditor.class);
|
allObjects.get(selected_index).removeUpdatedObserver(updatedObserver);
|
||||||
intent.putExtra("org.openpilot.androidgcs.ObjectName", allObjects.get(position).getName());
|
|
||||||
intent.putExtra("org.openpilot.androidgcs.ObjectId", allObjects.get(position).getObjID());
|
selected_index = position;
|
||||||
intent.putExtra("org.openpilot.androidgcs.InstId", allObjects.get(position).getInstID());
|
allObjects.get(position).addUpdatedObserver(updatedObserver);
|
||||||
startActivity(intent);
|
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() {
|
private void updateObject() {
|
||||||
adapter.notifyDataSetChanged();
|
//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,
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
||||||
|
@ -52,6 +52,11 @@ public abstract class UAVObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private CallbackListener updatedListeners = new CallbackListener(this);
|
private CallbackListener updatedListeners = new CallbackListener(this);
|
||||||
|
public void removeUpdatedObserver(Observer o) {
|
||||||
|
synchronized(updatedListeners) {
|
||||||
|
updatedListeners.deleteObserver(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
public void addUpdatedObserver(Observer o) {
|
public void addUpdatedObserver(Observer o) {
|
||||||
synchronized(updatedListeners) {
|
synchronized(updatedListeners) {
|
||||||
updatedListeners.addObserver(o);
|
updatedListeners.addObserver(o);
|
||||||
@ -730,14 +735,14 @@ public abstract class UAVObject {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return toStringBrief() + toStringData();
|
return toStringBrief(); // + toStringData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a string with the object information (only the header)
|
* Return a string with the object information (only the header)
|
||||||
*/
|
*/
|
||||||
public String toStringBrief() {
|
public String toStringBrief() {
|
||||||
return getName() + " (" + Integer.toHexString(getObjID()) + " " + Integer.toHexString(getInstID()) + " " + getNumBytes() + ")\n";
|
return getName(); // + " (" + Integer.toHexString(getObjID()) + " " + Integer.toHexString(getInstID()) + " " + getNumBytes() + ")\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -469,7 +469,11 @@ public class UAVObjectField {
|
|||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String sout = new String();
|
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;
|
return sout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user