package com.ifpdos.factorytest;

import android.app.Activity;
import android.content.Intent;
import android.icu.text.DecimalFormat;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.core.internal.view.SupportMenu;
import com.ifpdos.factorytest.util.StringUtil;
import com.seewo.sdk.OpenSDK;
import com.seewo.sdk.SDKConfigureHelper;
import java.math.RoundingMode;

/* JADX INFO: loaded from: classes.dex */
public class TxbOqcTestActivity extends Activity {
    private static final int REQUEST_CODE_B1 = 1;
    private static final int REQUEST_CODE_B2 = 2;
    private static final int REQUEST_CODE_B3 = 3;
    private static final String TAG = "TxbOqcTestActivity";
    private static final Handler mHandler = new Handler(Looper.getMainLooper());
    Button add;
    TextView b1Text;
    TextView b2Text;
    TextView b3Text;
    Button fail;
    Button pass;
    TextView snText;
    Button sub;
    TextView testTimesText;
    Button txbB1Begin;
    Button txbB1Clear;
    Button txbB2Begin;
    Button txbB2Clear;
    Button txbB3Begin;
    Button txbB3Clear;
    private int default_test_times = 1;
    private final float TXB_PASS_RATE = 0.99f;

    @Override // android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_txb_oqc_test);
        initUi();
        showSn();
    }

    @Override // android.app.Activity
    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        Log.d(TAG, "onActivityResult requestCode = " + i);
        int i3 = intent.getExtras().getInt("totalTestCount", -1);
        int i4 = intent.getExtras().getInt("successTestCount", -1);
        float f = (i4 * 1.0f) / i3;
        DecimalFormat decimalFormat = new DecimalFormat("#.##");
        decimalFormat.setRoundingMode(RoundingMode.DOWN.ordinal());
        String str = decimalFormat.format(f);
        if (i == 1) {
            this.b1Text.setText(i4 + "/" + i3 + "[" + str + "]");
            if (f >= 0.99f) {
                this.b1Text.setTextColor(-16711936);
                return;
            } else {
                this.b1Text.setTextColor(SupportMenu.CATEGORY_MASK);
                return;
            }
        }
        if (i == 2) {
            this.b2Text.setText(i4 + "/" + i3 + "[" + str + "]");
            if (f >= 0.99f) {
                this.b2Text.setTextColor(-16711936);
                return;
            } else {
                this.b2Text.setTextColor(SupportMenu.CATEGORY_MASK);
                return;
            }
        }
        if (i != 3) {
            return;
        }
        this.b3Text.setText(i4 + "/" + i3 + "[" + str + "]");
        if (f >= 0.99f) {
            this.b3Text.setTextColor(-16711936);
        } else {
            this.b3Text.setTextColor(SupportMenu.CATEGORY_MASK);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void showSn() {
        if (OpenSDK.getInstance().isConnected()) {
            String machineSN = getMachineSN();
            if (machineSN.isEmpty()) {
                this.snText.setText(getString(R.string.str_sn_empty));
                this.snText.setTextColor(SupportMenu.CATEGORY_MASK);
            } else {
                this.snText.setText(machineSN);
                this.snText.setTextColor(-16711936);
            }
            Log.d(TAG, "sn = " + machineSN);
            return;
        }
        mHandler.postDelayed(new Runnable() { // from class: com.ifpdos.factorytest.TxbOqcTestActivity$$ExternalSyntheticLambda1
            @Override // java.lang.Runnable
            public final void run() {
                this.f$0.showSn();
            }
        }, 1000L);
    }

    private String getMachineSN() {
        return SDKConfigureHelper.I.getMachineSN();
    }

    private void initUi() {
        this.txbB1Begin = (Button) findViewById(R.id.txb_b1_begin);
        this.txbB2Begin = (Button) findViewById(R.id.txb_b2_begin);
        this.txbB3Begin = (Button) findViewById(R.id.txb_b3_begin);
        this.txbB1Clear = (Button) findViewById(R.id.txb_b1_clear);
        this.txbB2Clear = (Button) findViewById(R.id.txb_b2_clear);
        this.txbB3Clear = (Button) findViewById(R.id.txb_b3_clear);
        this.snText = (TextView) findViewById(R.id.tv_txb_sn_text);
        this.b1Text = (TextView) findViewById(R.id.tv_txb_b1_text);
        this.b2Text = (TextView) findViewById(R.id.tv_txb_b2_text);
        this.b3Text = (TextView) findViewById(R.id.tv_txb_b3_text);
        this.testTimesText = (TextView) findViewById(R.id.tv_txb_test_tmies_text);
        this.pass = (Button) findViewById(R.id.txb_pass);
        this.fail = (Button) findViewById(R.id.txb_fail);
        this.add = (Button) findViewById(R.id.txb_add_test);
        this.sub = (Button) findViewById(R.id.txb_sub_test);
        View.OnClickListener onClickListener = new View.OnClickListener() { // from class: com.ifpdos.factorytest.TxbOqcTestActivity$$ExternalSyntheticLambda0
            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                this.f$0.lambda$initUi$0(view);
            }
        };
        this.txbB1Begin.setOnClickListener(onClickListener);
        this.txbB2Begin.setOnClickListener(onClickListener);
        this.txbB3Begin.setOnClickListener(onClickListener);
        this.txbB1Clear.setOnClickListener(onClickListener);
        this.txbB2Clear.setOnClickListener(onClickListener);
        this.txbB3Clear.setOnClickListener(onClickListener);
        this.pass.setOnClickListener(onClickListener);
        this.fail.setOnClickListener(onClickListener);
        this.add.setOnClickListener(onClickListener);
        this.sub.setOnClickListener(onClickListener);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ void lambda$initUi$0(View view) {
        Intent intent = new Intent(this, (Class<?>) TxbOqcBxTestActivity.class);
        int id = view.getId();
        int i = 1;
        if (id == R.id.txb_b1_begin) {
            intent.putExtra(StringUtil.TEST_ITEM_INTENT, StringUtil.TXB_B1_TEST_INTENT);
        } else if (id == R.id.txb_b2_begin) {
            intent.putExtra(StringUtil.TEST_ITEM_INTENT, StringUtil.TXB_B2_TEST_INTENT);
            i = 2;
        } else if (id == R.id.txb_b3_begin) {
            intent.putExtra(StringUtil.TEST_ITEM_INTENT, StringUtil.TXB_B3_TEST_INTENT);
            i = 3;
        } else {
            if (id == R.id.txb_b1_clear) {
                this.b1Text.setText("0/0");
                this.b1Text.setTextColor(-1);
            } else if (id == R.id.txb_b2_clear) {
                this.b2Text.setText("0/0");
                this.b2Text.setTextColor(-1);
            } else if (id == R.id.txb_b3_clear) {
                this.b3Text.setText("0/0");
                this.b3Text.setTextColor(-1);
            } else if (id == R.id.txb_pass) {
                setResult(1);
                finish();
            } else if (id == R.id.txb_fail) {
                setResult(2);
                finish();
            } else if (id == R.id.txb_add_test) {
                int i2 = this.default_test_times + 1;
                this.default_test_times = i2;
                this.testTimesText.setText(String.valueOf(i2));
                Log.d(TAG, "default_test_times = " + this.default_test_times);
            } else if (id == R.id.txb_sub_test) {
                int i3 = this.default_test_times;
                if (i3 > 1) {
                    int i4 = i3 - 1;
                    this.default_test_times = i4;
                    this.testTimesText.setText(String.valueOf(i4));
                }
                Log.d(TAG, "default_test_times = " + this.default_test_times);
            }
            i = 0;
        }
        if (i != 0) {
            intent.putExtra(StringUtil.TXB_TEST_TIMES, this.default_test_times);
            startActivityForResult(intent, i);
        }
    }
}
