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">
<!-- 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] -->
<!-- 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] -->
private final ArrayList<PrintServiceInfo> mAddPrinterServices =
new ArrayList<PrintServiceInfo>();
+ private AnnounceFilterResult mAnnounceFilterResult;
+
public static interface OnPrinterSelectedListener {
public void onPrinterSelected(PrinterId printerId);
}
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);
}
}
+ private void announceSearchResult() {
+ if (mAnnounceFilterResult == null) {
+ mAnnounceFilterResult = new AnnounceFilterResult();
+ }
+ mAnnounceFilterResult.post();
+ }
+
public static class AddPrinterAlertDialogFragment extends DialogFragment {
private String mAddPrintServiceItem;
@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) {
List<PrinterInfo> printers = (List<PrinterInfo>) results.values;
mFilteredPrinters.addAll(printers);
}
+ resultCountChanged = (oldPrinterCount != mFilteredPrinters.size());
+ }
+ if (resultCountChanged) {
+ announceSearchResult();
}
notifyDataSetChanged();
}
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);
+ }
+ }
}