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

AndroidGCS Tuning: Fix the callbacks for the scroll and edit boxes so both can work.

Also added an attribute for the maximum value for the scroll range.
This commit is contained in:
James Cotton 2012-08-29 03:19:49 -05:00
parent 4a433d32f7
commit 71d5f9d090
3 changed files with 58 additions and 7 deletions

View File

@ -20,37 +20,43 @@
android:id="@+id/rollRateKp" android:id="@+id/rollRateKp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
setting_attributes:setting_name="Roll Rate Kp" /> setting_attributes:setting_name="Roll Rate Kp"
setting_attributes:max_value="0.01" />
<org.openpilot.androidgcs.views.ScrollBarView <org.openpilot.androidgcs.views.ScrollBarView
android:id="@+id/pitchRateKp" android:id="@+id/pitchRateKp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
setting_attributes:setting_name="Pitch Rate Kp" /> setting_attributes:setting_name="Pitch Rate Kp"
setting_attributes:max_value="0.01" />
<org.openpilot.androidgcs.views.ScrollBarView <org.openpilot.androidgcs.views.ScrollBarView
android:id="@+id/rollRateKi" android:id="@+id/rollRateKi"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
setting_attributes:setting_name="Roll Rate Ki" /> setting_attributes:setting_name="Roll Rate Ki"
setting_attributes:max_value="0.05" />
<org.openpilot.androidgcs.views.ScrollBarView <org.openpilot.androidgcs.views.ScrollBarView
android:id="@+id/pitchRateKi" android:id="@+id/pitchRateKi"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
setting_attributes:setting_name="Pitch Rate Ki" /> setting_attributes:setting_name="Pitch Rate Ki"
setting_attributes:max_value="0.05" />
<org.openpilot.androidgcs.views.ScrollBarView <org.openpilot.androidgcs.views.ScrollBarView
android:id="@+id/rollKp" android:id="@+id/rollKp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
setting_attributes:setting_name="Roll Kp" /> setting_attributes:setting_name="Roll Kp"
setting_attributes:max_value="5" />
<org.openpilot.androidgcs.views.ScrollBarView <org.openpilot.androidgcs.views.ScrollBarView
android:id="@+id/pitchKp" android:id="@+id/pitchKp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
setting_attributes:setting_name="Pitch Kp" /> setting_attributes:setting_name="Pitch Kp"
setting_attributes:max_value="5" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View File

@ -2,5 +2,6 @@
<resources> <resources>
<declare-styleable name="setting_attributes"> <declare-styleable name="setting_attributes">
<attr name="setting_name" format="string"/> <attr name="setting_name" format="string"/>
<attr name="max_value" format="float"/>
</declare-styleable> </declare-styleable>
</resources> </resources>

View File

@ -5,12 +5,15 @@ import org.openpilot.androidgcs.util.ObjectFieldMappable;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.widget.EditText; import android.widget.EditText;
import android.widget.GridLayout; import android.widget.GridLayout;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView; import android.widget.TextView;
public class ScrollBarView extends GridLayout implements ObjectFieldMappable { public class ScrollBarView extends GridLayout implements ObjectFieldMappable {
@ -43,7 +46,48 @@ public class ScrollBarView extends GridLayout implements ObjectFieldMappable {
bar = new SeekBar(context); bar = new SeekBar(context);
addView(bar, new GridLayout.LayoutParams(spec(1), spec(0,2))); addView(bar, new GridLayout.LayoutParams(spec(1), spec(0,2)));
bar.setMax((int) (SCALE * 0.01));
ta = context.obtainStyledAttributes(attrs, R.styleable.setting_attributes, 0, 0);
final double max = ta.getFloat(R.styleable.setting_attributes_max_value,0);
bar.setMax((int) (SCALE * max));
// Update the value when the progress bar changes
bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
value = progress / SCALE;
edit.setText(Double.toString(value));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
// Update the value when the edit box changes
edit.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
value = Double.parseDouble(s.toString());
bar.setProgress((int) (SCALE * value));
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
});
setPadding(5,5,5,5); setPadding(5,5,5,5);