-
Notifications
You must be signed in to change notification settings - Fork 65
/
LocalManageUtil.java
78 lines (64 loc) · 2.19 KB
/
LocalManageUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.github.jokar.multilanguages.utils;
import android.content.Context;
import android.content.res.Configuration;
import com.github.jokar.multilanguages.R;
import com.github.jokar.multilanguages.library.MultiLanguage;
import java.util.Locale;
public class LocalManageUtil {
private static final String TAG = "LocalManageUtil";
/**
* 获取系统的locale
*
* @return Locale对象
*/
public static Locale getSystemLocale(Context context) {
return SPUtil.getInstance(context).getSystemCurrentLocal();
}
public static String getSelectLanguage(Context context) {
switch (SPUtil.getInstance(context).getSelectLanguage()) {
case 0:
return context.getString(R.string.language_auto);
case 1:
return context.getString(R.string.language_cn);
case 2:
return context.getString(R.string.language_traditional);
case 3:
default:
return context.getString(R.string.language_en);
}
}
/**
* 获取选择的语言设置
*
* @param context
* @return
*/
public static Locale getSetLanguageLocale(Context context) {
switch (SPUtil.getInstance(context).getSelectLanguage()) {
case 0:
return getSystemLocale(context);
case 1:
return Locale.CHINA;
case 2:
return Locale.TAIWAN;
case 3:
default:
return Locale.ENGLISH;
}
}
public static void saveSystemCurrentLanguage(Context context) {
SPUtil.getInstance(context).setSystemCurrentLocal(MultiLanguage.getSystemLocal(context));
}
/**
* 保存系统语言
* @param context
* @param newConfig
*/
public static void saveSystemCurrentLanguage(Context context, Configuration newConfig) {
SPUtil.getInstance(context).setSystemCurrentLocal(MultiLanguage.getSystemLocal(newConfig));
}
public static void saveSelectLanguage(Context context, int select) {
SPUtil.getInstance(context).saveLanguage(select);
MultiLanguage.setApplicationLanguage(context);
}
}