1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

AndroidGCS: Refine the graphics of the object editor

This commit is contained in:
James Cotton 2012-08-04 23:00:25 -05:00
parent 0348a8921e
commit 3a3ac552da
7 changed files with 179 additions and 108 deletions

View File

@ -2,14 +2,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.openpilot.androidgcs" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="11" />
<uses-sdk android:minSdkVersion="14" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.Holo">
<!-- for map overlay -->
<uses-library android:name="com.google.android.maps" />

View File

@ -1,10 +1,13 @@
<?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">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:gravity="right" >
<LinearLayout
android:layout_width="wrap_content"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
@ -12,7 +15,7 @@
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<CheckBox
@ -30,28 +33,62 @@
android:text="Data" />
</LinearLayout>
<View
android:layout_height="1dip"
android:layout_width="fill_parent"
android:background="#FFFFFFFF" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="fill_parent"
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" />
android:drawSelectorOnTop="true"
android:choiceMode="singleChoice"/>
<View
android:layout_width="1dip"
android:layout_height="fill_parent"
android:background="#FFFFFFFF" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="@+id/object_information"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="12dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/editButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginBottom="32dp"
android:layout_marginRight="12dp"
android:text="Edit" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>

View File

@ -1,9 +0,0 @@
<?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">
<org.openpilot.androidgcs.ObjectEditView android:layout_height="wrap_content" android:text="ObjectEditor: " android:id="@+id/object_edit_view" android:layout_alignParentTop="true" android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:textStyle="bold"></org.openpilot.androidgcs.ObjectEditView>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentBottom="true" android:id="@+id/object_edit_send_button" android:text="@string/send_button"></Button>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/object_edit_save_button" android:text="@string/save_button" android:layout_toRightOf="@+id/object_edit_send_button" android:layout_alignTop="@+id/object_edit_send_button" android:layout_alignBottom="@+id/object_edit_send_button"></Button>
</RelativeLayout>

View File

@ -1,6 +1,45 @@
<?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">
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ObjectEditor" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.56" >
<org.openpilot.androidgcs.ObjectEditView
android:id="@+id/object_edit_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</org.openpilot.androidgcs.ObjectEditView>
</ScrollView>
<!-- View android:layout_width="200dp" android:layout_height="1dip" android:background="#FFFFFFFF" / -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right" >
<Button
android:id="@+id/object_edit_send_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/send_button" />
<Button
android:id="@+id/object_edit_save_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save_button" />
</LinearLayout>
</LinearLayout>

View File

@ -14,19 +14,18 @@ import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
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;
import org.openpilot.uavtalk.UAVDataObject;
import org.openpilot.uavtalk.UAVObject;
public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPreferenceChangeListener {
@ -61,7 +60,6 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
@Override
void onOPConnected() {
Toast.makeText(this,"Telemetry estabilished",Toast.LENGTH_SHORT);
Log.d(TAG, "onOPConnected()");
OnCheckedChangeListener checkListener = new OnCheckedChangeListener() {
@ -75,6 +73,19 @@ public class ObjectBrowser extends ObjectManagerActivity implements OnSharedPref
((CheckBox) findViewById(R.id.dataCheck)).setOnCheckedChangeListener(checkListener);
((CheckBox) findViewById(R.id.settingsCheck)).setOnCheckedChangeListener(checkListener);
((Button) findViewById(R.id.editButton)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (selected_index > 0) {
Intent intent = new Intent(ObjectBrowser.this, ObjectEditor.class);
intent.putExtra("org.openpilot.androidgcs.ObjectName", allObjects.get(selected_index).getName());
intent.putExtra("org.openpilot.androidgcs.ObjectId", allObjects.get(selected_index).getObjID());
intent.putExtra("org.openpilot.androidgcs.InstId", allObjects.get(selected_index).getInstID());
startActivity(intent);
}
}
});
updateList();
}

View File

@ -2,20 +2,23 @@ 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.text.InputType;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.GridLayout;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
public class ObjectEditView extends LinearLayout {
public class ObjectEditView extends GridLayout {
TextView objectName;
String objectName;
List<View> fields;
public ObjectEditView(Context context) {
@ -36,79 +39,63 @@ public class ObjectEditView extends LinearLayout {
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));
setColumnCount(2);
fields = new ArrayList<View>();
}
public void setName(String name) {
objectName.setText(name);
objectName = 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<String> 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));
}
}
for (int i = 0; i < field.getNumElements(); i++)
addRow(getContext(), field, i);
}
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 addRow(Context context, UAVObjectField field, int idx) {
int row = getRowCount();
TextView fieldName = new TextView(context);
if(field.getNumElements() == 1) {
fieldName.setText(field.getName());
} else {
fieldName.setText(field.getName() + "-" + field.getElementNames().get(idx));
}
addView(fieldName, new GridLayout.LayoutParams(spec(row), spec(0)));
public void setName(String name) {
fieldName.setText(name);
View fieldValue = null;
switch(field.getType())
{
case FLOAT32:
fieldValue = new EditText(context);
((EditText)fieldValue).setText(field.getValue(idx).toString());
((EditText)fieldValue).setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL);
break;
case INT8:
case INT16:
case INT32:
fieldValue = new EditText(context);
((EditText)fieldValue).setText(field.getValue(idx).toString());
((EditText)fieldValue).setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
break;
case UINT8:
case UINT16:
case UINT32:
fieldValue = new EditText(context);
((EditText)fieldValue).setText(field.getValue(idx).toString());
((EditText)fieldValue).setInputType(InputType.TYPE_CLASS_NUMBER);
break;
case ENUM:
fieldValue = new Spinner(context);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item);
adapter.addAll(field.getOptions());
((Spinner) fieldValue).setAdapter(adapter);
break;
}
public void setValue(String value) {
fieldValue.setText(value);
}
addView(fieldValue, new GridLayout.LayoutParams(spec(row), spec(1)));
fields.add(fieldValue);
}
}

View File

@ -7,7 +7,6 @@ import org.openpilot.uavtalk.UAVObject;
import org.openpilot.uavtalk.UAVObjectField;
import android.os.Bundle;
import android.widget.Toast;
public class ObjectEditor extends ObjectManagerActivity {
@ -18,21 +17,28 @@ public class ObjectEditor extends ObjectManagerActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.object_edit);
setContentView(R.layout.object_editor);
System.out.println("Started. Intent:" + getIntent());
// TODO: Figure out why this line is required so it doesn't
// have to be set programmatically
setTheme(android.R.style.Theme_Holo);
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");
}
setTitle(objectName);
}
}
public void onOPConnected() {
UAVObject obj = objMngr.getObject(objectID, instID);
Toast.makeText(getApplicationContext(), obj.toString(), Toast.LENGTH_SHORT);
if (obj == null)
return;
ObjectEditView editView = (ObjectEditView) findViewById(R.id.object_edit_view);
editView.setName(obj.getName());