| | |
| | | package com.hdl.photovoltaic.utils; |
| | | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.res.Configuration; |
| | | import android.content.res.Resources; |
| | | import android.os.Build; |
| | |
| | | import android.util.DisplayMetrics; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.hdl.linkpm.sdk.utils.HDLFileUtils; |
| | | import com.hdl.photovoltaic.HDLApp; |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.other.HdlFileLogic; |
| | | import com.hdl.photovoltaic.ui.adapter.LanguageAdapter; |
| | | import com.hdl.photovoltaic.ui.bean.LongLatListInfo; |
| | | import com.hdl.photovoltaic.ui.bean.NationBean; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Locale; |
| | | |
| | | /** |
| | | * 多语言适配 |
| | | */ |
| | | public class LocalManageUtil { |
| | | |
| | | public static final String zh = "zh";//中文你 |
| | | public static final String en = "en";//英文 |
| | | |
| | | // private static Locale mLocale; |
| | | |
| | |
| | | } |
| | | return locale; |
| | | } |
| | | // |
| | | // public static Context setLocal(Context context) { |
| | | // return updateResources(context, mLocale); |
| | | // } |
| | | // |
| | | // public static Context updateResources(Context context, Locale locale) { |
| | | // if (locale == null) { |
| | | // return context; |
| | | // } |
| | | // LocalManageUtil.mLocale = locale; |
| | | // Locale.setDefault(locale); |
| | | // |
| | | // Resources res = context.getResources(); |
| | | // Configuration config = new Configuration(res.getConfiguration()); |
| | | // config.setLocale(locale); |
| | | // context = context.createConfigurationContext(config); |
| | | // return context; |
| | | // } |
| | | |
| | | |
| | | /** |
| | | * 应用内切换语言 |
| | |
| | | * @param context 上下文 |
| | | */ |
| | | private static void setCurrLanguageMode(Context context) { |
| | | String language = SharedPreUtils.getSharedPreferencesKey("languege", context); |
| | | String language = SharedPreUtils.getSharedPreferencesKey("languege"); |
| | | Locale local = getLocale(language); |
| | | Resources res = context.getResources(); |
| | | DisplayMetrics dm = res.getDisplayMetrics(); |
| | |
| | | res.updateConfiguration(conf, dm); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取语言列表 |
| | | * |
| | | * @return 返回语言列表 |
| | | */ |
| | | public static List<LanguageAdapter.ItemData> getLanguageList() { |
| | | List<LanguageAdapter.ItemData> list = new ArrayList<>(); |
| | | LanguageAdapter.ItemData zh = new LanguageAdapter.ItemData(); |
| | | zh.setState(false); |
| | | zh.setTitle("简体中文"); |
| | | zh.setLanguage(LocalManageUtil.zh); |
| | | list.add(zh); |
| | | LanguageAdapter.ItemData en = new LanguageAdapter.ItemData(); |
| | | en.setState(false); |
| | | en.setTitle("English"); |
| | | en.setLanguage(LocalManageUtil.en); |
| | | list.add(en); |
| | | |
| | | |
| | | return list; |
| | | } |
| | | |
| | | |
| | | public static LanguageAdapter.ItemData getLanguage(String languageStr) { |
| | | List<LanguageAdapter.ItemData> list = getLanguageList(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | if (list.get(i).getLanguage().equals(languageStr)) { |
| | | return list.get(i); |
| | | |
| | | } |
| | | } |
| | | return new LanguageAdapter.ItemData(); |
| | | } |
| | | |
| | | |
| | | //国家,省份,城市 |
| | | private static List<NationBean> nationBeans = new ArrayList<>(); |
| | | //国家,省份,经纬度 |
| | | private static List<LongLatListInfo> longLatBeans = new ArrayList<>(); |
| | | |
| | | public static void getLocationInfo(Context context) { |
| | | if (isZh()) { |
| | | nationBeans = JSON.parseArray(HdlFileLogic.getInstance().openAssetsFileJson("locationCN.json", context), NationBean.class); |
| | | } else { |
| | | nationBeans = JSON.parseArray(HdlFileLogic.getInstance().openAssetsFileJson("locationEN.json", context), NationBean.class); |
| | | } |
| | | } |
| | | |
| | | public static void getLongLatInfo(Context context) { |
| | | if (isZh()) { |
| | | longLatBeans = JSON.parseArray(HdlFileLogic.getInstance().openAssetsFileJson("longLatCN.json", context), LongLatListInfo.class); |
| | | } else { |
| | | longLatBeans = JSON.parseArray(HdlFileLogic.getInstance().openAssetsFileJson("longLatEN.json", context), LongLatListInfo.class); |
| | | } |
| | | } |
| | | |
| | | |
| | | public static boolean isZh() { |
| | | // Locale locale = context.getResources().getConfiguration().locale; |
| | | // String language = locale.getLanguage(); |
| | | String language = UserConfigManage.getInstance().getCurrentAppLanguage(); |
| | | return language.equals(zh); |
| | | } |
| | | |
| | | public static List<NationBean> getNationBeans() { |
| | | if (nationBeans == null) { |
| | | return new ArrayList<>(); |
| | | } |
| | | return nationBeans; |
| | | } |
| | | |
| | | public static List<LongLatListInfo> getLongLatBeans() { |
| | | if (longLatBeans == null) { |
| | | return new ArrayList<>(); |
| | | } |
| | | return longLatBeans; |
| | | } |
| | | |
| | | |
| | | } |
| | | |