Compare commits

4 Commits

Author SHA1 Message Date
LittleTurtle2333
12848808d3 修复A12状态栏布局兼容模式的一些BUG 2023-02-19 23:03:29 +08:00
LittleTurtle2333
7f23f07209 修复状态栏布局兼容模式的一些BUG 2023-02-19 17:11:25 +08:00
乌堆小透明
54b31ea478 Update dev.yml 2023-02-19 16:25:40 +08:00
乌堆小透明
44e6995da1 Create dev.yml 2023-02-19 16:19:12 +08:00
4 changed files with 356 additions and 213 deletions

50
.github/workflows/dev.yml vendored Normal file
View File

@@ -0,0 +1,50 @@
name: Dev
on:
push:
branches: [ "main" ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Clone UI
run: |
cd blockmiui
git submodule init
git submodule update
- name: Build with Gradle
run: |
bash ./gradlew assembleDebug
- name: Sign Debug APK
if: success()
id: sign_debug
uses: r0adkll/sign-android-release@v1.0.4
with:
releaseDirectory: ./app/build/outputs/apk/debug
signingKeyBase64: ${{ secrets.SIGNING_KEY }}
alias: ${{ secrets.KEY_STORE_ALIAS }}
keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
keyPassword: ${{ secrets.KEY_STORE_PASSWORD }}
- name: Upload Debug APK
uses: actions/upload-artifact@v2
with:
name: WooBox_Debug
path: ${{ steps.sign_debug.outputs.signedReleaseFile }}

View File

@@ -12,10 +12,9 @@ import cn.fkj233.ui.activity.view.TextSummaryV
import cn.fkj233.ui.activity.view.TextV import cn.fkj233.ui.activity.view.TextV
import cn.fkj233.ui.dialog.MIUIDialog import cn.fkj233.ui.dialog.MIUIDialog
import com.lt2333.simplicitytools.R import com.lt2333.simplicitytools.R
import java.util.HashMap
@BMPage("scope_systemui","System UI", hideMenu = false) @BMPage("scope_systemui", "System UI", hideMenu = false)
class SystemUIPageForS : BasePage() { class SystemUIPageForS : BasePage() {
override fun onCreate() { override fun onCreate() {
@@ -54,11 +53,10 @@ class SystemUIPageForS : BasePage() {
} }
}) })
val layoutCompatibilityModeBinding = GetDataBinding({ val layoutCompatibilityBinding = GetDataBinding({
MIUIActivity.safeSP.getInt( MIUIActivity.safeSP.getBoolean(
"screen_hole_location", "layout_compatibility_mode", false
0 )
) == 2
}) { view, flags, data -> }) { view, flags, data ->
when (flags) { when (flags) {
1 -> (view as Switch).isEnabled = data as Boolean 1 -> (view as Switch).isEnabled = data as Boolean
@@ -66,57 +64,23 @@ class SystemUIPageForS : BasePage() {
} }
} }
val screenHoleLocation: HashMap<Int, String> = hashMapOf<Int, String>().also { TextSummaryWithSwitch(
it[0] = getString(R.string.off)
it[1] = getString(R.string.center)
it[2] = getString(R.string.left_or_right)
}
TextSummaryWithSpinner(
TextSummaryV( TextSummaryV(
textId = R.string.layout_compatibility_mode, textId = R.string.layout_compatibility_mode, tipsId = R.string.layout_compatibility_mode_summary
tipsId = R.string.screen_hole_location ), SwitchV("layout_compatibility_mode", dataBindingSend = layoutCompatibilityBinding.bindingSend)
), )
SpinnerV(
screenHoleLocation[MIUIActivity.safeSP.getInt(
"screen_hole_location",
0
)].toString()
) {
add(screenHoleLocation[0].toString()) {
MIUIActivity.safeSP.putAny("screen_hole_location", 0)
layoutCompatibilityModeBinding.binding.Send().send(false)
}
add(screenHoleLocation[1].toString()) {
MIUIActivity.safeSP.putAny("screen_hole_location", 1)
layoutCompatibilityModeBinding.binding.Send().send(false)
}
add(screenHoleLocation[2].toString()) {
MIUIActivity.safeSP.putAny("screen_hole_location", 2)
layoutCompatibilityModeBinding.binding.Send().send(true)
}
})
Text( Text(
textId = R.string.left_margin, textId = R.string.left_margin, dataBindingRecv = layoutCompatibilityBinding.binding.getRecv(2)
dataBindingRecv = layoutCompatibilityModeBinding.binding.getRecv(2)
) )
SeekBarWithText( SeekBarWithText(
"status_bar_left_margin", "status_bar_left_margin", 0, 300, 0, dataBindingRecv = layoutCompatibilityBinding.binding.getRecv(2)
0,
300,
0,
dataBindingRecv = layoutCompatibilityModeBinding.binding.getRecv(2)
) )
Text( Text(
textId = R.string.right_margin, textId = R.string.right_margin, dataBindingRecv = layoutCompatibilityBinding.binding.getRecv(2)
dataBindingRecv = layoutCompatibilityModeBinding.binding.getRecv(2)
) )
SeekBarWithText( SeekBarWithText(
"status_bar_right_margin", "status_bar_right_margin", 0, 300, 0, dataBindingRecv = layoutCompatibilityBinding.binding.getRecv(2)
0,
300,
0,
dataBindingRecv = layoutCompatibilityModeBinding.binding.getRecv(2)
) )
Line() Line()
TitleText(textId = R.string.status_bar_clock_format) TitleText(textId = R.string.status_bar_clock_format)
@@ -248,7 +212,11 @@ class SystemUIPageForS : BasePage() {
TextSummaryWithArrow(TextSummaryV(textId = R.string.custom_clock_format_geek) { TextSummaryWithArrow(TextSummaryV(textId = R.string.custom_clock_format_geek) {
MIUIDialog(activity) { MIUIDialog(activity) {
setTitle(R.string.custom_clock_format_geek) setTitle(R.string.custom_clock_format_geek)
setEditText(MIUIActivity.safeSP.getString("custom_clock_format_geek", "HH:mm:ss"), "", isSingleLine = false) setEditText(
MIUIActivity.safeSP.getString("custom_clock_format_geek", "HH:mm:ss"),
"",
isSingleLine = false
)
setLButton(textId = R.string.cancel) { setLButton(textId = R.string.cancel) {
dismiss() dismiss()
} }

View File

@@ -1,5 +1,6 @@
package com.lt2333.simplicitytools.hooks.rules.s.systemui package com.lt2333.simplicitytools.hooks.rules.s.systemui
import android.app.KeyguardManager import android.app.KeyguardManager
import android.content.Context import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
@@ -16,10 +17,11 @@ import com.lt2333.simplicitytools.utils.XSPUtils
import com.lt2333.simplicitytools.utils.hasEnable import com.lt2333.simplicitytools.utils.hasEnable
import com.lt2333.simplicitytools.utils.xposed.base.HookRegister import com.lt2333.simplicitytools.utils.xposed.base.HookRegister
object StatusBarLayoutForS : HookRegister() { object StatusBarLayoutForS : HookRegister() {
private val getMode = XSPUtils.getInt("status_bar_layout_mode", 0) private val getMode = XSPUtils.getInt("status_bar_layout_mode", 0)
private val getHoleLocation = XSPUtils.getInt("screen_hole_location", 0) private val isCompatibilityMode = XSPUtils.getBoolean("layout_compatibility_mode", false)
private var statusBarLeft = 0 private var statusBarLeft = 0
private var statusBarTop = 0 private var statusBarTop = 0
@@ -32,23 +34,31 @@ object StatusBarLayoutForS : HookRegister() {
var mCenterLayout: LinearLayout? var mCenterLayout: LinearLayout?
var statusBar: ViewGroup? = null var statusBar: ViewGroup? = null
fun updateLayout(context: Context) { //判断屏幕状态更新布局 mode: 1正常布局 2居中布局
//判断屏幕方向 fun updateLayout(context: Context,mode: Int) {
val mConfiguration: Configuration = context.resources.configuration when(mode){
if (mConfiguration.orientation == Configuration.ORIENTATION_PORTRAIT) { 1->{
mLeftLayout!!.setPadding(statusBarLeft, 0, 0, 0) val mConfiguration: Configuration = context.resources.configuration
mRightLayout!!.setPadding(0, 0, statusBarRight, 0) if (mConfiguration.orientation == Configuration.ORIENTATION_PORTRAIT) { //横屏
statusBar!!.setPadding(0, statusBarTop, 0, statusBarBottom) statusBar!!.setPadding(statusBarLeft, statusBarTop, statusBarRight, statusBarBottom)
} else { }
//横屏状态 }
mLeftLayout!!.setPadding(175, 0, 0, 0) 2->{
mRightLayout!!.setPadding(0, 0, 175, 0) val mConfiguration: Configuration = context.resources.configuration
statusBar!!.setPadding(0, statusBarTop, 0, statusBarBottom) if (mConfiguration.orientation == Configuration.ORIENTATION_PORTRAIT) { //横屏
mLeftLayout!!.setPadding(statusBarLeft, 0, 0, 0)
mRightLayout!!.setPadding(0, 0, statusBarRight, 0)
statusBar!!.setPadding(0, statusBarTop, 0, statusBarBottom)
}else{ //竖屏
mLeftLayout!!.setPadding(0, 0, 0, 0)
mRightLayout!!.setPadding(0, 0, 0, 0)
}
}
} }
} }
//判断是否开启居中挖孔兼容模式 //判断是否开启挖孔兼容模式
if (getHoleLocation == 1) { if (isCompatibilityMode) {
findMethod("com.android.systemui.ScreenDecorations\$DisplayCutoutView") { findMethod("com.android.systemui.ScreenDecorations\$DisplayCutoutView") {
name == "boundsFromDirection" && parameterCount == 3 && isStatic name == "boundsFromDirection" && parameterCount == 3 && isStatic
}.hookBefore { }.hookBefore {
@@ -56,48 +66,83 @@ object StatusBarLayoutForS : HookRegister() {
} }
} }
//修改对应布局
when (getMode) { when (getMode) {
//默认 //默认
0 -> return 0 -> {
findMethod("com.android.systemui.statusbar.phone.CollapsedStatusBarFragment") {
name == "onViewCreated" && parameterCount == 2
}.hookAfter { param ->
val miuiPhoneStatusBarView = param.thisObject.getObjectAs<ViewGroup>("mStatusBar")
val context: Context = miuiPhoneStatusBarView.context
val res: Resources = miuiPhoneStatusBarView.resources
val statusBarId: Int = res.getIdentifier("status_bar", "id", "com.android.systemui")
statusBar = miuiPhoneStatusBarView.findViewById(statusBarId)
if (statusBar == null) return@hookAfter
statusBarLeft = statusBar!!.paddingLeft
statusBarTop = statusBar!!.paddingTop
statusBarRight = statusBar!!.paddingRight
statusBarBottom = statusBar!!.paddingBottom
if (isCompatibilityMode) {
val customLeftMargin = XSPUtils.getInt("status_bar_left_margin", 0)
if (customLeftMargin != 0) {
statusBarLeft = customLeftMargin
}
val customRightMargin = XSPUtils.getInt("status_bar_right_margin", 0)
if (customRightMargin != 0) {
statusBarRight = customRightMargin
}
updateLayout(context,1)
}
}
//兼容模式
findMethod("com.android.systemui.statusbar.phone.PhoneStatusBarView") {
name == "updateLayoutForCutout"
}.hookAfter {
if (isCompatibilityMode) {
val context = (it.thisObject as ViewGroup).context
updateLayout(context,1)
}
}
}
//时钟居中 //时钟居中
1 -> { 1 -> {
findMethod("com.android.systemui.statusbar.phone.CollapsedStatusBarFragment") { findMethod("com.android.systemui.statusbar.phone.CollapsedStatusBarFragment") {
name == "onViewCreated" && parameterCount == 2 name == "onViewCreated" && parameterCount == 2
}.hookAfter { param -> }.hookAfter { param ->
val miuiPhoneStatusBarView = val miuiPhoneStatusBarView = param.thisObject.getObjectAs<ViewGroup>("mStatusBar")
param.thisObject.getObjectAs<ViewGroup>("mStatusBar")
val context: Context = miuiPhoneStatusBarView.context val context: Context = miuiPhoneStatusBarView.context
val res: Resources = miuiPhoneStatusBarView.resources val res: Resources = miuiPhoneStatusBarView.resources
val statusBarId: Int = val statusBarId: Int = res.getIdentifier("status_bar", "id", "com.android.systemui")
res.getIdentifier("status_bar", "id", "com.android.systemui") val statusBarContentsId: Int = res.getIdentifier(
val statusBarContentsId: Int = "status_bar_contents", "id", "com.android.systemui"
res.getIdentifier("status_bar_contents", "id", "com.android.systemui") )
val systemIconAreaId: Int = val systemIconAreaId: Int = res.getIdentifier("system_icon_area", "id", "com.android.systemui")
res.getIdentifier("system_icon_area", "id", "com.android.systemui")
val clockId: Int = res.getIdentifier("clock", "id", "com.android.systemui") val clockId: Int = res.getIdentifier("clock", "id", "com.android.systemui")
val phoneStatusBarLeftContainerId: Int = val phoneStatusBarLeftContainerId: Int = res.getIdentifier(
res.getIdentifier( "phone_status_bar_left_container", "id", "com.android.systemui"
"phone_status_bar_left_container", )
"id", val notificationIconAreaInnerId: Int = res.getIdentifier(
"com.android.systemui" "notification_icon_area_inner", "id", "com.android.systemui"
) )
val notificationIconAreaInnerId: Int =
res.getIdentifier(
"notification_icon_area_inner",
"id",
"com.android.systemui"
)
statusBar = miuiPhoneStatusBarView.findViewById(statusBarId) statusBar = miuiPhoneStatusBarView.findViewById(statusBarId)
val statusBarContents: ViewGroup = val statusBarContents: ViewGroup = miuiPhoneStatusBarView.findViewById(statusBarContentsId)
miuiPhoneStatusBarView.findViewById(statusBarContentsId)
if (statusBar == null) return@hookAfter if (statusBar == null) return@hookAfter
val clock: TextView = miuiPhoneStatusBarView.findViewById(clockId) val clock: TextView = miuiPhoneStatusBarView.findViewById(clockId)
val phoneStatusBarLeftContainer: ViewGroup = val phoneStatusBarLeftContainer: ViewGroup = miuiPhoneStatusBarView.findViewById(
miuiPhoneStatusBarView.findViewById(phoneStatusBarLeftContainerId) phoneStatusBarLeftContainerId
val notificationIconAreaInner: ViewGroup = )
miuiPhoneStatusBarView.findViewById(notificationIconAreaInnerId) val notificationIconAreaInner: ViewGroup = miuiPhoneStatusBarView.findViewById(
val systemIconArea: ViewGroup = notificationIconAreaInnerId
miuiPhoneStatusBarView.findViewById(systemIconAreaId) )
val systemIconArea: ViewGroup = miuiPhoneStatusBarView.findViewById(systemIconAreaId)
(clock.parent as ViewGroup).removeView(clock) (clock.parent as ViewGroup).removeView(clock)
(phoneStatusBarLeftContainer.parent as ViewGroup).removeView( (phoneStatusBarLeftContainer.parent as ViewGroup).removeView(
@@ -108,41 +153,39 @@ object StatusBarLayoutForS : HookRegister() {
) )
(systemIconArea.parent as ViewGroup).removeView(systemIconArea) (systemIconArea.parent as ViewGroup).removeView(systemIconArea)
val mConstraintLayout = val mConstraintLayout = ConstraintLayout(context).also {
ConstraintLayout(context).also { it.layoutParams = ConstraintLayout.LayoutParams(
it.layoutParams = ConstraintLayout.LayoutParams( ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT
ConstraintLayout.LayoutParams.MATCH_PARENT, )
ConstraintLayout.LayoutParams.MATCH_PARENT }
)
}
mConstraintLayout.addView(notificationIconAreaInner) mConstraintLayout.addView(notificationIconAreaInner)
val fullscreenNotificationIconAreaLp = LinearLayout.LayoutParams( val fullscreenNotificationIconAreaLp = LinearLayout.LayoutParams(
ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT
ConstraintLayout.LayoutParams.MATCH_PARENT
) )
notificationIconAreaInner.layoutParams = fullscreenNotificationIconAreaLp notificationIconAreaInner.layoutParams = fullscreenNotificationIconAreaLp
//增加一个左对齐布局 //增加一个左对齐布局
mLeftLayout = LinearLayout(context) mLeftLayout = LinearLayout(context)
val leftLp: LinearLayout.LayoutParams = val leftLp: LinearLayout.LayoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f) 0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f
)
mLeftLayout!!.layoutParams = leftLp mLeftLayout!!.layoutParams = leftLp
mLeftLayout!!.gravity = Gravity.START or Gravity.CENTER_VERTICAL mLeftLayout!!.gravity = Gravity.START or Gravity.CENTER_VERTICAL
//增加一个居中布局 //增加一个居中布局
mCenterLayout = LinearLayout(context) mCenterLayout = LinearLayout(context)
val centerLp: LinearLayout.LayoutParams = LinearLayout.LayoutParams( val centerLp: LinearLayout.LayoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT
LinearLayout.LayoutParams.MATCH_PARENT
) )
mCenterLayout!!.layoutParams = centerLp mCenterLayout!!.layoutParams = centerLp
mCenterLayout!!.gravity = Gravity.CENTER or Gravity.CENTER_VERTICAL mCenterLayout!!.gravity = Gravity.CENTER or Gravity.CENTER_VERTICAL
mRightLayout = LinearLayout(context) mRightLayout = LinearLayout(context)
val rightLp: LinearLayout.LayoutParams = val rightLp: LinearLayout.LayoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f) 0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f
)
mRightLayout!!.layoutParams = rightLp mRightLayout!!.layoutParams = rightLp
mRightLayout!!.gravity = Gravity.END or Gravity.CENTER_VERTICAL mRightLayout!!.gravity = Gravity.END or Gravity.CENTER_VERTICAL
mLeftLayout!!.addView(phoneStatusBarLeftContainer) mLeftLayout!!.addView(phoneStatusBarLeftContainer)
@@ -160,7 +203,7 @@ object StatusBarLayoutForS : HookRegister() {
statusBarBottom = statusBar!!.paddingBottom statusBarBottom = statusBar!!.paddingBottom
if (getHoleLocation == 2) { if (isCompatibilityMode) {
val customLeftMargin = XSPUtils.getInt("status_bar_left_margin", 0) val customLeftMargin = XSPUtils.getInt("status_bar_left_margin", 0)
if (customLeftMargin != 0) { if (customLeftMargin != 0) {
statusBarLeft = customLeftMargin statusBarLeft = customLeftMargin
@@ -170,7 +213,7 @@ object StatusBarLayoutForS : HookRegister() {
if (customRightMargin != 0) { if (customRightMargin != 0) {
statusBarRight = customRightMargin statusBarRight = customRightMargin
} }
updateLayout(context) updateLayout(context,2)
} }
} }
@@ -179,7 +222,7 @@ object StatusBarLayoutForS : HookRegister() {
}.hookAfter { }.hookAfter {
hasEnable("layout_compatibility_mode") { hasEnable("layout_compatibility_mode") {
val context = (it.thisObject as ViewGroup).context val context = (it.thisObject as ViewGroup).context
updateLayout(context) updateLayout(context,2)
} }
} }
} }
@@ -188,14 +231,12 @@ object StatusBarLayoutForS : HookRegister() {
findMethod("com.android.systemui.statusbar.phone.CollapsedStatusBarFragment") { findMethod("com.android.systemui.statusbar.phone.CollapsedStatusBarFragment") {
name == "onViewCreated" && parameterCount == 2 name == "onViewCreated" && parameterCount == 2
}.hookAfter { param -> }.hookAfter { param ->
val miuiPhoneStatusBarView = val miuiPhoneStatusBarView = param.thisObject.getObjectAs<ViewGroup>("mStatusBar")
param.thisObject.getObjectAs<ViewGroup>("mStatusBar")
val context: Context = miuiPhoneStatusBarView.context val context: Context = miuiPhoneStatusBarView.context
val res: Resources = miuiPhoneStatusBarView.resources val res: Resources = miuiPhoneStatusBarView.resources
//组件ID //组件ID
val statusBarId: Int = val statusBarId: Int = res.getIdentifier("status_bar", "id", "com.android.systemui")
res.getIdentifier("status_bar", "id", "com.android.systemui")
val clockId: Int = res.getIdentifier("clock", "id", "com.android.systemui") val clockId: Int = res.getIdentifier("clock", "id", "com.android.systemui")
val batteryId: Int = res.getIdentifier("battery", "id", "com.android.systemui") val batteryId: Int = res.getIdentifier("battery", "id", "com.android.systemui")
@@ -207,8 +248,7 @@ object StatusBarLayoutForS : HookRegister() {
//新建布局 //新建布局
val rightLp = LinearLayout.LayoutParams( val rightLp = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT
LinearLayout.LayoutParams.MATCH_PARENT
).also { ).also {
it.marginStart = dp2px(context, 5f) it.marginStart = dp2px(context, 5f)
} }
@@ -220,6 +260,36 @@ object StatusBarLayoutForS : HookRegister() {
battery.addView(mRightLayout) battery.addView(mRightLayout)
(clock.parent as ViewGroup).removeView(clock) (clock.parent as ViewGroup).removeView(clock)
mRightLayout!!.addView(clock) mRightLayout!!.addView(clock)
statusBarLeft = statusBar!!.paddingLeft
statusBarTop = statusBar!!.paddingTop
statusBarRight = statusBar!!.paddingRight
statusBarBottom = statusBar!!.paddingBottom
if (isCompatibilityMode) {
val customLeftMargin = XSPUtils.getInt("status_bar_left_margin", 0)
if (customLeftMargin != 0) {
statusBarLeft = customLeftMargin
}
val customRightMargin = XSPUtils.getInt("status_bar_right_margin", 0)
if (customRightMargin != 0) {
statusBarRight = customRightMargin
}
updateLayout(context,1)
}
}
//兼容模式
findMethod("com.android.systemui.statusbar.phone.PhoneStatusBarView") {
name == "updateLayoutForCutout"
}.hookAfter {
if (isCompatibilityMode) {
val context = (it.thisObject as ViewGroup).context
updateLayout(context,1)
}
} }
} }
//时钟居中+图标居左 //时钟居中+图标居左
@@ -227,65 +297,45 @@ object StatusBarLayoutForS : HookRegister() {
findMethod("com.android.systemui.statusbar.phone.CollapsedStatusBarFragment") { findMethod("com.android.systemui.statusbar.phone.CollapsedStatusBarFragment") {
name == "onViewCreated" && parameterCount == 2 name == "onViewCreated" && parameterCount == 2
}.hookAfter { param -> }.hookAfter { param ->
val miuiPhoneStatusBarView = val miuiPhoneStatusBarView = param.thisObject.getObjectAs<ViewGroup>("mStatusBar")
param.thisObject.getObjectAs<ViewGroup>("mStatusBar")
val context: Context = miuiPhoneStatusBarView.context val context: Context = miuiPhoneStatusBarView.context
val res: Resources = miuiPhoneStatusBarView.resources val res: Resources = miuiPhoneStatusBarView.resources
val statusBarId: Int = val statusBarId: Int = res.getIdentifier("status_bar", "id", "com.android.systemui")
res.getIdentifier("status_bar", "id", "com.android.systemui") val statusBarContentsId: Int = res.getIdentifier(
val statusBarContentsId: Int = "status_bar_contents", "id", "com.android.systemui"
res.getIdentifier("status_bar_contents", "id", "com.android.systemui") )
val systemIconAreaId: Int = val systemIconAreaId: Int = res.getIdentifier("system_icon_area", "id", "com.android.systemui")
res.getIdentifier("system_icon_area", "id", "com.android.systemui")
val clockId: Int = res.getIdentifier("clock", "id", "com.android.systemui") val clockId: Int = res.getIdentifier("clock", "id", "com.android.systemui")
val phoneStatusBarLeftContainerId: Int = val phoneStatusBarLeftContainerId: Int = res.getIdentifier(
res.getIdentifier( "phone_status_bar_left_container", "id", "com.android.systemui"
"phone_status_bar_left_container", )
"id", val fullscreenNotificationIconAreaId: Int = res.getIdentifier(
"com.android.systemui" "fullscreen_notification_icon_area", "id", "com.android.systemui"
) )
val fullscreenNotificationIconAreaId: Int = val statusIconsId: Int = res.getIdentifier(
res.getIdentifier( "statusIcons", "id", "com.android.systemui"
"fullscreen_notification_icon_area", )
"id", val systemIconsId: Int = res.getIdentifier(
"com.android.systemui" "system_icons", "id", "com.android.systemui"
) )
val statusIconsId: Int = val batteryId: Int = res.getIdentifier(
res.getIdentifier( "battery", "id", "com.android.systemui"
"statusIcons", )
"id",
"com.android.systemui"
)
val systemIconsId: Int =
res.getIdentifier(
"system_icons",
"id",
"com.android.systemui"
)
val batteryId: Int =
res.getIdentifier(
"battery",
"id",
"com.android.systemui"
)
statusBar = miuiPhoneStatusBarView.findViewById(statusBarId) statusBar = miuiPhoneStatusBarView.findViewById(statusBarId)
val statusBarContents: ViewGroup = val statusBarContents: ViewGroup = miuiPhoneStatusBarView.findViewById(statusBarContentsId)
miuiPhoneStatusBarView.findViewById(statusBarContentsId)
if (statusBar == null) return@hookAfter if (statusBar == null) return@hookAfter
val clock: TextView = miuiPhoneStatusBarView.findViewById(clockId) val clock: TextView = miuiPhoneStatusBarView.findViewById(clockId)
val phoneStatusBarLeftContainer: ViewGroup = val phoneStatusBarLeftContainer: ViewGroup = miuiPhoneStatusBarView.findViewById(
miuiPhoneStatusBarView.findViewById(phoneStatusBarLeftContainerId) phoneStatusBarLeftContainerId
val fullscreenNotificationIconArea: ViewGroup = )
miuiPhoneStatusBarView.findViewById(fullscreenNotificationIconAreaId) val fullscreenNotificationIconArea: ViewGroup = miuiPhoneStatusBarView.findViewById(
val systemIconArea: ViewGroup = fullscreenNotificationIconAreaId
miuiPhoneStatusBarView.findViewById(systemIconAreaId) )
val statusIcons: ViewGroup = val systemIconArea: ViewGroup = miuiPhoneStatusBarView.findViewById(systemIconAreaId)
miuiPhoneStatusBarView.findViewById(statusIconsId) val statusIcons: ViewGroup = miuiPhoneStatusBarView.findViewById(statusIconsId)
val systemIcons: ViewGroup = val systemIcons: ViewGroup = miuiPhoneStatusBarView.findViewById(systemIconsId)
miuiPhoneStatusBarView.findViewById(systemIconsId) val battery: ViewGroup = miuiPhoneStatusBarView.findViewById(batteryId)
val battery: ViewGroup =
miuiPhoneStatusBarView.findViewById(batteryId)
(clock.parent as ViewGroup).removeView(clock) (clock.parent as ViewGroup).removeView(clock)
(phoneStatusBarLeftContainer.parent as ViewGroup).removeView( (phoneStatusBarLeftContainer.parent as ViewGroup).removeView(
@@ -299,29 +349,25 @@ object StatusBarLayoutForS : HookRegister() {
fullscreenNotificationIconArea fullscreenNotificationIconArea
) )
val mConstraintLayout = val mConstraintLayout = ConstraintLayout(context).also {
ConstraintLayout(context).also { it.layoutParams = ConstraintLayout.LayoutParams(
it.layoutParams = ConstraintLayout.LayoutParams( ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT
ConstraintLayout.LayoutParams.MATCH_PARENT, )
ConstraintLayout.LayoutParams.MATCH_PARENT }
)
}
mConstraintLayout.addView(fullscreenNotificationIconArea) mConstraintLayout.addView(fullscreenNotificationIconArea)
mConstraintLayout.addView(battery) mConstraintLayout.addView(battery)
battery.layoutParams = ConstraintLayout.LayoutParams( battery.layoutParams = ConstraintLayout.LayoutParams(
ConstraintLayout.LayoutParams.WRAP_CONTENT, ConstraintLayout.LayoutParams.WRAP_CONTENT, ConstraintLayout.LayoutParams.MATCH_PARENT
ConstraintLayout.LayoutParams.MATCH_PARENT
).also { ).also {
it.endToEnd = 0 it.endToEnd = 0
} }
fullscreenNotificationIconArea.layoutParams = ConstraintLayout.LayoutParams( fullscreenNotificationIconArea.layoutParams = ConstraintLayout.LayoutParams(
0, 0, ConstraintLayout.LayoutParams.MATCH_PARENT
ConstraintLayout.LayoutParams.MATCH_PARENT
).also { ).also {
it.startToEnd = batteryId it.startToEnd = batteryId
it.endToEnd = 0 it.endToEnd = 0
@@ -331,24 +377,25 @@ object StatusBarLayoutForS : HookRegister() {
//增加一个左对齐布局 //增加一个左对齐布局
mLeftLayout = LinearLayout(context) mLeftLayout = LinearLayout(context)
val leftLp: LinearLayout.LayoutParams = val leftLp: LinearLayout.LayoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f) 0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f
)
mLeftLayout!!.layoutParams = leftLp mLeftLayout!!.layoutParams = leftLp
mLeftLayout!!.gravity = Gravity.START or Gravity.CENTER_VERTICAL mLeftLayout!!.gravity = Gravity.START or Gravity.CENTER_VERTICAL
//增加一个居中布局 //增加一个居中布局
mCenterLayout = LinearLayout(context) mCenterLayout = LinearLayout(context)
val centerLp: LinearLayout.LayoutParams = LinearLayout.LayoutParams( val centerLp: LinearLayout.LayoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT
LinearLayout.LayoutParams.MATCH_PARENT
) )
mCenterLayout!!.layoutParams = centerLp mCenterLayout!!.layoutParams = centerLp
mCenterLayout!!.gravity = Gravity.CENTER or Gravity.CENTER_VERTICAL mCenterLayout!!.gravity = Gravity.CENTER or Gravity.CENTER_VERTICAL
//增加一个右布局 //增加一个右布局
mRightLayout = LinearLayout(context) mRightLayout = LinearLayout(context)
val rightLp: LinearLayout.LayoutParams = val rightLp: LinearLayout.LayoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f) 0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f
)
mRightLayout!!.layoutParams = rightLp mRightLayout!!.layoutParams = rightLp
mRightLayout!!.gravity = Gravity.END or Gravity.CENTER_VERTICAL mRightLayout!!.gravity = Gravity.END or Gravity.CENTER_VERTICAL
@@ -375,7 +422,7 @@ object StatusBarLayoutForS : HookRegister() {
statusBarBottom = statusBar!!.paddingBottom statusBarBottom = statusBar!!.paddingBottom
if (getHoleLocation == 2) { if (isCompatibilityMode) {
val customLeftMargin = XSPUtils.getInt("status_bar_left_margin", 0) val customLeftMargin = XSPUtils.getInt("status_bar_left_margin", 0)
if (customLeftMargin != 0) { if (customLeftMargin != 0) {
statusBarLeft = customLeftMargin statusBarLeft = customLeftMargin
@@ -385,16 +432,16 @@ object StatusBarLayoutForS : HookRegister() {
if (customRightMargin != 0) { if (customRightMargin != 0) {
statusBarRight = customRightMargin statusBarRight = customRightMargin
} }
updateLayout(context) updateLayout(context,2)
} }
} }
//兼容模式 //兼容模式
findMethod("com.android.systemui.statusbar.phone.PhoneStatusBarView") { findMethod("com.android.systemui.statusbar.phone.PhoneStatusBarView") {
name == "updateLayoutForCutout" name == "updateLayoutForCutout"
}.hookAfter { }.hookAfter {
if (getHoleLocation == 2) { if (isCompatibilityMode) {
val context = (it.thisObject as ViewGroup).context val context = (it.thisObject as ViewGroup).context
updateLayout(context) updateLayout(context,2)
} }
} }
@@ -404,12 +451,10 @@ object StatusBarLayoutForS : HookRegister() {
}.hookAfter { }.hookAfter {
val miuiPhoneStatusBarView = it.thisObject.getObjectAs<ViewGroup>("mStatusBar") val miuiPhoneStatusBarView = it.thisObject.getObjectAs<ViewGroup>("mStatusBar")
val res = miuiPhoneStatusBarView.resources val res = miuiPhoneStatusBarView.resources
val statusBarId = val statusBarId = res.getIdentifier("status_bar", "id", "com.android.systemui")
res.getIdentifier("status_bar", "id", "com.android.systemui")
val statusBar1 = miuiPhoneStatusBarView.findViewById<ViewGroup>(statusBarId) val statusBar1 = miuiPhoneStatusBarView.findViewById<ViewGroup>(statusBarId)
//非锁屏下整个状态栏布局 //非锁屏下整个状态栏布局
val keyguardMgr = val keyguardMgr = statusBar1.context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
statusBar1.context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
if (keyguardMgr.isKeyguardLocked) { if (keyguardMgr.isKeyguardLocked) {
statusBar1!!.visibility = View.GONE statusBar1!!.visibility = View.GONE
} else { } else {

View File

@@ -28,24 +28,31 @@ object StatusBarLayoutForT : HookRegister() {
private var statusBarBottom = 0 private var statusBarBottom = 0
override fun init() { override fun init() {
// TODO: Android13状态栏布局不可用
var mLeftLayout: LinearLayout? = null var mLeftLayout: LinearLayout? = null
var mRightLayout: LinearLayout? = null var mRightLayout: LinearLayout? = null
var mCenterLayout: LinearLayout? var mCenterLayout: LinearLayout?
var statusBar: ViewGroup? = null var statusBar: ViewGroup? = null
fun updateLayout(context: Context) { //判断屏幕状态更新布局 mode: 1正常布局 2居中布局
//判断屏幕方向 fun updateLayout(context: Context,mode: Int) {
val mConfiguration: Configuration = context.resources.configuration when(mode){
if (mConfiguration.orientation == Configuration.ORIENTATION_PORTRAIT) { 1->{
mLeftLayout!!.setPadding(statusBarLeft, 0, 0, 0) val mConfiguration: Configuration = context.resources.configuration
mRightLayout!!.setPadding(0, 0, statusBarRight, 0) if (mConfiguration.orientation == Configuration.ORIENTATION_PORTRAIT) { //横屏
statusBar!!.setPadding(0, statusBarTop, 0, statusBarBottom) statusBar!!.setPadding(statusBarLeft, statusBarTop, statusBarRight, statusBarBottom)
}else{ }
mLeftLayout!!.setPadding(0, 0, 0, 0) }
mRightLayout!!.setPadding(0, 0, 0, 0) 2->{
val mConfiguration: Configuration = context.resources.configuration
if (mConfiguration.orientation == Configuration.ORIENTATION_PORTRAIT) { //横屏
mLeftLayout!!.setPadding(statusBarLeft, 0, 0, 0)
mRightLayout!!.setPadding(0, 0, statusBarRight, 0)
statusBar!!.setPadding(0, statusBarTop, 0, statusBarBottom)
}else{ //竖屏
mLeftLayout!!.setPadding(0, 0, 0, 0)
mRightLayout!!.setPadding(0, 0, 0, 0)
}
}
} }
} }
@@ -58,9 +65,52 @@ object StatusBarLayoutForT : HookRegister() {
} }
} }
//修改对应布局
when (getMode) { when (getMode) {
//默认 //默认
0 -> return 0 -> {
findMethod("com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragment") {
name == "onViewCreated" && parameterCount == 2
}.hookAfter { param ->
val miuiPhoneStatusBarView = param.thisObject.getObjectAs<ViewGroup>("mStatusBar")
val context: Context = miuiPhoneStatusBarView.context
val res: Resources = miuiPhoneStatusBarView.resources
val statusBarId: Int = res.getIdentifier("status_bar", "id", "com.android.systemui")
statusBar = miuiPhoneStatusBarView.findViewById(statusBarId)
if (statusBar == null) return@hookAfter
statusBarLeft = statusBar!!.paddingLeft
statusBarTop = statusBar!!.paddingTop
statusBarRight = statusBar!!.paddingRight
statusBarBottom = statusBar!!.paddingBottom
if (isCompatibilityMode) {
val customLeftMargin = XSPUtils.getInt("status_bar_left_margin", 0)
if (customLeftMargin != 0) {
statusBarLeft = customLeftMargin
}
val customRightMargin = XSPUtils.getInt("status_bar_right_margin", 0)
if (customRightMargin != 0) {
statusBarRight = customRightMargin
}
updateLayout(context,1)
}
}
//兼容模式
findMethod("com.android.systemui.statusbar.phone.PhoneStatusBarView") {
name == "updateLayoutForCutout"
}.hookAfter {
if (isCompatibilityMode) {
val context = (it.thisObject as ViewGroup).context
updateLayout(context,1)
}
}
}
//时钟居中 //时钟居中
1 -> { 1 -> {
findMethod("com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragment") { findMethod("com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragment") {
@@ -162,7 +212,7 @@ object StatusBarLayoutForT : HookRegister() {
if (customRightMargin != 0) { if (customRightMargin != 0) {
statusBarRight = customRightMargin statusBarRight = customRightMargin
} }
updateLayout(context) updateLayout(context,2)
} }
} }
@@ -171,7 +221,7 @@ object StatusBarLayoutForT : HookRegister() {
}.hookAfter { }.hookAfter {
hasEnable("layout_compatibility_mode") { hasEnable("layout_compatibility_mode") {
val context = (it.thisObject as ViewGroup).context val context = (it.thisObject as ViewGroup).context
updateLayout(context) updateLayout(context,2)
} }
} }
} }
@@ -209,6 +259,36 @@ object StatusBarLayoutForT : HookRegister() {
battery.addView(mRightLayout) battery.addView(mRightLayout)
(clock.parent as ViewGroup).removeView(clock) (clock.parent as ViewGroup).removeView(clock)
mRightLayout!!.addView(clock) mRightLayout!!.addView(clock)
statusBarLeft = statusBar!!.paddingLeft
statusBarTop = statusBar!!.paddingTop
statusBarRight = statusBar!!.paddingRight
statusBarBottom = statusBar!!.paddingBottom
if (isCompatibilityMode) {
val customLeftMargin = XSPUtils.getInt("status_bar_left_margin", 0)
if (customLeftMargin != 0) {
statusBarLeft = customLeftMargin
}
val customRightMargin = XSPUtils.getInt("status_bar_right_margin", 0)
if (customRightMargin != 0) {
statusBarRight = customRightMargin
}
updateLayout(context,1)
}
}
//兼容模式
findMethod("com.android.systemui.statusbar.phone.PhoneStatusBarView") {
name == "updateLayoutForCutout"
}.hookAfter {
if (isCompatibilityMode) {
val context = (it.thisObject as ViewGroup).context
updateLayout(context,1)
}
} }
} }
//时钟居中+图标居左 //时钟居中+图标居左
@@ -351,7 +431,7 @@ object StatusBarLayoutForT : HookRegister() {
if (customRightMargin != 0) { if (customRightMargin != 0) {
statusBarRight = customRightMargin statusBarRight = customRightMargin
} }
updateLayout(context) updateLayout(context,2)
} }
} }
//兼容模式 //兼容模式
@@ -360,7 +440,7 @@ object StatusBarLayoutForT : HookRegister() {
}.hookAfter { }.hookAfter {
if (isCompatibilityMode) { if (isCompatibilityMode) {
val context = (it.thisObject as ViewGroup).context val context = (it.thisObject as ViewGroup).context
updateLayout(context) updateLayout(context,2)
} }
} }