Merge pull request #1589 from Andries-Smit/style/material-number-picker

Style: material number picker
This commit is contained in:
Milos Kozak 2022-04-08 14:29:57 +02:00 committed by GitHub
commit 094c653a4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 110 additions and 85 deletions

View file

@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activities.SurveyActivity">
tools:context=".activities.StatsActivity">
<LinearLayout
android:layout_width="match_parent"

View file

@ -1,34 +1,57 @@
<?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"
android:layout_width="60dp"
android:layout_height="100dp"
android:background="@drawable/background_total"
android:orientation="vertical">
android:layout_height="100dp">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="match_parent"
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">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/display"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:imeOptions="actionDone"
android:inputType="number"
tools:text="1" />
</com.google.android.material.textfield.TextInputLayout>
<ImageButton
android:id="@+id/increment"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@color/transparent"
android:src="@drawable/ic_plus" />
<EditText
android:id="@+id/display"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="40dp"
android:background="@drawable/border_gray"
android:gravity="center"
android:imeOptions="actionDone"
android:inputType="number"
android:textColor="?attr/numPickerText"
tools:text="1" />
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
android:id="@+id/decrement"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@color/transparent"
android:src="@drawable/ic_minus" />
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" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -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 ->

View file

@ -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>

View file

@ -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>

View file

@ -29,7 +29,8 @@
android:layout_marginRight="10dp"
android:layout_toEndOf="@id/header_icon"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
android:textAppearance="?android:attr/textAppearanceLarge"
tools:text="Going to deliver: 4.00 U" />
</RelativeLayout>
@ -46,7 +47,8 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp" />
android:paddingRight="10dp"
tools:text="Delivering 1.9U"/>
<TextView
android:id="@+id/stoppressed"
@ -69,7 +71,8 @@
android:layout_marginTop="20dp"
android:layout_marginRight="5dp"
android:maxHeight="5dp"
android:minHeight="3dp" />
android:minHeight="3dp"
tools:progress="50"/>
<com.google.android.material.button.MaterialButton
style="@style/GrayButton"

View file

@ -1,34 +1,58 @@
<?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"
android:layout_width="130dp"
android:layout_height="40dp"
android:background="@drawable/background_total"
android:orientation="horizontal">
android:layout_height="40dp">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/display"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:imeOptions="actionDone"
android:inputType="number"
android:padding="9dp"
tools:text="1" />
</com.google.android.material.textfield.TextInputLayout>
<ImageButton
android:id="@+id/decrement"
android:layout_width="30dp"
android:layout_height="match_parent"
android:background="@color/transparent"
android:src="@drawable/ic_minus" />
<EditText
android:id="@+id/display"
android:layout_width="70dp"
android:layout_height="match_parent"
android:background="@drawable/border_gray"
android:gravity="center"
android:imeOptions="actionDone"
android:inputType="number"
android:textColor="?attr/numPickerText"
tools:text="1" />
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
android:id="@+id/increment"
android:layout_width="30dp"
android:layout_height="match_parent"
android:background="@color/transparent"
android:src="@drawable/ic_plus" />
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" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -32,16 +32,12 @@
<item name="actionModeCloseDrawable">@drawable/ic_close</item>
<!---bolus color -->
<item name="bolusColor">@color/bolus</item>
<!---Number Picker text color -->
<item name="numPickerText">@color/black</item>
<!---NS Client action text color -->
<item name="actionButton">@color/action</item>
<!---Text color for Quickwizard and more -->
<item name="cardObjectiveText">@color/cardObjectiveText</item>
<!---Text color for misc buttons and texts -->
<item name="alarmColor">@color/alarm</item>
<!-- Number picker and more -->
<item name="totalBackground">@color/sphere_plastic_grey</item>
<!-- BG source temp button -->
<item name="setTempButton">@color/colorSetTempButton</item>
<!-- Card Item-->

View file

@ -1,16 +1,12 @@
<resources>
<!---bolus color -->
<attr name="bolusColor" format="reference|color" />
<!---Number Picker text color -->
<attr name="numPickerText" format="reference|color" />
<!---NS Client action text color -->
<attr name="actionButton" format="reference|color" />
<!---Text color for Quickwizard and more -->
<attr name="cardObjectiveText" format="reference|color" />
<!---Text color for misc buttons and texts -->
<attr name="alarmColor" format="reference|color" />
<!-- Number picker and more -->
<attr name="totalBackground" format="reference|color" />
<!-- BG source temp button -->
<attr name="setTempButton" format="reference|color" />
<!-- Card Item-->

View file

@ -40,16 +40,12 @@
<item name="actionModeCloseDrawable">@drawable/ic_close</item>
<!---bolus color -->
<item name="bolusColor">@color/bolus</item>
<!---Number Picker text color -->
<item name="numPickerText">@color/black</item>
<!---NS Client action text color -->
<item name="actionButton">@android:color/holo_orange_light</item>
<!---Text color for Quickwizard and more -->
<item name="cardObjectiveText">@color/cardObjectiveText</item>
<!---Text color for misc buttons and texts -->
<item name="alarmColor">@color/alarm</item>
<!-- Number picker and more -->
<item name="totalBackground">@color/gray</item>
<!-- BG source temp button -->
<item name="setTempButton">@color/colorSetTempButton</item>
<!-- Card Item-->