summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorSvetoslav <svetoslavganov@google.com>2013-10-28 22:07:03 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-10-28 22:07:03 +0000
commit714ba34556572d36b1f9f8d9b860c4da24da6361 (patch)
tree568d312dba2a79fe1cb4c52666ddfba02628658b /packages
parent66b753b06bb265d3f5b25244856f8d827a9dc5af (diff)
parentb4fda134761c9521a7e127db3806a07a18763b77 (diff)
downloadframeworks_base-714ba34556572d36b1f9f8d9b860c4da24da6361.zip
frameworks_base-714ba34556572d36b1f9f8d9b860c4da24da6361.tar.gz
frameworks_base-714ba34556572d36b1f9f8d9b860c4da24da6361.tar.bz2
Merge "Complete implementation of the advanced print options." into klp-dev
Diffstat (limited to 'packages')
-rw-r--r--packages/PrintSpooler/res/layout/print_job_config_activity_container.xml2
-rw-r--r--packages/PrintSpooler/res/layout/print_job_config_activity_content_editing.xml88
-rw-r--r--packages/PrintSpooler/res/layout/print_job_config_activity_content_error.xml30
-rw-r--r--packages/PrintSpooler/res/layout/print_job_config_activity_content_generating.xml30
-rw-r--r--packages/PrintSpooler/res/values/colors.xml6
-rw-r--r--packages/PrintSpooler/res/values/strings.xml3
-rw-r--r--packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java249
-rw-r--r--packages/PrintSpooler/src/com/android/printspooler/PrintSpoolerService.java74
8 files changed, 406 insertions, 76 deletions
diff --git a/packages/PrintSpooler/res/layout/print_job_config_activity_container.xml b/packages/PrintSpooler/res/layout/print_job_config_activity_container.xml
index d503216..3303ef1 100644
--- a/packages/PrintSpooler/res/layout/print_job_config_activity_container.xml
+++ b/packages/PrintSpooler/res/layout/print_job_config_activity_container.xml
@@ -16,7 +16,7 @@
<com.android.printspooler.PrintDialogFrame xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
- android:layout_height="fill_parent">
+ android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/content_container"
android:layout_width="fill_parent"
diff --git a/packages/PrintSpooler/res/layout/print_job_config_activity_content_editing.xml b/packages/PrintSpooler/res/layout/print_job_config_activity_content_editing.xml
index 02740a3..e50a7af 100644
--- a/packages/PrintSpooler/res/layout/print_job_config_activity_content_editing.xml
+++ b/packages/PrintSpooler/res/layout/print_job_config_activity_content_editing.xml
@@ -18,8 +18,7 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
- android:scrollbars="vertical"
- android:background="@color/editable_background">
+ android:scrollbars="vertical">
<LinearLayout
android:layout_width="fill_parent"
@@ -42,6 +41,7 @@
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
+ android:layout_marginBottom="24dip"
android:orientation="horizontal"
android:baselineAligned="false">
@@ -203,27 +203,79 @@
</LinearLayout>
+ <!-- Advanced settings button -->
+
+ <LinearLayout
+ android:id="@+id/advanced_settings_container"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:visibility="gone">
+
+ <ImageView
+ android:layout_width="fill_parent"
+ android:layout_height="1dip"
+ android:layout_marginStart="24dip"
+ android:layout_marginEnd="24dip"
+ android:layout_gravity="fill_horizontal"
+ android:background="@color/separator"
+ android:contentDescription="@null">
+ </ImageView>
+
+ <Button
+ android:id="@+id/advanced_settings_button"
+ style="?android:attr/buttonBarButtonStyle"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="24dip"
+ android:layout_marginEnd="24dip"
+ android:layout_gravity="fill_horizontal"
+ android:text="@string/advanced_settings_button"
+ android:gravity="start|center_vertical"
+ android:textSize="16sp"
+ android:textColor="@color/item_text_color">
+ </Button>
+
+ <ImageView
+ android:layout_width="fill_parent"
+ android:layout_height="1dip"
+ android:layout_gravity="fill_horizontal"
+ android:layout_marginStart="24dip"
+ android:layout_marginEnd="24dip"
+ android:background="@color/separator"
+ android:contentDescription="@null">
+ </ImageView>
+
+ </LinearLayout>
+
<!-- Print button -->
- <ImageView
+ <FrameLayout
android:layout_width="fill_parent"
- android:layout_height="1dip"
+ android:layout_height="wrap_content"
android:layout_marginTop="24dip"
- android:layout_gravity="fill_horizontal"
- android:background="@color/separator"
- android:contentDescription="@null">
- </ImageView>
+ android:background="@color/action_button_background">
+
+ <ImageView
+ android:layout_width="fill_parent"
+ android:layout_height="1dip"
+ android:layout_gravity="fill_horizontal"
+ android:background="@color/separator"
+ android:contentDescription="@null">
+ </ImageView>
+
+ <Button
+ android:id="@+id/print_button"
+ style="?android:attr/buttonBarButtonStyle"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="fill_horizontal"
+ android:text="@string/print_button"
+ android:textSize="16sp"
+ android:textColor="@color/item_text_color">
+ </Button>
- <Button
- android:id="@+id/print_button"
- style="?android:attr/buttonBarButtonStyle"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="fill_horizontal"
- android:text="@string/print_button"
- android:textSize="16sp"
- android:textColor="@color/item_text_color">
- </Button>
+ </FrameLayout>
</LinearLayout>
diff --git a/packages/PrintSpooler/res/layout/print_job_config_activity_content_error.xml b/packages/PrintSpooler/res/layout/print_job_config_activity_content_error.xml
index 222b5b6..f573d9d 100644
--- a/packages/PrintSpooler/res/layout/print_job_config_activity_content_error.xml
+++ b/packages/PrintSpooler/res/layout/print_job_config_activity_content_error.xml
@@ -23,7 +23,6 @@
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- android:background="@color/editable_background"
android:orientation="vertical">
<TextView
@@ -43,23 +42,30 @@
android:textSize="16sp">
</TextView>
+ </LinearLayout>
+
+ <FrameLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:background="@color/action_button_background">
+
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="@color/separator">
</View>
- </LinearLayout>
+ <Button
+ android:id="@+id/ok_button"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="fill_horizontal"
+ style="?android:attr/buttonBarButtonStyle"
+ android:text="@android:string/ok"
+ android:textSize="16sp"
+ android:textColor="@color/important_text">
+ </Button>
- <Button
- android:id="@+id/ok_button"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="fill_horizontal"
- style="?android:attr/buttonBarButtonStyle"
- android:text="@android:string/ok"
- android:textSize="16sp"
- android:textColor="@color/important_text">
- </Button>
+ </FrameLayout>
</LinearLayout>
diff --git a/packages/PrintSpooler/res/layout/print_job_config_activity_content_generating.xml b/packages/PrintSpooler/res/layout/print_job_config_activity_content_generating.xml
index 8bdb6c9..10602ee 100644
--- a/packages/PrintSpooler/res/layout/print_job_config_activity_content_generating.xml
+++ b/packages/PrintSpooler/res/layout/print_job_config_activity_content_generating.xml
@@ -23,7 +23,6 @@
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- android:background="@color/editable_background"
android:orientation="vertical">
<TextView
@@ -51,23 +50,30 @@
style="?android:attr/progressBarStyleLarge">
</ProgressBar>
+ </LinearLayout>
+
+ <FrameLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:background="@color/action_button_background">
+
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="@color/separator">
</View>
- </LinearLayout>
+ <Button
+ android:id="@+id/cancel_button"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="fill_horizontal"
+ style="?android:attr/buttonBarButtonStyle"
+ android:text="@string/cancel"
+ android:textSize="16sp"
+ android:textColor="@color/important_text">
+ </Button>
- <Button
- android:id="@+id/cancel_button"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="fill_horizontal"
- style="?android:attr/buttonBarButtonStyle"
- android:text="@string/cancel"
- android:textSize="16sp"
- android:textColor="@color/important_text">
- </Button>
+ </FrameLayout>
</LinearLayout>
diff --git a/packages/PrintSpooler/res/values/colors.xml b/packages/PrintSpooler/res/values/colors.xml
index 9972c96..4fc25b3 100644
--- a/packages/PrintSpooler/res/values/colors.xml
+++ b/packages/PrintSpooler/res/values/colors.xml
@@ -16,10 +16,10 @@
<resources>
- <color name="container_background">#FFFFFF</color>
+ <color name="container_background">#F2F2F2</color>
<color name="important_text">#333333</color>
<color name="print_option_title">#888888</color>
<color name="separator">#CCCCCC</color>
- <color name="editable_background">#F2F2F2</color>
+ <color name="action_button_background">#FFFFFF</color>
-</resources> \ No newline at end of file
+</resources>
diff --git a/packages/PrintSpooler/res/values/strings.xml b/packages/PrintSpooler/res/values/strings.xml
index d74b414..f2e768a 100644
--- a/packages/PrintSpooler/res/values/strings.xml
+++ b/packages/PrintSpooler/res/values/strings.xml
@@ -19,6 +19,9 @@
<!-- Title of the PrintSpooler application. [CHAR LIMIT=50] -->
<string name="app_label">Print Spooler</string>
+ <!-- Label of the print dialog's button for advanced printer settings. [CHAR LIMIT=25] -->
+ <string name="advanced_settings_button">Printer settings</string>
+
<!-- Label of the print dialog's print button. [CHAR LIMIT=16] -->
<string name="print_button">Print</string>
diff --git a/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java b/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java
index db3770e..8f26361 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java
@@ -19,6 +19,7 @@ package com.android.printspooler;
import android.app.Activity;
import android.app.Dialog;
import android.app.LoaderManager;
+import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -26,6 +27,8 @@ import android.content.Loader;
import android.content.ServiceConnection;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
import android.database.DataSetObserver;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
@@ -55,6 +58,8 @@ import android.print.PrintManager;
import android.print.PrinterCapabilitiesInfo;
import android.print.PrinterId;
import android.print.PrinterInfo;
+import android.printservice.PrintService;
+import android.printservice.PrintServiceInfo;
import android.provider.DocumentsContract;
import android.text.Editable;
import android.text.TextUtils;
@@ -130,6 +135,7 @@ public class PrintJobConfigActivity extends Activity {
private static final int ACTIVITY_REQUEST_CREATE_FILE = 1;
private static final int ACTIVITY_REQUEST_SELECT_PRINTER = 2;
+ private static final int ACTIVITY_POPULATE_ADVANCED_PRINT_OPTIONS = 3;
private static final int CONTROLLER_STATE_FINISHED = 1;
private static final int CONTROLLER_STATE_FAILED = 2;
@@ -254,28 +260,27 @@ public class PrintJobConfigActivity extends Activity {
}
@Override
- protected void onDestroy() {
- // We can safely do the work in here since at this point
- // the system is bound to our (spooler) process which
- // guarantees that this process will not be killed.
- if (mController != null && mController.hasStarted()) {
- mController.finish();
- }
- if (mEditor != null && mEditor.isPrintConfirmed()
- && mController != null && mController.isFinished()) {
- mSpoolerProvider.getSpooler().setPrintJobState(mPrintJobId,
- PrintJobInfo.STATE_QUEUED, null);
- } else {
- mSpoolerProvider.getSpooler().setPrintJobState(mPrintJobId,
- PrintJobInfo.STATE_CANCELED, null);
- }
- if (mGeneratingPrintJobDialog != null) {
- mGeneratingPrintJobDialog.dismiss();
- mGeneratingPrintJobDialog = null;
- }
- mIPrintDocumentAdapter.unlinkToDeath(mDeathRecipient, 0);
- mSpoolerProvider.destroy();
- super.onDestroy();
+ public void onPause() {
+ if (isFinishing()) {
+ if (mController != null && mController.hasStarted()) {
+ mController.finish();
+ }
+ if (mEditor != null && mEditor.isPrintConfirmed()
+ && mController != null && mController.isFinished()) {
+ mSpoolerProvider.getSpooler().setPrintJobState(mPrintJobId,
+ PrintJobInfo.STATE_QUEUED, null);
+ } else {
+ mSpoolerProvider.getSpooler().setPrintJobState(mPrintJobId,
+ PrintJobInfo.STATE_CANCELED, null);
+ }
+ if (mGeneratingPrintJobDialog != null) {
+ mGeneratingPrintJobDialog.dismiss();
+ mGeneratingPrintJobDialog = null;
+ }
+ mIPrintDocumentAdapter.unlinkToDeath(mDeathRecipient, 0);
+ mSpoolerProvider.destroy();
+ }
+ super.onPause();
}
public boolean onTouchEvent(MotionEvent event) {
@@ -607,18 +612,14 @@ public class PrintJobConfigActivity extends Activity {
} else {
// We did not get the pages we requested, then the application
// misbehaves, so we fail quickly.
- // TODO: We need some UI for announcing an error.
mControllerState = CONTROLLER_STATE_FAILED;
Log.e(LOG_TAG, "Received invalid pages from the app");
- mEditor.cancel();
- PrintJobConfigActivity.this.finish();
+ mEditor.showUi(Editor.UI_ERROR, null);
}
}
private void requestCreatePdfFileOrFinish() {
if (mEditor.isPrintingToPdf()) {
- PrintJobInfo printJob = mSpoolerProvider.getSpooler()
- .getPrintJobInfo(mPrintJobId, PrintManager.APP_ID_ANY);
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.setType("application/pdf");
intent.putExtra(Intent.EXTRA_TITLE, mDocument.info.getName());
@@ -791,6 +792,19 @@ public class PrintJobConfigActivity extends Activity {
}
mEditor.ensureCurrentPrinterSelected();
} break;
+
+ case ACTIVITY_POPULATE_ADVANCED_PRINT_OPTIONS: {
+ if (resultCode == RESULT_OK) {
+ PrintJobInfo printJobInfo = (PrintJobInfo) data.getParcelableExtra(
+ PrintService.EXTRA_PRINT_JOB_INFO);
+ if (printJobInfo != null) {
+ mEditor.updateFromAdvancedOptions(printJobInfo);
+ break;
+ }
+ }
+ mEditor.cancel();
+ PrintJobConfigActivity.this.finish();
+ } break;
}
}
@@ -869,6 +883,10 @@ public class PrintJobConfigActivity extends Activity {
private View mContentContainer;
+ private View mAdvancedPrintOptionsContainer;
+
+ private Button mAdvancedOptionsButton;
+
private Button mPrintButton;
private PrinterId mNextPrinterId;
@@ -932,6 +950,10 @@ public class PrintJobConfigActivity extends Activity {
refreshCurrentPrinter();
}
} else if (spinner == mMediaSizeSpinner) {
+ if (mIgnoreNextMediaSizeChange) {
+ mIgnoreNextMediaSizeChange = false;
+ return;
+ }
if (mOldMediaSizeSelectionIndex
== mMediaSizeSpinner.getSelectedItemPosition()) {
mOldMediaSizeSelectionIndex = AdapterView.INVALID_POSITION;
@@ -947,6 +969,10 @@ public class PrintJobConfigActivity extends Activity {
mController.update();
}
} else if (spinner == mColorModeSpinner) {
+ if (mIgnoreNextColorChange) {
+ mIgnoreNextColorChange = false;
+ return;
+ }
if (mOldColorModeSelectionIndex
== mColorModeSpinner.getSelectedItemPosition()) {
mOldColorModeSelectionIndex = AdapterView.INVALID_POSITION;
@@ -1193,6 +1219,16 @@ public class PrintJobConfigActivity extends Activity {
// greater than the to page. When computing the requested pages
// we just swap them if necessary.
+ // Keep the print job up to date with the selected pages if we
+ // know how many pages are there in the document.
+ PageRange[] requestedPages = getRequestedPages();
+ if (requestedPages != null && requestedPages.length > 0
+ && requestedPages[requestedPages.length - 1].getEnd()
+ < mDocument.info.getPageCount()) {
+ mSpoolerProvider.getSpooler().setPrintJobPagesNoPersistence(
+ mPrintJobId, requestedPages);
+ }
+
mPageRangeEditText.setError(null);
mPrintButton.setEnabled(true);
updateUi();
@@ -1215,6 +1251,8 @@ public class PrintJobConfigActivity extends Activity {
private boolean mIgnoreNextRangeOptionChange;
private boolean mIgnoreNextCopiesChange;
private boolean mIgnoreNextRangeChange;
+ private boolean mIgnoreNextMediaSizeChange;
+ private boolean mIgnoreNextColorChange;
private int mCurrentUi = UI_NONE;
@@ -1424,6 +1462,88 @@ public class PrintJobConfigActivity extends Activity {
}
}
+ public void updateFromAdvancedOptions(PrintJobInfo printJobInfo) {
+ boolean updateContent = false;
+
+ // Copies.
+ mCopiesEditText.setText(String.valueOf(printJobInfo.getCopies()));
+
+ // Media size and orientation
+ PrintAttributes attributes = printJobInfo.getAttributes();
+ if (!mCurrPrintAttributes.getMediaSize().equals(attributes.getMediaSize())) {
+ final int mediaSizeCount = mMediaSizeSpinnerAdapter.getCount();
+ for (int i = 0; i < mediaSizeCount; i++) {
+ MediaSize mediaSize = mMediaSizeSpinnerAdapter.getItem(i).value;
+ if (mediaSize.asPortrait().equals(attributes.getMediaSize().asPortrait())) {
+ updateContent = true;
+ mCurrPrintAttributes.setMediaSize(attributes.getMediaSize());
+ mMediaSizeSpinner.setSelection(i);
+ mIgnoreNextMediaSizeChange = true;
+ if (attributes.getMediaSize().isPortrait()) {
+ mOrientationSpinner.setSelection(0);
+ mIgnoreNextOrientationChange = true;
+ } else {
+ mOrientationSpinner.setSelection(1);
+ mIgnoreNextOrientationChange = true;
+ }
+ break;
+ }
+ }
+ }
+
+ // Color mode.
+ final int colorMode = attributes.getColorMode();
+ if (mCurrPrintAttributes.getColorMode() != colorMode) {
+ if (colorMode == PrintAttributes.COLOR_MODE_MONOCHROME) {
+ updateContent = true;
+ mColorModeSpinner.setSelection(0);
+ mIgnoreNextColorChange = true;
+ mCurrPrintAttributes.setColorMode(attributes.getColorMode());
+ } else if (colorMode == PrintAttributes.COLOR_MODE_COLOR) {
+ updateContent = true;
+ mColorModeSpinner.setSelection(1);
+ mIgnoreNextColorChange = true;
+ mCurrPrintAttributes.setColorMode(attributes.getColorMode());
+ }
+ }
+
+ // Range.
+ PageRange[] pageRanges = printJobInfo.getPages();
+ if (pageRanges != null && pageRanges.length > 0) {
+ pageRanges = PageRangeUtils.normalize(pageRanges);
+ final int pageRangeCount = pageRanges.length;
+ if (pageRangeCount == 1 && pageRanges[0] == PageRange.ALL_PAGES) {
+ mRangeOptionsSpinner.setSelection(0);
+ } else {
+ final int pageCount = mDocument.info.getPageCount();
+ if (pageRanges[0].getStart() >= 0
+ && pageRanges[pageRanges.length - 1].getEnd() < pageCount) {
+ mRangeOptionsSpinner.setSelection(1);
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < pageRangeCount; i++) {
+ if (builder.length() > 0) {
+ builder.append(',');
+ }
+ PageRange pageRange = pageRanges[i];
+ builder.append(pageRange.getStart());
+ builder.append('-');
+ builder.append(pageRange.getEnd());
+ }
+ mPageRangeEditText.setText(builder.toString());
+ }
+ }
+ }
+
+ // Update the advanced options.
+ mSpoolerProvider.getSpooler().setPrintJobAdvancedOptionsNoPersistence(
+ mPrintJobId, printJobInfo.getAdvancedOptions());
+
+ // Update the content if needed.
+ if (updateContent) {
+ mController.update();
+ }
+ }
+
public void ensurePrinterSelected(PrinterId printerId) {
// If the printer is not present maybe the loader is not
// updated yet. In this case make a note and as soon as
@@ -1609,6 +1729,44 @@ public class PrintJobConfigActivity extends Activity {
}
}
+ private void registerAdvancedPrintOptionsButtonClickListener() {
+ Button advancedOptionsButton = (Button) findViewById(R.id.advanced_settings_button);
+ advancedOptionsButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ ComponentName serviceName = mCurrentPrinter.getId().getServiceName();
+ String activityName = getAdvancedOptionsActivityName(serviceName);
+ if (TextUtils.isEmpty(activityName)) {
+ return;
+ }
+ Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.setComponent(new ComponentName(serviceName.getPackageName(),
+ activityName));
+
+ List<ResolveInfo> resolvedActivities = getPackageManager()
+ .queryIntentActivities(intent, 0);
+ if (resolvedActivities.isEmpty()) {
+ return;
+ }
+ // The activity is a component name, therefore it is one or none.
+ if (resolvedActivities.get(0).activityInfo.exported) {
+ PrintJobInfo printJobInfo = mSpoolerProvider.getSpooler().getPrintJobInfo(
+ mPrintJobId, PrintManager.APP_ID_ANY);
+ intent.putExtra(PrintService.EXTRA_PRINT_JOB_INFO, printJobInfo);
+ // TODO: Make this an API for the next release.
+ intent.putExtra("android.intent.extra.print.EXTRA_PRINTER_INFO",
+ mCurrentPrinter);
+ try {
+ startActivityForResult(intent,
+ ACTIVITY_POPULATE_ADVANCED_PRINT_OPTIONS);
+ } catch (ActivityNotFoundException anfe) {
+ Log.e(LOG_TAG, "Error starting activity for intent: " + intent, anfe);
+ }
+ }
+ }
+ });
+ }
+
private void registerPrintButtonClickListener() {
Button printButton = (Button) findViewById(R.id.print_button);
printButton.setOnClickListener(new OnClickListener() {
@@ -1656,6 +1814,9 @@ public class PrintJobConfigActivity extends Activity {
mEditor.initialize();
mEditor.bindUi();
mEditor.reselectCurrentPrinter();
+ if (!mController.hasPerformedLayout()) {
+ mController.update();
+ }
}
});
}
@@ -1857,6 +2018,11 @@ public class PrintJobConfigActivity extends Activity {
mPageRangeEditText.setOnFocusChangeListener(mFocusListener);
mPageRangeEditText.addTextChangedListener(mRangeTextWatcher);
+ // Advanced options button.
+ mAdvancedPrintOptionsContainer = findViewById(R.id.advanced_settings_container);
+ mAdvancedOptionsButton = (Button) findViewById(R.id.advanced_settings_button);
+ registerAdvancedPrintOptionsButtonClickListener();
+
// Print button
mPrintButton = (Button) findViewById(R.id.print_button);
registerPrintButtonClickListener();
@@ -1875,6 +2041,7 @@ public class PrintJobConfigActivity extends Activity {
mRangeOptionsSpinner.setEnabled(false);
mPageRangeEditText.setEnabled(false);
mPrintButton.setEnabled(false);
+ mAdvancedOptionsButton.setEnabled(false);
return false;
}
@@ -1900,6 +2067,7 @@ public class PrintJobConfigActivity extends Activity {
mRangeOptionsSpinner.setEnabled(false);
mPageRangeEditText.setEnabled(false);
mPrintButton.setEnabled(false);
+ mAdvancedOptionsButton.setEnabled(false);
return false;
} else {
boolean someAttributeSelectionChanged = false;
@@ -2077,7 +2245,17 @@ public class PrintJobConfigActivity extends Activity {
mPageRangeTitle.setVisibility(View.INVISIBLE);
}
- // Print/Print preview
+ // Advanced print options
+ ComponentName serviceName = mCurrentPrinter.getId().getServiceName();
+ if (!TextUtils.isEmpty(getAdvancedOptionsActivityName(serviceName))) {
+ mAdvancedPrintOptionsContainer.setVisibility(View.VISIBLE);
+ mAdvancedOptionsButton.setEnabled(true);
+ } else {
+ mAdvancedPrintOptionsContainer.setVisibility(View.GONE);
+ mAdvancedOptionsButton.setEnabled(false);
+ }
+
+ // Print
if (mDestinationSpinner.getSelectedItemId()
!= DEST_ADAPTER_ITEM_ID_SAVE_AS_PDF) {
String newText = getString(R.string.print_button);
@@ -2117,6 +2295,21 @@ public class PrintJobConfigActivity extends Activity {
}
}
+ private String getAdvancedOptionsActivityName(ComponentName serviceName) {
+ PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
+ List<PrintServiceInfo> printServices = printManager.getEnabledPrintServices();
+ final int printServiceCount = printServices.size();
+ for (int i = 0; i < printServiceCount; i ++) {
+ PrintServiceInfo printServiceInfo = printServices.get(i);
+ ServiceInfo serviceInfo = printServiceInfo.getResolveInfo().serviceInfo;
+ if (serviceInfo.name.equals(serviceName.getClassName())
+ && serviceInfo.packageName.equals(serviceName.getPackageName())) {
+ return printServiceInfo.getAdvancedOptionsActivityName();
+ }
+ }
+ return null;
+ }
+
private void setMediaSizeSpinnerSelectionNoCallback(int position) {
if (mMediaSizeSpinner.getSelectedItemPosition() != position) {
mOldMediaSizeSelectionIndex = position;
diff --git a/packages/PrintSpooler/src/com/android/printspooler/PrintSpoolerService.java b/packages/PrintSpooler/src/com/android/printspooler/PrintSpoolerService.java
index 636e245..609ae64 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/PrintSpoolerService.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/PrintSpoolerService.java
@@ -20,6 +20,7 @@ import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.os.AsyncTask;
+import android.os.Bundle;
import android.os.IBinder;
import android.os.Message;
import android.os.ParcelFileDescriptor;
@@ -623,6 +624,16 @@ public final class PrintSpoolerService extends Service {
}
}
+ public void setPrintJobAdvancedOptionsNoPersistence(PrintJobId printJobId,
+ Bundle advancedOptions) {
+ synchronized (mLock) {
+ PrintJobInfo printJob = getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY);
+ if (printJob != null) {
+ printJob.setAdvancedOptions(advancedOptions);
+ }
+ }
+ }
+
public void setPrintJobPrintDocumentInfoNoPersistence(PrintJobId printJobId,
PrintDocumentInfo info) {
synchronized (mLock) {
@@ -704,6 +715,14 @@ public final class PrintSpoolerService extends Service {
private static final String ATTR_STATE_REASON = "stateReason";
private static final String ATTR_CANCELLING = "cancelling";
+ private static final String TAG_ADVANCED_OPTIONS = "advancedOptions";
+ private static final String TAG_ADVANCED_OPTION = "advancedOption";
+ private static final String ATTR_KEY = "key";
+ private static final String ATTR_TYPE = "type";
+ private static final String ATTR_VALUE = "value";
+ private static final String TYPE_STRING = "string";
+ private static final String TYPE_INT = "int";
+
private static final String TAG_MEDIA_SIZE = "mediaSize";
private static final String TAG_RESOLUTION = "resolution";
private static final String TAG_MARGINS = "margins";
@@ -899,6 +918,30 @@ public final class PrintSpoolerService extends Service {
serializer.endTag(null, TAG_DOCUMENT_INFO);
}
+ Bundle advancedOptions = printJob.getAdvancedOptions();
+ if (advancedOptions != null) {
+ serializer.startTag(null, TAG_ADVANCED_OPTIONS);
+ for (String key : advancedOptions.keySet()) {
+ Object value = advancedOptions.get(key);
+ if (value instanceof String) {
+ String stringValue = (String) value;
+ serializer.startTag(null, TAG_ADVANCED_OPTION);
+ serializer.attribute(null, ATTR_KEY, key);
+ serializer.attribute(null, ATTR_TYPE, TYPE_STRING);
+ serializer.attribute(null, ATTR_VALUE, stringValue);
+ serializer.endTag(null, TAG_ADVANCED_OPTION);
+ } else if (value instanceof Integer) {
+ String intValue = Integer.toString((Integer) value);
+ serializer.startTag(null, TAG_ADVANCED_OPTION);
+ serializer.attribute(null, ATTR_KEY, key);
+ serializer.attribute(null, ATTR_TYPE, TYPE_INT);
+ serializer.attribute(null, ATTR_VALUE, intValue);
+ serializer.endTag(null, TAG_ADVANCED_OPTION);
+ }
+ }
+ serializer.endTag(null, TAG_ADVANCED_OPTIONS);
+ }
+
serializer.endTag(null, TAG_JOB);
if (DEBUG_PERSISTENCE) {
@@ -1027,6 +1070,7 @@ public final class PrintSpoolerService extends Service {
skipEmptyTextTags(parser);
expect(parser, XmlPullParser.END_TAG, TAG_PAGE_RANGE);
parser.next();
+ skipEmptyTextTags(parser);
}
if (pageRanges != null) {
PageRange[] pageRangesArray = new PageRange[pageRanges.size()];
@@ -1057,8 +1101,8 @@ public final class PrintSpoolerService extends Service {
final int labelResId = (labelResIdString != null)
? Integer.parseInt(labelResIdString) : 0;
label = parser.getAttributeValue(null, ATTR_LABEL);
- MediaSize mediaSize = new MediaSize(id, label, packageName, labelResId,
- widthMils, heightMils);
+ MediaSize mediaSize = new MediaSize(id, label, packageName,
+ widthMils, heightMils, labelResId);
builder.setMediaSize(mediaSize);
parser.next();
skipEmptyTextTags(parser);
@@ -1127,6 +1171,32 @@ public final class PrintSpoolerService extends Service {
parser.next();
}
+ skipEmptyTextTags(parser);
+ if (accept(parser, XmlPullParser.START_TAG, TAG_ADVANCED_OPTIONS)) {
+ parser.next();
+ skipEmptyTextTags(parser);
+ Bundle advancedOptions = new Bundle();
+ while (accept(parser, XmlPullParser.START_TAG, TAG_ADVANCED_OPTION)) {
+ String key = parser.getAttributeValue(null, ATTR_KEY);
+ String value = parser.getAttributeValue(null, ATTR_VALUE);
+ String type = parser.getAttributeValue(null, ATTR_TYPE);
+ if (TYPE_STRING.equals(type)) {
+ advancedOptions.putString(key, value);
+ } else if (TYPE_INT.equals(type)) {
+ advancedOptions.putInt(key, Integer.valueOf(value));
+ }
+ parser.next();
+ skipEmptyTextTags(parser);
+ expect(parser, XmlPullParser.END_TAG, TAG_ADVANCED_OPTION);
+ parser.next();
+ skipEmptyTextTags(parser);
+ }
+ printJob.setAdvancedOptions(advancedOptions);
+ skipEmptyTextTags(parser);
+ expect(parser, XmlPullParser.END_TAG, TAG_ADVANCED_OPTIONS);
+ parser.next();
+ }
+
mPrintJobs.add(printJob);
if (DEBUG_PERSISTENCE) {