Improve accessibility of SMS code keyboard.

This commit is contained in:
Alex Hart
2022-08-01 16:46:07 -03:00
committed by Greyson Parrelli
parent c2b5407911
commit 8be7fa8655
7 changed files with 256 additions and 56 deletions

View File

@@ -0,0 +1,75 @@
package org.thoughtcrime.securesms.components
import android.content.Context
import android.util.AttributeSet
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import org.thoughtcrime.securesms.R
/**
* A "forced" EN US Numeric keyboard designed solely for SMS code entry. This
* "upgrade" over KeyboardView will ensure that the keyboard is navigable via
* TalkBack and will read out keys as they are selected by the user. This is
* not a perfect solution, but save being able to force the system keyboard to
* appear in EN US, this is the best we can do for the time being.
*/
class NumericKeyboardView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null
) : ConstraintLayout(context, attrs) {
var listener: Listener? = null
init {
inflate(context, R.layout.numeric_keyboard_view, this)
findViewById<TextView>(R.id.numeric_keyboard_1).setOnClickListener {
listener?.onKeyPress(1)
}
findViewById<TextView>(R.id.numeric_keyboard_2).setOnClickListener {
listener?.onKeyPress(2)
}
findViewById<TextView>(R.id.numeric_keyboard_3).setOnClickListener {
listener?.onKeyPress(3)
}
findViewById<TextView>(R.id.numeric_keyboard_4).setOnClickListener {
listener?.onKeyPress(4)
}
findViewById<TextView>(R.id.numeric_keyboard_5).setOnClickListener {
listener?.onKeyPress(5)
}
findViewById<TextView>(R.id.numeric_keyboard_6).setOnClickListener {
listener?.onKeyPress(6)
}
findViewById<TextView>(R.id.numeric_keyboard_7).setOnClickListener {
listener?.onKeyPress(7)
}
findViewById<TextView>(R.id.numeric_keyboard_8).setOnClickListener {
listener?.onKeyPress(8)
}
findViewById<TextView>(R.id.numeric_keyboard_9).setOnClickListener {
listener?.onKeyPress(9)
}
findViewById<TextView>(R.id.numeric_keyboard_0).setOnClickListener {
listener?.onKeyPress(0)
}
findViewById<ImageView>(R.id.numeric_keyboard_back).setOnClickListener {
listener?.onKeyPress(-1)
}
}
interface Listener {
fun onKeyPress(keyCode: Int)
}
}

View File

@@ -3,8 +3,6 @@ package org.thoughtcrime.securesms.components.registration;
import android.content.Context;
import android.graphics.PorterDuff;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
@@ -21,17 +19,18 @@ import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.NumericKeyboardView;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
public class VerificationPinKeyboard extends FrameLayout {
private KeyboardView keyboardView;
private ProgressBar progressBar;
private ImageView successView;
private ImageView failureView;
private ImageView lockedView;
private NumericKeyboardView keyboardView;
private ProgressBar progressBar;
private ImageView successView;
private ImageView failureView;
private ImageView lockedView;
private OnKeyPressListener listener;
@@ -65,27 +64,8 @@ public class VerificationPinKeyboard extends FrameLayout {
this.failureView = findViewById(R.id.failure);
this.lockedView = findViewById(R.id.locked);
keyboardView.setPreviewEnabled(false);
keyboardView.setKeyboard(new Keyboard(getContext(), R.xml.pin_keyboard));
keyboardView.setOnKeyboardActionListener(new KeyboardView.OnKeyboardActionListener() {
@Override
public void onPress(int primaryCode) {
if (listener != null) listener.onKeyPress(primaryCode);
}
@Override
public void onRelease(int primaryCode) {}
@Override
public void onKey(int primaryCode, int[] keyCodes) {}
@Override
public void onText(CharSequence text) {}
@Override
public void swipeLeft() {}
@Override
public void swipeRight() {}
@Override
public void swipeDown() {}
@Override
public void swipeUp() {}
keyboardView.setListener(keyCode -> {
if (listener != null) listener.onKeyPress(keyCode);
});
displayKeyboard();