Loading packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java +64 −31 Original line number Diff line number Diff line Loading @@ -128,8 +128,6 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat private static final boolean DEBUG = false; public static final String INTENT_EXTRA_PRINTER_ID = "INTENT_EXTRA_PRINTER_ID"; private static final String FRAGMENT_TAG = "FRAGMENT_TAG"; private static final String HAS_PRINTED_PREF = "has_printed"; Loading Loading @@ -707,21 +705,17 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat private void onSelectPrinterActivityResult(int resultCode, Intent data) { if (resultCode == RESULT_OK && data != null) { PrinterId printerId = data.getParcelableExtra(INTENT_EXTRA_PRINTER_ID); if (printerId != null) { mDestinationSpinnerAdapter.ensurePrinterInVisibleAdapterPosition(printerId); final int index = mDestinationSpinnerAdapter.getPrinterIndex(printerId); if (index != AdapterView.INVALID_POSITION) { mDestinationSpinner.setSelection(index); return; } PrinterInfo printerInfo = data.getParcelableExtra( SelectPrinterActivity.INTENT_EXTRA_PRINTER); if (printerInfo != null) { mCurrentPrinter = printerInfo; mDestinationSpinnerAdapter.ensurePrinterInVisibleAdapterPosition(printerInfo); } } if (mCurrentPrinter != null) { PrinterId printerId = mCurrentPrinter.getId(); final int index = mDestinationSpinnerAdapter.getPrinterIndex(printerId); mDestinationSpinner.setSelection(index); // Trigger PrintersObserver.onChanged() to adjust selection back to current printer mDestinationSpinnerAdapter.notifyDataSetChanged(); } } Loading Loading @@ -2246,23 +2240,36 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat return AdapterView.INVALID_POSITION; } public void ensurePrinterInVisibleAdapterPosition(PrinterId printerId) { public void ensurePrinterInVisibleAdapterPosition(PrinterInfo printer) { final int printerCount = mPrinterHolders.size(); boolean isKnownPrinter = false; for (int i = 0; i < printerCount; i++) { PrinterHolder printerHolder = mPrinterHolders.get(i); if (printerHolder.printer.getId().equals(printerId)) { if (printerHolder.printer.getId().equals(printer.getId())) { isKnownPrinter = true; // If already in the list - do nothing. if (i < getCount() - 2) { return; break; } // Else replace the last one (two items are not printers). final int lastPrinterIndex = getCount() - 3; mPrinterHolders.set(i, mPrinterHolders.get(lastPrinterIndex)); mPrinterHolders.set(lastPrinterIndex, printerHolder); notifyDataSetChanged(); return; break; } } if (!isKnownPrinter) { PrinterHolder printerHolder = new PrinterHolder(printer); printerHolder.removed = true; mPrinterHolders.add(Math.max(0, getCount() - 3), printerHolder); } // Force reload to adjust selection in PrintersObserver.onChanged() notifyDataSetChanged(); } @Override Loading Loading @@ -2445,8 +2452,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat List<PrinterHolder> newPrinterHolders = new ArrayList<>(); // Update printers we already have which are either updated or removed. // We do not remove printers if the currently selected printer is removed // to prevent the user printing to a wrong printer. // We do not remove the currently selected printer. final int oldPrinterCount = mPrinterHolders.size(); for (int i = 0; i < oldPrinterCount; i++) { PrinterHolder printerHolder = mPrinterHolders.get(i); Loading @@ -2455,11 +2461,12 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat if (updatedPrinter != null) { printerHolder.printer = updatedPrinter; printerHolder.removed = false; } else { newPrinterHolders.add(printerHolder); } else if (mCurrentPrinter != null && mCurrentPrinter.getId().equals(oldPrinterId)){ printerHolder.removed = true; } newPrinterHolders.add(printerHolder); } } // Add the rest of the new printers, i.e. what is left. addPrinters(newPrinterHolders, newPrintersMap.values()); Loading Loading @@ -2490,14 +2497,25 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat return null; } public void pruneRemovedPrinters() { /** * Remove a printer from the holders if it is marked as removed. * * @param printerId the id of the printer to remove. * * @return true iff the printer was removed. */ public boolean pruneRemovedPrinter(PrinterId printerId) { final int holderCounts = mPrinterHolders.size(); for (int i = holderCounts - 1; i >= 0; i--) { PrinterHolder printerHolder = mPrinterHolders.get(i); if (printerHolder.removed) { if (printerHolder.printer.getId().equals(printerId) && printerHolder.removed) { mPrinterHolders.remove(i); return true; } } return false; } private void addPrinters(List<PrinterHolder> list, Collection<PrinterInfo> printers) { Loading Loading @@ -2542,17 +2560,17 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat PrinterHolder printerHolder = mDestinationSpinnerAdapter.getPrinterHolder( oldPrinterState.getId()); if (printerHolder == null) { return; } PrinterInfo newPrinterState = printerHolder.printer; if (!printerHolder.removed) { mDestinationSpinnerAdapter.pruneRemovedPrinters(); } else { if (printerHolder.removed) { onPrinterUnavailable(newPrinterState); } if (mDestinationSpinner.getSelectedItem() != printerHolder) { mDestinationSpinner.setSelection( mDestinationSpinnerAdapter.getPrinterIndex(newPrinterState.getId())); } if (oldPrinterState.equals(newPrinterState)) { return; } Loading Loading @@ -2644,13 +2662,28 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat return; } PrinterId oldId = null; if (mCurrentPrinter != null) { oldId = mCurrentPrinter.getId(); } mCurrentPrinter = currentPrinter; if (oldId != null) { boolean printerRemoved = mDestinationSpinnerAdapter.pruneRemovedPrinter(oldId); if (printerRemoved) { // Trigger PrinterObserver.onChanged to adjust selection. This will call // this function again. mDestinationSpinnerAdapter.notifyDataSetChanged(); return; } } PrinterHolder printerHolder = mDestinationSpinnerAdapter.getPrinterHolder( currentPrinter.getId()); if (!printerHolder.removed) { setState(STATE_CONFIGURING); mDestinationSpinnerAdapter.pruneRemovedPrinters(); ensurePreviewUiShown(); } Loading packages/PrintSpooler/src/com/android/printspooler/ui/SelectPrinterActivity.java +8 −7 Original line number Diff line number Diff line Loading @@ -73,8 +73,9 @@ public final class SelectPrinterActivity extends Activity implements private static final int LOADER_ID_PRINT_REGISTRY_INT = 2; private static final int LOADER_ID_ENABLED_PRINT_SERVICES = 3; public static final String INTENT_EXTRA_PRINTER_ID = "INTENT_EXTRA_PRINTER_ID"; public static final String INTENT_EXTRA_PRINTER = "INTENT_EXTRA_PRINTER"; private static final String EXTRA_PRINTER = "EXTRA_PRINTER"; private static final String EXTRA_PRINTER_ID = "EXTRA_PRINTER_ID"; private static final String KEY_NOT_FIRST_CREATE = "KEY_NOT_FIRST_CREATE"; Loading Loading @@ -134,7 +135,7 @@ public final class SelectPrinterActivity extends Activity implements if (printer == null) { startAddPrinterActivity(); } else { onPrinterSelected(printer.getId()); onPrinterSelected(printer); } } }); Loading Loading @@ -244,7 +245,7 @@ public final class SelectPrinterActivity extends Activity implements MenuItem selectItem = menu.add(Menu.NONE, R.string.print_select_printer, Menu.NONE, R.string.print_select_printer); Intent intent = new Intent(); intent.putExtra(EXTRA_PRINTER_ID, printer.getId()); intent.putExtra(EXTRA_PRINTER, printer); selectItem.setIntent(intent); } Loading @@ -263,8 +264,8 @@ public final class SelectPrinterActivity extends Activity implements public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case R.string.print_select_printer: { PrinterId printerId = item.getIntent().getParcelableExtra(EXTRA_PRINTER_ID); onPrinterSelected(printerId); PrinterInfo printer = item.getIntent().getParcelableExtra(EXTRA_PRINTER); onPrinterSelected(printer); } return true; case R.string.print_forget_printer: { Loading Loading @@ -302,9 +303,9 @@ public final class SelectPrinterActivity extends Activity implements super.onStop(); } private void onPrinterSelected(PrinterId printerId) { private void onPrinterSelected(PrinterInfo printer) { Intent intent = new Intent(); intent.putExtra(INTENT_EXTRA_PRINTER_ID, printerId); intent.putExtra(INTENT_EXTRA_PRINTER, printer); setResult(RESULT_OK, intent); finish(); } Loading Loading
packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java +64 −31 Original line number Diff line number Diff line Loading @@ -128,8 +128,6 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat private static final boolean DEBUG = false; public static final String INTENT_EXTRA_PRINTER_ID = "INTENT_EXTRA_PRINTER_ID"; private static final String FRAGMENT_TAG = "FRAGMENT_TAG"; private static final String HAS_PRINTED_PREF = "has_printed"; Loading Loading @@ -707,21 +705,17 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat private void onSelectPrinterActivityResult(int resultCode, Intent data) { if (resultCode == RESULT_OK && data != null) { PrinterId printerId = data.getParcelableExtra(INTENT_EXTRA_PRINTER_ID); if (printerId != null) { mDestinationSpinnerAdapter.ensurePrinterInVisibleAdapterPosition(printerId); final int index = mDestinationSpinnerAdapter.getPrinterIndex(printerId); if (index != AdapterView.INVALID_POSITION) { mDestinationSpinner.setSelection(index); return; } PrinterInfo printerInfo = data.getParcelableExtra( SelectPrinterActivity.INTENT_EXTRA_PRINTER); if (printerInfo != null) { mCurrentPrinter = printerInfo; mDestinationSpinnerAdapter.ensurePrinterInVisibleAdapterPosition(printerInfo); } } if (mCurrentPrinter != null) { PrinterId printerId = mCurrentPrinter.getId(); final int index = mDestinationSpinnerAdapter.getPrinterIndex(printerId); mDestinationSpinner.setSelection(index); // Trigger PrintersObserver.onChanged() to adjust selection back to current printer mDestinationSpinnerAdapter.notifyDataSetChanged(); } } Loading Loading @@ -2246,23 +2240,36 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat return AdapterView.INVALID_POSITION; } public void ensurePrinterInVisibleAdapterPosition(PrinterId printerId) { public void ensurePrinterInVisibleAdapterPosition(PrinterInfo printer) { final int printerCount = mPrinterHolders.size(); boolean isKnownPrinter = false; for (int i = 0; i < printerCount; i++) { PrinterHolder printerHolder = mPrinterHolders.get(i); if (printerHolder.printer.getId().equals(printerId)) { if (printerHolder.printer.getId().equals(printer.getId())) { isKnownPrinter = true; // If already in the list - do nothing. if (i < getCount() - 2) { return; break; } // Else replace the last one (two items are not printers). final int lastPrinterIndex = getCount() - 3; mPrinterHolders.set(i, mPrinterHolders.get(lastPrinterIndex)); mPrinterHolders.set(lastPrinterIndex, printerHolder); notifyDataSetChanged(); return; break; } } if (!isKnownPrinter) { PrinterHolder printerHolder = new PrinterHolder(printer); printerHolder.removed = true; mPrinterHolders.add(Math.max(0, getCount() - 3), printerHolder); } // Force reload to adjust selection in PrintersObserver.onChanged() notifyDataSetChanged(); } @Override Loading Loading @@ -2445,8 +2452,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat List<PrinterHolder> newPrinterHolders = new ArrayList<>(); // Update printers we already have which are either updated or removed. // We do not remove printers if the currently selected printer is removed // to prevent the user printing to a wrong printer. // We do not remove the currently selected printer. final int oldPrinterCount = mPrinterHolders.size(); for (int i = 0; i < oldPrinterCount; i++) { PrinterHolder printerHolder = mPrinterHolders.get(i); Loading @@ -2455,11 +2461,12 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat if (updatedPrinter != null) { printerHolder.printer = updatedPrinter; printerHolder.removed = false; } else { newPrinterHolders.add(printerHolder); } else if (mCurrentPrinter != null && mCurrentPrinter.getId().equals(oldPrinterId)){ printerHolder.removed = true; } newPrinterHolders.add(printerHolder); } } // Add the rest of the new printers, i.e. what is left. addPrinters(newPrinterHolders, newPrintersMap.values()); Loading Loading @@ -2490,14 +2497,25 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat return null; } public void pruneRemovedPrinters() { /** * Remove a printer from the holders if it is marked as removed. * * @param printerId the id of the printer to remove. * * @return true iff the printer was removed. */ public boolean pruneRemovedPrinter(PrinterId printerId) { final int holderCounts = mPrinterHolders.size(); for (int i = holderCounts - 1; i >= 0; i--) { PrinterHolder printerHolder = mPrinterHolders.get(i); if (printerHolder.removed) { if (printerHolder.printer.getId().equals(printerId) && printerHolder.removed) { mPrinterHolders.remove(i); return true; } } return false; } private void addPrinters(List<PrinterHolder> list, Collection<PrinterInfo> printers) { Loading Loading @@ -2542,17 +2560,17 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat PrinterHolder printerHolder = mDestinationSpinnerAdapter.getPrinterHolder( oldPrinterState.getId()); if (printerHolder == null) { return; } PrinterInfo newPrinterState = printerHolder.printer; if (!printerHolder.removed) { mDestinationSpinnerAdapter.pruneRemovedPrinters(); } else { if (printerHolder.removed) { onPrinterUnavailable(newPrinterState); } if (mDestinationSpinner.getSelectedItem() != printerHolder) { mDestinationSpinner.setSelection( mDestinationSpinnerAdapter.getPrinterIndex(newPrinterState.getId())); } if (oldPrinterState.equals(newPrinterState)) { return; } Loading Loading @@ -2644,13 +2662,28 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat return; } PrinterId oldId = null; if (mCurrentPrinter != null) { oldId = mCurrentPrinter.getId(); } mCurrentPrinter = currentPrinter; if (oldId != null) { boolean printerRemoved = mDestinationSpinnerAdapter.pruneRemovedPrinter(oldId); if (printerRemoved) { // Trigger PrinterObserver.onChanged to adjust selection. This will call // this function again. mDestinationSpinnerAdapter.notifyDataSetChanged(); return; } } PrinterHolder printerHolder = mDestinationSpinnerAdapter.getPrinterHolder( currentPrinter.getId()); if (!printerHolder.removed) { setState(STATE_CONFIGURING); mDestinationSpinnerAdapter.pruneRemovedPrinters(); ensurePreviewUiShown(); } Loading
packages/PrintSpooler/src/com/android/printspooler/ui/SelectPrinterActivity.java +8 −7 Original line number Diff line number Diff line Loading @@ -73,8 +73,9 @@ public final class SelectPrinterActivity extends Activity implements private static final int LOADER_ID_PRINT_REGISTRY_INT = 2; private static final int LOADER_ID_ENABLED_PRINT_SERVICES = 3; public static final String INTENT_EXTRA_PRINTER_ID = "INTENT_EXTRA_PRINTER_ID"; public static final String INTENT_EXTRA_PRINTER = "INTENT_EXTRA_PRINTER"; private static final String EXTRA_PRINTER = "EXTRA_PRINTER"; private static final String EXTRA_PRINTER_ID = "EXTRA_PRINTER_ID"; private static final String KEY_NOT_FIRST_CREATE = "KEY_NOT_FIRST_CREATE"; Loading Loading @@ -134,7 +135,7 @@ public final class SelectPrinterActivity extends Activity implements if (printer == null) { startAddPrinterActivity(); } else { onPrinterSelected(printer.getId()); onPrinterSelected(printer); } } }); Loading Loading @@ -244,7 +245,7 @@ public final class SelectPrinterActivity extends Activity implements MenuItem selectItem = menu.add(Menu.NONE, R.string.print_select_printer, Menu.NONE, R.string.print_select_printer); Intent intent = new Intent(); intent.putExtra(EXTRA_PRINTER_ID, printer.getId()); intent.putExtra(EXTRA_PRINTER, printer); selectItem.setIntent(intent); } Loading @@ -263,8 +264,8 @@ public final class SelectPrinterActivity extends Activity implements public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case R.string.print_select_printer: { PrinterId printerId = item.getIntent().getParcelableExtra(EXTRA_PRINTER_ID); onPrinterSelected(printerId); PrinterInfo printer = item.getIntent().getParcelableExtra(EXTRA_PRINTER); onPrinterSelected(printer); } return true; case R.string.print_forget_printer: { Loading Loading @@ -302,9 +303,9 @@ public final class SelectPrinterActivity extends Activity implements super.onStop(); } private void onPrinterSelected(PrinterId printerId) { private void onPrinterSelected(PrinterInfo printer) { Intent intent = new Intent(); intent.putExtra(INTENT_EXTRA_PRINTER_ID, printerId); intent.putExtra(INTENT_EXTRA_PRINTER, printer); setResult(RESULT_OK, intent); finish(); } Loading