├── .gitignore
├── .idea
├── .name
├── SwitchLanguage.iml
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── misc.xml
├── modules.xml
├── vcs.xml
└── workspace.xml
├── README.md
└── SwitchLanguage
├── .classpath
├── .idea
├── .name
├── SwitchLanguage.iml
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── misc.xml
├── modules.xml
└── workspace.xml
├── .project
├── .settings
├── org.eclipse.core.resources.prefs
└── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── bin
├── AndroidManifest.xml
├── SwitchLanguage.apk
├── classes.dex
├── dexedLibs
│ ├── android-support-v4-73a73a99ed2405b2c392f3e1f50333c1.jar
│ └── android-support-v4-a0baa4d5bf821448353914fecafaea7a.jar
├── jarlist.cache
├── res
│ └── crunch
│ │ ├── drawable-hdpi
│ │ ├── icon_anguage.png
│ │ └── img_label.png
│ │ ├── drawable-mdpi
│ │ └── icon_anguage.png
│ │ ├── drawable-xhdpi
│ │ └── icon_anguage.png
│ │ └── drawable-xxhdpi
│ │ └── icon_anguage.png
└── resources.ap_
├── ic_launcher-web.png
├── libs
└── android-support-v4.jar
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ ├── icon_anguage.png
│ └── img_label.png
├── drawable-mdpi
│ └── icon_anguage.png
├── drawable-xhdpi
│ └── icon_anguage.png
├── drawable-xxhdpi
│ └── icon_anguage.png
├── layout
│ ├── language.xml
│ └── language_item.xml
├── values-en-rUS
│ └── strings.xml
├── values-en
│ └── strings.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
├── values-zh
│ └── strings.xml
└── values
│ ├── color.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── screenshot
└── language.gif
└── src
└── com
└── github
├── changelanguage
├── LanguageActivity.java
└── LanguageInfo.java
└── language
├── adapter
└── LanguageAdapter.java
└── controller
├── LanguageController.java
├── ListViewUtils.java
├── ThreadPoolManager.java
└── UpdateLanguageUtils.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.agdai
2 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | SwitchLanguage
--------------------------------------------------------------------------------
/.idea/SwitchLanguage.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | 1.8
19 |
20 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
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 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 | 1458719726026
195 |
196 | 1458719726026
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SwitchLanguage
2 | 关于我,欢迎关注~
3 | [我的博客](http://blog.csdn.net/u011974987) 本Demo地址:[click here](http://blog.csdn.net/u011974987/article/details/50801770);
4 | * 项目描述:
5 | 本Demo主要运用于切换系统语言的功能,一般会在做出厂设置的App 会有这需求,但是Google并没有开放更改系统语言的接口,查看‘FrameWork’ 层'Settings' 源码下,有相关的功能,属于隐藏接口,所以我们利用反射机制来调用系统的API,虽然不是很靠谱,但是满足了我们的需求,我把项目整理的下,放在[GitHub](https://github.com/git-xuhao/SwitchLanguage) 上面了。
6 |
7 | * 本Demo效果截图示例如下:
8 |
9 | 
10 |
11 | 更新日志:
12 | ---------
13 | * v1.0:
14 | 初始化该项目
15 | 添加了icon。
16 | ###NOTICE!!!
17 | ----------
18 | * 需要注意的是调用此方法:
19 | // objIActMag.updateConfiguration(config);
20 | mtdIActMag$updateConfiguration.invoke(objIActMag, config);
21 |
22 | *需要加上权限:android.permission.CHANGE_CONFIGURATION
23 | 并且此处会重新调用onCreate方法,我就在这个地方处被坑了一把。(如果调用此方法的时候做了一些逻辑,就注意下)。
24 |
25 | 最后声明:
26 | ----------------
27 | 既然是更改系统的配置当然你的签名也应该是系统签名和sharedUserId。不然会类似以下的错误!
28 |
29 | error:
30 | ------
31 | java.lang.SecurityException: Permission Denial: updateConfiguration() from pid=31594, uid=10099 requires android.permission.CHANGE_CONFIGURATION
32 |
33 | 各位都注意下吧~
34 |
35 | ##Thanks!
36 |
37 | *[SwitchLanguage](https://github.com/git-xuhao/SwitchLanguage)
38 |
--------------------------------------------------------------------------------
/SwitchLanguage/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/SwitchLanguage/.idea/.name:
--------------------------------------------------------------------------------
1 | SwitchLanguage
--------------------------------------------------------------------------------
/SwitchLanguage/.idea/SwitchLanguage.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SwitchLanguage/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/SwitchLanguage/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/SwitchLanguage/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/SwitchLanguage/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/SwitchLanguage/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/SwitchLanguage/.idea/workspace.xml:
--------------------------------------------------------------------------------
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 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 | 1458719335537
319 |
320 | 1458719335537
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
--------------------------------------------------------------------------------
/SwitchLanguage/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | SwitchLanguage
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/SwitchLanguage/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=UTF-8
3 |
--------------------------------------------------------------------------------
/SwitchLanguage/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/SwitchLanguage/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
18 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/SwitchLanguage/bin/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
18 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/SwitchLanguage/bin/SwitchLanguage.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/bin/SwitchLanguage.apk
--------------------------------------------------------------------------------
/SwitchLanguage/bin/classes.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/bin/classes.dex
--------------------------------------------------------------------------------
/SwitchLanguage/bin/dexedLibs/android-support-v4-73a73a99ed2405b2c392f3e1f50333c1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/bin/dexedLibs/android-support-v4-73a73a99ed2405b2c392f3e1f50333c1.jar
--------------------------------------------------------------------------------
/SwitchLanguage/bin/dexedLibs/android-support-v4-a0baa4d5bf821448353914fecafaea7a.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/bin/dexedLibs/android-support-v4-a0baa4d5bf821448353914fecafaea7a.jar
--------------------------------------------------------------------------------
/SwitchLanguage/bin/jarlist.cache:
--------------------------------------------------------------------------------
1 | # cache for current jar dependency. DO NOT EDIT.
2 | # format is
3 | # Encoding is UTF-8
4 |
--------------------------------------------------------------------------------
/SwitchLanguage/bin/res/crunch/drawable-hdpi/icon_anguage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/bin/res/crunch/drawable-hdpi/icon_anguage.png
--------------------------------------------------------------------------------
/SwitchLanguage/bin/res/crunch/drawable-hdpi/img_label.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/bin/res/crunch/drawable-hdpi/img_label.png
--------------------------------------------------------------------------------
/SwitchLanguage/bin/res/crunch/drawable-mdpi/icon_anguage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/bin/res/crunch/drawable-mdpi/icon_anguage.png
--------------------------------------------------------------------------------
/SwitchLanguage/bin/res/crunch/drawable-xhdpi/icon_anguage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/bin/res/crunch/drawable-xhdpi/icon_anguage.png
--------------------------------------------------------------------------------
/SwitchLanguage/bin/res/crunch/drawable-xxhdpi/icon_anguage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/bin/res/crunch/drawable-xxhdpi/icon_anguage.png
--------------------------------------------------------------------------------
/SwitchLanguage/bin/resources.ap_:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/bin/resources.ap_
--------------------------------------------------------------------------------
/SwitchLanguage/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/ic_launcher-web.png
--------------------------------------------------------------------------------
/SwitchLanguage/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/SwitchLanguage/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/SwitchLanguage/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-21
15 |
--------------------------------------------------------------------------------
/SwitchLanguage/res/drawable-hdpi/icon_anguage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/res/drawable-hdpi/icon_anguage.png
--------------------------------------------------------------------------------
/SwitchLanguage/res/drawable-hdpi/img_label.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/res/drawable-hdpi/img_label.png
--------------------------------------------------------------------------------
/SwitchLanguage/res/drawable-mdpi/icon_anguage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/res/drawable-mdpi/icon_anguage.png
--------------------------------------------------------------------------------
/SwitchLanguage/res/drawable-xhdpi/icon_anguage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/res/drawable-xhdpi/icon_anguage.png
--------------------------------------------------------------------------------
/SwitchLanguage/res/drawable-xxhdpi/icon_anguage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/res/drawable-xxhdpi/icon_anguage.png
--------------------------------------------------------------------------------
/SwitchLanguage/res/layout/language.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
16 |
17 |
27 |
28 |
36 |
37 |
41 |
42 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/SwitchLanguage/res/layout/language_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
11 |
12 |
17 |
18 |
25 |
26 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/SwitchLanguage/res/values-en-rUS/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Please select your language system
6 |
7 | next
8 |
9 |
10 |
--------------------------------------------------------------------------------
/SwitchLanguage/res/values-en/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | SwitchLanguageDemo
5 | Hello buddy!Welcome to Android\'s skill share
6 | Switch Language
7 | English
8 | Chinese
9 | Jump to Next Activity
10 |
11 |
--------------------------------------------------------------------------------
/SwitchLanguage/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/SwitchLanguage/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/SwitchLanguage/res/values-zh/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 切换语言demo
5 | 你好,少年!欢迎收听android干货分享
6 | 切换语言
7 | 英语
8 | 中文
9 | 跳转到另一个页面
10 |
11 |
--------------------------------------------------------------------------------
/SwitchLanguage/res/values/color.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #ff7200
5 |
6 | #ffffff
7 |
8 | #000000
9 |
10 | #5e5e5e
11 |
12 | #664d5a6b
13 |
14 |
15 |
16 | #EEEEEE
17 |
18 | #E8E8E8
19 |
20 | #CECECE
21 |
22 | #E5E5E5
23 |
24 |
25 | #FF3C00
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/SwitchLanguage/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/SwitchLanguage/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | SwitchSystemLanguage
5 |
6 | 下一步
7 | 请选择您的系统语言
8 |
9 |
--------------------------------------------------------------------------------
/SwitchLanguage/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/SwitchLanguage/screenshot/language.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/git-xuhao/SwitchLanguage/5dd4630fa6b050fe0b1672ca73e513d3c0e6b043/SwitchLanguage/screenshot/language.gif
--------------------------------------------------------------------------------
/SwitchLanguage/src/com/github/changelanguage/LanguageActivity.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @Title: LanguageActivity.java
3 | * @author: Xiho
4 | * @data: 2016年2月29日 上午11:17:17 <创建时间>
5 | *
6 | * @history:<以下是历史记录>
7 | *
8 | * @modifier: <修改人>
9 | * @modify date: 2016年2月29日 上午11:17:17 <修改时间>
10 | * @log: <修改内容>
11 | *
12 | * @modifier: <修改人>
13 | * @modify date: 2016年2月29日 上午11:17:17 <修改时间>
14 | * @log: <修改内容>
15 | */
16 | package com.github.changelanguage;
17 |
18 | import java.util.List;
19 | import java.util.Locale;
20 |
21 | import com.example.switchlanguage.R;
22 | import com.github.language.adapter.LanguageAdapter;
23 | import com.github.language.controller.LanguageController;
24 |
25 | import android.app.Activity;
26 | import android.os.Bundle;
27 | import android.util.Log;
28 | import android.view.View;
29 | import android.view.Window;
30 | import android.view.View.OnClickListener;
31 | import android.widget.AdapterView;
32 | import android.widget.AdapterView.OnItemClickListener;
33 | import android.widget.Button;
34 | import android.widget.ListView;
35 |
36 | /**
37 | * TODO 选择多国语言
38 | * @author Xiho
39 | * @versionCode 1 <每次修改提交前+1>
40 | */
41 | public class LanguageActivity extends Activity {
42 | public static final String TAG="LanguageActivity";
43 | private ListView mListView;
44 | private Button mNextStep;
45 | private LanguageAdapter mLanguageAdapter;
46 | private List mListLanguageInfo;
47 | private LanguageController mLanguageController;
48 |
49 |
50 | @Override
51 | public void onCreate(Bundle savedInstanceState) {
52 | super.onCreate(savedInstanceState);
53 | requestWindowFeature(Window.FEATURE_NO_TITLE);
54 | setContentView(R.layout.language);
55 | Log.d(TAG,"---onCreate()");
56 | mLanguageController = LanguageController.getInstance(getApplicationContext());
57 | //初始化列表数据
58 | mListLanguageInfo = mLanguageController.getListData();
59 |
60 | }
61 |
62 | /**
63 | * 初始化View
64 | */
65 | private void initView() {
66 | mListView = (ListView) findViewById(R.id.language_listview);
67 | mNextStep = (Button) findViewById(R.id.next);
68 | mNextStep.setText(getResources().getString(R.string.button_next_step));
69 | mLanguageAdapter = new LanguageAdapter(getApplicationContext(), mListLanguageInfo);
70 | // mListView.setLayoutAnimation(ListViewUtils.setListAnim());
71 | mListView.setAdapter(mLanguageAdapter);
72 | mListView.setOnItemClickListener(new OnItemClickListener() {
73 | @Override
74 | public void onItemClick(AdapterView> parent, View view,
75 | final int position, long id) {
76 |
77 | LanguageInfo mInfo = mListLanguageInfo.get(position);
78 | //更改系统语言
79 | mLanguageController.updateLanguage(mInfo);
80 | }
81 | });
82 |
83 | mNextStep.setOnClickListener(new OnClickListener() {
84 | @Override
85 | public void onClick(View v) {
86 | }
87 | });
88 | }
89 |
90 | /**
91 | * 初始化本地语言
92 | */
93 | private void initLanguage() {
94 | Locale currentLocale = mLanguageController.getCurrentLocale(getApplicationContext());
95 | for (int i = 0; i < mListLanguageInfo.size(); i++) {
96 | Locale temp = mListLanguageInfo.get(i).getLocale();
97 | if(temp.equals(currentLocale)){
98 | //标记当前item
99 | mLanguageAdapter.setSelectItem(i);
100 | }
101 | }
102 | }
103 |
104 | @Override
105 | public void onResume() {
106 | super.onResume();
107 | //初始化View
108 | initView();
109 | //初始化本地语言
110 | initLanguage();
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/SwitchLanguage/src/com/github/changelanguage/LanguageInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.changelanguage;
2 |
3 | import java.io.Serializable;
4 | import java.util.Locale;
5 |
6 | /**
7 | * Created by Xiho on 2016/2/17.
8 | */
9 | public class LanguageInfo implements Serializable {
10 | /**
11 | *
12 | */
13 | private static final long serialVersionUID = -4295651469724630055L;
14 | private String language; //語言類型
15 | private Locale locale; // 语言
16 | /**
17 | * @return the language
18 | */
19 | public String getLanguage() {
20 | return language;
21 | }
22 | /**
23 | * @param language the language to set
24 | */
25 | public void setLanguage(String language) {
26 | this.language = language;
27 | }
28 | /**
29 | * @return the locale
30 | */
31 | public Locale getLocale() {
32 | return locale;
33 | }
34 | /**
35 | * @param locale the locale to set
36 | */
37 | public void setLocale(Locale locale) {
38 | this.locale = locale;
39 | }
40 |
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/SwitchLanguage/src/com/github/language/adapter/LanguageAdapter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @Title: LanguageAdapter.java
3 | * @author: Xiho
4 | * @data: 2016年3月1日 下午4:56:52 <创建时间>
5 | *
6 | * @history:<以下是历史记录>
7 | *
8 | * @modifier: <修改人>
9 | * @modify date: 2016年3月1日 下午4:56:52 <修改时间>
10 | * @log: <修改内容>
11 | *
12 | * @modifier: <修改人>
13 | * @modify date: 2016年3月1日 下午4:56:52 <修改时间>
14 | * @log: <修改内容>
15 | */
16 | package com.github.language.adapter;
17 |
18 | import java.util.List;
19 |
20 |
21 |
22 |
23 |
24 |
25 | import com.example.switchlanguage.R;
26 | import com.github.changelanguage.LanguageInfo;
27 |
28 | import android.content.Context;
29 | import android.view.LayoutInflater;
30 | import android.view.View;
31 | import android.view.ViewGroup;
32 | import android.widget.BaseAdapter;
33 | import android.widget.ImageView;
34 | import android.widget.RelativeLayout;
35 | import android.widget.TextView;
36 |
37 | /**
38 | * TODO<请描述这个类是干什么的>
39 | *
40 | * @author Xiho
41 | * @versionCode 1 <每次修改提交前+1>
42 | */
43 | public class LanguageAdapter extends BaseAdapter {
44 |
45 | private Context mContext;
46 |
47 | private List mListLanguageInfo;
48 |
49 | private int selectItem=-1;
50 | /**
51 | * @param mContext
52 | * @param mListLanguageInfo
53 | */
54 | public LanguageAdapter(Context mContext,
55 | List mListLanguageInfo) {
56 | super();
57 | this.mContext = mContext;
58 | this.mListLanguageInfo = mListLanguageInfo;
59 | }
60 |
61 | public void setSelectItem(int selectItem) {
62 | this.selectItem = selectItem;
63 | }
64 | @Override
65 | public int getCount() {
66 | return mListLanguageInfo.size();
67 | }
68 |
69 | @Override
70 | public Object getItem(int position) {
71 | return null;
72 | }
73 |
74 | @Override
75 | public long getItemId(int position) {
76 | return 0;
77 | }
78 |
79 | @Override
80 | public View getView(final int position, View convertView, ViewGroup parent) {
81 | final LanguageInfo mLanguageInfo = mListLanguageInfo.get(position);
82 | ViewHolder viewHolder=null;
83 | if (convertView == null) {
84 | viewHolder = new ViewHolder();
85 | convertView = LayoutInflater.from(mContext).inflate(
86 | R.layout.language_item, null);
87 | viewHolder.mImageView = (ImageView) convertView
88 | .findViewById(R.id.img_label);
89 | viewHolder.mLanguage = (TextView) convertView
90 | .findViewById(R.id.txt_language);
91 | viewHolder.mView = (RelativeLayout) convertView.findViewById(R.id.item_lv);
92 | viewHolder.mView.setTag(viewHolder);
93 | convertView.setTag(viewHolder);
94 | } else {
95 | viewHolder = (ViewHolder) convertView.getTag();
96 | }
97 | viewHolder.mLanguage.setText(mLanguageInfo.getLanguage());
98 | //当前选中项
99 | if (position == selectItem) {
100 | viewHolder.mImageView.setVisibility(View.VISIBLE);
101 | viewHolder.mLanguage.setTextColor(mContext.getResources().getColor(
102 | R.color.font_orange));
103 | } else {
104 | viewHolder.mImageView.setVisibility(View.INVISIBLE);
105 | viewHolder.mLanguage.setTextColor(mContext.getResources().getColor(
106 | R.color.black));
107 | }
108 | return convertView;
109 | }
110 |
111 | class ViewHolder {
112 | ImageView mImageView;
113 | TextView mLanguage;
114 | RelativeLayout mView;
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/SwitchLanguage/src/com/github/language/controller/LanguageController.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @Title: LanguageController.java
3 | * @author: Xiho
4 | * @data: 2016年3月2日 下午3:56:56 <创建时间>
5 | *
6 | * @history:<以下是历史记录>
7 | *
8 | * @modifier: <修改人>
9 | * @modify date: 2016年3月2日 下午3:56:56 <修改时间>
10 | * @log: <修改内容>
11 | *
12 | * @modifier: <修改人>
13 | * @modify date: 2016年3月2日 下午3:56:56 <修改时间>
14 | * @log: <修改内容>
15 | */
16 | package com.github.language.controller;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 | import java.util.Locale;
21 |
22 |
23 |
24 | import com.github.changelanguage.LanguageInfo;
25 |
26 | import android.content.Context;
27 |
28 |
29 |
30 | /**
31 | * TODO 多国语言的控制器
32 | * @author Xiho
33 | * @versionCode 1 <每次修改提交前+1>
34 | */
35 | public class LanguageController {
36 |
37 | private static LanguageController instance;// 单列模式
38 | private Context mContext;
39 |
40 | /**
41 | * @param applicationContext
42 | */
43 | public LanguageController(Context mContext) {
44 | this.mContext = mContext;
45 | }
46 |
47 | /**
48 | * 单列模式
49 | *
50 | * @param Context
51 | * @return UpdateController mUpdateController
52 | */
53 | public static LanguageController getInstance(Context mContext) {
54 | if (instance == null) {
55 | instance = new LanguageController(mContext.getApplicationContext());
56 | }
57 | return instance;
58 | }
59 |
60 |
61 |
62 | /**
63 | * 初始化列表数据
64 | */
65 | public List getListData() {
66 | List mListLanguageInfo = new ArrayList();
67 | LanguageInfo mLanguageInfo1 = new LanguageInfo();
68 | LanguageInfo mLanguageInfo2 = new LanguageInfo();
69 | LanguageInfo mLanguageInfo3 = new LanguageInfo();
70 | LanguageInfo mLanguageInfo4 = new LanguageInfo();
71 | LanguageInfo mLanguageInfo5 = new LanguageInfo();
72 | mLanguageInfo1.setLanguage("中文(简体)");
73 | mLanguageInfo1.setLocale(Locale.SIMPLIFIED_CHINESE);
74 | mLanguageInfo2.setLanguage("中文(繁體)");
75 | mLanguageInfo2.setLocale(Locale.TRADITIONAL_CHINESE);
76 | mLanguageInfo3.setLanguage("English");
77 | mLanguageInfo3.setLocale(Locale.US);
78 | mLanguageInfo4.setLanguage("한국어");
79 | mLanguageInfo4.setLocale(Locale.KOREA);
80 | mLanguageInfo5.setLanguage("日本語");
81 | mLanguageInfo5.setLocale(Locale.JAPAN);
82 | mListLanguageInfo.add(mLanguageInfo1);
83 | mListLanguageInfo.add(mLanguageInfo2);
84 | mListLanguageInfo.add(mLanguageInfo3);
85 | mListLanguageInfo.add(mLanguageInfo4);
86 | mListLanguageInfo.add(mLanguageInfo5);
87 | return mListLanguageInfo;
88 | }
89 |
90 | /**
91 | * 更换语言
92 | * @param info
93 | */
94 | public void updateLanguage(final LanguageInfo info){
95 | ThreadPoolManager.getInstance().executeTask(new Runnable() {
96 | @Override
97 | public void run() {
98 | // 更改系统语言
99 | UpdateLanguageUtils.updateLanguage(info.getLocale());
100 | }
101 | });
102 |
103 | }
104 |
105 | /**
106 | * 获取当前系统语言
107 | * @param mContext
108 | * @return
109 | */
110 | public Locale getCurrentLocale(Context mContext){
111 | Locale locale = mContext.getResources().getConfiguration().locale;
112 | return locale;
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/SwitchLanguage/src/com/github/language/controller/ListViewUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.language.controller;
2 |
3 | import java.util.List;
4 |
5 | import android.annotation.SuppressLint;
6 | import android.content.ComponentName;
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.content.pm.PackageManager;
10 | import android.content.pm.ResolveInfo;
11 | import android.provider.Settings;
12 | import android.view.animation.AlphaAnimation;
13 | import android.view.animation.Animation;
14 | import android.view.animation.AnimationSet;
15 | import android.view.animation.LayoutAnimationController;
16 | import android.view.animation.TranslateAnimation;
17 |
18 | public class ListViewUtils {
19 |
20 |
21 | /**
22 | * listview加载的效果
23 | *
24 | */
25 | public static LayoutAnimationController setListAnim() {
26 | AnimationSet set = new AnimationSet(true);
27 | Animation animation = new AlphaAnimation(0.0f, 1.0f);
28 | animation.setDuration(300);
29 | set.addAnimation(animation);
30 | animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
31 | Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
32 | -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
33 | animation.setDuration(500);
34 | set.addAnimation(animation);
35 | LayoutAnimationController controller = new LayoutAnimationController(
36 | set, 0.5f);
37 | return controller;
38 | }
39 |
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/SwitchLanguage/src/com/github/language/controller/ThreadPoolManager.java:
--------------------------------------------------------------------------------
1 | package com.github.language.controller;
2 |
3 | import java.util.concurrent.ExecutorService;
4 | import java.util.concurrent.Executors;
5 |
6 | /**
7 | * 线程池管理工具类
8 | */
9 | public class ThreadPoolManager {
10 |
11 | private ExecutorService service;
12 |
13 | @SuppressWarnings("unused")
14 | private ThreadPoolManager() {
15 | int num = Runtime.getRuntime().availableProcessors();
16 | //service = Executors.newFixedThreadPool(num * 3);
17 | service = Executors.newCachedThreadPool();
18 | }
19 |
20 | private static final ThreadPoolManager manager = new ThreadPoolManager();
21 |
22 | public static ThreadPoolManager getInstance() {
23 | return manager;
24 | }
25 |
26 | public void executeTask(Runnable runnable) {
27 | service.execute(runnable);
28 | }
29 |
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/SwitchLanguage/src/com/github/language/controller/UpdateLanguageUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @Title: UpdateLanguageUtils.java
3 | * @author: Xiho
4 | * @data: 2016年3月1日 下午7:09:45 <创建时间>
5 | *
6 | * @history:<以下是历史记录>
7 | *
8 | * @modifier: <修改人>
9 | * @modify date: 2016年3月1日 下午7:09:45 <修改时间>
10 | * @log: <修改内容>
11 | *
12 | * @modifier: <修改人>
13 | * @modify date: 2016年3月1日 下午7:09:45 <修改时间>
14 | * @log: <修改内容>
15 | */
16 | package com.github.language.controller;
17 |
18 | import java.lang.reflect.Method;
19 | import java.util.Locale;
20 |
21 | import android.content.res.Configuration;
22 |
23 | /**
24 | * TODO<请描述这个类是干什么的>
25 | *
26 | * @author Xiho
27 | * @versionCode 1 <每次修改提交前+1>
28 | */
29 | @SuppressWarnings("unchecked")
30 | public class UpdateLanguageUtils {
31 |
32 |
33 | public static void updateLanguage(Locale locale) {
34 | try {
35 | Object objIActMag, objActMagNative;
36 |
37 | Class clzIActMag = Class.forName("android.app.IActivityManager");
38 |
39 | Class clzActMagNative = Class
40 | .forName("android.app.ActivityManagerNative");
41 |
42 | Method mtdActMagNative$getDefault = clzActMagNative
43 | .getDeclaredMethod("getDefault");
44 |
45 | objIActMag = mtdActMagNative$getDefault.invoke(clzActMagNative);
46 |
47 | Method mtdIActMag$getConfiguration = clzIActMag
48 | .getDeclaredMethod("getConfiguration");
49 |
50 | Configuration config = (Configuration) mtdIActMag$getConfiguration
51 | .invoke(objIActMag);
52 |
53 | config.locale = locale;
54 |
55 | Class clzConfig = Class
56 | .forName("android.content.res.Configuration");
57 | java.lang.reflect.Field userSetLocale = clzConfig
58 | .getField("userSetLocale");
59 | userSetLocale.set(config, true);
60 |
61 | // 此处需要声明权限:android.permission.CHANGE_CONFIGURATION
62 | // 会重新调用 onCreate();
63 | Class[] clzParams = { Configuration.class };
64 |
65 | Method mtdIActMag$updateConfiguration = clzIActMag
66 | .getDeclaredMethod("updateConfiguration", clzParams);
67 |
68 | mtdIActMag$updateConfiguration.invoke(objIActMag, config);
69 |
70 | // BackupManager.dataChanged("com.android.providers.settings");
71 | } catch (Exception e) {
72 | e.printStackTrace();
73 | }
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------