OSDN Git Service

Merge "Add (back) receiver to disable camera." into gb-ub-photos-carlsbad
authorMangesh Ghiware <mghiware@google.com>
Mon, 23 Sep 2013 18:34:52 +0000 (18:34 +0000)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Mon, 23 Sep 2013 18:34:53 +0000 (18:34 +0000)
src/com/android/gallery3d/filtershow/FilterShowActivity.java
src/com/android/gallery3d/filtershow/history/HistoryManager.java
src/com/android/gallery3d/util/PrintJob.java

index 9d5005e..c4aca73 100644 (file)
@@ -138,6 +138,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
 
     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;
@@ -1264,8 +1265,17 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
         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();
     }
index 755e2ea..569b299 100644 (file)
@@ -42,6 +42,9 @@ public class HistoryManager {
     }
 
     public HistoryItem getItem(int position) {
+        if (position > mHistoryItems.size() - 1) {
+            return null;
+        }
         return mHistoryItems.elementAt(position);
     }
 
@@ -58,7 +61,7 @@ public class HistoryManager {
     }
 
     public boolean canReset() {
-        if (getCount() <= 1) {
+        if (getCount() <= 0) {
             return false;
         }
         return true;
@@ -108,9 +111,7 @@ public class HistoryManager {
         if (getCount() == 0) {
             return;
         }
-        HistoryItem first = getItem(getCount() - 1);
         clear();
-        addHistoryItem(first);
         updateMenuItems();
     }
 
index e2e345d..1ee0907 100644 (file)
@@ -20,6 +20,7 @@ import android.content.Context;
 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;
@@ -29,7 +30,6 @@ import android.print.PrintAttributes;
 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;
@@ -38,6 +38,8 @@ import java.io.FileOutputStream;
 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;
@@ -73,12 +75,12 @@ public class PrintJob {
                     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.
@@ -96,16 +98,25 @@ public class PrintJob {
                             // 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();