Skip to content

Commit f9048cd

Browse files
author
Adam Cohen
committed
Polish to 3d carousel and standard pager
-> updated assets -> Always showing outlines as per new mock -> Enabling layers on content during fades (still need to sort out layers for frames) -> Added carousel overscroll as per discussion with danship -> Fading side pages in carousel -> other small polish Change-Id: If88686768c621a65b175a74c07cb55a69321fd97
1 parent 1d269e8 commit f9048cd

File tree

11 files changed

+182
-115
lines changed

11 files changed

+182
-115
lines changed
-6.23 KB
Binary file not shown.
-516 Bytes
Binary file not shown.
-6.23 KB
Binary file not shown.
-516 Bytes
Binary file not shown.
-6.23 KB
Binary file not shown.
-516 Bytes
Binary file not shown.

core/res/res/values/symbols.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@
12341234
<java-symbol type="drawable" name="magnified_region_frame" />
12351235
<java-symbol type="drawable" name="menu_background" />
12361236
<java-symbol type="drawable" name="stat_sys_secure" />
1237-
<java-symbol type="drawable" name="security_frame" />
1237+
<java-symbol type="drawable" name="kg_bouncer_bg_white" />
12381238
<java-symbol type="id" name="action_mode_bar_stub" />
12391239
<java-symbol type="id" name="alarm_status" />
12401240
<java-symbol type="id" name="backspace" />

policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetCarousel.java

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818
import android.content.Context;
1919
import android.util.AttributeSet;
20+
import android.view.View;
2021

2122
import com.android.internal.R;
2223

