summaryrefslogtreecommitdiff
path: root/core/java/android/widget/StackView.java
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2010-12-13 12:29:17 -0800
committerAdam Cohen <adamcohen@google.com>2010-12-14 18:25:35 -0800
commit026e121bc35b9012943d8ea86518b51270d0c0ef (patch)
treeca25ec9521f083cfd11c5dcec5f7986e27232c37 /core/java/android/widget/StackView.java
parent6b8653c6a366de45a3a75fbd3898a6ae67756008 (diff)
New stack visualization
Change-Id: I0c479f92a3682dfb917e00935365dd3e99456daf
Diffstat (limited to 'core/java/android/widget/StackView.java')
-rw-r--r--core/java/android/widget/StackView.java92
1 files changed, 55 insertions, 37 deletions
diff --git a/core/java/android/widget/StackView.java b/core/java/android/widget/StackView.java
index feb09724155d..8b2f166f1864 100644
--- a/core/java/android/widget/StackView.java
+++ b/core/java/android/widget/StackView.java
@@ -22,6 +22,7 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
+import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
@@ -52,14 +53,17 @@ public class StackView extends AdapterViewAnimator {
* Default animation parameters
*/
private static final int DEFAULT_ANIMATION_DURATION = 400;
+ private static final int FADE_IN_ANIMATION_DURATION = 800;
private static final int MINIMUM_ANIMATION_DURATION = 50;
/**
* Parameters effecting the perspective visuals
*/
- private static float PERSPECTIVE_SHIFT_FACTOR = 0.12f;
+ private static final float PERSPECTIVE_SHIFT_FACTOR_Y = 0.1f;
+ private static final float PERSPECTIVE_SHIFT_FACTOR_X = 0.1f;
+
@SuppressWarnings({"FieldCanBeLocal"})
- private static float PERSPECTIVE_SCALE_FACTOR = 0.35f;
+ private static final float PERSPECTIVE_SCALE_FACTOR = 0.f;
/**
* Represent the two possible stack modes, one where items slide up, and the other
@@ -184,7 +188,7 @@ public class StackView extends AdapterViewAnimator {
* Animate the views between different relative indexes within the {@link AdapterViewAnimator}
*/
void animateViewForTransition(int fromIndex, int toIndex, View view) {
- if (fromIndex == -1 && toIndex != 0) {
+ if (fromIndex == -1 && toIndex > 0) {
// Fade item in
if (view.getAlpha() == 1) {
view.setAlpha(0);
@@ -192,7 +196,7 @@ public class StackView extends AdapterViewAnimator {
view.setVisibility(VISIBLE);
ObjectAnimator fadeIn = ObjectAnimator.ofFloat(view, "alpha", view.getAlpha(), 1.0f);
- fadeIn.setDuration(DEFAULT_ANIMATION_DURATION);
+ fadeIn.setDuration(FADE_IN_ANIMATION_DURATION);
fadeIn.start();
} else if (fromIndex == 0 && toIndex == 1) {
// Slide item in
@@ -239,12 +243,46 @@ public class StackView extends AdapterViewAnimator {
}
}
+ private void transformViewAtIndex(int index, View view) {
+ float maxPerspectiveShiftY = getMeasuredHeight() * PERSPECTIVE_SHIFT_FACTOR_Y;
+ float maxPerspectiveShiftX = getMeasuredHeight() * PERSPECTIVE_SHIFT_FACTOR_X;
+
+ index = mMaxNumActiveViews - index - 1;
+ if (index == mMaxNumActiveViews - 1) index--;
+
+ float r = (index * 1.0f) / (mMaxNumActiveViews - 2);
+
+ float scale = 1 - PERSPECTIVE_SCALE_FACTOR * (1 - r);
+ PropertyValuesHolder scalePropX = PropertyValuesHolder.ofFloat("scaleX", scale);
+ PropertyValuesHolder scalePropY = PropertyValuesHolder.ofFloat("scaleY", scale);
+
+ int stackDirection = (mStackMode == ITEMS_SLIDE_UP) ? 1 : -1;
+ float perspectiveTranslationY = -stackDirection * r * maxPerspectiveShiftY;
+ float scaleShiftCorrectionY = stackDirection * (1 - scale) *
+ (getMeasuredHeight() * (1 - PERSPECTIVE_SHIFT_FACTOR_Y) / 2.0f);
+ float transY = perspectiveTranslationY + scaleShiftCorrectionY;
+
+ float perspectiveTranslationX = (1 - r) * maxPerspectiveShiftX;
+ float scaleShiftCorrectionX = (1 - scale) *
+ (getMeasuredWidth() * (1 - PERSPECTIVE_SHIFT_FACTOR_X) / 2.0f);
+ float transX = perspectiveTranslationX + scaleShiftCorrectionX;
+
+ PropertyValuesHolder translationX = PropertyValuesHolder.ofFloat("translationX", transX);
+ PropertyValuesHolder translationY = PropertyValuesHolder.ofFloat("translationY", transY);
+
+ ObjectAnimator pa = ObjectAnimator.ofPropertyValuesHolder(view, scalePropX, scalePropY,
+ translationY, translationX);
+ pa.setDuration(100);
+ pa.start();
+ }
+
private void setupStackSlider(View v, int mode) {
mStackSlider.setMode(mode);
if (v != null) {
mHighlight.setImageBitmap(sHolographicHelper.createOutline(v));
mHighlight.setRotation(v.getRotation());
mHighlight.setTranslationY(v.getTranslationY());
+ mHighlight.setTranslationX(v.getTranslationX());
mHighlight.bringToFront();
v.bringToFront();
mStackSlider.setView(v);
@@ -283,32 +321,6 @@ public class StackView extends AdapterViewAnimator {
super.showPrevious();
}
- private void transformViewAtIndex(int index, View view) {
- float maxPerpectiveShift = getMeasuredHeight() * PERSPECTIVE_SHIFT_FACTOR;
-
- index = mMaxNumActiveViews - index - 1;
- if (index == mMaxNumActiveViews - 1) index--;
-
- float r = (index * 1.0f) / (mMaxNumActiveViews - 2);
-
- float scale = 1 - PERSPECTIVE_SCALE_FACTOR * (1 - r);
- PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", scale);
- PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", scale);
-
- r = (float) Math.pow(r, 2);
-
- int stackDirection = (mStackMode == ITEMS_SLIDE_UP) ? 1 : -1;
- float perspectiveTranslation = -stackDirection * r * maxPerpectiveShift;
- float scaleShiftCorrection = stackDirection * (1 - scale) *
- (getMeasuredHeight() * (1 - PERSPECTIVE_SHIFT_FACTOR) / 2.0f);
- float transY = perspectiveTranslation + scaleShiftCorrection;
-
- PropertyValuesHolder translationY = PropertyValuesHolder.ofFloat("translationY", transY);
- ObjectAnimator pa = ObjectAnimator.ofPropertyValuesHolder(view, scaleX, scaleY, translationY);
- pa.setDuration(100);
- pa.start();
- }
-
@Override
void showOnly(int childIndex, boolean animate, boolean onLayout) {
super.showOnly(childIndex, animate, onLayout);
@@ -910,8 +922,9 @@ public class StackView extends AdapterViewAnimator {
private void measureChildren() {
final int count = getChildCount();
- final int childWidth = getMeasuredWidth() - mPaddingLeft - mPaddingRight;
- final int childHeight = Math.round(getMeasuredHeight()*(1-PERSPECTIVE_SHIFT_FACTOR))
+ final int childWidth = Math.round(getMeasuredWidth()*(1-PERSPECTIVE_SHIFT_FACTOR_X))
+ - mPaddingLeft - mPaddingRight;
+ final int childHeight = Math.round(getMeasuredHeight()*(1-PERSPECTIVE_SHIFT_FACTOR_Y))
- mPaddingTop - mPaddingBottom;
for (int i = 0; i < count; i++) {
@@ -932,14 +945,14 @@ public class StackView extends AdapterViewAnimator {
// We need to deal with the case where our parent hasn't told us how
// big we should be. In this case we should
- float factor = 1/(1 - PERSPECTIVE_SHIFT_FACTOR);
+ float factorY = 1/(1 - PERSPECTIVE_SHIFT_FACTOR_Y);
if (heightSpecMode == MeasureSpec.UNSPECIFIED) {
heightSpecSize = haveChildRefSize ?
- Math.round(mReferenceChildHeight * (1 + factor)) +
+ Math.round(mReferenceChildHeight * (1 + factorY)) +
mPaddingTop + mPaddingBottom : 0;
} else if (heightSpecMode == MeasureSpec.AT_MOST) {
if (haveChildRefSize) {
- int height = Math.round(mReferenceChildHeight * (1 + factor))
+ int height = Math.round(mReferenceChildHeight * (1 + factorY))
+ mPaddingTop + mPaddingBottom;
if (height <= heightSpecSize) {
heightSpecSize = height;
@@ -951,9 +964,11 @@ public class StackView extends AdapterViewAnimator {
}
}
+ float factorX = 1/(1 - PERSPECTIVE_SHIFT_FACTOR_X);
if (widthSpecMode == MeasureSpec.UNSPECIFIED) {
- widthSpecSize = haveChildRefSize ? mReferenceChildWidth + mPaddingLeft +
- mPaddingRight : 0;
+ widthSpecSize = haveChildRefSize ?
+ Math.round(mReferenceChildWidth * (1 + factorX)) +
+ mPaddingLeft + mPaddingRight : 0;
} else if (heightSpecMode == MeasureSpec.AT_MOST) {
if (haveChildRefSize) {
int width = mReferenceChildWidth + mPaddingLeft + mPaddingRight;
@@ -1122,13 +1137,16 @@ public class StackView extends AdapterViewAnimator {
float rotationX = v.getRotationX();
float rotation = v.getRotation();
float translationY = v.getTranslationY();
+ float translationX = v.getTranslationX();
v.setRotationX(0);
v.setRotation(0);
v.setTranslationY(0);
+ v.setTranslationX(0);
v.draw(mCanvas);
v.setRotationX(rotationX);
v.setRotation(rotation);
v.setTranslationY(translationY);
+ v.setTranslationX(translationX);
drawOutline(mCanvas, bitmap);
return bitmap;