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
749df5da
Commit
749df5da
authored
Jan 31, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better method to change Locale
parent
af88b7c8
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
23 deletions
+13
-23
App.java
app-core/src/main/java/com/topjohnwu/magisk/App.java
+0
-12
LocaleManager.java
...c/main/java/com/topjohnwu/magisk/utils/LocaleManager.java
+11
-5
ApplicationAdapter.java
...ava/com/topjohnwu/magisk/adapters/ApplicationAdapter.java
+1
-2
BaseActivity.java
...ll/java/com/topjohnwu/magisk/components/BaseActivity.java
+1
-4
No files found.
app-core/src/main/java/com/topjohnwu/magisk/App.java
View file @
749df5da
...
...
@@ -28,8 +28,6 @@ public class App extends ContainerApp {
public
MagiskDB
mDB
;
public
RepoDatabaseHelper
repoDB
;
private
Resources
mResource
;
static
{
Shell
.
Config
.
setFlags
(
Shell
.
FLAG_MOUNT_MASTER
|
Shell
.
FLAG_USE_MAGISK_BUSYBOX
);
Shell
.
Config
.
verboseLogging
(
BuildConfig
.
DEBUG
);
...
...
@@ -41,7 +39,6 @@ public class App extends ContainerApp {
protected
void
attachBaseContext
(
Context
base
)
{
super
.
attachBaseContext
(
base
);
self
=
this
;
mResource
=
base
.
getResources
();
prefs
=
PreferenceManager
.
getDefaultSharedPreferences
(
this
);
mDB
=
new
MagiskDB
(
this
);
...
...
@@ -51,15 +48,6 @@ public class App extends ContainerApp {
LocaleManager
.
setLocale
(
this
);
}
@Override
public
Resources
getResources
()
{
return
mResource
;
}
public
void
setResources
(
Resources
res
)
{
mResource
=
res
;
}
@Override
public
void
onConfigurationChanged
(
Configuration
newConfig
)
{
super
.
onConfigurationChanged
(
newConfig
);
...
...
app-core/src/main/java/com/topjohnwu/magisk/utils/LocaleManager.java
View file @
749df5da
package
com
.
topjohnwu
.
magisk
.
utils
;
import
android.content.Context
;
import
android.content.ContextWrapper
;
import
android.content.res.Configuration
;
import
android.content.res.Resources
;
import
android.os.Build
;
...
...
@@ -8,6 +9,7 @@ import android.os.Build;
import
com.topjohnwu.magisk.App
;
import
com.topjohnwu.magisk.Config
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.internal.InternalUtils
;
import
java.util.ArrayList
;
import
java.util.Collections
;
...
...
@@ -86,7 +88,7 @@ public class LocaleManager {
}
}
public
static
void
setLocale
(
App
app
)
{
public
static
void
setLocale
(
ContextWrapper
wrapper
)
{
String
localeConfig
=
Config
.
get
(
Config
.
Key
.
LOCALE
);
if
(
localeConfig
.
isEmpty
())
{
locale
=
defaultLocale
;
...
...
@@ -94,13 +96,17 @@ public class LocaleManager {
locale
=
forLanguageTag
(
localeConfig
);
}
Locale
.
setDefault
(
locale
);
app
.
setResources
(
getLocaleContext
(
locale
).
getResources
(
));
InternalUtils
.
replaceBaseContext
(
wrapper
,
getLocaleContext
(
locale
));
}
public
static
Context
getLocaleContext
(
Locale
locale
)
{
Configuration
config
=
new
Configuration
(
App
.
self
.
getBaseContext
()
.
getResources
().
getConfiguration
());
public
static
Context
getLocaleContext
(
Context
context
,
Locale
locale
)
{
Configuration
config
=
new
Configuration
(
context
.
getResources
().
getConfiguration
());
config
.
setLocale
(
locale
);
return
App
.
self
.
createConfigurationContext
(
config
);
return
context
.
createConfigurationContext
(
config
);
}
public
static
Context
getLocaleContext
(
Locale
locale
)
{
return
getLocaleContext
(
App
.
self
.
getBaseContext
(),
locale
);
}
public
static
String
getString
(
Locale
locale
,
@StringRes
int
id
)
{
...
...
app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java
View file @
749df5da
...
...
@@ -63,8 +63,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
boolean
ah
=
hideList
.
contains
(
a
.
packageName
);
boolean
bh
=
hideList
.
contains
(
b
.
packageName
);
if
(
ah
==
bh
)
{
return
Utils
.
getAppLabel
(
a
,
pm
).
toLowerCase
()
.
compareTo
(
Utils
.
getAppLabel
(
b
,
pm
).
toLowerCase
());
return
Utils
.
getAppLabel
(
a
,
pm
).
compareToIgnoreCase
(
Utils
.
getAppLabel
(
b
,
pm
));
}
else
if
(
ah
)
{
return
-
1
;
}
else
{
...
...
app/src/full/java/com/topjohnwu/magisk/components/BaseActivity.java
View file @
749df5da
...
...
@@ -53,10 +53,7 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Au
@Override
protected
void
attachBaseContext
(
Context
base
)
{
super
.
attachBaseContext
(
base
);
Configuration
config
=
base
.
getResources
().
getConfiguration
();
config
.
setLocale
(
LocaleManager
.
locale
);
applyOverrideConfiguration
(
config
);
super
.
attachBaseContext
(
LocaleManager
.
getLocaleContext
(
base
,
LocaleManager
.
locale
));
}
@Override
...
...
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