Merge "Update the empty state for the "all printers activity"" into klp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
589a550596
@@ -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"
|
||||
|
||||
@@ -83,9 +83,12 @@
|
||||
<!-- 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] -->
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user