Add ability to set overscroll slot count
Change-Id: I10541172d99e1ede5b27bfcef106afadc0e540d4
diff --git a/carousel/java/com/android/ex/carousel/CarouselController.java b/carousel/java/com/android/ex/carousel/CarouselController.java
index cd29f68..8bb9c01 100644
--- a/carousel/java/com/android/ex/carousel/CarouselController.java
+++ b/carousel/java/com/android/ex/carousel/CarouselController.java
@@ -39,6 +39,7 @@
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_OVERSCROLL_SLOTS = 1.0f;
private final float DEFAULT_ROW_SPACING = 0.0f;
private final float DEFAULT_SWAY_SENSITIVITY = 0.0f;
private final float DEFAULT_FRICTION_COEFFICIENT = 10.0f;
@@ -72,6 +73,7 @@
private float mRadius = DEFAULT_RADIUS;
private float mCardRotation = 0.0f;
private boolean mCardsFaceTangent = false;
+ private float mOverscrollSlots = DEFAULT_OVERSCROLL_SLOTS;
private float mSwaySensitivity = DEFAULT_SWAY_SENSITIVITY;
private float mFrictionCoefficient = DEFAULT_FRICTION_COEFFICIENT;
private float mDragFactor = DEFAULT_DRAG_FACTOR;
@@ -109,6 +111,7 @@
setVisibleSlots(mVisibleSlots);
setVisibleDetails(mVisibleDetails);
setPrefetchCardCount(mPrefetchCardCount);
+ setOverscrollSlots(mOverscrollSlots);
setRowCount(mRowCount);
setRowSpacing(mRowSpacing);
setFirstCardTop(mFirstCardTop);
@@ -276,6 +279,16 @@
}
/**
+ * Sets the amount of allowed overscroll (in slots)
+ */
+ public void setOverscrollSlots(float slots) {
+ mOverscrollSlots = slots;
+ if (mRenderScript != null) {
+ mRenderScript.setOverscrollSlots(slots);
+ }
+ }
+
+ /**
* 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 8d32452..9d78d09 100644
--- a/carousel/java/com/android/ex/carousel/CarouselRS.java
+++ b/carousel/java/com/android/ex/carousel/CarouselRS.java
@@ -510,6 +510,10 @@
mScript.set_rowSpacing(spacing);
}
+ public void setOverscrollSlots(float slots) {
+ mScript.set_overscrollSlots(slots);
+ }
+
public void setFirstCardTop(boolean first) {
mScript.set_firstCardTop(first);
}
diff --git a/carousel/java/com/android/ex/carousel/CarouselView.java b/carousel/java/com/android/ex/carousel/CarouselView.java
index 235387b..25c7366 100644
--- a/carousel/java/com/android/ex/carousel/CarouselView.java
+++ b/carousel/java/com/android/ex/carousel/CarouselView.java
@@ -275,6 +275,13 @@
}
/**
+ * Sets the amount of allowed overscroll (in slots)
+ */
+ public void setOverscrollSlots(float slots) {
+ mController.setOverscrollSlots(slots);
+ }
+
+ /**
* 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 a5ff4e6..c4dce91 100644
--- a/carousel/java/com/android/ex/carousel/carousel.rs
+++ b/carousel/java/com/android/ex/carousel/carousel.rs
@@ -152,7 +152,6 @@
static const int ANIMATION_SCALE_UP_TIME = 200; // Time it takes to animate selected card, in ms
static const int ANIMATION_SCALE_DOWN_TIME = 200; // Time it takes to animate selected card, in ms
static const float3 SELECTED_SCALE_FACTOR = { 0.1f, 0.1f, 0.1f }; // increase by this %
-static const float OVERSCROLL_SLOTS = 1.0f; // amount of allowed overscroll (in slots)
static const int VELOCITY_HISTORY_MAX = 10; // # recent velocity samples used to calculate average
static const int VISIBLE_SLOT_PADDING = 2; // # slots to draw on either side of visible slots
@@ -190,6 +189,7 @@
int rowCount; // number of rows of cards in a given slot, default 1
float rowSpacing; // spacing between rows of cards
bool firstCardTop; // set true for first card on top row when multiple rows used
+float overscrollSlots; // amount of allowed overscroll (in slots)
int dragModel = DRAG_MODEL_SCREEN_DELTA;
int fillDirection; // the order in which to lay out cards: +1 for CCW (default), -1 for CW
@@ -1202,8 +1202,8 @@
float deltaOmega = dragFunction(x, y);
if (!enableSelection) {
bias += deltaOmega;
- bias = clamp(bias, lowBias - wedgeAngle(OVERSCROLL_SLOTS),
- highBias + wedgeAngle(OVERSCROLL_SLOTS));
+ bias = clamp(bias, lowBias - wedgeAngle(overscrollSlots),
+ highBias + wedgeAngle(overscrollSlots));
}
const float2 delta = (float2) { x, y } - touchPosition;
float distance = sqrt(dot(delta, delta));
@@ -1606,8 +1606,8 @@
velocity = 0.0f; // prevent bouncing due to v > 0 after overscroll animation.
}
}
- float newbias = clamp(bias, lowBias - wedgeAngle(OVERSCROLL_SLOTS),
- highBias + wedgeAngle(OVERSCROLL_SLOTS));
+ float newbias = clamp(bias, lowBias - wedgeAngle(overscrollSlots),
+ highBias + wedgeAngle(overscrollSlots));
if (newbias != bias) { // we clamped
velocity = 0.0f;
isOverScrolling = true;