Merge \"Prevent PrintRegistry callbacks when finishing\" into nyc-mr1-dev
am: 4b24c48e23
Change-Id: I937876d007e0102e5dcd1f451638543d23941ce6
This commit is contained in:
@@ -2060,6 +2060,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
|
|||||||
|
|
||||||
if (mPrinterRegistry != null) {
|
if (mPrinterRegistry != null) {
|
||||||
mPrinterRegistry.setTrackedPrinter(null);
|
mPrinterRegistry.setTrackedPrinter(null);
|
||||||
|
mPrinterRegistry.setOnPrintersChangeListener(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mPrintersObserver != null) {
|
if (mPrintersObserver != null) {
|
||||||
|
|||||||
@@ -120,13 +120,11 @@ public class PrinterRegistry {
|
|||||||
@Override
|
@Override
|
||||||
public void onLoaderReset(Loader<List<PrinterInfo>> loader) {
|
public void onLoaderReset(Loader<List<PrinterInfo>> loader) {
|
||||||
mPrinters.clear();
|
mPrinters.clear();
|
||||||
if (mOnPrintersChangeListener != null) {
|
|
||||||
// Post a message as we are in onLoadFinished and certain operations
|
// Post a message as we are in onLoadFinished and certain operations
|
||||||
// are not allowed in this callback, such as fragment transactions.
|
// are not allowed in this callback, such as fragment transactions.
|
||||||
// Clients should not handle this explicitly.
|
// Clients should not handle this explicitly.
|
||||||
mHandler.obtainMessage(MyHandler.MSG_PRINTERS_INVALID,
|
mHandler.obtainMessage(MyHandler.MSG_PRINTERS_INVALID).sendToTarget();
|
||||||
mOnPrintersChangeListener).sendToTarget();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoaderCallbacks#onLoadFinished
|
// LoaderCallbacks#onLoadFinished
|
||||||
@@ -134,15 +132,12 @@ public class PrinterRegistry {
|
|||||||
public void onLoadFinished(Loader<List<PrinterInfo>> loader, List<PrinterInfo> printers) {
|
public void onLoadFinished(Loader<List<PrinterInfo>> loader, List<PrinterInfo> printers) {
|
||||||
mPrinters.clear();
|
mPrinters.clear();
|
||||||
mPrinters.addAll(printers);
|
mPrinters.addAll(printers);
|
||||||
if (mOnPrintersChangeListener != null) {
|
|
||||||
// Post a message as we are in onLoadFinished and certain operations
|
// Post a message as we are in onLoadFinished and certain operations
|
||||||
// are not allowed in this callback, such as fragment transactions.
|
// are not allowed in this callback, such as fragment transactions.
|
||||||
// Clients should not handle this explicitly.
|
// Clients should not handle this explicitly.
|
||||||
SomeArgs args = SomeArgs.obtain();
|
mHandler.obtainMessage(MyHandler.MSG_PRINTERS_CHANGED, printers).sendToTarget();
|
||||||
args.arg1 = mOnPrintersChangeListener;
|
|
||||||
args.arg2 = printers;
|
|
||||||
mHandler.obtainMessage(MyHandler.MSG_PRINTERS_CHANGED, args).sendToTarget();
|
|
||||||
}
|
|
||||||
if (!mReady) {
|
if (!mReady) {
|
||||||
mReady = true;
|
mReady = true;
|
||||||
if (mReadyCallback != null) {
|
if (mReadyCallback != null) {
|
||||||
@@ -158,7 +153,7 @@ public class PrinterRegistry {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final class MyHandler extends Handler {
|
private final class MyHandler extends Handler {
|
||||||
public static final int MSG_PRINTERS_CHANGED = 0;
|
public static final int MSG_PRINTERS_CHANGED = 0;
|
||||||
public static final int MSG_PRINTERS_INVALID = 1;
|
public static final int MSG_PRINTERS_INVALID = 1;
|
||||||
|
|
||||||
@@ -171,16 +166,17 @@ public class PrinterRegistry {
|
|||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
switch (message.what) {
|
switch (message.what) {
|
||||||
case MSG_PRINTERS_CHANGED: {
|
case MSG_PRINTERS_CHANGED: {
|
||||||
SomeArgs args = (SomeArgs) message.obj;
|
List<PrinterInfo> printers = (List<PrinterInfo>) message.obj;
|
||||||
OnPrintersChangeListener callback = (OnPrintersChangeListener) args.arg1;
|
|
||||||
List<PrinterInfo> printers = (List<PrinterInfo>) args.arg2;
|
if (mOnPrintersChangeListener != null) {
|
||||||
args.recycle();
|
mOnPrintersChangeListener.onPrintersChanged(printers);
|
||||||
callback.onPrintersChanged(printers);
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case MSG_PRINTERS_INVALID: {
|
case MSG_PRINTERS_INVALID: {
|
||||||
OnPrintersChangeListener callback = (OnPrintersChangeListener) message.obj;
|
if (mOnPrintersChangeListener != null) {
|
||||||
callback.onPrintersInvalid();
|
mOnPrintersChangeListener.onPrintersInvalid();
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user