summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorSvetoslav Ganov <svetoslavganov@google.com>2013-09-28 00:28:07 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-09-28 00:28:08 +0000
commitc783f6738f0f6d2cb57702cfbc9219c59a3410a3 (patch)
treeac37e395db2a8b922ec19a8fcfd25ac9f0cef2f8 /packages
parentcc637d9ae5920ac2f685090f595dc1e1643d71cc (diff)
parent6be4c76441ecdc11ee4db7211edc421d26a78f1f (diff)
downloadframeworks_base-c783f6738f0f6d2cb57702cfbc9219c59a3410a3.zip
frameworks_base-c783f6738f0f6d2cb57702cfbc9219c59a3410a3.tar.gz
frameworks_base-c783f6738f0f6d2cb57702cfbc9219c59a3410a3.tar.bz2
Merge "Adding a timeout for waiting to get the selected printer's capabilities." into klp-dev
Diffstat (limited to 'packages')
-rw-r--r--packages/PrintSpooler/res/values/strings.xml3
-rw-r--r--packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java55
2 files changed, 49 insertions, 9 deletions
diff --git a/packages/PrintSpooler/res/values/strings.xml b/packages/PrintSpooler/res/values/strings.xml
index 9fe7e00..5ee8d8c 100644
--- a/packages/PrintSpooler/res/values/strings.xml
+++ b/packages/PrintSpooler/res/values/strings.xml
@@ -109,6 +109,9 @@
<!-- Label for an unknown reason for failed or blocked print job. [CHAR LIMIT=25] -->
<string name="reason_unknown">unknown</string>
+ <!-- Label for a printer that is not available. [CHAR LIMIT=25] -->
+ <string name="printer_unavailable"><xliff:g id="print_job_name" example="Canon-123GHT">%1$s</xliff:g> &#8211; unavailable</string>
+
<!-- Arrays -->
<!-- Color mode labels. -->
diff --git a/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java b/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java
index b6ef7b1..44362d4 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java
@@ -819,8 +819,6 @@ public class PrintJobConfigActivity extends Activity {
private PrinterInfo mCurrentPrinter;
- private boolean mRequestedCurrentPrinterRefresh;
-
private final OnItemSelectedListener mOnItemSelectedListener =
new AdapterView.OnItemSelectedListener() {
@Override
@@ -840,7 +838,7 @@ public class PrintJobConfigActivity extends Activity {
return;
}
- mRequestedCurrentPrinterRefresh = false;
+ mCapabilitiesTimeout.remove();
mCurrentPrinter = (PrinterInfo) mDestinationSpinnerAdapter
.getItem(position);
@@ -855,8 +853,7 @@ public class PrintJobConfigActivity extends Activity {
PrinterCapabilitiesInfo capabilities = mCurrentPrinter.getCapabilities();
if (capabilities == null) {
- // TODO: We need a timeout for the update.
- mRequestedCurrentPrinterRefresh = true;
+ mCapabilitiesTimeout.post();
updateUi();
refreshCurrentPrinter();
} else {
@@ -1129,6 +1126,9 @@ public class PrintJobConfigActivity extends Activity {
}
};
+ private final WaitForPrinterCapabilitiesTimeout mCapabilitiesTimeout =
+ new WaitForPrinterCapabilitiesTimeout();
+
private int mEditorState;
private boolean mIgnoreNextDestinationChange;
@@ -1174,16 +1174,16 @@ public class PrintJobConfigActivity extends Activity {
if (mCurrentPrinter.getStatus() == PrinterInfo.STATUS_UNAVAILABLE
&& printer.getStatus() != PrinterInfo.STATUS_UNAVAILABLE
&& printer.getCapabilities() == null
- && !mRequestedCurrentPrinterRefresh) {
- mRequestedCurrentPrinterRefresh = true;
+ && !mCapabilitiesTimeout.isPosted()) {
+ mCapabilitiesTimeout.post();
refreshCurrentPrinter();
return;
}
// We just refreshed the current printer.
if (printer.getCapabilities() != null
- && mRequestedCurrentPrinterRefresh) {
- mRequestedCurrentPrinterRefresh = false;
+ && mCapabilitiesTimeout.isPosted()) {
+ mCapabilitiesTimeout.remove();
updatePrintAttributes(printer.getCapabilities());
updateUi();
mController.update();
@@ -1972,6 +1972,43 @@ public class PrintJobConfigActivity extends Activity {
}
}
+ private final class WaitForPrinterCapabilitiesTimeout implements Runnable {
+ private static final long GET_CAPABILITIES_TIMEOUT_MILLIS = 10000; // 10sec
+
+ private boolean mIsPosted;
+
+ public void post() {
+ if (!mIsPosted) {
+ mDestinationSpinner.postDelayed(this,
+ GET_CAPABILITIES_TIMEOUT_MILLIS);
+ mIsPosted = true;
+ }
+ }
+
+ public void remove() {
+ if (mIsPosted) {
+ mIsPosted = false;
+ mDestinationSpinner.removeCallbacks(this);
+ }
+ }
+
+ public boolean isPosted() {
+ return mIsPosted;
+ }
+
+ @Override
+ public void run() {
+ mIsPosted = false;
+ if (mDestinationSpinner.getSelectedItemPosition() >= 0) {
+ View itemView = mDestinationSpinner.getSelectedView();
+ TextView titleView = (TextView) itemView.findViewById(R.id.title);
+ String title = getString(R.string.printer_unavailable,
+ mCurrentPrinter.getName());
+ titleView.setText(title);
+ }
+ }
+ }
+
private final class DestinationAdapter extends BaseAdapter
implements LoaderManager.LoaderCallbacks<List<PrinterInfo>>{
private final List<PrinterInfo> mPrinters = new ArrayList<PrinterInfo>();