| | |
| | | |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.text.SpannableStringBuilder; |
| | | import android.text.TextPaint; |
| | | import android.text.TextUtils; |
| | | import android.text.method.LinkMovementMethod; |
| | | import android.text.style.ClickableSpan; |
| | | import android.util.Log; |
| | | import android.view.View; |
| | | import android.widget.TextView; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.linkpm.sdk.user.HDLLinkPMUser; |
| | | import com.hdl.photovoltaic.HDLApp; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.CustomBaseActivity; |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.other.HdlCommonLogic; |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | | import com.hdl.photovoltaic.other.HdlResidenceLogic; |
| | | import com.hdl.photovoltaic.ui.bean.HouseIdBean; |
| | | import com.hdl.photovoltaic.ui.me.WebActivity; |
| | | import com.hdl.photovoltaic.utils.LocalManageUtil; |
| | | import com.hdl.photovoltaic.utils.SharedPreUtils; |
| | | import com.hdl.photovoltaic.widget.ConfirmationCancelDialog; |
| | | import com.hdl.sdk.link.HDLLinkLocalSdk; |
| | | |
| | | import java.util.List; |
| | | |
| | | import cn.jpush.android.api.JPushInterface; |
| | | import io.dcloud.common.util.RuningAcitvityUtil; |
| | | |
| | | |
| | | /** |
| | | * App启动页(目的是为了让用户点击APP图标的时候有一个瞬间响应的交互体验。) |
| | | */ |
| | | public class StartActivity extends CustomBaseActivity { |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | //7天内免登录 |
| | | if (UserConfigManage.getInstance().isAutoLogin()) { |
| | | // showLoading(); |
| | | HdlResidenceLogic.getInstance().getResidenceIdList("", "", new CloudCallBeak<List<HouseIdBean>>() { |
| | | setStatusBarTranslucent(); |
| | | getWindow().setNavigationBarColor(getColor(R.color.text_FF000000)); |
| | | //发布审核小米应用市场要求APP第一次启动提前提示《用户协议》和《隐私政策》才允许上线 |
| | | final String key = "is_login"; |
| | | boolean isLogin = SharedPreUtils.getBoolean(key); |
| | | if (!isLogin) { |
| | | ConfirmationCancelDialog confirmationCancelDialog = new ConfirmationCancelDialog(this); |
| | | confirmationCancelDialog.setTitle(getString(R.string.user_agreement_and_privacy_agreement)); |
| | | confirmationCancelDialog.setContent(getString(R.string.thank_you_for_using)); |
| | | confirmationCancelDialog.setConfirmation(getString(R.string.agree)); |
| | | confirmationCancelDialog.setCancel(getString(R.string.loading_on_agree)); |
| | | confirmationCancelDialog.show(); |
| | | setStringDifferentColors(confirmationCancelDialog.getContentTextView()); |
| | | confirmationCancelDialog.setNoOnclickListener(new ConfirmationCancelDialog.onNoOnclickListener() { |
| | | @Override |
| | | public void onSuccess(List<HouseIdBean> obj) { |
| | | // hideLoading(); |
| | | HdlResidenceLogic.getInstance().setHouseIdList(obj); |
| | | Intent intent = new Intent(); |
| | | intent.setClass(StartActivity.this, MyPowerStationActivity.class); |
| | | startActivity(intent); |
| | | finish(); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | // hideLoading(); |
| | | Intent intent = new Intent(); |
| | | intent.setClass(StartActivity.this, MyPowerStationActivity.class); |
| | | startActivity(intent); |
| | | public void Cancel() { |
| | | confirmationCancelDialog.dismiss(); |
| | | SharedPreUtils.putBoolean(key, false); |
| | | finish(); |
| | | } |
| | | }); |
| | | |
| | | confirmationCancelDialog.setYesOnclickListener(new ConfirmationCancelDialog.onYesOnclickListener() { |
| | | @Override |
| | | public void Confirm() { |
| | | confirmationCancelDialog.dismiss(); |
| | | initSdk(); |
| | | SharedPreUtils.putBoolean(key, true); |
| | | Intent intent = new Intent(); |
| | | intent.setClass(StartActivity.this, LoginActivity.class); |
| | | openActivity(intent); |
| | | } |
| | | }); |
| | | } else { |
| | | Intent intent = new Intent(); |
| | | intent.setClass(this, HomeLoginActivity.class); |
| | | startActivity(intent); |
| | | finish(); |
| | | initSdk(); |
| | | //初始化服务器域名(用户注册所在服务器域名地址) |
| | | AppConfigManage.setUserRegionUrl(HDLLinkPMUser.getInstance().getUserRegionUrl()); |
| | | //判断AccessToken是否null |
| | | if (!TextUtils.isEmpty(HDLLinkPMUser.getInstance().getAccessToken())) { |
| | | if (UserConfigManage.getInstance().isBAccount()) { |
| | | //安装商跳转界面 |
| | | Intent intent = new Intent(); |
| | | intent.setClass(StartActivity.this, BPowerStationActivity.class); |
| | | openActivity(intent); |
| | | } else { |
| | | //C端用户跳转界面 |
| | | // showLoading(); |
| | | HdlResidenceLogic.getInstance().getResidenceIdList("", "", new CloudCallBeak<List<HouseIdBean>>() { |
| | | @Override |
| | | public void onSuccess(List<HouseIdBean> obj) { |
| | | // hideLoading(); |
| | | HdlResidenceLogic.getInstance().setHouseIdList(obj); |
| | | Intent intent = new Intent(); |
| | | intent.setClass(StartActivity.this, CPowerStationActivity.class); |
| | | openActivity(intent); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | // hideLoading(); |
| | | Intent intent = new Intent(); |
| | | intent.setClass(StartActivity.this, CPowerStationActivity.class); |
| | | openActivity(intent); |
| | | } |
| | | }); |
| | | } |
| | | } else { |
| | | Intent intent = new Intent(); |
| | | intent.setClass(StartActivity.this, LoginActivity.class); |
| | | openActivity(intent); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void startActivity(Intent intent) { |
| | | super.startActivity(intent); |
| | | overridePendingTransition(0, 0); |
| | | } |
| | | |
| | | void openActivity(Intent intent) { |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); |
| | | startActivity(intent); |
| | | finish(); |
| | | } |
| | | |
| | | @Override |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | overridePendingTransition(0, 0); |
| | | } |
| | | |
| | | /** |
| | | * 设置一串字符多种颜色以及点击事件 |
| | | * |
| | | * @param textView 当前组件 |
| | | */ |
| | | private void setStringDifferentColors(TextView textView) { |
| | | try { |
| | | |
| | | |
| | | if (textView == null) { |
| | | return; |
| | | } |
| | | |
| | | String s = textView.getText().toString(); |
| | | if (!s.contains("《")) { |
| | | return; |
| | | } |
| | | |
| | | int startIndex1 = s.indexOf("《"); |
| | | int endIndex1 = s.indexOf("》") + 1; |
| | | |
| | | |
| | | int startIndex2 = s.lastIndexOf("《"); |
| | | int endIndex2 = s.lastIndexOf("》") + 1; |
| | | if (UserConfigManage.getInstance().getCurrentAppLanguage().equals(LocalManageUtil.en)) { |
| | | s = s.replace("《", "").replace("》", ""); |
| | | endIndex1 -= 1; |
| | | startIndex2 -= 2;//移除"《"和"》"总长度发生变化,索引也改变; |
| | | endIndex2 -= 4;//移除"《"和"》"总长度发生变化,索引也改变; |
| | | } |
| | | SpannableStringBuilder spannable = new SpannableStringBuilder(s); |
| | | //设置文字的前景色 |
| | | if (textView.getTag() != null && textView.getTag().toString().equals("click")) { |
| | | spannable.setSpan(new ClickableSpan() { |
| | | @Override |
| | | public void onClick(@NonNull View widget) { |
| | | //todo 需要跳转到服务协议界面 |
| | | Intent intent = new Intent(); |
| | | intent.putExtra("type", WebActivity.ServiceAgreement); |
| | | intent.setClass(_mActivity, WebActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | |
| | | @Override |
| | | public void updateDrawState(@NonNull TextPaint ds) { |
| | | super.updateDrawState(ds); |
| | | //设置字体颜色 |
| | | ds.setColor(getResources().getColor(R.color.text_E6FFFFFF, null)); |
| | | // 去掉下划线 |
| | | ds.setUnderlineText(!UserConfigManage.getInstance().isZh()); |
| | | } |
| | | |
| | | |
| | | }, startIndex1, endIndex1, 0); |
| | | // spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), startIndex1, endIndex1, 0); |
| | | |
| | | spannable.setSpan(new ClickableSpan() { |
| | | @Override |
| | | public void onClick(@NonNull View widget) { |
| | | //todo 需要跳转到隐私界面 |
| | | Intent intent = new Intent(); |
| | | intent.putExtra("type", WebActivity.PrivacyAgreement); |
| | | intent.setClass(_mActivity, WebActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | |
| | | @Override |
| | | public void updateDrawState(@NonNull TextPaint ds) { |
| | | super.updateDrawState(ds); |
| | | //设置字体颜色 |
| | | ds.setColor(getResources().getColor(R.color.text_E6FFFFFF, null)); |
| | | // 去掉下划线 |
| | | ds.setUnderlineText(!UserConfigManage.getInstance().isZh()); |
| | | } |
| | | |
| | | |
| | | }, startIndex2, endIndex2, 0); |
| | | // spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), startIndex2, endIndex2, 0); |
| | | |
| | | |
| | | } |
| | | textView.setText(spannable); |
| | | //中途遇到点击后字体显示高亮,取消高亮 |
| | | textView.setHighlightColor(getResources().getColor(R.color.text_66FFFFFF, null)); |
| | | //最后设置可点击,必须实现,否则只能显示样式,无法实现点击效果 |
| | | textView.setMovementMethod(LinkMovementMethod.getInstance()); |
| | | } catch (Exception ignored) { |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 初始化三方相关SDK |
| | | * 小米平台上线,需要先同意后,在初始化极光SDK,否则平台审核不让通过 |
| | | */ |
| | | private void initSdk() { |
| | | if (HDLApp.getInstance().isStartInitThirdSDK) { |
| | | return; |
| | | } |
| | | HDLApp.getInstance().isStartInitThirdSDK = true; |
| | | //初始化极光推送 |
| | | initJPush(); |
| | | } |
| | | |
| | | /** |
| | | * 初始化极光SDK |
| | | */ |
| | | private void initJPush() { |
| | | JPushInterface.setDebugMode(true); |
| | | JPushInterface.init(getBaseContext()); |
| | | } |
| | | |
| | | } |