Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TalkBack only read values that've changed when in "accessibility mode" #617 #618

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,18 @@ public static Calendar trimToMidnight(Calendar calendar) {
calendar.set(Calendar.MILLISECOND, 0);
return calendar;
}

/**
* Cast string to int
*
* @param text The text to convert to an int
* @return the parsed value or -1
*/
public static int stringToInt(String text) {
try {
return Integer.parseInt(text);
} catch (NumberFormatException exception) {
return -1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,11 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
amOrPm = AM;
}
mTimePicker.setAmOrPm(amOrPm);
if (amOrPm == AM) {
Utils.tryAccessibilityAnnounce(mTimePicker, mAmText);
} else if (amOrPm == PM) {
Utils.tryAccessibilityAnnounce(mTimePicker, mPmText);
}
};
mAmTextView .setVisibility(View.GONE);
mPmTextView.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -1055,20 +1060,16 @@ private void updateAmPmDisplay(int amOrPm) {
if (amOrPm == AM) {
mAmTextView.setTextColor(mSelectedColor);
mPmTextView.setTextColor(mUnselectedColor);
Utils.tryAccessibilityAnnounce(mTimePicker, mAmText);
} else {
mAmTextView.setTextColor(mUnselectedColor);
mPmTextView.setTextColor(mSelectedColor);
Utils.tryAccessibilityAnnounce(mTimePicker, mPmText);
}
} else {
if (amOrPm == AM) {
mPmTextView.setText(mAmText);
Utils.tryAccessibilityAnnounce(mTimePicker, mAmText);
mPmTextView.setContentDescription(mAmText);
} else if (amOrPm == PM){
mPmTextView.setText(mPmText);
Utils.tryAccessibilityAnnounce(mTimePicker, mPmText);
mPmTextView.setContentDescription(mPmText);
} else {
mPmTextView.setText(mDoublePlaceholderText);
Expand Down Expand Up @@ -1111,7 +1112,7 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
*/
@Override
public void onValueSelected(Timepoint newValue) {
setHour(newValue.getHour(), false);
setHour(newValue.getHour(), true);
mTimePicker.setContentDescription(mHourPickerDescription + ": " + newValue.getHour());
setMinute(newValue.getMinute());
mTimePicker.setContentDescription(mMinutePickerDescription + ": " + newValue.getMinute());
Expand All @@ -1126,12 +1127,12 @@ public void advancePicker(int index) {
if(index == HOUR_INDEX && mEnableMinutes) {
setCurrentItemShowing(MINUTE_INDEX, true, true, false);

String announcement = mSelectHours + ". " + mTimePicker.getMinutes();
String announcement = mSelectMinutes + ". " + mTimePicker.getMinutes();
Utils.tryAccessibilityAnnounce(mTimePicker, announcement);
} else if(index == MINUTE_INDEX && mEnableSeconds) {
setCurrentItemShowing(SECOND_INDEX, true, true, false);

String announcement = mSelectMinutes+". " + mTimePicker.getSeconds();
String announcement = mSelectSeconds +". " + mTimePicker.getSeconds();
Utils.tryAccessibilityAnnounce(mTimePicker, announcement);
}
}
Expand Down Expand Up @@ -1198,9 +1199,10 @@ private void setHour(int value, boolean announce) {
}

CharSequence text = String.format(mLocale, format, value);
int oldValue = Utils.stringToInt(mHourView.getText().toString());
mHourView.setText(text);
mHourSpaceView.setText(text);
if (announce) {
if (announce && oldValue != value && oldValue != -1) {
Utils.tryAccessibilityAnnounce(mTimePicker, text);
}
}
Expand All @@ -1209,20 +1211,26 @@ private void setMinute(int value) {
if (value == 60) {
value = 0;
}
int oldValue = Utils.stringToInt(mMinuteView.getText().toString());
CharSequence text = String.format(mLocale, "%02d", value);
Utils.tryAccessibilityAnnounce(mTimePicker, text);
mMinuteView.setText(text);
mMinuteSpaceView.setText(text);
if (oldValue != value && oldValue != -1) {
Utils.tryAccessibilityAnnounce(mTimePicker, text);
}
}

private void setSecond(int value) {
if(value == 60) {
value = 0;
}
int oldValue = Utils.stringToInt(mSecondView.getText().toString());
CharSequence text = String.format(mLocale, "%02d", value);
Utils.tryAccessibilityAnnounce(mTimePicker, text);
mSecondView.setText(text);
mSecondSpaceView.setText(text);
if (oldValue != value && oldValue != -1) {
Utils.tryAccessibilityAnnounce(mTimePicker, text);
}
}

// Show either Hours or Minutes.
Expand Down