OSDN Git Service

Update the empty state for the "all printers activity"
authorSvetoslav Ganov <svetoslavganov@google.com>
Sat, 5 Oct 2013 19:58:17 +0000 (12:58 -0700)
committerSvetoslav Ganov <svetoslavganov@google.com>
Sat, 5 Oct 2013 19:58:22 +0000 (12:58 -0700)
The empty state is now showing searching for printers hint if
the user is not searching, otherwise the empty state's hint is
a searching for printers message.

bug:10983508

Change-Id: I3df79c167546998c8055d9ff85efa8b460a15e48

packages/PrintSpooler/res/layout/select_printer_activity.xml
packages/PrintSpooler/res/values/strings.xml
packages/PrintSpooler/src/com/android/printspooler/SelectPrinterFragment.java

index 2792dcf..6fc77df 100644 (file)
@@ -48,6 +48,7 @@
             </ImageView>
 
             <TextView
+                android:id="@+id/title"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:textAppearance="?android:attr/textAppearanceLarge"
@@ -56,6 +57,7 @@
             </TextView>
 
             <ProgressBar
+                android:id="@+id/progress_bar"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:indeterminate="true"
index 3a888a8..7e1708e 100644 (file)
     <!-- Title for the alert dialog for selecting a print service. [CHAR LIMIT=50] -->
     <string name="choose_print_service">Choose print service</string>
 
-    <!-- Title for the prompt shown as a placeholder if no printers are found while searching. [CHAR LIMIT=50] -->
+    <!-- Title for the prompt shown as a placeholder if no printers are found while not searching. [CHAR LIMIT=50] -->
     <string name="print_searching_for_printers">Searching for printers</string>
 
+    <!-- Title for the prompt shown as a placeholder if there are no printers while searching. [CHAR LIMIT=50] -->
+    <string name="print_no_printers">No printers found</string>
+
     <!-- Notifications -->
 
     <!-- Template for the notificaiton label for a printing print job. [CHAR LIMIT=25] -->
index 0f29614..4ce7d05 100644 (file)
@@ -36,6 +36,7 @@ import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.pm.ResolveInfo;
 import android.content.pm.ServiceInfo;
+import android.database.DataSetObserver;
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.os.Bundle;
@@ -94,7 +95,21 @@ public final class SelectPrinterFragment extends ListFragment {
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
-        setListAdapter(new DestinationAdapter());
+        final DestinationAdapter adapter = new DestinationAdapter();
+        adapter.registerDataSetObserver(new DataSetObserver() {
+            @Override
+            public void onChanged() {
+                if (adapter.getCount() <= 0) {
+                    updateEmptyView(adapter);
+                }
+            }
+
+            @Override
+            public void onInvalidated() {
+                updateEmptyView(adapter);
+            }
+        });
+        setListAdapter(adapter);
         View emptyView = getActivity().findViewById(R.id.empty_print_state);
         getListView().setEmptyView(emptyView);
     }
@@ -214,6 +229,18 @@ public final class SelectPrinterFragment extends ListFragment {
         transaction.commit();
     }
 
+    public void updateEmptyView(DestinationAdapter adapter) {
+        TextView titleView = (TextView) getActivity().findViewById(R.id.title);
+        View progressBar = getActivity().findViewById(R.id.progress_bar);
+        if (adapter.getUnfilteredCount() <= 0) {
+            titleView.setText(R.string.print_searching_for_printers);
+            progressBar.setVisibility(View.VISIBLE);
+        } else {
+            titleView.setText(R.string.print_no_printers);
+            progressBar.setVisibility(View.GONE);
+        }
+    }
+
     public static class AddPrinterAlertDialogFragment extends DialogFragment {
 
         private String mAddPrintServiceItem;
@@ -339,6 +366,12 @@ public final class SelectPrinterFragment extends ListFragment {
             };
         }
 
+        public int getUnfilteredCount() {
+            synchronized (mLock) {
+                return mPrinters.size();
+            }
+        }
+
         @Override
         public int getCount() {
             synchronized (mLock) {