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