package com.ifpdos.factorytest;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.ifpdos.factorytest.ConfigParser;

/* JADX INFO: loaded from: classes.dex */
public class TestItem extends LinearLayout {
    public static final int ASK_CTP_SWITCH_TOGGLE = 7;
    public static final int ASK_HALL_SWITCH_TOGGLE = 8;
    public static final int ASK_INSERTE_CHARGER = 3;
    public static final int ASK_INSERTE_EAR_PHONE = 1;
    public static final int ASK_INSERTE_EAR_PHONE_WITH_MIC = 9;
    public static final int ASK_IR_SENSOR_TOGGLE = 10;
    public static final int ASK_PLUG_CHARGER = 4;
    public static final int ASK_PLUG_EAR_PHONE = 2;
    public static final int AUTO_CLICK_NO_BUTTON = 5;
    private static final int NOT_TEST_COLOR = -1;
    private static final int SELECT_COLOR = -28877;
    private static final String TAG = "TestItem";
    public static final int TEST_CANCEL = 3;
    public static final int TEST_FAIL = 2;
    private static final int TEST_FAIL_COLOR = -65536;
    public static final int TEST_HOME_KEY = 6;
    public static final int TEST_PASS = 1;
    private static final int TEST_PASS_COLOR = -16711936;
    private static final int TEXT_COLOR = -16777216;
    boolean mAutoTest;
    Context mContext;
    ConfigParser.IDS mId;
    boolean mNeedHide;
    boolean mNeedTest;
    protected OnTestDoneListener mOnTestDoneListener;
    boolean mResult;
    TextView mResultText;
    boolean mStarted;
    int mStatus;
    TextView mStatusText;
    String mTagDone;
    String mTagFail;
    String mTagIsPassed;
    String mTagNo;
    String mTagNoNeedTest;
    String mTagPass;
    String mTagWait;
    String mTagYes;
    boolean mTested;
    TextView mTitleText;

    enum TestStatus {
        PASS,
        WAITING,
        FAIL,
        TESTING
    }

    void onAutoTest() {
    }

    void onDestroy() {
    }

    void onNewIntent(Intent intent) {
    }

    void onPause() {
    }

    void onPreRetest() {
    }

    void onResume() {
    }

    void onStart() {
    }

    void onStop() {
    }

    public TestItem(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.mId = ConfigParser.IDS.NA;
        this.mNeedTest = true;
        this.mNeedHide = false;
        this.mContext = context;
        this.mOnTestDoneListener = null;
        this.mTagPass = context.getResources().getString(R.string.test_pass);
        this.mTagFail = context.getResources().getString(R.string.test_fail);
        this.mTagWait = context.getResources().getString(R.string.wait_for_test);
        this.mTagDone = context.getResources().getString(R.string.test_done);
        this.mTagYes = context.getResources().getString(R.string.yes);
        this.mTagNo = context.getResources().getString(R.string.no);
        this.mTagIsPassed = context.getResources().getString(R.string.test_yes_or_no_pass);
        this.mTagNoNeedTest = context.getResources().getString(R.string.no_need_test);
        this.mTitleText = new TextView(context);
        this.mResultText = new TextView(context);
        this.mStatusText = new TextView(context);
        this.mTitleText.setTextColor(-16777216);
        this.mResultText.setTextColor(-16777216);
        this.mStatusText.setTextColor(-16777216);
        this.mTitleText.setTextSize(ConfigParameter.mTitleTextSize.intValue());
        this.mResultText.setTextSize(ConfigParameter.mResultTextSize.intValue());
        this.mStatusText.setTextSize(ConfigParameter.mStatusTextSize.intValue());
        this.mTitleText.setGravity(17);
        this.mResultText.setGravity(17);
        this.mStatusText.setGravity(17);
        setOrientation(1);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
        int iDip = MainTestActivity.dip(2);
        layoutParams.setMargins(iDip, iDip, iDip, iDip);
        setLayoutParams(layoutParams);
        addView(this.mTitleText);
        addView(this.mResultText);
        addView(this.mStatusText);
        int iDip2 = MainTestActivity.dip(2);
        setPadding(iDip2, iDip2, iDip2, iDip2);
        setGravity(17);
        this.mStatusText.setText(this.mTagWait);
        setTestBackgroundColor(TestStatus.WAITING);
    }

