package com.seewo.ota.m.t;

import android.R;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.SpannableString;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.TypefaceSpan;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import com.seewo.ota.m.p;
import com.seewo.ota.m.t.f;
import com.seewo.ota.v.u.r;
import com.seewo.ota.v.u.s;
import com.seewo.ota.view.CircleProgressBar;
import f.b0.n;
import f.z.d.k;
import f.z.d.x;
import java.util.Arrays;
import java.util.Locale;

/* JADX INFO: compiled from: ABUpgradeExtendDialog.kt */
/* JADX INFO: loaded from: classes.dex */
public final class f extends Dialog {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private TextView f2202b;

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private TextView f2204g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private final Handler f2205h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private final a f2206i;

    /* JADX INFO: compiled from: ABUpgradeExtendDialog.kt */
    public static final class a implements s {
        a() {
        }

        /* JADX INFO: Access modifiers changed from: private */
        public static final void g(f fVar, int i2) {
            k.e(fVar, "this$0");
            fVar.f(i2);
        }

        /* JADX INFO: Access modifiers changed from: private */
        public static final void h(f fVar) {
            k.e(fVar, "this$0");
            fVar.f(100);
        }

        /* JADX INFO: Access modifiers changed from: private */
        public static final void i(f fVar) {
            k.e(fVar, "this$0");
            fVar.dismiss();
        }

        @Override // com.seewo.ota.v.u.s
        public void a(int i2) {
        }

        @Override // com.seewo.ota.v.u.s
        public void b() {
        }

        @Override // com.seewo.ota.v.u.s
        public void c(int i2, Object obj) {
            if (i2 == 5) {
                Handler handler = f.this.f2205h;
                final f fVar = f.this;
                handler.post(new Runnable() { // from class: com.seewo.ota.m.t.b
                    @Override // java.lang.Runnable
                    public final void run() {
                        f.a.h(fVar);
                    }
                });
            } else if (i2 != 6) {
                Handler handler2 = f.this.f2205h;
                final f fVar2 = f.this;
                handler2.postDelayed(new Runnable() { // from class: com.seewo.ota.m.t.a
                    @Override // java.lang.Runnable
                    public final void run() {
                        f.a.i(fVar2);
                    }
                }, p.u.a());
            }
        }

        @Override // com.seewo.ota.v.u.s, android.os.RecoverySystem.ProgressListener
        public void onProgress(final int i2) {
            Handler handler = f.this.f2205h;
            final f fVar = f.this;
            handler.post(new Runnable() { // from class: com.seewo.ota.m.t.c
                @Override // java.lang.Runnable
                public final void run() {
                    f.a.g(fVar, i2);
                }
            });
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public f(Context context) {
        super(context);
        k.e(context, "context");
        this.f2205h = new Handler(Looper.getMainLooper());
        this.f2206i = new a();
    }

    @SuppressLint({"WrongConstant"})
    private final void c() {
        Window window = getWindow();
        window.setLayout(-1, -1);
        window.setBackgroundDrawableResource(R.color.transparent);
        window.setType(2018);
        window.setFormat(1);
        window.setFlags(131840, 131840);
        window.setGravity(17);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final boolean e(DialogInterface dialogInterface, int i2, KeyEvent keyEvent) {
        return i2 == 4;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void f(int i2) {
        Log.d("ABUpgradeExtendDialog", "updateProgress. " + i2);
        int iC = n.c(n.a(i2, 0), 100);
        x xVar = x.a;
        String str = String.format(Locale.getDefault(), "%d%%", Arrays.copyOf(new Object[]{Integer.valueOf(iC)}, 1));
        k.d(str, "format(locale, format, *args)");
        SpannableString spannableString = new SpannableString(str);
        spannableString.setSpan(new AbsoluteSizeSpan(17, true), spannableString.length() - 1, spannableString.length(), 17);
        spannableString.setSpan(new TypefaceSpan("sans-serif"), spannableString.length() - 1, spannableString.length(), 17);
        TextView textView = this.f2202b;
        if (textView == null) {
            k.p("mProgressText");
            throw null;
        }
        textView.setText(spannableString);
        CircleProgressBar circleProgressBar = this.f2203f;
        if (circleProgressBar != null) {
            circleProgressBar.setProgress(iC);
        } else {
            k.p("mProgressbar");
            throw null;
        }
    }

    @Override // android.app.Dialog, android.view.Window.Callback
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        r.d().l("ABUpgradeExtendDialog", this.f2206i);
    }

    @Override // android.app.Dialog
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        Log.d("ABUpgradeExtendDialog", "onCreate: ");
        requestWindowFeature(1);
        setContentView(com.seewo.ota.R.layout.sys_ab_upgrade_dialog);
        c();
        View viewFindViewById = findViewById(com.seewo.ota.R.id.progress_text);
        k.d(viewFindViewById, "findViewById(R.id.progress_text)");
        this.f2202b = (TextView) viewFindViewById;
        View viewFindViewById2 = findViewById(com.seewo.ota.R.id.progressbar);
        k.d(viewFindViewById2, "findViewById(R.id.progressbar)");
        this.f2203f = (CircleProgressBar) viewFindViewById2;
        View viewFindViewById3 = findViewById(com.seewo.ota.R.id.upgrade_system_point);
        k.d(viewFindViewById3, "findViewById(R.id.upgrade_system_point)");
        this.f2204g = (TextView) viewFindViewById3;
        if (getContext().getResources().getBoolean(com.seewo.ota.R.bool.support_ota_update_time_tip)) {
            TextView textView = this.f2204g;
            if (textView == null) {
                k.p("mUpgradeSystemPoint");
                throw null;
            }
            textView.setText(getContext().getString(com.seewo.ota.R.string.auto_upgrade_system_point) + '\n' + getContext().getString(com.seewo.ota.R.string.auto_upgrade_system_time_point));
        }
        f(0);
        setCancelable(false);
        setOnKeyListener(new DialogInterface.OnKeyListener() { // from class: com.seewo.ota.m.t.d
            @Override // android.content.DialogInterface.OnKeyListener
            public final boolean onKey(DialogInterface dialogInterface, int i2, KeyEvent keyEvent) {
                return f.e(dialogInterface, i2, keyEvent);
            }
        });
    }

    @Override // android.app.Dialog, android.view.Window.Callback
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        r.d().m("ABUpgradeExtendDialog");
    }
}
