Merge "Fix some print UI issues." into lmp-dev
This commit is contained in:
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user