CarrotChat v2.8.60.240131版本的 MD5 值为:2baf8b9f31830b86b5c5a85ae6b47e05

以下内容为反编译后的 GestureImageView.java 源代码,内容仅作参考


package ak.im.ui.anim;

import ak.im.listener.n;
import ak.im.listener.o;
import ak.im.utils.Log;
import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import com.mobile.auth.gatewayauth.Constant;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
public class GestureImageView extends AppCompatImageView {
    private ColorFilter A;
    private int B;
    private int C;
    private n D;
    private o E;
    private View.OnTouchListener F;
    private View.OnClickListener G;
    public n H;
    private final Semaphore a;
    private ak.im.ui.anim.b f2645b;
    private Drawable f2646c;
    private float f2647d;
    private float f2648e;
    private boolean f;
    private float g;
    private float h;
    private float i;
    private float j;
    private float k;
    private float l;
    private float m;
    private float n;
    private float o;
    private float p;
    private Float q;
    private Float r;
    private int s;
    private int t;
    private int u;
    private boolean v;
    private boolean w;
    private int x;
    private int y;
    private int z;

    public class a implements View.OnTouchListener {
        a() {
        }

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (GestureImageView.this.F != null) {
                GestureImageView.this.F.onTouch(view, motionEvent);
            }
            return GestureImageView.this.E.onTouch(view, motionEvent);
        }
    }

    class b implements n {
        b() {
        }

        @Override
        public void onPosition(float f, float f2) {
            double scaledWidth = GestureImageView.this.getScaledWidth() / 2.0d;
            double width = GestureImageView.this.getWidth();
            double d2 = f;
            if (d2 != scaledWidth && d2 != width - scaledWidth) {
                GestureImageView.this.getParent().requestDisallowInterceptTouchEvent(true);
            } else {
                GestureImageView.this.getParent().requestDisallowInterceptTouchEvent(false);
            }
        }

        @Override
        public void onScale(float f) {
        }

        @Override
        public void onTouch(float f, float f2) {
        }
    }

    public static class c {
        static final int[] a;

        static {
            int[] iArr = new int[ImageView.ScaleType.values().length];
            a = iArr;
            try {
                iArr[ImageView.ScaleType.CENTER.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                a[ImageView.ScaleType.CENTER_CROP.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                a[ImageView.ScaleType.CENTER_INSIDE.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
        }
    }

    public GestureImageView(Context context, AttributeSet attributeSet, int i) {
        this(context, attributeSet);
    }

    public static Method getMethod(Class cls, String str, Class[] clsArr) throws Exception {
        try {
            try {
                return cls.getDeclaredMethod(str, clsArr);
            } catch (NoSuchMethodException unused) {
                if (cls.getSuperclass() == null) {
                    return null;
                }
                return getMethod(cls.getSuperclass(), str, clsArr);
            }
        } catch (NoSuchMethodException unused2) {
            return cls.getMethod(str, clsArr);
        }
    }

    public void animationStart(d dVar) {
        ak.im.ui.anim.b bVar = this.f2645b;
        if (bVar != null) {
            bVar.play(dVar);
        }
    }

    public void animationStop() {
        ak.im.ui.anim.b bVar = this.f2645b;
        if (bVar != null) {
            bVar.cancel();
        }
    }

    protected void c(int i, int i2, int i3, int i4) {
        this.l = i3 / i;
        this.m = i4 / i2;
    }

    protected void d(int i, int i2, int i3, int i4) {
        int i5 = c.a[getScaleType().ordinal()];
        if (i5 == 1) {
            this.h = 1.0f;
        } else if (i5 == 2) {
            this.h = Math.max(i4 / i2, i3 / i);
        } else if (i5 != 3) {
        } else {
            if (i / i3 > i2 / i4) {
                this.h = this.l;
            } else {
                this.h = this.m;
            }
        }
    }

    protected void e() {
        Drawable drawable = this.f2646c;
        if (drawable != null) {
            drawable.setAlpha(this.z);
            this.f2646c.setFilterBitmap(true);
            ColorFilter colorFilter = this.A;
            if (colorFilter != null) {
                this.f2646c.setColorFilter(colorFilter);
            }
        }
        if (this.f) {
            return;
        }
        requestLayout();
        redraw();
    }

    protected boolean f() {
        Bitmap bitmap;
        Drawable drawable = this.f2646c;
        if (drawable == null || !(drawable instanceof BitmapDrawable) || (bitmap = ((BitmapDrawable) drawable).getBitmap()) == null) {
            return false;
        }
        return bitmap.isRecycled();
    }

    protected void g() {
        Drawable drawable;
        Bitmap bitmap;
        if (!this.v || (drawable = this.f2646c) == null || !(drawable instanceof BitmapDrawable) || (bitmap = ((BitmapDrawable) drawable).getBitmap()) == null) {
            return;
        }
        bitmap.recycle();
    }

    public float getCenterX() {
        return this.o;
    }

    public float getCenterY() {
        return this.p;
    }

    public int getDeviceOrientation() {
        return this.B;
    }

    @Override
    public Drawable getDrawable() {
        return this.f2646c;
    }

    public n getGestureImageViewListener() {
        return this.D;
    }

    public int getImageHeight() {
        Drawable drawable = this.f2646c;
        if (drawable != null) {
            return drawable.getIntrinsicHeight();
        }
        return 0;
    }

    @Override
    public Matrix getImageMatrix() {
        if (!this.w) {
            return super.getImageMatrix();
        }
        throw new UnsupportedOperationException("Not supported");
    }

    public int getImageWidth() {
        Drawable drawable = this.f2646c;
        if (drawable != null) {
            return drawable.getIntrinsicWidth();
        }
        return 0;
    }

    public float getImageX() {
        return this.f2647d;
    }

    public float getImageY() {
        return this.f2648e;
    }

    public float getScale() {
        return this.g;
    }

    public int getScaledHeight() {
        return Math.round(getImageHeight() * getScale());
    }

    public int getScaledWidth() {
        return Math.round(getImageWidth() * getScale());
    }

    protected void h(int i, int i2, int i3) {
        if (this.B != i3) {
            this.f = false;
            this.B = i3;
        }
        if (this.f2646c == null || this.f) {
            return;
        }
        int imageWidth = getImageWidth();
        int imageHeight = getImageHeight();
        this.s = Math.round(imageWidth / 2.0f);
        this.t = Math.round(imageHeight / 2.0f);
        int paddingLeft = i - (getPaddingLeft() + getPaddingRight());
        int paddingTop = i2 - (getPaddingTop() + getPaddingBottom());
        c(imageWidth, imageHeight, paddingLeft, paddingTop);
        if (this.h <= 0.0f) {
            d(imageWidth, imageHeight, paddingLeft, paddingTop);
        }
        this.g = this.h;
        float f = paddingLeft / 2.0f;
        this.o = f;
        this.p = paddingTop / 2.0f;
        Float f2 = this.q;
        if (f2 == null) {
            this.f2647d = f;
        } else {
            this.f2647d = f2.floatValue();
        }
        Float f3 = this.r;
        if (f3 == null) {
            this.f2648e = this.p;
        } else {
            this.f2648e = f3.floatValue();
        }
        this.E = new o(this, paddingLeft, paddingTop);
        if (isLandscape()) {
            this.E.setMinScale(this.k * this.l);
        } else {
            this.E.setMinScale(this.k * this.m);
        }
        this.E.setMaxScale(this.j * this.h);
        this.E.setFitScaleHorizontal(this.l);
        this.E.setFitScaleVertical(this.m);
        this.E.setCanvasWidth(paddingLeft);
        this.E.setCanvasHeight(paddingTop);
        this.E.setOnClickListener(this.G);
        Drawable drawable = this.f2646c;
        int i4 = this.s;
        int i5 = this.t;
        drawable.setBounds(-i4, -i5, i4, i5);
        super.setOnTouchListener(new a());
        this.f = true;
    }

    @Override
    public void invalidateDrawable(Drawable drawable) {
        if (!this.w) {
            super.invalidateDrawable(drawable);
            return;
        }
        throw new UnsupportedOperationException("Not supported");
    }

    public boolean isLandscape() {
        return getImageWidth() >= getImageHeight();
    }

    public boolean isOrientationAligned() {
        int i = this.B;
        if (i == 2) {
            return isLandscape();
        }
        if (i == 1) {
            return isPortrait();
        }
        return true;
    }

    public boolean isPortrait() {
        return getImageWidth() <= getImageHeight();
    }

    public boolean isRecycle() {
        return this.v;
    }

    public boolean isStrict() {
        return this.w;
    }

    public void moveBy(float f, float f2) {
        this.f2647d += f;
        this.f2648e += f2;
    }

    @Override
    protected void onAttachedToWindow() {
        ak.im.ui.anim.b bVar = new ak.im.ui.anim.b(this, "GestureImageViewAnimator");
        this.f2645b = bVar;
        bVar.start();
        int i = this.u;
        if (i >= 0 && this.f2646c == null) {
            setImageResource(i);
        }
        super.onAttachedToWindow();
    }

    @Override
    public int[] onCreateDrawableState(int i) {
        if (!this.w) {
            return super.onCreateDrawableState(i);
        }
        throw new UnsupportedOperationException("Not supported");
    }

    @Override
    protected void onDetachedFromWindow() {
        ak.im.ui.anim.b bVar = this.f2645b;
        if (bVar != null) {
            bVar.finish();
        }
        if (this.v && this.f2646c != null && !f()) {
            g();
            this.f2646c = null;
        }
        super.onDetachedFromWindow();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        if (this.f) {
            if (this.f2646c != null && !f()) {
                canvas.save();
                float f = this.i * this.g;
                canvas.translate(this.f2647d, this.f2648e);
                float f2 = this.n;
                if (f2 != 0.0f) {
                    canvas.rotate(f2);
                }
                if (f != 1.0f) {
                    canvas.scale(f, f);
                }
                this.f2646c.draw(canvas);
                canvas.restore();
            }
            if (this.a.availablePermits() <= 0) {
                this.a.release();
            }
        }
    }

    @Override
    protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
        super.onLayout(z, i, i2, i3, i4);
        if (z || !this.f) {
            h(this.y, this.x, getResources().getConfiguration().orientation);
        }
    }

    @Override
    protected void onMeasure(int i, int i2) {
        if (this.f2646c != null) {
            if (getResources().getConfiguration().orientation == 2) {
                this.x = View.MeasureSpec.getSize(i2);
                if (getLayoutParams().width == -2) {
                    this.y = Math.round(this.x * (getImageWidth() / getImageHeight()));
                } else {
                    this.y = View.MeasureSpec.getSize(i);
                }
            } else {
                this.y = View.MeasureSpec.getSize(i);
                if (getLayoutParams().height == -2) {
                    this.x = Math.round(this.y * (getImageHeight() / getImageWidth()));
                } else {
                    this.x = View.MeasureSpec.getSize(i2);
                }
            }
        } else {
            this.x = View.MeasureSpec.getSize(i2);
            this.y = View.MeasureSpec.getSize(i);
        }
        setMeasuredDimension(this.y, this.x);
    }

    public void redraw() {
        postInvalidate();
    }

    public void removeLongPressTask(boolean z) {
        cancelLongPress();
    }

    public void reset() {
        this.f2647d = this.o;
        this.f2648e = this.p;
        this.g = this.h;
        o oVar = this.E;
        if (oVar != null) {
            oVar.reset();
        }
        redraw();
    }

    @Override
    public void setAdjustViewBounds(boolean z) {
        if (!this.w) {
            super.setAdjustViewBounds(z);
            return;
        }
        throw new UnsupportedOperationException("Not supported");
    }

    @Override
    public void setAlpha(int i) {
        this.z = i;
        Drawable drawable = this.f2646c;
        if (drawable != null) {
            drawable.setAlpha(i);
        }
    }

    @Override
    public void setColorFilter(ColorFilter colorFilter) {
        this.A = colorFilter;
        Drawable drawable = this.f2646c;
        if (drawable != null) {
            drawable.setColorFilter(colorFilter);
        }
    }

    public void setGestureImageViewListener(n nVar) {
        this.D = nVar;
    }

    @Override
    public void setImageBitmap(Bitmap bitmap) {
        this.f2646c = new BitmapDrawable(getResources(), bitmap);
        e();
    }

    @Override
    public void setImageDrawable(Drawable drawable) {
        this.f2646c = drawable;
        e();
    }

    @Override
    public void setImageLevel(int i) {
        if (!this.w) {
            super.setImageLevel(i);
            return;
        }
        throw new UnsupportedOperationException("Not supported");
    }

    @Override
    public void setImageMatrix(Matrix matrix) {
        if (this.w) {
            throw new UnsupportedOperationException("Not supported");
        }
    }

    @Override
    @SuppressLint({"ResourceType"})
    public void setImageResource(int i) {
        if (this.f2646c != null) {
            g();
        }
        if (i >= 0) {
            this.u = i;
            setImageDrawable(getContext().getResources().getDrawable(i));
        }
    }

    @Override
    public void setImageState(int[] iArr, boolean z) {
        if (this.w) {
            throw new UnsupportedOperationException("Not supported");
        }
    }

    @Override
    public void setImageURI(Uri uri) {
        if ("content".equals(uri.getScheme())) {
            try {
                String[] strArr = {Constant.PROTOCOL_WEB_VIEW_ORIENTATION};
                Cursor query = getContext().getContentResolver().query(uri, strArr, null, null, null);
                if (query != null && query.moveToFirst()) {
                    this.C = query.getInt(query.getColumnIndex(strArr[0]));
                }
                InputStream openInputStream = getContext().getContentResolver().openInputStream(uri);
                Bitmap decodeStream = BitmapFactory.decodeStream(openInputStream);
                if (this.C != 0) {
                    Matrix matrix = new Matrix();
                    matrix.postRotate(this.C);
                    Bitmap createBitmap = Bitmap.createBitmap(decodeStream, 0, 0, decodeStream.getWidth(), decodeStream.getHeight(), matrix, true);
                    decodeStream.recycle();
                    setImageDrawable(new BitmapDrawable(getResources(), createBitmap));
                } else {
                    setImageDrawable(new BitmapDrawable(getResources(), decodeStream));
                }
                if (openInputStream != null) {
                    openInputStream.close();
                }
                if (query != null) {
                    query.close();
                }
            } catch (Exception e2) {
                Log.w("GestureImageView", "Unable to open content: " + uri, e2);
            }
        } else {
            setImageDrawable(Drawable.createFromPath(uri.toString()));
        }
        if (this.f2646c == null) {
            Log.e("GestureImageView", "resolveUri failed on bad bitmap uri: " + uri);
        }
    }

    public void setMaxScale(float f) {
        this.j = f;
        o oVar = this.E;
        if (oVar != null) {
            oVar.setMaxScale(f * this.h);
        }
    }

    public void setMinScale(float f) {
        this.k = f;
        o oVar = this.E;
        if (oVar != null) {
            oVar.setMinScale(f * this.l);
        }
    }

    @Override
    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.G = onClickListener;
        o oVar = this.E;
        if (oVar != null) {
            oVar.setOnClickListener(onClickListener);
        }
    }

    @Override
    public void setOnLongClickListener(@Nullable View.OnLongClickListener onLongClickListener) {
        super.setOnLongClickListener(onLongClickListener);
    }

    @Override
    public void setOnTouchListener(View.OnTouchListener onTouchListener) {
        this.F = onTouchListener;
    }

    public void setPosition(float f, float f2) {
        this.f2647d = f;
        this.f2648e = f2;
    }

    public void setRecycle(boolean z) {
        this.v = z;
    }

    @Override
    public void setRotation(float f) {
        this.n = f;
    }

    public void setScale(float f) {
        this.g = f;
    }

    @Override
    public void setScaleType(ImageView.ScaleType scaleType) {
        if (scaleType != ImageView.ScaleType.CENTER && scaleType != ImageView.ScaleType.CENTER_CROP && scaleType != ImageView.ScaleType.CENTER_INSIDE) {
            if (this.w) {
                throw new UnsupportedOperationException("Not supported");
            }
            return;
        }
        super.setScaleType(scaleType);
    }

    @Override
    public void setSelected(boolean z) {
        if (!this.w) {
            super.setSelected(z);
            return;
        }
        throw new UnsupportedOperationException("Not supported");
    }

    public void setStartingPosition(float f, float f2) {
        this.q = Float.valueOf(f);
        this.r = Float.valueOf(f2);
    }

    public void setStartingScale(float f) {
        this.h = f;
    }

    public void setStrict(boolean z) {
        this.w = z;
    }

    public boolean waitForDraw(long j) throws InterruptedException {
        return this.a.tryAcquire(j, TimeUnit.MILLISECONDS);
    }

    public GestureImageView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.a = new Semaphore(0);
        this.f2647d = 0.0f;
        this.f2648e = 0.0f;
        this.f = false;
        this.g = 1.0f;
        this.h = -1.0f;
        this.i = 1.0f;
        this.j = 5.0f;
        this.k = 0.75f;
        this.l = 1.0f;
        this.m = 1.0f;
        this.n = 0.0f;
        this.u = -1;
        this.v = false;
        this.w = false;
        this.z = 255;
        this.B = -1;
        this.H = new b();
        String attributeValue = attributeSet.getAttributeValue("http://schemas.android.com/apk/res/android", "scaleType");
        if (attributeValue == null || attributeValue.trim().length() == 0) {
            setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        }
        String attributeValue2 = attributeSet.getAttributeValue("http://schemas.polites.com/android", "start-x");
        String attributeValue3 = attributeSet.getAttributeValue("http://schemas.polites.com/android", "start-y");
        if (attributeValue2 != null && attributeValue2.trim().length() > 0) {
            this.q = Float.valueOf(Float.parseFloat(attributeValue2));
        }
        if (attributeValue3 != null && attributeValue3.trim().length() > 0) {
            this.r = Float.valueOf(Float.parseFloat(attributeValue3));
        }
        setStartingScale(attributeSet.getAttributeFloatValue("http://schemas.polites.com/android", "start-scale", this.h));
        setMinScale(attributeSet.getAttributeFloatValue("http://schemas.polites.com/android", "min-scale", this.k));
        setMaxScale(attributeSet.getAttributeFloatValue("http://schemas.polites.com/android", "max-scale", this.j));
        setStrict(attributeSet.getAttributeBooleanValue("http://schemas.polites.com/android", "strict", this.w));
        setRecycle(attributeSet.getAttributeBooleanValue("http://schemas.polites.com/android", "recycle", this.v));
        e();
        setGestureImageViewListener(this.H);
    }

    public GestureImageView(Context context) {
        super(context);
        this.a = new Semaphore(0);
        this.f2647d = 0.0f;
        this.f2648e = 0.0f;
        this.f = false;
        this.g = 1.0f;
        this.h = -1.0f;
        this.i = 1.0f;
        this.j = 5.0f;
        this.k = 0.75f;
        this.l = 1.0f;
        this.m = 1.0f;
        this.n = 0.0f;
        this.u = -1;
        this.v = false;
        this.w = false;
        this.z = 255;
        this.B = -1;
        this.H = new b();
        setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        e();
        setGestureImageViewListener(this.H);
    }
}