package com.ifpdos.debugmenu.activity.agingtest;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.TextView;
import c.f.c.a;
import com.ifpdos.debugmenu.R;
import com.ifpdos.debugmenu.activity.agingtest.VideoPlayActivity;
import com.seewo.sdk.SDKSystemInfoHelper;
import com.seewo.sdk.SDKTouchHelper;
import com.seewo.vcommons.data.UserContentResolver;
import d.f.a.r2.u2;
import d.i.a.a.d;
import java.util.Objects;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/* JADX INFO: loaded from: classes.dex */
public class VideoPlayActivity extends Activity implements SurfaceHolder.Callback, MediaPlayer.OnCompletionListener, MediaPlayer.OnPreparedListener, MediaPlayer.OnVideoSizeChangedListener, MediaPlayer.OnErrorListener {

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public SurfaceHolder f1998e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public MediaPlayer f1999f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public int f2000g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public int f2001h;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public int f2004k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public int f2005l;
    public int m;
    public Timer n;
    public c o;
    public boolean q;
    public TextView r;
    public Runnable s;
    public Runnable t;
    public d.f.a.q1.n.b v;
    public ProgressDialog x;
    public long z;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public boolean f2002i = false;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public boolean f2003j = false;
    public TimerTask p = new a();
    public Handler u = new Handler();
    public int w = 120;

    @SuppressLint({"HandlerLeak"})
    public Handler y = new b();

    public class a extends TimerTask {
        public a() {
        }

        @Override // java.util.TimerTask, java.lang.Runnable
        public void run() {
            VideoPlayActivity.this.y.sendEmptyMessage(0);
        }
    }

    public class b extends Handler {
        public b() {
        }

        @Override // android.os.Handler
        public void handleMessage(Message message) {
            VideoPlayActivity videoPlayActivity = VideoPlayActivity.this;
            int i2 = videoPlayActivity.m + 1;
            videoPlayActivity.m = i2;
            if (i2 >= 60) {
                videoPlayActivity.m = 0;
                int i3 = videoPlayActivity.f2005l + 1;
                videoPlayActivity.f2005l = i3;
                if (i3 >= 60) {
                    videoPlayActivity.f2005l = 0;
                    videoPlayActivity.f2004k++;
                }
                Context applicationContext = videoPlayActivity.getApplicationContext();
                String strB = videoPlayActivity.b();
                UserContentResolver userContentResolver = d.i.f.c.b.a;
                d.i.f.c.b.h(applicationContext.getContentResolver(), "aging_video_play_time", strB);
            }
            VideoPlayActivity videoPlayActivity2 = VideoPlayActivity.this;
            videoPlayActivity2.f1997b.setText(videoPlayActivity2.b());
        }
    }

    public static class c {
        public static final int a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public ExecutorService f2007b = Executors.newFixedThreadPool(a);

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public volatile boolean f2008c;

        static {
            a = d.i.f.a.a.a >= 4 ? 2 : 1;
        }

        public c(a aVar) {
        }
    }

    public final String a(int i2) {
        return String.format("%02d", Integer.valueOf(i2));
    }

    public final String b() {
        return a(this.f2004k) + ":" + a(this.f2005l) + ":" + a(this.m);
    }

    public final void c() {
        if (7 != d.i.f.a.a.a) {
            try {
                MediaPlayer mediaPlayer = new MediaPlayer();
                this.f1999f = mediaPlayer;
                mediaPlayer.setDataSource(u2.j());
                this.f1999f.setDisplay(this.f1998e);
                this.f1999f.setLooping(true);
                this.f1999f.prepareAsync();
                this.f1999f.setAudioStreamType(3);
                this.f1999f.setOnCompletionListener(this);
                this.f1999f.setOnPreparedListener(this);
                this.f1999f.setOnErrorListener(this);
                this.f1999f.setOnVideoSizeChangedListener(this);
                return;
            } catch (Exception e2) {
                d.b("VideoPlayActivity", e2);
                finish();
                return;
            }
        }
        MediaPlayer mediaPlayer2 = this.f1999f;
        if (mediaPlayer2 != null) {
            mediaPlayer2.release();
            this.f1999f = null;
        }
        try {
            this.f2003j = false;
            this.f2002i = false;
            MediaPlayer mediaPlayer3 = new MediaPlayer();
            this.f1999f = mediaPlayer3;
            mediaPlayer3.setOnCompletionListener(this);
            this.f1999f.setOnPreparedListener(this);
            this.f1999f.setOnErrorListener(this);
            this.f1999f.setOnVideoSizeChangedListener(this);
            this.f1999f.reset();
            this.f1999f.setAudioStreamType(3);
            this.f1999f.setDataSource(u2.j());
            this.f1999f.setDisplay(this.f1998e);
            this.f1999f.prepareAsync();
        } catch (Exception e3) {
            d.b("VideoPlayActivity", e3);
            finish();
        }
    }

