summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-08-12 11:50:08 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2009-08-12 11:50:08 -0700
commit0ab8c3755f7126302446de42897219956feaba5b (patch)
treeb7a9267ce912b008d49acb07af111d702466e1db /src
parentccb9d2ad939765561eb936b045f899ab83f42b02 (diff)
parentd769a63e6c439536b3a5a52c1914271d07a4605a (diff)
downloadandroid_packages_apps_Trebuchet-0ab8c3755f7126302446de42897219956feaba5b.tar.gz
android_packages_apps_Trebuchet-0ab8c3755f7126302446de42897219956feaba5b.tar.bz2
android_packages_apps_Trebuchet-0ab8c3755f7126302446de42897219956feaba5b.zip
Merge change 20970
* changes: fling
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher2/AllAppsView.java64
-rw-r--r--src/com/android/launcher2/IntAllocation.java18
2 files changed, 65 insertions, 17 deletions
diff --git a/src/com/android/launcher2/AllAppsView.java b/src/com/android/launcher2/AllAppsView.java
index 78e3f1a22..662a9dcbc 100644
--- a/src/com/android/launcher2/AllAppsView.java
+++ b/src/com/android/launcher2/AllAppsView.java
@@ -44,13 +44,16 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
+import android.os.SystemClock;
import android.util.AttributeSet;
import android.util.Log;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
-import android.view.KeyEvent;
-import android.view.MotionEvent;
+import android.view.VelocityTracker;
+import android.view.ViewConfiguration;
import android.graphics.PixelFormat;
@@ -58,12 +61,16 @@ public class AllAppsView extends RSSurfaceView {
private RenderScript mRS;
private RolloRS mRollo;
+ private ViewConfiguration mConfig;
+ private VelocityTracker mVelocity;
+ private int mLastScrollX;
private int mLastMotionX;
public AllAppsView(Context context) {
super(context);
setFocusable(true);
getHolder().setFormat(PixelFormat.TRANSLUCENT);
+ mConfig = ViewConfiguration.get(context);
}
public AllAppsView(Context context, AttributeSet attrs) {
@@ -98,18 +105,34 @@ public class AllAppsView extends RSSurfaceView {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
mLastMotionX = x;
+ mRollo.mState.read();
+ mRollo.mState.scrollX = mLastScrollX = mRollo.mState.currentScrollX;
+ mRollo.mState.flingVelocityX = 0;
+ mRollo.mState.adjustedDeceleration = 0;
+ mRollo.mState.save();
+ mVelocity = VelocityTracker.obtain();
+ mVelocity.addMovement(ev);
break;
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_OUTSIDE:
deltaX = x - mLastMotionX;
- mRollo.mState.scrollX += deltaX;
- Log.d(Launcher.LOG_TAG, "updated scrollX=" + mRollo.mState.scrollX);
+ mVelocity.addMovement(ev);
+ mRollo.mState.currentScrollX = mLastScrollX;
+ mLastScrollX += deltaX;
+ mRollo.mState.scrollX = mLastScrollX;
mRollo.mState.save();
mLastMotionX = x;
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
+ mVelocity.computeCurrentVelocity(1000 /* px/sec */,
+ mConfig.getScaledMaximumFlingVelocity());
+ mRollo.mState.flingTimeMs = (int)SystemClock.uptimeMillis(); // TODO: use long
+ mRollo.mState.flingVelocityX = (int)mVelocity.getXVelocity();
+ mRollo.mState.save();
mLastMotionX = -10000;
+ mVelocity.recycle();
+ mVelocity = null;
break;
}
return true;
@@ -131,11 +154,6 @@ public class AllAppsView extends RSSurfaceView {
public class RolloRS {
// Allocations ======
- static final int ALLOC_PARAMS = 0;
- static final int ALLOC_STATE = 1;
- static final int ALLOC_SCRATCH = 2;
- static final int ALLOC_ICON_IDS = 3;
- static final int ALLOC_LABEL_IDS = 4;
private int mWidth;
private int mHeight;
@@ -168,6 +186,14 @@ public class AllAppsView extends RSSurfaceView {
Params mParams;
State mState;
+ class Defines {
+ public static final int ALLOC_PARAMS = 0;
+ public static final int ALLOC_STATE = 1;
+ public static final int ALLOC_SCRATCH = 2;
+ public static final int ALLOC_ICON_IDS = 3;
+ public static final int ALLOC_LABEL_IDS = 4;
+ }
+
class Params extends IntAllocation {
Params(RenderScript rs) {
super(rs);
@@ -184,6 +210,10 @@ public class AllAppsView extends RSSurfaceView {
}
@AllocationIndex(0) public int iconCount;
@AllocationIndex(1) public int scrollX;
+ @AllocationIndex(2) public int flingTimeMs;
+ @AllocationIndex(3) public int flingVelocityX;
+ @AllocationIndex(4) public int adjustedDeceleration;
+ @AllocationIndex(5) public int currentScrollX;
}
public RolloRS() {
@@ -261,15 +291,14 @@ public class AllAppsView extends RSSurfaceView {
mRS.contextBindProgramVertex(mPV);
mAllocScratchBuf = new int[32];
- mAllocScratch = Allocation.createSized(mRS,
- Element.USER_I32, mAllocScratchBuf.length);
+ mAllocScratch = Allocation.createSized(mRS, Element.USER_I32, mAllocScratchBuf.length);
mAllocScratch.data(mAllocScratchBuf);
Log.e("rs", "Done loading named");
}
private void initData() {
- final int count = 29;
+ final int count = 100;
mParams = new Params(mRS);
mState = new State(mRS);
@@ -324,14 +353,15 @@ public class AllAppsView extends RSSurfaceView {
ScriptC.Builder sb = new ScriptC.Builder(mRS);
sb.setScript(mRes, R.raw.rollo);
sb.setRoot(true);
+ sb.addDefines(Defines.class);
mScript = sb.create();
mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- mScript.bindAllocation(mParams.getAllocation(), ALLOC_PARAMS);
- mScript.bindAllocation(mState.getAllocation(), ALLOC_STATE);
- mScript.bindAllocation(mAllocIconID, ALLOC_ICON_IDS);
- mScript.bindAllocation(mAllocScratch, ALLOC_SCRATCH);
- mScript.bindAllocation(mAllocLabelID, ALLOC_LABEL_IDS);
+ mScript.bindAllocation(mParams.getAllocation(), Defines.ALLOC_PARAMS);
+ mScript.bindAllocation(mState.getAllocation(), Defines.ALLOC_STATE);
+ mScript.bindAllocation(mAllocIconID, Defines.ALLOC_ICON_IDS);
+ mScript.bindAllocation(mAllocScratch, Defines.ALLOC_SCRATCH);
+ mScript.bindAllocation(mAllocLabelID, Defines.ALLOC_LABEL_IDS);
mRS.contextBindRootScript(mScript);
}
diff --git a/src/com/android/launcher2/IntAllocation.java b/src/com/android/launcher2/IntAllocation.java
index ab9d9155d..dde3d22dd 100644
--- a/src/com/android/launcher2/IntAllocation.java
+++ b/src/com/android/launcher2/IntAllocation.java
@@ -81,6 +81,24 @@ public class IntAllocation {
mAlloc.data(buf);
}
+ public void read() {
+ int[] buf = mBuffer;
+ if (buf != null) {
+ mAlloc.readData(buf);
+ Field[] fields = this.getClass().getFields();
+ for (Field f: fields) {
+ AllocationIndex index = f.getAnnotation(AllocationIndex.class);
+ if (index != null) {
+ try {
+ f.setInt(this, buf[index.value()]);
+ } catch (IllegalAccessException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ }
+ }
+ }
+
Allocation getAllocation() {
return mAlloc;
}