Merge "Scrimming the notifications when QS is open."

This commit is contained in:
Selim Cinek
2014-06-20 00:26:10 +00:00
committed by Android (Google) Code Review
14 changed files with 179 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2014 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
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#34000000" />
<corners android:radius="@*android:dimen/notification_material_rounded_rect_radius" />
</shape>

View File

@@ -49,4 +49,10 @@
android:layout_width="120dp"
android:layout_height="wrap_content"
/>
<com.android.systemui.statusbar.NotificationScrimView
android:id="@+id/scrim_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.android.systemui.statusbar.NotificationOverflowContainer>

View File

@@ -48,4 +48,9 @@
android:padding="2dp"
/>
<com.android.systemui.statusbar.NotificationScrimView
android:id="@+id/scrim_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.android.systemui.statusbar.ExpandableNotificationRow>

View File

@@ -320,6 +320,9 @@
device. -->
<dimen name="unlock_move_distance">75dp</dimen>
<!-- Distance after which the scrim starts fading in when dragging down the quick settings -->
<dimen name="notification_scrim_wait_distance">100dp</dimen>
<!-- Move distance for the unlock hint animation on the lockscreen -->
<dimen name="hint_move_distance">75dp</dimen>

View File

@@ -119,6 +119,7 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
private NotificationBackgroundView mBackgroundNormal;
private NotificationBackgroundView mBackgroundDimmed;
private NotificationScrimView mScrimView;
private ObjectAnimator mBackgroundAnimator;
private RectF mAppearAnimationRect = new RectF();
private PorterDuffColorFilter mAppearAnimationFilter;
@@ -153,6 +154,7 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
mBackgroundDimmed = (NotificationBackgroundView) findViewById(R.id.backgroundDimmed);
updateBackground();
updateBackgroundResources();
mScrimView = (NotificationScrimView) findViewById(R.id.scrim_view);
}
private final Runnable mTapTimeoutRunnable = new Runnable() {
@@ -379,6 +381,7 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
setPivotY(actualHeight / 2);
mBackgroundNormal.setActualHeight(actualHeight);
mBackgroundDimmed.setActualHeight(actualHeight);
mScrimView.setActualHeight(actualHeight);
}
@Override
@@ -386,6 +389,7 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
super.setClipTopAmount(clipTopAmount);
mBackgroundNormal.setClipTopAmount(clipTopAmount);
mBackgroundDimmed.setClipTopAmount(clipTopAmount);
mScrimView.setClipTopAmount(clipTopAmount);
}
@Override
@@ -405,6 +409,11 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
}
}
@Override
public void setScrimAmount(float scrimAmount) {
mScrimView.setAlpha(scrimAmount);
}
private void startAppearAnimation(boolean isAppearing,
float translationDirection, long delay, final Runnable onFinishedRunnable) {
if (mAppearAnimator != null) {

View File

@@ -223,6 +223,8 @@ public abstract class ExpandableView extends FrameLayout {
public abstract void performAddAnimation(long delay);
public abstract void setScrimAmount(float scrimAmount);
/**
* A listener notifying when {@link #getActualHeight} changes.
*/

View File

@@ -0,0 +1,79 @@
/*
* Copyright (C) 2014 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.systemui.statusbar;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import com.android.keyguard.R;
/**
* A view that can be used for both the dimmed and normal background of an notification.
*/
public class NotificationScrimView extends View {
private Drawable mBackground;
private int mClipTopAmount;
private int mActualHeight;
public NotificationScrimView(Context context, AttributeSet attrs) {
super(context, attrs);
mBackground = getResources().getDrawable(R.drawable.notification_scrim);
}
@Override
protected void onDraw(Canvas canvas) {
draw(canvas, mBackground);
}
private void draw(Canvas canvas, Drawable drawable) {
if (drawable != null) {
drawable.setBounds(0, mClipTopAmount, getWidth(), mActualHeight);
drawable.draw(canvas);
}
}
@Override
protected boolean verifyDrawable(Drawable who) {
return super.verifyDrawable(who) || who == mBackground;
}
public void setActualHeight(int actualHeight) {
mActualHeight = actualHeight;
invalidate();
}
public int getActualHeight() {
return mActualHeight;
}
public void setClipTopAmount(int clipTopAmount) {
mClipTopAmount = clipTopAmount;
invalidate();
}
@Override
public boolean hasOverlappingRendering() {
// Prevents this view from creating a layer when alpha is animating.
return false;
}
}

View File

@@ -121,4 +121,9 @@ public class SpeedBumpView extends ExpandableView {
public void performAddAnimation(long delay) {
performVisibilityAnimation(true);
}
@Override
public void setScrimAmount(float scrimAmount) {
// We don't need to scrim the speedbumps
}
}

View File

@@ -108,6 +108,7 @@ public class NotificationPanelView extends PanelView implements
private KeyguardBottomAreaView mKeyguardBottomArea;
private boolean mBlockTouches;
private ArrayList<View> mSwipeTranslationViews = new ArrayList<>();
private int mNotificationScrimWaitDistance;
public NotificationPanelView(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -169,6 +170,8 @@ public class NotificationPanelView extends PanelView implements
getResources().getDimensionPixelSize(R.dimen.header_notifications_collide_distance);
mUnlockMoveDistance = getResources().getDimensionPixelOffset(R.dimen.unlock_move_distance);
mClockPositionAlgorithm.loadDimens(getResources());
mNotificationScrimWaitDistance =
getResources().getDimensionPixelSize(R.dimen.notification_scrim_wait_distance);
}
@Override
@@ -577,9 +580,17 @@ public class NotificationPanelView extends PanelView implements
mHeader.setExpansion(height - mQsPeekHeight);
setQsTranslation(height);
requestScrollerTopPaddingUpdate(false /* animate */);
updateNotificationScrim(height);
mStatusBar.userActivity();
}
private void updateNotificationScrim(float height) {
int startDistance = mQsMinExpansionHeight + mNotificationScrimWaitDistance;
float progress = (height - startDistance) / (mQsMaxExpansionHeight - startDistance);
progress = Math.max(0.0f, Math.min(progress, 1.0f));
mNotificationStackScroller.setScrimAlpha(progress);
}
private void setQsTranslation(float height) {
mQsContainer.setY(height - mQsContainer.getHeight());
}

View File

@@ -32,6 +32,7 @@ public class AmbientState {
private float mOverScrollTopAmount;
private float mOverScrollBottomAmount;
private int mSpeedBumpIndex = -1;
private float mScrimAmount;
public int getScrollY() {
return mScrollY;
@@ -85,6 +86,14 @@ public class AmbientState {
}
}
public void setScrimAmount(float scrimAmount) {
mScrimAmount = scrimAmount;
}
public float getScrimAmount() {
return mScrimAmount;
}
public float getOverScrollAmount(boolean top) {
return top ? mOverScrollTopAmount : mOverScrollBottomAmount;
}

View File

@@ -1845,6 +1845,11 @@ public class NotificationStackScrollLayout extends ViewGroup
return true;
}
public void setScrimAlpha(float progress) {
mAmbientState.setScrimAmount(progress);
requestChildrenUpdate();
}
/**
* A listener that is notified when some child locations might have changed.
*/

View File

@@ -154,6 +154,17 @@ public class StackScrollAlgorithm {
handleDraggedViews(ambientState, resultState, algorithmState);
updateDimmedActivated(ambientState, resultState, algorithmState);
updateClipping(resultState, algorithmState);
updateScrimAmount(resultState, algorithmState, ambientState.getScrimAmount());
}
private void updateScrimAmount(StackScrollState resultState,
StackScrollAlgorithmState algorithmState, float scrimAmount) {
int childCount = algorithmState.visibleChildren.size();
for (int i = 0; i < childCount; i++) {
View child = algorithmState.visibleChildren.get(i);
StackScrollState.ViewState childViewState = resultState.getViewStateForView(child);
childViewState.scrimAmount = scrimAmount;
}
}
private void updateClipping(StackScrollState resultState,

View File

@@ -148,6 +148,9 @@ public class StackScrollState {
// apply dimming
child.setDimmed(state.dimmed, false /* animate */);
// apply scrimming
child.setScrimAmount(state.scrimAmount);
float oldClipTopAmount = child.getClipTopAmount();
if (oldClipTopAmount != state.clipTopAmount) {
child.setClipTopAmount(state.clipTopAmount);
@@ -222,6 +225,12 @@ public class StackScrollState {
float scale;
boolean dimmed;
/**
* A value between 0 and 1 indicating how much the view should be scrimmed.
* 1 means that the notifications will be darkened as much as possible.
*/
float scrimAmount;
/**
* The amount which the view should be clipped from the top. This is calculated to
* perceive consistent shadows.

View File

@@ -176,6 +176,9 @@ public class StackStateAnimator {
// start dimmed animation
child.setDimmed(viewState.dimmed, mAnimationFilter.animateDimmed);
// apply scrimming
child.setScrimAmount(viewState.scrimAmount);
if (wasAdded) {
child.performAddAnimation(delay);
}