-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
265 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 6 additions & 21 deletions
27
app/src/main/java/de/szalkowski/activitylauncher/ActivityLauncherApp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,18 @@ | ||
package de.szalkowski.activitylauncher | ||
|
||
import android.app.Application | ||
import androidx.preference.PreferenceManager | ||
import dagger.hilt.android.HiltAndroidApp | ||
import de.szalkowski.activitylauncher.todo.RootDetection | ||
import de.szalkowski.activitylauncher.todo.SettingsUtils | ||
import de.szalkowski.activitylauncher.services.SettingsService | ||
import javax.inject.Inject | ||
|
||
@HiltAndroidApp | ||
class ActivityLauncherApp : Application() { | ||
@Inject | ||
internal lateinit var settingsService: SettingsService | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
val prefs = PreferenceManager.getDefaultSharedPreferences( | ||
baseContext | ||
) | ||
|
||
SettingsUtils.setTheme(prefs.getString("theme", "0")) | ||
|
||
if (!prefs.contains("allow_root")) { | ||
val hasSU = RootDetection.detectSU() | ||
prefs.edit().putBoolean("allow_root", hasSU).apply() | ||
} | ||
|
||
if (!prefs.contains("hide_hide_private")) { | ||
prefs.edit().putBoolean("hide_hide_private", false).apply() | ||
} | ||
|
||
if (!prefs.contains("language")) { | ||
prefs.edit().putString("language", "System Default").apply() | ||
} | ||
settingsService.init() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 20 additions & 29 deletions
49
app/src/main/java/de/szalkowski/activitylauncher/SettingsActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,22 @@ | ||
package de.szalkowski.activitylauncher.todo; | ||
|
||
import android.os.Bundle; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import java.util.Objects; | ||
|
||
import de.szalkowski.activitylauncher.R; | ||
|
||
public class SettingsActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_settings); | ||
Objects.requireNonNull(this.getSupportActionBar()).setDisplayHomeAsUpEnabled(true); | ||
|
||
setTitle(R.string.activity_settings); | ||
getSupportFragmentManager() | ||
.beginTransaction() | ||
.replace(R.id.settings_container, new SettingsFragment()) | ||
.commit(); | ||
} | ||
|
||
@Override | ||
public boolean onSupportNavigateUp() { | ||
finish(); | ||
return true; | ||
package de.szalkowski.activitylauncher | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import de.szalkowski.activitylauncher.services.SettingsService | ||
import de.szalkowski.activitylauncher.ui.SettingsFragment | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class SettingsActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
setContentView(R.layout.activity_settings) | ||
this.supportActionBar?.setDisplayHomeAsUpEnabled(true) | ||
setTitle(R.string.activity_settings) | ||
|
||
supportFragmentManager.beginTransaction() | ||
.replace(R.id.settings_container, SettingsFragment()).commit() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 11 additions & 19 deletions
30
app/src/main/java/de/szalkowski/activitylauncher/services/RootDetectionService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,17 @@ | ||
package de.szalkowski.activitylauncher.todo; | ||
package de.szalkowski.activitylauncher.services | ||
|
||
import java.io.File; | ||
import java.util.Objects; | ||
import java.util.Vector; | ||
import java.io.File | ||
import javax.inject.Inject | ||
|
||
public class RootDetection { | ||
public static boolean detectSU() { | ||
Vector<File> paths = new Vector<>(); | ||
String[] dirs = Objects.requireNonNull(System.getenv("PATH")).split(":"); | ||
for (String dir : dirs) { | ||
paths.add(new File(dir, "su")); | ||
} | ||
|
||
for (File path : paths) { | ||
if (path.exists() && path.canExecute() && path.isFile()) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
interface RootDetectionService { | ||
fun detectSU(): Boolean | ||
} | ||
|
||
class RootDetectionServiceImpl @Inject constructor() : RootDetectionService { | ||
override fun detectSU(): Boolean { | ||
val dirs = System.getenv("PATH").orEmpty().split(":").map { dir -> File(dir, "su") } | ||
|
||
return dirs.any { path -> path.exists() && path.canExecute() && path.isFile } | ||
} | ||
} |
114 changes: 80 additions & 34 deletions
114
app/src/main/java/de/szalkowski/activitylauncher/services/SettingsService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,96 @@ | ||
package de.szalkowski.activitylauncher.todo; | ||
package de.szalkowski.activitylauncher.services | ||
|
||
import android.content.res.Configuration; | ||
import android.content.Context | ||
import android.content.res.Configuration | ||
import android.content.res.Resources | ||
import androidx.appcompat.app.AppCompatDelegate | ||
import androidx.preference.PreferenceManager | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import java.util.Locale | ||
import javax.inject.Inject | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.appcompat.app.AppCompatDelegate; | ||
const val THEME_DEFAULT = "0" | ||
const val THEME_LIGHT = "1" | ||
const val THEME_DARK = "2" | ||
|
||
import java.util.Locale; | ||
interface SettingsService { | ||
fun getLocaleConfiguration(): Configuration | ||
fun getCountryName(name: String): String | ||
fun setTheme(theme: String?) | ||
|
||
public class SettingsUtils extends AppCompatActivity { | ||
public final static String THEME_DEFAULT = "0"; | ||
public final static String THEME_LIGHT = "1"; | ||
public final static String THEME_DARK = "2"; | ||
fun init() | ||
|
||
public static Configuration createLocaleConfiguration(String language) { | ||
Configuration config = new Configuration(); | ||
fun applyLocaleConfiguration(context: Context) | ||
} | ||
|
||
class SettingsServiceImpl @Inject constructor(@ApplicationContext val context: Context) : SettingsService { | ||
private val prefs = PreferenceManager.getDefaultSharedPreferences(context); | ||
|
||
@Inject | ||
internal lateinit var rootDetectionService: RootDetectionService | ||
|
||
override fun init() { | ||
setTheme(prefs.getString("theme", "0")) | ||
|
||
if (!prefs.contains("allow_root")) { | ||
val hasSU = rootDetectionService.detectSU() | ||
prefs.edit().putBoolean("allow_root", hasSU).apply() | ||
} | ||
|
||
if (!prefs.contains("hide_hide_private")) { | ||
prefs.edit().putBoolean("hide_hide_private", false).apply() | ||
} | ||
|
||
if (!prefs.contains("language")) { | ||
prefs.edit().putString("language", "System Default").apply() | ||
} | ||
} | ||
|
||
override fun applyLocaleConfiguration(context: Context) { | ||
val config = getLocaleConfiguration() | ||
Locale.setDefault(config.locale) | ||
context.resources.updateConfiguration(config, | ||
context.resources.displayMetrics); | ||
} | ||
|
||
override fun getLocaleConfiguration(): Configuration { | ||
val settingsLanguage = prefs.getString("language", "System Default")!! | ||
|
||
val language = if (settingsLanguage == "System Default") { | ||
Resources.getSystem().configuration.locale.toString() | ||
} else { | ||
settingsLanguage | ||
} | ||
|
||
val config = Configuration() | ||
if (language.contains("_")) { | ||
String[] parts = language.split("_"); | ||
Locale locale = new Locale(parts[0], parts[1]); | ||
Locale.setDefault(locale); | ||
config.locale = locale; | ||
val parts = language.split("_".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() | ||
val locale = Locale(parts[0], parts[1]) | ||
config.locale = locale // FIXME | ||
} | ||
return config; | ||
|
||
return config | ||
} | ||
|
||
public static String getCountryName(String name) { | ||
for (Locale locale : Locale.getAvailableLocales()) { | ||
if (name.equals(locale.getLanguage() + '_' + locale.getCountry())) { | ||
String language = locale.getDisplayName(locale); | ||
return language.substring(0, 1).toUpperCase() + language.substring(1); | ||
override fun getCountryName(name: String): String { | ||
for (locale in Locale.getAvailableLocales()) { | ||
if (name == locale.language + '_' + locale.country) { | ||
val language = locale.getDisplayName(locale) | ||
return language.substring(0, 1).uppercase(Locale.getDefault()) + language.substring( | ||
1 | ||
) | ||
} | ||
} | ||
return name; | ||
return name | ||
} | ||
|
||
public static void setTheme(String theme) { | ||
switch (theme) { | ||
default: | ||
case THEME_DEFAULT: | ||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); | ||
break; | ||
case THEME_LIGHT: | ||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); | ||
break; | ||
case THEME_DARK: | ||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); | ||
break; | ||
override fun setTheme(theme: String?) { | ||
when (theme) { | ||
THEME_DEFAULT -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) | ||
THEME_LIGHT -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) | ||
THEME_DARK -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) | ||
else -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.