123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796 |
- package epson.print.phlayout;
- import android.app.Activity;
- import android.content.Context;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.graphics.Canvas;
- import android.graphics.Paint;
- import android.graphics.Path;
- import android.graphics.Point;
- import android.graphics.Rect;
- import android.graphics.RectF;
- import android.graphics.Region;
- import android.os.Handler;
- import android.os.Message;
- import android.support.annotation.AnyThread;
- import android.support.p000v4.view.GestureDetectorCompat;
- import android.util.AttributeSet;
- import android.util.Log;
- import android.view.GestureDetector;
- import android.view.MotionEvent;
- import android.view.ScaleGestureDetector;
- import android.view.View;
- import java.lang.annotation.Retention;
- import java.lang.annotation.RetentionPolicy;
- import java.util.concurrent.locks.ReentrantLock;
- import epson.common.Info_paper;
- import epson.print.EPImage;
- import epson.print.EPImageCreator;
- import epson.print.EPImageList;
- import epson.print.IprintApplication;
- import epson.print.R;
- public class PhotoPreview extends View {
- private static final int ALL_REFRESH_DRAW_END = 4;
- private static final int CREATE_PREVIEW = 1;
- static final int FIT_MODE_CIRCUMSCRIBED = 1;
- static final int FIT_MODE_FREE = 0;
- static final int FIT_MODE_INSCRIBED = 2;
- private static final int INVALID_IMAGE_NO = -1;
- private static final String LOG_TAG = "previewView";
- private static final float MAX_MAGNIFICATION_FACTOR = 8.0f;
- private static final float MINI_MAGNIFICATION_FACTOR = 0.25f;
- private static final double MOVEMENT_MARGIN_RATE = 0.2d;
- public static final int RESET_PREVIEW = 2;
- public static final int RESTORE_PREVIEW = 0;
- private static final int ZOOM_CONTROL = 2;
- private float baseScaleFactor = 1.0f;
- private int color = 0;
- private Handler drawEndHandler = null;
- private PhotoPreviewImageList imageList = null;
- private volatile int imageNo = 0;
- private final Object lockObj = new Object();
- private Bitmap mBitmap = null;
- private final Rect mBitmapDrawRect = new Rect();
- private final ReentrantLock mDrawLock = new ReentrantLock();
- private final FitLayout mFitLayout = new FitLayout();
- private volatile int mFitMode;
- private GestureDetectorCompat mGestureDetector;
- private volatile ILayoutPosition mLayoutPosition = null;
- private int mPaperSizeId = 0;
- private final Path mPath = new Path();
- private volatile PreviewBitmapMaker mPreviewBitmapMaker;
- private ScaleGestureDetector mScaleGestureDetector = null;
- private int[] mViewSize = new int[2];
- private ViewSizeChangeListener mViewSizeChangeListener;
- private boolean maskExpandPreview = true;
- private int maxBitmapHeight = -1;
- private int maxBitmapWidth = -1;
- private final Paint paint = new Paint();
- private float scaleFactor = 1.0f;
- private final Point trans = new Point();
- private Handler zoomControlHandler = null;
- @Retention(RetentionPolicy.SOURCE)
- @interface FitMode {
- }
- public interface PreviewBitmapMaker {
- Bitmap getPreviewBitmap(EPImage ePImage, int i, int i2, int i3, boolean z);
- }
- public interface ViewSizeChangeListener {
- void onViewSizeChanged();
- }
- public PhotoPreview(Context context) {
- super(context);
- initLocal(context);
- }
- public PhotoPreview(Context context, AttributeSet attributeSet) {
- super(context, attributeSet);
- initLocal(context);
- }
- private void initLocal(Context context) {
- mGestureDetector = new GestureDetectorCompat(context, new MyGestureListener(this));
- mScaleGestureDetector = new ScaleGestureDetector(context, new MyScaledGestureListener(this));
- mFitMode = 1;
- }
- private void startScaleChange() {
- maskExpandPreview = false;
- baseScaleFactor = scaleFactor;
- mFitMode = 0;
- invalidate();
- }
- private void changeScale(float f) {
- scaleFactor = f * baseScaleFactor;
- float f2 = scaleFactor;
- if (f2 < MINI_MAGNIFICATION_FACTOR) {
- scaleFactor = MINI_MAGNIFICATION_FACTOR;
- } else if (f2 > MAX_MAGNIFICATION_FACTOR) {
- scaleFactor = MAX_MAGNIFICATION_FACTOR;
- }
- Handler handler = zoomControlHandler;
- if (handler != null) {
- handler.sendEmptyMessage(2);
- }
- adjustTrans(trans);
- invalidate();
- }
- private void changeFitModeAndRefresh() {
- maskExpandPreview = true;
- changeFitMode();
- invalidate();
- Handler handler = zoomControlHandler;
- if (handler != null) {
- handler.sendEmptyMessage(2);
- }
- }
- private void changeFitMode() {
- if (1 == mLayoutPosition.getLayoutId()) {
- fitCircumscribed();
- } else if (mFitMode == 1) {
- fitInscribed();
- } else {
- fitCircumscribed();
- }
- }
- @WorkerThread
- private void fitCircumscribed() {
- scaleFactor = 1.0f;
- baseScaleFactor = 1.0f;
- setPaper(mPaperSizeId);
- mFitMode = 1;
- }
- private void fitInscribed() {
- EPImage currentEpImage;
- mFitMode = 2;
- if (mLayoutPosition != null && (currentEpImage = getCurrentEpImage()) != null) {
- RectF previewImageCircumscribedTargetSize = mLayoutPosition.getPreviewImageCircumscribedTargetSize();
- double[] fitInscribed = mFitLayout.fitInscribed(new double[]{(double) previewImageCircumscribedTargetSize.left, (double) previewImageCircumscribedTargetSize.top, (double) previewImageCircumscribedTargetSize.right, (double) previewImageCircumscribedTargetSize.bottom}, new double[]{(double) currentEpImage.previewWidth, (double) currentEpImage.previewHeight});
- if (fitInscribed != null) {
- Point point = trans;
- point.x = (int) fitInscribed[0];
- point.y = (int) fitInscribed[1];
- scaleFactor = (float) fitInscribed[2];
- }
- }
- }
- @AnyThread
- private EPImage getCurrentEpImage() {
- if (imageNo < 0 || imageNo >= imageList.size()) {
- return null;
- }
- return imageList.get(imageNo);
- }
- private PhotoPreviewImageList.Element getCurrentElement() {
- return imageList.getElement(imageNo);
- }
- @WorkerThread
- private static Bitmap getBitmap(EPImage ePImage, int i, int i2, int i3, boolean z) {
- new EPImageCreator(IprintApplication.getInstance()).createPreviewImage(ePImage, i, i2, i3, z);
- if (ePImage.previewImageFileName != null) {
- return BitmapFactory.decodeFile(ePImage.previewImageFileName);
- }
- return null;
- }
- public void setViewSizeChangeListener(ViewSizeChangeListener viewSizeChangeListener) {
- mViewSizeChangeListener = viewSizeChangeListener;
- }
- public void setPreviewBitmapMaker(PreviewBitmapMaker previewBitmapMaker) {
- mPreviewBitmapMaker = previewBitmapMaker;
- }
- public EPImageList getImageList() {
- EPImageList ePImageList;
- synchronized (lockObj) {
- saveImage(imageNo);
- ePImageList = new EPImageList();
- ePImageList.setRenderingMode(1);
- for (int i = 0; i < imageList.size(); i++) {
- EPImage ePImage = imageList.get(i);
- if (ePImage != null) {
- RectF calcPreviewImageRect = calcPreviewImageRect(ePImage.previewWidth, ePImage.previewHeight, ePImage.scaleFactor, new Point(ePImage.previewImageRectCenterX, ePImage.previewImageRectCenterY));
- EPImage ePImage2 = new EPImage(ePImage);
- ePImage2.previewImageRectLeft = calcPreviewImageRect.left;
- ePImage2.previewImageRectTop = calcPreviewImageRect.top;
- ePImage2.previewImageRectRight = calcPreviewImageRect.right;
- ePImage2.previewImageRectBottom = calcPreviewImageRect.bottom;
- ePImageList.add(ePImage2);
- }
- }
- }
- return ePImageList;
- }
- public void setImageList(@NonNull PhotoPreviewImageList photoPreviewImageList) {
- imageList = photoPreviewImageList;
- }
- public void setLayout(int i, int i2) {
- if (i == 1) {
- mLayoutPosition = new BorderlessLayoutPosition();
- } else if (i != 4) {
- mLayoutPosition = new BorderedLayoutPosition();
- } else {
- mLayoutPosition = new CdLayoutPosition();
- }
- mLayoutPosition.setLayoutId(i, i2);
- }
- public void setColor(int i) {
- color = i;
- }
- public void setZoomControlHandler(Handler handler) {
- zoomControlHandler = handler;
- }
- public void setDrawEndHandler(Handler handler) {
- drawEndHandler = handler;
- }
- public boolean getIsPaperLandscape() {
- return mLayoutPosition.getIsPaperLandscape();
- }
- @WorkerThread
- public void setIsPaperLandscape(boolean z, Activity activity) {
- synchronized (lockObj) {
- mLayoutPosition.setPaperLandscape(z);
- if (imageList == null || imageList.size() <= 0) {
- setPaper(mPaperSizeId);
- } else {
- scaleFactor = 1.0f;
- baseScaleFactor = 1.0f;
- mFitMode = 1;
- setImage(imageNo, 1, activity);
- }
- postInvalidate();
- }
- }
- @AnyThread
- public boolean setPaper(int i) {
- synchronized (lockObj) {
- mPaperSizeId = i;
- Info_paper infoPaper = Info_paper.getInfoPaper(IprintApplication.getInstance(), mPaperSizeId);
- if (infoPaper == null) {
- return false;
- }
- int[] viewSize = getViewSize();
- if (viewSize == null) {
- return false;
- }
- mLayoutPosition.setPaperAndCalcPreviewPosition(infoPaper, viewSize[0], viewSize[1], trans);
- return true;
- }
- }
- @Nullable
- @AnyThread
- private synchronized int[] getViewSize() {
- if (mViewSize[0] > 0) {
- if (mViewSize[1] > 0) {
- return mViewSize;
- }
- }
- return null;
- }
- @WorkerThread
- private void reCalcPaperPosition() {
- Info_paper infoPaper;
- int[] viewSize = getViewSize();
- if (viewSize != null && (infoPaper = Info_paper.getInfoPaper(IprintApplication.getInstance(), mPaperSizeId)) != null) {
- mLayoutPosition.setPaperAndCalcPreviewPosition(infoPaper, viewSize[0], viewSize[1], new Point());
- }
- }
- @AnyThread
- public void invalidateImageNo() {
- if (imageList != null) {
- imageNo = -1;
- }
- }
- public void invalidatePreview() {
- if (imageList != null) {
- synchronized (lockObj) {
- for (int i = 0; i < imageList.size(); i++) {
- imageList.get(i).previewImageFileName = null;
- }
- }
- }
- }
- /* JADX WARNING: Code restructure failed: missing block: B:62:0x0099, code lost:
- r4.mDrawLock.unlock();
- */
- /* JADX WARNING: Code restructure failed: missing block: B:63:0x009e, code lost:
- return false;
- */
- /* JADX WARNING: Missing exception handler attribute for start block: B:45:0x007e */
- /* JADX WARNING: Missing exception handler attribute for start block: B:50:0x0088 */
- @android.support.annotation.WorkerThread
- /* Code decompiled incorrectly, please refer to instructions dump. */
- public boolean setImage(int r5, int r6, android.app.Activity r7) throws java.lang.OutOfMemoryError {
- /*
- r4 = this;
- java.util.concurrent.locks.ReentrantLock r0 = r4.mDrawLock // Catch:{ all -> 0x00a2 }
- r0.lock() // Catch:{ all -> 0x00a2 }
- java.lang.Object r0 = r4.lockObj // Catch:{ all -> 0x00a2 }
- monitor-enter(r0) // Catch:{ all -> 0x00a2 }
- epson.print.phlayout.PhotoPreviewImageList r1 = r4.imageList // Catch:{ all -> 0x009f }
- r2 = 0
- if (r1 == 0) goto L_0x0098
- epson.print.phlayout.ILayoutPosition r1 = r4.mLayoutPosition // Catch:{ all -> 0x009f }
- if (r1 != 0) goto L_0x0013
- goto L_0x0098
- L_0x0013:
- epson.print.phlayout.PhotoPreviewImageList r1 = r4.imageList // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- int r1 = r1.size() // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- r3 = 1
- if (r1 > 0) goto L_0x003e
- r5 = 0
- r4.mBitmap = r5 // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- r5 = 2
- if (r6 != r5) goto L_0x0025
- r4.fitCircumscribed() // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- L_0x0025:
- if (r6 == r3) goto L_0x002f
- epson.print.phlayout.ILayoutPosition r5 = r4.mLayoutPosition // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- boolean r5 = r5.isPreviewImageSizeValid() // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- if (r5 != 0) goto L_0x0034
- L_0x002f:
- int r5 = r4.mPaperSizeId // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- r4.setPaper(r5) // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- L_0x0034:
- r4.postInvalidate() // Catch:{ all -> 0x009f }
- monitor-exit(r0) // Catch:{ all -> 0x009f }
- java.util.concurrent.locks.ReentrantLock r5 = r4.mDrawLock
- r5.unlock()
- return r2
- L_0x003e:
- r4.setImageCore(r5, r6) // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- android.graphics.Bitmap r5 = r4.mBitmap // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- if (r5 == 0) goto L_0x0076
- int r5 = r4.maxBitmapWidth // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- r6 = -1
- if (r5 == r6) goto L_0x0054
- android.graphics.Bitmap r5 = r4.mBitmap // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- int r5 = r5.getWidth() // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- int r1 = r4.maxBitmapWidth // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- if (r5 > r1) goto L_0x0062
- L_0x0054:
- int r5 = r4.maxBitmapWidth // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- if (r5 == r6) goto L_0x006a
- android.graphics.Bitmap r5 = r4.mBitmap // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- int r5 = r5.getHeight() // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- int r6 = r4.maxBitmapHeight // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- if (r5 <= r6) goto L_0x006a
- L_0x0062:
- epson.print.phlayout.PhotoPreview$1 r5 = new epson.print.phlayout.PhotoPreview$1 // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- r5.<init>() // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- r7.runOnUiThread(r5) // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- L_0x006a:
- r4.maskExpandPreview = r3 // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- r4.postInvalidate() // Catch:{ all -> 0x009f }
- monitor-exit(r0) // Catch:{ all -> 0x009f }
- java.util.concurrent.locks.ReentrantLock r5 = r4.mDrawLock
- r5.unlock()
- return r3
- L_0x0076:
- java.lang.OutOfMemoryError r5 = new java.lang.OutOfMemoryError // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- r5.<init>() // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- throw r5 // Catch:{ OutOfMemoryError -> 0x0092, NullPointerException -> 0x0088, Exception -> 0x007e }
- L_0x007c:
- r5 = move-exception
- goto L_0x0094
- L_0x007e:
- r4.postInvalidate() // Catch:{ all -> 0x009f }
- monitor-exit(r0) // Catch:{ all -> 0x009f }
- java.util.concurrent.locks.ReentrantLock r5 = r4.mDrawLock
- r5.unlock()
- return r2
- L_0x0088:
- r4.postInvalidate() // Catch:{ all -> 0x009f }
- monitor-exit(r0) // Catch:{ all -> 0x009f }
- java.util.concurrent.locks.ReentrantLock r5 = r4.mDrawLock
- r5.unlock()
- return r2
- L_0x0092:
- r5 = move-exception
- throw r5 // Catch:{ all -> 0x007c }
- L_0x0094:
- r4.postInvalidate() // Catch:{ all -> 0x009f }
- throw r5 // Catch:{ all -> 0x009f }
- L_0x0098:
- monitor-exit(r0) // Catch:{ all -> 0x009f }
- java.util.concurrent.locks.ReentrantLock r5 = r4.mDrawLock
- r5.unlock()
- return r2
- L_0x009f:
- r5 = move-exception
- monitor-exit(r0) // Catch:{ all -> 0x009f }
- throw r5 // Catch:{ all -> 0x00a2 }
- L_0x00a2:
- r5 = move-exception
- java.util.concurrent.locks.ReentrantLock r6 = r4.mDrawLock
- r6.unlock()
- throw r5
- */
- throw new UnsupportedOperationException("Method not decompiled: epson.print.phlayout.PhotoPreview.setImage(int, int, android.app.Activity):boolean");
- }
- @WorkerThread
- private void setImageCore(int i, int i2) throws Exception {
- if (i < 0 || i >= imageList.size()) {
- throw new Exception();
- } else if (imageNo < 0 || imageNo >= imageList.size() || saveImage(imageNo)) {
- imageNo = i;
- PhotoPreviewImageList.Element currentElement = getCurrentElement();
- EPImage currentEpImage = getCurrentEpImage();
- if (i2 == 0) {
- setImageCore_RestorePreview(currentElement);
- } else {
- setImageCore2(currentEpImage, i2 == 2);
- }
- } else {
- throw new Exception();
- }
- }
- @WorkerThread
- private void setImageCore2(EPImage ePImage, boolean z) throws Exception {
- if (z) {
- mLayoutPosition.setPaperLandscape(ePImage.srcWidth > ePImage.srcHeight);
- fitCircumscribed();
- } else {
- setPaper(mPaperSizeId);
- }
- if (mLayoutPosition.isPreviewImageSizeValid()) {
- RectF previewImageCircumscribedTargetSize = mLayoutPosition.getPreviewImageCircumscribedTargetSize();
- mBitmap = localGetPreviewBitmap(ePImage, (int) previewImageCircumscribedTargetSize.width(), (int) previewImageCircumscribedTargetSize.height(), color, true, !z);
- return;
- }
- throw new Exception();
- }
- @WorkerThread
- private void setImageCore_RestorePreview(@NonNull PhotoPreviewImageList.Element element) throws Exception {
- restoreImage(element);
- reCalcPaperPosition();
- if (mLayoutPosition.isPreviewImageSizeValid()) {
- RectF previewImageCircumscribedTargetSize = mLayoutPosition.getPreviewImageCircumscribedTargetSize();
- mBitmap = localGetPreviewBitmap(element.getEPImage(), (int) previewImageCircumscribedTargetSize.width(), (int) previewImageCircumscribedTargetSize.height(), color, false, true);
- return;
- }
- throw new Exception();
- }
- @WorkerThread
- private Bitmap localGetPreviewBitmap(EPImage ePImage, int i, int i2, int i3, boolean z, boolean z2) {
- if (mPreviewBitmapMaker != null && z2) {
- mBitmap = mPreviewBitmapMaker.getPreviewBitmap(ePImage, i, i2, i3, z);
- Bitmap bitmap = mBitmap;
- if (bitmap != null) {
- return bitmap;
- }
- }
- mBitmap = getBitmap(ePImage, i, i2, i3, z);
- if (mBitmap == null) {
- return null;
- }
- Log.i(LOG_TAG, "bitmap <" + mBitmap.getWidth() + PreferencesConstants.COOKIE_DELIMITER + mBitmap.getHeight() + "> preview WxH <" + ePImage.previewWidth + PreferencesConstants.COOKIE_DELIMITER + ePImage.previewHeight + ">");
- return mBitmap;
- }
- @WorkerThread
- private boolean saveImage(int i) {
- try {
- PhotoPreviewImageList.Element element = imageList.getElement(i);
- EPImage ePImage = element.getEPImage();
- if (ePImage == null) {
- return false;
- }
- ePImage.previewImageRectCenterX = trans.x;
- ePImage.previewImageRectCenterY = trans.y;
- mLayoutPosition.copyPreviewPrintAreaToEpImage(ePImage);
- RectF calcPreviewImageRect = calcPreviewImageRect(mBitmap, scaleFactor, trans);
- ePImage.previewImageRectLeft = calcPreviewImageRect.left;
- ePImage.previewImageRectTop = calcPreviewImageRect.top;
- ePImage.previewImageRectRight = calcPreviewImageRect.right;
- ePImage.previewImageRectBottom = calcPreviewImageRect.bottom;
- ePImage.scaleFactor = scaleFactor;
- imageList.set(i, ePImage);
- element.setFitMode(mFitMode);
- return true;
- } catch (IndexOutOfBoundsException unused) {
- return false;
- }
- }
- @WorkerThread
- private void restoreImage(@NonNull PhotoPreviewImageList.Element element) {
- EPImage ePImage = element.getEPImage();
- trans.x = ePImage.previewImageRectCenterX;
- trans.y = ePImage.previewImageRectCenterY;
- mLayoutPosition.copyPreviewPrintAreaFromEpImage(ePImage);
- scaleFactor = ePImage.scaleFactor;
- mFitMode = element.getFitMode();
- }
- public boolean onTouchEvent(MotionEvent motionEvent) {
- boolean z = mGestureDetector.onTouchEvent(motionEvent) || mScaleGestureDetector.onTouchEvent(motionEvent);
- if ((motionEvent.getAction() & 255) == 1) {
- onMoveEventEnd();
- }
- if (z || super.onTouchEvent(motionEvent)) {
- return true;
- }
- return false;
- }
- private void onMoveEventEnd() {
- invalidate();
- }
- private void onMoveEventStarted(float f, float f2) {
- maskExpandPreview = false;
- invalidate();
- }
- private void onMoving(float f, float f2) {
- mFitMode = 0;
- if (mBitmap != null) {
- Point point = trans;
- point.x = (int) ((-f) + ((float) point.x));
- Point point2 = trans;
- point2.y = (int) ((-f2) + ((float) point2.y));
- adjustTrans(trans);
- invalidate();
- }
- }
- private void adjustTrans(@NonNull Point point) {
- synchronized (lockObj) {
- if (mLayoutPosition != null) {
- RectF previewImageCircumscribedTargetSize = mLayoutPosition.getPreviewImageCircumscribedTargetSize();
- EPImage currentEpImage = getCurrentEpImage();
- if (currentEpImage != null) {
- adjustPosition(point, MOVEMENT_MARGIN_RATE, previewImageCircumscribedTargetSize, (double) (((float) currentEpImage.previewWidth) * scaleFactor), (double) (((float) currentEpImage.previewHeight) * scaleFactor));
- }
- }
- }
- }
- private void adjustPosition(@NonNull Point point, double d, RectF rectF, double d2, double d3) {
- Point point2 = point;
- RectF rectF2 = rectF;
- double d4 = ((double) (rectF2.right - rectF2.left)) * d;
- double d5 = ((double) (rectF2.bottom - rectF2.top)) * d;
- double d6 = d2 / 2.0d;
- if (((double) rectF2.left) + d4 > ((double) point2.x) + d6) {
- point2.x = (int) ((((double) rectF2.left) + d4) - d6);
- }
- double d7 = d3 / 2.0d;
- if (((double) rectF2.top) + d5 > ((double) point2.y) + d7) {
- point2.y = (int) ((((double) rectF2.top) + d5) - d7);
- }
- if (((double) rectF2.right) - d4 < ((double) point2.x) - d6) {
- point2.x = (int) ((((double) rectF2.right) - d4) + d6);
- }
- if (((double) rectF2.bottom) - d5 < ((double) point2.y) - d7) {
- point2.y = (int) ((((double) rectF2.bottom) - d5) + d7);
- }
- }
- public void onSizeChanged(int i, int i2, int i3, int i4) {
- super.onSizeChanged(i, i2, i3, i4);
- synchronized (this) {
- mViewSize[0] = i;
- mViewSize[1] = i2;
- }
- ViewSizeChangeListener viewSizeChangeListener = mViewSizeChangeListener;
- if (viewSizeChangeListener != null) {
- viewSizeChangeListener.onViewSizeChanged();
- }
- }
- public void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- if (mDrawLock.tryLock()) {
- try {
- synchronized (lockObj) {
- if (!canvas.isHardwareAccelerated()) {
- if (maxBitmapWidth > 0 && maxBitmapHeight > 0) {
- maxBitmapWidth = -1;
- maxBitmapHeight = -1;
- }
- } else if (maxBitmapWidth < 0 || maxBitmapHeight < 0) {
- maxBitmapWidth = canvas.getMaximumBitmapWidth();
- maxBitmapHeight = canvas.getMaximumBitmapHeight();
- }
- RectF calcPreviewImageRect = mBitmap != null ? calcPreviewImageRect(mBitmap, scaleFactor, trans) : null;
- if (mLayoutPosition.getLayoutId() == 4) {
- drawCdPreviewAll(canvas, paint, mBitmap, mLayoutPosition, mBitmapDrawRect, maskExpandPreview, mPath, getResources().getColor(R.color.background_preview), calcPreviewImageRect);
- } else {
- drawPreview(canvas, paint, mBitmap, mLayoutPosition, mBitmapDrawRect, maskExpandPreview, getResources().getColor(R.color.background_preview), new int[]{getWidth(), getHeight()}, calcPreviewImageRect);
- }
- if (drawEndHandler != null) {
- Message message = new Message();
- message.what = 4;
- message.arg1 = imageNo;
- drawEndHandler.sendMessage(message);
- }
- }
- mDrawLock.unlock();
- } catch (Throwable th) {
- mDrawLock.unlock();
- throw th;
- }
- }
- }
- private void drawPreview(@NonNull Canvas canvas, @NonNull Paint paint2, @Nullable Bitmap bitmap, @NonNull ILayoutPosition iLayoutPosition, @NonNull Rect rect, boolean z, int i, int[] iArr, RectF rectF) {
- RectF rectF2;
- Canvas canvas2 = canvas;
- Paint paint3 = paint2;
- Bitmap bitmap2 = bitmap;
- Rect rect2 = rect;
- int layoutId = iLayoutPosition.getLayoutId();
- if (layoutId == 2) {
- rectF2 = iLayoutPosition.getPreviewImageCircumscribedTargetSize();
- } else {
- rectF2 = new RectF(iLayoutPosition.getPreviewPaperRect());
- }
- paint2.setColor(-1);
- canvas.drawRect(rectF2, paint2);
- if (bitmap2 != null) {
- rect.set(0, 0, bitmap.getWidth(), bitmap.getHeight());
- canvas.drawBitmap(bitmap, rect, rectF, (Paint) null);
- }
- drawBorderedOutsidePrintingArea(canvas, rectF2, layoutId, paint2, z, iLayoutPosition, i, iArr);
- }
- private static void drawBorderedOutsidePrintingArea(@NonNull Canvas canvas, @NonNull RectF rectF, int i, @NonNull Paint paint2, boolean z, @NonNull ILayoutPosition iLayoutPosition, int i2, @NonNull int[] iArr) {
- RectF rectF2 = rectF;
- int i3 = i;
- Paint paint3 = paint2;
- int i4 = i2;
- if (rectF2.left != 0.0f && rectF2.top != 0.0f && rectF2.right != 0.0f && rectF2.bottom != 0.0f) {
- paint3.setColor(i4);
- if (!z) {
- paint3.setAlpha(221);
- }
- int leftMargin = iLayoutPosition.getLeftMargin();
- int topMargin = iLayoutPosition.getTopMargin();
- int rightMargin = iLayoutPosition.getRightMargin();
- int bottomMargin = iLayoutPosition.getBottomMargin();
- float f = (float) leftMargin;
- Canvas canvas2 = canvas;
- Paint paint4 = paint2;
- canvas2.drawRect(0.0f, 0.0f, rectF2.left - f, (float) iArr[1], paint4);
- float f2 = (float) rightMargin;
- float f3 = (float) topMargin;
- canvas.drawRect(rectF2.left - f, 0.0f, rectF2.right + f2, rectF2.top - f3, paint4);
- canvas.drawRect(rectF2.right + f2, 0.0f, (float) iArr[0], (float) iArr[1], paint4);
- float f4 = (float) bottomMargin;
- canvas.drawRect(rectF2.left - f, rectF2.bottom + f4, rectF2.right + f2, (float) iArr[1], paint4);
- if (i3 == 2) {
- paint3.setColor(-1);
- } else if (i3 == 1) {
- paint3.setColor(i4);
- if (!z) {
- paint3.setAlpha(221);
- }
- }
- Paint paint5 = paint2;
- canvas.drawRect(rectF2.left - f, rectF2.top - f3, rectF2.left, rectF2.bottom + f4, paint5);
- canvas.drawRect(rectF2.left, rectF2.top - f3, rectF2.right, rectF2.top, paint5);
- canvas.drawRect(rectF2.right, rectF2.top - f3, rectF2.right + f2, rectF2.bottom + f4, paint5);
- canvas.drawRect(rectF2.left, rectF2.bottom, rectF2.right, rectF2.bottom + f4, paint2);
- }
- }
- private void drawCdPreviewAll(@NonNull Canvas canvas, @NonNull Paint paint2, @Nullable Bitmap bitmap, @NonNull ILayoutPosition iLayoutPosition, @NonNull Rect rect, boolean z, @NonNull Path path, int i, @NonNull RectF rectF) {
- float f;
- if (bitmap != null) {
- rect.set(0, 0, bitmap.getWidth(), bitmap.getHeight());
- canvas.drawBitmap(bitmap, rect, rectF, (Paint) null);
- }
- RectF previewImageCircumscribedTargetSize = iLayoutPosition.getPreviewImageCircumscribedTargetSize();
- paint2.setColor(i);
- if (!z) {
- paint2.setAlpha(221);
- }
- if (previewImageCircumscribedTargetSize.height() > previewImageCircumscribedTargetSize.width()) {
- f = previewImageCircumscribedTargetSize.width() / 2.0f;
- } else {
- f = previewImageCircumscribedTargetSize.height() / 2.0f;
- }
- path.reset();
- canvas.drawCircle(previewImageCircumscribedTargetSize.centerX(), previewImageCircumscribedTargetSize.centerY(), (43.0f * f) / 116.0f, paint2);
- path.addCircle(previewImageCircumscribedTargetSize.centerX(), previewImageCircumscribedTargetSize.centerY(), f, Path.Direction.CCW);
- canvas.clipPath(path, Region.Op.DIFFERENCE);
- canvas.drawPaint(paint2);
- }
- @WorkerThread
- @Deprecated
- @NonNull
- public RectF calcPreviewImageRect(@NonNull Bitmap bitmap, float f, @NonNull Point point) {
- return calcPreviewImageRect(bitmap.getWidth(), bitmap.getHeight(), f, point);
- }
- @WorkerThread
- @NonNull
- private RectF calcPreviewImageRect(int i, int i2, float f, @NonNull Point point) {
- RectF rectF = new RectF();
- float f2 = ((float) i) * f;
- rectF.left = ((float) point.x) - (f2 / 2.0f);
- float f3 = ((float) i2) * f;
- rectF.top = ((float) point.y) - (f3 / 2.0f);
- rectF.right = rectF.left + f2;
- rectF.bottom = rectF.top + f3;
- return rectF;
- }
- static class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
- private final PhotoPreview mPreviewView;
- public MyGestureListener(PhotoPreview photoPreview) {
- mPreviewView = photoPreview;
- }
- public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent2, float f, float f2) {
- mPreviewView.onMoving(f, f2);
- return true;
- }
- public boolean onDown(MotionEvent motionEvent) {
- mPreviewView.onMoveEventStarted(motionEvent.getX(), motionEvent.getY());
- return true;
- }
- public boolean onDoubleTap(MotionEvent motionEvent) {
- mPreviewView.changeFitModeAndRefresh();
- return true;
- }
- }
- static class MyScaledGestureListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
- private final PhotoPreview mPreviewView;
- public MyScaledGestureListener(PhotoPreview photoPreview) {
- mPreviewView = photoPreview;
- }
- public boolean onScaleBegin(ScaleGestureDetector scaleGestureDetector) {
- mPreviewView.startScaleChange();
- return super.onScaleBegin(scaleGestureDetector);
- }
- public boolean onScale(ScaleGestureDetector scaleGestureDetector) {
- mPreviewView.changeScale(scaleGestureDetector.getScaleFactor());
- return super.onScale(scaleGestureDetector);
- }
- }
- }
|