From 1b093af941a39a530898f79653a0733082d1fefa Mon Sep 17 00:00:00 2001 From: Andries Smit Date: Fri, 8 Apr 2022 13:33:12 +0200 Subject: [PATCH] style: convert number picker to material design --- .../layout/number_picker_layout_vertical.xml | 69 ++++++++++++------ .../androidaps/utils/ui/NumberPicker.kt | 12 +++- .../res/drawable-hdpi/background_total.xml | 8 --- .../main/res/drawable-hdpi/border_gray.xml | 11 --- .../main/res/layout/number_picker_layout.xml | 72 ++++++++++++------- core/src/main/res/values-night/styles.xml | 4 -- core/src/main/res/values/attrs.xml | 4 -- core/src/main/res/values/styles.xml | 4 -- 8 files changed, 103 insertions(+), 81 deletions(-) delete mode 100644 core/src/main/res/drawable-hdpi/background_total.xml delete mode 100644 core/src/main/res/drawable-hdpi/border_gray.xml diff --git a/app/src/main/res/layout/number_picker_layout_vertical.xml b/app/src/main/res/layout/number_picker_layout_vertical.xml index b43a9cec1b..1193461d9b 100644 --- a/app/src/main/res/layout/number_picker_layout_vertical.xml +++ b/app/src/main/res/layout/number_picker_layout_vertical.xml @@ -1,34 +1,57 @@ - + android:layout_height="100dp"> + + + + + + - - + android:layout_marginStart="-2dp" + android:layout_marginTop="-4dp" + android:layout_marginEnd="-2dp" + android:contentDescription="@string/a11y_min_button_description" + android:src="@drawable/ic_plus" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + android:layout_width="0dp" + android:layout_height="40dp" + android:layout_marginStart="-2dp" + android:layout_marginEnd="-2dp" + android:layout_marginBottom="-3.8dp" + android:contentDescription="@string/a11y_plus_button_description" + android:src="@drawable/ic_minus" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" /> - \ No newline at end of file + diff --git a/core/src/main/java/info/nightscout/androidaps/utils/ui/NumberPicker.kt b/core/src/main/java/info/nightscout/androidaps/utils/ui/NumberPicker.kt index f69da340a6..027b235d12 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/ui/NumberPicker.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/ui/NumberPicker.kt @@ -19,10 +19,12 @@ import android.view.accessibility.AccessibilityEvent import android.view.accessibility.AccessibilityManager import android.view.inputmethod.InputMethodManager import android.widget.Button -import android.widget.EditText import android.widget.ImageButton import android.widget.LinearLayout +import com.google.android.material.textfield.TextInputEditText +import com.google.android.material.textfield.TextInputLayout import info.nightscout.androidaps.core.R +import info.nightscout.androidaps.extensions.toVisibility import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.shared.SafeParse import java.text.NumberFormat @@ -39,9 +41,10 @@ open class NumberPicker(context: Context, attrs: AttributeSet? = null) : LinearL fun onValueChanged(value: Double) } - var editText: EditText? = null + var editText: TextInputEditText? = null private var minusButton: ImageButton? = null private var plusButton: ImageButton? = null + var textInputLayout: TextInputLayout? = null var currentValue = 0.0 var minValue = 0.0 var maxValue = 1.0 @@ -110,6 +113,7 @@ open class NumberPicker(context: Context, attrs: AttributeSet? = null) : LinearL minusButton?.id = generateViewId() plusButton = findViewById(R.id.increment) plusButton?.id = generateViewId() + textInputLayout = findViewById(R.id.textInputLayout) editText = findViewById(R.id.display) editText?.id = generateViewId() minusButton?.setOnTouchListener(this) @@ -124,7 +128,9 @@ open class NumberPicker(context: Context, attrs: AttributeSet? = null) : LinearL override fun afterTextChanged(s: Editable) { if (focused) currentValue = SafeParse.stringToDouble(editText?.text.toString()) callValueChangedListener() - okButton?.visibility = if (currentValue > maxValue || currentValue < minValue) INVISIBLE else VISIBLE + val inValid = currentValue > maxValue || currentValue < minValue + okButton?.visibility = inValid.not().toVisibility() + textInputLayout?.error = if (inValid) "invalid" else null } }) editText?.setOnFocusChangeListener { _: View?, hasFocus: Boolean -> diff --git a/core/src/main/res/drawable-hdpi/background_total.xml b/core/src/main/res/drawable-hdpi/background_total.xml deleted file mode 100644 index e37fbd2035..0000000000 --- a/core/src/main/res/drawable-hdpi/background_total.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/core/src/main/res/drawable-hdpi/border_gray.xml b/core/src/main/res/drawable-hdpi/border_gray.xml deleted file mode 100644 index a67f54bf90..0000000000 --- a/core/src/main/res/drawable-hdpi/border_gray.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/core/src/main/res/layout/number_picker_layout.xml b/core/src/main/res/layout/number_picker_layout.xml index 0ebb24a3ba..cf88f0c0f7 100644 --- a/core/src/main/res/layout/number_picker_layout.xml +++ b/core/src/main/res/layout/number_picker_layout.xml @@ -1,34 +1,58 @@ - + android:layout_height="40dp"> + + + + + + - - + android:layout_width="40dp" + android:layout_height="0dp" + android:layout_marginStart="-2dp" + android:layout_marginTop="-4dp" + android:layout_marginBottom="-3.7dp" + android:contentDescription="@string/a11y_min_button_description" + android:src="@drawable/ic_minus" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + android:layout_width="40dp" + android:layout_height="0dp" + android:layout_marginTop="-4dp" + android:layout_marginEnd="-2dp" + android:layout_marginBottom="-3.7dp" + android:contentDescription="@string/a11y_plus_button_description" + android:src="@drawable/ic_plus" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> - + diff --git a/core/src/main/res/values-night/styles.xml b/core/src/main/res/values-night/styles.xml index bd4e0d8a15..5528d9f13f 100644 --- a/core/src/main/res/values-night/styles.xml +++ b/core/src/main/res/values-night/styles.xml @@ -32,16 +32,12 @@ @drawable/ic_close @color/bolus - - @color/black @color/action @color/cardObjectiveText @color/alarm - - @color/sphere_plastic_grey @color/colorSetTempButton diff --git a/core/src/main/res/values/attrs.xml b/core/src/main/res/values/attrs.xml index 1078e1607c..695bca245c 100644 --- a/core/src/main/res/values/attrs.xml +++ b/core/src/main/res/values/attrs.xml @@ -1,16 +1,12 @@ - - - - diff --git a/core/src/main/res/values/styles.xml b/core/src/main/res/values/styles.xml index 43a98803bd..cf07ef10a6 100644 --- a/core/src/main/res/values/styles.xml +++ b/core/src/main/res/values/styles.xml @@ -40,16 +40,12 @@ @drawable/ic_close @color/bolus - - @color/black @android:color/holo_orange_light @color/cardObjectiveText @color/alarm - - @color/gray @color/colorSetTempButton