package com.doumee.keyCabinet.ui.face; 
 | 
  
 | 
import androidx.annotation.Nullable; 
 | 
  
 | 
import android.graphics.Color; 
 | 
import android.os.Bundle; 
 | 
import android.text.Editable; 
 | 
import android.text.TextWatcher; 
 | 
import android.text.method.ReplacementTransformationMethod; 
 | 
import android.view.animation.Animation; 
 | 
import android.view.animation.AnimationUtils; 
 | 
  
 | 
import com.baidu.idl.main.facesdk.FaceAuth; 
 | 
import com.baidu.idl.main.facesdk.callback.Callback; 
 | 
import com.doumee.keyCabinet.R; 
 | 
import com.doumee.keyCabinet.base.MyBaseActivity; 
 | 
import com.doumee.keyCabinet.databinding.ActivationActivityBinding; 
 | 
import com.doumee.lib_coremodel.bean.event.ActionEventData; 
 | 
import com.example.datalibrary.utils.NetUtil; 
 | 
  
 | 
import dagger.hilt.android.AndroidEntryPoint; 
 | 
  
 | 
@AndroidEntryPoint 
 | 
public class ActivationActivity extends MyBaseActivity<ActivationVM, ActivationActivityBinding> { 
 | 
    private FaceAuth faceAuth; 
 | 
    // 拼接后的激活码 
 | 
    private String end; 
 | 
  
 | 
    @Override 
 | 
    public int getLayoutId() { 
 | 
        return R.layout.activation_activity; 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public void initView(@Nullable Bundle savedInstanceState) { 
 | 
        isToGuild = false; 
 | 
        normalConfig(); 
 | 
        getDB().setModel(getVM()); 
 | 
  
 | 
        faceAuth = new FaceAuth(); 
 | 
        //禁止后续输入 
 | 
        getDB().activityEtTwo.setFocusable(false); 
 | 
        getDB().activityEtTwo.setFocusableInTouchMode(false); 
 | 
        getDB().activityEtTwo.requestFocus(); 
 | 
  
 | 
        getDB().activityEtThree.setFocusable(false); 
 | 
        getDB().activityEtThree.setFocusableInTouchMode(false); 
 | 
        getDB().activityEtThree.requestFocus(); 
 | 
  
 | 
        getDB().activityEtFour.setFocusable(false); 
 | 
        getDB().activityEtFour.setFocusableInTouchMode(false); 
 | 
        getDB().activityEtFour.requestFocus(); 
 | 
  
 | 
        initActivation(); 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public void initData(@Nullable Bundle savedInstanceState) { 
 | 
  
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    protected void doRegister(int type, ActionEventData data) { 
 | 
        switch (type){ 
 | 
            case 1: 
 | 
                jh(); 
 | 
                break; 
 | 
            default: 
 | 
                break; 
 | 
        } 
 | 
    } 
 | 
  
 | 
    private void jh(){ 
 | 
        if (getDB().activityEtOne.getText().toString().trim().length() == 4 && 
 | 
                getDB().activityEtTwo.getText().toString().trim().length() == 4 
 | 
                && getDB().activityEtThree.getText().toString().trim().length() == 4 
 | 
                && getDB().activityEtFour.getText().toString().trim().length() == 4) { 
 | 
            String etOne = getDB().activityEtOne.getText().toString().trim(); 
 | 
            String etTwo = getDB().activityEtTwo.getText().toString().trim(); 
 | 
            String etThree = getDB().activityEtThree.getText().toString().trim(); 
 | 
            String etFour = getDB().activityEtFour.getText().toString().trim(); 
 | 
            end = etOne + "-" + etTwo + "-" + etThree + "-" + etFour; 
 | 
        } 
 | 
        boolean onNetworkConnected = NetUtil.isNetworkConnected(this); 
 | 
        if (onNetworkConnected) { 
 | 
            faceAuth.initLicenseOnLine(this, end, new Callback() { 
 | 
                @Override 
 | 
                public void onResponse(final int code, final String response) { 
 | 
                    if (code == 0) { 
 | 
                        runOnUiThread(new Runnable() { 
 | 
                            @Override 
 | 
                            public void run() { 
 | 
                                getDB().accreditOnhintTv.setText(""); 
 | 
                                //激活成功 
 | 
                                finish(); 
 | 
                            } 
 | 
                        }); 
 | 
                    } else { 
 | 
                        runOnUiThread(new Runnable() { 
 | 
                            @Override 
 | 
                            public void run() { 
 | 
                                getDB().accreditOnhintTv.setText(getString(R.string.activation_err) + code + "  " + response); 
 | 
                                initShake(); 
 | 
                            } 
 | 
                        }); 
 | 
                    } 
 | 
                } 
 | 
            }); 
 | 
        } else { 
 | 
            getDB().accreditOnhintTv.setText(getString(R.string.activation_tip1)); 
 | 
            initShake(); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    private void initActivation() { 
 | 
        getDB().activityEtOne.setTransformationMethod(new AllCapTransformationMethod(true)); 
 | 
        getDB().activityEtTwo.setTransformationMethod(new AllCapTransformationMethod(true)); 
 | 
        getDB().activityEtThree.setTransformationMethod(new AllCapTransformationMethod(true)); 
 | 
        getDB().activityEtFour.setTransformationMethod(new AllCapTransformationMethod(true)); 
 | 
        getDB().activityEtOne.addTextChangedListener(new TextWatcher() { 
 | 
            @Override 
 | 
            public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
 | 
  
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void onTextChanged(CharSequence s, int start, int before, int count) { 
 | 
  
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void afterTextChanged(Editable s) { 
 | 
                if (getDB().activityEtOne.length() == 0) { 
 | 
                    getDB().activityOneView.setBackgroundColor(Color.parseColor("#666666")); 
 | 
                } else if (getDB().activityEtOne.length() == 4) { 
 | 
                    getDB().activityOneView.setBackgroundColor(Color.parseColor("#666666")); 
 | 
                    getDB().activityEtTwo.setFocusable(true); 
 | 
                    getDB().activityEtTwo.setFocusableInTouchMode(true); 
 | 
                    getDB().activityEtTwo.requestFocus(); 
 | 
                    getDB().activityEtTwo.setText(getDB().activityEtTwo.getText().toString().trim() + " "); 
 | 
                    getDB().activityEtTwo.setSelection(getDB().activityEtTwo.getText().length()); 
 | 
                } else if (getDB().activityEtOne.length() < 4) { 
 | 
                    getDB().activityOneView.setBackgroundColor(Color.parseColor("#FFFFFF")); 
 | 
                } 
 | 
            } 
 | 
        }); 
 | 
        getDB().activityEtTwo.addTextChangedListener(new TextWatcher() { 
 | 
            @Override 
 | 
            public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
 | 
  
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void onTextChanged(CharSequence s, int start, int before, int count) { 
 | 
  
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void afterTextChanged(Editable s) { 
 | 
                if (getDB().activityEtTwo.length() == 0) { 
 | 
                    getDB().activityEtOne.setFocusable(true); 
 | 
                    getDB().activityEtOne.setFocusableInTouchMode(true); 
 | 
                    getDB().activityEtOne.requestFocus(); 
 | 
                    getDB().activityTwoView.setBackgroundColor(Color.parseColor("#666666")); 
 | 
                } else if (getDB().activityEtTwo.getText().toString().trim().length() == 4) { 
 | 
                    getDB().activityTwoView.setBackgroundColor(Color.parseColor("#666666")); 
 | 
                    getDB().activityEtThree.setFocusable(true); 
 | 
                    getDB().activityEtThree.setFocusableInTouchMode(true); 
 | 
                    getDB().activityEtThree.requestFocus(); 
 | 
                    getDB().activityEtThree.setText(getDB().activityEtThree.getText().toString().trim() + " "); 
 | 
                    getDB().activityEtThree.setSelection(getDB().activityEtThree.getText().length()); 
 | 
                } else if (getDB().activityEtTwo.getText().toString().trim().length() < 4) { 
 | 
                    getDB().activityTwoView.setBackgroundColor(Color.parseColor("#FFFFFF")); 
 | 
                } 
 | 
  
 | 
  
 | 
            } 
 | 
        }); 
 | 
        getDB().activityEtThree.addTextChangedListener(new TextWatcher() { 
 | 
            @Override 
 | 
            public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
 | 
  
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void onTextChanged(CharSequence s, int start, int before, int count) { 
 | 
  
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void afterTextChanged(Editable s) { 
 | 
                if (getDB().activityEtThree.length() == 0) { 
 | 
                    getDB().activityEtTwo.setFocusable(true); 
 | 
                    getDB().activityEtTwo.setFocusableInTouchMode(true); 
 | 
                    getDB().activityEtTwo.requestFocus(); 
 | 
                    getDB().activityThreeView.setBackgroundColor(Color.parseColor("#666666")); 
 | 
  
 | 
                } else if (getDB().activityEtThree.getText().toString().trim().length() == 4) { 
 | 
                    getDB().activityThreeView.setBackgroundColor(Color.parseColor("#666666")); 
 | 
                    getDB().activityEtFour.setFocusable(true); 
 | 
                    getDB().activityEtFour.setFocusableInTouchMode(true); 
 | 
                    getDB().activityEtFour.requestFocus(); 
 | 
                    getDB().activityEtFour.setText(getDB().activityEtFour.getText().toString().trim() + " "); 
 | 
                    getDB().activityEtFour.setSelection(getDB().activityEtFour.getText().length()); 
 | 
                } else if (getDB().activityEtThree.getText().toString().trim().length() < 4) { 
 | 
                    getDB().activityThreeView.setBackgroundColor(Color.parseColor("#FFFFFF")); 
 | 
                } 
 | 
            } 
 | 
        }); 
 | 
        getDB().activityEtFour.addTextChangedListener(new TextWatcher() { 
 | 
            @Override 
 | 
            public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
 | 
  
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void onTextChanged(CharSequence s, int start, int before, int count) { 
 | 
  
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void afterTextChanged(Editable s) { 
 | 
                if (getDB().activityEtFour.length() == 0) { 
 | 
                    getDB().activityEtThree.setFocusable(true); 
 | 
                    getDB().activityEtThree.setFocusableInTouchMode(true); 
 | 
                    getDB().activityEtThree.requestFocus(); 
 | 
                    getDB().activityFourView.setBackgroundColor(Color.parseColor("#666666")); 
 | 
                } else if (getDB().activityEtFour.getText().toString().trim().length() == 4) { 
 | 
                    getDB().activityFourView.setBackgroundColor(Color.parseColor("#666666")); 
 | 
                    getDB().accreditOnBtn.setEnabled(true); 
 | 
                    getDB().accreditOnBtn.setBackgroundResource(R.drawable.shape_r40_ac_bg); 
 | 
                    getDB().accreditOnBtn.setTextColor(Color.parseColor("#FFFFFF")); 
 | 
                } else if (getDB().activityEtFour.getText().toString().trim().length() < 4) { 
 | 
                    getDB().activityFourView.setBackgroundColor(Color.parseColor("#FFFFFF")); 
 | 
                    getDB().accreditOnBtn.setBackgroundResource(R.drawable.shape_r40_999_bg); 
 | 
                    getDB().accreditOnBtn.setEnabled(false); 
 | 
                    getDB().accreditOnBtn.setTextColor(Color.parseColor("#666666")); 
 | 
                } 
 | 
            } 
 | 
        }); 
 | 
    } 
 | 
  
 | 
    // 为组件设置一个抖动效果 
 | 
    private void initShake() { 
 | 
        Animation shake = AnimationUtils.loadAnimation(this.getApplicationContext(), 
 | 
                R.anim.shake); 
 | 
        getDB().activityEtOne.startAnimation(shake); 
 | 
        getDB().activityEtTwo.startAnimation(shake); 
 | 
        getDB().activityEtThree.startAnimation(shake); 
 | 
        getDB().activityEtFour.startAnimation(shake); 
 | 
        // 改变view的颜色 
 | 
        getDB().activityOneView.setBackgroundColor(Color.parseColor("#F34B56")); 
 | 
        getDB().activityTwoView.setBackgroundColor(Color.parseColor("#FF0033")); 
 | 
        getDB().activityThreeView.setBackgroundColor(Color.parseColor("#FF0033")); 
 | 
        getDB().activityFourView.setBackgroundColor(Color.parseColor("#FF0033")); 
 | 
    } 
 | 
  
 | 
    public static class AllCapTransformationMethod extends ReplacementTransformationMethod { 
 | 
        private char[] lower = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 
 | 
                'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; 
 | 
        private char[] upper = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 
 | 
                'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; 
 | 
        private boolean allUpper = false; 
 | 
  
 | 
        public AllCapTransformationMethod(boolean needUpper) { 
 | 
            this.allUpper = needUpper; 
 | 
        } 
 | 
  
 | 
        @Override 
 | 
        protected char[] getOriginal() { 
 | 
            if (allUpper) { 
 | 
                return lower; 
 | 
            } else { 
 | 
                return upper; 
 | 
            } 
 | 
        } 
 | 
  
 | 
        @Override 
 | 
        protected char[] getReplacement() { 
 | 
            if (allUpper) { 
 | 
                return upper; 
 | 
            } else { 
 | 
                return lower; 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
} 
 |