| | |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.text.Editable; |
| | | import android.text.Spannable; |
| | | import android.text.SpannableStringBuilder; |
| | | import android.text.TextPaint; |
| | | import android.text.TextUtils; |
| | | import android.text.TextWatcher; |
| | | import android.text.method.HideReturnsTransformationMethod; |
| | | import android.text.method.LinkMovementMethod; |
| | | import android.text.method.PasswordTransformationMethod; |
| | | import android.text.style.ForegroundColorSpan; |
| | | import android.util.Log; |
| | | import android.text.style.ClickableSpan; |
| | | import android.view.View; |
| | | import android.widget.TextView; |
| | | |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.appcompat.content.res.AppCompatResources; |
| | | |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.other.HdlAccountLogic; |
| | | import com.hdl.photovoltaic.other.HdlThreadLogic; |
| | | import com.hdl.photovoltaic.widget.ConfirmationCancelDialog; |
| | | import com.hdl.photovoltaic.widget.ConfirmationCancelDialog1; |
| | | |
| | | import java.util.List; |
| | | import java.util.Locale; |
| | | |
| | | /** |
| | | * 登录的界面 |
| | |
| | | |
| | | @Override |
| | | public Object getContentView() { |
| | | |
| | | viewBinding = ActivityHomeLoginBinding.inflate(getLayoutInflater()); |
| | | return viewBinding.getRoot(); |
| | | } |
| | | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | |
| | | |
| | | //初始化 |
| | | initView(); |
| | | //初始化界面监听器 |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 初始化UI |
| | | */ |
| | | private void initView() { |
| | | viewBinding.homeLoginCheckBCIv.setSelected(UserConfigManage.getInstance().isBAccount()); |
| | | viewBinding.homeLoginInstallUserTv.setSelected(UserConfigManage.getInstance().isBAccount()); |
| | | viewBinding.homeLoginPrivacyCheckIv.setSelected(UserConfigManage.getInstance().isAcceiptPolicy()); |
| | | setStringDifferentColors(viewBinding.homeLoginPrivacyTv); |
| | | |
| | | String acc = "13375012441"; |
| | | String pws = "123456"; |
| | | //测试用 |
| | | viewBinding.homeLoginAccountEt.setText("13375012441"); |
| | | viewBinding.homeLoginPasswordEt.setText("123456"); |
| | | viewBinding.homeLoginAccountEt.setText(acc); |
| | | viewBinding.homeLoginPasswordEt.setText(pws); |
| | | isLoginTextViewEnabled(); |
| | | } |
| | | |
| | | /** |
| | | * 注册监听事件 |
| | | */ |
| | | private void initEvent() { |
| | | |
| | | viewBinding.homeLoginAccountEt.addTextChangedListener(accountTextWatcher); |
| | |
| | | public void onClick(View v) { |
| | | v.setSelected(!v.isSelected()); |
| | | UserConfigManage.getInstance().setBAccount(v.isSelected()); |
| | | viewBinding.homeLoginCheckIv.setSelected(UserConfigManage.getInstance().isBAccount()); |
| | | viewBinding.homeLoginCheckBCIv.setSelected(UserConfigManage.getInstance().isBAccount()); |
| | | if (UserConfigManage.getInstance().isBAccount()) { |
| | | viewBinding.homeLoginRegisterTv.setVisibility(View.GONE); |
| | | } else { |
| | |
| | | } |
| | | }); |
| | | //选择b端,c端 |
| | | viewBinding.homeLoginCheckIv.setOnClickListener(new View.OnClickListener() { |
| | | viewBinding.homeLoginCheckBCIv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | v.setSelected(!v.isSelected()); |
| | |
| | | } |
| | | } |
| | | }); |
| | | //隐私协议 |
| | | viewBinding.homeLoginPrivacyCheckIv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | v.setSelected(!v.isSelected()); |
| | | UserConfigManage.getInstance().setAcceiptPolicy(v.isSelected()); |
| | | } |
| | | }); |
| | | //登录 |
| | |
| | | if (!isLogin) { |
| | | return; |
| | | } |
| | | // boolean isSelected = viewBinding.homeLoginPrivacyCheckIv.isSelected(); |
| | | // if(!isSelected){ |
| | | // //隐私协议提示 |
| | | // return; |
| | | // } |
| | | showLoading(getString(R.string.home_login_登录中)); |
| | | boolean isSelected = UserConfigManage.getInstance().isAcceiptPolicy(); |
| | | if (!isSelected) { |
| | | //隐私协议提示 |
| | | getDialog(); |
| | | return; |
| | | } |
| | | showLoading(getString(R.string.home_login_be_logging_in)); |
| | | HdlAccountLogic.getInstance().regionByAccount(account, new CloudCallBeak<HDLUserRegionBean>() { |
| | | @Override |
| | | public void onSuccess(HDLUserRegionBean obj) { |
| | |
| | | HdlResidenceLogic.getInstance().setHouseIdList(obj); |
| | | restoreButtonStyleToInitializeState(); |
| | | startActivity(MyPowerStationActivity.class); |
| | | finish(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | hideLoading(); |
| | | restoreButtonStyleToInitializeState(); |
| | | startActivity(MyPowerStationActivity.class); |
| | | finish(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException exception) { |
| | | public void onFailure(HDLException e) { |
| | | hideLoading(); |
| | | HdlThreadLogic.toast(_mActivity, e.getMsg() + "(" + e.getCode() + ")"); |
| | | } |
| | | }); |
| | | } |
| | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | hideLoading(); |
| | | HdlThreadLogic.toast(_mActivity, e.getMsg() + "(" + e.getCode() + ")"); |
| | | } |
| | | }); |
| | | |
| | |
| | | UserConfigManage.getInstance().setUserExperience(v.isSelected()); |
| | | // requestPermissions(); |
| | | // startActivity(MyPowerStationActivity.class); |
| | | HdlFileLogic.getInstance().deleteDirectory(HdlFileLogic.getInstance().getCurrentHomeRootPath()); |
| | | } |
| | | }); |
| | | //注册 |
| | |
| | | private boolean isLocalCheckAccountAndPassword(String account, String password) { |
| | | if (TextUtils.isEmpty(account)) { |
| | | viewBinding.homeLoginLine1V.setBackgroundColor(getColor(R.color.text_D34545)); |
| | | viewBinding.homeLoginAccountTextErrorTv.setText(R.string.home_login_error_账号不能为空); |
| | | viewBinding.homeLoginAccountTextErrorTv.setText(R.string.home_login_error_account_null); |
| | | return false; |
| | | } |
| | | if (TextUtils.isEmpty(password)) { |
| | | viewBinding.homeLoginLine2V.setBackgroundColor(getColor(R.color.text_D34545)); |
| | | viewBinding.homeLoginPasswordTextErrorTv.setText(R.string.home_login_error_密码不能为空); |
| | | viewBinding.homeLoginPasswordTextErrorTv.setText(R.string.home_login_error_password_null); |
| | | return false; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 设置一串字符多种颜色 |
| | | * 设置一串字符多种颜色以及点击事件 |
| | | * |
| | | * @param view 当前组件 |
| | | * @param textView 当前组件 |
| | | */ |
| | | private void setStringDifferentColors(TextView view) { |
| | | String s = view.getText().toString(); |
| | | private void setStringDifferentColors(TextView textView) { |
| | | |
| | | if (textView == null) { |
| | | return; |
| | | } |
| | | |
| | | String s = textView.getText().toString(); |
| | | |
| | | int startIndex1 = s.indexOf("《"); |
| | | int endIndex1 = s.indexOf("》") + 1; |
| | | |
| | | int startIndex2 = s.lastIndexOf("《"); |
| | | int endIndex2 = s.lastIndexOf("》") + 1; |
| | | |
| | | SpannableStringBuilder spannable = new SpannableStringBuilder(s); |
| | | //设置文字的前景色 |
| | | spannable.setSpan(new ForegroundColorSpan(getColor(R.color.text_245EC3)), 2, 7, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); |
| | | spannable.setSpan(new ForegroundColorSpan(getColor(R.color.text_245EC3)), 9, 19, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); |
| | | view.setText(spannable); |
| | | // spannable.setSpan(new ForegroundColorSpan(getColor(R.color.text_245EC3)), startIndex1, endIndex1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); |
| | | // spannable.setSpan(new ForegroundColorSpan(getColor(R.color.text_245EC3)), startIndex2, endIndex2, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); |
| | | // textView.setText(spannable); |
| | | |
| | | if (textView.getTag() != null && textView.getTag().toString().equals("click")) { |
| | | // textView.setOnClickListener(new View.OnClickListener() { |
| | | // @Override |
| | | // public void onClick(View v) { |
| | | // //todo 需要跳转到隐私界面 |
| | | // } |
| | | // }); |
| | | spannable.setSpan(new ClickableSpan() { |
| | | @Override |
| | | public void onClick(@NonNull View widget) { |
| | | //todo 需要跳转到隐私界面 |
| | | } |
| | | |
| | | @Override |
| | | public void updateDrawState(@NonNull TextPaint ds) { |
| | | super.updateDrawState(ds); |
| | | //设置字体颜色 |
| | | ds.setColor(getResources().getColor(R.color.text_245EC3, null)); |
| | | // 去掉下划线 |
| | | ds.setUnderlineText(false); |
| | | } |
| | | |
| | | |
| | | }, startIndex1, endIndex1, 0); |
| | | |
| | | spannable.setSpan(new ClickableSpan() { |
| | | @Override |
| | | public void onClick(@NonNull View widget) { |
| | | //todo 需要跳转到隐私界面 |
| | | } |
| | | |
| | | @Override |
| | | public void updateDrawState(@NonNull TextPaint ds) { |
| | | super.updateDrawState(ds); |
| | | //设置字体颜色 |
| | | ds.setColor(getResources().getColor(R.color.text_245EC3, null)); |
| | | // 去掉下划线 |
| | | ds.setUnderlineText(false); |
| | | } |
| | | |
| | | |
| | | }, startIndex2, endIndex2, 0); |
| | | |
| | | |
| | | } |
| | | textView.setText(spannable); |
| | | //中途遇到点击后字体显示高亮,取消高亮 |
| | | textView.setHighlightColor(getResources().getColor(R.color.text_00000000, null)); |
| | | //最后设置可点击,必须实现,否则只能显示样式,无法实现点击效果 |
| | | textView.setMovementMethod(LinkMovementMethod.getInstance()); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 弹窗 |
| | | */ |
| | | private void getDialog() { |
| | | ConfirmationCancelDialog1 dialog = new ConfirmationCancelDialog1(_mActivity); |
| | | dialog.setTitle(getString(R.string.loading_privacy)); |
| | | dialog.setContent(getString(R.string.loading_privacy_server)); |
| | | dialog.show(); |
| | | setStringDifferentColors(dialog.getContentTextView()); |
| | | dialog.setYesOnclickListener(new ConfirmationCancelDialog.onYesOnclickListener() { |
| | | @Override |
| | | public void Confirm() { |
| | | |
| | | UserConfigManage.getInstance().setAcceiptPolicy(true); |
| | | viewBinding.homeLoginPrivacyCheckIv.setSelected(true); |
| | | dialog.dismiss(); |
| | | } |
| | | }); |
| | | dialog.setNoOnclickListener(new ConfirmationCancelDialog.onNoOnclickListener() { |
| | | @Override |
| | | public void Cancel() { |
| | | UserConfigManage.getInstance().setAcceiptPolicy(false); |
| | | viewBinding.homeLoginPrivacyCheckIv.setSelected(false); |
| | | dialog.dismiss(); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | viewBinding.homeLoginAccountEt.removeTextChangedListener(accountTextWatcher); |
| | | viewBinding.homeLoginPasswordEt.removeTextChangedListener(passwordTextWatcher); |
| | | } |
| | | |
| | | |
| | | } |