</ImageView>
<TextView
+ android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
</TextView>
<ProgressBar
+ android:id="@+id/progress_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
<!-- 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] -->
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;
@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);
}
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;
};
}
+ public int getUnfilteredCount() {
+ synchronized (mLock) {
+ return mPrinters.size();
+ }
+ }
+
@Override
public int getCount() {
synchronized (mLock) {