Commit a442434e authored by Joey's avatar Joey

glucose: rewrite keyboard layout to use ConstraintLayout

Signed-off-by: Joey's avatarJoey <bevilacquajoey@gmail.com>
Change-Id: I297a75f25334ea959dd281e919da0f79dd1e808a
parent 3609bb65
Pipeline #63020963 passed with stages
in 20 minutes and 33 seconds
......@@ -9,7 +9,10 @@
package it.diab.glucose.widget
import android.content.Context
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.TextUtils
import android.text.style.ImageSpan
import android.util.AttributeSet
import android.view.View
import android.widget.LinearLayout
......@@ -30,7 +33,7 @@ class NumericKeyboardView : LinearLayout {
private val btn7: View
private val btn8: View
private val btn9: View
private val btnDel: View
private val btnDel: TextView
private lateinit var inputView: TextView
private var onTextChanged: (Int) -> Unit = {}
......@@ -80,11 +83,20 @@ class NumericKeyboardView : LinearLayout {
btn8.setOnClickListener { input(8) }
btn9.setOnClickListener { input(9) }
btnDel.setOnClickListener { del() }
btnDel.setOnLongClickListener {
inputView.text = "0"
VibrationUtil.vibrateForImportantClick(it)
true
val delSpan = SpannableStringBuilder().apply {
append(" ")
setSpan(ImageSpan(context, R.drawable.ic_backspace), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
}
btnDel.apply {
setText(delSpan, TextView.BufferType.SPANNABLE)
setOnClickListener { del() }
setOnLongClickListener {
inputView.text = "0"
VibrationUtil.vibrateForImportantClick(it)
true
}
}
}
......
......@@ -7,8 +7,8 @@
or at https://www.gnu.org/licenses/gpl.txt
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:width="32dp"
android:height="32dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
......
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
Copyright (c) 2018 Bevilacqua Joey
Licensed under the GNU GPLv3 license
......@@ -7,90 +6,105 @@
The text of the license can be found in the LICENSE file
or at https://www.gnu.org/licenses/gpl.txt
-->
<TableLayout 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="match_parent"
android:layout_height="wrap_content"
android:paddingStart="16dp"
android:background="@color/colorPrimary"
android:paddingTop="24dp"
android:paddingBottom="16dp"
android:paddingEnd="16dp"
tools:ignore="HardcodedText,Overdraw">
<TableRow android:layout_width="match_parent">
<TextView
style="@style/AppTheme.GlucoseEditor_Key"
android:id="@+id/keyboard_key_1"
android:text="1" />
<TextView
style="@style/AppTheme.GlucoseEditor_Key"
android:id="@+id/keyboard_key_2"
android:text="2" />
<TextView
style="@style/AppTheme.GlucoseEditor_Key"
android:id="@+id/keyboard_key_3"
android:text="3" />
</TableRow>
<TableRow android:layout_width="match_parent">
<TextView
style="@style/AppTheme.GlucoseEditor_Key"
android:id="@+id/keyboard_key_4"
android:text="4" />
<TextView
style="@style/AppTheme.GlucoseEditor_Key"
android:id="@+id/keyboard_key_5"
android:text="5" />
<TextView
style="@style/AppTheme.GlucoseEditor_Key"
android:id="@+id/keyboard_key_6"
android:text="6" />
</TableRow>
<TableRow android:layout_width="match_parent">
<TextView
style="@style/AppTheme.GlucoseEditor_Key"
android:id="@+id/keyboard_key_7"
android:text="7" />
<TextView
style="@style/AppTheme.GlucoseEditor_Key"
android:id="@+id/keyboard_key_8"
android:text="8" />
<TextView
style="@style/AppTheme.GlucoseEditor_Key"
android:id="@+id/keyboard_key_9"
android:text="9" />
</TableRow>
<TableRow android:layout_width="match_parent">
<View
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
style="@style/AppTheme.GlucoseEditor_Key"
android:id="@+id/keyboard_key_0"
android:text="0" />
<ImageView
style="@style/AppTheme.GlucoseEditor_Key"
android:id="@+id/keyboard_key_del"
android:layout_height="match_parent"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:contentDescription="@string/remove"
app:srcCompat="@drawable/ic_backspace" />
</TableRow>
</TableLayout>
android:paddingBottom="16dp"
tools:ignore="HardcodedText">
<TextView
android:id="@+id/keyboard_key_1"
style="@style/AppTheme.GlucoseEditor_Key"
android:text="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.33" />
<TextView
android:id="@+id/keyboard_key_2"
style="@style/AppTheme.GlucoseEditor_Key"
android:text="2"
app:layout_constraintEnd_toStartOf="@id/keyboard_key_3"
app:layout_constraintStart_toEndOf="@id/keyboard_key_1"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/keyboard_key_3"
style="@style/AppTheme.GlucoseEditor_Key"
android:text="3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.33" />
<TextView
android:id="@+id/keyboard_key_4"
style="@style/AppTheme.GlucoseEditor_Key"
android:text="4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/keyboard_key_1"
app:layout_constraintWidth_percent="0.33" />
<TextView
android:id="@+id/keyboard_key_5"
style="@style/AppTheme.GlucoseEditor_Key"
android:text="5"
app:layout_constraintEnd_toStartOf="@id/keyboard_key_3"
app:layout_constraintStart_toEndOf="@id/keyboard_key_4"
app:layout_constraintTop_toBottomOf="@id/keyboard_key_1" />
<TextView
android:id="@+id/keyboard_key_6"
style="@style/AppTheme.GlucoseEditor_Key"
android:text="6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/keyboard_key_1"
app:layout_constraintWidth_percent="0.33" />
<TextView
android:id="@+id/keyboard_key_7"
style="@style/AppTheme.GlucoseEditor_Key"
android:text="7"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/keyboard_key_4"
app:layout_constraintWidth_percent="0.33" />
<TextView
android:id="@+id/keyboard_key_8"
style="@style/AppTheme.GlucoseEditor_Key"
android:text="8"
app:layout_constraintEnd_toStartOf="@id/keyboard_key_9"
app:layout_constraintStart_toEndOf="@id/keyboard_key_7"
app:layout_constraintTop_toBottomOf="@id/keyboard_key_4" />
<TextView
android:id="@+id/keyboard_key_9"
style="@style/AppTheme.GlucoseEditor_Key"
android:text="9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/keyboard_key_4"
app:layout_constraintWidth_percent="0.33" />
<TextView
android:id="@+id/keyboard_key_0"
style="@style/AppTheme.GlucoseEditor_Key"
android:text="0"
app:layout_constraintEnd_toEndOf="@id/keyboard_key_8"
app:layout_constraintStart_toStartOf="@id/keyboard_key_8"
app:layout_constraintTop_toBottomOf="@id/keyboard_key_8" />
<TextView
android:id="@+id/keyboard_key_del"
style="@style/AppTheme.GlucoseEditor_Key"
android:layout_height="match_parent"
android:contentDescription="@string/remove"
android:paddingTop="8dp"
android:paddingBottom="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/keyboard_key_8"
app:layout_constraintWidth_percent="0.33" />
</androidx.constraintlayout.widget.ConstraintLayout>
......@@ -10,7 +10,8 @@
<!-- Glucose editor -->
<style name="AppTheme.GlucoseEditor_Key" parent="@style/TextAppearance.AppCompat.Display1">
<item name="android:layout_weight">1</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">48dp</item>
<item name="android:clickable">true</item>
<item name="android:focusable">true</item>
<item name="android:textAlignment">center</item>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment