CarrotChat v2.8.80.240429版本的 MD5 值为:fdf98761f01e715a89df24b85b0d206e

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


package ak.im.ui.anim;

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 b0.d;
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;
import l.n;
import l.o;

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 f7641a;

    private b0.b f7642b;

    private Drawable f7643c;

    private float f7644d;

    private float f7645e;

    private boolean f7646f;

    private float f7647g;

    private float f7648h;

    private float f7649i;

    private float f7650j;

    private float f7651k;

    private float f7652l;

    private float f7653m;

    private float f7654n;

    private float f7655o;

    private float f7656p;

    private Float f7657q;

    private Float f7658r;

    private int f7659s;

    private int f7660t;

    private int f7661u;

    private boolean f7662v;

    private boolean f7663w;

    private int f7664x;

    private int f7665y;

    private int f7666z;

    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 f10, float f11) {
            double scaledWidth = GestureImageView.this.getScaledWidth() / 2.0d;
            double width = GestureImageView.this.getWidth();
            double d10 = f10;
            if (d10 != scaledWidth && d10 != width - scaledWidth) {
                GestureImageView.this.getParent().requestDisallowInterceptTouchEvent(true);
            } else {
                GestureImageView.this.getParent().requestDisallowInterceptTouchEvent(false);
            }
        }

        @Override
        public void onScale(float f10) {
        }

        @Override
        public void onTouch(float f10, float f11) {
        }
    }

    public static class c {

        static final int[] f7669a;

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

    public GestureImageView(Context context, AttributeSet attributeSet, int i10) {
        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) {
        b0.b bVar = this.f7642b;
        if (bVar != null) {
            bVar.play(dVar);
        }
    }

    public void animationStop() {
        b0.b bVar = this.f7642b;
        if (bVar != null) {
            bVar.cancel();
        }
    }

    protected void c(int i10, int i11, int i12, int i13) {
        this.f7652l = i12 / i10;
        this.f7653m = i13 / i11;
    }

    protected void d(int i10, int i11, int i12, int i13) {
        int i14 = c.f7669a[getScaleType().ordinal()];
        if (i14 != 1) {
            if (i14 != 2) {
                if (i14 == 3) {
                    if (i10 / i12 > i11 / i13) {
                        this.f7648h = this.f7652l;
                        return;
                    } else {
                        this.f7648h = this.f7653m;
                        return;
                    }
                }
                return;
            }
            this.f7648h = Math.max(i13 / i11, i12 / i10);
            return;
        }
        this.f7648h = 1.0f;
    }

    protected void e() {
        Drawable drawable = this.f7643c;
        if (drawable != null) {
            drawable.setAlpha(this.f7666z);
            this.f7643c.setFilterBitmap(true);
            ColorFilter colorFilter = this.A;
            if (colorFilter != null) {
                this.f7643c.setColorFilter(colorFilter);
            }
        }
        if (!this.f7646f) {
            requestLayout();
            redraw();
        }
    }

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

    protected void g() {
        Drawable drawable;
        Bitmap bitmap;
        if (this.f7662v && (drawable = this.f7643c) != null && (drawable instanceof BitmapDrawable) && (bitmap = ((BitmapDrawable) drawable).getBitmap()) != null) {
            bitmap.recycle();
        }
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

    protected void h(int i10, int i11, int i12) {
        if (this.B != i12) {
            this.f7646f = false;
            this.B = i12;
        }
        if (this.f7643c != null && !this.f7646f) {
            int imageWidth = getImageWidth();
            int imageHeight = getImageHeight();
            this.f7659s = Math.round(imageWidth / 2.0f);
            this.f7660t = Math.round(imageHeight / 2.0f);
            int paddingLeft = i10 - (getPaddingLeft() + getPaddingRight());
            int paddingTop = i11 - (getPaddingTop() + getPaddingBottom());
            c(imageWidth, imageHeight, paddingLeft, paddingTop);
            if (this.f7648h <= 0.0f) {
                d(imageWidth, imageHeight, paddingLeft, paddingTop);
            }
            this.f7647g = this.f7648h;
            float f10 = paddingLeft / 2.0f;
            this.f7655o = f10;
            this.f7656p = paddingTop / 2.0f;
            Float f11 = this.f7657q;
            if (f11 == null) {
                this.f7644d = f10;
            } else {
                this.f7644d = f11.floatValue();
            }
            Float f12 = this.f7658r;
            if (f12 == null) {
                this.f7645e = this.f7656p;
            } else {
                this.f7645e = f12.floatValue();
            }
            this.E = new o(this, paddingLeft, paddingTop);
            if (isLandscape()) {
                this.E.setMinScale(this.f7651k * this.f7652l);
            } else {
                this.E.setMinScale(this.f7651k * this.f7653m);
            }
            this.E.setMaxScale(this.f7650j * this.f7648h);
            this.E.setFitScaleHorizontal(this.f7652l);
            this.E.setFitScaleVertical(this.f7653m);
            this.E.setCanvasWidth(paddingLeft);
            this.E.setCanvasHeight(paddingTop);
            this.E.setOnClickListener(this.G);
            Drawable drawable = this.f7643c;
            int i13 = this.f7659s;
            int i14 = this.f7660t;
            drawable.setBounds(-i13, -i14, i13, i14);
            super.setOnTouchListener(new a());
            this.f7646f = true;
        }
    }

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

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

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

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

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

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

    public void moveBy(float f10, float f11) {
        this.f7644d += f10;
        this.f7645e += f11;
    }

    @Override
    protected void onAttachedToWindow() {
        b0.b bVar = new b0.b(this, "GestureImageViewAnimator");
        this.f7642b = bVar;
        bVar.start();
        int i10 = this.f7661u;
        if (i10 >= 0 && this.f7643c == null) {
            setImageResource(i10);
        }
        super.onAttachedToWindow();
    }

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

    @Override
    protected void onDetachedFromWindow() {
        b0.b bVar = this.f7642b;
        if (bVar != null) {
            bVar.finish();
        }
        if (this.f7662v && this.f7643c != null && !f()) {
            g();
            this.f7643c = null;
        }
        super.onDetachedFromWindow();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        if (this.f7646f) {
            if (this.f7643c != null && !f()) {
                canvas.save();
                float f10 = this.f7649i * this.f7647g;
                canvas.translate(this.f7644d, this.f7645e);
                float f11 = this.f7654n;
                if (f11 != 0.0f) {
                    canvas.rotate(f11);
                }
                if (f10 != 1.0f) {
                    canvas.scale(f10, f10);
                }
                this.f7643c.draw(canvas);
                canvas.restore();
            }
            if (this.f7641a.availablePermits() <= 0) {
                this.f7641a.release();
            }
        }
    }

    @Override
    protected void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        super.onLayout(z10, i10, i11, i12, i13);
        if (z10 || !this.f7646f) {
            h(this.f7665y, this.f7664x, getResources().getConfiguration().orientation);
        }
    }

    @Override
    protected void onMeasure(int i10, int i11) {
        if (this.f7643c != null) {
            if (getResources().getConfiguration().orientation == 2) {
                this.f7664x = View.MeasureSpec.getSize(i11);
                if (getLayoutParams().width == -2) {
                    this.f7665y = Math.round(this.f7664x * (getImageWidth() / getImageHeight()));
                } else {
                    this.f7665y = View.MeasureSpec.getSize(i10);
                }
            } else {
                this.f7665y = View.MeasureSpec.getSize(i10);
                if (getLayoutParams().height == -2) {
                    this.f7664x = Math.round(this.f7665y * (getImageHeight() / getImageWidth()));
                } else {
                    this.f7664x = View.MeasureSpec.getSize(i11);
                }
            }
        } else {
            this.f7664x = View.MeasureSpec.getSize(i11);
            this.f7665y = View.MeasureSpec.getSize(i10);
        }
        setMeasuredDimension(this.f7665y, this.f7664x);
    }

    public void redraw() {
        postInvalidate();
    }

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

    public void reset() {
        this.f7644d = this.f7655o;
        this.f7645e = this.f7656p;
        this.f7647g = this.f7648h;
        o oVar = this.E;
        if (oVar != null) {
            oVar.reset();
        }
        redraw();
    }

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

    @Override
    public void setAlpha(int i10) {
        this.f7666z = i10;
        Drawable drawable = this.f7643c;
        if (drawable != null) {
            drawable.setAlpha(i10);
        }
    }

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

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

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

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

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

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

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

    @Override
    public void setImageState(int[] iArr, boolean z10) {
        if (!this.f7663w) {
        } else {
            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 inputStream = null;
                try {
                    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 (Throwable th) {
                    if (0 != 0) {
                        inputStream.close();
                    }
                    if (query != null) {
                        query.close();
                    }
                    throw th;
                }
            } catch (Exception e10) {
                Log.w("GestureImageView", "Unable to open content: " + uri, e10);
            }
        } else {
            setImageDrawable(Drawable.createFromPath(uri.toString()));
        }
        if (this.f7643c == null) {
            Log.e("GestureImageView", "resolveUri failed on bad bitmap uri: " + uri);
        }
    }

    public void setMaxScale(float f10) {
        this.f7650j = f10;
        o oVar = this.E;
        if (oVar != null) {
            oVar.setMaxScale(f10 * this.f7648h);
        }
    }

    public void setMinScale(float f10) {
        this.f7651k = f10;
        o oVar = this.E;
        if (oVar != null) {
            oVar.setMinScale(f10 * this.f7652l);
        }
    }

    @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 f10, float f11) {
        this.f7644d = f10;
        this.f7645e = f11;
    }

    public void setRecycle(boolean z10) {
        this.f7662v = z10;
    }

    @Override
    public void setRotation(float f10) {
        this.f7654n = f10;
    }

    public void setScale(float f10) {
        this.f7647g = f10;
    }

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

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

    public void setStartingPosition(float f10, float f11) {
        this.f7657q = Float.valueOf(f10);
        this.f7658r = Float.valueOf(f11);
    }

    public void setStartingScale(float f10) {
        this.f7648h = f10;
    }

    public void setStrict(boolean z10) {
        this.f7663w = z10;
    }

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

    public GestureImageView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f7641a = new Semaphore(0);
        this.f7644d = 0.0f;
        this.f7645e = 0.0f;
        this.f7646f = false;
        this.f7647g = 1.0f;
        this.f7648h = -1.0f;
        this.f7649i = 1.0f;
        this.f7650j = 5.0f;
        this.f7651k = 0.75f;
        this.f7652l = 1.0f;
        this.f7653m = 1.0f;
        this.f7654n = 0.0f;
        this.f7661u = -1;
        this.f7662v = false;
        this.f7663w = false;
        this.f7666z = 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.f7657q = Float.valueOf(Float.parseFloat(attributeValue2));
        }
        if (attributeValue3 != null && attributeValue3.trim().length() > 0) {
            this.f7658r = Float.valueOf(Float.parseFloat(attributeValue3));
        }
        setStartingScale(attributeSet.getAttributeFloatValue("http://schemas.polites.com/android", "start-scale", this.f7648h));
        setMinScale(attributeSet.getAttributeFloatValue("http://schemas.polites.com/android", "min-scale", this.f7651k));
        setMaxScale(attributeSet.getAttributeFloatValue("http://schemas.polites.com/android", "max-scale", this.f7650j));
        setStrict(attributeSet.getAttributeBooleanValue("http://schemas.polites.com/android", "strict", this.f7663w));
        setRecycle(attributeSet.getAttributeBooleanValue("http://schemas.polites.com/android", "recycle", this.f7662v));
        e();
        setGestureImageViewListener(this.H);
    }

    public GestureImageView(Context context) {
        super(context);
        this.f7641a = new Semaphore(0);
        this.f7644d = 0.0f;
        this.f7645e = 0.0f;
        this.f7646f = false;
        this.f7647g = 1.0f;
        this.f7648h = -1.0f;
        this.f7649i = 1.0f;
        this.f7650j = 5.0f;
        this.f7651k = 0.75f;
        this.f7652l = 1.0f;
        this.f7653m = 1.0f;
        this.f7654n = 0.0f;
        this.f7661u = -1;
        this.f7662v = false;
        this.f7663w = false;
        this.f7666z = 255;
        this.B = -1;
        this.H = new b();
        setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        e();
        setGestureImageViewListener(this.H);
    }
}