京东到家.apk(点击下载) / IdentityPrivacyAgrDialogActivity.java


package com.jdjr.risk.identity.verify.activity;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.FragmentActivity;
import com.jd.sentry.performance.network.instrumentation.webview.ShooterWebViewClient;
import com.jd.sentry.performance.network.instrumentation.webview.ShooterWebviewInstrumentation;
import com.jdjr.risk.identity.face.constants.VerifyFaceContants;
import com.jdjr.risk.identity.face.view.JdcnToast;
import com.jdjr.risk.identity.face.view.MiscUtil;
import com.jdjr.risk.identity.verify.IdentityVerityEngine;
import com.jdjr.risk.identity.verify.R;
import com.jdjr.risk.identity.verify.bean.PolicyConfigForServer;
import com.jdjr.risk.identity.verify.tracker.IdentityTracker;
import com.jdjr.risk.identity.verify.tracker.TrackerConstantsImpl;
import com.jdjr.risk.jdcn.common.permisson.FsCameraPermissonCheck;
import com.jdjr.risk.jdcn.common.permisson.FsRequestCameraPermissionUtils;
import com.jdjr.risk.jdcn.common.utils.JDCNLogUtils;
import com.vivo.push.PushClientConstants;
import com.wangyin.maframe.bury.BuryUtils;
import org.eclipse.paho.client.mqttv3.MqttTopic;
import org.json.JSONObject;

public class IdentityPrivacyAgrDialogActivity extends FragmentActivity implements View.OnClickListener {
    public static final int TAKE_PHOTO_REQUEST_CODE = 34;
    private static final int TYPE_PRI_AGR = 0;
    private static final int TYPE_WEB = 1;
    private ConstraintLayout dialog_prv_web_container;
    private boolean isShowPriAgr = false;
    private boolean isUserAgree = false;
    private String mAgree = "我已阅读并同意《人脸识别服务协议》,开启后可以去「我的」页面,打开「设置」进行查看和操作。";
    private RelativeLayout mAgreeContainer;
    private ImageView mAgreeIcon;
    private String mAgreeWord = "《人脸识别服务协议》";
    private TextView mAgreementContent;
    private ImageView mCloseBtn;
    private Context mContext;
    private String mDesc = "";
    private TextView mIdentityBtn;
    private TextView mIdentityDesc;
    private TextView mIdentityTitle;
    private String mJumpUrl = "https://qiye.jd.com/contractCenter2_noHead.html?#/template-preview?cid=00006&sid=AIZT&tid=7283128";
    private String mPriAgrBgColor = "#FFFFFF";
    private ConstraintLayout mPriAgrContainer;
    private int mShowType = 0;
    private String mTitle = "开启人脸认证";
    private WebView mWebView;
    private ConstraintLayout mWebViewContainer;
    private PolicyConfigForServer policyConfigForServer;
    private String themeColor = "#EF4034";
    private String translateColor = "#00000000";

    /* access modifiers changed from: protected */
    @Override // androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, androidx.fragment.app.FragmentActivity
    public void onCreate(Bundle bundle) {
        requestWindowFeature(1);
        super.onCreate(bundle);
        this.mContext = this;
        setContentView(R.layout.vf_dialog_privacy_agreement);
        initData();
        initViews();
    }

    private void initData() {
        this.policyConfigForServer = (PolicyConfigForServer) getIntent().getSerializableExtra("policyConfigForServer");
        PolicyConfigForServer policyConfigForServer2 = this.policyConfigForServer;
        if (policyConfigForServer2 != null && policyConfigForServer2.verificationSdk != null && this.policyConfigForServer.verificationSdk.config != null) {
            if (!TextUtils.isEmpty(this.policyConfigForServer.verificationSdk.config.privacy_agreemen_name)) {
                this.mAgreeWord = this.policyConfigForServer.verificationSdk.config.privacy_agreemen_name;
            }
            if (!TextUtils.isEmpty(this.policyConfigForServer.verificationSdk.config.privacy_agreemen_text)) {
                this.mAgree = this.policyConfigForServer.verificationSdk.config.privacy_agreemen_text;
            }
            if (!TextUtils.isEmpty(this.policyConfigForServer.verificationSdk.config.privacy_agreemen_url)) {
                this.mJumpUrl = this.policyConfigForServer.verificationSdk.config.privacy_agreemen_url;
            }
            this.isShowPriAgr = "true".equals(this.policyConfigForServer.verificationSdk.config.privacy_agreemen_show_flag);
            if (!this.isShowPriAgr) {
                this.isUserAgree = true;
            }
            if (!TextUtils.isEmpty(this.policyConfigForServer.verificationSdk.config.privacy_agreemen_statement)) {
                this.mDesc = this.policyConfigForServer.verificationSdk.config.privacy_agreemen_statement;
            }
            if (!TextUtils.isEmpty(this.policyConfigForServer.verificationSdk.config.privacy_agreemen_background_colour)) {
                this.mPriAgrBgColor = this.policyConfigForServer.verificationSdk.config.privacy_agreemen_background_colour;
            }
        }
    }

