style: convert number picker to material design
This commit is contained in:
parent
fa9a470526
commit
1b093af941
8 changed files with 103 additions and 81 deletions
|
@ -1,34 +1,57 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="60dp"
|
android:layout_width="60dp"
|
||||||
android:layout_height="100dp"
|
android:layout_height="100dp">
|
||||||
android:background="@drawable/background_total"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<ImageButton
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:id="@+id/increment"
|
android:id="@+id/textInputLayout"
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="30dp"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/transparent"
|
app:errorEnabled="true"
|
||||||
android:src="@drawable/ic_plus" />
|
app:hintEnabled="false"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
<EditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
android:id="@+id/display"
|
android:id="@+id/display"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="40dp"
|
android:layout_height="match_parent"
|
||||||
android:background="@drawable/border_gray"
|
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:imeOptions="actionDone"
|
android:imeOptions="actionDone"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:textColor="?attr/numPickerText"
|
|
||||||
tools:text="1" />
|
tools:text="1" />
|
||||||
|
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/increment"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
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" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/decrement"
|
android:id="@+id/decrement"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="0dp"
|
||||||
android:layout_height="30dp"
|
android:layout_height="40dp"
|
||||||
android:background="@color/transparent"
|
android:layout_marginStart="-2dp"
|
||||||
android:src="@drawable/ic_minus" />
|
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" />
|
||||||
|
|
||||||
</LinearLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
|
@ -19,10 +19,12 @@ import android.view.accessibility.AccessibilityEvent
|
||||||
import android.view.accessibility.AccessibilityManager
|
import android.view.accessibility.AccessibilityManager
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.EditText
|
|
||||||
import android.widget.ImageButton
|
import android.widget.ImageButton
|
||||||
import android.widget.LinearLayout
|
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.core.R
|
||||||
|
import info.nightscout.androidaps.extensions.toVisibility
|
||||||
import info.nightscout.androidaps.utils.ToastUtils
|
import info.nightscout.androidaps.utils.ToastUtils
|
||||||
import info.nightscout.shared.SafeParse
|
import info.nightscout.shared.SafeParse
|
||||||
import java.text.NumberFormat
|
import java.text.NumberFormat
|
||||||
|
@ -39,9 +41,10 @@ open class NumberPicker(context: Context, attrs: AttributeSet? = null) : LinearL
|
||||||
fun onValueChanged(value: Double)
|
fun onValueChanged(value: Double)
|
||||||
}
|
}
|
||||||
|
|
||||||
var editText: EditText? = null
|
var editText: TextInputEditText? = null
|
||||||
private var minusButton: ImageButton? = null
|
private var minusButton: ImageButton? = null
|
||||||
private var plusButton: ImageButton? = null
|
private var plusButton: ImageButton? = null
|
||||||
|
var textInputLayout: TextInputLayout? = null
|
||||||
var currentValue = 0.0
|
var currentValue = 0.0
|
||||||
var minValue = 0.0
|
var minValue = 0.0
|
||||||
var maxValue = 1.0
|
var maxValue = 1.0
|
||||||
|
@ -110,6 +113,7 @@ open class NumberPicker(context: Context, attrs: AttributeSet? = null) : LinearL
|
||||||
minusButton?.id = generateViewId()
|
minusButton?.id = generateViewId()
|
||||||
plusButton = findViewById(R.id.increment)
|
plusButton = findViewById(R.id.increment)
|
||||||
plusButton?.id = generateViewId()
|
plusButton?.id = generateViewId()
|
||||||
|
textInputLayout = findViewById(R.id.textInputLayout)
|
||||||
editText = findViewById(R.id.display)
|
editText = findViewById(R.id.display)
|
||||||
editText?.id = generateViewId()
|
editText?.id = generateViewId()
|
||||||
minusButton?.setOnTouchListener(this)
|
minusButton?.setOnTouchListener(this)
|
||||||
|
@ -124,7 +128,9 @@ open class NumberPicker(context: Context, attrs: AttributeSet? = null) : LinearL
|
||||||
override fun afterTextChanged(s: Editable) {
|
override fun afterTextChanged(s: Editable) {
|
||||||
if (focused) currentValue = SafeParse.stringToDouble(editText?.text.toString())
|
if (focused) currentValue = SafeParse.stringToDouble(editText?.text.toString())
|
||||||
callValueChangedListener()
|
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 ->
|
editText?.setOnFocusChangeListener { _: View?, hasFocus: Boolean ->
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<shape
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:shape="rectangle">
|
|
||||||
<solid android:color="?attr/totalBackground"/>
|
|
||||||
<stroke android:width="1dp" android:color="?attr/colorControlNormal"/>
|
|
||||||
<corners android:radius="4dp" />
|
|
||||||
</shape>
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
|
|
||||||
<item android:bottom="0dp">
|
|
||||||
<shape
|
|
||||||
android:shape="rectangle">
|
|
||||||
<stroke android:width="1dp" android:color="?attr/colorControlNormal"/>
|
|
||||||
<solid android:color="@android:color/white" />
|
|
||||||
<corners android:radius="0dp" />
|
|
||||||
</shape>
|
|
||||||
</item>
|
|
||||||
</layer-list>
|
|
|
@ -1,34 +1,58 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="130dp"
|
android:layout_width="130dp"
|
||||||
android:layout_height="40dp"
|
android:layout_height="40dp">
|
||||||
android:background="@drawable/background_total"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<ImageButton
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:id="@+id/decrement"
|
android:id="@+id/textInputLayout"
|
||||||
android:layout_width="30dp"
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||||
android:layout_height="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:background="@color/transparent"
|
android:layout_height="wrap_content"
|
||||||
android:src="@drawable/ic_minus" />
|
app:errorEnabled="true"
|
||||||
|
app:hintEnabled="false"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
<EditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
android:id="@+id/display"
|
android:id="@+id/display"
|
||||||
android:layout_width="70dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/border_gray"
|
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:imeOptions="actionDone"
|
android:imeOptions="actionDone"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:textColor="?attr/numPickerText"
|
android:padding="9dp"
|
||||||
tools:text="1" />
|
tools:text="1" />
|
||||||
|
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/decrement"
|
||||||
|
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" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/increment"
|
android:id="@+id/increment"
|
||||||
android:layout_width="30dp"
|
android:layout_width="40dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="0dp"
|
||||||
android:background="@color/transparent"
|
android:layout_marginTop="-4dp"
|
||||||
android:src="@drawable/ic_plus" />
|
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" />
|
||||||
|
|
||||||
</LinearLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
|
@ -32,16 +32,12 @@
|
||||||
<item name="actionModeCloseDrawable">@drawable/ic_close</item>
|
<item name="actionModeCloseDrawable">@drawable/ic_close</item>
|
||||||
<!---bolus color -->
|
<!---bolus color -->
|
||||||
<item name="bolusColor">@color/bolus</item>
|
<item name="bolusColor">@color/bolus</item>
|
||||||
<!---Number Picker text color -->
|
|
||||||
<item name="numPickerText">@color/black</item>
|
|
||||||
<!---NS Client action text color -->
|
<!---NS Client action text color -->
|
||||||
<item name="actionButton">@color/action</item>
|
<item name="actionButton">@color/action</item>
|
||||||
<!---Text color for Quickwizard and more -->
|
<!---Text color for Quickwizard and more -->
|
||||||
<item name="cardObjectiveText">@color/cardObjectiveText</item>
|
<item name="cardObjectiveText">@color/cardObjectiveText</item>
|
||||||
<!---Text color for misc buttons and texts -->
|
<!---Text color for misc buttons and texts -->
|
||||||
<item name="alarmColor">@color/alarm</item>
|
<item name="alarmColor">@color/alarm</item>
|
||||||
<!-- Number picker and more -->
|
|
||||||
<item name="totalBackground">@color/sphere_plastic_grey</item>
|
|
||||||
<!-- BG source temp button -->
|
<!-- BG source temp button -->
|
||||||
<item name="setTempButton">@color/colorSetTempButton</item>
|
<item name="setTempButton">@color/colorSetTempButton</item>
|
||||||
<!-- Card Item-->
|
<!-- Card Item-->
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
<resources>
|
<resources>
|
||||||
<!---bolus color -->
|
<!---bolus color -->
|
||||||
<attr name="bolusColor" format="reference|color" />
|
<attr name="bolusColor" format="reference|color" />
|
||||||
<!---Number Picker text color -->
|
|
||||||
<attr name="numPickerText" format="reference|color" />
|
|
||||||
<!---NS Client action text color -->
|
<!---NS Client action text color -->
|
||||||
<attr name="actionButton" format="reference|color" />
|
<attr name="actionButton" format="reference|color" />
|
||||||
<!---Text color for Quickwizard and more -->
|
<!---Text color for Quickwizard and more -->
|
||||||
<attr name="cardObjectiveText" format="reference|color" />
|
<attr name="cardObjectiveText" format="reference|color" />
|
||||||
<!---Text color for misc buttons and texts -->
|
<!---Text color for misc buttons and texts -->
|
||||||
<attr name="alarmColor" format="reference|color" />
|
<attr name="alarmColor" format="reference|color" />
|
||||||
<!-- Number picker and more -->
|
|
||||||
<attr name="totalBackground" format="reference|color" />
|
|
||||||
<!-- BG source temp button -->
|
<!-- BG source temp button -->
|
||||||
<attr name="setTempButton" format="reference|color" />
|
<attr name="setTempButton" format="reference|color" />
|
||||||
<!-- Card Item-->
|
<!-- Card Item-->
|
||||||
|
|
|
@ -40,16 +40,12 @@
|
||||||
<item name="actionModeCloseDrawable">@drawable/ic_close</item>
|
<item name="actionModeCloseDrawable">@drawable/ic_close</item>
|
||||||
<!---bolus color -->
|
<!---bolus color -->
|
||||||
<item name="bolusColor">@color/bolus</item>
|
<item name="bolusColor">@color/bolus</item>
|
||||||
<!---Number Picker text color -->
|
|
||||||
<item name="numPickerText">@color/black</item>
|
|
||||||
<!---NS Client action text color -->
|
<!---NS Client action text color -->
|
||||||
<item name="actionButton">@android:color/holo_orange_light</item>
|
<item name="actionButton">@android:color/holo_orange_light</item>
|
||||||
<!---Text color for Quickwizard and more -->
|
<!---Text color for Quickwizard and more -->
|
||||||
<item name="cardObjectiveText">@color/cardObjectiveText</item>
|
<item name="cardObjectiveText">@color/cardObjectiveText</item>
|
||||||
<!---Text color for misc buttons and texts -->
|
<!---Text color for misc buttons and texts -->
|
||||||
<item name="alarmColor">@color/alarm</item>
|
<item name="alarmColor">@color/alarm</item>
|
||||||
<!-- Number picker and more -->
|
|
||||||
<item name="totalBackground">@color/gray</item>
|
|
||||||
<!-- BG source temp button -->
|
<!-- BG source temp button -->
|
||||||
<item name="setTempButton">@color/colorSetTempButton</item>
|
<item name="setTempButton">@color/colorSetTempButton</item>
|
||||||
<!-- Card Item-->
|
<!-- Card Item-->
|
||||||
|
|
Loading…
Reference in a new issue