    public final void d() {
        ProgressDialog progressDialog = this.x;
        if (progressDialog != null && progressDialog.isShowing()) {
            this.x.dismiss();
        }
        this.f1998e.setFixedSize(this.f2000g, this.f2001h);
        this.f1999f.start();
        if (this.q) {
            return;
        }
        this.q = true;
        this.n.schedule(this.p, 1000L, 1000L);
    }

    @Override // android.media.MediaPlayer.OnCompletionListener
    public void onCompletion(MediaPlayer mediaPlayer) {
        if (7 == d.i.f.a.a.a) {
            ProgressDialog progressDialog = new ProgressDialog(this);
            this.x = progressDialog;
            progressDialog.setProgressStyle(0);
            this.x.setCancelable(true);
            this.x.setCanceledOnTouchOutside(false);
            this.x.setTitle(getString(R.string.str_load_video_tip));
            this.x.setMessage(getString(R.string.str_load_video_tip_content));
            this.x.show();
            c();
        }
    }

    @Override // android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        requestWindowFeature(1);
        setContentView(R.layout.activity_video_play);
        SurfaceView surfaceView = (SurfaceView) findViewById(R.id.video_play_surfaceview);
        this.f1997b = (TextView) findViewById(R.id.time_show_textview);
        this.r = (TextView) findViewById(R.id.temperature_chronometer);
        SurfaceHolder holder = surfaceView.getHolder();
        this.f1998e = holder;
        holder.addCallback(this);
        this.n = new Timer();
        Context applicationContext = getApplicationContext();
        UserContentResolver userContentResolver = d.i.f.c.b.a;
        String strD = d.i.f.c.b.d(applicationContext.getContentResolver(), "aging_video_play_time");
        if (strD == null || strD.isEmpty()) {
            strD = "00:00:00";
        }
        String[] strArrSplit = strD.split(":");
        this.f2004k = Integer.parseInt(strArrSplit[0]);
        this.f2005l = Integer.parseInt(strArrSplit[1]);
        this.m = Integer.parseInt(strArrSplit[2]);
        this.f1997b.setText(a(this.f2004k) + ":" + a(this.f2005l) + ":" + a(this.m));
        sendBroadcast(new Intent("com.seewo.filbrowser.on"));
        this.w = d.i.f.c.c.c("persist.sys.cpu.tempthrehold", 120);
        Runnable runnable = new Runnable() { // from class: d.f.a.q1.m.a
            @Override // java.lang.Runnable
            public final void run() {
                VideoPlayActivity videoPlayActivity = this.f3083b;
                Objects.requireNonNull(videoPlayActivity);
                String cpuTemperature = SDKSystemInfoHelper.I.getCpuTemperature();
                if (!TextUtils.isEmpty(cpuTemperature)) {
                    float f2 = Float.parseFloat(cpuTemperature.trim());
                    String string = f2 > ((float) videoPlayActivity.w) ? videoPlayActivity.getString(R.string.str_temperature_status_fail) : videoPlayActivity.getString(R.string.str_temperature_pass);
                    videoPlayActivity.r.setText(String.format(videoPlayActivity.getString(R.string.str_textview_temperature) + string, Float.valueOf(f2)));
                    if (string.contains(videoPlayActivity.getString(R.string.str_temperature_pass))) {
                        videoPlayActivity.r.setTextColor(Color.parseColor("#00FF00"));
                    } else {
                        TextView textView = videoPlayActivity.r;
                        Object obj = c.f.c.a.a;
                        textView.setTextColor(a.c.a(videoPlayActivity, R.color.red));
                    }
                }
                videoPlayActivity.u.postDelayed(videoPlayActivity.s, 2000L);
            }
        };
        this.s = runnable;
        this.u.postDelayed(runnable, 0L);
        this.v = new d.f.a.q1.n.b(this);
        Runnable runnable2 = new Runnable() { // from class: d.f.a.q1.m.c
            @Override // java.lang.Runnable
            public final void run() {
                VideoPlayActivity videoPlayActivity = this.f3085b;
                videoPlayActivity.v.f3102c.add(new d.f.a.q1.n.a(SDKSystemInfoHelper.I.getCpuTemperature(), videoPlayActivity.b(), videoPlayActivity.w));
                videoPlayActivity.v.a();
                videoPlayActivity.u.postDelayed(videoPlayActivity.t, 60000L);
            }
        };
        this.t = runnable2;
        this.u.postDelayed(runnable2, 0L);
        String strF = d.i.f.c.b.f(this, "KEY_PIR_OFF_SECONDS", 0);
        long j2 = 900;
        if (!TextUtils.isEmpty(strF)) {
            try {
                j2 = Long.parseLong(strF);
            } catch (Exception e2) {
                Log.e("PreferencesUtils", "Exception", e2);
            }
        }
        this.z = j2;
        d.i.f.c.b.i(this, "KEY_PIR_OFF_SECONDS", String.valueOf(Long.MAX_VALUE), 0);
        sendBroadcast(new Intent("com.ifpdos.action.UPDATE_PIR_SENSOR_TIME"));
    }

    @Override // android.app.Activity
    public void onDestroy() {
        super.onDestroy();
        ProgressDialog progressDialog = this.x;
        if (progressDialog != null && progressDialog.isShowing()) {
            this.x.dismiss();
        }
        Context applicationContext = getApplicationContext();
        String strB = b();
        UserContentResolver userContentResolver = d.i.f.c.b.a;
        d.i.f.c.b.h(applicationContext.getContentResolver(), "aging_video_play_time", strB);
        sendBroadcast(new Intent("com.seewo.filbrowser.off"));
        MediaPlayer mediaPlayer = this.f1999f;
        if (mediaPlayer != null) {
            mediaPlayer.release();
            this.f1999f = null;
        }
        Timer timer = this.n;
        if (timer != null) {
            timer.cancel();
            this.n = null;
            this.p = null;
        }
        this.y.removeCallbacksAndMessages(null);
        d.i.f.c.b.i(this, "KEY_PIR_OFF_SECONDS", String.valueOf(this.z), 0);
        sendBroadcast(new Intent("com.ifpdos.action.UPDATE_PIR_SENSOR_TIME"));
        this.u.removeCallbacksAndMessages(null);
    }

    @Override // android.media.MediaPlayer.OnErrorListener
    public boolean onError(MediaPlayer mediaPlayer, int i2, int i3) {
        e.a.a.a.a(this, getResources().getString(R.string.video_play_error), 0).show();
        finish();
        return false;
    }

    @Override // android.app.Activity
    public void onPause() {
        super.onPause();
        SDKTouchHelper.I.setAgingTouchMode(false);
        c cVar = this.o;
        if (cVar != null) {
            cVar.f2008c = false;
            cVar.f2007b.shutdownNow();
            this.o = null;
        }
    }

    @Override // android.media.MediaPlayer.OnPreparedListener
    public void onPrepared(MediaPlayer mediaPlayer) {
        this.f2003j = true;
        if (this.f2002i) {
            d();
        }
    }

    @Override // android.app.Activity
    public void onResume() {
        super.onResume();
        SDKTouchHelper.I.setAgingTouchMode(true);
        final c cVar = new c(null);
        this.o = cVar;
        cVar.f2008c = true;
        for (int i2 = 0; i2 < c.a; i2++) {
            cVar.f2007b.execute(new Runnable() { // from class: d.f.a.q1.m.b
                @Override // java.lang.Runnable
                public final void run() {
                    while (cVar.f2008c) {
                    }
                }
            });
        }
    }

    @Override // android.app.Activity
    public void onStop() {
        super.onStop();
        finish();
    }

    @Override // android.media.MediaPlayer.OnVideoSizeChangedListener
    public void onVideoSizeChanged(MediaPlayer mediaPlayer, int i2, int i3) {
        if (i2 == 0 || i3 == 0) {
            return;
        }
        this.f2000g = i2;
        this.f2001h = i3;
        this.f2002i = true;
        if (this.f2003j) {
            d();
        }
    }

    @Override // android.view.SurfaceHolder.Callback
    public void surfaceChanged(SurfaceHolder surfaceHolder, int i2, int i3, int i4) {
    }

    @Override // android.view.SurfaceHolder.Callback
    public void surfaceCreated(SurfaceHolder surfaceHolder) {
        c();
    }

    @Override // android.view.SurfaceHolder.Callback
    public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
    }
}
