Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 253b628d authored by Svetoslav Ganov's avatar Svetoslav Ganov Committed by Android (Google) Code Review
Browse files

Merge "Update all printers activity's empty state and avoid selected printer flicker." into klp-dev

parents 589a5505 24c686b8
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@
    </style>

    <style name="PrintOptionEditTextStyle">
         <item name="android:selectAllOnFocus">true</item>
         <item name="android:minHeight">?android:attr/listPreferredItemHeightSmall</item>
         <item name="android:singleLine">true</item>
         <item name="android:ellipsize">end</item>
+5 −6
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
    private static final boolean DEBUG = false;

    private static final double WEIGHT_DECAY_COEFFICIENT = 0.95f;

    private static final int MAX_HISTORY_LENGTH = 50;

    private static final int MAX_FAVORITE_PRINTER_COUNT = 4;
@@ -388,25 +387,25 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
                            + FusedPrintersProvider.this.hashCode());
                }

                // Ignore printer records whose target services are not installed.
                // Ignore printer records whose target services are not enabled.
                PrintManager printManager = (PrintManager) getContext()
                        .getSystemService(Context.PRINT_SERVICE);
                List<PrintServiceInfo> services = printManager
                        .getInstalledPrintServices();
                        .getEnabledPrintServices();

                Set<ComponentName> installedComponents = new ArraySet<ComponentName>();
                Set<ComponentName> enabledComponents = new ArraySet<ComponentName>();
                final int installedServiceCount = services.size();
                for (int i = 0; i < installedServiceCount; i++) {
                    ServiceInfo serviceInfo = services.get(i).getResolveInfo().serviceInfo;
                    ComponentName componentName = new ComponentName(
                            serviceInfo.packageName, serviceInfo.name);
                    installedComponents.add(componentName);
                    enabledComponents.add(componentName);
                }

                final int printerCount = printers.size();
                for (int i = printerCount - 1; i >= 0; i--) {
                    ComponentName printerServiceName = printers.get(i).getId().getServiceName();
                    if (!installedComponents.contains(printerServiceName.getPackageName())) {
                    if (!enabledComponents.contains(printerServiceName)) {
                        printers.remove(i);
                    }
                }
+21 −14
Original line number Diff line number Diff line
@@ -1214,7 +1214,7 @@ public class PrintJobConfigActivity extends Activity {

                                if (capabilitiesChanged || statusChanged) {
                                    // If something changed during update...
                                    if (updateUi()) {
                                    if (updateUi() || !mController.hasPerformedLayout()) {
                                        // Update the document.
                                        mController.update();
                                    }
@@ -1269,10 +1269,6 @@ public class PrintJobConfigActivity extends Activity {

            showUi(UI_EDITING_PRINT_JOB, null);
            bindUi();

            mCurrentPrinter = mDestinationSpinnerAdapter.mFakePdfPrinter;
            updatePrintAttributes(mCurrentPrinter.getCapabilities());

            updateUi();
        }

@@ -2001,11 +1997,10 @@ public class PrintJobConfigActivity extends Activity {
                implements LoaderManager.LoaderCallbacks<List<PrinterInfo>>{
            private final List<PrinterInfo> mPrinters = new ArrayList<PrinterInfo>();

            private final PrinterInfo mFakePdfPrinter;
            private PrinterInfo mFakePdfPrinter;

            public DestinationAdapter() {
                getLoaderManager().initLoader(LOADER_ID_PRINTERS_LOADER, null, this);
                mFakePdfPrinter = createFakePdfPrinter();
            }

            public int getPrinterIndex(PrinterId printerId) {
@@ -2039,7 +2034,9 @@ public class PrintJobConfigActivity extends Activity {

            @Override
            public int getCount() {
                return Math.min(mPrinters.size() + 2, DEST_ADAPTER_MAX_ITEM_COUNT);
                final int additionalItemCount = (mFakePdfPrinter != null) ? 2 : 1;
                return Math.min(mPrinters.size() + additionalItemCount,
                        DEST_ADAPTER_MAX_ITEM_COUNT);
            }

            @Override
@@ -2055,14 +2052,14 @@ public class PrintJobConfigActivity extends Activity {
            @Override
            public Object getItem(int position) {
                if (mPrinters.isEmpty()) {
                    if (position == 0) {
                    if (position == 0 && mFakePdfPrinter != null) {
                        return mFakePdfPrinter;
                    }
                } else {
                    if (position < 1) {
                        return mPrinters.get(position);
                    }
                    if (position == 1) {
                    if (position == 1 && mFakePdfPrinter != null) {
                        return mFakePdfPrinter;
                    }
                    if (position < getCount() - 1) {
@@ -2075,14 +2072,14 @@ public class PrintJobConfigActivity extends Activity {
            @Override
            public long getItemId(int position) {
                if (mPrinters.isEmpty()) {
                    if (position == 0) {
                    if (position == 0 && mFakePdfPrinter != null) {
                        return DEST_ADAPTER_ITEM_ID_SAVE_AS_PDF;
                    }
                    if (position == 1) {
                        return DEST_ADAPTER_ITEM_ID_ALL_PRINTERS;
                    }
                } else {
                    if (position == 1) {
                    if (position == 1 && mFakePdfPrinter != null) {
                        return DEST_ADAPTER_ITEM_ID_SAVE_AS_PDF;
                    }
                    if (position == getCount() - 1) {
@@ -2114,14 +2111,14 @@ public class PrintJobConfigActivity extends Activity {
                Drawable icon = null;

                if (mPrinters.isEmpty()) {
                    if (position == 0) {
                    if (position == 0 && mFakePdfPrinter != null) {
                        PrinterInfo printer = (PrinterInfo) getItem(position);
                        title = printer.getName();
                    } else if (position == 1) {
                        title = getString(R.string.all_printers);
                    }
                } else {
                    if (position == 1) {
                    if (position == 1 && mFakePdfPrinter != null) {
                        PrinterInfo printer = (PrinterInfo) getItem(position);
                        title = printer.getName();
                    } else if (position == getCount() - 1) {
@@ -2174,6 +2171,16 @@ public class PrintJobConfigActivity extends Activity {
            @Override
            public void onLoadFinished(Loader<List<PrinterInfo>> loader,
                    List<PrinterInfo> printers) {
                // If this is the first load, create the fake PDF printer.
                // We do this to avoid flicker where the PDF printer is the
                // only one and as soon as the loader loads the favorites
                // it gets switched. Not a great user experience.
                if (mFakePdfPrinter == null) {
                    mCurrentPrinter = mFakePdfPrinter = createFakePdfPrinter();
                    updatePrintAttributes(mCurrentPrinter.getCapabilities());
                    updateUi();
                }

                // We rearrange the printers if the user selects a printer
                // not shown in the initial short list. Therefore, we have
                // to keep the printer order.
+8 −4
Original line number Diff line number Diff line
@@ -99,19 +99,19 @@ public final class SelectPrinterFragment extends ListFragment {
        adapter.registerDataSetObserver(new DataSetObserver() {
            @Override
            public void onChanged() {
                if (adapter.getCount() <= 0) {
                if (!getActivity().isFinishing() && adapter.getCount() <= 0) {
                    updateEmptyView(adapter);
                }
            }

            @Override
            public void onInvalidated() {
                if (!getActivity().isFinishing()) {
                    updateEmptyView(adapter);
                }
            }
        });
        setListAdapter(adapter);
        View emptyView = getActivity().findViewById(R.id.empty_print_state);
        getListView().setEmptyView(emptyView);
    }

    @Override
@@ -230,6 +230,10 @@ public final class SelectPrinterFragment extends ListFragment {
    }

    public void updateEmptyView(DestinationAdapter adapter) {
        if (getListView().getEmptyView() == null) {
            View emptyView = getActivity().findViewById(R.id.empty_print_state);
            getListView().setEmptyView(emptyView);
        }
        TextView titleView = (TextView) getActivity().findViewById(R.id.title);
        View progressBar = getActivity().findViewById(R.id.progress_bar);
        if (adapter.getUnfilteredCount() <= 0) {