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

AndroidGCS Tuning: Add custom attributes so we can specify the name of the tuning bars from the layout file.

Hopefully we can programmatically link them to the StabilizationSettings and create a smart Apply/Save button similarly to the GCS implementation.
This commit is contained in:
James Cotton 2012-08-28 16:06:52 -05:00
parent 7c48b46adf
commit 2a4adbda38
4 changed files with 91 additions and 7 deletions

View File

@ -1,12 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:setting_attributes="http://schemas.android.com/apk/res/org.openpilot.androidgcs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<org.openpilot.androidgcs.views.ScrollBarView
android:id="@+id/rollRateKp"
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<org.openpilot.androidgcs.views.ScrollBarView
android:id="@+id/rollRateKp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
setting_attributes:setting_name="Roll Rate Kp" />
<org.openpilot.androidgcs.views.ScrollBarView
android:id="@+id/pitchRateKp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
setting_attributes:setting_name="Pitch Rate Kp" />
<org.openpilot.androidgcs.views.ScrollBarView
android:id="@+id/rollRateKi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
setting_attributes:setting_name="Roll Rate Ki" />
<org.openpilot.androidgcs.views.ScrollBarView
android:id="@+id/pitchRateKi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
setting_attributes:setting_name="Pitch Rate Ki" />
<org.openpilot.androidgcs.views.ScrollBarView
android:id="@+id/rollKp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
setting_attributes:setting_name="Roll Kp" />
<org.openpilot.androidgcs.views.ScrollBarView
android:id="@+id/pitchKp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
setting_attributes:setting_name="Pitch Kp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<Button
android:id="@+id/applyBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/apply" />
<Button
android:id="@+id/saveBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="setting_attributes">
<attr name="setting_name" format="string"/>
</declare-styleable>
</resources>

View File

@ -33,4 +33,6 @@
<string name="txrate">TxRate: </string>
<string name="rxrate">RxRate: </string>
<string name="tuning">Tuning</string>
<string name="apply">Apply</string>
<string name="save">Save</string>
</resources>

View File

@ -1,6 +1,9 @@
package org.openpilot.androidgcs.views;
import org.openpilot.androidgcs.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.EditText;
@ -17,6 +20,7 @@ public class ScrollBarView extends GridLayout {
private final EditText edit;
private final SeekBar bar;
private double value;
private String name;
private final double SCALE = 1000000;
@ -29,7 +33,8 @@ public class ScrollBarView extends GridLayout {
setColumnCount(2);
lbl = new TextView(context);
lbl.setText("Roll Rate Kp:");
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.setting_attributes, 0, 0);
lbl.setText(ta.getString(R.styleable.setting_attributes_setting_name));
addView(lbl, new GridLayout.LayoutParams(spec(0), spec(0)));
edit = new EditText(context);
@ -47,8 +52,14 @@ public class ScrollBarView extends GridLayout {
public void setValue(double val)
{
value = val;
edit.setText(Double.toString(val));
bar.setProgress((int) (SCALE * val));
edit.setText(Double.toString(value));
bar.setProgress((int) (SCALE * value));
}
public void setName(String n)
{
name = n;
lbl.setText(name);
}
@Override