chore: wear: plus minus view adapter

This commit is contained in:
Andries Smit 2022-06-26 13:17:16 +02:00
parent 4628f3136d
commit 14d1ba80ab
19 changed files with 544 additions and 386 deletions

View file

@ -56,10 +56,9 @@ class AcceptActivity : ViewSelectorActivity() {
override fun getColumnCount(arg0: Int): Int = 2 override fun getColumnCount(arg0: Int): Int = 2
override fun getRowCount(): Int = 1 override fun getRowCount(): Int = 1
override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when (col) {
val view: View 0 -> {
if (col == 0) { val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_text, container, false)
view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_text, container, false)
val textView = view.findViewById<TextView>(R.id.message) val textView = view.findViewById<TextView>(R.id.message)
val scrollView = view.findViewById<View>(R.id.message_scroll) val scrollView = view.findViewById<View>(R.id.message_scroll)
textView.text = message textView.text = message
@ -79,8 +78,11 @@ class AcceptActivity : ViewSelectorActivity() {
false false
} }
scrollView.requestFocus() scrollView.requestFocus()
} else { view
view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) }
else -> {
val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false)
val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton) val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton)
confirmButton.setOnClickListener { confirmButton.setOnClickListener {
if (actionKey.isNotEmpty()) startService(IntentWearToMobile(this@AcceptActivity, actionKey)) if (actionKey.isNotEmpty()) startService(IntentWearToMobile(this@AcceptActivity, actionKey))
@ -88,8 +90,8 @@ class AcceptActivity : ViewSelectorActivity() {
finishAffinity() finishAffinity()
} }
container.addView(view) container.addView(view)
view
} }
return view
} }
override fun destroyItem(container: ViewGroup, row: Int, col: Int, view: Any) { override fun destroyItem(container: ViewGroup, row: Int, col: Int, view: Any) {
@ -127,4 +129,4 @@ class AcceptActivity : ViewSelectorActivity() {
finish() finish()
} }
} }
} }

View file

@ -37,20 +37,23 @@ class BolusActivity : ViewSelectorActivity() {
val increment1 = (sp.getDouble(R.string.key_insulin_button_increment_1, 0.5) * 10).roundToInt() / 10.0 val increment1 = (sp.getDouble(R.string.key_insulin_button_increment_1, 0.5) * 10).roundToInt() / 10.0
val increment2 = (sp.getDouble(R.string.key_insulin_button_increment_2, 1.0) * 10).roundToInt() / 10.0 val increment2 = (sp.getDouble(R.string.key_insulin_button_increment_2, 1.0) * 10).roundToInt() / 10.0
val stepValues = listOf(0.1, increment1, increment2)
override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when (col) {
val view: View 0 -> {
if (col == 0) { val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true)
view = EditPlusMinusViewAdapter.getInflatedPlusMinusView(sp, applicationContext, container, true).root
val initValue = if (editInsulin != null) SafeParse.stringToDouble(editInsulin?.editText?.text.toString()) else 0.0 val initValue = if (editInsulin != null) SafeParse.stringToDouble(editInsulin?.editText?.text.toString()) else 0.0
val maxBolus = sp.getDouble(getString(R.string.key_treatments_safety_max_bolus), 3.0) val maxBolus = sp.getDouble(getString(R.string.key_treatments_safety_max_bolus), 3.0)
val buttons = listOf(Pair(R.id.plusbutton, 0.1), Pair(R.id.plusbutton2, increment1), Pair(R.id.plusbutton3, increment2)) // When taken form phone settings round. val title = getString(R.string.action_insulin)
editInsulin = PlusMinusEditText(view, R.id.amountfield, buttons, R.id.minusbutton, initValue, 0.0, maxBolus, 0.1, DecimalFormat("#0.0"), false) editInsulin = PlusMinusEditText(viewAdapter, initValue, 0.0, maxBolus, stepValues, DecimalFormat("#0.0"), false, title)
setLabelToPlusMinusView(view, getString(R.string.action_insulin)) val view = viewAdapter.root
container.addView(view) container.addView(view)
view.requestFocus() view.requestFocus()
} else { view
view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) }
else -> {
val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false)
val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton) val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton)
confirmButton.setOnClickListener { confirmButton.setOnClickListener {
rxBus.send(EventWearToMobile(ActionBolusPreCheck(SafeParse.stringToDouble(editInsulin?.editText?.text.toString()), 0))) rxBus.send(EventWearToMobile(ActionBolusPreCheck(SafeParse.stringToDouble(editInsulin?.editText?.text.toString()), 0)))
@ -58,8 +61,8 @@ class BolusActivity : ViewSelectorActivity() {
finishAffinity() finishAffinity()
} }
container.addView(view) container.addView(view)
view
} }
return view
} }
override fun destroyItem(container: ViewGroup, row: Int, col: Int, view: Any) { override fun destroyItem(container: ViewGroup, row: Int, col: Int, view: Any) {

View file

@ -10,6 +10,7 @@ import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventWearToMobile import info.nightscout.androidaps.events.EventWearToMobile
import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText import info.nightscout.androidaps.interaction.utils.PlusMinusEditText
import info.nightscout.shared.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.shared.weardata.EventData.ActionECarbsPreCheck import info.nightscout.shared.weardata.EventData.ActionECarbsPreCheck
@ -32,26 +33,28 @@ class CarbActivity : ViewSelectorActivity() {
val increment1 = sp.getInt(R.string.key_carbs_button_increment_1, 5).toDouble() val increment1 = sp.getInt(R.string.key_carbs_button_increment_1, 5).toDouble()
val increment2 = sp.getInt(R.string.key_carbs_button_increment_2, 10).toDouble() val increment2 = sp.getInt(R.string.key_carbs_button_increment_2, 10).toDouble()
val stepValues = listOf(1.0, increment1, increment2)
override fun getColumnCount(arg0: Int): Int = 2 override fun getColumnCount(arg0: Int): Int = 2
override fun getRowCount(): Int = 1 override fun getRowCount(): Int = 1
override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when (col) {
val view: View 0 -> {
if (col == 0) { val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true)
view = getInflatedPlusMinusView(container, true) val view = viewAdapter.root
var def = 0.0 var def = 0.0
if (editCarbs != null) { if (editCarbs != null) {
def = SafeParse.stringToDouble(editCarbs?.editText?.text.toString()) def = SafeParse.stringToDouble(editCarbs?.editText?.text.toString())
} }
val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48) val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48)
val buttons = listOf(Pair(R.id.plusbutton, 1.0), Pair(R.id.plusbutton2, increment1), Pair(R.id.plusbutton3, increment2)) editCarbs = PlusMinusEditText(viewAdapter, def, 0.0, maxCarbs.toDouble(), stepValues, DecimalFormat("0"), true, getString(R.string.action_carbs))
editCarbs = PlusMinusEditText(view, R.id.amountfield, buttons, R.id.minusbutton, def, 0.0, maxCarbs.toDouble(), 1.0, DecimalFormat("0"), true)
setLabelToPlusMinusView(view, getString(R.string.action_carbs))
container.addView(view) container.addView(view)
view.requestFocus() view.requestFocus()
} else { view
view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) }
else -> {
val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false)
val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton) val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton)
confirmButton.setOnClickListener { confirmButton.setOnClickListener {
// With start time 0 and duration 0 // With start time 0 and duration 0
@ -61,8 +64,8 @@ class CarbActivity : ViewSelectorActivity() {
finishAffinity() finishAffinity()
} }
container.addView(view) container.addView(view)
view
} }
return view
} }
override fun destroyItem(container: ViewGroup, row: Int, col: Int, view: Any) { override fun destroyItem(container: ViewGroup, row: Int, col: Int, view: Any) {

View file

@ -10,6 +10,7 @@ import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventWearToMobile import info.nightscout.androidaps.events.EventWearToMobile
import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText import info.nightscout.androidaps.interaction.utils.PlusMinusEditText
import info.nightscout.shared.SafeParse.stringToDouble import info.nightscout.shared.SafeParse.stringToDouble
import info.nightscout.shared.SafeParse.stringToInt import info.nightscout.shared.SafeParse.stringToInt
@ -36,44 +37,50 @@ class ECarbActivity : ViewSelectorActivity() {
override fun getColumnCount(arg0: Int): Int = 4 override fun getColumnCount(arg0: Int): Int = 4
override fun getRowCount(): Int = 1 override fun getRowCount(): Int = 1
private val increment1 = sp.getInt(R.string.key_carbs_button_increment_1, 5).toDouble() val increment1 = sp.getInt(R.string.key_carbs_button_increment_1, 5).toDouble()
private val increment2 = sp.getInt(R.string.key_carbs_button_increment_2, 10).toDouble() val increment2 = sp.getInt(R.string.key_carbs_button_increment_2, 10).toDouble()
val stepValues = listOf(1.0, increment1, increment2)
override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when (col) {
return if (col == 0) { 0 -> {
val view = getInflatedPlusMinusView(container, true) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true)
val view = viewAdapter.root
var def = 0.0 var def = 0.0
if (editCarbs != null) { if (editCarbs != null) {
def = stringToDouble(editCarbs?.editText?.text.toString()) def = stringToDouble(editCarbs?.editText?.text.toString())
} }
val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48) val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48)
val buttons = listOf(Pair(R.id.plusbutton, 1.0), Pair(R.id.plusbutton2, increment1), Pair(R.id.plusbutton3, increment2)) editCarbs = PlusMinusEditText(viewAdapter, def, 0.0, maxCarbs.toDouble(), stepValues, DecimalFormat("0"), true, getString(R.string.action_carbs))
editCarbs = PlusMinusEditText(view, R.id.amountfield, buttons, R.id.minusbutton, def, 0.0, maxCarbs.toDouble(), 1.0, DecimalFormat("0"), true)
setLabelToPlusMinusView(view, getString(R.string.action_carbs))
container.addView(view) container.addView(view)
view.requestFocus() view.requestFocus()
view view
} else if (col == 1) { }
val view = getInflatedPlusMinusView(container)
1 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root
var def = 0.0 var def = 0.0
if (editStartTime != null) { if (editStartTime != null) {
def = stringToDouble(editStartTime?.editText?.text.toString()) def = stringToDouble(editStartTime?.editText?.text.toString())
} }
editStartTime = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, -60.0, 300.0, 15.0, DecimalFormat("0"), false) editStartTime = PlusMinusEditText(viewAdapter, 15.0, def, -60.0, 300.0, DecimalFormat("0"), false, getString(R.string.action_start_min))
setLabelToPlusMinusView(view, getString(R.string.action_start_min))
container.addView(view) container.addView(view)
view view
} else if (col == 2) { }
val view = getInflatedPlusMinusView(container)
2 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root
var def = 0.0 var def = 0.0
if (editDuration != null) { if (editDuration != null) {
def = stringToDouble(editDuration?.editText?.text.toString()) def = stringToDouble(editDuration?.editText?.text.toString())
} }
editDuration = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0.0, 8.0, 1.0, DecimalFormat("0"), false) editDuration = PlusMinusEditText(viewAdapter, 1.0, def, 0.0, 8.0, DecimalFormat("0"), false, getString(R.string.action_duration_h))
setLabelToPlusMinusView(view, getString(R.string.action_duration_h))
container.addView(view) container.addView(view)
view view
} else { }
else -> {
val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false)
val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton) val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton)
confirmButton.setOnClickListener { confirmButton.setOnClickListener {
@ -102,4 +109,4 @@ class ECarbActivity : ViewSelectorActivity() {
override fun isViewFromObject(view: View, `object`: Any): Boolean = view === `object` override fun isViewFromObject(view: View, `object`: Any): Boolean = view === `object`
} }
} }

