From 68c67d139beaa5af6f9fea286ff01a6485edadca Mon Sep 17 00:00:00 2001 From: LittleTurtle2333 Date: Sat, 26 Mar 2022 16:07:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A4=A7=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=9B=BE=E6=A0=87=E8=87=AA=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity/SettingsActivity.kt | 247 ++++++++++++++++-- .../systemui/StatusBarBigMobileTypeIcon.kt | 18 +- app/src/main/res/values/strings.xml | 8 + 3 files changed, 244 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt b/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt index 100851e0..c4731a4f 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt @@ -498,32 +498,6 @@ class SettingsActivity : MIUIActivity() { menuButton.visibility = View.VISIBLE return ArrayList().apply { add(TitleTextV(resId = R.string.statusbar)) - add( - TextSummaryWithSwitchV( - TextSummaryV( - textId = R.string.big_mobile_type_icon - ), - SwitchV("big_mobile_type_icon") - ) - ) - add( - TextSummaryWithSwitchV( - TextSummaryV( - textId = R.string.hide_battery_percentage_icon, - tipsId = R.string.hide_battery_percentage_icon_summary - ), - SwitchV("hide_battery_percentage_icon") - ) - ) - add( - TextSummaryWithSwitchV( - TextSummaryV( - textId = R.string.remove_the_maximum_number_of_notification_icons, - tipsId = R.string.remove_the_maximum_number_of_notification_icons_summary - ), - SwitchV("remove_the_maximum_number_of_notification_icons") - ) - ) add( TextSummaryWithSwitchV( TextSummaryV( @@ -725,6 +699,227 @@ class SettingsActivity : MIUIActivity() { ) ) ) + val big_mobile_type_icon_binding = getDataBinding( + SPUtils.getBoolean( + activity, + "big_mobile_type_icon", + false + ) + ) { view, flags, data -> + when (flags) { + 1 -> (view as Switch).isEnabled = data as Boolean + 2 -> view.visibility = if (data as Boolean) View.VISIBLE else View.GONE + } + } + add( + TextSummaryWithSwitchV( + TextSummaryV( + textId = R.string.big_mobile_type_icon + ), + SwitchV( + "big_mobile_type_icon", + dataBindingSend = big_mobile_type_icon_binding.bindingSend + ) + ) + ) + add( + TextSummaryWithSwitchV( + TextSummaryV( + textId = R.string.big_mobile_type_icon_bold + ), + SwitchV("big_mobile_type_icon_bold", true), + dataBindingRecv = big_mobile_type_icon_binding.binding.getRecv(2) + ) + ) + add( + TextSummaryArrowV( + TextSummaryV( + textId = R.string.big_mobile_type_icon_size, + onClickListener = { + MIUIDialog(activity).apply { + setTitle(R.string.big_mobile_type_icon_size) + setEditText( + "", + "${activity.getString(R.string.def)}12.5, ${activity.getString(R.string.current)}${ + OwnSP.ownSP.getFloat( + "big_mobile_type_icon_size", + 12.5f + ) + }" + ) + setLButton(textId = R.string.cancel) { + dismiss() + } + setRButton(textId = R.string.Done) { + if (getEditText() != "") { + OwnSP.ownSP.edit().run { + putFloat( + "big_mobile_type_icon_size", + getEditText().toFloat() + ) + apply() + } + } + dismiss() + } + show() + } + }), dataBindingRecv = big_mobile_type_icon_binding.binding.getRecv(2) + ) + ) + add( + TextSummaryArrowV( + TextSummaryV( + textId = R.string.big_mobile_type_icon_up_and_down_position + ) { + MIUIDialog(activity).apply { + setTitle(R.string.big_mobile_type_icon_up_and_down_position) + setMessage("${activity.getString(R.string.range)} -15~15") + setEditText( + "", + "${activity.getString(R.string.def)}0, ${activity.getString(R.string.current)}${ + OwnSP.ownSP.getInt( + "big_mobile_type_icon_up_and_down_position", + 0 + ) + }" + ) + setLButton(textId = R.string.cancel) { + dismiss() + } + setRButton(textId = R.string.Done) { + if (getEditText().isNotEmpty()) { + try { + val value = getEditText().toInt() + if (value in (-15..15)) { + OwnSP.ownSP.edit().run { + putInt( + "big_mobile_type_icon_up_and_down_position", + value + ) + apply() + } + dismiss() + return@setRButton + } + } catch (_: Throwable) { + } + } + Toast.makeText( + activity, + R.string.input_error, + Toast.LENGTH_SHORT + ).show() + } + show() + } + }, dataBindingRecv = big_mobile_type_icon_binding.binding.getRecv(2) + ) + ) + add( + TextSummaryArrowV( + TextSummaryV( + textId = R.string.big_mobile_type_icon_left_and_right_margins + ) { + MIUIDialog(activity).apply { + setTitle(R.string.big_mobile_type_icon_left_and_right_margins) + setMessage("${activity.getString(R.string.range)} -30~30") + setEditText( + "", + "${activity.getString(R.string.def)}0, ${activity.getString(R.string.current)}${ + OwnSP.ownSP.getInt( + "big_mobile_type_icon_left_and_right_margins", + 0 + ) + }" + ) + setLButton(textId = R.string.cancel) { + dismiss() + } + setRButton(textId = R.string.Done) { + if (getEditText().isNotEmpty()) { + try { + val value = getEditText().toInt() + if (value in (-30..30)) { + OwnSP.ownSP.edit().run { + putInt( + "big_mobile_type_icon_left_and_right_margins", + value + ) + apply() + } + dismiss() + return@setRButton + } + } catch (_: Throwable) { + } + } + Toast.makeText( + activity, + R.string.input_error, + Toast.LENGTH_SHORT + ).show() + } + show() + } + }, dataBindingRecv = big_mobile_type_icon_binding.binding.getRecv(2) + ) + ) + add( + TextSummaryWithSwitchV( + TextSummaryV( + textId = R.string.remove_the_maximum_number_of_notification_icons, + tipsId = R.string.remove_the_maximum_number_of_notification_icons_summary + ), + SwitchV("remove_the_maximum_number_of_notification_icons") + ) + ) + add( + TextSummaryArrowV( + TextSummaryV( + textId = R.string.battery_percentage_font_size, + onClickListener = { + MIUIDialog(activity).apply { + setTitle(R.string.battery_percentage_font_size) + setMessage(R.string.zero_do_no_change) + setEditText( + "", + "${activity.getString(R.string.current)}${ + OwnSP.ownSP.getFloat( + "battery_percentage_font_size", + 0f + ) + }" + ) + setLButton(textId = R.string.cancel) { + dismiss() + } + setRButton(textId = R.string.Done) { + if (getEditText() != "") { + OwnSP.ownSP.edit().run { + putFloat( + "battery_percentage_font_size", + getEditText().toFloat() + ) + apply() + } + } + dismiss() + } + show() + } + }) + ) + ) + add( + TextSummaryWithSwitchV( + TextSummaryV( + textId = R.string.hide_battery_percentage_icon, + tipsId = R.string.hide_battery_percentage_icon_summary + ), + SwitchV("hide_battery_percentage_icon") + ) + ) add(LineV()) add(TitleTextV(resId = R.string.status_bar_network_speed)) add( diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarBigMobileTypeIcon.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarBigMobileTypeIcon.kt index 78839fce..08d78eff 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarBigMobileTypeIcon.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/systemui/StatusBarBigMobileTypeIcon.kt @@ -9,6 +9,7 @@ import android.view.ViewGroup import android.widget.ImageView import android.widget.LinearLayout import android.widget.TextView +import com.lt2333.simplicitytools.util.XSPUtils import com.lt2333.simplicitytools.util.hasEnable import com.lt2333.simplicitytools.util.hookAfterMethod import com.lt2333.simplicitytools.util.hookBeforeMethod @@ -18,6 +19,11 @@ import de.robv.android.xposed.callbacks.XC_LoadPackage class StatusBarBigMobileTypeIcon : IXposedHookLoadPackage { + val upAndDownPosition = XSPUtils.getInt("big_mobile_type_icon_up_and_down_position", 0) + val leftAndRightMargin = XSPUtils.getInt("big_mobile_type_icon_left_and_right_margins", 0) + val isBold = XSPUtils.getBoolean("big_mobile_type_icon_bold", true) + val size = XSPUtils.getFloat("big_mobile_type_icon_size", 12.5f) + override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) { hasEnable("big_mobile_type_icon") { "com.android.systemui.statusbar.StatusBarMobileView".hookAfterMethod( @@ -63,10 +69,13 @@ class StatusBarBigMobileTypeIcon : IXposedHookLoadPackage { val newLinearLayoutLP = LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT - ) + ).also { + + } val newLinearlayout = LinearLayout(context).also { it.layoutParams = newLinearLayoutLP it.id = mobile_container_left_ID + it.setPadding(leftAndRightMargin, 0, leftAndRightMargin, 0) } XposedHelpers.setObjectField(it.thisObject, "mMobileLeftContainer", newLinearlayout) RightParentLayout.addView( @@ -86,10 +95,13 @@ class StatusBarBigMobileTypeIcon : IXposedHookLoadPackage { LinearLayout.LayoutParams.WRAP_CONTENT ).also { it.gravity = Gravity.CENTER_VERTICAL + it.topMargin = upAndDownPosition } mobile_type.also { - it.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12.5F) - it.typeface = Typeface.DEFAULT_BOLD + it.setTextSize(TypedValue.COMPLEX_UNIT_DIP, size) + if (isBold) { + it.typeface = Typeface.DEFAULT_BOLD + } it.layoutParams = mobile_type_lp } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6a94d793..3d40707e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -182,4 +182,12 @@ Right Big Mobile Type Icon Make all notification can be slide to small window + Battery percentage font size + 0: do not change + Big mobile type icon size + Big mobile type icon bold + Big mobile type icon up and down position + Input error + Range: + Big mobile type icon left and right margins