-
Notifications
You must be signed in to change notification settings - Fork 91
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
11 changed files
with
337 additions
and
76 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
android/android_framework/res/src/main/res/values-zh-rCN/app_strings.xml
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_select_activate_method">你想用哪种激活方式使用Thanox?</string> | ||
</resources> |
4 changes: 4 additions & 0 deletions
4
android/android_framework/res/src/main/res/values/app_strings.xml
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_select_activate_method">Which activation method do you prefer?</string> | ||
</resources> |
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
104 changes: 104 additions & 0 deletions
104
android/app/src/main/java/now/fortuitous/thanos/main/ChooserActivity.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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* (C) Copyright 2022 Thanox | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package now.fortuitous.thanos.main | ||
|
||
import android.content.Context | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import github.tornaco.android.thanos.module.compose.common.ComposeThemeActivity | ||
import github.tornaco.android.thanos.util.ActivityUtils | ||
import now.fortuitous.thanos.pref.AppPreference | ||
import tornaco.apps.thanox.base.ui.LargeSpacer | ||
import tornaco.apps.thanox.base.ui.NiaGradientBackground | ||
import tornaco.apps.thanox.base.ui.theme.ThanosTheme | ||
|
||
@AndroidEntryPoint | ||
class ChooserActivity : ComposeThemeActivity() { | ||
|
||
object Starter { | ||
@JvmStatic | ||
fun start(context: Context?) { | ||
ActivityUtils.startActivity(context, ChooserActivity::class.java) | ||
} | ||
} | ||
|
||
override fun isF(): Boolean { | ||
return false | ||
} | ||
|
||
@Composable | ||
override fun Content() { | ||
AppChooser() | ||
} | ||
|
||
@Composable | ||
private fun AppChooser() { | ||
val context = LocalContext.current | ||
ThanosTheme { | ||
NiaGradientBackground(modifier = Modifier.fillMaxSize()) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(16.dp), | ||
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
Text( | ||
modifier = Modifier.fillMaxWidth(), | ||
textAlign = TextAlign.Center, | ||
text = stringResource(id = github.tornaco.android.thanos.res.R.string.app_select_activate_method), | ||
style = MaterialTheme.typography.headlineSmall | ||
) | ||
repeat(4) { | ||
LargeSpacer() | ||
} | ||
|
||
Button(modifier = Modifier.fillMaxWidth(0.68f), onClick = { | ||
AppPreference.setAppType(context, "thanos") | ||
NavActivity.Starter.start(context) | ||
finish() | ||
}) { | ||
Text(text = "Shizuku") | ||
} | ||
LargeSpacer() | ||
Button(modifier = Modifier.fillMaxWidth(0.68f), onClick = { | ||
AppPreference.setAppType(context, "thanox") | ||
NavActivity.Starter.start(context) | ||
finish() | ||
}) { | ||
Text(text = "Xposed/Magisk") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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
112 changes: 112 additions & 0 deletions
112
android/app/src/main/java/now/fortuitous/thanos/main/ShortcutInit.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 |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package now.fortuitous.thanos.main | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.core.content.pm.ShortcutInfoCompat | ||
import androidx.core.content.pm.ShortcutManagerCompat | ||
import androidx.core.graphics.drawable.IconCompat | ||
import androidx.core.net.toUri | ||
import github.tornaco.android.thanos.R | ||
import now.fortuitous.thanos.power.SmartFreezeActivity | ||
import now.fortuitous.thanos.process.v2.ProcessManageActivityV2Delegate | ||
import tornaco.apps.thanox.ThanosMainActivity | ||
|
||
class ShortcutInit(val context: Context) { | ||
companion object { | ||
const val ID_THANOX_PM = "thanox_pm" | ||
const val ID_THANOX_SF = "thanox_sf" | ||
const val ID_THANOS_PM = "thanos_pm" | ||
const val ID_THANOS_SF = "thanos_sf" | ||
} | ||
|
||
private fun installForThanox() { | ||
if (!hasDynamicShortcut(ID_THANOX_SF)) { | ||
addDynamicShortcut( | ||
ID_THANOX_SF, | ||
SmartFreezeActivity::class.java, | ||
R.drawable.shortcut_smart_freeze, | ||
context.getString(R.string.feature_title_smart_app_freeze) | ||
) | ||
} | ||
if (!hasDynamicShortcut(ID_THANOX_PM)) { | ||
addDynamicShortcut( | ||
ID_THANOX_PM, | ||
ProcessManageActivityV2Delegate::class.java, | ||
R.drawable.ic_shortcut_process_manage, | ||
context.getString(R.string.feature_title_process_manage) | ||
) | ||
} | ||
} | ||
|
||
private fun installForThanos() { | ||
if (!hasDynamicShortcut(ID_THANOS_SF)) { | ||
addDynamicShortcut( | ||
ID_THANOS_SF, | ||
ThanosMainActivity::class.java, | ||
R.drawable.shortcut_smart_freeze, | ||
context.getString(R.string.feature_title_smart_app_freeze), | ||
"SF" | ||
) | ||
} | ||
|
||
if (!hasDynamicShortcut(ID_THANOS_PM)) { | ||
addDynamicShortcut( | ||
ID_THANOS_PM, | ||
ThanosMainActivity::class.java, | ||
R.drawable.ic_shortcut_process_manage, | ||
context.getString(R.string.feature_title_process_manage), | ||
"PM" | ||
) | ||
} | ||
} | ||
|
||
fun initOnBootThanos() { | ||
installForThanos() | ||
removeDynamicShortcuts(listOf(ID_THANOX_PM, ID_THANOX_SF)) | ||
} | ||
|
||
fun initOnBootThanox() { | ||
installForThanox() | ||
removeDynamicShortcuts(listOf(ID_THANOS_PM, ID_THANOS_SF)) | ||
} | ||
|
||
fun addDynamicShortcut( | ||
id: String, | ||
clazz: Class<*>, | ||
iconRes: Int, | ||
title: String, | ||
data: String? = null | ||
): Boolean { | ||
val shortcutInfoIntent = Intent(context, clazz).apply { | ||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
data?.let { | ||
setData(it.toUri()) | ||
} | ||
} | ||
shortcutInfoIntent.action = Intent.ACTION_VIEW | ||
|
||
val icon = IconCompat.createWithResource( | ||
context, | ||
iconRes | ||
) | ||
|
||
val shortcutInfo = ShortcutInfoCompat.Builder(context, id) | ||
.setShortLabel(title) | ||
.setLongLabel(title) | ||
.setIcon(icon) | ||
.setIntent(shortcutInfoIntent) | ||
.build() | ||
|
||
return ShortcutManagerCompat.pushDynamicShortcut(context, shortcutInfo) | ||
} | ||
|
||
fun removeDynamicShortcuts(id: List<String>) { | ||
ShortcutManagerCompat.removeDynamicShortcuts(context, id) | ||
} | ||
|
||
fun hasDynamicShortcut(id: String): Boolean { | ||
return ShortcutManagerCompat.getDynamicShortcuts(context).any { | ||
it.id == id | ||
} | ||
} | ||
} |
Oops, something went wrong.