    private void initViews() {
        this.mIdentityTitle = (TextView) findViewById(R.id.identity_privacy_title);
        this.mIdentityDesc = (TextView) findViewById(R.id.identity_privacy_desc);
        this.mAgreementContent = (TextView) findViewById(R.id.identity_privacy_agreement);
        this.mIdentityBtn = (TextView) findViewById(R.id.identity_privacy_identity);
        this.mIdentityBtn.setOnClickListener(this);
        this.mAgreeIcon = (ImageView) findViewById(R.id.identity_privacy_agr_icon);
        this.mAgreeContainer = (RelativeLayout) findViewById(R.id.identity_privacy_agr_container);
        this.mAgreeContainer.setOnClickListener(this);
        this.mCloseBtn = (ImageView) findViewById(R.id.img_btn_close);
        this.mCloseBtn.setOnClickListener(new View.OnClickListener() {
            /* class com.jdjr.risk.identity.verify.activity.IdentityPrivacyAgrDialogActivity.AnonymousClass1 */

            public void onClick(View view) {
                IdentityPrivacyAgrDialogActivity.this.onBackPressed();
            }
        });
        this.mPriAgrContainer = (ConstraintLayout) findViewById(R.id.dialog_prv_agr_container);
        this.mWebViewContainer = (ConstraintLayout) findViewById(R.id.dialog_prv_web_container);
        this.mWebView = (WebView) findViewById(R.id.vf_faq_webview);
        ShooterWebviewInstrumentation.setWebViewClient(this.mWebView, new ShooterWebViewClient() {
            /* class com.jdjr.risk.identity.verify.activity.IdentityPrivacyAgrDialogActivity.AnonymousClass2 */

            @Override // android.webkit.WebViewClient
            public boolean shouldOverrideUrlLoading(WebView webView, String str) {
                webView.loadUrl(str);
                return super.shouldOverrideUrlLoading(webView, str);
            }
        });
        WebSettings settings = this.mWebView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setCacheMode(2);
        settings.setSupportZoom(false);
        settings.setBuiltInZoomControls(false);
        settings.setDomStorageEnabled(true);
        try {
            this.mWebView.setBackgroundColor(0);
            this.mWebViewContainer.setBackgroundColor(Color.parseColor(this.mPriAgrBgColor));
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.mWebView.loadUrl(this.mJumpUrl);
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("p_Code", "verify");
            jSONObject.put("pin", this.policyConfigForServer.extra.userId);
            IdentityTracker.tracker(this.mContext, TrackerConstantsImpl.event_enter_authority_page, jSONObject);
        } catch (Exception e2) {
            JDCNLogUtils.e(VerifyFaceContants.LOG_TAG, "checkIdentityVerity", e2);
        }
        refreshViewsWithUserPrivacy();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void refreshViewsWithUserPrivacy() {
        GradientDrawable gradientDrawable;
        int i = this.mShowType;
        int i2 = 8;
        if (i == 0) {
            this.mPriAgrContainer.setVisibility(0);
            this.mWebViewContainer.setVisibility(8);
            this.mIdentityBtn.setText("继续");
        } else if (i == 1) {
            this.isUserAgree = true;
            this.mPriAgrContainer.setVisibility(8);
            this.mWebViewContainer.setVisibility(0);
            this.mIdentityBtn.setText("同意并继续");
        }
        this.mIdentityTitle.setText(this.mTitle);
        this.mIdentityDesc.setText(this.mDesc);
        this.mAgreementContent.setText(getClickableSpan(this.mAgree));
        View findViewById = findViewById(R.id.dialog_pri_agr_container);
        if (this.isShowPriAgr) {
            i2 = 0;
        }
        findViewById.setVisibility(i2);
        try {
            this.mAgreementContent.setMovementMethod(LinkMovementMethod.getInstance());
            if (this.themeColor.length() == 9) {
                this.themeColor = MqttTopic.MULTI_LEVEL_WILDCARD + this.themeColor.substring(3);
            }
            this.themeColor = this.themeColor.replace(MqttTopic.MULTI_LEVEL_WILDCARD, this.isUserAgree ? "#FF" : "#66");
            ImageView imageView = this.mAgreeIcon;
            if (this.isUserAgree) {
                gradientDrawable = createRectangleDrawable(Color.parseColor(this.themeColor), Color.parseColor(this.themeColor), MiscUtil.dipToPx(this.mContext, 1.0f), (float) MiscUtil.dipToPx(this.mContext, 15.0f));
            } else {
                int parseColor = Color.parseColor(this.translateColor);
                gradientDrawable = createRectangleDrawable(parseColor, Color.parseColor("#FF" + this.themeColor.substring(3)), MiscUtil.dipToPx(this.mContext, 1.0f), (float) MiscUtil.dipToPx(this.mContext, 15.0f));
            }
            imageView.setBackgroundDrawable(gradientDrawable);
            this.mAgreeIcon.setImageResource(this.isUserAgree ? R.drawable.jdcn_identity_agree_check_icon : 0);
            this.mIdentityBtn.setBackgroundDrawable(createRectangleDrawable(Color.parseColor(this.themeColor), Color.parseColor(this.themeColor), 0, (float) MiscUtil.dipToPx(this.mContext, 25.0f)));
            if (this.isUserAgree) {
                this.mIdentityBtn.setTextColor(Color.parseColor("#FFFFFF"));
            } else {
                this.mIdentityBtn.setTextColor(Color.parseColor("#99FFFFFF"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private SpannableString getClickableSpan(String str) {
        SpannableString spannableString = new SpannableString(str);
        AnonymousClass3 r1 = new ClickableSpan() {
            /* class com.jdjr.risk.identity.verify.activity.IdentityPrivacyAgrDialogActivity.AnonymousClass3 */

            public void onClick(@NonNull View view) {
                IdentityPrivacyAgrDialogActivity.this.mShowType = 1;
                IdentityPrivacyAgrDialogActivity.this.refreshViewsWithUserPrivacy();
                try {
                    IdentityPrivacyAgrDialogActivity.this.findViewById(R.id.faceCheck_Layout).setBackgroundDrawable(IdentityPrivacyAgrDialogActivity.this.createRectangleDrawable(Color.parseColor(IdentityPrivacyAgrDialogActivity.this.mPriAgrBgColor), Color.parseColor(IdentityPrivacyAgrDialogActivity.this.mPriAgrBgColor), 1, (float) MiscUtil.dipToPx(IdentityPrivacyAgrDialogActivity.this.mContext, 8.0f)));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            public void updateDrawState(@NonNull TextPaint textPaint) {
                textPaint.setUnderlineText(false);
            }
        };
        try {
            String str2 = this.mAgreeWord;
            int indexOf = str.indexOf(str2);
            int length = str2.length() + indexOf;
            spannableString.setSpan(r1, indexOf, length, 17);
            spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FFCC8C4E")), indexOf, length, 17);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return spannableString;
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private GradientDrawable createRectangleDrawable(@ColorInt int i, @ColorInt int i2, int i3, float f) {
        try {
            GradientDrawable gradientDrawable = new GradientDrawable();
            gradientDrawable.setShape(0);
            gradientDrawable.setColor(i);
            gradientDrawable.setStroke(i3, i2);
            gradientDrawable.setCornerRadius(f);
            return gradientDrawable;
        } catch (Exception unused) {
            return new GradientDrawable();
        }
    }

    public void onClick(View view) {
        if (view.getId() == R.id.identity_privacy_agr_container) {
            this.isUserAgree = !this.isUserAgree;
            refreshViewsWithUserPrivacy();
        } else if (view.getId() != R.id.identity_privacy_identity) {
        } else {
            if (!this.isUserAgree) {
                JdcnToast.makeText(this.mContext, "请先同意服务协议", 0).show();
                return;
            }
            try {
                JSONObject jSONObject = new JSONObject();
                jSONObject.put("p_Code", "verify");
                jSONObject.put("pin", this.policyConfigForServer.extra.userId);
                IdentityTracker.tracker(this.mContext, TrackerConstantsImpl.event_face_begin, jSONObject);
            } catch (Exception e) {
                JDCNLogUtils.e(VerifyFaceContants.LOG_TAG, "checkIdentityVerity", e);
            }
            checkCameraPermissions();
        }
    }

    @Override // androidx.activity.ComponentActivity
    public void onBackPressed() {
        super.onBackPressed();
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("p_Code", "verify");
            jSONObject.put("pin", this.policyConfigForServer.extra.userId);
            IdentityTracker.tracker(this.mContext, TrackerConstantsImpl.event_exit_button, jSONObject);
        } catch (Exception e) {
            JDCNLogUtils.e(VerifyFaceContants.LOG_TAG, "checkIdentityVerity", e);
        }
        IdentityVerityEngine.getInstance().callbackFinishSDK(3, "用户取消核验", "", new Bundle());
    }

    public void checkCameraPermissions() {
        if (!FsCameraPermissonCheck.hasCameraPermission(this)) {
            PolicyConfigForServer policyConfigForServer2 = (PolicyConfigForServer) getIntent().getSerializableExtra("policyConfigForServer");
            if (policyConfigForServer2 == null || policyConfigForServer2.verificationSdk == null || policyConfigForServer2.verificationSdk.config == null || !"true".equals(policyConfigForServer2.verificationSdk.config.privacy_authorization_flag)) {
                findViewById(R.id.lay_permission_tip).setVisibility(0);
            } else {
                requestCameraPermissions();
            }
        } else {
            permissionsOK();
        }
    }

    public void requestCameraPermissions() {
        try {
            findViewById(R.id.lay_permission_tip).setVisibility(4);
            IdentityTracker.tracker(this.mContext, "checkCamera", null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Bundle bundle = new Bundle();
        bundle.putString(BuryUtils.MODULE_NAME, "jdcn_face_camera");
        bundle.putString(PushClientConstants.TAG_CLASS_NAME, "IdentityPrivacyAgrDialogActivity");
        bundle.putString("methodName", "requestCameraPermissions");
        bundle.putBoolean("isInitiative", true);
        FsRequestCameraPermissionUtils.requestPermission(this, bundle, "android.permission.CAMERA", new FsRequestCameraPermissionUtils.PermissionResultCallBack() {
            /* class com.jdjr.risk.identity.verify.activity.IdentityPrivacyAgrDialogActivity.AnonymousClass4 */

            @Override // com.jdjr.risk.jdcn.common.permisson.FsRequestCameraPermissionUtils.PermissionResultCallBack
            public void onGranted() {
                super.onGranted();
                IdentityPrivacyAgrDialogActivity.this.permissionsOK();
            }

            @Override // com.jdjr.risk.jdcn.common.permisson.FsRequestCameraPermissionUtils.PermissionResultCallBack
            public void onDenied() {
                super.onDenied();
                IdentityPrivacyAgrDialogActivity.this.permissionsRefuse();
            }

            @Override // com.jdjr.risk.jdcn.common.permisson.FsRequestCameraPermissionUtils.PermissionResultCallBack
            public void onCanceled() {
                super.onCanceled();
                IdentityPrivacyAgrDialogActivity.this.permissionsRefuse();
            }

            @Override // com.jdjr.risk.jdcn.common.permisson.FsRequestCameraPermissionUtils.PermissionResultCallBack
            public void onIgnored() {
                super.onIgnored();
                IdentityPrivacyAgrDialogActivity.this.permissionsRefuse();
            }

            @Override // com.jdjr.risk.jdcn.common.permisson.FsRequestCameraPermissionUtils.PermissionResultCallBack
            public void onOpenSetting() {
                super.onOpenSetting();
                IdentityPrivacyAgrDialogActivity.this.permissionsRefuse();
            }
        }, "摄像头", "京东需要申请摄像头拍摄权限,以便您能正常使用人脸识别服务");
    }

    @Override // androidx.activity.ComponentActivity, androidx.core.app.ActivityCompat.OnRequestPermissionsResultCallback, androidx.fragment.app.FragmentActivity
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        if (i != 34 || getApplicationInfo().targetSdkVersion < 23 || iArr == null || iArr.length <= 0) {
            return;
        }
        if (iArr[0] == 0) {
            permissionsOK();
        } else {
            permissionsRefuse();
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void permissionsOK() {
        FsRequestCameraPermissionUtils.releasePermissionCallback();
        try {
            IdentityTracker.tracker(this.mContext, "authority", null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        IdentityVerityEngine.getInstance().routerOnPermissionAuthed(this.mContext, (PolicyConfigForServer) getIntent().getSerializableExtra("policyConfigForServer"));
        finish();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void permissionsRefuse() {
        FsRequestCameraPermissionUtils.releasePermissionCallback();
        try {
            IdentityTracker.tracker(this.mContext, "noauthority", null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        IdentityVerityEngine.getInstance().callbackFinishSDK(4, "没有相机权限", "", new Bundle());
        finish();
    }
}