diff options
author | Jorim Jaggi <jjaggi@google.com> | 2014-05-15 03:09:01 +0200 |
---|---|---|
committer | Jorim Jaggi <jjaggi@google.com> | 2014-05-17 02:01:41 +0200 |
commit | 069cd03740312159faf24a01910ff1daeae93131 (patch) | |
tree | 14b73afba0af149a5a9065cf69308ab1ce298d54 /packages/SystemUI/src | |
parent | c5baa188068bac4c71ffdca62f09134a59f87454 (diff) | |
download | frameworks_base-069cd03740312159faf24a01910ff1daeae93131.zip frameworks_base-069cd03740312159faf24a01910ff1daeae93131.tar.gz frameworks_base-069cd03740312159faf24a01910ff1daeae93131.tar.bz2 |
Position clock and notifications dynamically.
The positioning is dependant on how many notifications are currently
showing. This makes sure that the lockscreen always looks balanced
and harmonic.
Bug: 14592994
Change-Id: Ic647b887dd23e6cc5ecd07d70f279ff2f218f4ca
Diffstat (limited to 'packages/SystemUI/src')
3 files changed, 88 insertions, 19 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java index cd985f5..047983b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java @@ -26,8 +26,6 @@ import android.view.VelocityTracker; import android.view.View; import android.view.ViewGroup; import android.view.accessibility.AccessibilityEvent; -import android.view.animation.AnimationUtils; -import android.view.animation.Interpolator; import android.widget.LinearLayout; import com.android.systemui.R; @@ -40,8 +38,6 @@ import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; public class NotificationPanelView extends PanelView implements ExpandableView.OnHeightChangedListener, ObservableScrollView.Listener, View.OnClickListener { - public static final boolean DEBUG_GESTURES = true; - private static final int EXPANSION_ANIMATION_LENGTH = 375; PhoneStatusBar mStatusBar; private StatusBarHeaderView mHeader; @@ -80,6 +76,17 @@ public class NotificationPanelView extends PanelView implements private FlingAnimationUtils mFlingAnimationUtils; private int mStatusBarMinHeight; + private int mClockNotificationsMarginMin; + private int mClockNotificationsMarginMax; + private float mClockYFractionMin; + private float mClockYFractionMax; + + /** + * The number (fractional) of notifications the "more" card counts when calculating how many + * notifications are currently visible for the y positioning of the clock. + */ + private float mMoreCardNotificationAmount; + public NotificationPanelView(Context context, AttributeSet attrs) { super(context, attrs); } @@ -113,9 +120,25 @@ public class NotificationPanelView extends PanelView implements mNotificationStackScroller = (NotificationStackScrollLayout) findViewById(R.id.notification_stack_scroller); mNotificationStackScroller.setOnHeightChangedListener(this); + } + + @Override + protected void loadDimens() { + super.loadDimens(); mNotificationTopPadding = getResources().getDimensionPixelSize( R.dimen.notifications_top_padding); mMinStackHeight = getResources().getDimensionPixelSize(R.dimen.collapsed_stack_height); + mClockNotificationsMarginMin = getResources().getDimensionPixelSize( + R.dimen.keyguard_clock_notifications_margin_min); + mClockNotificationsMarginMax = getResources().getDimensionPixelSize( + R.dimen.keyguard_clock_notifications_margin_max); + mClockYFractionMin = + getResources().getFraction(R.fraction.keyguard_clock_y_fraction_min, 1, 1); + mClockYFractionMax = + getResources().getFraction(R.fraction.keyguard_clock_y_fraction_max, 1, 1); + mMoreCardNotificationAmount = + (float) getResources().getDimensionPixelSize(R.dimen.notification_summary_height) / + getResources().getDimensionPixelSize(R.dimen.notification_min_height); mFlingAnimationUtils = new FlingAnimationUtils(getContext()); mStatusBarMinHeight = getResources().getDimensionPixelSize( com.android.internal.R.dimen.status_bar_height); @@ -124,15 +147,8 @@ public class NotificationPanelView extends PanelView implements @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); - int keyguardBottomMargin = - ((MarginLayoutParams) mKeyguardStatusView.getLayoutParams()).bottomMargin; if (!mQsExpanded) { - mStackScrollerIntrinsicPadding = mStatusBar.getBarState() == StatusBarState.KEYGUARD - ? mKeyguardStatusView.getBottom() + keyguardBottomMargin - : mHeader.getBottom() + mNotificationTopPadding; - mNotificationStackScroller.setTopPadding(mStackScrollerIntrinsicPadding, - mAnimateNextTopPaddingChange); - mAnimateNextTopPaddingChange = false; + positionClockAndNotifications(); } // Calculate quick setting heights. @@ -143,6 +159,44 @@ public class NotificationPanelView extends PanelView implements } } + /** + * Positions the clock and notifications dynamically depending on how many notifications are + * showing. + */ + private void positionClockAndNotifications() { + if (mStatusBar.getBarState() != StatusBarState.KEYGUARD) { + mStackScrollerIntrinsicPadding = mHeader.getBottom() + mNotificationTopPadding; + } else { + int notificationCount = mNotificationStackScroller.getNotGoneChildCount(); + int y = getClockY(notificationCount); + int padding = getClockNotificationsPadding(notificationCount); + mKeyguardStatusView.setY(y - mKeyguardStatusView.getHeight()/2); + mStackScrollerIntrinsicPadding = + (int) (mKeyguardStatusView.getY() + mKeyguardStatusView.getHeight() + padding); + } + mNotificationStackScroller.setTopPadding(mStackScrollerIntrinsicPadding, + mAnimateNextTopPaddingChange); + mAnimateNextTopPaddingChange = false; + } + + private int getClockNotificationsPadding(int notificationCount) { + float t = notificationCount + / (mStatusBar.getMaxKeyguardNotifications() + mMoreCardNotificationAmount); + t = Math.min(t, 1.0f); + return (int) (t * mClockNotificationsMarginMin + (1 - t) * mClockNotificationsMarginMax); + } + + private float getClockYFraction(int notificationCount) { + float t = notificationCount + / (mStatusBar.getMaxKeyguardNotifications() + mMoreCardNotificationAmount); + t = Math.min(t, 1.0f); + return (1 - t) * mClockYFractionMax + t * mClockYFractionMin; + } + + private int getClockY(int notificationCount) { + return (int) (getClockYFraction(notificationCount) * getHeight()); + } + public void animateToFullShade() { mAnimateNextTopPaddingChange = true; mNotificationStackScroller.goToFullShade(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java index dde2ebb..517f763 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java @@ -322,7 +322,7 @@ public class PanelView extends FrameLayout { setOnHierarchyChangeListener(mHierarchyListener); } - private void loadDimens() { + protected void loadDimens() { final Resources res = getContext().getResources(); mSelfExpandVelocityPx = res.getDimension(R.dimen.self_expand_velocity); @@ -583,8 +583,14 @@ public class PanelView extends FrameLayout { @Override protected void onFinishInflate() { super.onFinishInflate(); + loadDimens(); + } + @Override + protected void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); loadDimens(); + mMaxPanelHeight = -1; } public void fling(float vel, boolean always) { @@ -697,12 +703,6 @@ public class PanelView extends FrameLayout { mExpandedFraction = Math.min(1f, (fh == 0) ? 0 : h / fh); } - @Override - protected void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - mMaxPanelHeight = -1; - } - protected void onHeightUpdated(float expandedHeight) { requestLayout(); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java index f125c9a..cb0a696 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java @@ -961,6 +961,21 @@ public class NotificationStackScrollLayout extends ViewGroup return null; } + /** + * @return the number of children which have visibility unequal to GONE + */ + public int getNotGoneChildCount() { + int childCount = getChildCount(); + int count = 0; + for (int i = 0; i < childCount; i++) { + View child = getChildAt(i); + if (child.getVisibility() != View.GONE) { + count++; + } + } + return count; + } + private int getMaxExpandHeight(View view) { if (view instanceof ExpandableNotificationRow) { ExpandableNotificationRow row = (ExpandableNotificationRow) view; |