Adds ability score picker.
This commit is contained in:
@@ -35,12 +35,11 @@ public class AbilityScorePicker extends LinearLayout {
|
||||
// TODO: use this as default but allow setting via attribute
|
||||
mLabel = "Ability Score";
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AbilityScorePicker, 0, 0);
|
||||
String label = a.getString(R.styleable.AbilityScorePicker_label);
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Stepper, 0, 0);
|
||||
String label = a.getString(R.styleable.Stepper_label);
|
||||
if (label != null) {
|
||||
mLabel = label;
|
||||
}
|
||||
a.recycle();
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View root = inflater.inflate(R.layout.component_ability_score_picker, this, true);
|
||||
@@ -70,17 +69,18 @@ public class AbilityScorePicker extends LinearLayout {
|
||||
mHolder.spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
setValue((AbilityScore) parent.getItemAtPosition(position));
|
||||
mSelectedValue = (AbilityScore) parent.getItemAtPosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
setValue(mSelectedValue = AbilityScore.STRENGTH);
|
||||
mSelectedValue = AbilityScore.STRENGTH;
|
||||
}
|
||||
});
|
||||
mHolder.spinner.setSelection(ArrayHelper.indexOf(AbilityScore.values(), mSelectedValue));
|
||||
|
||||
setValue(AbilityScore.STRENGTH);
|
||||
// TODO: listen for changes on the component to update mSelectedValue;
|
||||
}
|
||||
|
||||
public AbilityScorePicker(@NonNull Context context) {
|
||||
@@ -93,8 +93,7 @@ public class AbilityScorePicker extends LinearLayout {
|
||||
|
||||
public void setValue(AbilityScore value) {
|
||||
if (value != mSelectedValue) {
|
||||
mSelectedValue = value;
|
||||
mHolder.spinner.setSelection(ArrayHelper.indexOf(AbilityScore.values(), value));
|
||||
mHolder.spinner.setSelection(ArrayHelper.indexOf(AbilityScore.values(), mSelectedValue));
|
||||
if (mOnValueChangedListener != null) {
|
||||
mOnValueChangedListener.onValueChanged(value);
|
||||
}
|
||||
@@ -125,7 +124,7 @@ public class AbilityScorePicker extends LinearLayout {
|
||||
private final Spinner spinner;
|
||||
private final TextView label;
|
||||
|
||||
ViewHolder(@NonNull View root) {
|
||||
ViewHolder(View root) {
|
||||
spinner = root.findViewById(R.id.spinner);
|
||||
label = root.findViewById(R.id.label);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
tools:context=".ui.components.AbilityScorePicker">
|
||||
<!-- // TODO: style this control to look less awful by default -->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label"
|
||||
|
||||
Reference in New Issue
Block a user