Skip to content

Commit

Permalink
Optimize lockscreen items for Android 15 #730
Browse files Browse the repository at this point in the history
Signed-off-by: DrDisagree <29881338+Mahmud0808@users.noreply.github.com>
  • Loading branch information
Mahmud0808 committed Feb 2, 2025
1 parent c1f022e commit f60ba34
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -464,20 +464,32 @@ object ViewHelper {
fun View?.hideView() {
if (this == null) return

fun hide() {
fun makeInvisible() {
apply {
layoutParams.height = 0
layoutParams.width = 0
visibility = View.INVISIBLE
if (visibility == View.VISIBLE) {
visibility = View.INVISIBLE
}
}
}

hide()
fun makeSizeZero() {
apply {
layoutParams.apply {
if (height != 0) height = 0
if (width != 0) width = 0
}
}
}

makeSizeZero()
makeInvisible()

viewTreeObserver?.addOnGlobalLayoutListener {
hide()
makeSizeZero()
makeInvisible()
}
viewTreeObserver?.addOnDrawListener {
hide()
makeInvisible()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,14 @@ class LockscreenClockA15(context: Context) : ModPack(context) {
mContext.packageName
)

val keyguardStatusViewBottomMarginId = mContext.resources.getDimensionPixelSize(
mContext.resources.getIdentifier(
"keyguard_status_view_bottom_margin",
"dimen",
mContext.packageName
)
)

aodNotificationIconsSectionClass
.hookMethod("applyConstraints")
.runAfter { param ->
Expand All @@ -379,57 +387,42 @@ class LockscreenClockA15(context: Context) : ModPack(context) {
ConstraintSet.TOP,
mLsItemsContainer!!.id,
ConstraintSet.BOTTOM,
mContext.resources.getDimensionPixelSize(
mContext.resources.getIdentifier(
"keyguard_status_view_bottom_margin",
"dimen",
mContext.packageName
)
)
keyguardStatusViewBottomMarginId
)
}
}

val smartspaceSectionClass =
findClass("$SYSTEMUI_PACKAGE.keyguard.ui.view.layout.sections.SmartspaceSection")

val bcSmartSpaceViewId = mContext.resources.getIdentifier(
"bc_smartspace_view",
"id",
mContext.packageName
)
val dateSmartSpaceViewId = mContext.resources.getIdentifier(
"date_smartspace_view",
"id",
mContext.packageName
)
val keyguardSliceViewId = mContext.resources.getIdentifier(
"keyguard_slice_view",
"id",
mContext.packageName
)
val smartspaceViewIds = listOf(
bcSmartSpaceViewId,
dateSmartSpaceViewId,
keyguardSliceViewId
).filter { it != -1 }

smartspaceSectionClass
.hookMethod("applyConstraints")
.runAfter { param ->
if (!showLockscreenClock) return@runAfter

val constraintSet = param.args[0]

val smartspaceViewIdNames = listOf(
"bc_smartspace_view",
"date_smartspace_view",
"keyguard_slice_view"
)

val bcSmartSpaceViewId = mContext.resources.getIdentifier(
smartspaceViewIdNames[0],
"id",
mContext.packageName
)

val dateSmartSpaceViewId = mContext.resources.getIdentifier(
smartspaceViewIdNames[1],
"id",
mContext.packageName
)

val keyguardSliceViewId = mContext.resources.getIdentifier(
smartspaceViewIdNames[2],
"id",
mContext.packageName
)

val smartspaceViewIds = listOf(
bcSmartSpaceViewId,
dateSmartSpaceViewId,
keyguardSliceViewId
).filter { it != -1 }

// Connect bc smartspace to bottom of date smartspace
constraintSet.clear(
bcSmartSpaceViewId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,26 +318,29 @@ class LockscreenWeatherA15(context: Context) : ModPack(context) {
val smartspaceSectionClass =
findClass("$SYSTEMUI_PACKAGE.keyguard.ui.view.layout.sections.SmartspaceSection")

val bcSmartSpaceViewId = mContext.resources.getIdentifier(
"bc_smartspace_view",
"id",
mContext.packageName
)
val dateSmartSpaceViewId = mContext.resources.getIdentifier(
"date_smartspace_view",
"id",
mContext.packageName
)

smartspaceSectionClass
.hookMethod("applyConstraints")
.runAfter { param ->
if (!mWeatherEnabled) return@runAfter

val constraintSet = param.args[0]

val dateSmartSpaceViewId = if (dateSmartSpaceViewAvailable) {
mContext.resources.getIdentifier(
"date_smartspace_view",
"id",
mContext.packageName
)
val smartSpaceViewId = if (dateSmartSpaceViewAvailable) {
dateSmartSpaceViewId
} else {
// Some ROMs don't have date smartspace view
mContext.resources.getIdentifier(
"bc_smartspace_view",
"id",
mContext.packageName
)
bcSmartSpaceViewId
}

// Connect weather view to bottom of date smartspace
Expand All @@ -349,7 +352,7 @@ class LockscreenWeatherA15(context: Context) : ModPack(context) {
constraintSet.connect(
mLsItemsContainer!!.id,
ConstraintSet.TOP,
dateSmartSpaceViewId,
smartSpaceViewId,
ConstraintSet.BOTTOM
)
} else if (mLockscreenClockEnabled && mLsItemsContainer != null) {
Expand All @@ -363,15 +366,15 @@ class LockscreenWeatherA15(context: Context) : ModPack(context) {
ConstraintSet.PARENT_ID,
ConstraintSet.TOP
)
} else if (!mLockscreenClockEnabled && !mWeatherEnabled) {
} else if (!mLockscreenClockEnabled && !mWidgetsEnabled) {
constraintSet.clear(
mWeatherContainer.id,
ConstraintSet.TOP
)
constraintSet.connect(
mWeatherContainer.id,
ConstraintSet.TOP,
dateSmartSpaceViewId,
smartSpaceViewId,
ConstraintSet.BOTTOM
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,26 +379,29 @@ class LockscreenWidgetsA15(context: Context) : ModPack(context) {
val smartspaceSectionClass =
findClass("$SYSTEMUI_PACKAGE.keyguard.ui.view.layout.sections.SmartspaceSection")

val bcSmartSpaceViewId = mContext.resources.getIdentifier(
"bc_smartspace_view",
"id",
mContext.packageName
)
val dateSmartSpaceViewId = mContext.resources.getIdentifier(
"date_smartspace_view",
"id",
mContext.packageName
)

smartspaceSectionClass
.hookMethod("applyConstraints")
.runAfter { param ->
if (!mWidgetsEnabled) return@runAfter

val constraintSet = param.args[0]

val dateSmartSpaceViewId = if (dateSmartSpaceViewAvailable) {
mContext.resources.getIdentifier(
"date_smartspace_view",
"id",
mContext.packageName
)
val smartSpaceViewId = if (dateSmartSpaceViewAvailable) {
dateSmartSpaceViewId
} else {
// Some ROMs don't have date smartspace view
mContext.resources.getIdentifier(
"bc_smartspace_view",
"id",
mContext.packageName
)
bcSmartSpaceViewId
}

// Connect widget view to bottom of date smartspace
Expand All @@ -410,7 +413,7 @@ class LockscreenWidgetsA15(context: Context) : ModPack(context) {
constraintSet.connect(
mLsItemsContainer!!.id,
ConstraintSet.TOP,
dateSmartSpaceViewId,
smartSpaceViewId,
ConstraintSet.BOTTOM
)
} else if (mLockscreenClockEnabled && mLsItemsContainer != null) {
Expand All @@ -432,7 +435,7 @@ class LockscreenWidgetsA15(context: Context) : ModPack(context) {
constraintSet.connect(
mWidgetsContainer.id,
ConstraintSet.TOP,
dateSmartSpaceViewId,
smartSpaceViewId,
ConstraintSet.BOTTOM
)
}
Expand Down

0 comments on commit f60ba34

Please sign in to comment.