曹妃甸核酸检测平台.apk(点击下载) / GestureImageView.java


package com.polites.android;

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.View;
import android.widget.ImageView;
import com.yht.util.s;
import java.io.InputStream;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

public class GestureImageView extends ImageView {
    private ColorFilter A;
    private int B;
    private int C;
    private h D;
    private m E;
    private View.OnTouchListener F;
    private View.OnClickListener G;

    /* renamed from: a  reason: collision with root package name */
    private final Semaphore f12022a;

    /* renamed from: b  reason: collision with root package name */
    private b f12023b;

    /* renamed from: c  reason: collision with root package name */
    private Drawable f12024c;

    /* renamed from: d  reason: collision with root package name */
    private float f12025d;

    /* renamed from: e  reason: collision with root package name */
    private float f12026e;

    /* renamed from: f  reason: collision with root package name */
    private boolean f12027f;

    /* renamed from: g  reason: collision with root package name */
    private float f12028g;

    /* renamed from: h  reason: collision with root package name */
    private float f12029h;
    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 GestureImageView(Context context) {
        super(context);
        this.f12022a = new Semaphore(0);
        this.f12025d = 0.0f;
        this.f12026e = 0.0f;
        this.f12027f = false;
        this.f12028g = 1.0f;
        this.f12029h = -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;
        setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        b();
    }

