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.
57 lines
1.3 KiB
57 lines
1.3 KiB
5 years ago
|
package com.community.pocket.util;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.content.SharedPreferences;
|
||
|
|
||
|
import java.util.Locale;
|
||
|
|
||
|
/**
|
||
|
* 界面语言配置读写
|
||
|
*/
|
||
|
public class SPUtil {
|
||
|
|
||
|
private final String SP_NAME = "language_setting";
|
||
|
private final String TAG_LANGUAGE = "language_select";
|
||
|
private static volatile SPUtil instance;
|
||
|
|
||
|
private final SharedPreferences mSharedPreferences;
|
||
|
|
||
|
private Locale systemCurrentLocal = Locale.ENGLISH;
|
||
|
|
||
|
|
||
|
private SPUtil(Context context) {
|
||
|
mSharedPreferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
|
||
|
}
|
||
|
|
||
|
|
||
|
void saveLanguage(int select) {
|
||
|
SharedPreferences.Editor edit = mSharedPreferences.edit();
|
||
|
edit.putInt(TAG_LANGUAGE, select);
|
||
|
edit.apply();
|
||
|
}
|
||
|
|
||
|
public int getSelectLanguage() {
|
||
|
return mSharedPreferences.getInt(TAG_LANGUAGE, 0);
|
||
|
}
|
||
|
|
||
|
|
||
|
Locale getSystemCurrentLocal() {
|
||
|
return systemCurrentLocal;
|
||
|
}
|
||
|
|
||
|
void setSystemCurrentLocal(Locale local) {
|
||
|
systemCurrentLocal = local;
|
||
|
}
|
||
|
|
||
|
public static SPUtil getInstance(Context context) {
|
||
|
if (instance == null) {
|
||
|
synchronized (SPUtil.class) {
|
||
|
if (instance == null) {
|
||
|
instance = new SPUtil(context);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return instance;
|
||
|
}
|
||
|
}
|