diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.kt index 2134f60f6d..b3c395fb76 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/AcceptActivity.kt @@ -56,10 +56,9 @@ class AcceptActivity : ViewSelectorActivity() { override fun getColumnCount(arg0: Int): Int = 2 override fun getRowCount(): Int = 1 - override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { - val view: View - if (col == 0) { - view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_text, container, false) + override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when (col) { + 0 -> { + val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_text, container, false) val textView = view.findViewById(R.id.message) val scrollView = view.findViewById(R.id.message_scroll) textView.text = message @@ -79,8 +78,11 @@ class AcceptActivity : ViewSelectorActivity() { false } scrollView.requestFocus() - } else { - view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) + view + } + + else -> { + val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) val confirmButton = view.findViewById(R.id.confirmbutton) confirmButton.setOnClickListener { if (actionKey.isNotEmpty()) startService(IntentWearToMobile(this@AcceptActivity, actionKey)) @@ -88,8 +90,8 @@ class AcceptActivity : ViewSelectorActivity() { finishAffinity() } container.addView(view) + view } - return view } override fun destroyItem(container: ViewGroup, row: Int, col: Int, view: Any) { @@ -127,4 +129,4 @@ class AcceptActivity : ViewSelectorActivity() { finish() } } -} \ No newline at end of file +} diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.kt index 766983c581..012d5ec516 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.kt @@ -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 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 { - val view: View - if (col == 0) { - view = EditPlusMinusViewAdapter.getInflatedPlusMinusView(sp, applicationContext, container, true).root + override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when (col) { + 0 -> { + val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true) 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 buttons = listOf(Pair(R.id.plusbutton, 0.1), Pair(R.id.plusbutton2, increment1), Pair(R.id.plusbutton3, increment2)) // When taken form phone settings round. - editInsulin = PlusMinusEditText(view, R.id.amountfield, buttons, R.id.minusbutton, initValue, 0.0, maxBolus, 0.1, DecimalFormat("#0.0"), false) - setLabelToPlusMinusView(view, getString(R.string.action_insulin)) + val title = getString(R.string.action_insulin) + editInsulin = PlusMinusEditText(viewAdapter, initValue, 0.0, maxBolus, stepValues, DecimalFormat("#0.0"), false, title) + val view = viewAdapter.root container.addView(view) view.requestFocus() - } else { - view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) + view + } + + else -> { + val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) val confirmButton = view.findViewById(R.id.confirmbutton) confirmButton.setOnClickListener { rxBus.send(EventWearToMobile(ActionBolusPreCheck(SafeParse.stringToDouble(editInsulin?.editText?.text.toString()), 0))) @@ -58,8 +61,8 @@ class BolusActivity : ViewSelectorActivity() { finishAffinity() } container.addView(view) + view } - return view } override fun destroyItem(container: ViewGroup, row: Int, col: Int, view: Any) { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CarbActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CarbActivity.kt index 7de9a45dd3..b941049002 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CarbActivity.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CarbActivity.kt @@ -10,6 +10,7 @@ import android.view.ViewGroup import android.widget.ImageView import info.nightscout.androidaps.R import info.nightscout.androidaps.events.EventWearToMobile +import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter import info.nightscout.androidaps.interaction.utils.PlusMinusEditText import info.nightscout.shared.SafeParse 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 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 getRowCount(): Int = 1 - override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { - val view: View - if (col == 0) { - view = getInflatedPlusMinusView(container, true) + override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when (col) { + 0 -> { + val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true) + val view = viewAdapter.root var def = 0.0 if (editCarbs != null) { def = SafeParse.stringToDouble(editCarbs?.editText?.text.toString()) } 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(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)) + editCarbs = PlusMinusEditText(viewAdapter, def, 0.0, maxCarbs.toDouble(), stepValues, DecimalFormat("0"), true, getString(R.string.action_carbs)) container.addView(view) view.requestFocus() - } else { - view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) + view + } + + else -> { + val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) val confirmButton = view.findViewById(R.id.confirmbutton) confirmButton.setOnClickListener { // With start time 0 and duration 0 @@ -61,8 +64,8 @@ class CarbActivity : ViewSelectorActivity() { finishAffinity() } container.addView(view) + view } - return view } override fun destroyItem(container: ViewGroup, row: Int, col: Int, view: Any) { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.kt index 50988562a4..0a643e9bff 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.kt @@ -10,6 +10,7 @@ import android.view.ViewGroup import android.widget.ImageView import info.nightscout.androidaps.R import info.nightscout.androidaps.events.EventWearToMobile +import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter import info.nightscout.androidaps.interaction.utils.PlusMinusEditText import info.nightscout.shared.SafeParse.stringToDouble import info.nightscout.shared.SafeParse.stringToInt @@ -36,44 +37,50 @@ class ECarbActivity : ViewSelectorActivity() { override fun getColumnCount(arg0: Int): Int = 4 override fun getRowCount(): Int = 1 - 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() + 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 stepValues = listOf(1.0, increment1, increment2) - override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { - return if (col == 0) { - val view = getInflatedPlusMinusView(container, true) + override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when (col) { + 0 -> { + val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true) + val view = viewAdapter.root var def = 0.0 if (editCarbs != null) { def = stringToDouble(editCarbs?.editText?.text.toString()) } 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(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)) + editCarbs = PlusMinusEditText(viewAdapter, def, 0.0, maxCarbs.toDouble(), stepValues, DecimalFormat("0"), true, getString(R.string.action_carbs)) container.addView(view) view.requestFocus() 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 if (editStartTime != null) { 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) - setLabelToPlusMinusView(view, getString(R.string.action_start_min)) + editStartTime = PlusMinusEditText(viewAdapter, 15.0, def, -60.0, 300.0, DecimalFormat("0"), false, getString(R.string.action_start_min)) container.addView(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 if (editDuration != null) { 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) - setLabelToPlusMinusView(view, getString(R.string.action_duration_h)) + editDuration = PlusMinusEditText(viewAdapter, 1.0, def, 0.0, 8.0, DecimalFormat("0"), false, getString(R.string.action_duration_h)) container.addView(view) view - } else { + } + + else -> { val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) val confirmButton = view.findViewById(R.id.confirmbutton) confirmButton.setOnClickListener { @@ -102,4 +109,4 @@ class ECarbActivity : ViewSelectorActivity() { override fun isViewFromObject(view: View, `object`: Any): Boolean = view === `object` } -} +} \ No newline at end of file diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.kt index a10163e466..2525033df0 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/FillActivity.kt @@ -10,6 +10,7 @@ import android.view.ViewGroup import android.widget.ImageView import info.nightscout.androidaps.R import info.nightscout.androidaps.events.EventWearToMobile +import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter import info.nightscout.androidaps.interaction.utils.PlusMinusEditText import info.nightscout.shared.SafeParse.stringToDouble import info.nightscout.shared.weardata.EventData.ActionFillPreCheck @@ -33,19 +34,21 @@ class FillActivity : ViewSelectorActivity() { override fun getColumnCount(arg0: Int): Int = 2 override fun getRowCount(): Int = 1 - override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { - return if (col == 0) { - val view = getInflatedPlusMinusView(container) + override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when (col) { + 0 -> { + val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false) + val view = viewAdapter.root var def = 0.0 if (editInsulin != null) { 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) - setLabelToPlusMinusView(view, getString(R.string.action_insulin)) + editInsulin = PlusMinusEditText(viewAdapter, def, 0.0, 30.0, 0.1, DecimalFormat("#0.0"), false, getString(R.string.action_insulin)) container.addView(view) view.requestFocus() view - } else { + } + + else -> { val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) val confirmButton = view.findViewById(R.id.confirmbutton) confirmButton.setOnClickListener { @@ -68,4 +71,4 @@ class FillActivity : ViewSelectorActivity() { override fun isViewFromObject(view: View, `object`: Any): Boolean = view === `object` } -} \ No newline at end of file +} diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ProfileSwitchActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ProfileSwitchActivity.kt index 73b9551b53..c6498f2638 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ProfileSwitchActivity.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ProfileSwitchActivity.kt @@ -10,6 +10,7 @@ import android.view.ViewGroup import android.widget.ImageView import info.nightscout.androidaps.R import info.nightscout.androidaps.events.EventWearToMobile +import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter import info.nightscout.androidaps.interaction.utils.PlusMinusEditText import info.nightscout.shared.SafeParse import info.nightscout.shared.weardata.EventData.ActionProfileSwitchPreCheck @@ -43,29 +44,34 @@ class ProfileSwitchActivity : ViewSelectorActivity() { override fun getColumnCount(arg0: Int): Int = 3 override fun getRowCount(): Int = 1 - override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { - return if (col == 0) { - val view = getInflatedPlusMinusView(container) + override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when (col) { + 0 -> { + val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false) + val view = viewAdapter.root var def = timeshift.toDouble() if (editTimeshift != null) { 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) - setLabelToPlusMinusView(view, getString(R.string.action_timeshift)) + editTimeshift = PlusMinusEditText(viewAdapter, def, 0.0, 23.0, 1.0, DecimalFormat("0"), true, getString(R.string.action_timeshift), true) container.addView(view) view.requestFocus() 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() if (editPercentage != null) { 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) - setLabelToPlusMinusView(view, getString(R.string.action_percentage)) + editPercentage = PlusMinusEditText(viewAdapter, def, 30.0, 250.0, 1.0, DecimalFormat("0"), false, getString(R.string.action_percentage)) + container.addView(view) view - } else { + } + + else -> { val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) val confirmButton = view.findViewById(R.id.confirmbutton) confirmButton.setOnClickListener { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.kt index cab25b52eb..26570a6bdd 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.kt @@ -10,6 +10,7 @@ import android.view.ViewGroup import android.widget.ImageView import info.nightscout.androidaps.R import info.nightscout.androidaps.events.EventWearToMobile +import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter import info.nightscout.androidaps.interaction.utils.PlusMinusEditText import info.nightscout.shared.SafeParse import info.nightscout.shared.weardata.EventData.ActionTempTargetPreCheck @@ -45,49 +46,56 @@ class TempTargetActivity : ViewSelectorActivity() { return 1 } - override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { - return if (col == 0) { - val view = getInflatedPlusMinusView(container) + override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when { + col == 0 -> { + val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false) + val view = viewAdapter.root 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 { 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) view.requestFocus() 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) { var def = 100.0 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 { var def = 5.5 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) 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) { var def = 100.0 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 { var def = 5.5 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) view - } else { + } + + else -> { val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) val confirmButton = view.findViewById(R.id.confirmbutton) confirmButton.setOnClickListener { @@ -119,4 +127,4 @@ class TempTargetActivity : ViewSelectorActivity() { return view === `object` } } -} \ No newline at end of file +} diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TreatmentActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TreatmentActivity.kt index 630317b89a..55805803d4 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TreatmentActivity.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TreatmentActivity.kt @@ -10,6 +10,7 @@ import android.view.ViewGroup import android.widget.ImageView import info.nightscout.androidaps.R import info.nightscout.androidaps.events.EventWearToMobile +import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter import info.nightscout.androidaps.interaction.utils.PlusMinusEditText import info.nightscout.shared.SafeParse.stringToDouble 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 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 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 { - return if (col == 0) { - val view = getInflatedPlusMinusView(container, true) + override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when (col) { + 0 -> { + val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true) + val view = viewAdapter.root var def = 0.0 if (editInsulin != null) def = stringToDouble(editInsulin?.editText?.text.toString()) 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(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)) + editInsulin = PlusMinusEditText(viewAdapter, def, 0.0, maxBolus, stepValuesInsulin, DecimalFormat("#0.0"), false, getString(R.string.action_insulin)) container.addView(view) view.requestFocus() 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 val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48) 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) - setLabelToPlusMinusView(view, getString(R.string.action_carbs)) + + editCarbs = PlusMinusEditText(viewAdapter, def, 0.0, maxCarbs.toDouble(), stepValuesCarbs, DecimalFormat("0"), false, getString(R.string.action_carbs)) container.addView(view) view - } else { + } + + else -> { val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) val confirmButton = view.findViewById(R.id.confirmbutton) confirmButton.setOnClickListener { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ViewSelectorActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ViewSelectorActivity.kt index eb3a9b70d7..d1d3b19099 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ViewSelectorActivity.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ViewSelectorActivity.kt @@ -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(R.id.label) - textView.text = labelText - } - fun showToast(context: Context?, text: Int) { Toast.makeText(context, getString(text), Toast.LENGTH_LONG).show() } diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.kt index dfd6e6291b..9a9bd01967 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.kt @@ -10,6 +10,7 @@ import android.view.ViewGroup import android.widget.ImageView import info.nightscout.androidaps.R import info.nightscout.androidaps.events.EventWearToMobile +import info.nightscout.androidaps.interaction.utils.EditPlusMinusViewAdapter import info.nightscout.androidaps.interaction.utils.PlusMinusEditText import info.nightscout.shared.SafeParse import info.nightscout.shared.weardata.EventData.ActionWizardPreCheck @@ -37,35 +38,39 @@ class WizardActivity : ViewSelectorActivity() { override fun getRowCount(): Int = 1 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() + val stepValues = listOf(1.0, increment1, increment2) - override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { - return if (col == 0) { - val view = getInflatedPlusMinusView(container, true) + override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when { + col == 0 -> { + 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 buttons = listOf(Pair(R.id.plusbutton, 1.0), Pair(R.id.plusbutton2, increment1), Pair(R.id.plusbutton3, increment2)) 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 { 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) view.requestFocus() 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) 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 { 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) view - } else { + } + + else -> { val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_confirm_ok, container, false) view.findViewById(R.id.confirmbutton) .setOnClickListener { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/EditPlusMinusViewAdapter.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/EditPlusMinusViewAdapter.kt index 4b3798940b..a1de3f1e9d 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/EditPlusMinusViewAdapter.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/EditPlusMinusViewAdapter.kt @@ -2,10 +2,10 @@ package info.nightscout.androidaps.interaction.utils import android.content.Context import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup import info.nightscout.androidaps.R import info.nightscout.androidaps.databinding.ActionEditplusminusItemBinding +import info.nightscout.androidaps.databinding.ActionEditplusminusItemPlusBinding import info.nightscout.androidaps.databinding.ActionEditplusminusItemQuickleftyPlusBinding import info.nightscout.androidaps.databinding.ActionEditplusminusItemQuickleftyBinding import info.nightscout.androidaps.databinding.ActionEditplusminusItemQuickrightyBinding @@ -14,65 +14,84 @@ import info.nightscout.androidaps.databinding.ActionEditplusminusItemViktoriaBin 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. */ class EditPlusMinusViewAdapter( - val eS: ActionEditplusminusItemBinding?, - val eQLP: ActionEditplusminusItemQuickleftyPlusBinding?, - val eQL: ActionEditplusminusItemQuickleftyBinding?, - val eQRP: ActionEditplusminusItemQuickleftyPlusBinding?, - val qQR: ActionEditplusminusItemQuickrightyBinding?, - val nQRP: ActionEditplusminusItemQuickrightyPlusBinding?, - val eV: ActionEditplusminusItemViktoriaBinding? + eD: ActionEditplusminusItemBinding?, + eDP: ActionEditplusminusItemPlusBinding?, + eQL: ActionEditplusminusItemQuickleftyBinding?, + eQLP: ActionEditplusminusItemQuickleftyPlusBinding?, + eQR: ActionEditplusminusItemQuickrightyBinding?, + eQRP: ActionEditplusminusItemQuickrightyPlusBinding?, + eV: ActionEditplusminusItemViktoriaBinding? ) { 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") } } - val amountField = - eS?.amountfield ?: eQLP?.amountfield ?: eQL?.amountfield ?: eQRP?.amountfield ?: qQR?.amountfield ?: nQRP?.amountfield ?: eV?.amountfield + val editText = + eD?.editText ?: eDP?.editText ?: eQL?.editText ?: eQLP?.editText ?: eQR?.editText ?: eQRP?.editText ?: eV?.editText ?: throw IllegalArgumentException("Missing require View Binding parameter display") 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") - val plusButton = - eS?.plusbutton ?: eQLP?.plusbutton ?: eQL?.plusbutton ?: eQRP?.plusbutton ?: qQR?.plusbutton ?: nQRP?.plusbutton ?: eV?.plusbutton + val plusButton1 = + eD?.plusButton1 ?: eDP?.plusButton1 ?: eQL?.plusButton1 ?: eQLP?.plusButton1 ?: eQR?.plusButton1 ?: eQRP?.plusButton1 ?: eV?.plusButton1 ?: throw IllegalArgumentException("Missing require View Binding parameter display") 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") - val plusButton2 = eQLP?.plusbutton2 ?: eQRP?.plusbutton2 - val plusButton3 = eQLP?.plusbutton3 ?: eQRP?.plusbutton3 + val plusButton2 = eDP?.plusButton2 ?: eQLP?.plusButton2 ?: eQRP?.plusButton2 + val plusButton3 = eDP?.plusButton3 ?: eQLP?.plusButton3 ?: eQRP?.plusButton3 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") 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 bindLayout = ActionEditplusminusItemBinding.inflate(inflater, container, false) - val binding = EditPlusMinusViewAdapter(bindLayout, null, null, null, null, null, null) - return binding - // 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) - // } + + return when (sp.getInt(R.string.key_input_design, 1)) { + 2 -> { + if (multiple) { + val bindLayout = ActionEditplusminusItemQuickrightyPlusBinding.inflate(inflater, container, false) + EditPlusMinusViewAdapter(null, null, null, null, null, bindLayout, null) + } else { + val bindLayout = ActionEditplusminusItemQuickrightyBinding.inflate(inflater, container, false) + EditPlusMinusViewAdapter(null, null, null, null, bindLayout, null, null) + } + } + + 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) - // } } -} \ No newline at end of file +} diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/PlusMinusEditText.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/PlusMinusEditText.kt index f812b7e245..2430c9e677 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/PlusMinusEditText.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/PlusMinusEditText.kt @@ -9,7 +9,6 @@ import android.view.View import android.view.View.OnGenericMotionListener import android.view.View.OnTouchListener import android.widget.TextView -import androidx.appcompat.widget.AppCompatButton import androidx.core.view.InputDeviceCompat import androidx.core.view.MotionEventCompat import java.text.DecimalFormat @@ -17,47 +16,38 @@ import java.text.NumberFormat import java.util.concurrent.Executors import java.util.concurrent.ScheduledExecutorService import java.util.concurrent.TimeUnit -import kotlin.Pair /** * Created by mike on 28.06.2016. */ @SuppressLint("SetTextI18n") class PlusMinusEditText @JvmOverloads constructor( - view: View, - editTextID: Int, - private var plusButtons: List>, - minusID: Int, + private val binding: EditPlusMinusViewAdapter, initValue: Double, private val minValue: Double, private val maxValue: Double, - private val stepGeneral: Double, + private val stepValues: List, private val formatter: NumberFormat, private val allowZero: Boolean, + label: String, private val roundRobin: Boolean = false, ) : View.OnKeyListener, OnTouchListener, View.OnClickListener, OnGenericMotionListener { constructor( - view: View, - editTextID: Int, - plusID: Int, - minusID: Int, + binding: EditPlusMinusViewAdapter, initValue: Double, minValue: Double, maxValue: Double, - stepGeneral: Double, + step: Double, formatter: NumberFormat, allowZero: Boolean, + label: String, 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 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 val context: Context private var mChangeCounter = 0 private var mLastChange: Long = 0 private val mHandler: Handler @@ -70,11 +60,11 @@ import kotlin.Pair override fun run() { val msg = Message() 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 val bundle = Bundle() - bundle.putDouble("step", step) - bundle.putInt("multiplier", multiplier) + bundle.putDouble(STEP, step) + bundle.putInt(MULTIPLIER, multiplier) msg.data = bundle if (mInc) { @@ -114,14 +104,14 @@ import kotlin.Pair if (vibrate) vibrateDevice() } - fun vibrateDevice() { + private fun vibrateDevice() { val vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { val vibratorManager = - context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager + binding.root.context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager vibratorManager.defaultVibrator } else { @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) { @@ -155,19 +145,19 @@ import kotlin.Pair private fun getStep(v: View): Double { return when (v) { - plusImage1 -> plusButtons[0].second - plusImage2 -> plusButtons[1].second - plusImage3 -> plusButtons[2].second - else -> stepGeneral + binding.plusButton1 -> stepValues[0] + binding.plusButton2 -> stepValues[1] + binding.plusButton3 -> stepValues[2] + else -> stepValues[0] } } private fun isIncrement(v: View): Boolean { return when (v) { - plusImage1 -> true - plusImage2 -> true - plusImage3 -> true - else -> false + binding.plusButton1 -> true + binding.plusButton2 -> true + binding.plusButton3 -> true + else -> false } } @@ -229,30 +219,22 @@ import kotlin.Pair private const val THRESHOLD_TIME = 100 private const val MSG_INC = 0 private const val MSG_DEC = 1 + private const val STEP = "step" + private const val MULTIPLIER = "multiplier" } init { - context = view.context - editText = view.findViewById(editTextID) - minusImage = view.findViewById(minusID) - plusImage1 = view.findViewById(plusButtons.first().first) + editText = binding.editText + binding.label.text = label val format = DecimalFormat("#.#") - plusButtons.getOrNull(1)?.let { - plusImage2 = view.findViewById(it.first) - 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 - } + binding.plusButton2?.text = "+${format.format(stepValues[1]).replaceFirst("^0+(?!$)".toRegex(), "")}" + binding.plusButton3?.text = "+${format.format(stepValues[2]).replaceFirst("^0+(?!$)".toRegex(), "")}" value = initValue mHandler = object : Handler(Looper.getMainLooper()) { override fun handleMessage(msg: Message) { - val multiplier = msg.data.getInt("multiplier") - val step = msg.data.getDouble("step") + val multiplier = msg.data.getInt(MULTIPLIER) + val step = msg.data.getDouble(STEP) when (msg.what) { MSG_INC -> { @@ -271,18 +253,18 @@ import kotlin.Pair editText.showSoftInputOnFocus = false editText.setTextIsSelectable(false) - minusImage.setOnTouchListener(this) - minusImage.setOnKeyListener(this) - minusImage.setOnClickListener(this) - plusImage1.setOnTouchListener(this) - plusImage1.setOnKeyListener(this) - plusImage1.setOnClickListener(this) - plusImage2?.setOnTouchListener(this) - plusImage2?.setOnKeyListener(this) - plusImage2?.setOnClickListener(this) - plusImage3?.setOnTouchListener(this) - plusImage3?.setOnKeyListener(this) - plusImage3?.setOnClickListener(this) + binding.minusButton.setOnTouchListener(this) + binding.minusButton.setOnKeyListener(this) + binding.minusButton.setOnClickListener(this) + binding.plusButton1.setOnTouchListener(this) + binding.plusButton1.setOnKeyListener(this) + binding.plusButton1.setOnClickListener(this) + binding.plusButton2?.setOnTouchListener(this) + binding.plusButton2?.setOnKeyListener(this) + binding.plusButton2?.setOnClickListener(this) + binding.plusButton3?.setOnTouchListener(this) + binding.plusButton3?.setOnKeyListener(this) + binding.plusButton3?.setOnClickListener(this) editText.setOnGenericMotionListener(this) updateEditText() } diff --git a/wear/src/main/res/layout/action_editplusminus_item.xml b/wear/src/main/res/layout/action_editplusminus_item.xml index 5c5b8856d5..75c3b21594 100644 --- a/wear/src/main/res/layout/action_editplusminus_item.xml +++ b/wear/src/main/res/layout/action_editplusminus_item.xml @@ -1,67 +1,131 @@ - + android:layout_height="match_parent"> - + + + + + + + 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" /> - + + + + + 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"> - - - - - + + 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" /> - + diff --git a/wear/src/main/res/layout/action_editplusminus_item_plus.xml b/wear/src/main/res/layout/action_editplusminus_item_plus.xml new file mode 100644 index 0000000000..18ea44cc13 --- /dev/null +++ b/wear/src/main/res/layout/action_editplusminus_item_plus.xml @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/wear/src/main/res/layout/action_editplusminus_item_quicklefty.xml b/wear/src/main/res/layout/action_editplusminus_item_quicklefty.xml index d96ae1d26f..d857446caa 100644 --- a/wear/src/main/res/layout/action_editplusminus_item_quicklefty.xml +++ b/wear/src/main/res/layout/action_editplusminus_item_quicklefty.xml @@ -14,38 +14,11 @@ android:layout_marginEnd="-8dp" android:orientation="vertical"> - - - - - - + android:importantForAccessibility="no" + app:layout_constraintBottom_toTopOf="@+id/minus_button" + app:layout_constraintDimensionRatio="1:1" + app:layout_constraintLeft_toRightOf="@+id/plus_button3" + app:layout_constraintTop_toTopOf="@+id/plus_button3" /> diff --git a/wear/src/main/res/layout/action_editplusminus_item_quickrighty.xml b/wear/src/main/res/layout/action_editplusminus_item_quickrighty.xml index 7e3ae3dcb1..d2e7950a05 100644 --- a/wear/src/main/res/layout/action_editplusminus_item_quickrighty.xml +++ b/wear/src/main/res/layout/action_editplusminus_item_quickrighty.xml @@ -15,7 +15,7 @@ android:orientation="vertical"> - - - - + android:importantForAccessibility="no" - + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" />