package com.tencent.mm.plugin.scanner.ui;

import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.view.GestureDetector;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import com.tencent.mm.plugin.scanner.a.m;
import com.tencent.mm.plugin.scanner.util.b;
import com.tencent.mm.sdk.platformtools.BackwardSupportUtil;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ak;

public abstract class i {
    protected ProgressDialog ehJ = null;
    protected TextView iqU;
    GestureDetector lCs;
    protected Point lUF;
    protected boolean ovx;
    protected long qel;
    protected Rect qem;
    protected b qen;
    protected Point qeo;
    protected int qep;
    protected int qeq;
    protected int qer = 40;
    protected int qes = 20;
    protected b qet;
    protected int qeu;
    protected boolean qev;
    protected ak qew = new 1(this);

    public abstract void cgN();

    public abstract b cgO();

    public abstract int cgP();

    public abstract int cgQ();

    public abstract void cgR();

    public abstract boolean cgS();

    public abstract boolean cgT();

    public abstract void j(Rect rect);

    public abstract void onDestroy();

    public abstract void onResume();

    public final b chu() {
        return this.qet;
    }

    /* Access modifiers changed, original: protected|final */
    public final void kl(boolean z) {
        if (this.iqU != null) {
            if (z) {
                this.iqU.setVisibility(4);
                this.qew.sendEmptyMessageDelayed(1, 210);
                return;
            }
            this.qew.removeMessages(1);
            this.iqU.setVisibility(4);
        }
    }

    public i(b bVar, Point point) {
        this.qet = bVar;
        this.qeo = point;
    }

    public i(b bVar, Point point, byte b) {
        this.qet = bVar;
        this.qeo = point;
        this.qer = 50;
    }

    /* Access modifiers changed, original: protected */
    public void onPause() {
        if (this.ehJ != null && this.ehJ.isShowing()) {
            this.ehJ.dismiss();
        }
    }

    public final void e(Point point) {
        this.qeo = point;
    }

    /* Access modifiers changed, original: protected */
    public void dw(View view) {
    }

    /* Access modifiers changed, original: protected|final */
    public final double fd(int i, int i2) {
        Activity context = this.qet.getContext();
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getMetrics(displayMetrics);
        double d = ((double) displayMetrics.densityDpi) / 160.0d;
        ab.d("MicroMsg.scanner.ScanMode", "dpiLevel [%s]", new Object[]{Double.valueOf(d)});
        int i3 = (int) (((float) this.qeo.x) * 0.85f);
        int i4 = (int) (((float) this.qeo.y) * 0.85f);
        int i5;
        if ((this instanceof j) || (this instanceof c)) {
            i3 = (int) (((float) this.qeo.y) * 0.85f);
            i5 = (int) (((float) this.qeo.x) * 0.85f);
        } else {
            i5 = i4;
        }
        float f = 1.0f;
        if (d <= 1.2d) {
            f = (this.qeo == null || this.qeo.x + this.qeo.y <= 1560) ? (this.qeo == null || this.qeo.x + this.qeo.y <= 1460) ? 0.9f : 1.1f : 1.7f;
        } else if (this.qeo.x + this.qeo.y > 3000 && d < 2.4d) {
            f = 1.6f;
        }
        this.qep = BackwardSupportUtil.b.b(this.qet.getContext(), ((float) i) * f);
        this.qeq = BackwardSupportUtil.b.b(this.qet.getContext(), ((float) i2) * f);
        if (this.qep > i3 || this.qeq > i5) {
            while (true) {
                if (this.qep <= i3 && this.qeq <= i5) {
                    break;
                }
                this.qep = BackwardSupportUtil.b.b(this.qet.getContext(), ((float) i) * f);
                this.qeq = BackwardSupportUtil.b.b(this.qet.getContext(), ((float) i2) * f);
                f -= 0.1f;
            }
            ab.i("MicroMsg.scanner.ScanMode", "final adjust ratio: %s", new Object[]{Float.valueOf(f)});
        }
        if (this.qep % 2 == 1) {
            this.qep++;
        }
        if (this.qeq % 2 == 1) {
            this.qeq++;
        }
        ab.d("MicroMsg.scanner.ScanMode", "frame, width:%d, height:%d, visDisplayFrameRes:%s", new Object[]{Integer.valueOf(this.qep), Integer.valueOf(this.qeq), this.qeo});
        return d;
    }

    /* Access modifiers changed, original: protected */
    public Rect H(boolean z, boolean z2) {
        if (this.qem == null || z) {
            int i;
            int i2;
            int i3;
            int i4;
            int i5 = this.qeo.x;
            int i6 = this.qeo.y;
            if (!z2) {
                i = (i5 / 2) - (this.qep / 2);
                i2 = (i5 / 2) + (this.qep / 2);
                i3 = (i6 / 2) - (this.qeq / 2);
                i4 = this.qeq + i3;
            } else if (i5 < i6) {
                i = (i6 / 2) - (this.qep / 2);
                i2 = (i6 / 2) + (this.qep / 2);
                i3 = BackwardSupportUtil.b.b(this.qet.getContext(), (float) this.qes);
                i4 = this.qeq + i3;
            } else {
                i = (i5 / 2) - (this.qep / 2);
                i2 = (i5 / 2) + (this.qep / 2);
                i3 = BackwardSupportUtil.b.b(this.qet.getContext(), (float) this.qes);
                i4 = this.qeq + i3;
            }
            ab.d("MicroMsg.scanner.ScanMode", "framingRect: width = %s, height = %s; left = %s, right = %s, top = %s, bottom = %s", new Object[]{Integer.valueOf(i5), Integer.valueOf(i6), Integer.valueOf(i), Integer.valueOf(i2), Integer.valueOf(i3), Integer.valueOf(i4)});
            this.qem = new Rect(i, i3, i2, i4);
        }
        return this.qem;
    }

    /* Access modifiers changed, original: protected */
    public Rect km(boolean z) {
        return H(true, z);
    }

    /* Access modifiers changed, original: protected */
    public void f(Point point) {
        this.lUF = point;
    }

    /* Access modifiers changed, original: protected */
    public void kn(boolean z) {
        this.ovx = z;
    }

    public final void ko(boolean z) {
        if (this.iqU != null) {
            this.iqU.setVisibility(z ? 0 : 4);
        }
    }

    /* Access modifiers changed, original: protected|final */
    public final void dx(View view) {
        this.lCs = new GestureDetector(new 2(this));
        view.setOnTouchListener(new 3(this));
    }

    /* Access modifiers changed, original: protected */
    public void a(byte[] bArr, Point point, int i, Rect rect) {
        ab.i("MicroMsg.scanner.ScanMode", "decode count:" + m.pZK.pZN);
        if (cgO() != null) {
            cgO().a(bArr, point, i, rect);
            if (m.pZK.pZN == 30) {
                this.qet.chk();
            }
        }
    }
}
