Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 93e23c58 authored by Hawkwood Glazier's avatar Hawkwood Glazier
Browse files

Prevent alpha transitions from clipping out-of-bounds clocks

In order to do this, we bypass the default alpha mechaism used by views,
and call saveLayerAlpha ourselves on several views. This allows us to
set bounds for this area outside of the measured bounds.

Clipping still appears to occur after a user switch. b/282226587 will
track that follow up issue.

This is effectively a revert of Ia73ea00920ca0147e0acc5d2919b457203b7575e

Bug: 280113068
Bug: 281697986
Test: Manually checked several transitions
Change-Id: I9112efab88facd0f32daa5cd7377b8184658c159
parent 7e39238a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@
    android:layout_height="wrap_content"
    android:clipChildren="false"
    android:layout_gravity="center_horizontal|top">
    <FrameLayout
    <com.android.keyguard.KeyguardClockFrame
        android:id="@+id/lockscreen_clock_view"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/small_clock_height"
@@ -34,7 +34,7 @@
        android:clipChildren="false"
        android:paddingStart="@dimen/clock_padding_start"
        android:visibility="invisible" />
    <FrameLayout
    <com.android.keyguard.KeyguardClockFrame
        android:id="@+id/lockscreen_clock_view_large"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
+2 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@
    android:clipChildren="false"
    android:layout_width="0dp"
    android:layout_height="wrap_content">
    <LinearLayout
    <com.android.keyguard.KeyguardStatusContainer
        android:id="@+id/status_view_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
@@ -48,5 +48,5 @@
            android:layout_height="wrap_content"
            android:padding="@dimen/qs_media_padding"
            />
    </LinearLayout>
    </com.android.keyguard.KeyguardStatusContainer>
</com.android.keyguard.KeyguardStatusView>
+39 −0
Original line number Diff line number Diff line
package com.android.keyguard

import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout

class KeyguardClockFrame(
    context: Context,
    attrs: AttributeSet,
) : FrameLayout(context, attrs) {
    private var drawAlpha: Int = 255

    protected override fun onSetAlpha(alpha: Int): Boolean {
        drawAlpha = alpha
        return true
    }

    protected override fun dispatchDraw(canvas: Canvas) {
        val restoreTo = saveCanvasAlpha(this, canvas, drawAlpha)
        super.dispatchDraw(canvas)
        canvas.restoreToCount(restoreTo)
    }

    companion object {
        @JvmStatic
        fun saveCanvasAlpha(view: View, canvas: Canvas, alpha: Int): Int {
            var (x, y) =
                run {
                    val locationOnScreen = IntArray(2)
                    view.getLocationOnScreen(locationOnScreen)
                    Pair(locationOnScreen[0].toFloat(), locationOnScreen[1].toFloat())
                }

            return canvas.saveLayerAlpha(-1f * x, -1f * y, x + view.width, y + view.height, alpha)
        }
    }
}
+17 −3
Original line number Diff line number Diff line
@@ -5,11 +5,11 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

import androidx.annotation.IntDef;
@@ -69,12 +69,13 @@ public class KeyguardClockSwitch extends RelativeLayout {
    /**
     * Frame for small/large clocks
     */
    private FrameLayout mSmallClockFrame;
    private FrameLayout mLargeClockFrame;
    private KeyguardClockFrame mSmallClockFrame;
    private KeyguardClockFrame mLargeClockFrame;
    private ClockController mClock;

    private View mStatusArea;
    private int mSmartspaceTopOffset;
    private int mDrawAlpha = 255;

    /**
     * Maintain state so that a newly connected plugin can be initialized.
@@ -121,6 +122,19 @@ public class KeyguardClockSwitch extends RelativeLayout {
        onDensityOrFontScaleChanged();
    }

    @Override
    protected boolean onSetAlpha(int alpha) {
        mDrawAlpha = alpha;
        return true;
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        int restoreTo = KeyguardClockFrame.saveCanvasAlpha(this, canvas, mDrawAlpha);
        super.dispatchDraw(canvas);
        canvas.restoreToCount(restoreTo);
    }

    public void setLogBuffer(LogBuffer logBuffer) {
        mLogBuffer = logBuffer;
    }
+0 −14
Original line number Diff line number Diff line
@@ -178,20 +178,6 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
        }
    }

    /**
     * Set alpha directly to mView will clip clock, so we set alpha to clock face instead
     */
    public void setAlpha(float alpha) {
        ClockController clock = getClock();
        if (clock != null) {
            clock.getLargeClock().getView().setAlpha(alpha);
            clock.getSmallClock().getView().setAlpha(alpha);
        }
        if (mStatusArea != null) {
            mStatusArea.setAlpha(alpha);
        }
    }

    /**
     * Attach the controller to the view it relates to.
     */
Loading