public static final String TINY_PLANET_ACTION = "com.android.camera.action.TINY_PLANET";
public static final String LAUNCH_FULLSCREEN = "launch-fullscreen";
+ public static final boolean RESET_TO_LOADED = false;
private ImageShow mImageShow = null;
private View mSaveButton = null;
HistoryManager adapter = mMasterImage.getHistory();
adapter.reset();
HistoryItem historyItem = adapter.getItem(0);
- ImagePreset original = new ImagePreset(historyItem.getImagePreset());
- mMasterImage.setPreset(original, historyItem.getFilterRepresentation(), true);
+ ImagePreset original = null;
+ if (RESET_TO_LOADED) {
+ original = new ImagePreset(historyItem.getImagePreset());
+ } else {
+ original = new ImagePreset();
+ }
+ FilterRepresentation rep = null;
+ if (historyItem != null) {
+ rep = historyItem.getFilterRepresentation();
+ }
+ mMasterImage.setPreset(original, rep, true);
invalidateViews();
backToMain();
}
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.RectF;
+import android.graphics.pdf.PdfDocument.Page;
import android.net.Uri;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.print.PrintDocumentAdapter;
import android.print.PrintDocumentInfo;
import android.print.PrintManager;
-import android.print.pdf.PdfDocument.Page;
import android.print.pdf.PrintedPdfDocument;
import com.android.gallery3d.filtershow.cache.ImageLoader;
import java.io.IOException;
public class PrintJob {
+ private static final String LOG_TAG = "PrintJob";
+
// will be <= 300 dpi on A4 (8.3×11.7) paper
// with a worst case of 150 dpi
private final static int MAX_PRINT_SIZE = 3500;
public void onWrite(PageRange[] pageRanges, ParcelFileDescriptor fileDescriptor,
CancellationSignal cancellationSignal,
WriteResultCallback writeResultCallback) {
+ PrintedPdfDocument pdfDocument = new PrintedPdfDocument(context,
+ mAttributes);
try {
- PrintedPdfDocument pdfDocument = PrintedPdfDocument.open(context,
- mAttributes);
Page page = pdfDocument.startPage(1);
- RectF content = new RectF(page.getInfo().getContentSize());
+ RectF content = new RectF(page.getInfo().getContentRect());
Matrix matrix = new Matrix();
// Compute and apply scale to fill the page.
// Draw the bitmap.
page.getCanvas().drawBitmap(bitmap, matrix, null);
- // Write the document.
+ // Finish the page.
pdfDocument.finishPage(page);
- pdfDocument.writeTo(new FileOutputStream(
- fileDescriptor.getFileDescriptor()));
- pdfDocument.close();
- // Done.
- writeResultCallback.onWriteFinished(
- new PageRange[] { PageRange.ALL_PAGES });
+ try {
+ // Write the document.
+ pdfDocument.writeTo(new FileOutputStream(
+ fileDescriptor.getFileDescriptor()));
+ // Done.
+ writeResultCallback.onWriteFinished(
+ new PageRange[] { PageRange.ALL_PAGES });
+ } catch (IOException ioe) {
+ // Failed.
+ Log.e(LOG_TAG, "Error writing printed content", ioe);
+ writeResultCallback.onWriteFailed(null);
+ }
} finally {
+ if (pdfDocument != null) {
+ pdfDocument.close();
+ }
if (fileDescriptor != null) {
try {
fileDescriptor.close();