Merge "Bouncer: Adjust tracking animations." into tm-dev

This commit is contained in:
Aaron Liu
2022-03-18 19:15:35 +00:00
committed by Android (Google) Code Review
6 changed files with 144 additions and 6 deletions

View File

@@ -129,4 +129,7 @@
<dimen name="user_switcher_icon_selected_width">8dp</dimen>
<dimen name="user_switcher_fullscreen_button_text_size">14sp</dimen>
<dimen name="user_switcher_fullscreen_button_padding">12dp</dimen>
<!-- Translation y for appear animation -->
<dimen name="keyguard_host_view_translation_y">80dp</dimen>
</resources>

View File

@@ -0,0 +1,49 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.android.keyguard
import android.util.MathUtils
object BouncerPanelExpansionCalculator {
/**
* Scale the alpha/position of the host view.
*/
@JvmStatic
fun getHostViewScaledExpansion(fraction: Float): Float {
return when {
fraction >= 0.9f -> 1f
fraction < 0.6 -> 0f
else -> (fraction - 0.6f) / 0.3f
}
}
/**
* Scale the alpha/tint of the back scrim.
*/
@JvmStatic
fun getBackScrimScaledExpansion(fraction: Float): Float {
return MathUtils.constrain((fraction - 0.9f) / 0.1f, 0f, 1f)
}
/**
* This will scale the alpha/position of the clock.
*/
@JvmStatic
fun getKeyguardClockScaledExpansion(fraction: Float): Float {
return MathUtils.constrain((fraction - 0.7f) / 0.3f, 0f, 1f)
}
}

View File

