mirror of
https://github.com/LittleTurtle2333/SimplicityTools.git
synced 2026-07-13 20:01:17 +08:00
新增状态栏时钟居右布局
This commit is contained in:
@@ -508,13 +508,47 @@ class SettingsActivity : MIUIActivity() {
|
||||
)
|
||||
add(LineV())
|
||||
add(TitleTextV(resId = R.string.status_bar_layout))
|
||||
val statusBarLayoutMode: HashMap<Int, String> = hashMapOf()
|
||||
statusBarLayoutMode[0] = getString(R.string.default1)
|
||||
statusBarLayoutMode[1] = getString(R.string.clock_center)
|
||||
statusBarLayoutMode[2] = getString(R.string.clock_right)
|
||||
add(
|
||||
TextSummaryWithSwitchV(
|
||||
TextSummaryV(
|
||||
textId = R.string.status_bar_time_center,
|
||||
tipsId = R.string.status_bar_layout_summary
|
||||
),
|
||||
SwitchV("status_bar_time_center")
|
||||
TextWithSpinnerV(
|
||||
TextV(resId = R.string.status_bar_layout_mode),
|
||||
SpinnerV(
|
||||
arrayListOf<MIUIPopupData>().apply {
|
||||
add(MIUIPopupData(statusBarLayoutMode[0].toString()) {
|
||||
OwnSP.ownSP.edit().run {
|
||||
putInt(
|
||||
"status_bar_layout_mode",
|
||||
0
|
||||
)
|
||||
apply()
|
||||
}
|
||||
})
|
||||
add(MIUIPopupData(statusBarLayoutMode[1].toString()) {
|
||||
OwnSP.ownSP.edit().run {
|
||||
putInt(
|
||||
"status_bar_layout_mode",
|
||||
1
|
||||
)
|
||||
apply()
|
||||
}
|
||||
})
|
||||
add(MIUIPopupData(statusBarLayoutMode[2].toString()) {
|
||||
OwnSP.ownSP.edit().run {
|
||||
putInt(
|
||||
"status_bar_layout_mode",
|
||||
2
|
||||
)
|
||||
apply()
|
||||
}
|
||||
})
|
||||
}, currentValue = statusBarLayoutMode[OwnSP.ownSP.getInt(
|
||||
"status_bar_layout_mode",
|
||||
0
|
||||
)].toString()
|
||||
)
|
||||
)
|
||||
)
|
||||
val layoutCompatibilityModeBinding = getDataBinding(
|
||||
|
||||
@@ -12,6 +12,7 @@ import android.widget.FrameLayout
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import cn.fkj233.ui.activity.dp2px
|
||||
import com.lt2333.simplicitytools.util.XSPUtils
|
||||
import com.lt2333.simplicitytools.util.findClass
|
||||
import com.lt2333.simplicitytools.util.getObjectField
|
||||
@@ -32,10 +33,17 @@ object StatusBarLayout: HookRegister() {
|
||||
private var statusBarBottom = 0
|
||||
|
||||
override fun init() {
|
||||
if (!XSPUtils.getBoolean("status_bar_time_center", false)) return
|
||||
val mode = XSPUtils.getInt("status_bar_layout_mode", 0)
|
||||
|
||||
when (mode) {
|
||||
//默认
|
||||
0 -> return
|
||||
//时钟居中
|
||||
1 -> {
|
||||
val collapsedStatusBarFragmentClass =
|
||||
"com.android.systemui.statusbar.phone.CollapsedStatusBarFragment".findClass(getDefaultClassLoader())
|
||||
"com.android.systemui.statusbar.phone.CollapsedStatusBarFragment".findClass(
|
||||
getDefaultClassLoader()
|
||||
)
|
||||
|
||||
collapsedStatusBarFragmentClass.hookAfterMethod(
|
||||
"onViewCreated",
|
||||
@@ -46,16 +54,25 @@ object StatusBarLayout: HookRegister() {
|
||||
param.thisObject.getObjectField("mStatusBar") as ViewGroup
|
||||
val context: Context = MiuiPhoneStatusBarView.context
|
||||
val res: Resources = MiuiPhoneStatusBarView.resources
|
||||
val statusBarId: Int = res.getIdentifier("status_bar", "id", "com.android.systemui")
|
||||
val statusBarId: Int =
|
||||
res.getIdentifier("status_bar", "id", "com.android.systemui")
|
||||
val statusBarContentsId: Int =
|
||||
res.getIdentifier("status_bar_contents", "id", "com.android.systemui")
|
||||
val systemIconAreaId: Int =
|
||||
res.getIdentifier("system_icon_area", "id", "com.android.systemui")
|
||||
val clockId: Int = res.getIdentifier("clock", "id", "com.android.systemui")
|
||||
val phoneStatusBarLeftContainerId: Int =
|
||||
res.getIdentifier("phone_status_bar_left_container", "id", "com.android.systemui")
|
||||
res.getIdentifier(
|
||||
"phone_status_bar_left_container",
|
||||
"id",
|
||||
"com.android.systemui"
|
||||
)
|
||||
val notificationIconAreaInnerId: Int =
|
||||
res.getIdentifier("notification_icon_area_inner", "id", "com.android.systemui")
|
||||
res.getIdentifier(
|
||||
"notification_icon_area_inner",
|
||||
"id",
|
||||
"com.android.systemui"
|
||||
)
|
||||
statusBar = MiuiPhoneStatusBarView.findViewById(statusBarId)
|
||||
val statusBarContents: ViewGroup =
|
||||
MiuiPhoneStatusBarView.findViewById(statusBarContentsId)
|
||||
@@ -141,20 +158,11 @@ object StatusBarLayout: HookRegister() {
|
||||
}
|
||||
updateLayout(context)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
val phoneStatusBarViewClass =
|
||||
"com.android.systemui.statusbar.phone.PhoneStatusBarView".findClass(getDefaultClassLoader())
|
||||
|
||||
phoneStatusBarViewClass.hookAfterMethod("updateLayoutForCutout") {
|
||||
if (XSPUtils.getBoolean("layout_compatibility_mode", false)) {
|
||||
val context = (it.thisObject as ViewGroup).context
|
||||
updateLayout(context)
|
||||
}
|
||||
}
|
||||
val miuiPhoneStatusBarViewClass =
|
||||
"com.android.systemui.statusbar.phone.MiuiPhoneStatusBarView".findClass(getDefaultClassLoader())
|
||||
"com.android.systemui.statusbar.phone.MiuiPhoneStatusBarView".findClass(
|
||||
getDefaultClassLoader()
|
||||
)
|
||||
|
||||
miuiPhoneStatusBarViewClass.hookAfterMethod("updateNotificationIconAreaInnnerParent") {
|
||||
val viewGroup = it.thisObject as ViewGroup
|
||||
@@ -164,6 +172,51 @@ object StatusBarLayout: HookRegister() {
|
||||
)
|
||||
viewGroup.layoutParams = fullscreen_notification_icon_area_lp
|
||||
}
|
||||
val phoneStatusBarViewClass =
|
||||
"com.android.systemui.statusbar.phone.PhoneStatusBarView".findClass(
|
||||
getDefaultClassLoader()
|
||||
)
|
||||
|
||||
phoneStatusBarViewClass.hookAfterMethod("updateLayoutForCutout") {
|
||||
if (XSPUtils.getBoolean("layout_compatibility_mode", false)) {
|
||||
val context = (it.thisObject as ViewGroup).context
|
||||
updateLayout(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
//时钟居右
|
||||
2 -> {
|
||||
val collapsedStatusBarFragmentClass =
|
||||
"com.android.systemui.statusbar.phone.CollapsedStatusBarFragment".findClass(
|
||||
getDefaultClassLoader()
|
||||
)
|
||||
|
||||
collapsedStatusBarFragmentClass.hookAfterMethod(
|
||||
"onViewCreated",
|
||||
View::class.java,
|
||||
Bundle::class.java
|
||||
) { param ->
|
||||
val MiuiPhoneStatusBarView: ViewGroup =
|
||||
param.thisObject.getObjectField("mStatusBar") as ViewGroup
|
||||
val context: Context = MiuiPhoneStatusBarView.context
|
||||
val res: Resources = MiuiPhoneStatusBarView.resources
|
||||
|
||||
val statusBarId: Int =
|
||||
res.getIdentifier("status_bar", "id", "com.android.systemui")
|
||||
val clockId: Int = res.getIdentifier("clock", "id", "com.android.systemui")
|
||||
val batteryId: Int = res.getIdentifier("battery", "id", "com.android.systemui")
|
||||
|
||||
statusBar = MiuiPhoneStatusBarView.findViewById(statusBarId)
|
||||
if (statusBar == null) return@hookAfterMethod
|
||||
val clock: TextView = MiuiPhoneStatusBarView.findViewById(clockId)
|
||||
val battery: ViewGroup = MiuiPhoneStatusBarView.findViewById(batteryId)
|
||||
|
||||
(clock.parent as ViewGroup).removeView(clock)
|
||||
battery!!.addView(clock)
|
||||
clock.setPadding(dp2px(context,5f),0,0,0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -193,4 +193,8 @@
|
||||
<string name="cast">Cast</string>
|
||||
<string name="force_support_send_app">Force all apps support open on another device</string>
|
||||
<string name="status_bar_time_double_line_center_align">Dual row center align</string>
|
||||
<string name="default1">Default</string>
|
||||
<string name="clock_center">Clock Center</string>
|
||||
<string name="clock_right">Clock Right</string>
|
||||
<string name="status_bar_layout_mode">Status bar layout mode</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user