-
Notifications
You must be signed in to change notification settings - Fork 169
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
16 changed files
with
219 additions
and
194 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
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
40 changes: 17 additions & 23 deletions
40
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,25 @@ | ||
package de.szalkowski.activitylauncher.todo; | ||
package de.szalkowski.activitylauncher | ||
|
||
import android.os.Bundle; | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import de.szalkowski.activitylauncher.ui.SettingsFragment | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
@AndroidEntryPoint | ||
class SettingsActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
import java.util.Objects; | ||
setContentView(R.layout.activity_settings) | ||
this.supportActionBar?.setDisplayHomeAsUpEnabled(true) | ||
setTitle(R.string.activity_settings) | ||
|
||
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(); | ||
supportFragmentManager.beginTransaction() | ||
.replace(R.id.settings_container, SettingsFragment()).commit() | ||
} | ||
|
||
@Override | ||
public boolean onSupportNavigateUp() { | ||
finish(); | ||
return true; | ||
override fun onSupportNavigateUp(): Boolean { | ||
finish() | ||
return true | ||
} | ||
} |
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 } | ||
} | ||
} |
72 changes: 37 additions & 35 deletions
72
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,52 @@ | ||
package de.szalkowski.activitylauncher.todo; | ||
package de.szalkowski.activitylauncher.services | ||
|
||
import android.content.res.Configuration; | ||
import android.content.res.Configuration | ||
import androidx.appcompat.app.AppCompatDelegate | ||
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; | ||
|
||
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"; | ||
interface SettingsService { | ||
fun createLocaleConfiguration(language: String): Configuration | ||
fun getCountryName(name: String): String | ||
fun setTheme(theme: String?) | ||
} | ||
|
||
public static Configuration createLocaleConfiguration(String language) { | ||
Configuration config = new Configuration(); | ||
class SettingsServiceImpl @Inject constructor() : SettingsService { | ||
override fun createLocaleConfiguration(language: String): Configuration { | ||
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]) | ||
Locale.setDefault(locale) | ||
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) | ||
} | ||
} | ||
} | ||
|
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
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
Oops, something went wrong.