    /* JADX INFO: renamed from: com.ifpdos.factorytest.TestItem$1, reason: invalid class name */
    static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] $SwitchMap$com$ifpdos$factorytest$TestItem$TestStatus;

        static {
            int[] iArr = new int[TestStatus.values().length];
            $SwitchMap$com$ifpdos$factorytest$TestItem$TestStatus = iArr;
            try {
                iArr[TestStatus.FAIL.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$com$ifpdos$factorytest$TestItem$TestStatus[TestStatus.PASS.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                $SwitchMap$com$ifpdos$factorytest$TestItem$TestStatus[TestStatus.WAITING.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                $SwitchMap$com$ifpdos$factorytest$TestItem$TestStatus[TestStatus.TESTING.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
        }
    }

    public void setTestBackgroundColor(TestStatus testStatus) {
        int i = AnonymousClass1.$SwitchMap$com$ifpdos$factorytest$TestItem$TestStatus[testStatus.ordinal()];
        if (i == 1) {
            setBackgroundResource(R.drawable.test_fail_background);
            return;
        }
        if (i == 2) {
            setBackgroundResource(R.drawable.test_pass_background);
        } else if (i == 3) {
            setBackgroundResource(R.drawable.test_init_background);
        } else {
            if (i != 4) {
                return;
            }
            setBackgroundResource(R.drawable.test_testing_background);
        }
    }

    @Override // android.view.View
    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (!this.mNeedTest) {
            return true;
        }
        getWidth();
        getHeight();
        motionEvent.getX();
        motionEvent.getY();
        if (motionEvent.getAction() == 1) {
            setTestBackgroundColor(TestStatus.WAITING);
            setFocusableInTouchMode(true);
            requestFocus();
        }
        return super.onTouchEvent(motionEvent);
    }

    void setTitle(String str) {
        this.mTitleText.setText(str);
    }

    String getTitle() {
        return this.mTitleText.getText().toString();
    }

    void setStatus(String str) {
        this.mStatusText.setText(str);
    }

    void setStatus(String str, int i) {
        this.mStatusText.setText(str);
        this.mStatusText.setTextColor(i);
    }

    boolean retest() {
        if (!this.mNeedTest) {
            return false;
        }
        Log.d("TestItem", "retest");
        onPreRetest();
        this.mAutoTest = false;
        this.mStatusText.setText(this.mTagWait);
        this.mResultText.setText("");
        setTestBackgroundColor(TestStatus.WAITING);
        this.mStatus = 0;
        this.mTested = false;
        return doTest();
    }

    void setResult(boolean z) {
        if (z) {
            this.mResultText.setText(this.mTagPass);
            setTestBackgroundColor(TestStatus.PASS);
        } else {
            this.mResultText.setText(this.mTagFail);
            setTestBackgroundColor(TestStatus.FAIL);
        }
        this.mResult = z;
    }

    void setOnTestDoneListener(OnTestDoneListener onTestDoneListener) {
        this.mOnTestDoneListener = onTestDoneListener;
    }

    void testDone(boolean z, String str) {
        this.mTested = true;
        this.mStarted = false;
        setResult(z);
        setStatus(str, -16777216);
        OnTestDoneListener onTestDoneListener = this.mOnTestDoneListener;
        if (onTestDoneListener != null) {
            onTestDoneListener.onTestDone(this, this.mId, z, this.mTagDone);
        }
    }

    boolean doTest() {
        if (!this.mNeedTest) {
            return false;
        }
        this.mTested = true;
        this.mStarted = true;
        this.mAutoTest = false;
        testDone(true, this.mTagDone);
        return false;
    }

    void startTestingUi() {
        setStatus(this.mContext.getString(R.string.testing), -16777216);
        this.mResultText.setText("");
        setTestBackgroundColor(TestStatus.TESTING);
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        if (this.mNeedTest) {
            if (i != this.mId.ordinal()) {
                testDone(false, this.mTagDone);
            } else if (i2 == 1) {
                testDone(true, this.mTagDone);
            } else {
                testDone(false, this.mTagDone);
            }
        }
    }

    void doAutoTest() {
        if (this.mNeedTest) {
            onAutoTest();
        }
    }

    void setNoTest() {
        this.mNeedTest = false;
        setBackgroundColor(-7829368);
        this.mResultText.setText(this.mTagNoNeedTest);
        setShowResultOnly();
    }

    void setShowResultOnly() {
        setStatus("");
        setTitle("");
        if (ConfigParameter.mTitleTextSize.intValue() > ConfigParameter.mResultTextSize.intValue()) {
            this.mTitleText.setTextSize(ConfigParameter.mResultTextSize.intValue());
            this.mResultText.setTextSize(ConfigParameter.mTitleTextSize.intValue());
        }
    }
}
