Refine clock and unlock statusbar transitions

This commit is contained in:
ajp_anton
2026-06-11 14:57:36 +00:00
parent ab28b7d8a3
commit fbab6dac6a
4 changed files with 60 additions and 7 deletions
@@ -1959,9 +1959,13 @@ final class StockLayoutCanvasController {
} }
unlockedIconRenderController.clearRoot(root); unlockedIconRenderController.clearRoot(root);
dirtyUnlockedLayoutRoots.add(root); dirtyUnlockedLayoutRoots.add(root);
if (isViewThread(root)) {
applyToRoot(root);
} else {
root.requestLayout(); root.requestLayout();
root.invalidate(); root.invalidate();
} }
}
private boolean isLockscreenScene() { private boolean isLockscreenScene() {
SceneKey scene = runtimeContext.getModeStateRepository().getActiveScene(); SceneKey scene = runtimeContext.getModeStateRepository().getActiveScene();
@@ -2,6 +2,8 @@ package se.ajpanton.statusbartweak.runtime.mode;
import android.content.Context; import android.content.Context;
import java.util.List;
import io.github.libxposed.api.XposedModuleInterface; import io.github.libxposed.api.XposedModuleInterface;
import se.ajpanton.statusbartweak.runtime.SystemContextProvider; import se.ajpanton.statusbartweak.runtime.SystemContextProvider;
import se.ajpanton.statusbartweak.runtime.features.RuntimeContext; import se.ajpanton.statusbartweak.runtime.features.RuntimeContext;
@@ -19,6 +21,8 @@ public final class SystemUiStatusBarStateFeature implements RuntimeFeature {
private static final String CLASS_STATUS_BAR_STATE_CONTROLLER = private static final String CLASS_STATUS_BAR_STATE_CONTROLLER =
"com.android.systemui.statusbar.StatusBarStateControllerImpl"; "com.android.systemui.statusbar.StatusBarStateControllerImpl";
private static final String CLASS_KEYGUARD_STATE_CONTROLLER =
"com.android.systemui.statusbar.policy.KeyguardStateControllerImpl";
private boolean installed; private boolean installed;
@@ -57,9 +61,30 @@ public final class SystemUiStatusBarStateFeature implements RuntimeFeature {
updateScene(context, chain.getThisObject()); updateScene(context, chain.getThisObject());
return result; return result;
}); });
installKeyguardGoingAwayHook(context, param.getClassLoader());
installed = true; installed = true;
} }
private void installKeyguardGoingAwayHook(RuntimeContext context, ClassLoader classLoader) {
Class<?> keyguardClass = ReflectionSupport.findClassIfExists(
CLASS_KEYGUARD_STATE_CONTROLLER,
classLoader);
if (keyguardClass == null) {
return;
}
XposedHookSupport.hookAllMethodsIfExists(
context.getFramework(),
keyguardClass,
"notifyKeyguardGoingAway",
chain -> {
Object result = chain.proceed();
if (firstBooleanArg(chain.getArgs())) {
context.getModeStateRepository().setUnlocked();
}
return result;
});
}
private void updateScene(RuntimeContext context, Object controller) { private void updateScene(RuntimeContext context, Object controller) {
if (context == null || controller == null) { if (context == null || controller == null) {
return; return;
@@ -73,6 +98,10 @@ public final class SystemUiStatusBarStateFeature implements RuntimeFeature {
SystemNotificationDisplayStyleDetector.read(systemContext(controller))); SystemNotificationDisplayStyleDetector.read(systemContext(controller)));
} }
private boolean firstBooleanArg(List<Object> args) {
return args != null && !args.isEmpty() && Boolean.TRUE.equals(args.get(0));
}
private Context systemContext(Object controller) { private Context systemContext(Object controller) {
Object context = ReflectionSupport.getFieldValue(controller, "mContext"); Object context = ReflectionSupport.getFieldValue(controller, "mContext");
if (context instanceof Context androidContext) { if (context instanceof Context androidContext) {
@@ -63,7 +63,8 @@ final class ClockLayout {
int baseHeightSteps, int baseHeightSteps,
int autoGapSteps, int autoGapSteps,
int statusbarHeight, int statusbarHeight,
int verticalOffsetSteps int verticalOffsetSteps,
int bottomRowBaselineAnchorY
) { ) {
if (source == null || model == null || model.rows.isEmpty()) { if (source == null || model == null || model.rows.isEmpty()) {
return null; return null;
@@ -103,7 +104,8 @@ final class ClockLayout {
measuredRows, measuredRows,
Math.max(1, autoGapSteps), Math.max(1, autoGapSteps),
Math.max(1, statusbarHeight), Math.max(1, statusbarHeight),
verticalOffsetSteps); verticalOffsetSteps,
bottomRowBaselineAnchorY);
RowAlignment alignment = alignRows(measuredRows, position); RowAlignment alignment = alignRows(measuredRows, position);
ArrayList<ClockRow> rows = alignment.rows; ArrayList<ClockRow> rows = alignment.rows;
@@ -215,7 +217,8 @@ final class ClockLayout {
ArrayList<MeasuredClockRow> measuredRows, ArrayList<MeasuredClockRow> measuredRows,
int autoGapSteps, int autoGapSteps,
int statusbarHeight, int statusbarHeight,
int verticalOffsetSteps int verticalOffsetSteps,
int bottomRowBaselineAnchorY
) { ) {
ArrayList<MeasuredClockRow> positionedRows = new ArrayList<>(measuredRows); ArrayList<MeasuredClockRow> positionedRows = new ArrayList<>(measuredRows);
int nextBottomSteps = 0; int nextBottomSteps = 0;
@@ -227,7 +230,12 @@ final class ClockLayout {
if (rowIndex == measuredRows.size() - 1) { if (rowIndex == measuredRows.size() - 1) {
topSteps = 100 - Math.max(1, row.logicalHeightSteps) - verticalOffsetSteps; topSteps = 100 - Math.max(1, row.logicalHeightSteps) - verticalOffsetSteps;
int heightPx = Math.max(1, stepsToPx(Math.max(1, row.logicalHeightSteps), statusbarHeight)); int heightPx = Math.max(1, stepsToPx(Math.max(1, row.logicalHeightSteps), statusbarHeight));
bottomPx = Math.max(1, statusbarHeight) - stepsToPx(verticalOffsetSteps, statusbarHeight); int offsetPx = stepsToPx(verticalOffsetSteps, statusbarHeight);
if (bottomRowBaselineAnchorY > 0 && row.baseline > 0) {
bottomPx = bottomRowBaselineAnchorY - row.baseline + heightPx - offsetPx;
} else {
bottomPx = Math.max(1, statusbarHeight) - offsetPx;
}
} else { } else {
MeasuredClockRow nextRow = measuredRows.get(rowIndex + 1); MeasuredClockRow nextRow = measuredRows.get(rowIndex + 1);
int gapSteps = resolveGapSteps(nextRow.source.gapBeforePx, autoGapSteps); int gapSteps = resolveGapSteps(nextRow.source.gapBeforePx, autoGapSteps);
@@ -763,10 +763,22 @@ public final class UnlockedIconSnapshotRenderController {
textSizeSteps, textSizeSteps,
autoGapSteps, autoGapSteps,
statusbarHeight, statusbarHeight,
settings.clockVerticalOffsetPx); settings.clockVerticalOffsetPx,
stockClockBaselineY(sourceBounds, source));
return layout; return layout;
} }
private int stockClockBaselineY(Bounds sourceBounds, TextView source) {
if (sourceBounds == null || source == null) {
return 0;
}
int baseline = source.getBaseline();
if (baseline <= 0) {
baseline = ClockLayout.centeredTextBaseline(source, sourceBounds.height);
}
return baseline > 0 ? sourceBounds.top + baseline : 0;
}
private int clockAutoGapSteps(TextView source, int statusbarHeight, int fallbackSteps) { private int clockAutoGapSteps(TextView source, int statusbarHeight, int fallbackSteps) {
int lineHeight = source != null ? source.getLineHeight() : 0; int lineHeight = source != null ? source.getLineHeight() : 0;
if (lineHeight <= 0 || statusbarHeight <= 0) { if (lineHeight <= 0 || statusbarHeight <= 0) {