Skip to content

Commit

Permalink
Add cursor focus translations
Browse files Browse the repository at this point in the history
  • Loading branch information
martenrebane committed May 13, 2024
1 parent f58380c commit 09be171
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.util.Locale;

import ee.ria.DigiDoc.R;
import ee.ria.DigiDoc.android.Activity;
import ee.ria.DigiDoc.common.TextUtil;

Expand Down Expand Up @@ -101,7 +102,7 @@ public static void setViewAccessibilityPaneTitle(View view, @StringRes int title
view.setAccessibilityPaneTitle(view.getResources().getString(titleResId).toLowerCase());
}

public static void setTextViewContentDescription(boolean setAsSingleCharacters, @Nullable String hint, String label, EditText editText) {
public static void setTextViewContentDescription(Context context, boolean setAsSingleCharacters, @Nullable String hint, String label, EditText editText) {
editText.setAccessibilityDelegate(new View.AccessibilityDelegate() {

@Override
Expand Down Expand Up @@ -136,11 +137,11 @@ public void onPopulateAccessibilityEvent(@NonNull View host, @NonNull Accessibil

String cursorPositionDescription;
if (cursorPosition == 0) {
cursorPositionDescription = "Cursor's focus is at the beginning";
cursorPositionDescription = context.getResources().getString(R.string.cursor_focus_beginning_content_description);
} else if (cursorPosition == textLength) {
cursorPositionDescription = "Cursor's focus is at the end";
cursorPositionDescription = context.getResources().getString(R.string.cursor_focus_end_content_description);
} else {
cursorPositionDescription = "Cursor's focus is at character " + (cursorPosition + 1);
cursorPositionDescription = context.getResources().getString(R.string.cursor_focus_at_character_content_description, cursorPosition + 1);
}
if (editText.getText() != null && !editText.getText().toString().isEmpty()) {
if (setAsSingleCharacters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ public SettingsProxyDialog(Context context) {
AccessibilityUtils.setEditTextCursorToEnd(port);
AccessibilityUtils.setEditTextCursorToEnd(username);
AccessibilityUtils.setEditTextCursorToEnd(password);
AccessibilityUtils.setTextViewContentDescription(false, null, context.getString(R.string.main_settings_proxy_host), host);
AccessibilityUtils.setTextViewContentDescription(false, "80", context.getString(R.string.main_settings_proxy_port), port);
AccessibilityUtils.setTextViewContentDescription(false, null, context.getString(R.string.main_settings_proxy_username), username);
AccessibilityUtils.setTextViewContentDescription(false, null, context.getString(R.string.main_settings_proxy_password), password);
AccessibilityUtils.setTextViewContentDescription(context, false, null, context.getString(R.string.main_settings_proxy_host), host);
AccessibilityUtils.setTextViewContentDescription(context, false, "80", context.getString(R.string.main_settings_proxy_port), port);
AccessibilityUtils.setTextViewContentDescription(context, false, null, context.getString(R.string.main_settings_proxy_username), username);
AccessibilityUtils.setTextViewContentDescription(context, false, null, context.getString(R.string.main_settings_proxy_password), password);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ protected void onBindDialogView(@NonNull View view) {

if (appCompatEditText != null) {
setAccessibilityForEditText(tsaUrlPreference, appCompatEditText, appCompatTextView);
AccessibilityUtils.setTextViewContentDescription(true, configurationProvider.getTsaUrl(), appCompatTextView.getText().toString(), appCompatEditText);
if (AccessibilityUtils.isTalkBackEnabled()) {
AccessibilityUtils.setTextViewContentDescription(getContext(), true, configurationProvider.getTsaUrl(), appCompatTextView.getText().toString(), appCompatEditText);
}
}

if (summary != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ protected void onBindDialogView(@NonNull View view) {

if (appCompatEditText != null) {
setAccessibilityForEditText(uuidPreference, appCompatEditText, appCompatTextView);
AccessibilityUtils.setTextViewContentDescription(true, "00000000-0000-0000-0000-000000000000", appCompatTextView.getText().toString(), appCompatEditText);
if (AccessibilityUtils.isTalkBackEnabled()) {
AccessibilityUtils.setTextViewContentDescription(getContext(), true, "00000000-0000-0000-0000-000000000000", appCompatTextView.getText().toString(), appCompatEditText);
}
}

if (summary != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public SettingsSivaDialog(Context context) {
if (AccessibilityUtils.isTalkBackEnabled()) {
handleSivaUrlContentDescription();
AccessibilityUtils.setEditTextCursorToEnd(sivaServiceUrl);
AccessibilityUtils.setTextViewContentDescription(false, null, context.getString(R.string.main_settings_siva_service_title), sivaServiceUrl);
AccessibilityUtils.setTextViewContentDescription(context, false, null, context.getString(R.string.main_settings_siva_service_title), sivaServiceUrl);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,16 @@ public MobileIdView(Context context, @Nullable AttributeSet attrs, int defStyleA

if (AccessibilityUtils.isTalkBackEnabled()) {
setAccessibilityDescription();
}
AccessibilityUtils.setSingleCharactersContentDescription(phoneNoView, countryAndPhoneNoLabel.getText().toString());
AccessibilityUtils.setSingleCharactersContentDescription(personalCodeView, personalCodeLabelText.getText().toString());

AccessibilityUtils.setEditTextCursorToEnd(phoneNoView);
AccessibilityUtils.setEditTextCursorToEnd(personalCodeView);
AccessibilityUtils.setSingleCharactersContentDescription(phoneNoView, countryAndPhoneNoLabel.getText().toString());
AccessibilityUtils.setSingleCharactersContentDescription(personalCodeView, personalCodeLabelText.getText().toString());

AccessibilityUtils.setTextViewContentDescription(true, getResources().getString(R.string.mobile_id_country_code_and_phone_number_placeholder), countryAndPhoneNoLabel.getText().toString(), phoneNoView);
AccessibilityUtils.setTextViewContentDescription(true, null, personalCodeLabelText.getText().toString(), personalCodeView);
AccessibilityUtils.setEditTextCursorToEnd(phoneNoView);
AccessibilityUtils.setEditTextCursorToEnd(personalCodeView);

AccessibilityUtils.setTextViewContentDescription(context, true, getResources().getString(R.string.mobile_id_country_code_and_phone_number_placeholder), countryAndPhoneNoLabel.getText().toString(), phoneNoView);
AccessibilityUtils.setTextViewContentDescription(context, true, null, personalCodeLabelText.getText().toString(), personalCodeView);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ public NFCView(Context context, @Nullable AttributeSet attrs, int defStyleAttr,

handleNFCSupportLayout();

AccessibilityUtils.setSingleCharactersContentDescription(canView, "Card number");
AccessibilityUtils.setSingleCharactersContentDescription(pinView, "PIN code");
AccessibilityUtils.setEditTextCursorToEnd(canView);
AccessibilityUtils.setEditTextCursorToEnd(pinView);
AccessibilityUtils.setTextViewContentDescription(true, null, canLabel.getText().toString(), canView);
AccessibilityUtils.setTextViewContentDescription(true, null, pinLabel.getText().toString(), pinView);
if (AccessibilityUtils.isTalkBackEnabled()) {
AccessibilityUtils.setSingleCharactersContentDescription(canView, "Card number");
AccessibilityUtils.setSingleCharactersContentDescription(pinView, "PIN code");
AccessibilityUtils.setEditTextCursorToEnd(canView);
AccessibilityUtils.setEditTextCursorToEnd(pinView);
AccessibilityUtils.setTextViewContentDescription(context, true, null, canLabel.getText().toString(), canView);
AccessibilityUtils.setTextViewContentDescription(context, true, null, pinLabel.getText().toString(), pinView);
}
checkInputsValidity();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ public void onNothingSelected(AdapterView<?> parent) {

if (AccessibilityUtils.isTalkBackEnabled()) {
setAccessibilityDescription();
AccessibilityUtils.setTextViewContentDescription(context, true, null, personalCodeViewLabel.getText().toString(), personalCodeView);
}

AccessibilityUtils.setTextViewContentDescription(true, null, personalCodeViewLabel.getText().toString(), personalCodeView);
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-et/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
<string name="sign_send_content_description">Allkirjasta, vahekaart %1$d / %2$d</string>
<string name="sign_save_content_description">Salvesta, vahekaart %1$d / %2$d</string>
<string name="decrypt_send_content_description">Jaga, vahekaart %1$d / %2$d</string>
<string name="cursor_focus_beginning_content_description">Kursori fookus on alguses</string>
<string name="cursor_focus_at_character_content_description">Kursori fookus on %1$d tähemärgi juures</string>
<string name="cursor_focus_end_content_description">Kursori fookus on lõpus</string>

<string name="document">Dokument</string>
<string name="container_has">Ümbrikus </string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,9 @@
<string name="sign_send_content_description">Подписать, вкладка %1$d из %2$d</string>
<string name="sign_save_content_description">Сохраните, вкладка %1$d из %2$d</string>
<string name="decrypt_send_content_description">Поделиться, вкладка %1$d из %2$d</string>
<string name="cursor_focus_beginning_content_description">Фокус курсора в начале</string>
<string name="cursor_focus_at_character_content_description">Фокус курсора на символе %1$d</string>
<string name="cursor_focus_end_content_description">Фокус курсора в конце</string>

<string name="yes_button">ДА</string>
<string name="cancel_button">ОТМЕНИТЬ</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,9 @@
<string name="sign_send_content_description">Sign, tab %1$d of %2$d</string>
<string name="sign_save_content_description">Save, tab %1$d of %2$d</string>
<string name="decrypt_send_content_description">Share, tab %1$d of %2$d</string>
<string name="cursor_focus_beginning_content_description">Cursor\'s focus is at the beginning</string>
<string name="cursor_focus_at_character_content_description">Cursor\'s focus is at character %1$d</string>
<string name="cursor_focus_end_content_description">Cursor\'s focus is at the end</string>

<string name="yes_button">YES</string>
<string name="cancel_button" tools:ignore="ButtonCase">CANCEL</string>
Expand Down

0 comments on commit 09be171

Please sign in to comment.