Merge "Update print document view if printer capabilities changed" into nyc-dev
am: 59d12c6a27
* commit '59d12c6a27c3c928823b336e3f0c85a12a31f1ae':
Update print document view if printer capabilities changed
This commit is contained in:
@@ -236,6 +236,9 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
|
|||||||
|
|
||||||
private int mUiState = UI_STATE_PREVIEW;
|
private int mUiState = UI_STATE_PREVIEW;
|
||||||
|
|
||||||
|
/** Observer for changes to the printers */
|
||||||
|
private PrintersObserver mPrintersObserver;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -1191,7 +1194,8 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
|
|||||||
mCopiesEditText.addTextChangedListener(new EditTextWatcher());
|
mCopiesEditText.addTextChangedListener(new EditTextWatcher());
|
||||||
|
|
||||||
// Destination.
|
// Destination.
|
||||||
mDestinationSpinnerAdapter.registerDataSetObserver(new PrintersObserver());
|
mPrintersObserver = new PrintersObserver();
|
||||||
|
mDestinationSpinnerAdapter.registerDataSetObserver(mPrintersObserver);
|
||||||
mDestinationSpinner = (Spinner) findViewById(R.id.destination_spinner);
|
mDestinationSpinner = (Spinner) findViewById(R.id.destination_spinner);
|
||||||
mDestinationSpinner.setAdapter(mDestinationSpinnerAdapter);
|
mDestinationSpinner.setAdapter(mDestinationSpinnerAdapter);
|
||||||
mDestinationSpinner.setOnItemSelectedListener(itemSelectedListener);
|
mDestinationSpinner.setOnItemSelectedListener(itemSelectedListener);
|
||||||
@@ -1969,6 +1973,10 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
|
|||||||
mPrinterRegistry.setTrackedPrinter(null);
|
mPrinterRegistry.setTrackedPrinter(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mPrintersObserver != null) {
|
||||||
|
mDestinationSpinnerAdapter.unregisterDataSetObserver(mPrintersObserver);
|
||||||
|
}
|
||||||
|
|
||||||
if (mState != STATE_INITIALIZING) {
|
if (mState != STATE_INITIALIZING) {
|
||||||
mProgressMessageController.cancel();
|
mProgressMessageController.cancel();
|
||||||
mSpoolerProvider.destroy();
|
mSpoolerProvider.destroy();
|
||||||
@@ -2449,6 +2457,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
|
|||||||
PrinterCapabilitiesInfo oldCapab = oldPrinterState.getCapabilities();
|
PrinterCapabilitiesInfo oldCapab = oldPrinterState.getCapabilities();
|
||||||
PrinterCapabilitiesInfo newCapab = newPrinterState.getCapabilities();
|
PrinterCapabilitiesInfo newCapab = newPrinterState.getCapabilities();
|
||||||
|
|
||||||
|
final boolean hadCabab = oldCapab != null;
|
||||||
final boolean hasCapab = newCapab != null;
|
final boolean hasCapab = newCapab != null;
|
||||||
final boolean gotCapab = oldCapab == null && newCapab != null;
|
final boolean gotCapab = oldCapab == null && newCapab != null;
|
||||||
final boolean lostCapab = oldCapab != null && newCapab == null;
|
final boolean lostCapab = oldCapab != null && newCapab == null;
|
||||||
@@ -2467,19 +2476,23 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
|
|||||||
|
|
||||||
mCurrentPrinter = newPrinterState;
|
mCurrentPrinter = newPrinterState;
|
||||||
|
|
||||||
if ((isActive && gotCapab) || (becameActive && hasCapab)) {
|
|
||||||
if (hasCapab && capabChanged) {
|
|
||||||
updatePrintAttributesFromCapabilities(newCapab);
|
|
||||||
updatePrintPreviewController(false);
|
|
||||||
}
|
|
||||||
onPrinterAvailable(newPrinterState);
|
|
||||||
} else if ((becameInactive && hasCapab) || (isActive && lostCapab)) {
|
|
||||||
onPrinterUnavailable(newPrinterState);
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean updateNeeded = ((capabChanged && hasCapab && isActive)
|
final boolean updateNeeded = ((capabChanged && hasCapab && isActive)
|
||||||
|| (becameActive && hasCapab) || (isActive && gotCapab));
|
|| (becameActive && hasCapab) || (isActive && gotCapab));
|
||||||
|
|
||||||
|
if (capabChanged && hasCapab) {
|
||||||
|
updatePrintAttributesFromCapabilities(newCapab);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updateNeeded) {
|
||||||
|
updatePrintPreviewController(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((isActive && gotCapab) || (becameActive && hasCapab)) {
|
||||||
|
onPrinterAvailable(newPrinterState);
|
||||||
|
} else if ((becameInactive && hadCabab) || (isActive && lostCapab)) {
|
||||||
|
onPrinterUnavailable(newPrinterState);
|
||||||
|
}
|
||||||
|
|
||||||
if (updateNeeded && canUpdateDocument()) {
|
if (updateNeeded && canUpdateDocument()) {
|
||||||
updateDocument(false);
|
updateDocument(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user