优化界面以及大小

This commit is contained in:
方块君
2022-02-18 20:40:02 +08:00
parent 0f4779defe
commit 37066e3c29
15 changed files with 221 additions and 383 deletions

View File

@@ -1,128 +1,172 @@
package com.lt2333.simplicitytools.activity
import android.annotation.SuppressLint
import android.content.DialogInterface
import android.app.AlertDialog
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import cn.fkj233.ui.activity.MIUIActivity
import cn.fkj233.ui.activity.view.*
import cn.fkj233.ui.dialog.MIUIDialog
import com.lt2333.simplicitytools.BuildConfig
import com.lt2333.simplicitytools.R
import com.lt2333.simplicitytools.util.ShellUtils
import kotlin.system.exitProcess
class SettingsActivity : AppCompatActivity() {
class SettingsActivity : MIUIActivity() {
private val activity = this
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.settings_activity)
if (savedInstanceState == null) {
supportFragmentManager
.beginTransaction()
.replace(R.id.settings, SettingsFragment())
.commit()
}
supportActionBar?.setDisplayHomeAsUpEnabled(false)
checkLSPosed()
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.main, menu)
return super.onCreateOptionsMenu(menu)
super.onCreate(savedInstanceState)
}
@SuppressLint("WorldReadableFiles")
private fun checkLSPosed() {
try {
getSharedPreferences("config", MODE_WORLD_READABLE)
setSP(getSharedPreferences("config", MODE_WORLD_READABLE))
} catch (exception: SecurityException) {
AlertDialog.Builder(this)
.setMessage("您似乎正在使用过时的 LSPosed 版本或 LSPosed 未激活,请更新 LSPosed 或者激活后再试。")
.setCancelable(false)
.setPositiveButton("确定", DialogInterface.OnClickListener { dialogInterface, i ->
android.os.Process.killProcess(android.os.Process.myPid())
})
.show()
isLoad = false
MIUIDialog(this).apply {
setTitle(R.string.Tips)
setMessage("您似乎正在使用过时的 LSPosed 版本或 LSPosed 未激活,请更新 LSPosed 或者激活后再试。")
setCancelable(false)
setRButton("确定") {
exitProcess(0)
}
show()
}
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.reboot -> {
AlertDialog.Builder(this)
.setMessage("确定重启?")
.setPositiveButton(
"",
DialogInterface.OnClickListener { dialogInterface, i ->
val commad = arrayOf("reboot")
ShellUtils.execCommand(commad, true)
})
.setNegativeButton("", null)
.show()
}
R.id.reboot_ui -> {
val commad = arrayOf("killall com.android.systemui")
ShellUtils.execCommand(commad, true)
}
}
return super.onOptionsItemSelected(item)
override fun mainName(): String {
return getString(R.string.app_name)
}
class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
preferenceManager.sharedPreferencesName = "config"
setPreferencesFromResource(R.xml.root_preferences, rootKey)
findPreference<Preference>("verison")!!.summary =
BuildConfig.VERSION_NAME + "(" + BuildConfig.BUILD_TYPE + ")"
}
override fun onPreferenceTreeClick(preference: Preference): Boolean {
when (preference.key) {
"opensource" -> {
try {
val uri =
Uri.parse("https://github.com/LittleTurtle2333/Simplicity_Tools_Xposed")
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
} catch (e: Exception) {
Toast.makeText(activity, "访问失败", Toast.LENGTH_SHORT).show()
}
override fun mainItems(): ArrayList<BaseView> {
return arrayListOf<BaseView>().apply {
add(TitleTextV(resId = R.string.ui))
add(TextWithSwitchV(TextV(resId = R.string.delete_on_post_notification), SwitchV("delete_on_post_notification")))
add(LineV())
add(TitleTextV(resId = R.string.statusbar))
add(TextWithSwitchV(TextV(resId = R.string.status_bar_time_seconds), SwitchV("status_bar_time_seconds")))
add(TextWithSwitchV(TextV(resId = R.string.status_bar_network_speed_refresh_speed), SwitchV("status_bar_network_speed_refresh_speed")))
add(TextWithSwitchV(TextV(resId = R.string.hide_status_bar_network_speed_second), SwitchV("hide_status_bar_network_speed_second")))
add(TextWithSwitchV(TextV(resId = R.string.remove_the_maximum_number_of_notification_icons), SwitchV("remove_the_maximum_number_of_notification_icons")))
add(LineV())
add(TitleTextV(resId = R.string.status_bar_icon))
add(TextWithSwitchV(TextV(resId = R.string.hide_gps_icon), SwitchV("hide_gps_icon")))
add(TextWithSwitchV(TextV(resId = R.string.hide_bluetooth_icon), SwitchV("hide_bluetooth_icon")))
add(TextWithSwitchV(TextV(resId = R.string.hide_bluetooth_battery_icon), SwitchV("hide_bluetooth_battery_icon")))
add(TextWithSwitchV(TextV(resId = R.string.hide_small_hd_icon), SwitchV("hide_small_hd_icon")))
add(TextWithSwitchV(TextV(resId = R.string.hide_big_hd_icon), SwitchV("hide_big_hd_icon")))
add(TextWithSwitchV(TextV(resId = R.string.hide_hd_no_service_icon), SwitchV("hide_hd_no_service_icon")))
add(TextWithSwitchV(TextV(resId = R.string.hide_sim_one_icon), SwitchV("hide_sim_one_icon")))
add(TextWithSwitchV(TextV(resId = R.string.hide_sim_two_icon), SwitchV("hide_sim_two_icon")))
add(TextWithSwitchV(TextV(resId = R.string.hide_no_sim_icon), SwitchV("hide_no_sim_icon")))
add(TextWithSwitchV(TextV(resId = R.string.hide_wifi_icon), SwitchV("hide_wifi_icon")))
add(TextWithSwitchV(TextV(resId = R.string.hide_hotspot_icon), SwitchV("hide_hotspot_icon")))
add(TextWithSwitchV(TextV(resId = R.string.hide_vpn_icon), SwitchV("hide_vpn_icon")))
add(TextWithSwitchV(TextV(resId = R.string.hide_airplane_icon), SwitchV("hide_airplane_icon")))
add(TextWithSwitchV(TextV(resId = R.string.hide_alarm_icon), SwitchV("hide_alarm_icon")))
add(TextWithSwitchV(TextV(resId = R.string.hide_headset_icon), SwitchV("hide_headset_icon")))
add(TextWithSwitchV(TextV(resId = R.string.hide_volume_zen_icon), SwitchV("hide_volume_zen_icon")))
add(LineV())
add(TitleTextV(resId = R.string.home))
add(TextWithSwitchV(TextV(resId = R.string.home_time), SwitchV("home_time")))
add(LineV())
add(TitleTextV(resId = R.string.performance))
add(TextWithSwitchV(TextV(resId = R.string.lock_max_fps), SwitchV("lock_max_fps")))
add(LineV())
add(TitleTextV(resId = R.string.other))
add(TextWithSwitchV(TextV(resId = R.string.disable_flag_secure), SwitchV("disable_flag_secure")))
add(LineV())
add(TitleTextV(resId = R.string.about))
add(TextSummaryV(textId = R.string.opensource, tipsId = R.string.github_url, onClickListener = {
try {
val uri =
Uri.parse("https://github.com/LittleTurtle2333/Simplicity_Tools_Xposed")
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
} catch (e: Exception) {
Toast.makeText(activity, "访问失败", Toast.LENGTH_SHORT).show()
}
"issues" -> {
try {
val uri =
Uri.parse("https://github.com/LittleTurtle2333/Simplicity_Tools_Xposed/issues")
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
} catch (e: Exception) {
Toast.makeText(activity, "访问失败", Toast.LENGTH_SHORT).show()
}
}))
add(TextSummaryV(textId = R.string.issues, tipsId = R.string.issues_url, onClickListener = {
try {
val uri =
Uri.parse("https://github.com/LittleTurtle2333/Simplicity_Tools_Xposed/issues")
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
} catch (e: Exception) {
Toast.makeText(activity, "访问失败", Toast.LENGTH_SHORT).show()
}
"dev_coolapk" -> {
try {
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("coolmarket://u/883441")
)
}))
add(TextSummaryV(textId = R.string.dev_coolapk, tipsId = R.string.dev_coolapk_name, onClickListener = {
try {
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("coolmarket://u/883441")
)
Toast.makeText(activity, "乌堆小透明:靓仔,点个关注吧!", Toast.LENGTH_SHORT).show()
} catch (e: Exception) {
Toast.makeText(activity, "本机未安装酷安应用", Toast.LENGTH_SHORT).show()
val uri = Uri.parse("http://www.coolapk.com/u/883441")
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
}
)
Toast.makeText(activity, "乌堆小透明:靓仔,点个关注吧!", Toast.LENGTH_SHORT).show()
} catch (e: Exception) {
Toast.makeText(activity, "本机未安装酷安应用", Toast.LENGTH_SHORT).show()
val uri = Uri.parse("http://www.coolapk.com/u/883441")
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
}
}
return super.onPreferenceTreeClick(preference)
}))
add(TextSummaryV(textId = R.string.verison, tips = "${BuildConfig.VERSION_NAME}(${BuildConfig.BUILD_TYPE})"))
}
}
override fun menuName(): String {
return getString(R.string.menu)
}
override fun menuItems(): ArrayList<BaseView> {
return ArrayList<BaseView>().apply {
add(TextSummaryV(textId = R.string.reboot_ui, onClickListener = {
MIUIDialog(activity).apply {
setTitle(R.string.Tips)
setMessage("确定重启系统界面?")
setLButton("取消") {
dismiss()
}
setRButton("确定") {
val command = arrayOf("killall com.android.systemui")
ShellUtils.execCommand(command, true)
dismiss()
}
show()
}
}))
add(TextSummaryV(textId = R.string.reboot, onClickListener = {
MIUIDialog(activity).apply {
setTitle(R.string.Tips)
setMessage("确定重启系统?")
setLButton("取消") {
dismiss()
}
setRButton("确定") {
val command = arrayOf("reboot")
ShellUtils.execCommand(command, true)
dismiss()
}
show()
}
}))
}
}
override fun getItems(item: String): ArrayList<BaseView> {
return when (item) {
/** 必须写这两个 不然会出错 */
menuName() -> menuItems()
else -> mainItems()
}
}
}