语言选择
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package com.ckkj.water;
|
||||
|
||||
public class AppConfig {
|
||||
|
||||
//用户当前保存的语言状态,用于接口请求头传参
|
||||
//zh_CN 中文
|
||||
//en_US 英文
|
||||
public static String LOCAL_LANUAGE = "zh_CN";
|
||||
|
||||
|
||||
/**************************生产*******************************/
|
||||
|
||||
@@ -87,60 +87,83 @@ public class LoginActivity extends BaseActivity<LoginLayoutBinding, LoginPresent
|
||||
}
|
||||
|
||||
private void setupAgreementText() {
|
||||
//勾选协议,增加点击区域
|
||||
ClickUtil.addClickPart(viewBinding.checkboxRead,100);
|
||||
|
||||
ClickUtil.addClickPart(viewBinding.checkboxRead, 100);
|
||||
|
||||
TextView tvAgreement = findViewById(R.id.tv_agreement_full);
|
||||
String content = "我已经阅读并同意智能浇灌《用户协议》、《隐私政策》";
|
||||
|
||||
String content = getString(R.string.agree_user_policy);
|
||||
|
||||
String userAgreementText = getString(R.string.user_agreement);
|
||||
String privacyPolicyText = getString(R.string.privacy_policy);
|
||||
|
||||
SpannableString spannableString = new SpannableString(content);
|
||||
|
||||
// 设置“用户协议”可点击
|
||||
ClickableSpan userAgreementSpan = new ClickableSpan() {
|
||||
addClickableSpan(
|
||||
spannableString,
|
||||
content,
|
||||
userAgreementText,
|
||||
() -> {
|
||||
ToastUtil.showShort(mContext, "用户协议");
|
||||
}
|
||||
);
|
||||
|
||||
addClickableSpan(
|
||||
spannableString,
|
||||
content,
|
||||
privacyPolicyText,
|
||||
() -> {
|
||||
ToastUtil.showShort(mContext, "隐私政策");
|
||||
}
|
||||
);
|
||||
|
||||
tvAgreement.setText(spannableString);
|
||||
tvAgreement.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
tvAgreement.setHighlightColor(Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
private void addClickableSpan(
|
||||
SpannableString spannableString,
|
||||
String content,
|
||||
String target,
|
||||
Runnable action) {
|
||||
|
||||
int start = content.indexOf(target);
|
||||
|
||||
if (start < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int end = start + target.length();
|
||||
|
||||
ClickableSpan clickableSpan = new ClickableSpan() {
|
||||
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
// 跳转用户协议
|
||||
// Bundle bundle = new Bundle();
|
||||
// bundle.putInt("from_requse_code", WebviewUserAgreement.AGREEMENT_CODE);
|
||||
// goToWihoutNoPresent(mContext, WebviewUserAgreement.class,bundle);
|
||||
ToastUtil.showShort(mContext,"用户协议");
|
||||
action.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDrawState(@NonNull TextPaint ds) {
|
||||
super.updateDrawState(ds);
|
||||
ds.setColor(ContextCompat.getColor(mContext, R.color.color_zhu)); // 设置颜色
|
||||
ds.setUnderlineText(false); // 去掉下划线
|
||||
}
|
||||
};
|
||||
int start1 = content.indexOf("《用户协议》");
|
||||
int end1 = start1 + "《用户协议》".length();
|
||||
spannableString.setSpan(userAgreementSpan, start1, end1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
|
||||
// 设置“隐私政策”可点击
|
||||
ClickableSpan privacyPolicySpan = new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
// 跳转隐私政策
|
||||
// Bundle bundleYS = new Bundle();
|
||||
// bundleYS.putInt("from_requse_code",WebviewUserAgreement.PRIVACY_CODE);
|
||||
// goToWihoutNoPresent(mContext, WebviewUserAgreement.class,bundleYS);
|
||||
ToastUtil.showShort(mContext,"跳转隐私政策");
|
||||
}
|
||||
ds.setColor(
|
||||
ContextCompat.getColor(
|
||||
mContext,
|
||||
R.color.color_zhu
|
||||
)
|
||||
);
|
||||
|
||||
@Override
|
||||
public void updateDrawState(@NonNull TextPaint ds) {
|
||||
super.updateDrawState(ds);
|
||||
ds.setColor(ContextCompat.getColor(mContext, R.color.color_zhu)); // 设置颜色
|
||||
ds.setUnderlineText(false);
|
||||
}
|
||||
};
|
||||
int start2 = content.indexOf("《隐私政策》");
|
||||
int end2 = start2 + "《隐私政策》".length();
|
||||
spannableString.setSpan(privacyPolicySpan, start2, end2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
|
||||
tvAgreement.setText(spannableString);
|
||||
tvAgreement.setMovementMethod(LinkMovementMethod.getInstance()); // 开启点击事件
|
||||
tvAgreement.setHighlightColor(Color.TRANSPARENT);
|
||||
spannableString.setSpan(
|
||||
clickableSpan,
|
||||
start,
|
||||
end,
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
);
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.ckkj.water.EventMessage;
|
||||
import com.ckkj.water.MyApplication;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.utils.AppInfoUtil;
|
||||
import com.ckkj.water.utils.manager.LanguageManager;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@@ -338,7 +339,7 @@ public class NetWorkManager {
|
||||
try {
|
||||
map.put("Authorization", "Bearer " + AppConfig.USER_TOKEN);
|
||||
map.put("clientId", AppConfig.APP_CLIENT_ID);
|
||||
// map.put("Authorization", "Bearer " + "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxOTI1NzYwMTgxMTMyNzI2MDIyLCJ1c2VyX2tleSI6IjY0YjVmMjRjLTIyM2ItNDRkZC1iMDJlLTI0ZTRiNzNmODgxZCIsInVzZXJuYW1lIjoiMTg2NDU5MDQzMDIifQ.PiIjBZlQ9UtOuotfhd5mZZO2e8SbMpbXU7VDvVeiWZIecsFDUd51Rae09EFxQ_MJmBUEvIdyysnyqYiBC2AEfw");
|
||||
map.put("content-language", LanguageManager.getCurrentRequestLanguage());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ import com.ckkj.water.utils.show.ToastUtil;
|
||||
public class LanguageManager {
|
||||
|
||||
private static final String TAG = "LanguageManager";
|
||||
private static final String LANGUAGE_ZH_CN = "zh_CN";
|
||||
private static final String LANGUAGE_EN_US = "en_US";
|
||||
|
||||
/**
|
||||
* 语言类型枚举
|
||||
@@ -77,6 +79,20 @@ public class LanguageManager {
|
||||
return getCurrentLanguageType().index;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口请求头需要的语言值
|
||||
*/
|
||||
public static String getCurrentRequestLanguage() {
|
||||
return getCurrentLanguageType() == LanguageType.ENGLISH ? LANGUAGE_EN_US : LANGUAGE_ZH_CN;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步当前语言到全局配置
|
||||
*/
|
||||
public static void syncCurrentLanguageToAppConfig() {
|
||||
AppConfig.LOCAL_LANUAGE = getCurrentRequestLanguage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换语言
|
||||
* @param languageType 要切换到的语言类型
|
||||
@@ -97,6 +113,7 @@ public class LanguageManager {
|
||||
// 设置应用语言
|
||||
LocaleListCompat localeList = LocaleListCompat.forLanguageTags(languageType.languageTag);
|
||||
AppCompatDelegate.setApplicationLocales(localeList);
|
||||
AppConfig.LOCAL_LANUAGE = languageType == LanguageType.ENGLISH ? LANGUAGE_EN_US : LANGUAGE_ZH_CN;
|
||||
|
||||
// 如果传入了Activity,则重启应用
|
||||
if (activity != null) {
|
||||
@@ -163,6 +180,7 @@ public class LanguageManager {
|
||||
LocaleListCompat localeList = LocaleListCompat.forLanguageTags(savedLocale);
|
||||
AppCompatDelegate.setApplicationLocales(localeList);
|
||||
}
|
||||
syncCurrentLanguageToAppConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user