am 719e486f: am 9470cd95: Merge "Polish print dialog accessibility." into klp-dev
* commit '719e486f54b668d13680552f96558ee30d220a00':
Polish print dialog accessibility.
diff --git a/packages/PrintSpooler/res/menu/select_printer_activity.xml b/packages/PrintSpooler/res/menu/select_printer_activity.xml
index d4ce1cf..ee62f9f 100644
--- a/packages/PrintSpooler/res/menu/select_printer_activity.xml
+++ b/packages/PrintSpooler/res/menu/select_printer_activity.xml
@@ -21,14 +21,14 @@
android:title="@string/search"
android:icon="@*android:drawable/ic_menu_search_holo_light"
android:actionViewClass="android.widget.SearchView"
- android:showAsAction="ifRoom"
+ android:showAsAction="ifRoom|collapseActionView"
android:alphabeticShortcut="f"
android:imeOptions="actionSearch">
</item>
<item
android:id="@+id/action_add_printer"
- android:title="@null"
+ android:title="@string/print_add_printer"
android:icon="@*android:drawable/create_contact"
android:showAsAction="ifRoom"
android:alphabeticShortcut="a">
diff --git a/packages/PrintSpooler/res/values/strings.xml b/packages/PrintSpooler/res/values/strings.xml
index 7e1708e..c82a20e 100644
--- a/packages/PrintSpooler/res/values/strings.xml
+++ b/packages/PrintSpooler/res/values/strings.xml
@@ -67,6 +67,9 @@
<!-- Title for the open all printers UI option in the printer list. [CHAR LIMIT=30] -->
<string name="all_printers">All printers…</string>
+ <!-- Title for the print dialog announced to the user for accessibility. Not shown in the UI. [CHAR LIMIT=none] -->
+ <string name="print_dialog">Print dialog</string>
+
<!-- Select printer activity -->
<!-- Title for the share action bar menu item. [CHAR LIMIT=20] -->
@@ -78,6 +81,21 @@
<!-- Title of the button to install a print service. [CHAR LIMIT=25] -->
<string name="add_print_service_label">Add service</string>
+ <!-- Utterance to announce that the search box is shown. This is spoken to a blind user. [CHAR LIMIT=none] -->
+ <string name="print_search_box_shown_utterance">Search box shown</string>
+
+ <!-- Utterance to announce that the search box is hidden. This is spoken to a blind user. [CHAR LIMIT=none] -->
+ <string name="print_search_box_hidden_utterance">Search box hidden</string>
+
+ <!-- Title of the action bar button to got to add a printer. [CHAR LIMIT=25] -->
+ <string name="print_add_printer">Add printer</string>
+
+ <!-- Utterance to announce a change in the number of matches during a search. This is spoken to a blind user. [CHAR LIMIT=none] -->
+ <plurals name="print_search_result_count_utterance">
+ <item quantity="one"><xliff:g id="count" example="1">%1$s</xliff:g> printer found</item>
+ <item quantity="other"><xliff:g id="count" example="2">%1$s</xliff:g> printers found</item>
+ </plurals>
+
<!-- Add printer dialog -->
<!-- Title for the alert dialog for selecting a print service. [CHAR LIMIT=50] -->
diff --git a/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java b/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java
index f50cdfd..7f9be6c 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java
@@ -178,6 +178,8 @@
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
+ setTitle(R.string.print_dialog);
+
Bundle extras = getIntent().getExtras();
PrintJobInfo printJob = extras.getParcelable(EXTRA_PRINT_JOB);
diff --git a/packages/PrintSpooler/src/com/android/printspooler/SelectPrinterFragment.java b/packages/PrintSpooler/src/com/android/printspooler/SelectPrinterFragment.java
index 62673b2..b8a9417 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/SelectPrinterFragment.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/SelectPrinterFragment.java
@@ -82,6 +82,8 @@
private final ArrayList<PrintServiceInfo> mAddPrinterServices =
new ArrayList<PrintServiceInfo>();
+ private AnnounceFilterResult mAnnounceFilterResult;
+
public static interface OnPrinterSelectedListener {
public void onPrinterSelected(PrinterId printerId);
}
@@ -133,6 +135,18 @@
return true;
}
});
+ searchView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
+ @Override
+ public void onViewAttachedToWindow(View view) {
+ view.announceForAccessibility(getString(
+ R.string.print_search_box_shown_utterance));
+ }
+ @Override
+ public void onViewDetachedFromWindow(View view) {
+ view.announceForAccessibility(getString(
+ R.string.print_search_box_hidden_utterance));
+ }
+ });
if (mAddPrinterServices.isEmpty()) {
menu.removeItem(R.id.action_add_printer);
@@ -245,6 +259,13 @@
}
}
+ private void announceSearchResult() {
+ if (mAnnounceFilterResult == null) {
+ mAnnounceFilterResult = new AnnounceFilterResult();
+ }
+ mAnnounceFilterResult.post();
+ }
+
public static class AddPrinterAlertDialogFragment extends DialogFragment {
private String mAddPrintServiceItem;
@@ -355,7 +376,9 @@
@Override
@SuppressWarnings("unchecked")
protected void publishResults(CharSequence constraint, FilterResults results) {
+ final boolean resultCountChanged;
synchronized (mLock) {
+ final int oldPrinterCount = mFilteredPrinters.size();
mLastSearchString = constraint;
mFilteredPrinters.clear();
if (results == null) {
@@ -364,6 +387,10 @@
List<PrinterInfo> printers = (List<PrinterInfo>) results.values;
mFilteredPrinters.addAll(printers);
}
+ resultCountChanged = (oldPrinterCount != mFilteredPrinters.size());
+ }
+ if (resultCountChanged) {
+ announceSearchResult();
}
notifyDataSetChanged();
}
@@ -480,4 +507,30 @@
notifyDataSetInvalidated();
}
}
+
+ private final class AnnounceFilterResult implements Runnable {
+ private static final int SEARCH_RESULT_ANNOUNCEMENT_DELAY = 1000; // 1 sec
+
+ public void post() {
+ remove();
+ getListView().postDelayed(this, SEARCH_RESULT_ANNOUNCEMENT_DELAY);
+ }
+
+ public void remove() {
+ getListView().removeCallbacks(this);
+ }
+
+ @Override
+ public void run() {
+ final int count = getListView().getAdapter().getCount();
+ final String text;
+ if (count <= 0) {
+ text = getString(R.string.print_no_printers);
+ } else {
+ text = getActivity().getResources().getQuantityString(
+ R.plurals.print_search_result_count_utterance, count, count);
+ }
+ getListView().announceForAccessibility(text);
+ }
+ }
}