Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
bce9cfa3
Commit
bce9cfa3
authored
Dec 13, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update LocaleManager
parent
ff3d66a6
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
16 deletions
+60
-16
SplashActivity.java
app/src/full/java/com/topjohnwu/magisk/SplashActivity.java
+3
-3
BaseActivity.java
...ll/java/com/topjohnwu/magisk/components/BaseActivity.java
+1
-2
build.gradle
core/build.gradle
+1
-1
App.java
core/src/main/java/com/topjohnwu/core/App.java
+12
-0
LocaleManager.java
...src/main/java/com/topjohnwu/core/utils/LocaleManager.java
+43
-10
No files found.
app/src/full/java/com/topjohnwu/magisk/SplashActivity.java
View file @
bce9cfa3
...
@@ -24,6 +24,9 @@ public class SplashActivity extends BaseActivity {
...
@@ -24,6 +24,9 @@ public class SplashActivity extends BaseActivity {
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
// Dynamic detect all locales
LocaleManager
.
loadAvailableLocales
(
R
.
string
.
app_changelog
);
String
pkg
=
app
.
mDB
.
getStrings
(
Const
.
Key
.
SU_MANAGER
,
null
);
String
pkg
=
app
.
mDB
.
getStrings
(
Const
.
Key
.
SU_MANAGER
,
null
);
if
(
pkg
!=
null
&&
getPackageName
().
equals
(
BuildConfig
.
APPLICATION_ID
))
{
if
(
pkg
!=
null
&&
getPackageName
().
equals
(
BuildConfig
.
APPLICATION_ID
))
{
app
.
mDB
.
setStrings
(
Const
.
Key
.
SU_MANAGER
,
null
);
app
.
mDB
.
setStrings
(
Const
.
Key
.
SU_MANAGER
,
null
);
...
@@ -47,9 +50,6 @@ public class SplashActivity extends BaseActivity {
...
@@ -47,9 +50,6 @@ public class SplashActivity extends BaseActivity {
Data
.
importPrefs
();
Data
.
importPrefs
();
// Dynamic detect all locales
LocaleManager
.
loadAvailableLocales
(
R
.
string
.
download_file_error
);
// Create notification channel on Android O
// Create notification channel on Android O
Notifications
.
setup
(
this
);
Notifications
.
setup
(
this
);
...
...
app/src/full/java/com/topjohnwu/magisk/components/BaseActivity.java
View file @
bce9cfa3
...
@@ -31,7 +31,7 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Au
...
@@ -31,7 +31,7 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Au
static
int
[]
EMPTY_INT_ARRAY
=
new
int
[
0
];
static
int
[]
EMPTY_INT_ARRAY
=
new
int
[
0
];
private
ActivityResultListener
activityResultListener
;
private
ActivityResultListener
activityResultListener
;
public
App
app
;
public
App
app
=
App
.
self
;
@Override
@Override
public
int
[]
getSubscribedTopics
()
{
public
int
[]
getSubscribedTopics
()
{
...
@@ -49,7 +49,6 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Au
...
@@ -49,7 +49,6 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Au
Configuration
config
=
base
.
getResources
().
getConfiguration
();
Configuration
config
=
base
.
getResources
().
getConfiguration
();
config
.
setLocale
(
LocaleManager
.
locale
);
config
.
setLocale
(
LocaleManager
.
locale
);
applyOverrideConfiguration
(
config
);
applyOverrideConfiguration
(
config
);
app
=
App
.
self
;
}
}
@Override
@Override
...
...
core/build.gradle
View file @
bce9cfa3
...
@@ -5,7 +5,7 @@ android {
...
@@ -5,7 +5,7 @@ android {
buildToolsVersion
rootProject
.
ext
.
buildToolsVersion
buildToolsVersion
rootProject
.
ext
.
buildToolsVersion
defaultConfig
{
defaultConfig
{
minSdkVersion
1
6
minSdkVersion
1
7
targetSdkVersion
rootProject
.
ext
.
compileSdkVersion
targetSdkVersion
rootProject
.
ext
.
compileSdkVersion
versionCode
1
versionCode
1
versionName
"1.0"
versionName
"1.0"
...
...
core/src/main/java/com/topjohnwu/core/App.java
View file @
bce9cfa3
...
@@ -2,6 +2,7 @@ package com.topjohnwu.core;
...
@@ -2,6 +2,7 @@ package com.topjohnwu.core;
import
android.content.SharedPreferences
;
import
android.content.SharedPreferences
;
import
android.content.res.Configuration
;
import
android.content.res.Configuration
;
import
android.content.res.Resources
;
import
android.os.Handler
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.os.Looper
;
import
android.preference.PreferenceManager
;
import
android.preference.PreferenceManager
;
...
@@ -24,6 +25,8 @@ public class App extends ContainerApp {
...
@@ -24,6 +25,8 @@ public class App extends ContainerApp {
public
MagiskDB
mDB
;
public
MagiskDB
mDB
;
public
RepoDatabaseHelper
repoDB
;
public
RepoDatabaseHelper
repoDB
;
private
Resources
mResource
;
public
App
()
{
public
App
()
{
self
=
this
;
self
=
this
;
}
}
...
@@ -45,6 +48,15 @@ public class App extends ContainerApp {
...
@@ -45,6 +48,15 @@ public class App extends ContainerApp {
Data
.
loadConfig
();
Data
.
loadConfig
();
}
}
@Override
public
Resources
getResources
()
{
return
mResource
;
}
public
void
setResources
(
Resources
res
)
{
mResource
=
res
;
}
@Override
@Override
public
void
onConfigurationChanged
(
Configuration
newConfig
)
{
public
void
onConfigurationChanged
(
Configuration
newConfig
)
{
super
.
onConfigurationChanged
(
newConfig
);
super
.
onConfigurationChanged
(
newConfig
);
...
...
core/src/main/java/com/topjohnwu/core/utils/LocaleManager.java
View file @
bce9cfa3
package
com
.
topjohnwu
.
core
.
utils
;
package
com
.
topjohnwu
.
core
.
utils
;
import
android.content.Context
;
import
android.content.res.Configuration
;
import
android.content.res.Configuration
;
import
android.content.res.Resources
;
import
android.content.res.Resources
;
import
android.os.
AsyncTask
;
import
android.os.
Build
;
import
com.topjohnwu.core.App
;
import
com.topjohnwu.core.App
;
import
com.topjohnwu.core.Const
;
import
com.topjohnwu.core.Const
;
import
com.topjohnwu.superuser.Shell
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
...
@@ -20,28 +22,59 @@ public class LocaleManager {
...
@@ -20,28 +22,59 @@ public class LocaleManager {
public
final
static
Locale
defaultLocale
=
Locale
.
getDefault
();
public
final
static
Locale
defaultLocale
=
Locale
.
getDefault
();
public
static
List
<
Locale
>
locales
;
public
static
List
<
Locale
>
locales
;
public
static
Locale
forLanguageTag
(
String
tag
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
21
)
{
return
Locale
.
forLanguageTag
(
tag
);
}
else
{
String
[]
tok
=
tag
.
split
(
"-"
);
if
(
tok
.
length
==
0
)
{
return
new
Locale
(
""
);
}
String
language
;
switch
(
tok
[
0
])
{
case
"und"
:
language
=
""
;
// Undefined
break
;
case
"fil"
:
language
=
"tl"
;
// Filipino
break
;
default
:
language
=
tok
[
0
];
}
if
((
language
.
length
()
!=
2
&&
language
.
length
()
!=
3
))
return
new
Locale
(
""
);
if
(
tok
.
length
==
1
)
return
new
Locale
(
language
);
String
country
=
tok
[
1
];
if
(
country
.
length
()
!=
2
&&
country
.
length
()
!=
3
)
return
new
Locale
(
language
);
return
new
Locale
(
language
,
country
);
}
}
public
static
void
setLocale
(
App
app
)
{
public
static
void
setLocale
(
App
app
)
{
String
localeConfig
=
app
.
prefs
.
getString
(
Const
.
Key
.
LOCALE
,
""
);
String
localeConfig
=
app
.
prefs
.
getString
(
Const
.
Key
.
LOCALE
,
""
);
if
(
localeConfig
.
isEmpty
())
{
if
(
localeConfig
.
isEmpty
())
{
locale
=
defaultLocale
;
locale
=
defaultLocale
;
}
else
{
}
else
{
locale
=
Locale
.
forLanguageTag
(
localeConfig
);
locale
=
forLanguageTag
(
localeConfig
);
}
}
Locale
.
setDefault
(
locale
);
Locale
.
setDefault
(
locale
);
Resources
res
=
app
.
getResources
();
app
.
setResources
(
getLocaleContext
(
locale
).
getResources
());
Configuration
config
=
res
.
getConfiguration
();
}
public
static
Context
getLocaleContext
(
Locale
locale
)
{
Configuration
config
=
new
Configuration
(
App
.
self
.
getBaseContext
().
getResources
().
getConfiguration
());
config
.
setLocale
(
locale
);
config
.
setLocale
(
locale
);
re
s
.
updateConfiguration
(
config
,
res
.
getDisplayMetrics
()
);
re
turn
App
.
self
.
createConfigurationContext
(
config
);
}
}
public
static
String
getString
(
Locale
locale
,
@StringRes
int
id
)
{
public
static
String
getString
(
Locale
locale
,
@StringRes
int
id
)
{
Configuration
config
=
new
Configuration
();
return
getLocaleContext
(
locale
).
getString
(
id
);
config
.
setLocale
(
locale
);
return
App
.
self
.
createConfigurationContext
(
config
).
getString
(
id
);
}
}
public
static
void
loadAvailableLocales
(
@StringRes
int
compareId
)
{
public
static
void
loadAvailableLocales
(
@StringRes
int
compareId
)
{
AsyncTask
.
THREAD_POOL_
EXECUTOR
.
execute
(()
->
{
Shell
.
EXECUTOR
.
execute
(()
->
{
locales
=
new
ArrayList
<>();
locales
=
new
ArrayList
<>();
HashSet
<
String
>
set
=
new
HashSet
<>();
HashSet
<
String
>
set
=
new
HashSet
<>();
Resources
res
=
App
.
self
.
getResources
();
Resources
res
=
App
.
self
.
getResources
();
...
@@ -60,7 +93,7 @@ public class LocaleManager {
...
@@ -60,7 +93,7 @@ public class LocaleManager {
// Other locales
// Other locales
for
(
String
s
:
res
.
getAssets
().
getLocales
())
{
for
(
String
s
:
res
.
getAssets
().
getLocales
())
{
locale
=
Locale
.
forLanguageTag
(
s
);
locale
=
forLanguageTag
(
s
);
if
(
set
.
add
(
getString
(
locale
,
compareId
)))
{
if
(
set
.
add
(
getString
(
locale
,
compareId
)))
{
locales
.
add
(
locale
);
locales
.
add
(
locale
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment