1717package com.ichi2.ui
1818
1919import android.content.Context
20+ import android.util.AttributeSet
2021import android.view.LayoutInflater
2122import android.view.MotionEvent
2223import android.view.View
24+ import androidx.constraintlayout.widget.ConstraintLayout
2325import com.ichi2.anki.databinding.DialogAxisPickerBinding
2426import com.ichi2.anki.reviewer.Axis
2527import com.ichi2.anki.reviewer.Binding
@@ -33,10 +35,12 @@ import timber.log.Timber
3335 *
3436 * @see AxisSelector
3537 */
36- class AxisPicker (
37- private val binding : DialogAxisPickerBinding ,
38- ) {
39- val rootLayout = binding.root
38+ class AxisPicker : ConstraintLayout {
39+ constructor (context: Context ) : super (context)
40+ constructor (context: Context , attrs: AttributeSet ? ) : super (context, attrs)
41+ constructor (context: Context , attrs: AttributeSet ? , defStyleAttr: Int ) : super (context, attrs, defStyleAttr)
42+
43+ val binding = DialogAxisPickerBinding .inflate(LayoutInflater .from(context))
4044
4145 /* * Maps from an [Axis] to the [AxisSelector] displaying + allowing selection of it */
4246 private val axisMap = mutableMapOf<Axis , AxisSelector >()
@@ -48,10 +52,8 @@ class AxisPicker(
4852 }
4953
5054 init {
51- // We use a TextView to listen due to issues with handling AXIS_BRAKE and AXIS_GAS
52- // When listening to 'rootLayout', these axes are ONLY detected after another joystick is moved
53- binding.selectedAxisTextView.requestFocus()
54- binding.selectedAxisTextView.setOnGenericMotionListener { _, event -> handleMotionEvent(event) }
55+ binding.root.requestFocus()
56+ binding.root.setOnGenericMotionListener { _, event -> handleMotionEvent(event) }
5557 }
5658
5759 @Suppress(" SameReturnValue" )
@@ -96,11 +98,4 @@ class AxisPicker(
9698 binding.availableAxes.addView(view)
9799 }
98100 }
99-
100- companion object {
101- fun inflate (context : Context ): AxisPicker {
102- val binding = DialogAxisPickerBinding .inflate(LayoutInflater .from(context))
103- return AxisPicker (binding)
104- }
105- }
106101}
0 commit comments