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
7c74be27
Commit
7c74be27
authored
Jul 31, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create LocaleManager
parent
70dd2d48
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
113 additions
and
95 deletions
+113
-95
MagiskManager.java
app/src/full/java/com/topjohnwu/magisk/MagiskManager.java
+3
-22
SettingsActivity.java
app/src/full/java/com/topjohnwu/magisk/SettingsActivity.java
+7
-6
SplashActivity.java
app/src/full/java/com/topjohnwu/magisk/SplashActivity.java
+2
-14
FlavorActivity.java
.../java/com/topjohnwu/magisk/components/FlavorActivity.java
+2
-1
Repo.java
app/src/full/java/com/topjohnwu/magisk/container/Repo.java
+2
-2
SuLogEntry.java
.../full/java/com/topjohnwu/magisk/container/SuLogEntry.java
+3
-3
MagiskDatabaseHelper.java
...a/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java
+2
-1
LocaleManager.java
...c/full/java/com/topjohnwu/magisk/utils/LocaleManager.java
+92
-0
Utils.java
app/src/full/java/com/topjohnwu/magisk/utils/Utils.java
+0
-46
No files found.
app/src/full/java/com/topjohnwu/magisk/MagiskManager.java
View file @
7c74be27
...
...
@@ -2,8 +2,6 @@ package com.topjohnwu.magisk;
import
android.content.SharedPreferences
;
import
android.content.pm.PackageManager
;
import
android.content.res.Configuration
;
import
android.content.res.Resources
;
import
android.preference.PreferenceManager
;
import
android.text.TextUtils
;
...
...
@@ -11,21 +9,18 @@ import com.topjohnwu.magisk.container.Module;
import
com.topjohnwu.magisk.database.MagiskDatabaseHelper
;
import
com.topjohnwu.magisk.database.RepoDatabaseHelper
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.LocaleManager
;
import
com.topjohnwu.magisk.utils.RootUtils
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.superuser.ContainerApp
;
import
com.topjohnwu.superuser.Shell
;
import
java.lang.ref.WeakReference
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
public
class
MagiskManager
extends
ContainerApp
{
public
static
Locale
locale
;
public
static
Locale
defaultLocale
;
// Topics
public
final
Topic
magiskHideDone
=
new
Topic
();
public
final
Topic
reloadActivity
=
new
Topic
();
...
...
@@ -40,7 +35,6 @@ public class MagiskManager extends ContainerApp {
// Data
public
Map
<
String
,
Module
>
moduleMap
;
public
List
<
Locale
>
locales
;
// Global resources
public
SharedPreferences
prefs
;
...
...
@@ -61,7 +55,7 @@ public class MagiskManager extends ContainerApp {
prefs
=
PreferenceManager
.
getDefaultSharedPreferences
(
this
);
mDB
=
MagiskDatabaseHelper
.
getInstance
(
this
);
locale
=
defaultLocale
=
Locale
.
getDefault
();
LocaleManager
.
locale
=
LocaleManager
.
defaultLocale
=
Locale
.
getDefault
();
String
pkg
=
mDB
.
getStrings
(
Const
.
Key
.
SU_MANAGER
,
null
);
if
(
pkg
!=
null
&&
getPackageName
().
equals
(
Const
.
ORIG_PKG_NAME
))
{
...
...
@@ -76,21 +70,8 @@ public class MagiskManager extends ContainerApp {
}
catch
(
PackageManager
.
NameNotFoundException
ignored
)
{}
}
setLocale
();
LocaleManager
.
setLocale
();
Global
.
loadConfig
();
}
public
void
setLocale
()
{
Global
.
localeConfig
=
prefs
.
getString
(
Const
.
Key
.
LOCALE
,
""
);
if
(
Global
.
localeConfig
.
isEmpty
())
{
locale
=
defaultLocale
;
}
else
{
locale
=
Locale
.
forLanguageTag
(
Global
.
localeConfig
);
}
Resources
res
=
getBaseContext
().
getResources
();
Configuration
config
=
new
Configuration
(
res
.
getConfiguration
());
config
.
setLocale
(
locale
);
res
.
updateConfiguration
(
config
,
res
.
getDisplayMetrics
());
}
}
app/src/full/java/com/topjohnwu/magisk/SettingsActivity.java
View file @
7c74be27
...
...
@@ -27,6 +27,7 @@ import com.topjohnwu.magisk.receivers.DownloadReceiver;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Download
;
import
com.topjohnwu.magisk.utils.FingerprintHelper
;
import
com.topjohnwu.magisk.utils.LocaleManager
;
import
com.topjohnwu.magisk.utils.RootUtils
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
...
...
@@ -212,18 +213,18 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
}
private
void
setLocalePreference
(
ListPreference
lp
)
{
CharSequence
[]
entries
=
new
CharSequence
[
mm
.
locales
.
size
()
+
1
];
CharSequence
[]
entryValues
=
new
CharSequence
[
mm
.
locales
.
size
()
+
1
];
entries
[
0
]
=
Utils
.
getLocaleString
(
Magisk
Manager
.
defaultLocale
,
R
.
string
.
system_default
);
CharSequence
[]
entries
=
new
CharSequence
[
LocaleManager
.
locales
.
size
()
+
1
];
CharSequence
[]
entryValues
=
new
CharSequence
[
LocaleManager
.
locales
.
size
()
+
1
];
entries
[
0
]
=
LocaleManager
.
getString
(
Locale
Manager
.
defaultLocale
,
R
.
string
.
system_default
);
entryValues
[
0
]
=
""
;
int
i
=
1
;
for
(
Locale
locale
:
mm
.
locales
)
{
for
(
Locale
locale
:
LocaleManager
.
locales
)
{
entries
[
i
]
=
locale
.
getDisplayName
(
locale
);
entryValues
[
i
++]
=
locale
.
toLanguageTag
();
}
lp
.
setEntries
(
entries
);
lp
.
setEntryValues
(
entryValues
);
lp
.
setSummary
(
MagiskManager
.
locale
.
getDisplayName
(
Magisk
Manager
.
locale
));
lp
.
setSummary
(
LocaleManager
.
locale
.
getDisplayName
(
Locale
Manager
.
locale
));
}
@Override
...
...
@@ -282,7 +283,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
mm
.
mDB
.
setSettings
(
key
,
Utils
.
getPrefsInt
(
prefs
,
key
));
break
;
case
Const
.
Key
.
LOCALE
:
mm
.
setLocale
();
LocaleManager
.
setLocale
();
mm
.
reloadActivity
.
publish
(
false
);
break
;
case
Const
.
Key
.
UPDATE_CHANNEL
:
...
...
app/src/full/java/com/topjohnwu/magisk/SplashActivity.java
View file @
7c74be27
...
...
@@ -8,13 +8,13 @@ import android.os.Bundle;
import
com.topjohnwu.magisk.asyncs.CheckUpdates
;
import
com.topjohnwu.magisk.asyncs.LoadModules
;
import
com.topjohnwu.magisk.asyncs.ParallelTask
;
import
com.topjohnwu.magisk.asyncs.UpdateRepos
;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.database.RepoDatabaseHelper
;
import
com.topjohnwu.magisk.receivers.ShortcutReceiver
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Download
;
import
com.topjohnwu.magisk.utils.LocaleManager
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
...
...
@@ -32,7 +32,7 @@ public class SplashActivity extends Activity {
Global
.
importPrefs
();
// Dynamic detect all locales
new
LoadLocale
().
exec
();
new
Lo
caleManager
.
Lo
adLocale
().
exec
();
// Create notification channel on Android O
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
...
...
@@ -72,16 +72,4 @@ public class SplashActivity extends Activity {
startActivity
(
intent
);
finish
();
}
static
class
LoadLocale
extends
ParallelTask
<
Void
,
Void
,
Void
>
{
@Override
protected
Void
doInBackground
(
Void
...
voids
)
{
Global
.
MM
().
locales
=
Utils
.
getAvailableLocale
();
return
null
;
}
@Override
protected
void
onPostExecute
(
Void
aVoid
)
{
Global
.
MM
().
localeDone
.
publish
();
}
}
}
app/src/full/java/com/topjohnwu/magisk/components/FlavorActivity.java
View file @
7c74be27
...
...
@@ -11,6 +11,7 @@ import android.view.WindowManager;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.utils.LocaleManager
;
import
com.topjohnwu.magisk.utils.Topic
;
public
abstract
class
FlavorActivity
extends
AppCompatActivity
{
...
...
@@ -20,7 +21,7 @@ public abstract class FlavorActivity extends AppCompatActivity {
public
FlavorActivity
()
{
super
();
Configuration
configuration
=
new
Configuration
();
configuration
.
setLocale
(
Magisk
Manager
.
locale
);
configuration
.
setLocale
(
Locale
Manager
.
locale
);
applyOverrideConfiguration
(
configuration
);
}
...
...
app/src/full/java/com/topjohnwu/magisk/container/Repo.java
View file @
7c74be27
...
...
@@ -3,8 +3,8 @@ package com.topjohnwu.magisk.container;
import
android.content.ContentValues
;
import
android.database.Cursor
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.LocaleManager
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.WebService
;
...
...
@@ -77,7 +77,7 @@ public class Repo extends BaseModule {
public
String
getLastUpdateString
()
{
return
DateFormat
.
getDateTimeInstance
(
DateFormat
.
MEDIUM
,
DateFormat
.
MEDIUM
,
Magisk
Manager
.
locale
).
format
(
mLastUpdate
);
Locale
Manager
.
locale
).
format
(
mLastUpdate
);
}
public
Date
getLastUpdate
()
{
...
...
app/src/full/java/com/topjohnwu/magisk/container/SuLogEntry.java
View file @
7c74be27
...
...
@@ -3,7 +3,7 @@ package com.topjohnwu.magisk.container;
import
android.content.ContentValues
;
import
android.database.Cursor
;
import
com.topjohnwu.magisk.
Magisk
Manager
;
import
com.topjohnwu.magisk.
utils.Locale
Manager
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
...
...
@@ -47,10 +47,10 @@ public class SuLogEntry {
}
public
String
getDateString
()
{
return
DateFormat
.
getDateInstance
(
DateFormat
.
MEDIUM
,
Magisk
Manager
.
locale
).
format
(
date
);
return
DateFormat
.
getDateInstance
(
DateFormat
.
MEDIUM
,
Locale
Manager
.
locale
).
format
(
date
);
}
public
String
getTimeString
()
{
return
new
SimpleDateFormat
(
"h:mm a"
,
Magisk
Manager
.
locale
).
format
(
date
);
return
new
SimpleDateFormat
(
"h:mm a"
,
Locale
Manager
.
locale
).
format
(
date
);
}
}
app/src/full/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java
View file @
7c74be27
...
...
@@ -17,6 +17,7 @@ import com.topjohnwu.magisk.R;
import
com.topjohnwu.magisk.container.Policy
;
import
com.topjohnwu.magisk.container.SuLogEntry
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.LocaleManager
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.io.SuFile
;
...
...
@@ -236,7 +237,7 @@ public class MagiskDatabaseHelper {
String
dateString
=
null
,
newString
;
while
(
c
.
moveToNext
())
{
Date
date
=
new
Date
(
c
.
getLong
(
c
.
getColumnIndex
(
"time"
)));
newString
=
DateFormat
.
getDateInstance
(
DateFormat
.
MEDIUM
,
Magisk
Manager
.
locale
).
format
(
date
);
newString
=
DateFormat
.
getDateInstance
(
DateFormat
.
MEDIUM
,
Locale
Manager
.
locale
).
format
(
date
);
if
(!
TextUtils
.
equals
(
dateString
,
newString
))
{
dateString
=
newString
;
list
=
new
ArrayList
<>();
...
...
app/src/full/java/com/topjohnwu/magisk/utils/LocaleManager.java
0 → 100644
View file @
7c74be27
package
com
.
topjohnwu
.
magisk
.
utils
;
import
android.content.res.Configuration
;
import
android.content.res.Resources
;
import
android.support.annotation.StringRes
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.asyncs.ParallelTask
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Locale
;
public
class
LocaleManager
{
public
static
Locale
locale
;
public
static
Locale
defaultLocale
;
public
static
List
<
Locale
>
locales
;
public
static
void
setLocale
()
{
MagiskManager
mm
=
Global
.
MM
();
Global
.
localeConfig
=
mm
.
prefs
.
getString
(
Const
.
Key
.
LOCALE
,
""
);
if
(
Global
.
localeConfig
.
isEmpty
())
{
locale
=
defaultLocale
;
}
else
{
locale
=
Locale
.
forLanguageTag
(
Global
.
localeConfig
);
}
Resources
res
=
mm
.
getResources
();
Configuration
config
=
new
Configuration
(
res
.
getConfiguration
());
config
.
setLocale
(
locale
);
res
.
updateConfiguration
(
config
,
res
.
getDisplayMetrics
());
}
public
static
String
getString
(
Locale
locale
,
@StringRes
int
id
)
{
Configuration
config
=
Global
.
MM
().
getResources
().
getConfiguration
();
config
.
setLocale
(
locale
);
return
getString
(
config
,
id
);
}
private
static
String
getString
(
Configuration
config
,
@StringRes
int
id
)
{
return
Global
.
MM
().
createConfigurationContext
(
config
).
getString
(
id
);
}
private
static
List
<
Locale
>
getAvailableLocale
()
{
List
<
Locale
>
locales
=
new
ArrayList
<>();
HashSet
<
String
>
set
=
new
HashSet
<>();
MagiskManager
mm
=
Global
.
MM
();
Locale
locale
;
@StringRes
int
compareId
=
R
.
string
.
download_file_error
;
// Add default locale
locales
.
add
(
Locale
.
ENGLISH
);
set
.
add
(
getString
(
Locale
.
ENGLISH
,
compareId
));
// Add some special locales
locales
.
add
(
Locale
.
TAIWAN
);
set
.
add
(
getString
(
Locale
.
TAIWAN
,
compareId
));
locale
=
new
Locale
(
"pt"
,
"BR"
);
locales
.
add
(
locale
);
set
.
add
(
getString
(
locale
,
compareId
));
// Other locales
Configuration
config
=
mm
.
getResources
().
getConfiguration
();
for
(
String
s
:
mm
.
getAssets
().
getLocales
())
{
locale
=
Locale
.
forLanguageTag
(
s
);
config
.
setLocale
(
locale
);
if
(
set
.
add
(
getString
(
config
,
compareId
)))
{
locales
.
add
(
locale
);
}
}
Collections
.
sort
(
locales
,
(
a
,
b
)
->
a
.
getDisplayName
(
a
).
compareTo
(
b
.
getDisplayName
(
b
)));
return
locales
;
}
public
static
class
LoadLocale
extends
ParallelTask
<
Void
,
Void
,
Void
>
{
@Override
protected
Void
doInBackground
(
Void
...
voids
)
{
locales
=
getAvailableLocale
();
return
null
;
}
@Override
protected
void
onPostExecute
(
Void
aVoid
)
{
Global
.
MM
().
localeDone
.
publish
();
}
}
}
app/src/full/java/com/topjohnwu/magisk/utils/Utils.java
View file @
7c74be27
...
...
@@ -5,21 +5,14 @@ import android.app.job.JobScheduler;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
android.content.res.Configuration
;
import
android.database.Cursor
;
import
android.net.Uri
;
import
android.provider.OpenableColumns
;
import
android.support.annotation.StringRes
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.services.UpdateCheckService
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Locale
;
public
class
Utils
{
...
...
@@ -54,45 +47,6 @@ public class Utils {
return
name
;
}
public
static
String
getLocaleString
(
Locale
locale
,
@StringRes
int
id
)
{
Context
context
=
Global
.
MM
();
Configuration
config
=
context
.
getResources
().
getConfiguration
();
config
.
setLocale
(
locale
);
Context
localizedContext
=
context
.
createConfigurationContext
(
config
);
return
localizedContext
.
getString
(
id
);
}
public
static
List
<
Locale
>
getAvailableLocale
()
{
List
<
Locale
>
locales
=
new
ArrayList
<>();
HashSet
<
String
>
set
=
new
HashSet
<>();
Locale
locale
;
@StringRes
int
compareId
=
R
.
string
.
download_file_error
;
// Add default locale
locales
.
add
(
Locale
.
ENGLISH
);
set
.
add
(
getLocaleString
(
Locale
.
ENGLISH
,
compareId
));
// Add some special locales
locales
.
add
(
Locale
.
TAIWAN
);
set
.
add
(
getLocaleString
(
Locale
.
TAIWAN
,
compareId
));
locale
=
new
Locale
(
"pt"
,
"BR"
);
locales
.
add
(
locale
);
set
.
add
(
getLocaleString
(
locale
,
compareId
));
// Other locales
for
(
String
s
:
Global
.
MM
().
getAssets
().
getLocales
())
{
locale
=
Locale
.
forLanguageTag
(
s
);
if
(
set
.
add
(
getLocaleString
(
locale
,
compareId
)))
{
locales
.
add
(
locale
);
}
}
Collections
.
sort
(
locales
,
(
l1
,
l2
)
->
l1
.
getDisplayName
(
l1
).
compareTo
(
l2
.
getDisplayName
(
l2
)));
return
locales
;
}
public
static
int
dpInPx
(
int
dp
)
{
Context
context
=
Global
.
MM
();
float
scale
=
context
.
getResources
().
getDisplayMetrics
().
density
;
...
...
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