View file

@ -10,6 +10,7 @@ import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventWearToMobile import info.nightscout.androidaps.events.EventWearToMobile
import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText import info.nightscout.androidaps.interaction.utils.PlusMinusEditText
import info.nightscout.shared.SafeParse.stringToDouble import info.nightscout.shared.SafeParse.stringToDouble
import info.nightscout.shared.weardata.EventData.ActionFillPreCheck import info.nightscout.shared.weardata.EventData.ActionFillPreCheck
@ -33,19 +34,21 @@ class FillActivity : ViewSelectorActivity() {
override fun getColumnCount(arg0: Int): Int = 2 override fun getColumnCount(arg0: Int): Int = 2
override fun getRowCount(): Int = 1 override fun getRowCount(): Int = 1
override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when (col) {
return if (col == 0) { 0 -> {
val view = getInflatedPlusMinusView(container) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root
var def = 0.0 var def = 0.0
if (editInsulin != null) { if (editInsulin != null) {
def = stringToDouble(editInsulin?.editText?.text.toString()) def = stringToDouble(editInsulin?.editText?.text.toString())
} }
editInsulin = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0.0, 30.0, 0.1, DecimalFormat("#0.0"), false) editInsulin = PlusMinusEditText(viewAdapter, def, 0.0, 30.0, 0.1, DecimalFormat("#0.0"), false, getString(R.string.action_insulin))
setLabelToPlusMinusView(view, getString(R.string.action_insulin))
container.addView(view) container.addView(view)
view.requestFocus() view.requestFocus()
view view
} else { }
else -> {
val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false)
val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton) val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton)
confirmButton.setOnClickListener { confirmButton.setOnClickListener {
@ -68,4 +71,4 @@ class FillActivity : ViewSelectorActivity() {
override fun isViewFromObject(view: View, `object`: Any): Boolean = view === `object` override fun isViewFromObject(view: View, `object`: Any): Boolean = view === `object`
} }
} }

View file

