diff options
| author | Bryan Mawhinney <bryanmawhinney@google.com> | 2010-11-12 09:59:35 +0000 |
|---|---|---|
| committer | Bryan Mawhinney <bryanmawhinney@google.com> | 2010-11-16 17:51:40 +0000 |
| commit | 0cec8afdb4f9d78adf88c9b9b41e993aef617bea (patch) | |
| tree | 56fabec4c2700d4a254364032c2160554cc035f3 /carousel | |
| parent | 6af401bca5f8854524d128e9df5700035fae1160 (diff) | |
| download | android_frameworks_ex-0cec8afdb4f9d78adf88c9b9b41e993aef617bea.tar.gz android_frameworks_ex-0cec8afdb4f9d78adf88c9b9b41e993aef617bea.tar.bz2 android_frameworks_ex-0cec8afdb4f9d78adf88c9b9b41e993aef617bea.zip | |
Add multiple row support to carousel.
Change-Id: Ic4f2586b1ff45a40c03a728b1664c55977c7b846
Diffstat (limited to 'carousel')
4 files changed, 85 insertions, 20 deletions
diff --git a/carousel/java/com/android/ex/carousel/CarouselController.java b/carousel/java/com/android/ex/carousel/CarouselController.java index 68b2f7c..d61e2a7 100644 --- a/carousel/java/com/android/ex/carousel/CarouselController.java +++ b/carousel/java/com/android/ex/carousel/CarouselController.java @@ -40,6 +40,8 @@ public class CarouselController { private final float DEFAULT_RADIUS = 20.0f; private final int DEFAULT_VISIBLE_DETAIL_COUNT = 3; private final int DEFAULT_PREFETCH_CARD_COUNT = 2; + private final int DEFAULT_ROW_COUNT = 1; + private final float DEFAULT_ROW_SPACING = 0.0f; private final float DEFAULT_SWAY_SENSITIVITY = 0.0f; private final float DEFAULT_FRICTION_COEFFICIENT = 10.0f; private final float DEFAULT_DRAG_FACTOR = 0.25f; @@ -75,6 +77,8 @@ public class CarouselController { private float mFrictionCoefficient = DEFAULT_FRICTION_COEFFICIENT; private float mDragFactor = DEFAULT_DRAG_FACTOR; private int mSlotCount = DEFAULT_SLOT_COUNT; + private int mRowCount = DEFAULT_ROW_COUNT; + private float mRowSpacing = DEFAULT_ROW_SPACING; private float mEye[] = { 20.6829f, 2.77081f, 16.7314f }; private float mAt[] = { 14.7255f, -3.40001f, -1.30184f }; private float mUp[] = { 0.0f, 1.0f, 0.0f }; @@ -101,6 +105,8 @@ public class CarouselController { setVisibleSlots(mVisibleSlots); setVisibleDetails(mVisibleDetails); setPrefetchCardCount(mPrefetchCardCount); + setRowCount(mRowCount); + setRowSpacing(mRowSpacing); setDetailTextureAlignment(mDetailTextureAlignment); setForceBlendCardsWithZ(mForceBlendCardsWithZ); setDrawRuler(mDrawRuler); @@ -208,6 +214,26 @@ public class CarouselController { } /** + * Sets the number of rows of cards to show in each slot. + */ + public void setRowCount(int n) { + mRowCount = n; + if (mRenderScript != null) { + mRenderScript.setRowCount(n); + } + } + + /** + * Sets the spacing between each row of cards when rowCount > 1. + */ + public void setRowSpacing(float s) { + mRowSpacing = s; + if (mRenderScript != null) { + mRenderScript.setRowSpacing(s); + } + } + + /** * Sets how detail textures are aligned with respect to the card. * * @param alignment a bitmask of DetailAlignment flags. diff --git a/carousel/java/com/android/ex/carousel/CarouselRS.java b/carousel/java/com/android/ex/carousel/CarouselRS.java index b0f208d..f97d881 100644 --- a/carousel/java/com/android/ex/carousel/CarouselRS.java +++ b/carousel/java/com/android/ex/carousel/CarouselRS.java @@ -32,6 +32,7 @@ import static android.renderscript.Element.*; public class CarouselRS { private static final int DEFAULT_VISIBLE_SLOTS = 1; private static final int DEFAULT_CARD_COUNT = 0; + private static final int DEFAULT_ROW_COUNT = 1; // Client messages *** THIS LIST MUST MATCH THOSE IN carousel.rs *** public static final int CMD_CARD_SELECTED = 100; @@ -73,6 +74,7 @@ public class CarouselRS { private ProgramRaster mRasterProgram; private Allocation[] mAllocationPool; private int mVisibleSlots; + private int mRowCount; private int mPrefetchCardCount; private CarouselCallback mCallback; private float[] mEyePoint = new float[] { 2.0f, 0.0f, 0.0f }; @@ -244,6 +246,7 @@ public class CarouselRS { initVertexProgram(); setSlotCount(DEFAULT_SLOT_COUNT); setVisibleSlots(DEFAULT_VISIBLE_SLOTS); + setRowCount(DEFAULT_ROW_COUNT); createCards(DEFAULT_CARD_COUNT); setStartAngle(0.0f); setCarouselRotationAngle(0.0f); @@ -408,6 +411,15 @@ public class CarouselRS { mScript.set_visibleDetailCount(count); } + public void setRowCount(int count) { + mRowCount = count; + mScript.set_rowCount(count); + } + + public void setRowSpacing(float spacing) { + mScript.set_rowSpacing(spacing); + } + public void setPrefetchCardCount(int count) { mPrefetchCardCount = count; mScript.set_prefetchCardCount(count); @@ -470,7 +482,7 @@ public class CarouselRS { private Allocation allocationFromPool(int n, Bitmap bitmap, boolean mipmap) { - int count = mVisibleSlots + mPrefetchCardCount; + int count = (mVisibleSlots + mPrefetchCardCount) * mRowCount; if (mAllocationPool == null || mAllocationPool.length != count) { Allocation[] tmp = new Allocation[count]; int oldsize = mAllocationPool == null ? 0 : mAllocationPool.length; diff --git a/carousel/java/com/android/ex/carousel/CarouselView.java b/carousel/java/com/android/ex/carousel/CarouselView.java index 90ddd4c..b995060 100644 --- a/carousel/java/com/android/ex/carousel/CarouselView.java +++ b/carousel/java/com/android/ex/carousel/CarouselView.java @@ -229,6 +229,20 @@ public abstract class CarouselView extends RSSurfaceView { } /** + * Sets the number of rows of cards to show in each slot. + */ + public void setRowCount(int n) { + mController.setRowCount(n); + } + + /** + * Sets the spacing between each row of cards when rowCount > 1. + */ + public void setRowSpacing(float s) { + mController.setRowSpacing(s); + } + + /** * Set the number of detail textures that can be visible at one time. * * @param n the number of slots diff --git a/carousel/java/com/android/ex/carousel/carousel.rs b/carousel/java/com/android/ex/carousel/carousel.rs index bb846ce..230d1fe 100644 --- a/carousel/java/com/android/ex/carousel/carousel.rs +++ b/carousel/java/com/android/ex/carousel/carousel.rs @@ -169,6 +169,9 @@ int fadeInDuration; // amount of time (in ms) for smoothly switching out texture float rezInCardCount; // this controls how rapidly distant card textures will be rez-ed in float detailFadeRate; // rate at which details fade as they move into the distance float4 backgroundColor; +int rowCount; // number of rows of cards in a given slot, default 1 +float rowSpacing; // spacing between rows of cards + int dragModel = DRAG_MODEL_SCREEN_DELTA; rs_program_store programStoreAlphaZ; rs_program_store programStoreAlphaNoZ; @@ -273,6 +276,8 @@ void init() { backgroundColor = (float4) { 0.0f, 0.0f, 0.0f, 1.0f }; cardAllocationValid = false; cardCount = 0; + rowCount = 1; + rowSpacing = 0.0f; fadeInDuration = 250; rezInCardCount = 0.0f; // alpha will ramp to 1.0f over this many cards (0.0f means disabled) detailFadeRate = 0.5f; // fade details over this many slot positions. @@ -329,22 +334,22 @@ float getAnimatedAlpha(int64_t startTime, int64_t currentTime) return min(1.0f, (float) alpha); } -// Return angle for position p. Typically p will be an integer position, but can be fractional. -static float cardPosition(float p) +// Returns total angle for given number of slots +static float wedgeAngle(float slots) { - return startAngle + bias + 2.0f * M_PI * p / slotCount; + return slots * 2.0f * M_PI / slotCount; } -// Return slot for a card in position p. Typically p will be an integer slot, but can be fractional. -static float slotPosition(float p) +// Return angle of slot in position p. +static float slotPosition(int p) { - return startAngle + 2.0f * M_PI * p / slotCount; + return startAngle + wedgeAngle(p); } -// Returns total angle for given number of cards -static float wedgeAngle(float cards) +// Return angle for card in position p. +static float cardPosition(int p) { - return cards * 2.0f * M_PI / slotCount; + return bias + slotPosition(p / rowCount); } // convert from carousel rotation angle (in card slot units) to radians. @@ -359,13 +364,6 @@ static float radiansToCarouselRotationAngle(float angle) return -angle * slotCount / ( 2.0f * M_PI ); } - -// Return the lowest slot number for a given angular position. -static int cardIndex(float angle) -{ - return floor(angle - startAngle - bias) * slotCount / (2.0f * M_PI); -} - // Set basic camera properties: // from - position of the camera in x,y,z // at - target we're looking at - used to compute view direction @@ -509,6 +507,19 @@ static float getSwayAngleForVelocity(float v, bool enableSway) return sway; } +// Returns the vertical offset for a card in its slot, +// depending on the number of rows configured. +static float getVerticalOffsetForCard(int i) { + if (rowCount == 1) { + // fast path + return 0; + } + const float cardHeight = cardVertices[3].y - cardVertices[0].y; + const float totalHeight = rowCount * (cardHeight + rowSpacing) - rowSpacing; + const float rowOffset = (i % rowCount) * (cardHeight + rowSpacing); + return (cardHeight - totalHeight) / 2 + rowOffset; +} + /* * Composes a matrix for the given card. * matrix: The output matrix. @@ -522,7 +533,7 @@ static bool getMatrixForCard(rs_matrix4x4* matrix, int i, bool enableSway) float theta = cardPosition(i); float swayAngle = getSwayAngleForVelocity(velocity, enableSway); rsMatrixRotate(matrix, degrees(theta), 0, 1, 0); - rsMatrixTranslate(matrix, radius, 0, 0); + rsMatrixTranslate(matrix, radius, getVerticalOffsetForCard(i), 0); float rotation = cardRotation + swayAngle; if (!cardsFaceTangent) { rotation -= theta; @@ -1006,8 +1017,9 @@ void doLongPress() void doMotion(float x, float y, long eventTime) { + const int totalSlots = (cardCount + rowCount - 1) / rowCount; const float firstBias = wedgeAngle(0.0f); - const float lastBias = -max(0.0f, wedgeAngle(cardCount - visibleDetailCount)); + const float lastBias = -max(0.0f, wedgeAngle(totalSlots - visibleDetailCount)); float deltaOmega = dragFunction(x, y); if (!enableSelection) { bias += deltaOmega; @@ -1292,8 +1304,9 @@ static bool updateNextPosition(int64_t currentTime) return true; } + const int totalSlots = (cardCount + rowCount - 1) / rowCount; const float firstBias = wedgeAngle(0.0f); - const float lastBias = -max(0.0f, wedgeAngle(cardCount - visibleDetailCount)); + const float lastBias = -max(0.0f, wedgeAngle(totalSlots - visibleDetailCount)); bool stillAnimating = false; if (overscroll) { if (bias > firstBias) { |
