Loading packages/PrintSpooler/src/com/android/printspooler/model/PageContentRepository.java +10 −5 Original line number Diff line number Diff line Loading @@ -24,13 +24,14 @@ import android.content.ServiceConnection; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.os.AsyncTask; import android.os.IBinder; import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.print.PrintAttributes; import android.print.PrintAttributes.MediaSize; import android.print.PrintAttributes.Margins; import android.print.PrintDocumentInfo; import android.util.ArrayMap; import android.util.Log; Loading @@ -41,7 +42,6 @@ import com.android.printspooler.renderer.PdfRendererService; import dalvik.system.CloseGuard; import libcore.io.IoUtils; import java.io.FileDescriptor; import java.io.IOException; import java.util.Iterator; import java.util.LinkedHashMap; Loading Loading @@ -354,13 +354,14 @@ public final class PageContentRepository { public static final class RenderSpec { final int bitmapWidth; final int bitmapHeight; final PrintAttributes printAttributes; final PrintAttributes printAttributes = new PrintAttributes.Builder().build(); public RenderSpec(int bitmapWidth, int bitmapHeight, PrintAttributes printAttributes) { MediaSize mediaSize, Margins minMargins) { this.bitmapWidth = bitmapWidth; this.bitmapHeight = bitmapHeight; this.printAttributes = printAttributes; printAttributes.setMediaSize(mediaSize); printAttributes.setMinMargins(minMargins); } @Override Loading Loading @@ -508,6 +509,10 @@ public final class PageContentRepository { } catch (RemoteException re) { Log.e(LOG_TAG, "Cannot open PDF document"); return MALFORMED_PDF_FILE_ERROR; } finally { // Close the fd as we passed it to another process // which took ownership. IoUtils.closeQuietly(source); } } } Loading packages/PrintSpooler/src/com/android/printspooler/model/RemotePrintDocument.java +1 −1 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ import java.util.Arrays; public final class RemotePrintDocument { private static final String LOG_TAG = "RemotePrintDocument"; private static final boolean DEBUG = true; private static final boolean DEBUG = false; private static final int STATE_INITIAL = 0; private static final int STATE_STARTED = 1; Loading packages/PrintSpooler/src/com/android/printspooler/renderer/PdfRendererService.java +3 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.app.Service; import android.content.Intent; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Rect; import android.graphics.pdf.PdfRenderer; Loading Loading @@ -171,11 +172,13 @@ public final class PdfRendererService extends Service { private Bitmap getBitmapForSize(int width, int height) { if (mBitmap != null) { if (mBitmap.getWidth() == width && mBitmap.getHeight() == height) { mBitmap.eraseColor(Color.WHITE); return mBitmap; } mBitmap.recycle(); } mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); mBitmap.eraseColor(Color.WHITE); return mBitmap; } Loading packages/PrintSpooler/src/com/android/printspooler/ui/PrintPreviewController.java +3 −2 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.print.PageRange; import android.print.PrintAttributes.MediaSize; import android.print.PrintAttributes.Margins; import android.print.PrintDocumentInfo; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.OrientationHelper; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView.ViewHolder; Loading Loading @@ -51,7 +52,7 @@ class PrintPreviewController implements MutexFileProvider.OnReleaseRequestCallba private final MyHandler mHandler; private final PageAdapter mPageAdapter; private final StaggeredGridLayoutManager mLayoutManger; private final GridLayoutManager mLayoutManger; private final PrintOptionsLayout mPrintOptionsLayout; private final RecyclerView mRecyclerView; Loading @@ -73,7 +74,7 @@ class PrintPreviewController implements MutexFileProvider.OnReleaseRequestCallba final int columnCount = mActivity.getResources().getInteger( R.integer.preview_page_per_row_count); mLayoutManger = new StaggeredGridLayoutManager(columnCount, OrientationHelper.VERTICAL); mLayoutManger = new GridLayoutManager(mActivity, columnCount); mRecyclerView = (RecyclerView) activity.findViewById(R.id.preview_content); mRecyclerView.setLayoutManager(mLayoutManger); Loading packages/PrintSpooler/src/com/android/printspooler/widget/PageContentView.java +23 −12 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; import android.print.PrintAttributes; import android.print.PrintAttributes.MediaSize; import android.print.PrintAttributes.Margins; import android.util.AttributeSet; Loading @@ -39,14 +38,18 @@ import com.android.printspooler.model.PageContentRepository.RenderSpec; public class PageContentView extends View implements PageContentRepository.OnPageContentAvailableCallback { private final PrintAttributes mAttributes = new PrintAttributes.Builder().build(); private final ColorDrawable mEmptyState; private PageContentProvider mProvider; private MediaSize mMediaSize; private Margins mMinMargins; private boolean mContentRequested; private boolean mNeedsLayout; public PageContentView(Context context, AttributeSet attrs) { super(context, attrs); Loading @@ -68,6 +71,7 @@ public class PageContentView extends View @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); mNeedsLayout = false; requestPageContentIfNeeded(); } Loading @@ -83,18 +87,23 @@ public class PageContentView extends View } public void init(PageContentProvider provider, MediaSize mediaSize, Margins minMargins) { if (mProvider == null ? provider == null : mProvider.equals(provider) && ((mAttributes.getMediaSize() == null) ? mediaSize == null : mAttributes.getMediaSize().equals(mediaSize)) && ((mAttributes.getMinMargins() == null) ? minMargins == null : mAttributes.getMinMargins().equals(minMargins))) { final boolean providerChanged = (mProvider == null) ? provider != null : !mProvider.equals(provider); final boolean mediaSizeChanged = (mMediaSize == null) ? mediaSize != null : !mMediaSize.equals(mediaSize); final boolean marginsChanged = (mMinMargins == null) ? minMargins != null : !mMinMargins.equals(minMargins); if (!providerChanged && !mediaSizeChanged && !marginsChanged) { return; } mProvider = provider; mAttributes.setMediaSize(mediaSize); mAttributes.setMinMargins(minMargins); mMediaSize = mediaSize; mMinMargins = minMargins; mContentRequested = false; mNeedsLayout = mNeedsLayout || mediaSizeChanged || marginsChanged; // If there is no provider we want immediately to switch to // the empty state, so pages with no content appear blank. Loading @@ -106,9 +115,11 @@ public class PageContentView extends View } private void requestPageContentIfNeeded() { if (getWidth() > 0 && getHeight() > 0 && !mContentRequested && mProvider != null) { if (getWidth() > 0 && getHeight() > 0 && !mContentRequested && mProvider != null && !mNeedsLayout) { mContentRequested = true; mProvider.getPageContent(new RenderSpec(getWidth(), getHeight(), mAttributes), this); mProvider.getPageContent(new RenderSpec(getWidth(), getHeight(), mMediaSize, mMinMargins), this); } } } Loading
packages/PrintSpooler/src/com/android/printspooler/model/PageContentRepository.java +10 −5 Original line number Diff line number Diff line Loading @@ -24,13 +24,14 @@ import android.content.ServiceConnection; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.os.AsyncTask; import android.os.IBinder; import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.print.PrintAttributes; import android.print.PrintAttributes.MediaSize; import android.print.PrintAttributes.Margins; import android.print.PrintDocumentInfo; import android.util.ArrayMap; import android.util.Log; Loading @@ -41,7 +42,6 @@ import com.android.printspooler.renderer.PdfRendererService; import dalvik.system.CloseGuard; import libcore.io.IoUtils; import java.io.FileDescriptor; import java.io.IOException; import java.util.Iterator; import java.util.LinkedHashMap; Loading Loading @@ -354,13 +354,14 @@ public final class PageContentRepository { public static final class RenderSpec { final int bitmapWidth; final int bitmapHeight; final PrintAttributes printAttributes; final PrintAttributes printAttributes = new PrintAttributes.Builder().build(); public RenderSpec(int bitmapWidth, int bitmapHeight, PrintAttributes printAttributes) { MediaSize mediaSize, Margins minMargins) { this.bitmapWidth = bitmapWidth; this.bitmapHeight = bitmapHeight; this.printAttributes = printAttributes; printAttributes.setMediaSize(mediaSize); printAttributes.setMinMargins(minMargins); } @Override Loading Loading @@ -508,6 +509,10 @@ public final class PageContentRepository { } catch (RemoteException re) { Log.e(LOG_TAG, "Cannot open PDF document"); return MALFORMED_PDF_FILE_ERROR; } finally { // Close the fd as we passed it to another process // which took ownership. IoUtils.closeQuietly(source); } } } Loading
packages/PrintSpooler/src/com/android/printspooler/model/RemotePrintDocument.java +1 −1 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ import java.util.Arrays; public final class RemotePrintDocument { private static final String LOG_TAG = "RemotePrintDocument"; private static final boolean DEBUG = true; private static final boolean DEBUG = false; private static final int STATE_INITIAL = 0; private static final int STATE_STARTED = 1; Loading
packages/PrintSpooler/src/com/android/printspooler/renderer/PdfRendererService.java +3 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.app.Service; import android.content.Intent; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Rect; import android.graphics.pdf.PdfRenderer; Loading Loading @@ -171,11 +172,13 @@ public final class PdfRendererService extends Service { private Bitmap getBitmapForSize(int width, int height) { if (mBitmap != null) { if (mBitmap.getWidth() == width && mBitmap.getHeight() == height) { mBitmap.eraseColor(Color.WHITE); return mBitmap; } mBitmap.recycle(); } mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); mBitmap.eraseColor(Color.WHITE); return mBitmap; } Loading
packages/PrintSpooler/src/com/android/printspooler/ui/PrintPreviewController.java +3 −2 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.print.PageRange; import android.print.PrintAttributes.MediaSize; import android.print.PrintAttributes.Margins; import android.print.PrintDocumentInfo; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.OrientationHelper; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView.ViewHolder; Loading Loading @@ -51,7 +52,7 @@ class PrintPreviewController implements MutexFileProvider.OnReleaseRequestCallba private final MyHandler mHandler; private final PageAdapter mPageAdapter; private final StaggeredGridLayoutManager mLayoutManger; private final GridLayoutManager mLayoutManger; private final PrintOptionsLayout mPrintOptionsLayout; private final RecyclerView mRecyclerView; Loading @@ -73,7 +74,7 @@ class PrintPreviewController implements MutexFileProvider.OnReleaseRequestCallba final int columnCount = mActivity.getResources().getInteger( R.integer.preview_page_per_row_count); mLayoutManger = new StaggeredGridLayoutManager(columnCount, OrientationHelper.VERTICAL); mLayoutManger = new GridLayoutManager(mActivity, columnCount); mRecyclerView = (RecyclerView) activity.findViewById(R.id.preview_content); mRecyclerView.setLayoutManager(mLayoutManger); Loading
packages/PrintSpooler/src/com/android/printspooler/widget/PageContentView.java +23 −12 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; import android.print.PrintAttributes; import android.print.PrintAttributes.MediaSize; import android.print.PrintAttributes.Margins; import android.util.AttributeSet; Loading @@ -39,14 +38,18 @@ import com.android.printspooler.model.PageContentRepository.RenderSpec; public class PageContentView extends View implements PageContentRepository.OnPageContentAvailableCallback { private final PrintAttributes mAttributes = new PrintAttributes.Builder().build(); private final ColorDrawable mEmptyState; private PageContentProvider mProvider; private MediaSize mMediaSize; private Margins mMinMargins; private boolean mContentRequested; private boolean mNeedsLayout; public PageContentView(Context context, AttributeSet attrs) { super(context, attrs); Loading @@ -68,6 +71,7 @@ public class PageContentView extends View @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); mNeedsLayout = false; requestPageContentIfNeeded(); } Loading @@ -83,18 +87,23 @@ public class PageContentView extends View } public void init(PageContentProvider provider, MediaSize mediaSize, Margins minMargins) { if (mProvider == null ? provider == null : mProvider.equals(provider) && ((mAttributes.getMediaSize() == null) ? mediaSize == null : mAttributes.getMediaSize().equals(mediaSize)) && ((mAttributes.getMinMargins() == null) ? minMargins == null : mAttributes.getMinMargins().equals(minMargins))) { final boolean providerChanged = (mProvider == null) ? provider != null : !mProvider.equals(provider); final boolean mediaSizeChanged = (mMediaSize == null) ? mediaSize != null : !mMediaSize.equals(mediaSize); final boolean marginsChanged = (mMinMargins == null) ? minMargins != null : !mMinMargins.equals(minMargins); if (!providerChanged && !mediaSizeChanged && !marginsChanged) { return; } mProvider = provider; mAttributes.setMediaSize(mediaSize); mAttributes.setMinMargins(minMargins); mMediaSize = mediaSize; mMinMargins = minMargins; mContentRequested = false; mNeedsLayout = mNeedsLayout || mediaSizeChanged || marginsChanged; // If there is no provider we want immediately to switch to // the empty state, so pages with no content appear blank. Loading @@ -106,9 +115,11 @@ public class PageContentView extends View } private void requestPageContentIfNeeded() { if (getWidth() > 0 && getHeight() > 0 && !mContentRequested && mProvider != null) { if (getWidth() > 0 && getHeight() > 0 && !mContentRequested && mProvider != null && !mNeedsLayout) { mContentRequested = true; mProvider.getPageContent(new RenderSpec(getWidth(), getHeight(), mAttributes), this); mProvider.getPageContent(new RenderSpec(getWidth(), getHeight(), mMediaSize, mMinMargins), this); } } }