    public GestureImageView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f12022a = new Semaphore(0);
        this.f12025d = 0.0f;
        this.f12026e = 0.0f;
        this.f12027f = false;
        this.f12028g = 1.0f;
        this.f12029h = -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;
        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.f12029h));
        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));
        b();
    }

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

    public void a() {
        b bVar = this.f12023b;
        if (bVar != null) {
            bVar.b();
        }
    }

    public void a(float f2, float f3) {
        this.f12025d = f2;
        this.f12026e = f3;
    }

    /* access modifiers changed from: protected */
    public void a(int i2, int i3, int i4) {
        m mVar;
        float f2;
        float f3;
        if (this.B != i4) {
            this.f12027f = false;
            this.B = i4;
        }
        if (this.f12024c != null && !this.f12027f) {
            int imageWidth = getImageWidth();
            int imageHeight = getImageHeight();
            this.s = Math.round(((float) imageWidth) / 2.0f);
            this.t = Math.round(((float) imageHeight) / 2.0f);
            int paddingLeft = i2 - (getPaddingLeft() + getPaddingRight());
            int paddingTop = i3 - (getPaddingTop() + getPaddingBottom());
            a(imageWidth, imageHeight, paddingLeft, paddingTop);
            if (this.f12029h <= 0.0f) {
                b(imageWidth, imageHeight, paddingLeft, paddingTop);
            }
            this.f12028g = this.f12029h;
            this.o = ((float) paddingLeft) / 2.0f;
            this.p = ((float) paddingTop) / 2.0f;
            Float f4 = this.q;
            this.f12025d = f4 == null ? this.o : f4.floatValue();
            Float f5 = this.r;
            this.f12026e = f5 == null ? this.p : f5.floatValue();
            this.E = new m(this, paddingLeft, paddingTop);
            if (c()) {
                mVar = this.E;
                f3 = this.k;
                f2 = this.l;
            } else {
                mVar = this.E;
                f3 = this.k;
                f2 = this.m;
            }
            mVar.d(f3 * f2);
            this.E.c(this.j * this.f12029h);
            this.E.a(this.l);
            this.E.b(this.m);
            this.E.b(paddingLeft);
            this.E.a(paddingTop);
            this.E.setOnClickListener(this.G);
            Drawable drawable = this.f12024c;
            int i5 = this.s;
            int i6 = this.t;
            drawable.setBounds(-i5, -i6, i5, i6);
            super.setOnTouchListener(new f(this));
            this.f12027f = true;
        }
    }

    /* access modifiers changed from: protected */
    public void a(int i2, int i3, int i4, int i5) {
        this.l = ((float) i4) / ((float) i2);
        this.m = ((float) i5) / ((float) i3);
    }

    public void a(a aVar) {
        b bVar = this.f12023b;
        if (bVar != null) {
            bVar.a(aVar);
        }
    }

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

    /* access modifiers changed from: protected */
    public void b() {
        Drawable drawable = this.f12024c;
        if (drawable != null) {
            drawable.setAlpha(this.z);
            this.f12024c.setFilterBitmap(true);
            ColorFilter colorFilter = this.A;
            if (colorFilter != null) {
                this.f12024c.setColorFilter(colorFilter);
            }
        }
        if (!this.f12027f) {
            requestLayout();
            f();
        }
    }

    /* access modifiers changed from: protected */
    public void b(int i2, int i3, int i4, int i5) {
        float f2;
        int i6 = g.f12043a[getScaleType().ordinal()];
        if (i6 == 1) {
            f2 = 1.0f;
        } else if (i6 == 2) {
            f2 = Math.max(((float) i5) / ((float) i3), ((float) i4) / ((float) i2));
        } else if (i6 == 3) {
            f2 = ((float) i2) / ((float) i4) > ((float) i3) / ((float) i5) ? this.l : this.m;
        } else {
            return;
        }
        this.f12029h = f2;
    }

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

    /* access modifiers changed from: protected */
    public boolean d() {
        Bitmap bitmap;
        Drawable drawable = this.f12024c;
        if (drawable == null || !(drawable instanceof BitmapDrawable) || (bitmap = ((BitmapDrawable) drawable).getBitmap()) == null) {
            return false;
        }
        return bitmap.isRecycled();
    }

    /* access modifiers changed from: protected */
    public void e() {
        Drawable drawable;
        Bitmap bitmap;
        if (this.v && (drawable = this.f12024c) != null && (drawable instanceof BitmapDrawable) && (bitmap = ((BitmapDrawable) drawable).getBitmap()) != null) {
            bitmap.recycle();
        }
    }

    public void f() {
        postInvalidate();
    }

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

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

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

    public Drawable getDrawable() {
        return this.f12024c;
    }

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

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

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

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

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

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

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

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

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

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

    /* access modifiers changed from: protected */
    public void onAttachedToWindow() {
        this.f12023b = new b(this, "GestureImageViewAnimator");
        this.f12023b.start();
        int i2 = this.u;
        if (i2 >= 0 && this.f12024c == null) {
            setImageResource(i2);
        }
        super.onAttachedToWindow();
    }

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

    /* access modifiers changed from: protected */
    public void onDetachedFromWindow() {
        b bVar = this.f12023b;
        if (bVar != null) {
            bVar.c();
        }
        if (this.v && this.f12024c != null && !d()) {
            e();
            this.f12024c = null;
        }
        super.onDetachedFromWindow();
    }

    /* access modifiers changed from: protected */
    public void onDraw(Canvas canvas) {
        if (this.f12027f) {
            if (this.f12024c != null && !d()) {
                canvas.save();
                float f2 = this.i * this.f12028g;
                canvas.translate(this.f12025d, this.f12026e);
                float f3 = this.n;
                if (f3 != 0.0f) {
                    canvas.rotate(f3);
                }
                if (f2 != 1.0f) {
                    canvas.scale(f2, f2);
                }
                this.f12024c.draw(canvas);
                canvas.restore();
            }
            if (this.f12022a.availablePermits() <= 0) {
                this.f12022a.release();
            }
        }
    }

    /* access modifiers changed from: protected */
    public void onLayout(boolean z2, int i2, int i3, int i4, int i5) {
        super.onLayout(z2, i2, i3, i4, i5);
        if (z2 || !this.f12027f) {
            a(this.y, this.x, getResources().getConfiguration().orientation);
        }
    }

    /* access modifiers changed from: protected */
    public void onMeasure(int i2, int i3) {
        int i4;
        int i5;
        if (this.f12024c == null) {
            this.x = View.MeasureSpec.getSize(i3);
        } else if (getResources().getConfiguration().orientation == 2) {
            this.x = View.MeasureSpec.getSize(i3);
            if (getLayoutParams().width == -2) {
                i4 = Math.round(((float) this.x) * (((float) getImageWidth()) / ((float) getImageHeight())));
                this.y = i4;
                setMeasuredDimension(this.y, this.x);
            }
        } else {
            this.y = View.MeasureSpec.getSize(i2);
            if (getLayoutParams().height == -2) {
                i5 = Math.round(((float) this.y) * (((float) getImageHeight()) / ((float) getImageWidth())));
            } else {
                i5 = View.MeasureSpec.getSize(i3);
            }
            this.x = i5;
            setMeasuredDimension(this.y, this.x);
        }
        i4 = View.MeasureSpec.getSize(i2);
        this.y = i4;
        setMeasuredDimension(this.y, this.x);
    }

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

    @Override // android.widget.ImageView
    public void setAlpha(int i2) {
        this.z = i2;
        Drawable drawable = this.f12024c;
        if (drawable != null) {
            drawable.setAlpha(i2);
        }
    }

    @Override // android.widget.ImageView
    public void setColorFilter(ColorFilter colorFilter) {
        this.A = colorFilter;
        Drawable drawable = this.f12024c;
        if (drawable != null) {
            drawable.setColorFilter(colorFilter);
        }
    }

    public void setGestureImageViewListener(h hVar) {
        this.D = hVar;
    }

    public void setImageBitmap(Bitmap bitmap) {
        this.f12024c = new BitmapDrawable(getResources(), bitmap);
        b();
    }

    public void setImageDrawable(Drawable drawable) {
        this.f12024c = drawable;
        b();
    }

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

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

    public void setImageResource(int i2) {
        if (this.f12024c != null) {
            e();
        }
        if (i2 >= 0) {
            this.u = i2;
            setImageDrawable(getContext().getResources().getDrawable(i2));
        }
    }

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

    public void setImageURI(Uri uri) {
        if ("content".equals(uri.getScheme())) {
            try {
                String[] strArr = {"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 = getContext().getContentResolver().openInputStream(uri);
                    Bitmap decodeStream = BitmapFactory.decodeStream(inputStream);
                    if (this.C != 0) {
                        Matrix matrix = new Matrix();
                        matrix.postRotate((float) 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));
                    }
                } finally {
                    if (inputStream != null) {
                        inputStream.close();
                    }
                    if (query != null) {
                        query.close();
                    }
                }
            } catch (Exception e2) {
                s.f("GestureImageView", "Unable to open content: " + uri + "  Exception:" + e2.getMessage());
            }
        } else {
            setImageDrawable(Drawable.createFromPath(uri.toString()));
        }
        if (this.f12024c == null) {
            s.b("GestureImageView", "resolveUri failed on bad bitmap uri: " + uri);
        }
    }

    public void setMaxScale(float f2) {
        this.j = f2;
        m mVar = this.E;
        if (mVar != null) {
            mVar.c(f2 * this.f12029h);
        }
    }

    public void setMinScale(float f2) {
        this.k = f2;
        m mVar = this.E;
        if (mVar != null) {
            mVar.d(f2 * this.l);
        }
    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.G = onClickListener;
        m mVar = this.E;
        if (mVar != null) {
            mVar.setOnClickListener(onClickListener);
        }
    }

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

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

    public void setRotation(float f2) {
        this.n = f2;
    }

    public void setScale(float f2) {
        this.f12028g = f2;
    }

    public void setScaleType(ImageView.ScaleType scaleType) {
        if (scaleType == ImageView.ScaleType.CENTER || scaleType == ImageView.ScaleType.CENTER_CROP || scaleType == ImageView.ScaleType.CENTER_INSIDE) {
            super.setScaleType(scaleType);
        } else if (this.w) {
            throw new UnsupportedOperationException("Not supported");
        }
    }

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

    public void setStartingScale(float f2) {
        this.f12029h = f2;
    }

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