Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.launcher2; |
| 18 | |
| 19 | import java.io.Writer; |
| 20 | import java.util.ArrayList; |
| 21 | import java.util.concurrent.Semaphore; |
| 22 | import java.lang.Float; |
| 23 | |
| 24 | import android.renderscript.RSSurfaceView; |
| 25 | import android.renderscript.RenderScript; |
| 26 | |
| 27 | import android.renderscript.RenderScript; |
| 28 | import android.renderscript.ProgramVertex; |
| 29 | import android.renderscript.Element; |
| 30 | import android.renderscript.Allocation; |
| 31 | import android.renderscript.Script; |
| 32 | import android.renderscript.ScriptC; |
| 33 | import android.renderscript.ProgramFragment; |
| 34 | import android.renderscript.ProgramStore; |
| 35 | import android.renderscript.Sampler; |
| 36 | |
| 37 | import android.content.Context; |
| 38 | import android.content.res.Resources; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 39 | import android.database.DataSetObserver; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 40 | import android.graphics.Bitmap; |
| 41 | import android.graphics.BitmapFactory; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 42 | import android.graphics.BlurMaskFilter; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 43 | import android.graphics.Canvas; |
| 44 | import android.graphics.Paint; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 45 | import android.graphics.drawable.BitmapDrawable; |
| 46 | import android.graphics.drawable.Drawable; |
| 47 | import android.os.Handler; |
| 48 | import android.os.Message; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 49 | import android.os.SystemClock; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 50 | import android.util.AttributeSet; |
| 51 | import android.util.Log; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 52 | import android.view.KeyEvent; |
| 53 | import android.view.MotionEvent; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 54 | import android.view.Surface; |
| 55 | import android.view.SurfaceHolder; |
| 56 | import android.view.SurfaceView; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 57 | import android.view.View; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 58 | import android.view.VelocityTracker; |
| 59 | import android.view.ViewConfiguration; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 60 | import android.graphics.PixelFormat; |
| 61 | |
| 62 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 63 | public class AllAppsView extends RSSurfaceView |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 64 | implements View.OnClickListener, View.OnLongClickListener, DragSource { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 65 | private static final String TAG = "Launcher.AllAppsView"; |
| 66 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 67 | private Launcher mLauncher; |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 68 | private DragController mDragController; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 69 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 70 | private RenderScript mRS; |
| 71 | private RolloRS mRollo; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 72 | private ArrayList<ApplicationInfo> mAllAppsList; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 73 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 74 | private ViewConfiguration mConfig; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 75 | private int mPageCount; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 76 | private boolean mStartedScrolling; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 77 | private VelocityTracker mVelocity; |
| 78 | private int mLastScrollX; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 79 | private int mLastMotionX; |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 80 | private int mMotionDownRawX; |
| 81 | private int mMotionDownRawY; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 82 | private TouchHandler mTouchHandler; |
| 83 | private int mScrollHandleTop; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 84 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 85 | static class Defines { |
| 86 | private static float farSize(float sizeAt0) { |
| 87 | return sizeAt0 * (Defines.RADIUS - Defines.CAMERA_Z) / -Defines.CAMERA_Z; |
| 88 | } |
| 89 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 90 | public static final int ALLOC_PARAMS = 0; |
| 91 | public static final int ALLOC_STATE = 1; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 92 | public static final int ALLOC_ICON_IDS = 2; |
| 93 | public static final int ALLOC_LABEL_IDS = 3; |
| 94 | public static final int ALLOC_X_BORDERS = 4; |
| 95 | public static final int ALLOC_Y_BORDERS = 5; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 96 | |
| 97 | public static final int COLUMNS_PER_PAGE = 4; |
| 98 | public static final int ROWS_PER_PAGE = 4; |
| 99 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 100 | public static final float RADIUS = 4.0f; |
| 101 | |
| 102 | public static final int SCREEN_WIDTH_PX = 480; |
| 103 | public static final int SCREEN_HEIGHT_PX = 854; |
| 104 | |
| 105 | public static final int ICON_WIDTH_PX = 64; |
| 106 | public static final int ICON_TEXTURE_WIDTH_PX = 128; |
| 107 | |
| 108 | public static final int ICON_HEIGHT_PX = 64; |
| 109 | public static final int ICON_TEXTURE_HEIGHT_PX = 128; |
| 110 | public static final float ICON_TOP_OFFSET = 0.2f; |
| 111 | |
| 112 | public static final float CAMERA_Z = -2; |
| 113 | public static final float FAR_ICON_SIZE |
| 114 | = farSize(2 * ICON_WIDTH_PX / (float)SCREEN_WIDTH_PX); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 115 | } |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 116 | |
| 117 | public AllAppsView(Context context, AttributeSet attrs) { |
| 118 | super(context, attrs); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 119 | setFocusable(true); |
| 120 | getHolder().setFormat(PixelFormat.TRANSLUCENT); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 121 | mConfig = ViewConfiguration.get(context); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 122 | setOnClickListener(this); |
| 123 | setOnLongClickListener(this); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 126 | public AllAppsView(Context context, AttributeSet attrs, int defStyle) { |
| 127 | this(context, attrs); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 130 | public void setLauncher(Launcher launcher) { |
| 131 | mLauncher = launcher; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 134 | @Override |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 135 | public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { |
| 136 | super.surfaceChanged(holder, format, w, h); |
| 137 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 138 | long startTime = SystemClock.uptimeMillis(); |
| 139 | |
Jason Sams | b58cbdc | 2009-08-21 16:56:58 -0700 | [diff] [blame] | 140 | mRS = createRenderScript(true); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 141 | mRollo = new RolloRS(); |
| 142 | mRollo.init(getResources(), w, h); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 143 | if (mAllAppsList != null) { |
| 144 | mRollo.setApps(mAllAppsList); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 145 | Log.d(TAG, "surfaceChanged... calling mRollo.setApps"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 146 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 147 | |
| 148 | Resources res = getContext().getResources(); |
| 149 | int barHeight = (int)res.getDimension(R.dimen.button_bar_height); |
| 150 | mScrollHandleTop = h - barHeight; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 151 | |
| 152 | long endTime = SystemClock.uptimeMillis(); |
| 153 | Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms"); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public boolean onKeyDown(int keyCode, KeyEvent event) |
| 158 | { |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 159 | // this method doesn't work when 'extends View' include 'extends ScrollView'. |
| 160 | return super.onKeyDown(keyCode, event); |
| 161 | } |
| 162 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 163 | @Override |
| 164 | public boolean onTouchEvent(MotionEvent ev) |
| 165 | { |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 166 | super.onTouchEvent(ev); |
| 167 | |
Joe Onorato | e3406a2 | 2009-09-03 14:36:25 -0700 | [diff] [blame^] | 168 | if (mRollo.mState.visible == 0) { |
| 169 | return false; |
| 170 | } |
| 171 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 172 | mTouchHandler = mFlingHandler; |
| 173 | /* |
| 174 | int action = ev.getAction(); |
| 175 | if (action == MotionEvent.ACTION_DOWN) { |
| 176 | if (ev.getY() > mScrollHandleTop) { |
| 177 | mTouchHandler = mScrollHandler; |
| 178 | } else { |
| 179 | mTouchHandler = mFlingHandler; |
| 180 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 181 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 182 | */ |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 183 | mTouchHandler.onTouchEvent(ev); |
| 184 | |
| 185 | return true; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 188 | private abstract class TouchHandler { |
| 189 | abstract boolean onTouchEvent(MotionEvent ev); |
| 190 | }; |
| 191 | |
| 192 | private TouchHandler mFlingHandler = new TouchHandler() { |
| 193 | @Override |
| 194 | public boolean onTouchEvent(MotionEvent ev) |
| 195 | { |
| 196 | int x = (int)ev.getX(); |
| 197 | int deltaX; |
| 198 | switch (ev.getAction()) { |
| 199 | case MotionEvent.ACTION_DOWN: |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 200 | mMotionDownRawX = (int)ev.getRawX(); |
| 201 | mMotionDownRawY = (int)ev.getRawY(); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 202 | mLastMotionX = x; |
| 203 | mRollo.mState.read(); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 204 | mRollo.mState.startScrollX = mRollo.mState.scrollX = mLastScrollX |
| 205 | = mRollo.mState.currentScrollX; |
| 206 | if (mRollo.mState.flingVelocityX != 0) { |
| 207 | mRollo.clearSelectedIcon(); |
| 208 | } else { |
| 209 | mRollo.selectIcon(x, (int)ev.getY(), mRollo.mState.startScrollX, |
| 210 | (-mRollo.mState.startScrollX / Defines.SCREEN_WIDTH_PX)); |
| 211 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 212 | mRollo.mState.flingVelocityX = 0; |
| 213 | mRollo.mState.adjustedDeceleration = 0; |
| 214 | mRollo.mState.save(); |
| 215 | mVelocity = VelocityTracker.obtain(); |
| 216 | mVelocity.addMovement(ev); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 217 | mStartedScrolling = false; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 218 | break; |
| 219 | case MotionEvent.ACTION_MOVE: |
| 220 | case MotionEvent.ACTION_OUTSIDE: |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 221 | int slop = Math.abs(x - mLastMotionX); |
| 222 | if (!mStartedScrolling && slop < mConfig.getScaledTouchSlop()) { |
| 223 | // don't update mLastMotionX so slop is right and when we do start scrolling |
| 224 | // below, we get the right delta. |
| 225 | } else { |
| 226 | mStartedScrolling = true; |
| 227 | mRollo.clearSelectedIcon(); |
| 228 | deltaX = x - mLastMotionX; |
| 229 | mVelocity.addMovement(ev); |
| 230 | mRollo.mState.currentScrollX = mLastScrollX; |
| 231 | mLastScrollX += deltaX; |
| 232 | mRollo.mState.scrollX = mLastScrollX; |
| 233 | mRollo.mState.save(); |
| 234 | mLastMotionX = x; |
| 235 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 236 | break; |
| 237 | case MotionEvent.ACTION_UP: |
| 238 | case MotionEvent.ACTION_CANCEL: |
| 239 | mVelocity.computeCurrentVelocity(1000 /* px/sec */, |
| 240 | mConfig.getScaledMaximumFlingVelocity()); |
| 241 | mRollo.mState.flingTimeMs = (int)SystemClock.uptimeMillis(); // TODO: use long |
| 242 | mRollo.mState.flingVelocityX = (int)mVelocity.getXVelocity(); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 243 | mRollo.clearSelectedIcon(); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 244 | mRollo.mState.save(); |
| 245 | mLastMotionX = -10000; |
| 246 | mVelocity.recycle(); |
| 247 | mVelocity = null; |
| 248 | break; |
| 249 | } |
| 250 | return true; |
| 251 | } |
| 252 | }; |
| 253 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 254 | public void onClick(View v) { |
| 255 | int index = mRollo.mState.selectedIconIndex; |
| 256 | if (mRollo.mState.flingVelocityX == 0 && index >= 0 && index < mAllAppsList.size()) { |
| 257 | ApplicationInfo app = mAllAppsList.get(index); |
| 258 | mLauncher.startActivitySafely(app.intent); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | public boolean onLongClick(View v) { |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 263 | int index = mRollo.mState.selectedIconIndex; |
| 264 | Log.d(TAG, "long click! velocity=" + mRollo.mState.flingVelocityX + " index=" + index); |
| 265 | if (mRollo.mState.flingVelocityX == 0 && index >= 0 && index < mAllAppsList.size()) { |
| 266 | ApplicationInfo app = mAllAppsList.get(index); |
| 267 | |
| 268 | // We don't really have an accurate location to use. This will do. |
| 269 | int screenX = mMotionDownRawX - (Defines.ICON_WIDTH_PX / 2); |
| 270 | int screenY = mMotionDownRawY - Defines.ICON_HEIGHT_PX; |
| 271 | |
| 272 | int left = (Defines.ICON_TEXTURE_WIDTH_PX - Defines.ICON_WIDTH_PX) / 2; |
| 273 | int top = (Defines.ICON_TEXTURE_HEIGHT_PX - Defines.ICON_HEIGHT_PX) / 2; |
| 274 | mDragController.startDrag(app.iconBitmap, screenX, screenY, |
| 275 | left, top, Defines.ICON_WIDTH_PX, Defines.ICON_HEIGHT_PX, |
| 276 | this, app, DragController.DRAG_ACTION_COPY); |
Joe Onorato | e3406a2 | 2009-09-03 14:36:25 -0700 | [diff] [blame^] | 277 | |
| 278 | mLauncher.closeAllAppsDialog(true); |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 279 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 280 | return true; |
| 281 | } |
| 282 | |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 283 | public void setDragController(DragController dragger) { |
| 284 | mDragController = dragger; |
| 285 | } |
| 286 | |
| 287 | public void onDropCompleted(View target, boolean success) { |
| 288 | } |
| 289 | |
Joe Onorato | 006b25f | 2009-09-03 11:38:43 -0700 | [diff] [blame] | 290 | public void show() { |
| 291 | mRollo.mState.read(); |
| 292 | mRollo.mState.visible = 1; |
| 293 | mRollo.mState.save(); |
| 294 | } |
| 295 | |
| 296 | public void hide(boolean animate) { |
| 297 | mRollo.mState.read(); |
| 298 | mRollo.mState.visible = 0; |
| 299 | mRollo.mState.save(); |
| 300 | } |
| 301 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 302 | /* |
| 303 | private TouchHandler mScrollHandler = new TouchHandler() { |
| 304 | @Override |
| 305 | public boolean onTouchEvent(MotionEvent ev) |
| 306 | { |
| 307 | int x = (int)ev.getX(); |
| 308 | int w = getWidth(); |
| 309 | |
| 310 | float percent = x / (float)w; |
| 311 | |
| 312 | mRollo.mState.read(); |
| 313 | |
| 314 | mRollo.mState.scrollX = mLastScrollX = -(int)(mPageCount * w * percent); |
| 315 | mRollo.mState.flingVelocityX = 0; |
| 316 | mRollo.mState.adjustedDeceleration = 0; |
| 317 | mRollo.mState.save(); |
| 318 | |
| 319 | return true; |
| 320 | } |
| 321 | }; |
| 322 | */ |
| 323 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 324 | @Override |
| 325 | public boolean onTrackballEvent(MotionEvent ev) |
| 326 | { |
| 327 | float x = ev.getX(); |
| 328 | float y = ev.getY(); |
| 329 | //Float tx = new Float(x); |
| 330 | //Float ty = new Float(y); |
| 331 | //Log.e("rs", "tbe " + tx.toString() + ", " + ty.toString()); |
| 332 | |
| 333 | |
| 334 | return true; |
| 335 | } |
| 336 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 337 | public void setApps(ArrayList<ApplicationInfo> list) { |
| 338 | mAllAppsList = list; |
| 339 | if (mRollo != null) { |
| 340 | mRollo.setApps(list); |
| 341 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 342 | mPageCount = countPages(list.size()); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 343 | Log.d(TAG, "setApps mRollo=" + mRollo + " list=" + list); |
| 344 | } |
| 345 | |
| 346 | private void invokeIcon(int index) { |
| 347 | Log.d(TAG, "launch it!!!! index=" + index); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | private static int countPages(int iconCount) { |
| 351 | int iconsPerPage = Defines.COLUMNS_PER_PAGE * Defines.ROWS_PER_PAGE; |
| 352 | int pages = iconCount / iconsPerPage; |
| 353 | if (pages*iconsPerPage != iconCount) { |
| 354 | pages++; |
| 355 | } |
| 356 | return pages; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 357 | } |
| 358 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 359 | public class RolloRS { |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 360 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 361 | // Allocations ====== |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 362 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 363 | private int mWidth; |
| 364 | private int mHeight; |
| 365 | |
| 366 | private Resources mRes; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 367 | private Script mScript; |
| 368 | private Sampler mSampler; |
| 369 | private Sampler mSamplerText; |
| 370 | private ProgramStore mPSBackground; |
| 371 | private ProgramStore mPSText; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 372 | private ProgramFragment mPFDebug; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 373 | private ProgramFragment mPFImages; |
| 374 | private ProgramFragment mPFText; |
| 375 | private ProgramVertex mPV; |
| 376 | private ProgramVertex.MatrixAllocation mPVAlloc; |
| 377 | private ProgramVertex mPVOrtho; |
| 378 | private ProgramVertex.MatrixAllocation mPVOrthoAlloc; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 379 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 380 | private Allocation mScrollHandle; |
| 381 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 382 | private Allocation[] mIcons; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 383 | private int[] mIconIds; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 384 | private Allocation mAllocIconID; |
| 385 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 386 | private Allocation[] mLabels; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 387 | private int[] mLabelIds; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 388 | private Allocation mAllocLabelID; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 389 | private Allocation mSelectedIcon; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 390 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 391 | private int[] mTouchYBorders; |
| 392 | private Allocation mAllocTouchYBorders; |
| 393 | private int[] mTouchXBorders; |
| 394 | private Allocation mAllocTouchXBorders; |
| 395 | |
| 396 | private Bitmap mSelectionBitmap; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 397 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 398 | Params mParams; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 399 | State mState; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 400 | |
| 401 | class Params extends IntAllocation { |
| 402 | Params(RenderScript rs) { |
| 403 | super(rs); |
| 404 | } |
| 405 | @AllocationIndex(0) public int bubbleWidth; |
| 406 | @AllocationIndex(1) public int bubbleHeight; |
| 407 | @AllocationIndex(2) public int bubbleBitmapWidth; |
| 408 | @AllocationIndex(3) public int bubbleBitmapHeight; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 409 | @AllocationIndex(4) public int scrollHandleId; |
| 410 | @AllocationIndex(5) public int scrollHandleTextureWidth; |
| 411 | @AllocationIndex(6) public int scrollHandleTextureHeight; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 414 | class State extends IntAllocation { |
| 415 | State(RenderScript rs) { |
| 416 | super(rs); |
| 417 | } |
| 418 | @AllocationIndex(0) public int iconCount; |
| 419 | @AllocationIndex(1) public int scrollX; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 420 | @AllocationIndex(2) public int flingTimeMs; |
| 421 | @AllocationIndex(3) public int flingVelocityX; |
| 422 | @AllocationIndex(4) public int adjustedDeceleration; |
| 423 | @AllocationIndex(5) public int currentScrollX; |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 424 | @AllocationIndex(6) public int flingDuration; |
| 425 | @AllocationIndex(7) public int flingEndPos; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 426 | @AllocationIndex(8) public int startScrollX; |
| 427 | @AllocationIndex(9) public int selectedIconIndex = -1; |
| 428 | @AllocationIndex(10) public int selectedIconTexture; |
Joe Onorato | 006b25f | 2009-09-03 11:38:43 -0700 | [diff] [blame] | 429 | @AllocationIndex(11) public int visible; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | public RolloRS() { |
| 433 | } |
| 434 | |
| 435 | public void init(Resources res, int width, int height) { |
| 436 | mRes = res; |
| 437 | mWidth = width; |
| 438 | mHeight = height; |
| 439 | initGl(); |
| 440 | initData(); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 441 | initTouchState(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 442 | initRs(); |
| 443 | } |
| 444 | |
| 445 | private void initGl() { |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 446 | Sampler.Builder sb = new Sampler.Builder(mRS); |
| 447 | sb.setMin(Sampler.Value.LINEAR);//_MIP_LINEAR); |
| 448 | sb.setMag(Sampler.Value.LINEAR); |
| 449 | sb.setWrapS(Sampler.Value.CLAMP); |
| 450 | sb.setWrapT(Sampler.Value.CLAMP); |
| 451 | mSampler = sb.create(); |
| 452 | |
| 453 | sb.setMin(Sampler.Value.NEAREST); |
| 454 | sb.setMag(Sampler.Value.NEAREST); |
| 455 | mSamplerText = sb.create(); |
| 456 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 457 | ProgramFragment.Builder dbg = new ProgramFragment.Builder(mRS, null, null); |
| 458 | mPFDebug = dbg.create(); |
| 459 | mPFDebug.setName("PFDebug"); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 460 | |
| 461 | ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null); |
| 462 | bf.setTexEnable(true, 0); |
| 463 | bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0); |
| 464 | mPFImages = bf.create(); |
| 465 | mPFImages.setName("PF"); |
| 466 | mPFImages.bindSampler(mSampler, 0); |
| 467 | |
| 468 | bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 469 | //mPFText = bf.create(); |
| 470 | mPFText = (new ProgramFragment.Builder(mRS, null, null)).create(); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 471 | mPFText.setName("PFText"); |
| 472 | mPFText.bindSampler(mSamplerText, 0); |
| 473 | |
| 474 | ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null); |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 475 | bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 476 | bs.setDitherEnable(false); |
| 477 | bs.setDepthMask(true); |
| 478 | bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, |
| 479 | ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA); |
| 480 | mPSBackground = bs.create(); |
| 481 | mPSBackground.setName("PFS"); |
| 482 | |
| 483 | bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); |
| 484 | bs.setDepthMask(false); |
| 485 | bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, |
| 486 | ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA); |
| 487 | mPSText = bs.create(); |
| 488 | mPSText.setName("PFSText"); |
| 489 | |
| 490 | mPVAlloc = new ProgramVertex.MatrixAllocation(mRS); |
| 491 | mPVAlloc.setupProjectionNormalized(mWidth, mHeight); |
| 492 | |
| 493 | ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null); |
| 494 | mPV = pvb.create(); |
| 495 | mPV.setName("PV"); |
| 496 | mPV.bindAllocation(mPVAlloc); |
| 497 | |
| 498 | mPVOrthoAlloc = new ProgramVertex.MatrixAllocation(mRS); |
| 499 | mPVOrthoAlloc.setupOrthoWindow(mWidth, mHeight); |
| 500 | |
| 501 | pvb.setTextureMatrixEnable(true); |
| 502 | mPVOrtho = pvb.create(); |
| 503 | mPVOrtho.setName("PVOrtho"); |
| 504 | mPVOrtho.bindAllocation(mPVOrthoAlloc); |
| 505 | |
| 506 | mRS.contextBindProgramVertex(mPV); |
| 507 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 508 | mTouchXBorders = new int[Defines.COLUMNS_PER_PAGE+1]; |
| 509 | mAllocTouchXBorders = Allocation.createSized(mRS, Element.USER_I32, |
| 510 | mTouchXBorders.length); |
| 511 | mAllocTouchXBorders.data(mTouchXBorders); |
| 512 | |
| 513 | mTouchYBorders = new int[Defines.ROWS_PER_PAGE+1]; |
| 514 | mAllocTouchYBorders = Allocation.createSized(mRS, Element.USER_I32, |
| 515 | mTouchYBorders.length); |
| 516 | mAllocTouchYBorders.data(mTouchYBorders); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 517 | |
| 518 | Log.e("rs", "Done loading named"); |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 521 | private void initData() { |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 522 | mParams = new Params(mRS); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 523 | mState = new State(mRS); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 524 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 525 | final Utilities.BubbleText bubble = new Utilities.BubbleText(getContext()); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 526 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 527 | mParams.bubbleWidth = bubble.getBubbleWidth(); |
| 528 | mParams.bubbleHeight = bubble.getMaxBubbleHeight(); |
| 529 | mParams.bubbleBitmapWidth = bubble.getBitmapWidth(); |
| 530 | mParams.bubbleBitmapHeight = bubble.getBitmapHeight(); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 531 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 532 | mScrollHandle = Allocation.createFromBitmapResource(mRS, mRes, |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 533 | R.drawable.all_apps_button_pow2, Element.RGBA_8888, false); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 534 | mScrollHandle.uploadToTexture(0); |
| 535 | mParams.scrollHandleId = mScrollHandle.getID(); |
| 536 | Log.d(TAG, "mParams.scrollHandleId=" + mParams.scrollHandleId); |
| 537 | mParams.scrollHandleTextureWidth = 128; |
| 538 | mParams.scrollHandleTextureHeight = 128; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 539 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 540 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 541 | mParams.save(); |
| 542 | mState.save(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 543 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 544 | mSelectionBitmap = Bitmap.createBitmap(Defines.ICON_WIDTH_PX, Defines.ICON_HEIGHT_PX, |
| 545 | Bitmap.Config.ARGB_8888); |
| 546 | Bitmap selectionBitmap = mSelectionBitmap; |
| 547 | Paint paint = new Paint(); |
| 548 | float radius = 12 * getContext().getResources().getDisplayMetrics().density; |
| 549 | //paint.setMaskFilter(new BlurMaskFilter(radius, BlurMaskFilter.Blur.OUTER)); |
| 550 | Canvas canvas = new Canvas(selectionBitmap); |
| 551 | canvas.drawColor(0xffff0000); |
| 552 | |
| 553 | mSelectedIcon = Allocation.createFromBitmap(mRS, selectionBitmap, |
| 554 | Element.RGBA_8888, false); |
| 555 | mSelectedIcon.uploadToTexture(0); |
| 556 | |
| 557 | mState.selectedIconTexture = mSelectedIcon.getID(); |
| 558 | |
| 559 | Log.d(TAG, "initData calling mRollo.setApps"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 560 | setApps(null); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 563 | private void initRs() { |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 564 | ScriptC.Builder sb = new ScriptC.Builder(mRS); |
| 565 | sb.setScript(mRes, R.raw.rollo); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 566 | sb.setRoot(true); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 567 | sb.addDefines(Defines.class); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 568 | mScript = sb.create(); |
| 569 | mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 570 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 571 | mScript.bindAllocation(mParams.getAllocation(), Defines.ALLOC_PARAMS); |
| 572 | mScript.bindAllocation(mState.getAllocation(), Defines.ALLOC_STATE); |
| 573 | mScript.bindAllocation(mAllocIconID, Defines.ALLOC_ICON_IDS); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 574 | mScript.bindAllocation(mAllocLabelID, Defines.ALLOC_LABEL_IDS); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 575 | mScript.bindAllocation(mAllocTouchXBorders, Defines.ALLOC_X_BORDERS); |
| 576 | mScript.bindAllocation(mAllocTouchYBorders, Defines.ALLOC_Y_BORDERS); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 577 | |
| 578 | mRS.contextBindRootScript(mScript); |
| 579 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 580 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 581 | private void setApps(ArrayList<ApplicationInfo> list) { |
| 582 | final int count = list != null ? list.size() : 0; |
| 583 | mIcons = new Allocation[count]; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 584 | mIconIds = new int[count]; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 585 | mAllocIconID = Allocation.createSized(mRS, Element.USER_I32, count); |
| 586 | |
| 587 | mLabels = new Allocation[count]; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 588 | mLabelIds = new int[count]; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 589 | mAllocLabelID = Allocation.createSized(mRS, Element.USER_I32, count); |
| 590 | |
| 591 | Element ie8888 = Element.RGBA_8888; |
| 592 | |
| 593 | Utilities.BubbleText bubble = new Utilities.BubbleText(getContext()); |
| 594 | |
| 595 | for (int i=0; i<count; i++) { |
| 596 | final ApplicationInfo item = list.get(i); |
| 597 | |
| 598 | mIcons[i] = Allocation.createFromBitmap(mRS, item.iconBitmap, |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 599 | Element.RGBA_8888, false); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 600 | mLabels[i] = Allocation.createFromBitmap(mRS, item.titleBitmap, |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 601 | Element.RGBA_8888, false); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 602 | |
| 603 | mIcons[i].uploadToTexture(0); |
| 604 | mLabels[i].uploadToTexture(0); |
| 605 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 606 | mIconIds[i] = mIcons[i].getID(); |
| 607 | mLabelIds[i] = mLabels[i].getID(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 608 | } |
| 609 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 610 | mAllocIconID.data(mIconIds); |
| 611 | mAllocLabelID.data(mLabelIds); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 612 | |
| 613 | mState.iconCount = count; |
| 614 | |
| 615 | Log.d("AllAppsView", "mScript=" + mScript + " mAllocIconID=" + mAllocIconID); |
| 616 | |
| 617 | if (mScript != null) { // wtf |
| 618 | mScript.bindAllocation(mAllocIconID, Defines.ALLOC_ICON_IDS); |
| 619 | mScript.bindAllocation(mAllocLabelID, Defines.ALLOC_LABEL_IDS); |
| 620 | } |
| 621 | |
| 622 | mState.save(); |
| 623 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 624 | |
| 625 | void initTouchState() { |
| 626 | int width = getWidth(); |
| 627 | int height = getHeight(); |
| 628 | |
| 629 | int iconsSize; |
| 630 | if (width < height) { |
| 631 | iconsSize = width; |
| 632 | } else { |
| 633 | iconsSize = height; |
| 634 | } |
| 635 | int cellHeight = iconsSize / Defines.ROWS_PER_PAGE; |
| 636 | int cellWidth = iconsSize / Defines.COLUMNS_PER_PAGE; |
| 637 | |
| 638 | int centerY = (height / 2) - (int)(cellHeight * 0.35f); |
| 639 | mTouchYBorders[0] = centerY - (int)(2.4f * cellHeight); |
| 640 | mTouchYBorders[1] = centerY - (int)(1.15f * cellHeight); |
| 641 | mTouchYBorders[2] = centerY; |
| 642 | mTouchYBorders[3] = centerY + (int)(1.15f * cellHeight);; |
| 643 | mTouchYBorders[4] = centerY + (int)(2.4f * cellHeight); |
| 644 | |
| 645 | mAllocTouchYBorders.data(mTouchYBorders); |
| 646 | |
| 647 | int centerX = (width / 2); |
| 648 | mTouchXBorders[0] = centerX - (2 * cellWidth); |
| 649 | mTouchXBorders[1] = centerX - (int)(0.83f * cellWidth);; |
| 650 | mTouchXBorders[2] = centerX; |
| 651 | mTouchXBorders[3] = centerX + (int)(0.83f * cellWidth);; |
| 652 | mTouchXBorders[4] = centerX + (2 * cellWidth); |
| 653 | |
| 654 | mAllocTouchXBorders.data(mTouchXBorders); |
| 655 | } |
| 656 | |
| 657 | int chooseTappedIcon(int x, int y, int scrollX, int currentPage) { |
| 658 | int col = -1; |
| 659 | int row = -1; |
| 660 | |
| 661 | for (int i=0; i<Defines.COLUMNS_PER_PAGE; i++) { |
| 662 | if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) { |
| 663 | col = i; |
| 664 | break; |
| 665 | } |
| 666 | } |
| 667 | for (int i=0; i<Defines.ROWS_PER_PAGE; i++) { |
| 668 | if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) { |
| 669 | row = i; |
| 670 | break; |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | if (row < 0 || col < 0) { |
| 675 | return -1; |
| 676 | } |
| 677 | |
| 678 | return (currentPage * Defines.ROWS_PER_PAGE * Defines.COLUMNS_PER_PAGE) |
| 679 | + (row * Defines.ROWS_PER_PAGE) + col; |
| 680 | } |
| 681 | |
| 682 | /** |
| 683 | * You need to call save() on mState on your own after calling this. |
| 684 | */ |
| 685 | void selectIcon(int x, int y, int scrollX, int currentPage) { |
| 686 | int iconCount = mAllAppsList.size(); |
| 687 | int index = chooseTappedIcon(x, y, scrollX, currentPage); |
| 688 | if (index < 0 || index >= iconCount) { |
| 689 | mState.selectedIconIndex = -1; |
| 690 | return; |
| 691 | } else { |
| 692 | mState.selectedIconIndex = index; |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | /** |
| 697 | * You need to call save() on mState on your own after calling this. |
| 698 | */ |
| 699 | void clearSelectedIcon() { |
| 700 | mState.selectedIconIndex = -1; |
| 701 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 702 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | |