summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authornicolasroard <nicolasroard@google.com>2013-08-16 14:06:43 -0700
committernicolasroard <nicolasroard@google.com>2013-08-16 15:00:59 -0700
commit9c5d6700209699c3f1a47b6fa37618ddcd2f24c3 (patch)
tree08b42ac4cbee28420df9b4e9b0ef7fa4591ae604 /src/com
parentd33fe6fd37d8c506ab0e47139ef0f77746a275b8 (diff)
downloadandroid_packages_apps_Gallery2-9c5d6700209699c3f1a47b6fa37618ddcd2f24c3.tar.gz
android_packages_apps_Gallery2-9c5d6700209699c3f1a47b6fa37618ddcd2f24c3.tar.bz2
android_packages_apps_Gallery2-9c5d6700209699c3f1a47b6fa37618ddcd2f24c3.zip
Implements Printing in the editor
Change-Id: Ib307f8b9c1aaaee2ab96f8e8ddcd86abe38bdc72
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/gallery3d/filtershow/FilterShowActivity.java15
-rw-r--r--src/com/android/gallery3d/util/PrintJob.java98
2 files changed, 113 insertions, 0 deletions
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index af333b6dd..4f1f7f07f 100644
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -29,11 +29,14 @@ import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
+import android.graphics.Matrix;
import android.graphics.Rect;
+import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.os.CancellationSignal;
import android.os.Handler;
import android.os.IBinder;
import android.support.v4.app.DialogFragment;
@@ -106,10 +109,13 @@ import com.android.gallery3d.filtershow.tools.XmpPresets.XMresults;
import com.android.gallery3d.filtershow.ui.ExportDialog;
import com.android.gallery3d.filtershow.ui.FramedTextButton;
import com.android.gallery3d.util.GalleryUtils;
+import com.android.gallery3d.util.PrintJob;
import com.android.gallery3d.util.UsageStatistics;
import com.android.photos.data.GalleryBitmapPool;
import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileOutputStream;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Vector;
@@ -962,10 +968,19 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
toggleInformationPanel();
return true;
}
+ case R.id.printButton: {
+ print();
+ return true;
+ }
}
return false;
}
+ public void print() {
+ Bitmap bitmap = MasterImage.getImage().getHighresImage();
+ PrintJob.printBitmap(this, "ImagePrint", bitmap);
+ }
+
public void addNewPreset() {
DialogFragment dialog = new PresetManagementDialog();
dialog.show(getSupportFragmentManager(), "NoticeDialogFragment");
diff --git a/src/com/android/gallery3d/util/PrintJob.java b/src/com/android/gallery3d/util/PrintJob.java
new file mode 100644
index 000000000..d06466a21
--- /dev/null
+++ b/src/com/android/gallery3d/util/PrintJob.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.gallery3d.util;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Matrix;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.os.Bundle;
+import android.os.CancellationSignal;
+import android.print.PageRange;
+import android.print.PrintAttributes;
+import android.print.PrintDocumentAdapter;
+import android.print.PrintDocumentInfo;
+import android.print.PrintManager;
+import android.print.pdf.PdfDocument;
+import com.android.gallery3d.filtershow.imageshow.MasterImage;
+
+import java.io.FileDescriptor;
+import java.io.FileOutputStream;
+
+public class PrintJob {
+ public static void printBitmap(Context context, final String jobName, final Bitmap bitmap) {
+ PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
+ android.print.PrintJob printJob = printManager.print(jobName,
+ new PrintDocumentAdapter() {
+ private Rect mPageRect;
+ private Matrix mPrintMatrix;
+ private float mDensity;
+ @Override
+ public void onLayout(PrintAttributes oldPrintAttributes,
+ PrintAttributes newPrintAttributes,
+ CancellationSignal cancellationSignal,
+ LayoutResultCallback layoutResultCallback, Bundle bundle) {
+
+ mDensity = Math.max(newPrintAttributes.getResolution().getHorizontalDpi(),
+ newPrintAttributes.getResolution().getVerticalDpi());
+
+ float MILS_PER_INCH = 1000f;
+
+ int pageWidth = (int) (mDensity
+ * newPrintAttributes.getMediaSize().getWidthMils() / MILS_PER_INCH);
+ int pageHeight = (int) (mDensity
+ * newPrintAttributes.getMediaSize().getWidthMils() / MILS_PER_INCH);
+
+ mPageRect = new Rect(0, 0, pageWidth, pageHeight);
+ if (newPrintAttributes.getOrientation()
+ == PrintAttributes.ORIENTATION_LANDSCAPE) {
+ mPageRect = new Rect(0, 0, pageHeight, pageWidth);
+ }
+
+ PrintDocumentInfo info = new PrintDocumentInfo.Builder(jobName)
+ .setContentType(PrintDocumentInfo.CONTENT_TYPE_PHOTO)
+ .setPageCount(1)
+ .create();
+ layoutResultCallback.onLayoutFinished(info, false);
+ }
+
+ @Override
+ public void onWrite(PageRange[] pageRanges, FileDescriptor fileDescriptor,
+ CancellationSignal cancellationSignal,
+ WriteResultCallback writeResultCallback) {
+ PdfDocument mPdfDocument = PdfDocument.open();
+ PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(
+ mPageRect, 1, (int) mDensity).create();
+ PdfDocument.Page page = mPdfDocument.startPage(pageInfo);
+ mPrintMatrix = new Matrix();
+ mPrintMatrix.setRectToRect(
+ new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight()),
+ new RectF(mPageRect),
+ Matrix.ScaleToFit.CENTER);
+ page.getCanvas().drawBitmap(bitmap, mPrintMatrix, null);
+ mPdfDocument.finishPage(page);
+ mPdfDocument.writeTo(new FileOutputStream(fileDescriptor));
+ mPdfDocument.close();
+ writeResultCallback.onWriteFinished(
+ new PageRange[] { PageRange.ALL_PAGES });
+ }
+ }, new PrintAttributes.Builder().create());
+
+ }
+
+}