@ -10,6 +10,7 @@ import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventWearToMobile import info.nightscout.androidaps.events.EventWearToMobile
import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText import info.nightscout.androidaps.interaction.utils.PlusMinusEditText
import info.nightscout.shared.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.shared.weardata.EventData.ActionProfileSwitchPreCheck import info.nightscout.shared.weardata.EventData.ActionProfileSwitchPreCheck
@ -43,29 +44,34 @@ class ProfileSwitchActivity : ViewSelectorActivity() {
override fun getColumnCount(arg0: Int): Int = 3 override fun getColumnCount(arg0: Int): Int = 3
override fun getRowCount(): Int = 1 override fun getRowCount(): Int = 1
override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when (col) {
return if (col == 0) { 0 -> {
val view = getInflatedPlusMinusView(container) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root
var def = timeshift.toDouble() var def = timeshift.toDouble()
if (editTimeshift != null) { if (editTimeshift != null) {
def = SafeParse.stringToDouble(editTimeshift?.editText?.text.toString()) def = SafeParse.stringToDouble(editTimeshift?.editText?.text.toString())
} }
editTimeshift = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0.0, 23.0, 1.0, DecimalFormat("0"), true, true) editTimeshift = PlusMinusEditText(viewAdapter, def, 0.0, 23.0, 1.0, DecimalFormat("0"), true, getString(R.string.action_timeshift), true)
setLabelToPlusMinusView(view, getString(R.string.action_timeshift))
container.addView(view) container.addView(view)
view.requestFocus() view.requestFocus()
view view
} else if (col == 1) { }
val view = getInflatedPlusMinusView(container)
1 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root
var def = percentage.toDouble() var def = percentage.toDouble()
if (editPercentage != null) { if (editPercentage != null) {
def = SafeParse.stringToDouble(editPercentage?.editText?.text.toString()) def = SafeParse.stringToDouble(editPercentage?.editText?.text.toString())
} }
editPercentage = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 30.0, 250.0, 1.0, DecimalFormat("0"), false) editPercentage = PlusMinusEditText(viewAdapter, def, 30.0, 250.0, 1.0, DecimalFormat("0"), false, getString(R.string.action_percentage))
setLabelToPlusMinusView(view, getString(R.string.action_percentage))
container.addView(view) container.addView(view)
view view
} else { }
else -> {
val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false)
val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton) val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton)
confirmButton.setOnClickListener { confirmButton.setOnClickListener {

View file

@ -10,6 +10,7 @@ import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventWearToMobile import info.nightscout.androidaps.events.EventWearToMobile
import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText import info.nightscout.androidaps.interaction.utils.PlusMinusEditText
import info.nightscout.shared.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.shared.weardata.EventData.ActionTempTargetPreCheck import info.nightscout.shared.weardata.EventData.ActionTempTargetPreCheck
@ -45,49 +46,56 @@ class TempTargetActivity : ViewSelectorActivity() {
return 1 return 1
} }
override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when {
return if (col == 0) { col == 0 -> {
val view = getInflatedPlusMinusView(container) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root
time = if (time == null) { time = if (time == null) {
PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 60.0, 0.0, 24 * 60.0, 5.0, DecimalFormat("0"), false) PlusMinusEditText(viewAdapter, 60.0, 0.0, 24 * 60.0, 5.0, DecimalFormat("0"), false, getString(R.string.action_duration))
} else { } else {
val def = SafeParse.stringToDouble(time?.editText?.text.toString()) val def = SafeParse.stringToDouble(time?.editText?.text.toString())
PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0.0, 24 * 60.0, 5.0, DecimalFormat("0"), false) PlusMinusEditText(viewAdapter, def, 0.0, 24 * 60.0, 5.0, DecimalFormat("0"), false, getString(R.string.action_duration))
} }
setLabelToPlusMinusView(view, getString(R.string.action_duration))
container.addView(view) container.addView(view)
view.requestFocus() view.requestFocus()
view view
} else if (col == 1) { }
val view = getInflatedPlusMinusView(container)
col == 1 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root
val title = if (isSingleTarget) getString(R.string.action_target) else getString(R.string.action_low)
if (isMGDL) { if (isMGDL) {
var def = 100.0 var def = 100.0
if (lowRange != null) def = SafeParse.stringToDouble(lowRange?.editText?.text.toString()) if (lowRange != null) def = SafeParse.stringToDouble(lowRange?.editText?.text.toString())
lowRange = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 72.0, 180.0, 1.0, DecimalFormat("0"), false) lowRange = PlusMinusEditText(viewAdapter, def, 72.0, 180.0, 1.0, DecimalFormat("0"), false, title)
} else { } else {
var def = 5.5 var def = 5.5
if (lowRange != null) def = SafeParse.stringToDouble(lowRange?.editText?.text.toString()) if (lowRange != null) def = SafeParse.stringToDouble(lowRange?.editText?.text.toString())
lowRange = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 4.0, 10.0, 0.1, DecimalFormat("#0.0"), false) lowRange = PlusMinusEditText(viewAdapter, def, 4.0, 10.0, 0.1, DecimalFormat("#0.0"), false, title)
} }
if (isSingleTarget) setLabelToPlusMinusView(view, getString(R.string.action_target))
else setLabelToPlusMinusView(view, getString(R.string.action_low))
container.addView(view) container.addView(view)
view view
} else if (col == 2 && !isSingleTarget) { }
val view = getInflatedPlusMinusView(container)
col == 2 && !isSingleTarget -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root
if (isMGDL) { if (isMGDL) {
var def = 100.0 var def = 100.0
if (highRange != null) def = SafeParse.stringToDouble(highRange?.editText?.text.toString()) if (highRange != null) def = SafeParse.stringToDouble(highRange?.editText?.text.toString())
highRange = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 72.0, 180.0, 1.0, DecimalFormat("0"), false) highRange = PlusMinusEditText(viewAdapter, def, 72.0, 180.0, 1.0, DecimalFormat("0"), false, getString(R.string.action_high))
} else { } else {
var def = 5.5 var def = 5.5
if (highRange != null) def = SafeParse.stringToDouble(highRange?.editText?.text.toString()) if (highRange != null) def = SafeParse.stringToDouble(highRange?.editText?.text.toString())
highRange = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 4.0, 10.0, 0.1, DecimalFormat("#0.0"), false) highRange = PlusMinusEditText(viewAdapter, def, 4.0, 10.0, 0.1, DecimalFormat("#0.0"), false, getString(R.string.action_high))
} }
setLabelToPlusMinusView(view, getString(R.string.action_high))
container.addView(view) container.addView(view)
view view
} else { }
else -> {
val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false)
val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton) val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton)
confirmButton.setOnClickListener { confirmButton.setOnClickListener {
@ -119,4 +127,4 @@ class TempTargetActivity : ViewSelectorActivity() {
return view === `object` return view === `object`
} }
} }
} }

View file

@ -10,6 +10,7 @@ import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventWearToMobile import info.nightscout.androidaps.events.EventWearToMobile
import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText import info.nightscout.androidaps.interaction.utils.PlusMinusEditText
import info.nightscout.shared.SafeParse.stringToDouble import info.nightscout.shared.SafeParse.stringToDouble
import info.nightscout.shared.SafeParse.stringToInt import info.nightscout.shared.SafeParse.stringToInt
@ -38,32 +39,37 @@ class TreatmentActivity : ViewSelectorActivity() {
val incrementInsulin1 = (sp.getDouble(R.string.key_insulin_button_increment_1, 0.5) * 10).roundToInt() / 10.0 val incrementInsulin1 = (sp.getDouble(R.string.key_insulin_button_increment_1, 0.5) * 10).roundToInt() / 10.0
val incrementInsulin2 = (sp.getDouble(R.string.key_insulin_button_increment_2, 1.0) * 10).roundToInt() / 10.0 val incrementInsulin2 = (sp.getDouble(R.string.key_insulin_button_increment_2, 1.0) * 10).roundToInt() / 10.0
val stepValuesInsulin = listOf(0.1, incrementInsulin1, incrementInsulin2)
val incrementCarbs1 = sp.getInt(R.string.key_carbs_button_increment_1, 5).toDouble() val incrementCarbs1 = sp.getInt(R.string.key_carbs_button_increment_1, 5).toDouble()
val incrementCarbs2 = sp.getInt(R.string.key_carbs_button_increment_2, 10).toDouble() val incrementCarbs2 = sp.getInt(R.string.key_carbs_button_increment_2, 10).toDouble()
val stepValuesCarbs = listOf(1.0, incrementCarbs1, incrementCarbs2)
override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when (col) {
return if (col == 0) { 0 -> {
val view = getInflatedPlusMinusView(container, true) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true)
val view = viewAdapter.root
var def = 0.0 var def = 0.0
if (editInsulin != null) def = stringToDouble(editInsulin?.editText?.text.toString()) if (editInsulin != null) def = stringToDouble(editInsulin?.editText?.text.toString())
val maxBolus = sp.getDouble(getString(R.string.key_treatments_safety_max_bolus), 3.0) val maxBolus = sp.getDouble(getString(R.string.key_treatments_safety_max_bolus), 3.0)
val buttons = listOf(Pair(R.id.plusbutton, 0.1), Pair(R.id.plusbutton2, incrementInsulin1), Pair(R.id.plusbutton3, incrementInsulin2)) editInsulin = PlusMinusEditText(viewAdapter, def, 0.0, maxBolus, stepValuesInsulin, DecimalFormat("#0.0"), false, getString(R.string.action_insulin))
editInsulin = PlusMinusEditText(view, R.id.amountfield, buttons, R.id.minusbutton, def, 0.0, maxBolus, 0.1, DecimalFormat("#0.0"), false)
setLabelToPlusMinusView(view, getString(R.string.action_insulin))
container.addView(view) container.addView(view)
view.requestFocus() view.requestFocus()
view view
} else if (col == 1) { }
val view = getInflatedPlusMinusView(container, true)
1 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true)
val view = viewAdapter.root
var def = 0.0 var def = 0.0
val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48) val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48)
if (editCarbs != null) def = stringToDouble(editCarbs?.editText?.text.toString()) if (editCarbs != null) def = stringToDouble(editCarbs?.editText?.text.toString())
val buttons = listOf(Pair(R.id.plusbutton, 1.0), Pair(R.id.plusbutton2, incrementCarbs1), Pair(R.id.plusbutton3, incrementCarbs2))
editCarbs = PlusMinusEditText(view, R.id.amountfield, buttons, R.id.minusbutton, def, 0.0, maxCarbs.toDouble(), 1.0, DecimalFormat("0"), false) editCarbs = PlusMinusEditText(viewAdapter, def, 0.0, maxCarbs.toDouble(), stepValuesCarbs, DecimalFormat("0"), false, getString(R.string.action_carbs))
setLabelToPlusMinusView(view, getString(R.string.action_carbs))
container.addView(view) container.addView(view)
view view
} else { }
else -> {
val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false)
val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton) val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton)
confirmButton.setOnClickListener { confirmButton.setOnClickListener {

View file

@ -73,22 +73,6 @@ open class ViewSelectorActivity : DaggerActivity() {
} }
} }
fun getInflatedPlusMinusView(container: ViewGroup?, mulitple: Boolean = false): View {
val layoutRight = if (mulitple) R.layout.action_editplusminus_item_quickrighty_plus else R.layout.action_editplusminus_item_quickrighty
val layoutLeft = if (mulitple) R.layout.action_editplusminus_item_quicklefty_plus else R.layout.action_editplusminus_item_quicklefty
return when (sp.getInt(R.string.key_input_design, 1)) {
2 -> LayoutInflater.from(applicationContext).inflate(layoutRight, container, false)
3 -> LayoutInflater.from(applicationContext).inflate(layoutLeft, container, false)
4 -> LayoutInflater.from(applicationContext).inflate(R.layout.action_editplusminus_item_viktoria, container, false)
else -> LayoutInflater.from(applicationContext).inflate(R.layout.action_editplusminus_item, container, false)
}
}
fun setLabelToPlusMinusView(view: View, labelText: String?) {
val textView = view.findViewById<TextView>(R.id.label)
textView.text = labelText
}
fun showToast(context: Context?, text: Int) { fun showToast(context: Context?, text: Int) {
Toast.makeText(context, getString(text), Toast.LENGTH_LONG).show() Toast.makeText(context, getString(text), Toast.LENGTH_LONG).show()
} }

