From 536ebb37106a5f92f7479fdfbdcfb988d818ff9d Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Thu, 11 Mar 2010 12:32:24 -0800 Subject: [PATCH 1/8] Fix 2507267 - stack overflow when adding shortcut Change-Id: Ife5bea443debd481854693b3924e72a04fb66f97 --- src/com/android/launcher2/LauncherModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java index 00b17549b2..6560c5d35f 100644 --- a/src/com/android/launcher2/LauncherModel.java +++ b/src/com/android/launcher2/LauncherModel.java @@ -1089,7 +1089,7 @@ public class LauncherModel extends BroadcastReceiver { * doesn't have a Cursor, but */ public ShortcutInfo getShortcutInfo(PackageManager manager, Intent intent, Context context) { - return getShortcutInfo(manager, intent, context); + return getShortcutInfo(manager, intent, context, null, -1, -1); } /** From 7f5bbaaeaa327854936afbe7811e9792e7c20e36 Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Thu, 11 Mar 2010 12:38:48 -0800 Subject: [PATCH 2/8] Unbind root script around load activities to prevent commands from being delayed due to swap buffers. Change-Id: I9720fbe936d3cd336ca39235d0a1bba9e10d137a --- src/com/android/launcher2/AllApps3D.java | 388 ++++++++++++----------- 1 file changed, 200 insertions(+), 188 deletions(-) diff --git a/src/com/android/launcher2/AllApps3D.java b/src/com/android/launcher2/AllApps3D.java index e59fa6cb19..d977885682 100644 --- a/src/com/android/launcher2/AllApps3D.java +++ b/src/com/android/launcher2/AllApps3D.java @@ -88,7 +88,7 @@ public class AllApps3D extends RSSurfaceView private static RenderScriptGL mRS; private static RolloRS mRollo; - + /** * True when we are using arrow keys or trackball to drive navigation */ @@ -100,21 +100,21 @@ public class AllApps3D extends RSSurfaceView * One of the SELECTION_ constants. */ private int mLastSelection; - + /** * Used to keep track of the selection when AllAppsView loses window focus */ private int mLastSelectedIcon; - + private VelocityTracker mVelocityTracker; private int mTouchTracking; private int mMotionDownRawX; private int mMotionDownRawY; private int mDownIconIndex = -1; private int mCurrentIconIndex = -1; - + private boolean mShouldGainFocus; - + private boolean mHaveSurface = false; private boolean mZoomDirty = false; private boolean mAnimateNextZoom; @@ -123,7 +123,7 @@ public class AllApps3D extends RSSurfaceView private float mPosX; private float mVelocity; private AAMessage mMessageProc; - + private int mColumnsPerPage; private int mRowsPerPage; private boolean mSurrendered; @@ -135,22 +135,22 @@ public class AllApps3D extends RSSurfaceView public static final int ALLOC_ICON_IDS = 3; public static final int ALLOC_LABEL_IDS = 4; public static final int ALLOC_VP_CONSTANTS = 5; - + public static final int COLUMNS_PER_PAGE_PORTRAIT = 4; public static final int ROWS_PER_PAGE_PORTRAIT = 4; - + public static final int COLUMNS_PER_PAGE_LANDSCAPE = 6; public static final int ROWS_PER_PAGE_LANDSCAPE = 3; - + public static final int ICON_WIDTH_PX = 64; public static final int ICON_TEXTURE_WIDTH_PX = 74; public static final int SELECTION_TEXTURE_WIDTH_PX = 74 + 20; - + public static final int ICON_HEIGHT_PX = 64; public static final int ICON_TEXTURE_HEIGHT_PX = 74; public static final int SELECTION_TEXTURE_HEIGHT_PX = 74 + 20; } - + public AllApps3D(Context context, AttributeSet attrs) { super(context, attrs); setFocusable(true); @@ -159,12 +159,12 @@ public class AllApps3D extends RSSurfaceView final ViewConfiguration config = ViewConfiguration.get(context); mSlop = config.getScaledTouchSlop(); mMaxFlingVelocity = config.getScaledMaximumFlingVelocity(); - + setOnClickListener(this); setOnLongClickListener(this); setZOrderOnTop(true); getHolder().setFormat(PixelFormat.TRANSLUCENT); - + if (mRS == null) { mRS = createRenderScript(true); } else { @@ -184,12 +184,12 @@ public class AllApps3D extends RSSurfaceView mRollo.mInitialize = true; } } - + @SuppressWarnings({"UnusedDeclaration"}) public AllApps3D(Context context, AttributeSet attrs, int defStyle) { this(context, attrs); } - + public void surrender() { mRS.contextSetSurface(0, 0, null); mRS.mMessageCallback = null; @@ -207,7 +207,7 @@ public class AllApps3D extends RSSurfaceView mRS = null; } } - + /** * If you have an attached click listener, View always plays the click sound!?!? * Deal with sound effects by hand. @@ -218,11 +218,11 @@ public class AllApps3D extends RSSurfaceView playSoundEffect(sound); setSoundEffectsEnabled(old); } - + public void setLauncher(Launcher launcher) { mLauncher = launcher; } - + @Override public void surfaceDestroyed(SurfaceHolder holder) { super.surfaceDestroyed(holder); @@ -235,17 +235,17 @@ public class AllApps3D extends RSSurfaceView mZoomDirty = true; mHaveSurface = false; } - + @Override public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { //long startTime = SystemClock.uptimeMillis(); - + super.surfaceChanged(holder, format, w, h); - + if (mSurrendered) return; - + mHaveSurface = true; - + if (mRollo == null) { mRollo = new RolloRS(this); mRollo.init(getResources(), w, h); @@ -261,14 +261,14 @@ public class AllApps3D extends RSSurfaceView mRollo.initTouchState(w, h); mRollo.mInitialize = false; } - + mRollo.dirtyCheck(); mRollo.resize(w, h); - + if (mRS != null) { mRS.mMessageCallback = mMessageProc = new AAMessage(); } - + if (mRollo.mUniformAlloc != null) { float tf[] = new float[] {72.f, 72.f, 120.f, 120.f, 0.f, 0.f, @@ -281,20 +281,20 @@ public class AllApps3D extends RSSurfaceView tf[10] = -((float)w / 2) - 0.25f; tf[11] = -((float)h / 2) - 0.25f; } - + mRollo.mUniformAlloc.data(tf); } - + //long endTime = SystemClock.uptimeMillis(); //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms"); } - + @Override public void onWindowFocusChanged(boolean hasWindowFocus) { super.onWindowFocusChanged(hasWindowFocus); if (mSurrendered) return; - + if (mArrowNavigation) { if (!hasWindowFocus) { // Clear selection when we lose window focus @@ -315,7 +315,7 @@ public class AllApps3D extends RSSurfaceView (mColumnsPerPage * mRowsPerPage)) { selection = firstIcon; } - + // Select the first icon when we gain window focus mRollo.selectIcon(selection, SELECTED_FOCUSED); mRollo.mState.save(); @@ -327,15 +327,15 @@ public class AllApps3D extends RSSurfaceView } } } - + @Override protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); - + if (!isVisible() || mSurrendered) { return; } - + if (gainFocus) { if (mRollo != null) { gainFocus(); @@ -356,7 +356,7 @@ public class AllApps3D extends RSSurfaceView } } } - + private void gainFocus() { if (!mArrowNavigation && mRollo.mState.iconCount > 0) { // Select the first icon when we gain keyboard focus @@ -366,17 +366,17 @@ public class AllApps3D extends RSSurfaceView mRollo.mState.save(); } } - + @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - + boolean handled = false; - + if (!isVisible()) { return false; } final int iconCount = mRollo.mState.iconCount; - + if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) { if (mArrowNavigation) { if (mLastSelection == SELECTION_HOME) { @@ -392,22 +392,22 @@ public class AllApps3D extends RSSurfaceView } } } - + if (iconCount > 0) { mArrowNavigation = true; - + int currentSelection = mRollo.mState.selectedIconIndex; int currentTopRow = Math.round(mPosX); - + // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1 final int currentPageCol = currentSelection % mColumnsPerPage; - + // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1 final int currentPageRow = (currentSelection - (currentTopRow* mColumnsPerPage)) / mRowsPerPage; - + int newSelection = currentSelection; - + switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: if (mLastSelection == SELECTION_HOME) { @@ -440,7 +440,7 @@ public class AllApps3D extends RSSurfaceView } handled = true; break; - + case KeyEvent.KEYCODE_DPAD_DOWN: { final int rowCount = iconCount / mColumnsPerPage + (iconCount % mColumnsPerPage == 0 ? 0 : 1); @@ -496,25 +496,25 @@ public class AllApps3D extends RSSurfaceView } return handled; } - + @Override public boolean onTouchEvent(MotionEvent ev) { mArrowNavigation = false; - + if (!isVisible()) { return true; } - + if (mLocks != 0) { return true; } - + super.onTouchEvent(ev); - + int x = (int)ev.getX(); int y = (int)ev.getY(); - + final boolean isPortrait = getWidth() < getHeight(); int action = ev.getAction(); switch (action) { @@ -527,13 +527,13 @@ public class AllApps3D extends RSSurfaceView mCurrentIconIndex = -1; } else { mTouchTracking = TRACKING_FLING; - + mMotionDownRawX = (int)ev.getRawX(); mMotionDownRawY = (int)ev.getRawY(); - + mRollo.mState.newPositionX = ev.getRawY() / getHeight(); mRollo.mState.newTouchDown = 1; - + if (!mRollo.checkClickOK()) { mRollo.clearSelectedIcon(); } else { @@ -563,7 +563,7 @@ public class AllApps3D extends RSSurfaceView int rawY = (int)ev.getRawY(); int slop; slop = Math.abs(rawY - mMotionDownRawY); - + if (!mStartedScrolling && slop < mSlop) { // don't update anything so when we do start scrolling // below, we get the right delta. @@ -582,7 +582,7 @@ public class AllApps3D extends RSSurfaceView mRollo.mState.newPositionX = ev.getRawY() / getHeight(); mRollo.mState.newTouchDown = 1; mRollo.move(); - + mStartedScrolling = true; mRollo.clearSelectedIcon(); mVelocityTracker.addMovement(ev); @@ -606,13 +606,13 @@ public class AllApps3D extends RSSurfaceView } else if (mTouchTracking == TRACKING_FLING) { mRollo.mState.newTouchDown = 0; mRollo.mState.newPositionX = ev.getRawY() / getHeight(); - + mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity); mRollo.mState.flingVelocity = mVelocityTracker.getYVelocity() / getHeight(); mRollo.clearSelectedIcon(); mRollo.mState.save(); mRollo.fling(); - + if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; @@ -621,10 +621,10 @@ public class AllApps3D extends RSSurfaceView mTouchTracking = TRACKING_NONE; break; } - + return true; } - + public void onClick(View v) { if (mLocks != 0 || !isVisible()) { return; @@ -636,7 +636,7 @@ public class AllApps3D extends RSSurfaceView mLauncher.startActivitySafely(app.intent); } } - + public boolean onLongClick(View v) { if (mLocks != 0 || !isVisible()) { return true; @@ -644,23 +644,23 @@ public class AllApps3D extends RSSurfaceView if (mRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) { ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex); - + Bitmap bmp = app.iconBitmap; final int w = bmp.getWidth(); final int h = bmp.getHeight(); - + // We don't really have an accurate location to use. This will do. int screenX = mMotionDownRawX - (w / 2); int screenY = mMotionDownRawY - h; - + mDragController.startDrag(bmp, screenX, screenY, 0, 0, w, h, this, app, DragController.DRAG_ACTION_COPY); - + mLauncher.closeAllApps(true); } return true; } - + @Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) { @@ -697,14 +697,14 @@ public class AllApps3D extends RSSurfaceView } return false; } - + public void setDragController(DragController dragger) { mDragController = dragger; } - + public void onDropCompleted(View target, boolean success) { } - + /** * Zoom to the specifed level. * @@ -723,15 +723,15 @@ public class AllApps3D extends RSSurfaceView mRollo.setZoom(zoom, animate); } } - + public boolean isVisible() { return mZoom > 0.001f; } - + public boolean isOpaque() { return mZoom > 0.999f; } - + public void setApps(ArrayList list) { if (mRS == null) { // We've been removed from the window. Don't bother with all this. @@ -752,14 +752,14 @@ public class AllApps3D extends RSSurfaceView } } } - + mAllAppsList = list; if (mRollo != null && reload) { mRollo.setApps(list); } mLocks &= ~LOCK_ICONS_PENDING; } - + public void addApps(ArrayList list) { if (mAllAppsList == null) { // Not done loading yet. We'll find out about it later. @@ -769,12 +769,13 @@ public class AllApps3D extends RSSurfaceView // We've been removed from the window. Don't bother with all this. return; } - + final int N = list.size(); if (mRollo != null) { + mRollo.pause(); mRollo.reallocAppsList(mRollo.mState.iconCount + N); } - + for (int i=0; i list) { if (mAllAppsList == null) { // Not done loading yet. We'll find out about it later. return; } - + + if (mRollo != null) { + mRollo.pause(); + } final int N = list.size(); for (int i=0; i list) { // Just remove and add, because they may need to be re-sorted. removeApps(list); addApps(list); } - + private static int findAppByComponent(ArrayList list, ApplicationInfo item) { ComponentName component = item.intent.getComponent(); final int N = list.size(); @@ -836,7 +842,7 @@ public class AllApps3D extends RSSurfaceView } return -1; } - + /* private static int countPages(int iconCount) { int iconsPerPage = getColumnsCount() * Defines.ROWS_PER_PAGE_PORTRAIT; @@ -856,12 +862,12 @@ public class AllApps3D extends RSSurfaceView mZoomDirty = false; } } - + public static class RolloRS { // Allocations ====== private int mWidth; private int mHeight; - + private Resources mRes; private Script mScript; private Script.Invokable mInvokeMove; @@ -869,7 +875,7 @@ public class AllApps3D extends RSSurfaceView private Script.Invokable mInvokeFling; private Script.Invokable mInvokeResetWAR; private Script.Invokable mInvokeSetZoom; - + private ProgramStore mPSIcons; private ProgramFragment mPFTexMip; private ProgramFragment mPFTexMipAlpha; @@ -878,48 +884,56 @@ public class AllApps3D extends RSSurfaceView private ProgramVertex mPVCurve; private SimpleMesh mMesh; private ProgramVertex.MatrixAllocation mPVA; - + private Allocation mUniformAlloc; - + private Allocation mHomeButtonNormal; private Allocation mHomeButtonFocused; private Allocation mHomeButtonPressed; - + private Allocation[] mIcons; private int[] mIconIds; private Allocation mAllocIconIds; - + private Allocation[] mLabels; private int[] mLabelIds; private Allocation mAllocLabelIds; private Allocation mSelectedIcon; - + private int[] mTouchYBorders; private int[] mTouchXBorders; - + private Bitmap mSelectionBitmap; private Canvas mSelectionCanvas; - + Params mParams; State mState; - + AllApps3D mAllApps; boolean mInitialize; class BaseAlloc { Allocation mAlloc; Type mType; - + void save() { mAlloc.data(this); } } - + private boolean checkClickOK() { return (Math.abs(mAllApps.mVelocity) < 0.4f) && (Math.abs(mAllApps.mPosX - Math.round(mAllApps.mPosX)) < 0.4f); } - + + void pause() { + mRS.contextBindRootScript(null); + } + + void resume() { + mRS.contextBindRootScript(mScript); + } + class Params extends BaseAlloc { Params() { mType = Type.createFromClass(mRS, Params.class, 1, "ParamsClass"); @@ -930,13 +944,13 @@ public class AllApps3D extends RSSurfaceView public int bubbleHeight; public int bubbleBitmapWidth; public int bubbleBitmapHeight; - + public int homeButtonWidth; public int homeButtonHeight; public int homeButtonTextureWidth; public int homeButtonTextureHeight; } - + class State extends BaseAlloc { public float newPositionX; public int newTouchDown; @@ -947,18 +961,18 @@ public class AllApps3D extends RSSurfaceView public float zoomTarget; public int homeButtonId; public float targetPos; - + State() { mType = Type.createFromClass(mRS, State.class, 1, "StateClass"); mAlloc = Allocation.createTyped(mRS, mType); save(); } } - + public RolloRS(AllApps3D allApps) { mAllApps = allApps; } - + public void init(Resources res, int width, int height) { mRes = res; mWidth = width; @@ -971,10 +985,10 @@ public class AllApps3D extends RSSurfaceView initTouchState(width, height); initRs(); } - + public void initMesh() { SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(mRS, 2, 0); - + for (int ct=0; ct < 16; ct++) { float pos = (1.f / (16.f - 1)) * ct; tm.addVertex(0.0f, pos); @@ -987,55 +1001,55 @@ public class AllApps3D extends RSSurfaceView mMesh = tm.create(); mMesh.setName("SMCell"); } - + void resize(int w, int h) { mPVA.setupProjectionNormalized(w, h); mWidth = w; mHeight = h; } - + private void initProgramVertex() { mPVA = new ProgramVertex.MatrixAllocation(mRS); resize(mWidth, mHeight); - + ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null); pvb.setTextureMatrixEnable(true); mPV = pvb.create(); mPV.setName("PV"); mPV.bindAllocation(mPVA); - + Element.Builder eb = new Element.Builder(mRS); eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 2), "ImgSize"); eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Position"); eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 2), "BendPos"); eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "ScaleOffset"); Element e = eb.create(); - + mUniformAlloc = Allocation.createSized(mRS, e, 1); - + initMesh(); ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(mRS); String t = "void main() {\n" + // Animation " float ani = UNI_Position.z;\n" + - + " float bendY1 = UNI_BendPos.x;\n" + " float bendY2 = UNI_BendPos.y;\n" + " float bendAngle = 47.0 * (3.14 / 180.0);\n" + " float bendDistance = bendY1 * 0.4;\n" + " float distanceDimLevel = 0.6;\n" + - + " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" + " float aDy = cos(bendAngle);\n" + " float aDz = sin(bendAngle);\n" + - + " float scale = (2.0 / 480.0);\n" + " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" + " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" + " float y = 0.0;\n" + " float z = 0.0;\n" + " float lum = 1.0;\n" + - + " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" + " y += cv * aDy;\n" + " z += -cv * aDz;\n" + @@ -1043,7 +1057,7 @@ public class AllApps3D extends RSSurfaceView " lum += cv / bendDistance * distanceDimLevel;\n" + " y += cv * cos(cv * bendStep);\n" + " z += cv * sin(cv * bendStep);\n" + - + " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" + " y += cv * aDy;\n" + " z += cv * aDz;\n" + @@ -1051,20 +1065,20 @@ public class AllApps3D extends RSSurfaceView " lum -= cv / bendDistance * distanceDimLevel;\n" + " y += cv * cos(cv * bendStep);\n" + " z += cv * sin(cv * bendStep);\n" + - + " y += clamp(ys, bendY1, bendY2);\n" + - + " vec4 pos;\n" + " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" + " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" + " pos.z = z * UNI_ScaleOffset.x;\n" + " pos.w = 1.0;\n" + - + " pos.x *= 1.0 + ani * 4.0;\n" + " pos.y *= 1.0 + ani * 4.0;\n" + " pos.z -= ani * 1.5;\n" + " lum *= 1.0 - ani;\n" + - + " gl_Position = UNI_MVP * pos;\n" + " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" + " varTex0.xy = ATTRIB_position;\n" + @@ -1078,10 +1092,10 @@ public class AllApps3D extends RSSurfaceView mPVCurve.setName("PVCurve"); mPVCurve.bindAllocation(mPVA); mPVCurve.bindConstants(mUniformAlloc, 1); - + mRS.contextBindProgramVertex(mPV); } - + private void initProgramFragment() { Sampler.Builder sb = new Sampler.Builder(mRS); sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR); @@ -1089,30 +1103,30 @@ public class AllApps3D extends RSSurfaceView sb.setWrapS(Sampler.Value.CLAMP); sb.setWrapT(Sampler.Value.CLAMP); Sampler linear = sb.create(); - + sb.setMin(Sampler.Value.NEAREST); sb.setMag(Sampler.Value.NEAREST); Sampler nearest = sb.create(); - + ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS); bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE, ProgramFragment.Builder.Format.RGBA, 0); mPFTexMip = bf.create(); mPFTexMip.setName("PFTexMip"); mPFTexMip.bindSampler(linear, 0); - + mPFTexNearest = bf.create(); mPFTexNearest.setName("PFTexNearest"); mPFTexNearest.bindSampler(nearest, 0); - + bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE, ProgramFragment.Builder.Format.ALPHA, 0); mPFTexMipAlpha = bf.create(); mPFTexMipAlpha.setName("PFTexMipAlpha"); mPFTexMipAlpha.bindSampler(linear, 0); - + } - + private void initProgramStore() { ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null); bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); @@ -1123,23 +1137,23 @@ public class AllApps3D extends RSSurfaceView mPSIcons = bs.create(); mPSIcons.setName("PSIcons"); } - + private void initGl() { mTouchXBorders = new int[mAllApps.mColumnsPerPage + 1]; mTouchYBorders = new int[mAllApps.mRowsPerPage + 1]; } - + private void initData() { mParams = new Params(); mState = new State(); - + final Utilities.BubbleText bubble = new Utilities.BubbleText(mAllApps.getContext()); - + mParams.bubbleWidth = bubble.getBubbleWidth(); mParams.bubbleHeight = bubble.getMaxBubbleHeight(); mParams.bubbleBitmapWidth = bubble.getBitmapWidth(); mParams.bubbleBitmapHeight = bubble.getBitmapHeight(); - + mHomeButtonNormal = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.home_button_normal, Element.RGBA_8888(mRS), false); mHomeButtonNormal.uploadToTexture(0); @@ -1153,19 +1167,19 @@ public class AllApps3D extends RSSurfaceView mParams.homeButtonHeight = 68; mParams.homeButtonTextureWidth = 128; mParams.homeButtonTextureHeight = 128; - + mState.homeButtonId = mHomeButtonNormal.getID(); - + mParams.save(); mState.save(); - + mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX, Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888); mSelectionCanvas = new Canvas(mSelectionBitmap); - + setApps(null); } - + private void initRs() { ScriptC.Builder sb = new ScriptC.Builder(mRS); sb.setScript(mRes, R.raw.allapps); @@ -1186,32 +1200,33 @@ public class AllApps3D extends RSSurfaceView mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS); mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS); mScript.bindAllocation(mUniformAlloc, Defines.ALLOC_VP_CONSTANTS); - + mRS.contextBindRootScript(mScript); } - + void dirtyCheck() { if (mAllApps.mZoomDirty) { setZoom(mAllApps.mNextZoom, mAllApps.mAnimateNextZoom); } } - + @SuppressWarnings({"ConstantConditions"}) private void setApps(ArrayList list) { + mRollo.pause(); final int count = list != null ? list.size() : 0; int allocCount = count; if (allocCount < 1) { allocCount = 1; } - + mIcons = new Allocation[count]; mIconIds = new int[allocCount]; mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount); - + mLabels = new Allocation[count]; mLabelIds = new int[allocCount]; mAllocLabelIds = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount); - + mState.iconCount = count; for (int i=0; i < mState.iconCount; i++) { createAppIconAllocations(i, list.get(i)); @@ -1220,8 +1235,9 @@ public class AllApps3D extends RSSurfaceView uploadAppIcon(i, list.get(i)); } saveAppsList(); + mRollo.resume(); } - + private void setZoom(float zoom, boolean animate) { mRollo.clearSelectedIcon(); mRollo.setHomeSelected(SELECTED_NONE); @@ -1235,7 +1251,7 @@ public class AllApps3D extends RSSurfaceView mRollo.mInvokeSetZoom.execute(); } } - + private void createAppIconAllocations(int index, ApplicationInfo item) { mIcons[index] = Allocation.createFromBitmap(mRS, item.iconBitmap, Element.RGBA_8888(mRS), false); @@ -1244,7 +1260,7 @@ public class AllApps3D extends RSSurfaceView mIconIds[index] = mIcons[index].getID(); mLabelIds[index] = mLabels[index].getID(); } - + private void uploadAppIcon(int index, ApplicationInfo item) { if (mIconIds[index] != mIcons[index].getID()) { throw new IllegalStateException("uploadAppIcon index=" + index @@ -1255,7 +1271,7 @@ public class AllApps3D extends RSSurfaceView mIcons[index].uploadToTexture(true, 0); mLabels[index].uploadToTexture(true, 0); } - + /** * Puts the empty spaces at the end. Updates mState.iconCount. You must * fill in the values and call saveAppsList(). @@ -1264,88 +1280,84 @@ public class AllApps3D extends RSSurfaceView Allocation[] icons = new Allocation[count]; int[] iconIds = new int[count]; mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), count); - + Allocation[] labels = new Allocation[count]; int[] labelIds = new int[count]; mAllocLabelIds = Allocation.createSized(mRS, Element.USER_I32(mRS), count); - + final int oldCount = mRollo.mState.iconCount; - + System.arraycopy(mIcons, 0, icons, 0, oldCount); System.arraycopy(mIconIds, 0, iconIds, 0, oldCount); System.arraycopy(mLabels, 0, labels, 0, oldCount); System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount); - + mIcons = icons; mIconIds = iconIds; mLabels = labels; mLabelIds = labelIds; } - + /** * Handle the allocations for the new app. Make sure you call saveAppsList when done. */ private void addApp(int index, ApplicationInfo item) { final int count = mState.iconCount - index; final int dest = index + 1; - + System.arraycopy(mIcons, index, mIcons, dest, count); System.arraycopy(mIconIds, index, mIconIds, dest, count); System.arraycopy(mLabels, index, mLabels, dest, count); System.arraycopy(mLabelIds, index, mLabelIds, dest, count); - + createAppIconAllocations(index, item); uploadAppIcon(index, item); mRollo.mState.iconCount++; } - + /** * Handle the allocations for the removed app. Make sure you call saveAppsList when done. */ private void removeApp(int index) { final int count = mState.iconCount - index - 1; final int src = index + 1; - + System.arraycopy(mIcons, src, mIcons, index, count); System.arraycopy(mIconIds, src, mIconIds, index, count); System.arraycopy(mLabels, src, mLabels, index, count); System.arraycopy(mLabelIds, src, mLabelIds, index, count); - + mRollo.mState.iconCount--; final int last = mState.iconCount; - + mIcons[last] = null; mIconIds[last] = 0; mLabels[last] = null; mLabelIds[last] = 0; } - + /** * Send the apps list structures to RS. */ private void saveAppsList() { // WTF: how could mScript be not null but mAllocIconIds null b/2460740. if (mScript != null && mAllocIconIds != null) { - mRS.contextBindRootScript(null); - mAllocIconIds.data(mIconIds); mAllocLabelIds.data(mLabelIds); - + mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS); mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS); - + mState.save(); - + // Note: mScript may be null if we haven't initialized it yet. // In that case, this is a no-op. if (mInvokeResetWAR != null) { mInvokeResetWAR.execute(); } - - mRS.contextBindRootScript(mScript); } } - + void initTouchState(int width, int height) { boolean isPortrait = width < height; @@ -1356,7 +1368,7 @@ public class AllApps3D extends RSSurfaceView if (!isPortrait) centerY += cellHeight / 2; int half = (int) Math.floor((mAllApps.mRowsPerPage + 1) / 2); int end = mTouchYBorders.length - (half + 1); - + for (int i = -half; i <= end; i++) { mTouchYBorders[i + half] = centerY + i * cellHeight; } @@ -1369,25 +1381,25 @@ public class AllApps3D extends RSSurfaceView x += columnWidth; } } - + void fling() { mInvokeFling.execute(); } - + void move() { mInvokeMove.execute(); } - + void moveTo(float row) { mState.targetPos = row; mState.save(); mInvokeMoveTo.execute(); } - + int chooseTappedIcon(int x, int y, float pos) { // Adjust for scroll position if not zero. y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]); - + int col = -1; int row = -1; final int columnsCount = mAllApps.mColumnsPerPage; @@ -1404,20 +1416,20 @@ public class AllApps3D extends RSSurfaceView break; } } - + if (row < 0 || col < 0) { return -1; } - + int index = (((int)pos) * columnsCount) + (row * columnsCount) + col; - + if (index >= mState.iconCount) { return -1; } else { return index; } } - + /** * You need to call save() on mState on your own after calling this. * @@ -1428,7 +1440,7 @@ public class AllApps3D extends RSSurfaceView selectIcon(index, pressed); return index; } - + /** * Select the icon at the given index. * @@ -1446,22 +1458,22 @@ public class AllApps3D extends RSSurfaceView if (pressed == SELECTED_FOCUSED) { mAllApps.mLastSelection = SELECTION_ICONS; } - + int prev = mState.selectedIconIndex; mState.selectedIconIndex = index; - + ApplicationInfo info = appsList.get(index); Bitmap selectionBitmap = mSelectionBitmap; - + Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas, selectionBitmap.getWidth(), selectionBitmap.getHeight(), pressed == SELECTED_PRESSED, info.iconBitmap); - + mSelectedIcon = Allocation.createFromBitmap(mRS, selectionBitmap, Element.RGBA_8888(mRS), false); mSelectedIcon.uploadToTexture(0); mState.selectedIconTexture = mSelectedIcon.getID(); - + if (prev != index) { if (info.title != null && info.title.length() > 0) { //setContentDescription(info.title); @@ -1470,14 +1482,14 @@ public class AllApps3D extends RSSurfaceView } } } - + /** * You need to call save() on mState on your own after calling this. */ void clearSelectedIcon() { mState.selectedIconIndex = -1; } - + void setHomeSelected(int mode) { final int prev = mAllApps.mLastSelection; switch (mode) { @@ -1496,7 +1508,7 @@ public class AllApps3D extends RSSurfaceView break; } } - + public void dumpState() { Log.d(TAG, "mRollo.mWidth=" + mWidth); Log.d(TAG, "mRollo.mHeight=" + mHeight); @@ -1533,7 +1545,7 @@ public class AllApps3D extends RSSurfaceView Log.d(TAG, "mRollo.mParams.homeButtonTextureHeight=" + mParams.homeButtonTextureHeight); } } - + public void dumpState() { Log.d(TAG, "mRS=" + mRS); Log.d(TAG, "mRollo=" + mRollo); From 9fe71456e6610a651d43af502bcd7042916fd2f3 Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Thu, 11 Mar 2010 17:59:11 -0800 Subject: [PATCH 3/8] Bug 2509023 - NPE on upgrade to froyo Change-Id: I07cb4f272948062b47da8826ca917fd74ad18404 --- src/com/android/launcher2/LauncherModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java index 6560c5d35f..cc5953875e 100644 --- a/src/com/android/launcher2/LauncherModel.java +++ b/src/com/android/launcher2/LauncherModel.java @@ -1195,14 +1195,14 @@ public class LauncherModel extends BroadcastReceiver { } else { info.customIcon = true; } - info.setIcon(icon); break; default: - info.setIcon(getFallbackIcon()); + icon = getFallbackIcon(); info.usingFallbackIcon = true; info.customIcon = false; break; } + info.setIcon(icon); return info; } From 6e3a75050822040ca9654a9850220e337113aa87 Mon Sep 17 00:00:00 2001 From: android-build SharedAccount Date: Mon, 15 Mar 2010 10:05:55 -0700 Subject: [PATCH 4/8] resolve conflicts Change-Id: I2af5d0c5d3c80ad598a5cd7729f8a1b9b2842502 --- src/com/android/launcher2/AllApps3D.java | 104 ++++++++++++++--------- 1 file changed, 66 insertions(+), 38 deletions(-) diff --git a/src/com/android/launcher2/AllApps3D.java b/src/com/android/launcher2/AllApps3D.java index d977885682..6d0655e756 100644 --- a/src/com/android/launcher2/AllApps3D.java +++ b/src/com/android/launcher2/AllApps3D.java @@ -120,7 +120,6 @@ public class AllApps3D extends RSSurfaceView private boolean mAnimateNextZoom; private float mNextZoom; private float mZoom; - private float mPosX; private float mVelocity; private AAMessage mMessageProc; @@ -128,6 +127,8 @@ public class AllApps3D extends RSSurfaceView private int mRowsPerPage; private boolean mSurrendered; + private int mRestoreFocusIndex = -1; + @SuppressWarnings({"UnusedDeclaration"}) static class Defines { public static final int ALLOC_PARAMS = 0; @@ -306,8 +307,7 @@ public class AllApps3D extends RSSurfaceView if (mRollo.mState.iconCount > 0) { if (mLastSelection == SELECTION_ICONS) { int selection = mLastSelectedIcon; - final int firstIcon = Math.round(mPosX) * - mColumnsPerPage; + final int firstIcon = Math.round(mRollo.mScrollPos) * mColumnsPerPage; if (selection < 0 || // No selection selection < firstIcon || // off the top of the screen selection >= mRollo.mState.iconCount || // past last icon @@ -361,8 +361,7 @@ public class AllApps3D extends RSSurfaceView if (!mArrowNavigation && mRollo.mState.iconCount > 0) { // Select the first icon when we gain keyboard focus mArrowNavigation = true; - mRollo.selectIcon(Math.round(mPosX) * mColumnsPerPage, - SELECTED_FOCUSED); + mRollo.selectIcon(Math.round(mRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED); mRollo.mState.save(); } } @@ -394,16 +393,18 @@ public class AllApps3D extends RSSurfaceView } if (iconCount > 0) { + final boolean isPortrait = getWidth() < getHeight(); + mArrowNavigation = true; int currentSelection = mRollo.mState.selectedIconIndex; - int currentTopRow = Math.round(mPosX); + int currentTopRow = Math.round(mRollo.mScrollPos); // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1 final int currentPageCol = currentSelection % mColumnsPerPage; // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1 - final int currentPageRow = (currentSelection - (currentTopRow* mColumnsPerPage)) + final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage)) / mRowsPerPage; int newSelection = currentSelection; @@ -411,26 +412,30 @@ public class AllApps3D extends RSSurfaceView switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: if (mLastSelection == SELECTION_HOME) { - mRollo.setHomeSelected(SELECTED_NONE); - int lastRowCount = iconCount % mColumnsPerPage; - if (lastRowCount == 0) { - lastRowCount = mColumnsPerPage; - } - newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2); - if (newSelection >= iconCount) { - newSelection = iconCount-1; - } - int target = (newSelection / mColumnsPerPage) - - (mRowsPerPage - 1); - if (target < 0) { - target = 0; - } - if (currentTopRow != target) { - mRollo.moveTo(target); + if (isPortrait) { + mRollo.setHomeSelected(SELECTED_NONE); + int lastRowCount = iconCount % mColumnsPerPage; + if (lastRowCount == 0) { + lastRowCount = mColumnsPerPage; + } + newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2); + if (newSelection >= iconCount) { + newSelection = iconCount-1; + } + int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1); + if (target < 0) { + target = 0; + } + if (currentTopRow != target) { + mRollo.moveTo(target); + } } } else { if (currentPageRow > 0) { newSelection = currentSelection - mColumnsPerPage; + if (currentTopRow > newSelection / mColumnsPerPage) { + mRollo.moveTo(newSelection / mColumnsPerPage); + } } else if (currentTopRow > 0) { newSelection = currentSelection - mColumnsPerPage; mRollo.moveTo(newSelection / mColumnsPerPage); @@ -460,10 +465,9 @@ public class AllApps3D extends RSSurfaceView newSelection = iconCount - 1; } if (currentPageRow >= mRowsPerPage - 1) { - mRollo.moveTo((newSelection / mColumnsPerPage) - - mRowsPerPage + 1); + mRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1); } - } else { + } else if (isPortrait) { newSelection = -1; mRollo.setHomeSelected(SELECTED_FOCUSED); } @@ -476,12 +480,20 @@ public class AllApps3D extends RSSurfaceView if (currentPageCol > 0) { newSelection = currentSelection - 1; } + } else if (!isPortrait) { + newSelection = ((int) (mRollo.mScrollPos) * mColumnsPerPage) + + (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1; + mRollo.setHomeSelected(SELECTED_NONE); } handled = true; break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (mLastSelection != SELECTION_HOME) { - if ((currentPageCol < mColumnsPerPage - 1) && + if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 || + currentSelection == iconCount - 1)) { + newSelection = -1; + mRollo.setHomeSelected(SELECTED_FOCUSED); + } else if ((currentPageCol < mColumnsPerPage - 1) && (currentSelection < iconCount - 1)) { newSelection = currentSelection + 1; } @@ -538,7 +550,7 @@ public class AllApps3D extends RSSurfaceView mRollo.clearSelectedIcon(); } else { mDownIconIndex = mCurrentIconIndex - = mRollo.selectIcon(x, y, mPosX, SELECTED_PRESSED); + = mRollo.selectIcon(x, y, SELECTED_PRESSED); if (mDownIconIndex < 0) { // if nothing was selected, no long press. cancelLongPress(); @@ -567,7 +579,7 @@ public class AllApps3D extends RSSurfaceView if (!mStartedScrolling && slop < mSlop) { // don't update anything so when we do start scrolling // below, we get the right delta. - mCurrentIconIndex = mRollo.chooseTappedIcon(x, y, mPosX); + mCurrentIconIndex = mRollo.chooseTappedIcon(x, y); if (mDownIconIndex != mCurrentIconIndex) { // If a different icon is selected, don't allow it to be picked up. // This handles off-axis dragging. @@ -757,6 +769,13 @@ public class AllApps3D extends RSSurfaceView if (mRollo != null && reload) { mRollo.setApps(list); } + + if (hasFocus() && mRestoreFocusIndex != -1) { + mRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED); + mRollo.mState.save(); + mRestoreFocusIndex = -1; + } + mLocks &= ~LOCK_ICONS_PENDING; } @@ -856,7 +875,7 @@ public class AllApps3D extends RSSurfaceView class AAMessage extends RenderScript.RSMessage { public void run() { - mPosX = ((float)mData[0]) / (1 << 16); + mRollo.mScrollPos = ((float)mData[0]) / (1 << 16); mVelocity = ((float)mData[1]) / (1 << 16); mZoom = ((float)mData[2]) / (1 << 16); mZoomDirty = false; @@ -905,6 +924,8 @@ public class AllApps3D extends RSSurfaceView private Bitmap mSelectionBitmap; private Canvas mSelectionCanvas; + + private float mScrollPos; Params mParams; State mState; @@ -923,7 +944,7 @@ public class AllApps3D extends RSSurfaceView private boolean checkClickOK() { return (Math.abs(mAllApps.mVelocity) < 0.4f) && - (Math.abs(mAllApps.mPosX - Math.round(mAllApps.mPosX)) < 0.4f); + (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f); } void pause() { @@ -1239,8 +1260,10 @@ public class AllApps3D extends RSSurfaceView } private void setZoom(float zoom, boolean animate) { - mRollo.clearSelectedIcon(); - mRollo.setHomeSelected(SELECTED_NONE); + if (animate) { + mRollo.clearSelectedIcon(); + mRollo.setHomeSelected(SELECTED_NONE); + } if (zoom > 0.001f) { mRollo.mState.zoomTarget = zoom; } else { @@ -1396,7 +1419,9 @@ public class AllApps3D extends RSSurfaceView mInvokeMoveTo.execute(); } - int chooseTappedIcon(int x, int y, float pos) { + int chooseTappedIcon(int x, int y) { + float pos = mScrollPos; + // Adjust for scroll position if not zero. y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]); @@ -1421,7 +1446,7 @@ public class AllApps3D extends RSSurfaceView return -1; } - int index = (((int)pos) * columnsCount) + (row * columnsCount) + col; + int index = (((int) pos) * columnsCount) + (row * columnsCount) + col; if (index >= mState.iconCount) { return -1; @@ -1435,8 +1460,8 @@ public class AllApps3D extends RSSurfaceView * * @return the index of the icon that was selected. */ - int selectIcon(int x, int y, float pos, int pressed) { - final int index = chooseTappedIcon(x, y, pos); + int selectIcon(int x, int y, int pressed) { + final int index = chooseTappedIcon(x, y); selectIcon(index, pressed); return index; } @@ -1450,6 +1475,9 @@ public class AllApps3D extends RSSurfaceView void selectIcon(int index, int pressed) { final ArrayList appsList = mAllApps.mAllAppsList; if (appsList == null || index < 0 || index >= appsList.size()) { + if (mAllApps != null) { + mAllApps.mRestoreFocusIndex = index; + } mState.selectedIconIndex = -1; if (mAllApps.mLastSelection == SELECTION_ICONS) { mAllApps.mLastSelection = SELECTION_NONE; @@ -1560,7 +1588,7 @@ public class AllApps3D extends RSSurfaceView Log.d(TAG, "mZoomDirty=" + mZoomDirty); Log.d(TAG, "mAnimateNextZoom=" + mAnimateNextZoom); Log.d(TAG, "mZoom=" + mZoom); - Log.d(TAG, "mPosX=" + mPosX); + Log.d(TAG, "mScrollPos=" + mRollo.mScrollPos); Log.d(TAG, "mVelocity=" + mVelocity); Log.d(TAG, "mMessageProc=" + mMessageProc); if (mRollo != null) { From 280cece0234d34c98853dc65b83bdff039121e44 Mon Sep 17 00:00:00 2001 From: Daniel Sandler Date: Thu, 15 Apr 2010 16:28:40 -0400 Subject: [PATCH 5/8] Launcher2 performance: Don't sort apps in LauncherModel. AllApps2D and AllApps3D do their own sorting before display. Bug: 2562420 Change-Id: I77e3865b856a5123872bee3d8578d0596956cddd --- src/com/android/launcher2/AllAppsList.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/com/android/launcher2/AllAppsList.java b/src/com/android/launcher2/AllAppsList.java index 96d936948c..ee89e5aca3 100644 --- a/src/com/android/launcher2/AllAppsList.java +++ b/src/com/android/launcher2/AllAppsList.java @@ -57,17 +57,10 @@ class AllAppsList { /** * Add the supplied ApplicationInfo objects to the list, and enqueue it into the * list to broadcast when notify() is called. - * - * Postcondition: data and added are sorted in order of LauncherModel.APP_NAME_COMPARATOR. */ public void add(ApplicationInfo info) { - int pos = Collections.binarySearch(data, info, LauncherModel.APP_NAME_COMPARATOR); - if (pos < 0) pos = -1 - pos; - data.add(pos, info); - - pos = Collections.binarySearch(added, info, LauncherModel.APP_NAME_COMPARATOR); - if (pos < 0) pos = -1 - pos; - added.add(pos, info); + data.add(info); + added.add(info); } public void clear() { From 44ce293c66aea10a0efa5874c3779ff8a50aa080 Mon Sep 17 00:00:00 2001 From: Daniel Sandler Date: Thu, 15 Apr 2010 16:41:31 -0400 Subject: [PATCH 6/8] Sort apps in AllApps3D.setApps(). The sorting is no longer being done in LauncherModel. AA3D.addApps correctly performs an insertion sort, but setApps did not. Missing from change I77e3865b. Bug: 2562420 Change-Id: I6854c2c4a221b2c1ad123410292da1fbfece7871 --- src/com/android/launcher2/AllApps3D.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/com/android/launcher2/AllApps3D.java b/src/com/android/launcher2/AllApps3D.java index 64c8c4c53c..2b27c7cc19 100644 --- a/src/com/android/launcher2/AllApps3D.java +++ b/src/com/android/launcher2/AllApps3D.java @@ -831,6 +831,10 @@ public class AllApps3D extends RSSurfaceView return; } + if (list != null) { + Collections.sort(list, LauncherModel.APP_NAME_COMPARATOR); + } + boolean reload = false; if (mAllAppsList == null) { reload = true; From 4a4c729a5bd110442abe69ba3c13235b28fc129f Mon Sep 17 00:00:00 2001 From: Daniel Sandler Date: Fri, 23 Apr 2010 16:43:48 -0400 Subject: [PATCH 7/8] Fix proguard flags. Fixes a crash in the new hotseat launcher icons. Change-Id: Idcb7441647f16c783a47dfe09400f04fa8980dd3 --- proguard.flags | 1 + 1 file changed, 1 insertion(+) diff --git a/proguard.flags b/proguard.flags index 255f970501..1187fd8a29 100644 --- a/proguard.flags +++ b/proguard.flags @@ -1,6 +1,7 @@ -keep class com.android.launcher2.Launcher { public void previousScreen(android.view.View); public void nextScreen(android.view.View); + public void launchHotSeat(android.view.View); } -keep class com.android.launcher2.AllApps3D$Defines { From 6f2dbc2ffb3ae803eae6c83f6036074ede29841a Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Thu, 29 Apr 2010 11:42:45 -0700 Subject: [PATCH 8/8] Filter input events and smooth out touch scrolling. Bug 2639807 Change-Id: I71a18497862a30db5ff0f52f566fb86eae213ea3 --- src/com/android/launcher2/CellLayout.java | 2 +- src/com/android/launcher2/Workspace.java | 46 +++++++++++++++++------ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java index 9d39c2ca78..bc52af128f 100644 --- a/src/com/android/launcher2/CellLayout.java +++ b/src/com/android/launcher2/CellLayout.java @@ -584,7 +584,7 @@ public class CellLayout extends ViewGroup { final View view = getChildAt(i); view.setDrawingCacheEnabled(enabled); // Update the drawing caches - view.buildDrawingCache(true); + view.buildDrawingCache(false); } } diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index d84d4cdd5c..dca40cec41 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -118,6 +118,10 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag private Drawable mPreviousIndicator; private Drawable mNextIndicator; + + // Touch scrolling history for smoothing + private float[] mLastX = new float[6]; + private int mLastCount = 0; private WorkspaceOvershootInterpolator mScrollInterpolator; @@ -662,7 +666,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag // Scroll if the user moved far enough along the X axis mTouchState = TOUCH_STATE_SCROLLING; mLastMotionX = x; - enableChildrenCache(mCurrentScreen - 1, mCurrentScreen + 1); + enableChildrenCache(0, getChildCount()); } // Either way, cancel any pending longpress if (mAllowLongPress) { @@ -751,6 +755,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag if (mVelocityTracker != null) { mVelocityTracker.clear(); } + resetFilter(); } } @@ -784,18 +789,16 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag void enableChildrenCache(int fromScreen, int toScreen) { if (fromScreen > toScreen) { - final int temp = fromScreen; - fromScreen = toScreen - 1; + final int temp = fromScreen; + fromScreen = toScreen; toScreen = temp; - } else { - toScreen++; } final int count = getChildCount(); - + fromScreen = Math.max(fromScreen, 0); toScreen = Math.min(toScreen, count - 1); - + for (int i = fromScreen; i <= toScreen; i++) { final CellLayout layout = (CellLayout) getChildAt(i); layout.setChildrenDrawnWithCacheEnabled(true); @@ -810,6 +813,25 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag layout.setChildrenDrawnWithCacheEnabled(false); } } + + private float filterX(float x) { + final float[] lastX = mLastX; + final int len = lastX.length; + final int lastCount = Math.min(len, mLastCount + 1); + + float sum = x; + for (int i = 1; i < lastCount; i++) { + sum += lastX[i] = lastX[i - 1]; + } + lastX[0] = x; + + mLastCount = lastCount; + return sum / lastCount; + } + + private void resetFilter() { + mLastCount = 0; + } @Override public boolean onTouchEvent(MotionEvent ev) { @@ -851,20 +873,20 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag if (mTouchState == TOUCH_STATE_SCROLLING) { // Scroll to follow the motion event final int pointerIndex = ev.findPointerIndex(mActivePointerId); - final float x = ev.getX(pointerIndex); - final int deltaX = (int) (mLastMotionX - x); + final float x = filterX(ev.getX(pointerIndex)); + final float deltaX = mLastMotionX - x; mLastMotionX = x; if (deltaX < 0) { if (mScrollX > 0) { - scrollBy(Math.max(-mScrollX, deltaX), 0); + scrollBy(Math.round(Math.max(-mScrollX, deltaX)), 0); updateWallpaperOffset(); } } else if (deltaX > 0) { final int availableToScroll = getChildAt(getChildCount() - 1).getRight() - mScrollX - getWidth(); if (availableToScroll > 0) { - scrollBy(Math.min(availableToScroll, deltaX), 0); + scrollBy(Math.round(Math.min(availableToScroll, deltaX)), 0); updateWallpaperOffset(); } } else { @@ -902,6 +924,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag mVelocityTracker.recycle(); mVelocityTracker = null; } + resetFilter(); } mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; @@ -909,6 +932,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag case MotionEvent.ACTION_CANCEL: mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; + resetFilter(); break; case MotionEvent.ACTION_POINTER_UP: onSecondaryPointerUp(ev);