Skip to content

Commit 98a5a5a

Browse files
BrayanDSOlukstbit
authored andcommitted
refactor(controls): convert AxisPicker to ConstraintLayout
both "BRAKE" and "GAS" work here in my PS4 controller after this
1 parent 8a4c286 commit 98a5a5a

2 files changed

Lines changed: 12 additions & 17 deletions

File tree

AnkiDroid/src/main/java/com/ichi2/preferences/ControlPreference.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ open class ControlPreference :
150150
}
151151

152152
fun showAddAxisDialog() {
153-
val axisPicker = AxisPicker.inflate(context)
153+
val axisPicker = AxisPicker(context)
154154
val dialog =
155155
AlertDialog.Builder(context).create {
156-
customView(view = axisPicker.rootLayout)
156+
customView(view = axisPicker.binding.root)
157157
setTitle(title)
158158
setIcon(icon)
159159
negativeButton(R.string.dialog_cancel) { it.dismiss() }

AnkiDroid/src/main/java/com/ichi2/ui/AxisPicker.kt

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
package com.ichi2.ui
1818

1919
import android.content.Context
20+
import android.util.AttributeSet
2021
import android.view.LayoutInflater
2122
import android.view.MotionEvent
2223
import android.view.View
24+
import androidx.constraintlayout.widget.ConstraintLayout
2325
import com.ichi2.anki.databinding.DialogAxisPickerBinding
2426
import com.ichi2.anki.reviewer.Axis
2527
import 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

Comments
 (0)