View file

@ -10,6 +10,7 @@ import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventWearToMobile import info.nightscout.androidaps.events.EventWearToMobile
import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText import info.nightscout.androidaps.interaction.utils.PlusMinusEditText
import info.nightscout.shared.SafeParse import info.nightscout.shared.SafeParse
import info.nightscout.shared.weardata.EventData.ActionWizardPreCheck import info.nightscout.shared.weardata.EventData.ActionWizardPreCheck
@ -37,35 +38,39 @@ class WizardActivity : ViewSelectorActivity() {
override fun getRowCount(): Int = 1 override fun getRowCount(): Int = 1
private val increment1 = sp.getInt(R.string.key_carbs_button_increment_1, 5).toDouble() private val increment1 = sp.getInt(R.string.key_carbs_button_increment_1, 5).toDouble()
private val increment2 = sp.getInt(R.string.key_carbs_button_increment_2, 10).toDouble() private val increment2 = sp.getInt(R.string.key_carbs_button_increment_2, 10).toDouble()
val stepValues = listOf(1.0, increment1, increment2)
override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when {
return if (col == 0) { col == 0 -> {
val view = getInflatedPlusMinusView(container, true) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true)
val view = viewAdapter.root
val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48) val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48)
val buttons = listOf(Pair(R.id.plusbutton, 1.0), Pair(R.id.plusbutton2, increment1), Pair(R.id.plusbutton3, increment2))
editCarbs = if (editCarbs == null) { editCarbs = if (editCarbs == null) {
PlusMinusEditText(view, R.id.amountfield, buttons, R.id.minusbutton, 0.0, 0.0, maxCarbs.toDouble(), 1.0, DecimalFormat("0"), false) PlusMinusEditText(viewAdapter, 0.0, 0.0, maxCarbs.toDouble(), stepValues, DecimalFormat("0"), false, getString(R.string.action_carbs))
} else { } else {
val def = SafeParse.stringToDouble(editCarbs?.editText?.text.toString()) val def = SafeParse.stringToDouble(editCarbs?.editText?.text.toString())
PlusMinusEditText(view, R.id.amountfield, buttons, R.id.minusbutton, def, 0.0, maxCarbs.toDouble(), 1.0, DecimalFormat("0"), false) PlusMinusEditText(viewAdapter, def, 0.0, maxCarbs.toDouble(), 1.0, DecimalFormat("0"), false, getString(R.string.action_carbs))
} }
setLabelToPlusMinusView(view, getString(R.string.action_carbs))
container.addView(view) container.addView(view)
view.requestFocus() view.requestFocus()
view view
} else if (col == 1 && hasPercentage) { }
val view = getInflatedPlusMinusView(container)
col == 1 && hasPercentage -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root
val percentage = sp.getInt(getString(R.string.key_bolus_wizard_percentage), 100) val percentage = sp.getInt(getString(R.string.key_bolus_wizard_percentage), 100)
editPercentage = if (editPercentage == null) { editPercentage = if (editPercentage == null) {
PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, percentage.toDouble(), 50.0, 150.0, 1.0, DecimalFormat("0"), false) PlusMinusEditText(viewAdapter, percentage.toDouble(), 50.0, 150.0, 1.0, DecimalFormat("0"), false, getString(R.string.action_percentage))
} else { } else {
val def = SafeParse.stringToDouble(editPercentage?.editText?.text.toString()) val def = SafeParse.stringToDouble(editPercentage?.editText?.text.toString())
PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 50.0, 150.0, 1.0, DecimalFormat("0"), false) PlusMinusEditText(viewAdapter, def, 50.0, 150.0, 1.0, DecimalFormat("0"), false, getString(R.string.action_percentage))
} }
setLabelToPlusMinusView(view, getString(R.string.action_percentage))
container.addView(view) container.addView(view)
view view
} else { }
else -> {
val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false)
view.findViewById<ImageView>(R.id.confirmbutton) view.findViewById<ImageView>(R.id.confirmbutton)
.setOnClickListener { .setOnClickListener {

View file

@ -2,10 +2,10 @@ package info.nightscout.androidaps.interaction.utils
import android.content.Context import android.content.Context
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.databinding.ActionEditplusminusItemBinding import info.nightscout.androidaps.databinding.ActionEditplusminusItemBinding
import info.nightscout.androidaps.databinding.ActionEditplusminusItemPlusBinding
import info.nightscout.androidaps.databinding.ActionEditplusminusItemQuickleftyPlusBinding import info.nightscout.androidaps.databinding.ActionEditplusminusItemQuickleftyPlusBinding
import info.nightscout.androidaps.databinding.ActionEditplusminusItemQuickleftyBinding import info.nightscout.androidaps.databinding.ActionEditplusminusItemQuickleftyBinding
import info.nightscout.androidaps.databinding.ActionEditplusminusItemQuickrightyBinding import info.nightscout.androidaps.databinding.ActionEditplusminusItemQuickrightyBinding
@ -14,65 +14,84 @@ import info.nightscout.androidaps.databinding.ActionEditplusminusItemViktoriaBin
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
/** /**
* NumberPickerViewAdapter binds both NumberPickerLayoutBinding and NumberPickerLayoutVerticalBinding shared attributes to one common view adapter. * EditPlusMinusViewAdapter binds both ActionEditplusminusItemBinding variants shared attributes to one common view adapter.
* Requires at least one of the ViewBinding as a parameter. Recommended to use the factory object to create the binding. * Requires at least one of the ViewBinding as a parameter. Recommended to use the factory object to create the binding.
*/ */
class EditPlusMinusViewAdapter( class EditPlusMinusViewAdapter(
val eS: ActionEditplusminusItemBinding?, eD: ActionEditplusminusItemBinding?,
val eQLP: ActionEditplusminusItemQuickleftyPlusBinding?, eDP: ActionEditplusminusItemPlusBinding?,
val eQL: ActionEditplusminusItemQuickleftyBinding?, eQL: ActionEditplusminusItemQuickleftyBinding?,
val eQRP: ActionEditplusminusItemQuickleftyPlusBinding?, eQLP: ActionEditplusminusItemQuickleftyPlusBinding?,
val qQR: ActionEditplusminusItemQuickrightyBinding?, eQR: ActionEditplusminusItemQuickrightyBinding?,
val nQRP: ActionEditplusminusItemQuickrightyPlusBinding?, eQRP: ActionEditplusminusItemQuickrightyPlusBinding?,
val eV: ActionEditplusminusItemViktoriaBinding? eV: ActionEditplusminusItemViktoriaBinding?
) { ) {
init { init {
if (eS == null && eQLP == null && eQL == null && eQRP == null && qQR == null && nQRP == null && eV == null) { if (eD == null && eDP == null && eQL == null && eQLP == null && eQR == null && eQRP == null && eV == null) {
throw IllegalArgumentException("Require at least on Binding parameter") throw IllegalArgumentException("Require at least on Binding parameter")
} }
} }
val amountField = val editText =
eS?.amountfield ?: eQLP?.amountfield ?: eQL?.amountfield ?: eQRP?.amountfield ?: qQR?.amountfield ?: nQRP?.amountfield ?: eV?.amountfield eD?.editText ?: eDP?.editText ?: eQL?.editText ?: eQLP?.editText ?: eQR?.editText ?: eQRP?.editText ?: eV?.editText
?: throw IllegalArgumentException("Missing require View Binding parameter display") ?: throw IllegalArgumentException("Missing require View Binding parameter display")
val minusButton = val minusButton =
eS?.minusbutton ?: eQLP?.minusbutton ?: eQL?.minusbutton ?: eQRP?.minusbutton ?: qQR?.minusbutton ?: nQRP?.minusbutton ?: eV?.minusbutton eD?.minusButton ?: eDP?.minusButton ?: eQL?.minusButton ?: eQLP?.minusButton ?: eQR?.minusButton ?: eQRP?.minusButton ?: eV?.minusButton
?: throw IllegalArgumentException("Missing require View Binding parameter display") ?: throw IllegalArgumentException("Missing require View Binding parameter display")
val plusButton = val plusButton1 =
eS?.plusbutton ?: eQLP?.plusbutton ?: eQL?.plusbutton ?: eQRP?.plusbutton ?: qQR?.plusbutton ?: nQRP?.plusbutton ?: eV?.plusbutton eD?.plusButton1 ?: eDP?.plusButton1 ?: eQL?.plusButton1 ?: eQLP?.plusButton1 ?: eQR?.plusButton1 ?: eQRP?.plusButton1 ?: eV?.plusButton1
?: throw IllegalArgumentException("Missing require View Binding parameter display") ?: throw IllegalArgumentException("Missing require View Binding parameter display")
val label = val label =
eS?.label ?: eQLP?.label ?: eQL?.label ?: eQRP?.label ?: qQR?.label ?: nQRP?.label ?: eV?.label eD?.label ?: eDP?.label ?: eQL?.label ?: eQLP?.label ?: eQR?.label ?: eQRP?.label ?: eV?.label
?: throw IllegalArgumentException("Missing require View Binding parameter display") ?: throw IllegalArgumentException("Missing require View Binding parameter display")
val plusButton2 = eQLP?.plusbutton2 ?: eQRP?.plusbutton2 val plusButton2 = eDP?.plusButton2 ?: eQLP?.plusButton2 ?: eQRP?.plusButton2
val plusButton3 = eQLP?.plusbutton3 ?: eQRP?.plusbutton3 val plusButton3 = eDP?.plusButton3 ?: eQLP?.plusButton3 ?: eQRP?.plusButton3
val root = val root =
eS?.root ?: eQLP?.root ?: eQL?.root ?: eQRP?.root ?: qQR?.root ?: nQRP?.root ?: eV?.root eD?.root ?: eDP?.root ?: eQL?.root ?: eQLP?.root ?: eQR?.root ?: eQRP?.root ?: eV?.root
?: throw IllegalArgumentException("Missing require View Binding parameter display") ?: throw IllegalArgumentException("Missing require View Binding parameter display")
companion object { companion object {
fun getInflatedPlusMinusView(sp: SP, context: Context, container: ViewGroup?, mulitple: Boolean = false): EditPlusMinusViewAdapter { fun getViewAdapter(sp: SP, context: Context, container: ViewGroup?, multiple: Boolean = false): EditPlusMinusViewAdapter {
val inflater = LayoutInflater.from(context) val inflater = LayoutInflater.from(context)
val bindLayout = ActionEditplusminusItemBinding.inflate(inflater, container, false)
val binding = EditPlusMinusViewAdapter(bindLayout, null, null, null, null, null, null) return when (sp.getInt(R.string.key_input_design, 1)) {
return binding 2 -> {
// val layoutRight = if (mulitple) R.layout.action_editplusminus_item_quickrighty_plus else R.layout.action_editplusminus_item_quickrighty if (multiple) {
// val layoutLeft = if (mulitple) R.layout.action_editplusminus_item_quicklefty_plus else R.layout.action_editplusminus_item_quicklefty val bindLayout = ActionEditplusminusItemQuickrightyPlusBinding.inflate(inflater, container, false)
// return when (sp.getInt(R.string.key_input_design, 1)) { EditPlusMinusViewAdapter(null, null, null, null, null, bindLayout, null)
// 2 -> LayoutInflater.from(applicationContext).inflate(layoutRight, container, false) } else {
// 3 -> LayoutInflater.from(applicationContext).inflate(layoutLeft, container, false) val bindLayout = ActionEditplusminusItemQuickrightyBinding.inflate(inflater, container, false)
// 4 -> LayoutInflater.from(applicationContext).inflate(R.layout.action_editplusminus_item_viktoria, container, false) EditPlusMinusViewAdapter(null, null, null, null, bindLayout, null, null)
// else -> LayoutInflater.from(applicationContext).inflate(R.layout.action_editplusminus_item, container, false) }
// } }
3 -> {
if (multiple) {
val bindLayout = ActionEditplusminusItemQuickleftyPlusBinding.inflate(inflater, container, false)
EditPlusMinusViewAdapter(null, null, null, bindLayout, null, null, null)
} else {
val bindLayout = ActionEditplusminusItemQuickleftyBinding.inflate(inflater, container, false)
EditPlusMinusViewAdapter(null, null, bindLayout, null, null, null, null)
}
}
4 -> {
val bindLayout = ActionEditplusminusItemViktoriaBinding.inflate(inflater, container, false)
EditPlusMinusViewAdapter(null, null, null, null, null, null, bindLayout)
}
else -> {
if (multiple) {
val bindLayout = ActionEditplusminusItemPlusBinding.inflate(inflater, container, false)
EditPlusMinusViewAdapter(null, bindLayout, null, null, null, null, null)
} else {
val bindLayout = ActionEditplusminusItemBinding.inflate(inflater, container, false)
EditPlusMinusViewAdapter(bindLayout, null, null, null, null, null, null)
}
}
}
} }
// fun getBinding(bindLayout: NumberPickerLayoutBinding): NumberPickerViewAdapter {
// return NumberPickerViewAdapter(bindLayout, null)
// }
//
// fun getBinding(bindLayout: NumberPickerLayoutVerticalBinding): NumberPickerViewAdapter {
// return NumberPickerViewAdapter(null, bindLayout)
// }
} }
} }

View file

@ -9,7 +9,6 @@ import android.view.View
import android.view.View.OnGenericMotionListener import android.view.View.OnGenericMotionListener
import android.view.View.OnTouchListener import android.view.View.OnTouchListener
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.widget.AppCompatButton
import androidx.core.view.InputDeviceCompat import androidx.core.view.InputDeviceCompat
import androidx.core.view.MotionEventCompat import androidx.core.view.MotionEventCompat
import java.text.DecimalFormat import java.text.DecimalFormat
@ -17,47 +16,38 @@ import java.text.NumberFormat
import java.util.concurrent.Executors import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlin.Pair
/** /**
* Created by mike on 28.06.2016. * Created by mike on 28.06.2016.
*/ */
@SuppressLint("SetTextI18n") class PlusMinusEditText @JvmOverloads constructor( @SuppressLint("SetTextI18n") class PlusMinusEditText @JvmOverloads constructor(
view: View, private val binding: EditPlusMinusViewAdapter,
editTextID: Int,
private var plusButtons: List<Pair<Int, Double>>,
minusID: Int,
initValue: Double, initValue: Double,
private val minValue: Double, private val minValue: Double,
private val maxValue: Double, private val maxValue: Double,
private val stepGeneral: Double, private val stepValues: List<Double>,
private val formatter: NumberFormat, private val formatter: NumberFormat,
private val allowZero: Boolean, private val allowZero: Boolean,
label: String,
private val roundRobin: Boolean = false, private val roundRobin: Boolean = false,
) : View.OnKeyListener, OnTouchListener, View.OnClickListener, OnGenericMotionListener { ) : View.OnKeyListener, OnTouchListener, View.OnClickListener, OnGenericMotionListener {
constructor( constructor(
view: View, binding: EditPlusMinusViewAdapter,
editTextID: Int,
plusID: Int,
minusID: Int,
initValue: Double, initValue: Double,
minValue: Double, minValue: Double,
maxValue: Double, maxValue: Double,
stepGeneral: Double, step: Double,
formatter: NumberFormat, formatter: NumberFormat,
allowZero: Boolean, allowZero: Boolean,
label: String,
roundRobin: Boolean = false roundRobin: Boolean = false
) : this(view, editTextID, listOf(Pair(plusID, stepGeneral)), minusID, initValue, minValue, maxValue, stepGeneral, formatter, allowZero, roundRobin) ) : this(binding, initValue, minValue, maxValue, listOf(step), formatter, allowZero, label, roundRobin)
private val stepGeneral: Double = stepValues[0]
var editText: TextView var editText: TextView
private set private set
private var minusImage: View
private var plusImage1: View
private var plusImage2: AppCompatButton? = null
private var plusImage3: AppCompatButton? = null
private var value: Double private var value: Double
private val context: Context
private var mChangeCounter = 0 private var mChangeCounter = 0
private var mLastChange: Long = 0 private var mLastChange: Long = 0
private val mHandler: Handler private val mHandler: Handler
@ -70,11 +60,11 @@ import kotlin.Pair
override fun run() { override fun run() {
val msg = Message() val msg = Message()
val doubleLimit = 5 val doubleLimit = 5
val multipleButtons = mInc && (plusImage2 != null || plusImage3 != null) val multipleButtons = mInc && (binding.plusButton2 != null || binding.plusButton3 != null)
if (!multipleButtons && repeated % doubleLimit == 0) multiplier *= 2 if (!multipleButtons && repeated % doubleLimit == 0) multiplier *= 2
val bundle = Bundle() val bundle = Bundle()
bundle.putDouble("step", step) bundle.putDouble(STEP, step)
bundle.putInt("multiplier", multiplier) bundle.putInt(MULTIPLIER, multiplier)
msg.data = bundle msg.data = bundle
if (mInc) { if (mInc) {
@ -114,14 +104,14 @@ import kotlin.Pair
if (vibrate) vibrateDevice() if (vibrate) vibrateDevice()
} }
fun vibrateDevice() { private fun vibrateDevice() {
val vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { val vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val vibratorManager = val vibratorManager =
context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager binding.root.context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
vibratorManager.defaultVibrator vibratorManager.defaultVibrator
} else { } else {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator binding.root.context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@ -155,19 +145,19 @@ import kotlin.Pair
private fun getStep(v: View): Double { private fun getStep(v: View): Double {
return when (v) { return when (v) {
plusImage1 -> plusButtons[0].second binding.plusButton1 -> stepValues[0]
plusImage2 -> plusButtons[1].second binding.plusButton2 -> stepValues[1]
plusImage3 -> plusButtons[2].second binding.plusButton3 -> stepValues[2]
else -> stepGeneral else -> stepValues[0]
} }
} }
private fun isIncrement(v: View): Boolean { private fun isIncrement(v: View): Boolean {
return when (v) { return when (v) {
plusImage1 -> true binding.plusButton1 -> true
plusImage2 -> true binding.plusButton2 -> true
plusImage3 -> true binding.plusButton3 -> true
else -> false else -> false
} }
} }
@ -229,30 +219,22 @@ import kotlin.Pair
private const val THRESHOLD_TIME = 100 private const val THRESHOLD_TIME = 100
private const val MSG_INC = 0 private const val MSG_INC = 0
private const val MSG_DEC = 1 private const val MSG_DEC = 1
private const val STEP = "step"
private const val MULTIPLIER = "multiplier"
} }
init { init {
context = view.context editText = binding.editText
editText = view.findViewById(editTextID) binding.label.text = label
minusImage = view.findViewById(minusID)
plusImage1 = view.findViewById(plusButtons.first().first)
val format = DecimalFormat("#.#") val format = DecimalFormat("#.#")
plusButtons.getOrNull(1)?.let { binding.plusButton2?.text = "+${format.format(stepValues[1]).replaceFirst("^0+(?!$)".toRegex(), "")}"
plusImage2 = view.findViewById(it.first) binding.plusButton3?.text = "+${format.format(stepValues[2]).replaceFirst("^0+(?!$)".toRegex(), "")}"
plusImage2?.text = "+${format.format(it.second).replaceFirst("^0+(?!$)".toRegex(), "")}"
plusImage2?.visibility = View.VISIBLE
}
plusButtons.getOrNull(2)?.let {
plusImage3 = view.findViewById(it.first)
plusImage3?.text = "+${format.format(it.second).replaceFirst("^0+(?!$)".toRegex(), "")}"
plusImage3?.visibility = View.VISIBLE
}
value = initValue value = initValue
mHandler = object : Handler(Looper.getMainLooper()) { mHandler = object : Handler(Looper.getMainLooper()) {
override fun handleMessage(msg: Message) { override fun handleMessage(msg: Message) {
val multiplier = msg.data.getInt("multiplier") val multiplier = msg.data.getInt(MULTIPLIER)
val step = msg.data.getDouble("step") val step = msg.data.getDouble(STEP)
when (msg.what) { when (msg.what) {
MSG_INC -> { MSG_INC -> {
@ -271,18 +253,18 @@ import kotlin.Pair
editText.showSoftInputOnFocus = false editText.showSoftInputOnFocus = false
editText.setTextIsSelectable(false) editText.setTextIsSelectable(false)
minusImage.setOnTouchListener(this) binding.minusButton.setOnTouchListener(this)
minusImage.setOnKeyListener(this) binding.minusButton.setOnKeyListener(this)
minusImage.setOnClickListener(this) binding.minusButton.setOnClickListener(this)
plusImage1.setOnTouchListener(this) binding.plusButton1.setOnTouchListener(this)
plusImage1.setOnKeyListener(this) binding.plusButton1.setOnKeyListener(this)
plusImage1.setOnClickListener(this) binding.plusButton1.setOnClickListener(this)
plusImage2?.setOnTouchListener(this) binding.plusButton2?.setOnTouchListener(this)
plusImage2?.setOnKeyListener(this) binding.plusButton2?.setOnKeyListener(this)
plusImage2?.setOnClickListener(this) binding.plusButton2?.setOnClickListener(this)
plusImage3?.setOnTouchListener(this) binding.plusButton3?.setOnTouchListener(this)
plusImage3?.setOnKeyListener(this) binding.plusButton3?.setOnKeyListener(this)
plusImage3?.setOnClickListener(this) binding.plusButton3?.setOnClickListener(this)
editText.setOnGenericMotionListener(this) editText.setOnGenericMotionListener(this)
updateEditText() updateEditText()
} }

View file

@ -1,67 +1,131 @@
<?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="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatImageButton <View
android:id="@+id/minusbutton" android:id="@+id/center"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="-10dp"
android:layout_marginHorizontal="10dp"
android:cursorVisible="false"
android:inputType="numberDecimal"
android:textColor="@color/white"
android:textSize="40sp"
android:gravity="center"
app:layout_constraintEnd_toEndOf="@+id/value_background"
app:layout_constraintStart_toStartOf="@+id/value_background"
app:layout_constraintTop_toTopOf="@+id/value_background"
tools:text="123" />
<TextView
android:id="@+id/label"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_marginTop="-8dp"
android:layout_below="@+id/edit_text"
android:gravity="center"
android:labelFor="@+id/edit_text"
android:textColor="@color/white"
android:textSize="25sp"
app:layout_constraintEnd_toEndOf="@+id/edit_text"
app:layout_constraintStart_toStartOf="@+id/edit_text"
app:layout_constraintTop_toBottomOf="@id/edit_text"
tools:ignore="LabelFor"
tools:text="label" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/minus_button"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/circle" android:background="@drawable/circle"
android:backgroundTint="@color/white" android:backgroundTint="@color/white"
android:contentDescription="@string/decrement" android:contentDescription="@string/decrement"
android:src="@drawable/ic_action_minus" android:src="@drawable/ic_action_minus"
android:tint="@color/white" /> android:tint="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintCircle="@+id/center"
app:layout_constraintCircleAngle="145"
app:layout_constraintCircleRadius="70dp"
app:layout_constraintLeft_toLeftOf="parent" />
<LinearLayout <androidx.appcompat.widget.AppCompatButton
android:layout_width="wrap_content" android:id="@+id/plus_button3"
android:layout_height="wrap_content" android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/circle"
android:backgroundTint="@color/white"
android:gravity="center"
android:textColor="@color/white"
android:textSize="25sp"
android:visibility="visible"
app:layout_constraintCircle="@+id/center"
app:layout_constraintCircleAngle="325"
app:layout_constraintCircleRadius="70dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="+10" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/plus_button2"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/circle"
android:backgroundTint="@color/white"
android:gravity="center"
android:textColor="@color/white"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/plus_button1"
app:layout_constraintCircle="@+id/center"
app:layout_constraintCircleAngle="270"
app:layout_constraintCircleRadius="70dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/plus_button3"
tools:text="+5" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/value_background"
android:layout_width="108dp"
android:layout_height="108dp"
android:layout_gravity="center" android:layout_gravity="center"
android:orientation="vertical"> android:layout_marginBottom="8dp"
android:background="@drawable/circle"
android:backgroundTint="@color/gray_700"
android:contentDescription="@string/increment"
app:layout_constraintBottom_toTopOf="@+id/minus_button"
app:layout_constraintCircle="@+id/center"
app:layout_constraintCircleAngle="55"
app:layout_constraintCircleRadius="40dp"
app:layout_constraintRight_toLeftOf="@id/plus_button1">
<EditText </androidx.appcompat.widget.AppCompatImageView>
android:id="@+id/amountfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:cursorVisible="false"
android:gravity="center_horizontal"
android:inputType="numberDecimal"
android:minWidth="50dp"
android:padding="10dp"
android:textColor="@color/white"
android:textSize="45sp"
tools:text="112" />
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:labelFor="@+id/amountfield"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white"
android:textSize="25sp"
tools:ignore="LabelFor"
tools:text="label" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatImageButton <androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/plusbutton" android:id="@+id/plus_button1"
android:layout_width="wrap_content" android:layout_width="48dp"
android:layout_height="wrap_content" android:layout_height="48dp"
android:layout_gravity="center" android:layout_gravity="center"
android:background="@drawable/circle" android:background="@drawable/circle"
android:backgroundTint="@color/white" android:backgroundTint="@color/white"
android:contentDescription="@string/increment" android:contentDescription="@string/increment"
android:src="@drawable/ic_action_add" android:src="@drawable/ic_action_add"
android:tint="@color/white" /> android:tint="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintCircle="@+id/center"
app:layout_constraintCircleAngle="215"
app:layout_constraintCircleRadius="70dp"
app:layout_constraintRight_toRightOf="parent" />
</LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent">
<View
android:id="@+id/center"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="-6dp"
android:layout_marginHorizontal="10dp"
android:cursorVisible="false"
android:inputType="numberDecimal"
android:textColor="@color/white"
android:textSize="40sp"
android:gravity="center"
app:layout_constraintEnd_toEndOf="@+id/value_background"
app:layout_constraintStart_toStartOf="@+id/value_background"
app:layout_constraintTop_toTopOf="@+id/value_background"
tools:text="123" />
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-10dp"
android:layout_below="@+id/edit_text"
android:gravity="center"
android:labelFor="@+id/edit_text"
android:textColor="@color/white"
android:textSize="25sp"
app:layout_constraintEnd_toEndOf="@+id/edit_text"
app:layout_constraintStart_toStartOf="@+id/edit_text"
app:layout_constraintTop_toBottomOf="@id/edit_text"
tools:ignore="LabelFor"
tools:text="label" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/minus_button"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/circle"
android:backgroundTint="@color/white"
android:contentDescription="@string/decrement"
android:src="@drawable/ic_action_minus"
android:tint="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintCircle="@+id/center"
app:layout_constraintCircleAngle="215"
app:layout_constraintCircleRadius="70dp"
app:layout_constraintLeft_toLeftOf="parent" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/plus_button3"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/circle"
android:backgroundTint="@color/white"
android:gravity="center"
android:textColor="@color/white"
android:textSize="25sp"
android:visibility="visible"
app:layout_constraintCircle="@+id/center"
app:layout_constraintCircleAngle="325"
app:layout_constraintCircleRadius="70dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="+10" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/plus_button2"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/circle"
android:backgroundTint="@color/white"
android:gravity="center"
android:textColor="@color/white"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/plus_button1"
app:layout_constraintCircle="@+id/center"
app:layout_constraintCircleAngle="35"
app:layout_constraintCircleRadius="70dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/plus_button3"
tools:text="+5" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/value_background"
android:layout_width="108dp"
android:layout_height="108dp"
android:layout_gravity="center"
android:backgroundTint="@color/gray_700"
android:contentDescription="@string/increment"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/plus_button1"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:background="@drawable/circle"
android:backgroundTint="@color/white"
android:contentDescription="@string/increment"
android:src="@drawable/ic_action_add"
android:tint="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintCircle="@+id/center"
app:layout_constraintCircleAngle="145"
app:layout_constraintCircleRadius="70dp"
app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -14,38 +14,11 @@
android:layout_marginEnd="-8dp" android:layout_marginEnd="-8dp"
android:orientation="vertical"> android:orientation="vertical">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/plusbutton3"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:background="@drawable/circle"
android:backgroundTint="@color/white"
android:gravity="center"
android:textColor="@color/white"
android:textSize="25sp"
android:visibility="gone"
tools:text="+10" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/plusbutton2"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="start"
android:layout_marginVertical="7dp"
android:background="@drawable/circle"
android:backgroundTint="@color/white"
android:gravity="center"
android:textColor="@color/white"
android:textSize="25sp"
android:visibility="gone"
tools:text="+5" />
<androidx.appcompat.widget.AppCompatImageButton <androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/plusbutton" android:id="@+id/plus_button1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end" android:layout_gravity="center"
android:background="@drawable/circle" android:background="@drawable/circle"
android:backgroundTint="@color/white" android:backgroundTint="@color/white"
android:contentDescription="@string/increment" android:contentDescription="@string/increment"
@ -62,7 +35,7 @@
android:orientation="vertical"> android:orientation="vertical">
<EditText <EditText
android:id="@+id/amountfield" android:id="@+id/edit_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
@ -81,7 +54,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:gravity="center" android:gravity="center"
android:labelFor="@+id/amountfield" android:labelFor="@+id/edit_text"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="25sp" android:textSize="25sp"
@ -89,7 +62,7 @@
tools:text="label" /> tools:text="label" />
<androidx.appcompat.widget.AppCompatImageButton <androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/minusbutton" android:id="@+id/minus_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"

View file

@ -15,16 +15,16 @@
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<EditText <EditText
android:id="@+id/amountfield" android:id="@+id/edit_text"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="-10dp"
android:layout_marginHorizontal="10dp" android:layout_marginHorizontal="10dp"
android:layout_marginTop="-10dp"
android:cursorVisible="false" android:cursorVisible="false"
android:gravity="center"
android:inputType="numberDecimal" android:inputType="numberDecimal"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="40sp" android:textSize="40sp"
android:gravity="center"
app:layout_constraintEnd_toEndOf="@+id/value_background" app:layout_constraintEnd_toEndOf="@+id/value_background"
app:layout_constraintStart_toStartOf="@+id/value_background" app:layout_constraintStart_toStartOf="@+id/value_background"
app:layout_constraintTop_toTopOf="@+id/value_background" app:layout_constraintTop_toTopOf="@+id/value_background"
@ -34,20 +34,20 @@
android:id="@+id/label" android:id="@+id/label"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/edit_text"
android:layout_marginTop="-8dp" android:layout_marginTop="-8dp"
android:layout_below="@+id/amountfield"
android:gravity="center" android:gravity="center"
android:labelFor="@+id/amountfield" android:labelFor="@+id/edit_text"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="25sp" android:textSize="25sp"
app:layout_constraintEnd_toEndOf="@+id/amountfield" app:layout_constraintEnd_toEndOf="@+id/edit_text"
app:layout_constraintStart_toStartOf="@+id/amountfield" app:layout_constraintStart_toStartOf="@+id/edit_text"
app:layout_constraintTop_toBottomOf="@id/amountfield" app:layout_constraintTop_toBottomOf="@id/edit_text"
tools:ignore="LabelFor" tools:ignore="LabelFor"
tools:text="label" /> tools:text="label" />
<androidx.appcompat.widget.AppCompatImageButton <androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/minusbutton" android:id="@+id/minus_button"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:background="@drawable/circle" android:background="@drawable/circle"
@ -58,11 +58,11 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintCircle="@+id/center" app:layout_constraintCircle="@+id/center"
app:layout_constraintCircleAngle="145" app:layout_constraintCircleAngle="145"
app:layout_constraintCircleRadius="70dp" app:layout_constraintCircleRadius="65dp"
app:layout_constraintLeft_toLeftOf="parent" /> app:layout_constraintLeft_toLeftOf="parent" />
<androidx.appcompat.widget.AppCompatButton <androidx.appcompat.widget.AppCompatButton
android:id="@+id/plusbutton3" android:id="@+id/plus_button3"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:background="@drawable/circle" android:background="@drawable/circle"
@ -73,13 +73,13 @@
android:visibility="visible" android:visibility="visible"
app:layout_constraintCircle="@+id/center" app:layout_constraintCircle="@+id/center"
app:layout_constraintCircleAngle="325" app:layout_constraintCircleAngle="325"
app:layout_constraintCircleRadius="70dp" app:layout_constraintCircleRadius="65dp"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:text="+10" /> tools:text="+10" />
<androidx.appcompat.widget.AppCompatButton <androidx.appcompat.widget.AppCompatButton
android:id="@+id/plusbutton2" android:id="@+id/plus_button2"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:background="@drawable/circle" android:background="@drawable/circle"
@ -87,33 +87,31 @@
android:gravity="center" android:gravity="center"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="30sp" android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/plusbutton" app:layout_constraintBottom_toTopOf="@+id/plus_button1"
app:layout_constraintCircle="@+id/center" app:layout_constraintCircle="@+id/center"
app:layout_constraintCircleAngle="270" app:layout_constraintCircleAngle="270"
app:layout_constraintCircleRadius="70dp" app:layout_constraintCircleRadius="65dp"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/plusbutton3" app:layout_constraintTop_toBottomOf="@+id/plus_button3"
tools:text="+5" /> tools:text="+5" />
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/value_background" android:id="@+id/value_background"
android:layout_width="108dp" android:layout_width="0dp"
android:layout_height="108dp" android:layout_height="0dp"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginLeft="2dp"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:background="@drawable/circle" android:background="@drawable/circle"
android:backgroundTint="@color/gray_700" android:backgroundTint="@color/gray_700"
android:contentDescription="@string/increment" android:importantForAccessibility="no"
app:layout_constraintBottom_toTopOf="@+id/minusbutton" app:layout_constraintBottom_toTopOf="@+id/minus_button"
app:layout_constraintCircle="@+id/center" app:layout_constraintDimensionRatio="1:1"
app:layout_constraintCircleAngle="55" app:layout_constraintLeft_toRightOf="@+id/plus_button3"
app:layout_constraintCircleRadius="40dp" app:layout_constraintTop_toTopOf="@+id/plus_button3" />
app:layout_constraintRight_toLeftOf="@id/plusbutton">
</androidx.appcompat.widget.AppCompatImageView>
<androidx.appcompat.widget.AppCompatImageButton <androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/plusbutton" android:id="@+id/plus_button1"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_gravity="center" android:layout_gravity="center"
@ -125,7 +123,7 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintCircle="@+id/center" app:layout_constraintCircle="@+id/center"
app:layout_constraintCircleAngle="215" app:layout_constraintCircleAngle="215"
app:layout_constraintCircleRadius="70dp" app:layout_constraintCircleRadius="65dp"
app:layout_constraintRight_toRightOf="parent" /> app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -15,7 +15,7 @@
android:orientation="vertical"> android:orientation="vertical">
<EditText <EditText
android:id="@+id/amountfield" android:id="@+id/edit_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
@ -34,7 +34,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:gravity="center" android:gravity="center"
android:labelFor="@+id/amountfield" android:labelFor="@+id/edit_text"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="25sp" android:textSize="25sp"
@ -42,7 +42,7 @@
tools:text="label" /> tools:text="label" />
<androidx.appcompat.widget.AppCompatImageButton <androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/minusbutton" android:id="@+id/minus_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
@ -62,35 +62,8 @@
android:orientation="vertical" android:orientation="vertical"
tools:visibility="visible"> tools:visibility="visible">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/plusbutton3"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:background="@drawable/circle"
android:backgroundTint="@color/white"
android:gravity="center"
android:textColor="@color/white"
android:textSize="25sp"
android:visibility="gone"
tools:text="+10" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/plusbutton2"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="end"
android:layout_marginVertical="7dp"
android:background="@drawable/circle"
android:backgroundTint="@color/white"
android:gravity="center"
android:textColor="@color/white"
android:visibility="gone"
android:textSize="25sp"
tools:text="+5" />
<androidx.appcompat.widget.AppCompatImageButton <androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/plusbutton" android:id="@+id/plus_button1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"

View file

@ -15,16 +15,16 @@
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<EditText <EditText
android:id="@+id/amountfield" android:id="@+id/edit_text"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="-10dp" android:layout_marginTop="-1dp"
android:layout_marginHorizontal="10dp" android:layout_marginHorizontal="10dp"
android:cursorVisible="false" android:cursorVisible="false"
android:gravity="center"
android:inputType="numberDecimal" android:inputType="numberDecimal"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="40sp" android:textSize="40sp"
android:gravity="center"
app:layout_constraintEnd_toEndOf="@+id/value_background" app:layout_constraintEnd_toEndOf="@+id/value_background"
app:layout_constraintStart_toStartOf="@+id/value_background" app:layout_constraintStart_toStartOf="@+id/value_background"
app:layout_constraintTop_toTopOf="@+id/value_background" app:layout_constraintTop_toTopOf="@+id/value_background"
@ -34,20 +34,20 @@
android:id="@+id/label" android:id="@+id/label"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/edit_text"
android:layout_marginTop="-8dp" android:layout_marginTop="-8dp"
android:layout_below="@+id/amountfield"
android:gravity="center" android:gravity="center"
android:labelFor="@+id/amountfield" android:labelFor="@+id/edit_text"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="25sp" android:textSize="25sp"
app:layout_constraintEnd_toEndOf="@+id/amountfield" app:layout_constraintEnd_toEndOf="@+id/edit_text"
app:layout_constraintStart_toStartOf="@+id/amountfield" app:layout_constraintStart_toStartOf="@+id/edit_text"
app:layout_constraintTop_toBottomOf="@id/amountfield" app:layout_constraintTop_toBottomOf="@id/edit_text"
tools:ignore="LabelFor" tools:ignore="LabelFor"
tools:text="label" /> tools:text="label" />
<androidx.appcompat.widget.AppCompatImageButton <androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/minusbutton" android:id="@+id/minus_button"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:background="@drawable/circle" android:background="@drawable/circle"
@ -62,7 +62,7 @@
app:layout_constraintLeft_toLeftOf="parent" /> app:layout_constraintLeft_toLeftOf="parent" />
<androidx.appcompat.widget.AppCompatButton <androidx.appcompat.widget.AppCompatButton
android:id="@+id/plusbutton3" android:id="@+id/plus_button3"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:background="@drawable/circle" android:background="@drawable/circle"
@ -79,7 +79,7 @@
tools:text="+10" /> tools:text="+10" />
<androidx.appcompat.widget.AppCompatButton <androidx.appcompat.widget.AppCompatButton
android:id="@+id/plusbutton2" android:id="@+id/plus_button2"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:background="@drawable/circle" android:background="@drawable/circle"
@ -87,12 +87,12 @@
android:gravity="center" android:gravity="center"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="30sp" android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/plusbutton" app:layout_constraintBottom_toTopOf="@+id/plus_button1"
app:layout_constraintCircle="@+id/center" app:layout_constraintCircle="@+id/center"
app:layout_constraintCircleAngle="90" app:layout_constraintCircleAngle="90"
app:layout_constraintCircleRadius="70dp" app:layout_constraintCircleRadius="70dp"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/plusbutton3" app:layout_constraintTop_toBottomOf="@+id/plus_button3"
tools:text="+5" /> tools:text="+5" />
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
@ -101,19 +101,15 @@
android:layout_height="108dp" android:layout_height="108dp"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:background="@drawable/circle" android:importantForAccessibility="no"
android:backgroundTint="@color/gray_700"
android:contentDescription="@string/increment"
app:layout_constraintBottom_toTopOf="@+id/minusbutton"
app:layout_constraintCircle="@+id/center"
app:layout_constraintCircleAngle="305"
app:layout_constraintCircleRadius="40dp"
app:layout_constraintRight_toLeftOf="@id/plusbutton">
</androidx.appcompat.widget.AppCompatImageView> app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatImageButton <androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/plusbutton" android:id="@+id/plus_button1"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_gravity="center" android:layout_gravity="center"

View file

@ -11,7 +11,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="start|center_vertical" android:layout_gravity="start|center_vertical"
android:gravity="center" android:gravity="center"
android:labelFor="@+id/amountfield" android:labelFor="@+id/edit_text"
android:rotation="90" android:rotation="90"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white" android:textColor="@color/white"
@ -26,7 +26,7 @@
android:orientation="vertical"> android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageButton <androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/plusbutton" android:id="@+id/plus_button1"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal" android:layout_gravity="center_vertical|center_horizontal"
@ -36,7 +36,7 @@
android:tint="@color/white" /> android:tint="@color/white" />
<EditText <EditText
android:id="@+id/amountfield" android:id="@+id/edit_text"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal" android:layout_gravity="center_vertical|center_horizontal"
@ -51,7 +51,7 @@
tools:text="112" /> tools:text="112" />
<androidx.appcompat.widget.AppCompatImageButton <androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/minusbutton" android:id="@+id/minus_button"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal" android:layout_gravity="center_vertical|center_horizontal"