You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.7 KiB
51 lines
1.7 KiB
5 years ago
|
package com.community.pocket.util;
|
||
|
|
||
|
import android.app.Application;
|
||
|
import android.content.Context;
|
||
|
import android.content.res.Configuration;
|
||
|
|
||
|
import com.github.jokar.multilanguages.library.LanguageLocalListener;
|
||
|
import com.github.jokar.multilanguages.library.MultiLanguage;
|
||
|
|
||
|
import org.jetbrains.annotations.NotNull;
|
||
|
import org.xutils.x;
|
||
|
|
||
|
import java.util.Locale;
|
||
|
|
||
|
/**
|
||
|
* 应用启动初始化
|
||
|
*/
|
||
|
public class InitApp extends Application {
|
||
|
@Override
|
||
|
public void onCreate() {
|
||
|
super.onCreate();
|
||
|
//框架初始化
|
||
|
x.Ext.init(this);
|
||
|
|
||
|
MultiLanguage.init(new LanguageLocalListener() {
|
||
|
@Override
|
||
|
public Locale getSetLanguageLocale(Context context) {
|
||
|
//返回自己本地保存选择的语言设置
|
||
|
return LocalManageUtil.getSetLanguageLocale(context);
|
||
|
}
|
||
|
});
|
||
|
MultiLanguage.setApplicationLanguage(this);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected void attachBaseContext(Context base) {
|
||
|
//第一次进入app时保存系统选择语言(为了选择随系统语言时使用,如果不保存,切换语言后就拿不到了)
|
||
|
LocalManageUtil.saveSystemCurrentLanguage(base);
|
||
|
super.attachBaseContext(MultiLanguage.setLocal(base));
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onConfigurationChanged(@NotNull Configuration newConfig) {
|
||
|
super.onConfigurationChanged(newConfig);
|
||
|
//用户在系统设置页面切换语言时保存系统选择语言(为了选择随系统语言时使用,如果不保存,切换语言后就拿不到了)
|
||
|
LocalManageUtil.saveSystemCurrentLanguage(getApplicationContext(), newConfig);
|
||
|
MultiLanguage.onConfigurationChanged(getApplicationContext());
|
||
|
}
|
||
|
|
||
|
}
|