Merge "Bug fixes in the print dialog" into klp-dev
This commit is contained in:
@@ -556,7 +556,7 @@ public final class PrintAttributes implements Parcelable {
|
||||
* @return New instance in landscape orientation.
|
||||
*/
|
||||
public MediaSize asPortrait() {
|
||||
return new MediaSize(mId, mPackageName, mLabel,
|
||||
return new MediaSize(mId, mLabel, mPackageName,
|
||||
Math.min(mWidthMils, mHeightMils),
|
||||
Math.max(mWidthMils, mHeightMils),
|
||||
mLabelResId);
|
||||
@@ -569,7 +569,7 @@ public final class PrintAttributes implements Parcelable {
|
||||
* @return New instance in landscape orientation.
|
||||
*/
|
||||
public MediaSize asLandscape() {
|
||||
return new MediaSize(mId, mLabel,
|
||||
return new MediaSize(mId, mLabel, mPackageName,
|
||||
Math.max(mWidthMils, mHeightMils),
|
||||
Math.min(mWidthMils, mHeightMils),
|
||||
mLabelResId);
|
||||
|
||||
@@ -257,8 +257,96 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
|
||||
private boolean mReadHistoryCompleted;
|
||||
private boolean mReadHistoryInProgress;
|
||||
|
||||
private final AsyncTask<Void, Void, List<PrinterInfo>> mReadTask =
|
||||
new AsyncTask<Void, Void, List<PrinterInfo>>() {
|
||||
private ReadTask mReadTask;
|
||||
|
||||
private PersistenceManager(Context context) {
|
||||
mStatePersistFile = new AtomicFile(new File(context.getFilesDir(),
|
||||
PERSIST_FILE_NAME));
|
||||
}
|
||||
|
||||
public boolean isReadHistoryInProgress() {
|
||||
return mReadHistoryInProgress;
|
||||
}
|
||||
|
||||
public boolean isReadHistoryCompleted() {
|
||||
return mReadHistoryCompleted;
|
||||
}
|
||||
|
||||
public boolean stopReadPrinterHistory() {
|
||||
final boolean cancelled = mReadTask.cancel(true);
|
||||
mReadTask = null;
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
public void readPrinterHistory() {
|
||||
if (DEBUG) {
|
||||
Log.i(LOG_TAG, "read history started");
|
||||
}
|
||||
mReadHistoryInProgress = true;
|
||||
mReadTask = new ReadTask();
|
||||
mReadTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, (Void[]) null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addPrinterAndWritePrinterHistory(PrinterInfo printer) {
|
||||
if (mHistoricalPrinters.size() >= MAX_HISTORY_LENGTH) {
|
||||
mHistoricalPrinters.remove(0);
|
||||
}
|
||||
mHistoricalPrinters.add(printer);
|
||||
new WriteTask().executeOnExecutor(AsyncTask.SERIAL_EXECUTOR,
|
||||
new ArrayList<PrinterInfo>(mHistoricalPrinters));
|
||||
}
|
||||
|
||||
private List<PrinterInfo> computeFavoritePrinters(List<PrinterInfo> printers) {
|
||||
Map<PrinterId, PrinterRecord> recordMap =
|
||||
new ArrayMap<PrinterId, PrinterRecord>();
|
||||
|
||||
// Recompute the weights.
|
||||
float currentWeight = 1.0f;
|
||||
final int printerCount = printers.size();
|
||||
for (int i = printerCount - 1; i >= 0; i--) {
|
||||
PrinterInfo printer = printers.get(i);
|
||||
// Aggregate weight for the same printer
|
||||
PrinterRecord record = recordMap.get(printer.getId());
|
||||
if (record == null) {
|
||||
record = new PrinterRecord(printer);
|
||||
recordMap.put(printer.getId(), record);
|
||||
}
|
||||
record.weight += currentWeight;
|
||||
currentWeight *= WEIGHT_DECAY_COEFFICIENT;
|
||||
}
|
||||
|
||||
// Soft the favorite printers.
|
||||
List<PrinterRecord> favoriteRecords = new ArrayList<PrinterRecord>(
|
||||
recordMap.values());
|
||||
Collections.sort(favoriteRecords);
|
||||
|
||||
// Write the favorites to the output.
|
||||
final int favoriteCount = favoriteRecords.size();
|
||||
List<PrinterInfo> favoritePrinters = new ArrayList<PrinterInfo>(favoriteCount);
|
||||
for (int i = 0; i < favoriteCount; i++) {
|
||||
PrinterInfo printer = favoriteRecords.get(i).printer;
|
||||
favoritePrinters.add(printer);
|
||||
}
|
||||
|
||||
return favoritePrinters;
|
||||
}
|
||||
|
||||
private final class PrinterRecord implements Comparable<PrinterRecord> {
|
||||
public final PrinterInfo printer;
|
||||
public float weight;
|
||||
|
||||
public PrinterRecord(PrinterInfo printer) {
|
||||
this.printer = printer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(PrinterRecord another) {
|
||||
return Float.floatToIntBits(another.weight) - Float.floatToIntBits(weight);
|
||||
}
|
||||
}
|
||||
|
||||
private final class ReadTask extends AsyncTask<Void, Void, List<PrinterInfo>> {
|
||||
@Override
|
||||
protected List<PrinterInfo> doInBackground(Void... args) {
|
||||
return doReadPrinterHistory();
|
||||
@@ -284,6 +372,9 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
|
||||
|
||||
// Start loading the available printers.
|
||||
loadInternal();
|
||||
|
||||
// We are done.
|
||||
mReadTask = null;
|
||||
}
|
||||
|
||||
private List<PrinterInfo> doReadPrinterHistory() {
|
||||
@@ -411,8 +502,7 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
|
||||
}
|
||||
};
|
||||
|
||||
private final AsyncTask<List<PrinterInfo>, Void, Void> mWriteTask =
|
||||
new AsyncTask<List<PrinterInfo>, Void, Void>() {
|
||||
private final class WriteTask extends AsyncTask<List<PrinterInfo>, Void, Void> {
|
||||
@Override
|
||||
protected Void doInBackground(List<PrinterInfo>... printers) {
|
||||
doWritePrinterHistory(printers[0]);
|
||||
@@ -473,89 +563,5 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private PersistenceManager(Context context) {
|
||||
mStatePersistFile = new AtomicFile(new File(context.getFilesDir(),
|
||||
PERSIST_FILE_NAME));
|
||||
}
|
||||
|
||||
public boolean isReadHistoryInProgress() {
|
||||
return mReadHistoryInProgress;
|
||||
}
|
||||
|
||||
public boolean isReadHistoryCompleted() {
|
||||
return mReadHistoryCompleted;
|
||||
}
|
||||
|
||||
public boolean stopReadPrinterHistory() {
|
||||
return mReadTask.cancel(true);
|
||||
}
|
||||
|
||||
public void readPrinterHistory() {
|
||||
if (DEBUG) {
|
||||
Log.i(LOG_TAG, "read history started");
|
||||
}
|
||||
mReadHistoryInProgress = true;
|
||||
mReadTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, (Void[]) null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addPrinterAndWritePrinterHistory(PrinterInfo printer) {
|
||||
if (mHistoricalPrinters.size() >= MAX_HISTORY_LENGTH) {
|
||||
mHistoricalPrinters.remove(0);
|
||||
}
|
||||
mHistoricalPrinters.add(printer);
|
||||
mWriteTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR,
|
||||
new ArrayList<PrinterInfo>(mHistoricalPrinters));
|
||||
}
|
||||
|
||||
private List<PrinterInfo> computeFavoritePrinters(List<PrinterInfo> printers) {
|
||||
Map<PrinterId, PrinterRecord> recordMap =
|
||||
new ArrayMap<PrinterId, PrinterRecord>();
|
||||
|
||||
// Recompute the weights.
|
||||
float currentWeight = 1.0f;
|
||||
final int printerCount = printers.size();
|
||||
for (int i = printerCount - 1; i >= 0; i--) {
|
||||
PrinterInfo printer = printers.get(i);
|
||||
// Aggregate weight for the same printer
|
||||
PrinterRecord record = recordMap.get(printer.getId());
|
||||
if (record == null) {
|
||||
record = new PrinterRecord(printer);
|
||||
recordMap.put(printer.getId(), record);
|
||||
}
|
||||
record.weight += currentWeight;
|
||||
currentWeight *= WEIGHT_DECAY_COEFFICIENT;
|
||||
}
|
||||
|
||||
// Soft the favorite printers.
|
||||
List<PrinterRecord> favoriteRecords = new ArrayList<PrinterRecord>(
|
||||
recordMap.values());
|
||||
Collections.sort(favoriteRecords);
|
||||
|
||||
// Write the favorites to the output.
|
||||
final int favoriteCount = favoriteRecords.size();
|
||||
List<PrinterInfo> favoritePrinters = new ArrayList<PrinterInfo>(favoriteCount);
|
||||
for (int i = 0; i < favoriteCount; i++) {
|
||||
PrinterInfo printer = favoriteRecords.get(i).printer;
|
||||
favoritePrinters.add(printer);
|
||||
}
|
||||
|
||||
return favoritePrinters;
|
||||
}
|
||||
|
||||
private final class PrinterRecord implements Comparable<PrinterRecord> {
|
||||
public final PrinterInfo printer;
|
||||
public float weight;
|
||||
|
||||
public PrinterRecord(PrinterInfo printer) {
|
||||
this.printer = printer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(PrinterRecord another) {
|
||||
return Float.floatToIntBits(another.weight) - Float.floatToIntBits(weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,8 +100,6 @@ public class PrintJobConfigActivity extends Activity {
|
||||
|
||||
private static final boolean DEBUG = true && Build.IS_DEBUGGABLE;
|
||||
|
||||
private static final boolean LIVE_PREVIEW_SUPPORTED = false;
|
||||
|
||||
public static final String EXTRA_PRINT_DOCUMENT_ADAPTER = "printDocumentAdapter";
|
||||
public static final String EXTRA_PRINT_ATTRIBUTES = "printAttributes";
|
||||
public static final String EXTRA_PRINT_JOB_ID = "printJobId";
|
||||
@@ -133,8 +131,7 @@ public class PrintJobConfigActivity extends Activity {
|
||||
|
||||
private static final int EDITOR_STATE_INITIALIZED = 1;
|
||||
private static final int EDITOR_STATE_CONFIRMED_PRINT = 2;
|
||||
// private static final int EDITOR_STATE_CONFIRMED_PREVIEW = 3;
|
||||
private static final int EDITOR_STATE_CANCELLED = 4;
|
||||
private static final int EDITOR_STATE_CANCELLED = 3;
|
||||
|
||||
private static final int MIN_COPIES = 1;
|
||||
private static final String MIN_COPIES_STRING = String.valueOf(MIN_COPIES);
|
||||
@@ -240,8 +237,7 @@ public class PrintJobConfigActivity extends Activity {
|
||||
}
|
||||
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (!mEditor.isPrintConfirmed() && !mEditor.isPreviewConfirmed()
|
||||
&& mEditor.shouldCloseOnTouch(event)) {
|
||||
if (!mEditor.isPrintConfirmed() && mEditor.shouldCloseOnTouch(event)) {
|
||||
if (!mController.isWorking()) {
|
||||
PrintJobConfigActivity.this.finish();
|
||||
}
|
||||
@@ -424,19 +420,7 @@ public class PrintJobConfigActivity extends Activity {
|
||||
if (!infoChanged && !layoutChanged
|
||||
&& PageRangeUtils.contains(mDocument.pages, mRequestedPages)) {
|
||||
if (mEditor.isDone()) {
|
||||
PrintJobConfigActivity.this.finish();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// If we do not support live preview and the current layout is
|
||||
// not for preview purposes, i.e. the user did not poke the
|
||||
// preview button, then just skip the write.
|
||||
if (!LIVE_PREVIEW_SUPPORTED && !mEditor.isPreviewConfirmed()
|
||||
&& mMetadata.getBoolean(PrintDocumentAdapter.METADATA_KEY_PRINT_PREVIEW)) {
|
||||
mEditor.updateUi();
|
||||
if (mEditor.isDone()) {
|
||||
PrintJobConfigActivity.this.finish();
|
||||
requestCreatePdfFileOrFinish();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -526,16 +510,20 @@ public class PrintJobConfigActivity extends Activity {
|
||||
}
|
||||
|
||||
if (mEditor.isDone()) {
|
||||
if (mEditor.isPrintingToPdf()) {
|
||||
PrintJobInfo printJob = PrintSpoolerService.peekInstance()
|
||||
.getPrintJobInfo(mPrintJobId, PrintManager.APP_ID_ANY);
|
||||
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
|
||||
intent.setType("application/pdf");
|
||||
intent.putExtra(Intent.EXTRA_TITLE, printJob.getLabel());
|
||||
startActivityForResult(intent, ACTIVITY_REQUEST_CREATE_FILE);
|
||||
} else {
|
||||
PrintJobConfigActivity.this.finish();
|
||||
}
|
||||
requestCreatePdfFileOrFinish();
|
||||
}
|
||||
}
|
||||
|
||||
private void requestCreatePdfFileOrFinish() {
|
||||
if (mEditor.isPrintingToPdf()) {
|
||||
PrintJobInfo printJob = PrintSpoolerService.peekInstance()
|
||||
.getPrintJobInfo(mPrintJobId, PrintManager.APP_ID_ANY);
|
||||
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
|
||||
intent.setType("application/pdf");
|
||||
intent.putExtra(Intent.EXTRA_TITLE, printJob.getLabel());
|
||||
startActivityForResult(intent, ACTIVITY_REQUEST_CREATE_FILE);
|
||||
} else {
|
||||
PrintJobConfigActivity.this.finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1101,7 +1089,8 @@ public class PrintJobConfigActivity extends Activity {
|
||||
|
||||
public void addCurrentPrinterToHistory() {
|
||||
PrinterInfo printer = (PrinterInfo) mDestinationSpinner.getSelectedItem();
|
||||
if (printer != null) {
|
||||
PrinterId fakePdfPritnerId = mDestinationSpinnerAdapter.mFakePdfPrinter.getId();
|
||||
if (printer != null && !printer.getId().equals(fakePdfPritnerId)) {
|
||||
FusedPrintersProvider printersLoader = (FusedPrintersProvider)
|
||||
(Loader<?>) getLoaderManager().getLoader(
|
||||
LOADER_ID_PRINTERS_LOADER);
|
||||
@@ -1324,7 +1313,7 @@ public class PrintJobConfigActivity extends Activity {
|
||||
}
|
||||
|
||||
public boolean isDone() {
|
||||
return isPrintConfirmed() || isPreviewConfirmed() || isCancelled();
|
||||
return isPrintConfirmed() || isCancelled();
|
||||
}
|
||||
|
||||
public boolean isPrintConfirmed() {
|
||||
@@ -1337,10 +1326,6 @@ public class PrintJobConfigActivity extends Activity {
|
||||
showUi(UI_GENERATING_PRINT_JOB, null);
|
||||
}
|
||||
|
||||
public boolean isPreviewConfirmed() {
|
||||
return mEditorState == EDITOR_STATE_CONFIRMED_PRINT;
|
||||
}
|
||||
|
||||
public PageRange[] getRequestedPages() {
|
||||
if (hasErrors()) {
|
||||
return null;
|
||||
@@ -1450,7 +1435,7 @@ public class PrintJobConfigActivity extends Activity {
|
||||
if (mCurrentUi != UI_EDITING_PRINT_JOB) {
|
||||
return false;
|
||||
}
|
||||
if (isPrintConfirmed() || isPreviewConfirmed() || isCancelled()) {
|
||||
if (isPrintConfirmed() || isCancelled()) {
|
||||
mDestinationSpinner.setEnabled(false);
|
||||
mCopiesEditText.setEnabled(false);
|
||||
mMediaSizeSpinner.setEnabled(false);
|
||||
@@ -1498,9 +1483,9 @@ public class PrintJobConfigActivity extends Activity {
|
||||
mColorModeSpinner.setEnabled(false);
|
||||
|
||||
// Orientation
|
||||
if (mOrientationSpinner.getSelectedItemPosition() != AdapterView.INVALID_POSITION) {
|
||||
if (mOrientationSpinner.getSelectedItemPosition() != 0) {
|
||||
mIgnoreNextOrientationChange = true;
|
||||
mOrientationSpinner.setSelection(AdapterView.INVALID_POSITION);
|
||||
mOrientationSpinner.setSelection(0);
|
||||
}
|
||||
mOrientationSpinner.setEnabled(false);
|
||||
|
||||
@@ -1768,7 +1753,7 @@ public class PrintJobConfigActivity extends Activity {
|
||||
mIgnoreNextColorModeChange = true;
|
||||
mColorModeSpinnerAdapter.clear();
|
||||
}
|
||||
if (!mOrientationSpinnerAdapter.isEmpty()) {
|
||||
if (mOrientationSpinner.getSelectedItemPosition() != 0) {
|
||||
mIgnoreNextOrientationChange = true;
|
||||
mOrientationSpinner.setSelection(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user