2324
public class KeyguardWidgetCarousel extends KeyguardWidgetPager {
2425

2526
private float mAdjacentPagesAngle;
27+
private static float MAX_SCROLL_PROGRESS = 1.3f;
2628
private static float CAMERA_DISTANCE = 10000;
2729

2830
public KeyguardWidgetCarousel(Context context, AttributeSet attrs) {
@@ -39,43 +41,73 @@ public KeyguardWidgetCarousel(Context context, AttributeSet attrs, int defStyle)
3941
}
4042

4143
protected float getMaxScrollProgress() {
42-
return 1.5f;
44+
return MAX_SCROLL_PROGRESS;
45+
}
46+
47+
public float getAlphaForPage(int screenCenter, int index) {
48+
View child = getChildAt(index);
49+
if (child == null) return 0f;
50+
51+
float scrollProgress = getScrollProgress(screenCenter, child, index);
52+
if (!isOverScrollChild(index, scrollProgress)) {
53+
scrollProgress = getBoundedScrollProgress(screenCenter, child, index);
54+
float alpha = 1 - Math.abs(scrollProgress / MAX_SCROLL_PROGRESS);
55+
return alpha;
56+
} else {
57+
return 1f;
58+
}
4359
}
4460

4561
private void updatePageAlphaValues(int screenCenter) {
46-
boolean isInOverscroll = mOverScrollX < 0 || mOverScrollX > mMaxScrollX;
47-
if (!isInOverscroll) {
62+
if (mChildrenOutlineFadeAnimation != null) {
63+
mChildrenOutlineFadeAnimation.cancel();
64+
mChildrenOutlineFadeAnimation = null;
65+
}
66+
if (!isReordering(false)) {
4867
for (int i = 0; i < getChildCount(); i++) {
4968
KeyguardWidgetFrame child = getWidgetPageAt(i);
5069
if (child != null) {
51-
float scrollProgress = getScrollProgress(screenCenter, child, i);
52-
if (!isReordering(false)) {
53-
child.setBackgroundAlphaMultiplier(
54-
backgroundAlphaInterpolator(Math.abs(scrollProgress)));
55-
} else {
56-
child.setBackgroundAlphaMultiplier(1f);
57-
}
70+
float alpha = getAlphaForPage(screenCenter, i);
71+
child.setBackgroundAlpha(alpha);
72+
child.setContentAlpha(alpha);
5873
}
5974
}
6075
}
76+
6177
}
6278

6379
@Override
6480
protected void screenScrolled(int screenCenter) {
81+
mScreenCenter = screenCenter;
6582
updatePageAlphaValues(screenCenter);
6683
for (int i = 0; i < getChildCount(); i++) {
6784
KeyguardWidgetFrame v = getWidgetPageAt(i);
68-
if (v == mDragView) continue;
69-
if (v != null) {
70-
float scrollProgress = getScrollProgress(screenCenter, v, i);
85+
float scrollProgress = getScrollProgress(screenCenter, v, i);
86+
if (v == mDragView || v == null) continue;
87+
v.setCameraDistance(CAMERA_DISTANCE);
88+
89+
if (isOverScrollChild(i, scrollProgress)) {
90+
v.setRotationY(- OVERSCROLL_MAX_ROTATION * scrollProgress);
91+
v.setOverScrollAmount(Math.abs(scrollProgress), scrollProgress < 0);
92+
} else {
93+
scrollProgress = getBoundedScrollProgress(screenCenter, v, i);
7194
int width = v.getMeasuredWidth();
7295
float pivotX = (width / 2f) + scrollProgress * (width / 2f);
7396
float pivotY = v.getMeasuredHeight() / 2;
7497
float rotationY = - mAdjacentPagesAngle * scrollProgress;
75-
v.setCameraDistance(CAMERA_DISTANCE);
7698
v.setPivotX(pivotX);
7799
v.setPivotY(pivotY);
78100
v.setRotationY(rotationY);
101+
v.setOverScrollAmount(0f, false);
102+
}
103+
104+
float alpha = v.getAlpha();
105+
// If the view has 0 alpha, we set it to be invisible so as to prevent
106+
// it from accepting touches
107+
if (alpha == 0) {
108+
v.setVisibility(INVISIBLE);
109+
} else if (v.getVisibility() != VISIBLE) {
110+
v.setVisibility(VISIBLE);
79111
}
80112
}
81113
}

policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetFrame.java

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class KeyguardWidgetFrame extends FrameLayout {
5151
private CheckLongPressHelper mLongPressHelper;
5252

5353
private float mBackgroundAlpha;
54+
private float mContentAlpha;
5455
private float mBackgroundAlphaMultiplier = 1.0f;
5556
private Drawable mBackgroundDrawable;
5657
private Rect mBackgroundRect = new Rect();
@@ -74,7 +75,7 @@ public KeyguardWidgetFrame(Context context, AttributeSet attrs, int defStyle) {
7475
int padding = (int) (res.getDisplayMetrics().density * 8);
7576
setPadding(padding, padding, padding, padding);
7677

77-
mBackgroundDrawable = res.getDrawable(R.drawable.security_frame);
78+
mBackgroundDrawable = res.getDrawable(R.drawable.kg_bouncer_bg_white);
7879
mGradientColor = res.getColor(com.android.internal.R.color.kg_widget_pager_gradient);
7980
mGradientPaint.setXfermode(sAddBlendMode);
8081
}
@@ -133,6 +134,23 @@ public void cancelLongPress() {
133134
mLongPressHelper.cancelLongPress();
134135
}
135136

137+
138+
private void drawGradientOverlay(Canvas c) {
139+
mGradientPaint.setShader(mForegroundGradient);
140+
mGradientPaint.setAlpha(mForegroundAlpha);
141+
c.drawRect(mForegroundRect, mGradientPaint);
142+
}
143+
144+
protected void drawBg(Canvas canvas) {
145+
if (mBackgroundAlpha > 0.0f) {
146+
Drawable bg = mBackgroundDrawable;
147+
148+
bg.setAlpha((int) (mBackgroundAlpha * mBackgroundAlphaMultiplier * 255));
149+
bg.setBounds(mBackgroundRect);
150+
bg.draw(canvas);
151+
}
152+
}
153+
136154
@Override
137155
protected void dispatchDraw(Canvas canvas) {
138156
drawBg(canvas);
@@ -164,6 +182,14 @@ public void disableHardwareLayersForContent() {
164182
}
165183
}
166184

185+
public void enableHardwareLayers() {
186+
setLayerType(LAYER_TYPE_HARDWARE, null);
187+
}
188+
189+
public void disableHardwareLayers() {
190+
setLayerType(LAYER_TYPE_NONE, null);
191+
}
192+
167193
public View getContent() {
168194
return getChildAt(0);
169195
}
@@ -177,28 +203,12 @@ public int getContentAppWidgetId() {
177203
}
178204
}
179205

180-
private void drawGradientOverlay(Canvas c) {
181-
mGradientPaint.setShader(mForegroundGradient);
182-
mGradientPaint.setAlpha(mForegroundAlpha);
183-
c.drawRect(mForegroundRect, mGradientPaint);
184-
}
185-
186-
protected void drawBg(Canvas canvas) {
187-
if (mBackgroundAlpha > 0.0f) {
188-
Drawable bg = mBackgroundDrawable;
189-
190-
bg.setAlpha((int) (mBackgroundAlpha * mBackgroundAlphaMultiplier * 255));
191-
bg.setBounds(mBackgroundRect);
192-
bg.draw(canvas);
193-
}
194-
}
195-
196206
public float getBackgroundAlpha() {
197207
return mBackgroundAlpha;
198208
}
199209

200210
public void setBackgroundAlphaMultiplier(float multiplier) {
201-
if (mBackgroundAlphaMultiplier != multiplier) {
211+
if (Float.compare(mBackgroundAlphaMultiplier, multiplier) != 0) {
202212
mBackgroundAlphaMultiplier = multiplier;
203213
invalidate();
204214
}
@@ -209,13 +219,18 @@ public float getBackgroundAlphaMultiplier() {
209219
}
210220

211221
public void setBackgroundAlpha(float alpha) {
212-
if (mBackgroundAlpha != alpha) {
222+
if (Float.compare(mBackgroundAlpha, alpha) != 0) {
213223
mBackgroundAlpha = alpha;
214224
invalidate();
215225
}
216226
}
217227

228+
public float getContentAlpha() {
229+
return mContentAlpha;
230+
}
231+
218232
public void setContentAlpha(float alpha) {
233+
mContentAlpha = alpha;
219234
View content = getContent();
220235
if (content != null) {
221236
content.setAlpha(alpha);

0 commit comments

Comments
 (0)