From: snickersun Date: Mon, 21 Dec 2020 11:00:56 +0000 (+0800) Subject: protocol_jiai 添加语言切换命令 BPLA X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=3ae746878d0214ffd4db3ac368fc336f39055e43;p=protocol_srv.git protocol_jiai 添加语言切换命令 BPLA 补充提交楼下的文件。 --- diff --git a/app/src/main/java/com/enqualcomm/support/utils/LanguageUtils.java b/app/src/main/java/com/enqualcomm/support/utils/LanguageUtils.java new file mode 100644 index 00000000..dcf7843f --- /dev/null +++ b/app/src/main/java/com/enqualcomm/support/utils/LanguageUtils.java @@ -0,0 +1,103 @@ +package com.enqualcomm.support.utils; + +import android.app.backup.BackupManager; +import android.content.Context; +import android.os.Build; +import android.support.annotation.RequiresApi; +import android.util.Log; + +import com.enqualcomm.support.R; + +import java.util.Locale; + +public class LanguageUtils { + private static String language = "zh-cn"; + public static String getCurrentLanguage(){ + ICLogger.i(" get Current language "+Locale.getDefault().getDisplayLanguage()); + return language; + } + + + + public static void changeLanguageByIndex(Context mContext, String index){ + + String languageName=mContext.getResources().getString(R.string.zh); + String msg_index_no=index; + if(msg_index_no.equals("1")){ + languageName=mContext.getResources().getString(R.string.it); + }else if(msg_index_no.equals("2")){ + languageName=mContext.getResources().getString(R.string.de); + }else if(msg_index_no.equals("3")){ + languageName=mContext.getResources().getString(R.string.fr); + }else if(msg_index_no.equals("4")){ + languageName=mContext.getResources().getString(R.string.zh); + }else if(msg_index_no.equals("5")){ + languageName=mContext.getResources().getString(R.string.en); + } + ICLogger.i("切换到语言 "+languageName); + LanguageUtils.changeLanguage(mContext,languageName); + + } + + + public static boolean changeLanguage(Context context, String language) { + Object config; + Object am; + + try { + getCurrentLanguage(); + Class clazz = Class.forName("android.app.ActivityManagerNative"); + Log.i("amnType", clazz.toString()); + am = clazz.getMethod("getDefault", new Class[0]).invoke(clazz, new Object[0]); + Log.i("amType", am.getClass().toString()); + config = am.getClass().getMethod("getConfiguration", new Class[0]).invoke(am, new Object[0]); + Log.i("configType", config.getClass().toString()); + if (language.equals(context.getResources().getString(R.string.zh))) { + config.getClass().getDeclaredField("locale").set(config, Locale.CHINA); + config.getClass().getDeclaredField("userSetLocale").setBoolean(config, true); + am.getClass().getMethod("updateConfiguration", new Class[]{android.content.res.Configuration.class}).invoke(am, new Object[]{config}); + BackupManager.dataChanged("com.android.providers.settings"); + }else if (language.equals(context.getResources().getString(R.string.en))) { + config.getClass().getDeclaredField("locale").set(config, Locale.ENGLISH); + config.getClass().getDeclaredField("userSetLocale").setBoolean(config, true); + am.getClass().getMethod("updateConfiguration", new Class[]{android.content.res.Configuration.class}).invoke(am, new Object[]{config}); + BackupManager.dataChanged("com.android.providers.settings"); + }else if (language.equals(context.getResources().getString(R.string.th))) { + config.getClass().getDeclaredField("locale").set(config, Locale.forLanguageTag("th")); + config.getClass().getDeclaredField("userSetLocale").setBoolean(config, true); + am.getClass().getMethod("updateConfiguration", new Class[]{android.content.res.Configuration.class}).invoke(am, new Object[]{config}); + BackupManager.dataChanged("com.android.providers.settings"); + }else if (language.equals(context.getResources().getString(R.string.zh_rhk))) { + config.getClass().getDeclaredField("locale").set(config, new Locale("zh", "HK")); + config.getClass().getDeclaredField("userSetLocale").setBoolean(config, true); + am.getClass().getMethod("updateConfiguration", new Class[]{android.content.res.Configuration.class}).invoke(am, new Object[]{config}); + BackupManager.dataChanged("com.android.providers.settings"); + }else if (language.equals(context.getResources().getString(R.string.ja))) { + config.getClass().getDeclaredField("locale").set(config, Locale.JAPANESE); + config.getClass().getDeclaredField("userSetLocale").setBoolean(config, true); + am.getClass().getMethod("updateConfiguration", new Class[]{android.content.res.Configuration.class}).invoke(am, new Object[]{config}); + BackupManager.dataChanged("com.android.providers.settings"); + }else if (language.equals(context.getResources().getString(R.string.de))) { + config.getClass().getDeclaredField("locale").set(config, Locale.GERMANY); + config.getClass().getDeclaredField("userSetLocale").setBoolean(config, true); + am.getClass().getMethod("updateConfiguration", new Class[]{android.content.res.Configuration.class}).invoke(am, new Object[]{config}); + BackupManager.dataChanged("com.android.providers.settings"); + }else if (language.equals(context.getResources().getString(R.string.it))) { + config.getClass().getDeclaredField("locale").set(config, Locale.ITALY); + config.getClass().getDeclaredField("userSetLocale").setBoolean(config, true); + am.getClass().getMethod("updateConfiguration", new Class[]{android.content.res.Configuration.class}).invoke(am, new Object[]{config}); + BackupManager.dataChanged("com.android.providers.settings"); + }else if (language.equals(context.getResources().getString(R.string.fr))) { + config.getClass().getDeclaredField("locale").set(config, Locale.FRANCE); + config.getClass().getDeclaredField("userSetLocale").setBoolean(config, true); + am.getClass().getMethod("updateConfiguration", new Class[]{android.content.res.Configuration.class}).invoke(am, new Object[]{config}); + BackupManager.dataChanged("com.android.providers.settings"); + } + getCurrentLanguage(); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + return false; + } +} diff --git a/app/src/main/java/com/ic/protocols/protocol_jiai.java b/app/src/main/java/com/ic/protocols/protocol_jiai.java index 96d2d43f..243f0565 100644 --- a/app/src/main/java/com/ic/protocols/protocol_jiai.java +++ b/app/src/main/java/com/ic/protocols/protocol_jiai.java @@ -1853,6 +1853,8 @@ public static StringMessage AP50(Runtime ds){ * 设备响应: IWAPLA,080835# * 080835:指令流水号 */ + + ICLogger.i("received BPLA "+cmd); String[] cmdlist=cmd.split(","); if (cmdlist.length == 4){ String cmdindex=cmdlist[2]; @@ -1862,7 +1864,7 @@ public static StringMessage AP50(Runtime ds){ LanguageUtils.changeLanguageByIndex(runtime.getContextProxy().context,msg_index_no); }else{ - ICLogger.i("BP40 format error!"); + ICLogger.i("BPLA format error!"); } }