summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/view
diff options
context:
space:
mode:
authorMichael Kolb <kolby@google.com>2011-08-09 10:24:41 -0700
committerMichael Kolb <kolby@google.com>2011-08-15 13:31:03 -0700
commitc3af06776be83ba64a0d3549cb72ca6e5e7f03cd (patch)
tree60d1a15205ac0b46f94528c0da0963a79f6d547e /src/com/android/browser/view
parent8d5af2d0208aa5b5197f50e12ba11c5565d74dc4 (diff)
downloadpackages_apps_Browser-c3af06776be83ba64a0d3549cb72ca6e5e7f03cd.zip
packages_apps_Browser-c3af06776be83ba64a0d3549cb72ca6e5e7f03cd.tar.gz
packages_apps_Browser-c3af06776be83ba64a0d3549cb72ca6e5e7f03cd.tar.bz2
Tab switcher animation
Bug: 5123884 first step towards animations between browser and tab switcher Change-Id: I1d959d42d0036f3c4498972fcc8ad434fa7f4437
Diffstat (limited to 'src/com/android/browser/view')
-rw-r--r--src/com/android/browser/view/Gallery.java62
1 files changed, 56 insertions, 6 deletions
diff --git a/src/com/android/browser/view/Gallery.java b/src/com/android/browser/view/Gallery.java
index 78d4bc6..2e2c75f 100644
--- a/src/com/android/browser/view/Gallery.java
+++ b/src/com/android/browser/view/Gallery.java
@@ -34,6 +34,8 @@ import android.view.SoundEffectConstants;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
+import android.view.animation.BounceInterpolator;
+import android.view.animation.DecelerateInterpolator;
import android.view.animation.Transformation;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
@@ -130,6 +132,8 @@ public class Gallery extends ViewGroup implements
private float mLastMotionCoord;
private float mLastOrthoCoord;
+ private int mScrollValue;
+
public Gallery(Context context) {
this(context, null);
}
@@ -172,6 +176,7 @@ public class Gallery extends ViewGroup implements
mGap = 0;
// proguard
setGap(getGap());
+ setScrollValue(getScrollValue());
}
/**
@@ -180,7 +185,10 @@ public class Gallery extends ViewGroup implements
*/
public interface OnItemSelectedListener {
void onItemSelected(ViewGroup parent, View view, int position, long id);
+ }
+ public interface OnScrollFinishedListener {
+ void onScrollFinished();
}
/**
@@ -226,6 +234,11 @@ public class Gallery extends ViewGroup implements
return mGap;
}
+ public void setAdapter(BaseAdapter adapter, int selpos) {
+ mSelectedPosition = selpos;
+ setAdapter(adapter);
+ }
+
public void setAdapter(BaseAdapter adapter) {
mAdapter = adapter;
if (mAdapter != null) {
@@ -246,7 +259,7 @@ public class Gallery extends ViewGroup implements
handleDataChanged();
}
- void handleDataChanged() {
+ public void handleDataChanged() {
if (mAdapter != null) {
if (mGapAnimator != null) {
mGapAnimator.cancel();
@@ -427,7 +440,8 @@ public class Gallery extends ViewGroup implements
return;
}
boolean toLeft = deltaX < 0;
- int limitedDeltaX = getLimitedMotionScrollAmount(toLeft, deltaX);
+ int limitedDeltaX = mFlingRunnable.mScroller.isFinished()
+ ? deltaX : getLimitedMotionScrollAmount(toLeft, deltaX);
if (limitedDeltaX != deltaX) {
// The above call returned a limited amount, so stop any
// scrolls/flings
@@ -1178,7 +1192,7 @@ public class Gallery extends ViewGroup implements
}
}
- boolean moveNext() {
+ public boolean moveNext() {
if (mItemCount > 0 && mSelectedPosition < mItemCount - 1) {
scrollToChild(mSelectedPosition - mFirstPosition + 1);
return true;
@@ -1187,16 +1201,48 @@ public class Gallery extends ViewGroup implements
}
}
- protected boolean scrollToChild(int childPosition) {
+ public boolean scrollToChild(int childPosition) {
View child = getChildAt(childPosition);
if (child != null) {
int distance = getCenterOfGallery() - getCenterOfView(child);
- mFlingRunnable.startUsingDistance(distance);
+ mFlingRunnable.startUsingDistance(distance, 0);
return true;
}
return false;
}
+ /**
+ * use the scroller to scroll to a new position, independent
+ * of whether attached or not
+ * this uses trackMotionScroll, which will set the selection
+ */
+ public void smoothScrollToPosition(int pos, int duration,
+ final OnScrollFinishedListener listener) {
+ if (pos >= mAdapter.getCount() || getChildCount() < 1) return;
+ int dist = (mSelectedPosition - pos) * (mHorizontal ? getChildHeight(getChildAt(0))
+ : getChildWidth(getChildAt(0)));
+ ObjectAnimator scroll = ObjectAnimator.ofInt(this, "scrollValue", 0, dist);
+ scroll.setDuration(duration);
+ scroll.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ mScrollValue = 0;
+ listener.onScrollFinished();
+ }
+ });
+ scroll.setInterpolator(new BounceInterpolator());
+ scroll.start();
+ }
+
+ public void setScrollValue(int scroll) {
+ trackMotionScroll(scroll - mScrollValue);
+ mScrollValue = scroll;
+ }
+
+ public int getScrollValue() {
+ return mScrollValue;
+ }
+
protected void setSelectedPositionInt(int position) {
mSelectedPosition = position;
updateSelectedItemMetadata();
@@ -1368,11 +1414,15 @@ public class Gallery extends ViewGroup implements
}
public void startUsingDistance(int distance) {
+ startUsingDistance(distance, mAnimationDuration);
+ }
+
+ public void startUsingDistance(int distance, int duration) {
if (distance == 0)
return;
startCommon();
mLastFlingX = 0;
- mScroller.startScroll(0, 0, -distance, 0, mAnimationDuration);
+ mScroller.startScroll(0, 0, -distance, 0, duration);
post(this);
}