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