Merge "Update HUN visuals to UX spec" into lmp-preview-dev

This commit is contained in:
Jorim Jaggi
2014-05-31 11:44:48 +00:00
committed by Android (Google) Code Review
9 changed files with 104 additions and 38 deletions

View File

@@ -0,0 +1,25 @@
<?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">
<gradient
android:type="linear"
android:angle="-90"
android:startColor="#55000000"
android:endColor="#00000000" />
</shape>

View File

@@ -17,13 +17,14 @@
<com.android.systemui.statusbar.policy.HeadsUpNotificationView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
android:layout_width="match_parent"
android:background="@drawable/heads_up_scrim">
<FrameLayout
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/notification_side_padding"
android:layout_marginEnd="@dimen/notification_side_padding"
android:elevation="16dp"
android:paddingStart="@dimen/notification_side_padding"
android:paddingEnd="@dimen/notification_side_padding"
android:elevation="8dp"
android:id="@+id/content_holder"
style="@style/NotificationsQuickSettings" />

View File

@@ -305,6 +305,7 @@
keyguard_clock_height_fraction_* for the difference between min and max.-->
<dimen name="keyguard_clock_notifications_margin_min">22dp</dimen>
<dimen name="keyguard_clock_notifications_margin_max">36dp</dimen>
<dimen name="heads_up_window_height">250dp</dimen>
<!-- The minimum amount the user needs to swipe to go to the camera / phone. -->
<dimen name="keyguard_min_swipe_amount">75dp</dimen>

View File

@@ -51,12 +51,12 @@ public class SwipeHelper implements Gefingerpoken {
private int MAX_DISMISS_VELOCITY = 2000; // dp/sec
private static final int SNAP_ANIM_LEN = SLOW_ANIMATIONS ? 1000 : 150; // ms
public static float ALPHA_FADE_START = 0f; // fraction of thumbnail width
public static float SWIPE_PROGRESS_FADE_START = 0f; // fraction of thumbnail width
// where fade starts
static final float ALPHA_FADE_END = 0.5f; // fraction of thumbnail width
// beyond which alpha->0
private float mMinAlpha = 0f;
private float mMaxAlpha = 1f;
static final float SWIPE_PROGRESS_FADE_END = 0.5f; // fraction of thumbnail width
// beyond which swipe progress->0
private float mMinSwipeProgress = 0f;
private float mMaxSwipeProgress = 1f;
private float mPagingTouchSlop;
private Callback mCallback;
@@ -137,36 +137,39 @@ public class SwipeHelper implements Gefingerpoken {
v.getMeasuredHeight();
}
public void setMinAlpha(float minAlpha) {
mMinAlpha = minAlpha;
public void setMinSwipeProgress(float minSwipeProgress) {
mMinSwipeProgress = minSwipeProgress;
}
public void setMaxAlpha(float maxAlpha) {
mMaxAlpha = maxAlpha;
public void setMaxSwipeProgress(float maxSwipeProgress) {
mMaxSwipeProgress = maxSwipeProgress;
}
private float getAlphaForOffset(View view) {
private float getSwipeProgressForOffset(View view) {
float viewSize = getSize(view);
final float fadeSize = ALPHA_FADE_END * viewSize;
final float fadeSize = SWIPE_PROGRESS_FADE_END * viewSize;
float result = 1.0f;
float pos = getTranslation(view);
if (pos >= viewSize * ALPHA_FADE_START) {
result = 1.0f - (pos - viewSize * ALPHA_FADE_START) / fadeSize;
} else if (pos < viewSize * (1.0f - ALPHA_FADE_START)) {
result = 1.0f + (viewSize * ALPHA_FADE_START + pos) / fadeSize;
if (pos >= viewSize * SWIPE_PROGRESS_FADE_START) {
result = 1.0f - (pos - viewSize * SWIPE_PROGRESS_FADE_START) / fadeSize;
} else if (pos < viewSize * (1.0f - SWIPE_PROGRESS_FADE_START)) {
result = 1.0f + (viewSize * SWIPE_PROGRESS_FADE_START + pos) / fadeSize;
}
return Math.min(Math.max(mMinAlpha, result), mMaxAlpha);
return Math.min(Math.max(mMinSwipeProgress, result), mMaxSwipeProgress);
}
private void updateAlphaFromOffset(View animView, boolean dismissable) {
if (FADE_OUT_DURING_SWIPE && dismissable) {
float alpha = getAlphaForOffset(animView);
if (alpha != 0f && alpha != 1f) {
animView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
animView.setLayerType(View.LAYER_TYPE_NONE, null);
private void updateSwipeProgressFromOffset(View animView, boolean dismissable) {
float swipeProgress = getSwipeProgressForOffset(animView);
if (!mCallback.updateSwipeProgress(animView, dismissable, swipeProgress)) {
if (FADE_OUT_DURING_SWIPE && dismissable) {
float alpha = swipeProgress;
if (alpha != 0f && alpha != 1f) {
animView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else {
animView.setLayerType(View.LAYER_TYPE_NONE, null);
}
animView.setAlpha(getSwipeProgressForOffset(animView));
}
animView.setAlpha(getAlphaForOffset(animView));
}
invalidateGlobalRegion(animView);
}
@@ -307,7 +310,7 @@ public class SwipeHelper implements Gefingerpoken {
});
anim.addUpdateListener(new AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
updateAlphaFromOffset(animView, canAnimViewBeDismissed);
updateSwipeProgressFromOffset(animView, canAnimViewBeDismissed);
}
});
anim.start();
@@ -321,12 +324,12 @@ public class SwipeHelper implements Gefingerpoken {
anim.setDuration(duration);
anim.addUpdateListener(new AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
updateAlphaFromOffset(animView, canAnimViewBeDismissed);
updateSwipeProgressFromOffset(animView, canAnimViewBeDismissed);
}
});
anim.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator animator) {
updateAlphaFromOffset(animView, canAnimViewBeDismissed);
updateSwipeProgressFromOffset(animView, canAnimViewBeDismissed);
mCallback.onChildSnappedBack(animView);
}
});
@@ -365,7 +368,7 @@ public class SwipeHelper implements Gefingerpoken {
}
setTranslation(mCurrAnimView, delta);
updateAlphaFromOffset(mCurrAnimView, mCanCurrViewBeDimissed);
updateSwipeProgressFromOffset(mCurrAnimView, mCanCurrViewBeDimissed);
}
break;
case MotionEvent.ACTION_UP:
@@ -415,5 +418,12 @@ public class SwipeHelper implements Gefingerpoken {
void onDragCancelled(View v);
void onChildSnappedBack(View animView);
/**
* Updates the swipe progress on a child.
*
* @return if true, prevents the default alpha fading.
*/
boolean updateSwipeProgress(View animView, boolean dismissable, float swipeProgress);
}
}