@@ -37,7 +37,6 @@ import com.android.keyguard.dagger.KeyguardBouncerScope;
import com.android.settingslib.Utils;
import com.android.systemui.R;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.statusbar.phone.KeyguardBouncer;
import com.android.systemui.util.ViewController;
import java.io.File;
@@ -64,6 +63,7 @@ public class KeyguardHostViewController extends ViewController<KeyguardHostView>
private ActivityStarter.OnDismissAction mDismissAction;
private Runnable mCancelAction;
private int mTranslationY;
private final KeyguardUpdateMonitorCallback mUpdateCallback =
new KeyguardUpdateMonitorCallback() {
@@ -322,12 +322,14 @@ public class KeyguardHostViewController extends ViewController<KeyguardHostView>
/**
* Fades and translates in/out the security screen.
* Fades in as expansion approaches 0.
* Animation duration is between 0.33f and 0.67f of panel expansion fraction.
* @param fraction amount of the screen that should show.
*/
public void setExpansion(float fraction) {
float alpha = MathUtils.map(KeyguardBouncer.ALPHA_EXPANSION_THRESHOLD, 1, 1, 0, fraction);
mView.setAlpha(MathUtils.constrain(alpha, 0f, 1f));
mView.setTranslationY(fraction * mView.getHeight());
float scaledFraction = BouncerPanelExpansionCalculator.getHostViewScaledExpansion(fraction);
mView.setAlpha(MathUtils.constrain(1 - scaledFraction, 0f, 1f));
mView.setTranslationY(scaledFraction * mTranslationY);
}
/**
@@ -490,6 +492,8 @@ public class KeyguardHostViewController extends ViewController<KeyguardHostView>
gravity = resources.getInteger(R.integer.keyguard_host_view_gravity);
}
mTranslationY = resources
.getDimensionPixelSize(R.dimen.keyguard_host_view_translation_y);
// Android SysUI uses a FrameLayout as the top-level, but Auto uses RelativeLayout.
// We're just changing the gravity here though (which can't be applied to RelativeLayout),
// so only attempt the update if mView is inside a FrameLayout.

View File

@@ -23,6 +23,7 @@ import static com.android.systemui.statusbar.notification.NotificationUtils.inte
import android.content.res.Resources;
import android.util.MathUtils;
import com.android.keyguard.BouncerPanelExpansionCalculator;
import com.android.keyguard.KeyguardStatusView;
import com.android.systemui.R;
import com.android.systemui.animation.Interpolators;
@@ -169,7 +170,8 @@ public class KeyguardClockPositionAlgorithm {
boolean isSplitShade, float udfpsTop, float clockBottom, boolean isClockTopAligned) {
mMinTopMargin = keyguardStatusBarHeaderHeight + Math.max(mContainerTopPadding,
userSwitchHeight);
mPanelExpansion = panelExpansion;
mPanelExpansion = BouncerPanelExpansionCalculator
.getKeyguardClockScaledExpansion(panelExpansion);
mKeyguardStatusHeight = keyguardStatusHeight + mStatusViewBottomMargin;
mUserSwitchHeight = userSwitchHeight;
mUserSwitchPreferredY = userSwitchPreferredY;

View File

@@ -41,6 +41,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.colorextraction.ColorExtractor.GradientColors;
import com.android.internal.graphics.ColorUtils;
import com.android.internal.util.function.TriConsumer;
import com.android.keyguard.BouncerPanelExpansionCalculator;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.settingslib.Utils;
@@ -808,7 +809,15 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, Dump
private Pair<Integer, Float> calculateBackStateForState(ScrimState state) {
// Either darken of make the scrim transparent when you
// pull down the shade
float interpolatedFract = getInterpolatedFraction();
float interpolatedFract;
if (state == ScrimState.KEYGUARD) {
interpolatedFract = BouncerPanelExpansionCalculator
.getBackScrimScaledExpansion(mPanelExpansionFraction);
} else {
interpolatedFract = getInterpolatedFraction();
}
float stateBehind = mClipsQsScrim ? state.getNotifAlpha() : state.getBehindAlpha();
float behindAlpha;
int behindTint;

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.android.keyguard
import android.test.suitebuilder.annotation.SmallTest
import android.testing.AndroidTestingRunner
import com.android.systemui.SysuiTestCase
import com.google.common.truth.Truth.assertThat
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidTestingRunner::class)
@SmallTest
class BouncerPanelExpansionCalculatorTest : SysuiTestCase() {
@Test
fun testGetHostViewScaledExpansion() {
assertThat(BouncerPanelExpansionCalculator.getHostViewScaledExpansion(1f))
.isEqualTo(1f)
assertThat(BouncerPanelExpansionCalculator.getHostViewScaledExpansion(0.9f))
.isEqualTo(1f)
assertThat(BouncerPanelExpansionCalculator.getHostViewScaledExpansion(0.59f))
.isEqualTo(0f)
assertThat(BouncerPanelExpansionCalculator.getHostViewScaledExpansion(0f))
.isEqualTo(0f)
assertEquals(BouncerPanelExpansionCalculator
.getHostViewScaledExpansion(0.8f), 2f / 3f, 0.01f)
}
@Test
fun testGetBackScrimScaledExpansion() {
assertThat(BouncerPanelExpansionCalculator.getBackScrimScaledExpansion(1f))
.isEqualTo(1f)
assertEquals(BouncerPanelExpansionCalculator
.getBackScrimScaledExpansion(0.95f), 1f / 2f, 0.01f)
assertThat(BouncerPanelExpansionCalculator.getBackScrimScaledExpansion(0.9f))
.isEqualTo(0f)
assertThat(BouncerPanelExpansionCalculator.getBackScrimScaledExpansion(0.5f))
.isEqualTo(0f)
assertThat(BouncerPanelExpansionCalculator.getBackScrimScaledExpansion(0f))
.isEqualTo(0f)
}
@Test
fun testGetKeyguardClockScaledExpansion() {
assertThat(BouncerPanelExpansionCalculator.getKeyguardClockScaledExpansion(1f))
.isEqualTo(1f)
assertEquals(BouncerPanelExpansionCalculator
.getKeyguardClockScaledExpansion(0.8f), 1f / 3f, 0.01f)
assertThat(BouncerPanelExpansionCalculator.getKeyguardClockScaledExpansion(0.7f))
.isEqualTo(0f)
assertThat(BouncerPanelExpansionCalculator.getBackScrimScaledExpansion(0.5f))
.isEqualTo(0f)
assertThat(BouncerPanelExpansionCalculator.getBackScrimScaledExpansion(0f))
.isEqualTo(0f)
}
}