package com.ifpdos.autotest;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import com.ifpdos.autotest.api.IWB;

/* JADX INFO: compiled from: FloatView.java */
/* JADX INFO: loaded from: classes.dex */
public class h0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static String f1972a = "FloatView";

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static final h0 f1973b = new h0();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private WindowManager f1974c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private WindowManager.LayoutParams f1975d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private WindowManager.LayoutParams f1976e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private View f1977f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private View f1978g;
    private View h;
    private String i;
    private ImageView j;
    private View k;
    private Handler l = new Handler(Looper.getMainLooper());
    private Runnable m = new a();
    private BroadcastReceiver n = new b();

    /* JADX INFO: compiled from: FloatView.java */
    class a implements Runnable {
        a() {
        }

        @Override // java.lang.Runnable
        public void run() {
            h0.this.i();
        }
    }

    /* JADX INFO: compiled from: FloatView.java */
    class b extends BroadcastReceiver {
        b() {
        }

        @Override // android.content.BroadcastReceiver
        public void onReceive(Context context, Intent intent) {
            if ("com.cvte.seewo.KEY_HOME".equals(intent.getAction())) {
                h0.this.o();
                h0.this.m();
                h0.this.n();
                h0.this.C("ng");
                ((IWB) com.ifpdos.autotest.lancontrol.module.other.a.b().a(IWB.class)).quit();
            }
        }
    }

    /* JADX INFO: compiled from: FloatView.java */
    class c implements View.OnKeyListener {

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        final /* synthetic */ Context f1981c;

        c(Context context) {
            this.f1981c = context;
        }

        @Override // android.view.View.OnKeyListener
        public boolean onKey(View view, int i, KeyEvent keyEvent) {
            h0.this.B(i, this.f1981c);
            return false;
        }
    }

    /* JADX INFO: compiled from: FloatView.java */
    class d implements Runnable {

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        final /* synthetic */ int f1983c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        final /* synthetic */ int f1984d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        final /* synthetic */ int f1985e;

        d(int i, int i2, int i3) {
            this.f1983c = i;
            this.f1984d = i2;
            this.f1985e = i3;
        }

        @Override // java.lang.Runnable
        public void run() {
            h0.this.n();
            Log.d(h0.f1972a, "showColor, isAttachedToWindow " + h0.q(h0.this.f1978g));
            if (!h0.q(h0.this.f1978g)) {
                h0.this.f1974c.addView(h0.this.f1978g, h0.this.f1976e);
            }
            h0.this.f1978g.setBackgroundColor(Color.rgb(this.f1983c, this.f1984d, this.f1985e));
        }
    }

    /* JADX INFO: compiled from: FloatView.java */
    class e implements Runnable {
        e() {
        }

        @Override // java.lang.Runnable
        public void run() {
            Log.d(h0.f1972a, "hideColor, isAttachedToWindow " + h0.q(h0.this.f1978g));
            if (h0.q(h0.this.f1978g)) {
                h0.this.f1974c.removeView(h0.this.f1978g);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void B(int i, Context context) {
        Log.d(f1972a, "onKey " + i);
        if (i == 4 || i == 3106) {
            o();
            n();
            m();
            C("ng");
            ((IWB) com.ifpdos.autotest.lancontrol.module.other.a.b().a(IWB.class)).quit();
            if (b.c.e.e.e.b()) {
                com.ifpdos.autotest.k0.g.b.f2053a.g(context);
            }
            b.c.c.h hVar = b.c.c.h.f1453a;
            hVar.a(hVar.f());
        }
    }

    private void h(final int i, final int i2, final int i3, final int i4, final int i5) {
        this.l.post(new Runnable() { // from class: com.ifpdos.autotest.x
            @Override // java.lang.Runnable
            public final void run() {
                this.f2357c.s(i, i2, i3, i4, i5);
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void i() {
        if (q(this.h) && !this.h.isFocused()) {
            Log.d(f1972a, "requestFocus " + this.h.findFocus());
            this.h.setFocusable(true);
            this.h.requestFocus();
        }
        this.l.postDelayed(this.m, 1000L);
    }

    private WindowManager.LayoutParams j() {
        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
        layoutParams.type = 2008;
        layoutParams.format = 1;
        layoutParams.gravity = 51;
        layoutParams.flags = 268436736;
        layoutParams.x = 0;
        layoutParams.y = 0;
        layoutParams.width = -1;
        layoutParams.height = -1;
        layoutParams.systemUiVisibility = 4102;
        return layoutParams;
    }

    public static h0 l() {
        return f1973b;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static boolean q(View view) {
        return (view == null || view.getParent() == null) ? false : true;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX INFO: renamed from: r, reason: merged with bridge method [inline-methods] */
    public /* synthetic */ void s(int i, int i2, int i3, int i4, int i5) {
        m();
        Log.d(f1972a, "addPatternView, isAttachedToWindow " + q(this.k));
        if (!q(this.k)) {
            this.f1974c.addView(this.k, this.f1976e);
        }
        this.k.setFocusable(true);
        this.k.setFocusableInTouchMode(true);
        this.k.requestFocus();
        if (i != 0) {
            this.j.setBackgroundResource(i);
        } else {
            this.j.setBackgroundColor(Color.argb(i2, i3, i4, i5));
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX INFO: renamed from: t, reason: merged with bridge method [inline-methods] */
    public /* synthetic */ void u() {
        if (q(this.k)) {
            this.f1974c.removeView(this.k);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX INFO: renamed from: v, reason: merged with bridge method [inline-methods] */
    public /* synthetic */ void w() {
        Log.d(f1972a, "hideTarget, isAttachedToWindow " + q(this.f1977f));
        if (q(this.f1977f)) {
            this.f1974c.removeView(this.f1977f);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX INFO: renamed from: x, reason: merged with bridge method [inline-methods] */
    public /* synthetic */ boolean y(Context context, View view, int i, KeyEvent keyEvent) {
        B(i, context);
        return false;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX INFO: renamed from: z, reason: merged with bridge method [inline-methods] */
    public /* synthetic */ void A() throws Exception {
        Log.d(f1972a, "showTarget, isAttachedToWindow " + q(this.f1977f));
        if (q(this.f1977f)) {
            return;
        }
        try {
            this.f1974c.addView(this.f1977f, this.f1975d);
        } catch (Exception e2) {
            if (!(e2 instanceof IllegalStateException) || !q(this.f1977f)) {
                throw e2;
            }
            Log.d(f1972a, "showTarget quickly, fix IllegalStateException");
        }
    }

    public void C(String str) {
        this.i = str;
    }

    public void D(int i, int i2, int i3) {
        n();
        this.l.post(new d(i, i2, i3));
    }

    public void E(int i, int i2, int i3) {
        h(0, 255, i, i2, i3);
    }

    public void F(int i) {
        h(i, 0, 0, 0, 0);
    }

    public void G() {
        if ("pass".equalsIgnoreCase(this.i)) {
            F(R.drawable.nine_pic);
            ((IWB) com.ifpdos.autotest.lancontrol.module.other.a.b().a(IWB.class)).closeNoSignalSleepTime();
        }
    }

    public void H() {
        ((IWB) com.ifpdos.autotest.lancontrol.module.other.a.b().a(IWB.class)).closeNoSignalSleepTime();
        n();
        this.l.post(new Runnable() { // from class: com.ifpdos.autotest.y
            @Override // java.lang.Runnable
            public final void run() throws Exception {
                this.f2362c.A();
            }
        });
    }

    public void I() {
        if ("ng".equalsIgnoreCase(this.i)) {
            H();
        } else {
            ((IWB) com.ifpdos.autotest.lancontrol.module.other.a.b().a(IWB.class)).closeNoSignalSleepTime();
        }
    }

    public void k(Context context) {
        B(4, context);
    }

    public void m() {
        this.l.post(new e());
    }

    public void n() {
        this.l.post(new Runnable() { // from class: com.ifpdos.autotest.b0
            @Override // java.lang.Runnable
            public final void run() {
                this.f1959c.u();
            }
        });
    }

    public void o() {
        this.l.post(new Runnable() { // from class: com.ifpdos.autotest.a0
            @Override // java.lang.Runnable
            public final void run() {
                this.f1957c.w();
            }
        });
    }

    public void p(final Context context) {
        this.f1974c = (WindowManager) context.getSystemService("window");
        this.f1976e = j();
        this.f1978g = LayoutInflater.from(context).inflate(R.layout.view_color, (ViewGroup) null);
        this.f1975d = j();
        this.f1977f = LayoutInflater.from(context).inflate(R.layout.view_target, (ViewGroup) null);
        this.k = LayoutInflater.from(context).inflate(R.layout.view_picture, (ViewGroup) null);
        this.h = this.f1977f.findViewById(R.id.v_focus);
        this.j = (ImageView) this.k.findViewById(R.id.imageView);
        this.k.setOnKeyListener(new View.OnKeyListener() { // from class: com.ifpdos.autotest.z
            @Override // android.view.View.OnKeyListener
            public final boolean onKey(View view, int i, KeyEvent keyEvent) {
                return this.f2363c.y(context, view, i, keyEvent);
            }
        });
        this.h.setOnKeyListener(new c(context));
        context.registerReceiver(this.n, new IntentFilter("com.cvte.seewo.KEY_HOME"));
        i();
    }
}