View File

@@ -64,7 +64,7 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView
}
public void setMinSwipeAlpha(float minAlpha) {
mSwipeHelper.setMinAlpha(minAlpha);
mSwipeHelper.setMinSwipeProgress(minAlpha);
}
private int scrollPositionOfMostRecent() {
@@ -221,6 +221,11 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView
public void onChildSnappedBack(View animView) {
}
@Override
public boolean updateSwipeProgress(View animView, boolean dismissable, float swipeProgress) {
return false;
}
public View getChildAtPosition(MotionEvent ev) {
final float x = ev.getX() + getScrollX();
final float y = ev.getY() + getScrollY();

View File

@@ -65,7 +65,7 @@ public class RecentsVerticalScrollView extends ScrollView
}
public void setMinSwipeAlpha(float minAlpha) {
mSwipeHelper.setMinAlpha(minAlpha);
mSwipeHelper.setMinSwipeProgress(minAlpha);
}
private int scrollPositionOfMostRecent() {
@@ -229,6 +229,11 @@ public class RecentsVerticalScrollView extends ScrollView
public void onChildSnappedBack(View animView) {
}
@Override
public boolean updateSwipeProgress(View animView, boolean dismissable, float swipeProgress) {
return false;
}
public View getChildAtPosition(MotionEvent ev) {
final float x = ev.getX() + getScrollX();
final float y = ev.getY() + getScrollY();

View File

@@ -980,8 +980,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
}
private void addHeadsUpView() {
int headsUpHeight = mContext.getResources()
.getDimensionPixelSize(R.dimen.heads_up_window_height);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT, headsUpHeight,
WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, // above the status bar!
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS

View File

@@ -47,7 +47,7 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper.
int[] mTmpTwoArray = new int[2];
private final int mTouchSensitivityDelay;
private final float mMaxAlpha = 0.95f;
private final float mMaxAlpha = 1f;
private SwipeHelper mSwipeHelper;
private EdgeSwipeHelper mEdgeSwipeHelper;
@@ -114,7 +114,7 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper.
float pagingTouchSlop = viewConfiguration.getScaledPagingTouchSlop();
float touchSlop = viewConfiguration.getScaledTouchSlop();
mSwipeHelper = new SwipeHelper(SwipeHelper.X, this, densityScale, pagingTouchSlop);
mSwipeHelper.setMaxAlpha(mMaxAlpha);
mSwipeHelper.setMaxSwipeProgress(mMaxAlpha);
mEdgeSwipeHelper = new EdgeSwipeHelper(touchSlop);
int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_min_height);
@@ -184,7 +184,13 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper.
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
Outline o = new Outline();
o.setRect(0, 0, mContentHolder.getWidth(), mContentHolder.getHeight());
// Apply padding to shadow.
int outlineLeft = mContentHolder.getPaddingLeft();
int outlineTop = mContentHolder.getPaddingTop();
o.setRect(outlineLeft, outlineTop,
mContentHolder.getWidth() - outlineLeft - mContentHolder.getPaddingRight(),
mContentHolder.getHeight() - outlineTop - mContentHolder.getPaddingBottom());
mContentHolder.setOutline(o);
}
@@ -245,6 +251,12 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper.
public void onChildSnappedBack(View animView) {
}
@Override
public boolean updateSwipeProgress(View animView, boolean dismissable, float swipeProgress) {
getBackground().setAlpha((int) (255 * swipeProgress));
return false;
}
@Override
public View getChildAtPosition(MotionEvent ev) {
return mContentHolder;

View File

@@ -449,6 +449,11 @@ public class NotificationStackScrollLayout extends ViewGroup
}
}
@Override
public boolean updateSwipeProgress(View animView, boolean dismissable, float swipeProgress) {
return false;
}
public void onBeginDrag(View v) {
setSwipingInProgress(true);
mAmbientState.onBeginDrag(v);