blob: 613cd9733783e91f191bb390bb80117c1ace835c [file] [log] [blame]
Joe Onorato93839052009-08-06 20:34:32 -07001/*
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
17package com.android.launcher2;
18
19import java.io.Writer;
20import java.util.ArrayList;
21import java.util.concurrent.Semaphore;
22import java.lang.Float;
23
24import android.renderscript.RSSurfaceView;
25import android.renderscript.RenderScript;
26
27import android.renderscript.RenderScript;
28import android.renderscript.ProgramVertex;
29import android.renderscript.Element;
30import android.renderscript.Allocation;
Jason Sams78aebd82009-09-15 13:06:59 -070031import android.renderscript.Type;
Joe Onorato93839052009-08-06 20:34:32 -070032import android.renderscript.Script;
33import android.renderscript.ScriptC;
34import android.renderscript.ProgramFragment;
35import android.renderscript.ProgramStore;
36import android.renderscript.Sampler;
37
38import android.content.Context;
39import android.content.res.Resources;
Joe Onorato7c312c12009-08-13 21:36:53 -070040import android.database.DataSetObserver;
Joe Onorato93839052009-08-06 20:34:32 -070041import android.graphics.Bitmap;
42import android.graphics.BitmapFactory;
43import android.graphics.Canvas;
44import android.graphics.Paint;
Joe Onorato93839052009-08-06 20:34:32 -070045import android.graphics.drawable.BitmapDrawable;
46import android.graphics.drawable.Drawable;
47import android.os.Handler;
48import android.os.Message;
Joe Onoratod769a632009-08-11 17:09:02 -070049import android.os.SystemClock;
Joe Onorato93839052009-08-06 20:34:32 -070050import android.util.AttributeSet;
51import android.util.Log;
Joe Onoratod769a632009-08-11 17:09:02 -070052import android.view.KeyEvent;
53import android.view.MotionEvent;
Joe Onorato93839052009-08-06 20:34:32 -070054import android.view.Surface;
55import android.view.SurfaceHolder;
56import android.view.SurfaceView;
Joe Onorato6665c0f2009-09-02 15:27:24 -070057import android.view.View;
Joe Onoratod769a632009-08-11 17:09:02 -070058import android.view.VelocityTracker;
59import android.view.ViewConfiguration;
Joe Onorato93839052009-08-06 20:34:32 -070060import android.graphics.PixelFormat;
61
62
Joe Onorato6665c0f2009-09-02 15:27:24 -070063public class AllAppsView extends RSSurfaceView
Joe Onorato5162ea92009-09-03 09:39:42 -070064 implements View.OnClickListener, View.OnLongClickListener, DragSource {
Joe Onorato9c1289c2009-08-17 11:03:03 -040065 private static final String TAG = "Launcher.AllAppsView";
66
Joe Onoratofb0ca672009-09-14 17:55:46 -040067 /** Bit for mLocks for when there are icons being loaded. */
68 private static final int LOCK_ICONS_PENDING = 1;
69
Joe Onoratobcbeab82009-10-01 21:45:43 -070070 private static final int TRACKING_FLING = 0;
71 private static final int TRACKING_HOME = 1;
72
Joe Onorato6665c0f2009-09-02 15:27:24 -070073 private Launcher mLauncher;
Joe Onorato5162ea92009-09-03 09:39:42 -070074 private DragController mDragController;
Joe Onoratofb0ca672009-09-14 17:55:46 -040075
76 /** When this is 0, modifications are allowed, when it's not, they're not.
77 * TODO: What about scrolling? */
78 private int mLocks = LOCK_ICONS_PENDING;
Joe Onorato6665c0f2009-09-02 15:27:24 -070079
Joe Onoratof7b0e012009-10-01 14:09:15 -070080 private int mSlopX;
81 private int mMaxFlingVelocity;
82
Joe Onoratobcbeab82009-10-01 21:45:43 -070083 private Defines mDefines = new Defines();
Joe Onorato1feb3a82009-08-08 22:32:00 -070084 private RenderScript mRS;
85 private RolloRS mRollo;
Joe Onorato9c1289c2009-08-17 11:03:03 -040086 private ArrayList<ApplicationInfo> mAllAppsList;
Joe Onorato1feb3a82009-08-08 22:32:00 -070087
Joe Onoratoc567acb2009-08-31 14:34:43 -070088 private int mPageCount;
Joe Onorato6665c0f2009-09-02 15:27:24 -070089 private boolean mStartedScrolling;
Joe Onoratod769a632009-08-11 17:09:02 -070090 private VelocityTracker mVelocity;
Joe Onoratobcbeab82009-10-01 21:45:43 -070091 private int mTouchTracking;
Joe Onorato1feb3a82009-08-08 22:32:00 -070092 private int mLastMotionX;
Joe Onorato5162ea92009-09-03 09:39:42 -070093 private int mMotionDownRawX;
94 private int mMotionDownRawY;
Joe Onoratobcbeab82009-10-01 21:45:43 -070095 private int mHomeButtonTop;
Jason Sams86c87ed2009-09-18 13:55:55 -070096 private long mTouchTime;
Joe Onorato360d0352009-09-28 14:37:53 -040097 private boolean mZoomSwipeInProgress;
Joe Onorato1feb3a82009-08-08 22:32:00 -070098
Joe Onorato6665c0f2009-09-02 15:27:24 -070099 static class Defines {
Joe Onoratoc567acb2009-08-31 14:34:43 -0700100 public static final int ALLOC_PARAMS = 0;
101 public static final int ALLOC_STATE = 1;
Joe Onorato7bb17492009-09-24 17:51:01 -0700102 public static final int ALLOC_READBACK = 2;
103 public static final int ALLOC_ICON_IDS = 3;
104 public static final int ALLOC_LABEL_IDS = 4;
105 public static final int ALLOC_X_BORDERS = 5;
106 public static final int ALLOC_Y_BORDERS = 6;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700107
108 public static final int COLUMNS_PER_PAGE = 4;
109 public static final int ROWS_PER_PAGE = 4;
Jason Sams78aebd82009-09-15 13:06:59 -0700110
Joe Onorato6665c0f2009-09-02 15:27:24 -0700111 public static final float RADIUS = 4.0f;
112
Joe Onorato6665c0f2009-09-02 15:27:24 -0700113 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;
Joe Onoratobcbeab82009-10-01 21:45:43 -0700121
122 public int SCREEN_WIDTH_PX;
123 public int SCREEN_HEIGHT_PX;
124
125 public float FAR_ICON_SIZE;
126
127 public void recompute(int w, int h) {
128 SCREEN_WIDTH_PX = 480;
129 SCREEN_HEIGHT_PX = 800;
130 FAR_ICON_SIZE = farSize(2 * ICON_WIDTH_PX / (float)w);
131 }
132
133 private static float farSize(float sizeAt0) {
134 return sizeAt0 * (Defines.RADIUS - Defines.CAMERA_Z) / -Defines.CAMERA_Z;
135 }
Joe Onoratoc567acb2009-08-31 14:34:43 -0700136 }
Joe Onorato7c312c12009-08-13 21:36:53 -0700137
138 public AllAppsView(Context context, AttributeSet attrs) {
139 super(context, attrs);
Joe Onorato93839052009-08-06 20:34:32 -0700140 setFocusable(true);
141 getHolder().setFormat(PixelFormat.TRANSLUCENT);
Joe Onoratof7b0e012009-10-01 14:09:15 -0700142 final ViewConfiguration config = ViewConfiguration.get(context);
143 mSlopX = config.getScaledTouchSlop();
144 mMaxFlingVelocity = config.getScaledMaximumFlingVelocity();
145
Joe Onorato6665c0f2009-09-02 15:27:24 -0700146 setOnClickListener(this);
147 setOnLongClickListener(this);
Dianne Hackborne52a1b52009-09-30 22:36:20 -0700148 setZOrderOnTop(true);
Jason Samsfd22dac2009-09-20 17:24:16 -0700149 getHolder().setFormat(PixelFormat.TRANSLUCENT);
Joe Onorato93839052009-08-06 20:34:32 -0700150 }
151
Joe Onorato7c312c12009-08-13 21:36:53 -0700152 public AllAppsView(Context context, AttributeSet attrs, int defStyle) {
153 this(context, attrs);
Joe Onorato93839052009-08-06 20:34:32 -0700154 }
155
Joe Onorato6665c0f2009-09-02 15:27:24 -0700156 public void setLauncher(Launcher launcher) {
157 mLauncher = launcher;
Joe Onorato93839052009-08-06 20:34:32 -0700158 }
159
Joe Onorato1feb3a82009-08-08 22:32:00 -0700160 @Override
Joe Onorato7bb17492009-09-24 17:51:01 -0700161 public void surfaceDestroyed(SurfaceHolder holder) {
162 super.surfaceDestroyed(holder);
163
164 destroyRenderScript();
165 mRS = null;
166 mRollo = null;
167 }
168
169 @Override
Joe Onorato93839052009-08-06 20:34:32 -0700170 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
171 super.surfaceChanged(holder, format, w, h);
172
Joe Onorato6665c0f2009-09-02 15:27:24 -0700173 long startTime = SystemClock.uptimeMillis();
174
Jason Sams05de32a2009-09-27 14:01:40 -0700175 mRS = createRenderScript(true);
Joe Onorato1feb3a82009-08-08 22:32:00 -0700176 mRollo = new RolloRS();
177 mRollo.init(getResources(), w, h);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400178 if (mAllAppsList != null) {
179 mRollo.setApps(mAllAppsList);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700180 Log.d(TAG, "surfaceChanged... calling mRollo.setApps");
Joe Onorato9c1289c2009-08-17 11:03:03 -0400181 }
Joe Onoratoc567acb2009-08-31 14:34:43 -0700182
183 Resources res = getContext().getResources();
184 int barHeight = (int)res.getDimension(R.dimen.button_bar_height);
Joe Onoratobcbeab82009-10-01 21:45:43 -0700185 mHomeButtonTop = h - barHeight;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700186
187 long endTime = SystemClock.uptimeMillis();
188 Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
Joe Onorato93839052009-08-06 20:34:32 -0700189 }
190
191 @Override
192 public boolean onKeyDown(int keyCode, KeyEvent event)
193 {
Joe Onorato93839052009-08-06 20:34:32 -0700194 // this method doesn't work when 'extends View' include 'extends ScrollView'.
195 return super.onKeyDown(keyCode, event);
196 }
197
Joe Onorato93839052009-08-06 20:34:32 -0700198 @Override
199 public boolean onTouchEvent(MotionEvent ev)
200 {
Joe Onorato7bb17492009-09-24 17:51:01 -0700201 if (!isVisible()) {
Joe Onorato85a02a82009-09-08 12:34:22 -0700202 return true;
Joe Onoratoe3406a22009-09-03 14:36:25 -0700203 }
204
Joe Onoratofb0ca672009-09-14 17:55:46 -0400205 if (mLocks != 0) {
Joe Onorato85a02a82009-09-08 12:34:22 -0700206 return true;
207 }
208
209 super.onTouchEvent(ev);
210
Joe Onoratofb0ca672009-09-14 17:55:46 -0400211 int x = (int)ev.getX();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700212 int y = (int)ev.getY();
213
Joe Onoratofb0ca672009-09-14 17:55:46 -0400214 int deltaX;
Joe Onoratobcbeab82009-10-01 21:45:43 -0700215 int action = ev.getAction();
216 switch (action) {
Joe Onoratofb0ca672009-09-14 17:55:46 -0400217 case MotionEvent.ACTION_DOWN:
Joe Onoratobcbeab82009-10-01 21:45:43 -0700218 if (y > mRollo.mTouchYBorders[mRollo.mTouchYBorders.length-1]) {
219 mTouchTracking = TRACKING_HOME;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700220 } else {
Joe Onoratobcbeab82009-10-01 21:45:43 -0700221 mTouchTracking = TRACKING_FLING;
222
223 mMotionDownRawX = (int)ev.getRawX();
224 mMotionDownRawY = (int)ev.getRawY();
225 mLastMotionX = x;
226 mRollo.mReadback.read();
227
228 mRollo.mState.newPositionX = ev.getRawX() / mDefines.SCREEN_WIDTH_PX;
229 mRollo.mState.newTouchDown = 1;
230
231 if (!mRollo.checkClickOK()) {
232 mRollo.clearSelectedIcon();
233 } else {
234 mRollo.selectIcon(x, y, mRollo.mReadback.posX);
235 }
236 mRollo.mState.save();
237 mRollo.mInvokeMove.execute();
238 mVelocity = VelocityTracker.obtain();
239 mVelocity.addMovement(ev);
240 mStartedScrolling = false;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700241 }
Joe Onoratofb0ca672009-09-14 17:55:46 -0400242 break;
243 case MotionEvent.ACTION_MOVE:
244 case MotionEvent.ACTION_OUTSIDE:
Joe Onoratobcbeab82009-10-01 21:45:43 -0700245 if (mTouchTracking == TRACKING_HOME) {
246 // TODO: highlight?
Joe Onoratofb0ca672009-09-14 17:55:46 -0400247 } else {
Joe Onoratobcbeab82009-10-01 21:45:43 -0700248 int slopX = Math.abs(x - mLastMotionX);
249 if (!mStartedScrolling && slopX < mSlopX) {
250 // don't update mLastMotionX so slopX is right and when we do start scrolling
251 // below, we get the right delta.
252 } else {
253 mRollo.mState.newPositionX = ev.getRawX() / mDefines.SCREEN_WIDTH_PX;
254 mRollo.mState.newTouchDown = 1;
255 mRollo.mInvokeMove.execute();
Jason Sams86c87ed2009-09-18 13:55:55 -0700256
Joe Onoratobcbeab82009-10-01 21:45:43 -0700257 mStartedScrolling = true;
258 mRollo.clearSelectedIcon();
259 deltaX = x - mLastMotionX;
260 mVelocity.addMovement(ev);
261 mRollo.mState.save();
262 mLastMotionX = x;
263 }
Joe Onoratofb0ca672009-09-14 17:55:46 -0400264 }
265 break;
266 case MotionEvent.ACTION_UP:
267 case MotionEvent.ACTION_CANCEL:
Joe Onoratobcbeab82009-10-01 21:45:43 -0700268 if (mTouchTracking == TRACKING_HOME) {
269 if (action == MotionEvent.ACTION_UP) {
270 if (y > mRollo.mTouchYBorders[mRollo.mTouchYBorders.length-1]) {
271 mLauncher.closeAllApps(true);
272 }
273 }
Jason Sams476339d2009-09-29 18:14:38 -0700274 } else {
Joe Onoratobcbeab82009-10-01 21:45:43 -0700275 mRollo.mState.newTouchDown = 0;
276 mRollo.mState.newPositionX = ev.getRawX() / mDefines.SCREEN_WIDTH_PX;
Jason Sams476339d2009-09-29 18:14:38 -0700277
Joe Onoratobcbeab82009-10-01 21:45:43 -0700278 if (!mZoomSwipeInProgress) {
279 mVelocity.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
280 mRollo.mState.flingVelocityX
281 = mVelocity.getXVelocity() / mDefines.SCREEN_WIDTH_PX;
282 mRollo.clearSelectedIcon();
283 mRollo.mState.save();
284 mRollo.mInvokeFling.execute();
285 } else {
286 mRollo.mState.save();
287 mRollo.mInvokeMove.execute();
288 }
289
290 mLastMotionX = -10000;
291 mVelocity.recycle();
292 mVelocity = null;
293 break;
294 }
Joe Onorato93839052009-08-06 20:34:32 -0700295 }
Joe Onorato6665c0f2009-09-02 15:27:24 -0700296
297 return true;
Joe Onorato93839052009-08-06 20:34:32 -0700298 }
299
Joe Onorato6665c0f2009-09-02 15:27:24 -0700300 public void onClick(View v) {
Joe Onorato7bb17492009-09-24 17:51:01 -0700301 if (mLocks != 0 || !isVisible()) {
Joe Onoratofb0ca672009-09-14 17:55:46 -0400302 return;
303 }
Joe Onorato6665c0f2009-09-02 15:27:24 -0700304 int index = mRollo.mState.selectedIconIndex;
Jason Sams476339d2009-09-29 18:14:38 -0700305 if (mRollo.checkClickOK() && index >= 0 && index < mAllAppsList.size()) {
Joe Onorato6665c0f2009-09-02 15:27:24 -0700306 ApplicationInfo app = mAllAppsList.get(index);
307 mLauncher.startActivitySafely(app.intent);
308 }
309 }
310
311 public boolean onLongClick(View v) {
Joe Onorato7bb17492009-09-24 17:51:01 -0700312 if (mLocks != 0 || !isVisible()) {
Joe Onoratofb0ca672009-09-14 17:55:46 -0400313 return true;
314 }
Joe Onorato5162ea92009-09-03 09:39:42 -0700315 int index = mRollo.mState.selectedIconIndex;
Jason Sams476339d2009-09-29 18:14:38 -0700316 Log.d(TAG, "long click! velocity=" + mRollo.mReadback.velocity + " index=" + index);
317 if (mRollo.checkClickOK() && index >= 0 && index < mAllAppsList.size()) {
Joe Onorato5162ea92009-09-03 09:39:42 -0700318 ApplicationInfo app = mAllAppsList.get(index);
319
320 // We don't really have an accurate location to use. This will do.
Joe Onoratobcbeab82009-10-01 21:45:43 -0700321 int screenX = mMotionDownRawX - (mDefines.ICON_WIDTH_PX / 2);
322 int screenY = mMotionDownRawY - mDefines.ICON_HEIGHT_PX;
Joe Onorato5162ea92009-09-03 09:39:42 -0700323
Joe Onoratobcbeab82009-10-01 21:45:43 -0700324 int left = (mDefines.ICON_TEXTURE_WIDTH_PX - mDefines.ICON_WIDTH_PX) / 2;
325 int top = (mDefines.ICON_TEXTURE_HEIGHT_PX - mDefines.ICON_HEIGHT_PX) / 2;
Joe Onorato5162ea92009-09-03 09:39:42 -0700326 mDragController.startDrag(app.iconBitmap, screenX, screenY,
Joe Onoratobcbeab82009-10-01 21:45:43 -0700327 left, top, mDefines.ICON_WIDTH_PX, mDefines.ICON_HEIGHT_PX,
Joe Onorato5162ea92009-09-03 09:39:42 -0700328 this, app, DragController.DRAG_ACTION_COPY);
Joe Onoratoe3406a22009-09-03 14:36:25 -0700329
Joe Onorato7bb17492009-09-24 17:51:01 -0700330 mLauncher.closeAllApps(true);
Joe Onorato5162ea92009-09-03 09:39:42 -0700331 }
Joe Onorato6665c0f2009-09-02 15:27:24 -0700332 return true;
333 }
334
Joe Onorato5162ea92009-09-03 09:39:42 -0700335 public void setDragController(DragController dragger) {
336 mDragController = dragger;
337 }
338
339 public void onDropCompleted(View target, boolean success) {
340 }
341
Joe Onorato360d0352009-09-28 14:37:53 -0400342 public void setZoomSwipeInProgress(boolean swiping, boolean touchStillDown) {
343 mZoomSwipeInProgress = swiping;
344 if (!touchStillDown) {
345 mRollo.mState.newTouchDown = 0;
346 mRollo.mState.save();
347 mRollo.mInvokeTouchUp.execute();
348 }
349 }
350
Joe Onorato7bb17492009-09-24 17:51:01 -0700351 public void setZoomTarget(float amount) {
352 zoom(amount, true);
Jason Samsfd22dac2009-09-20 17:24:16 -0700353 }
354
Joe Onorato7bb17492009-09-24 17:51:01 -0700355 public void setZoom(float amount) {
356 zoom(amount, false);
357 }
358
359 private void zoom(float amount, boolean animate) {
360 if (mRollo == null) {
361 return;
362 }
363
Joe Onoratofb0ca672009-09-14 17:55:46 -0400364 cancelLongPress();
Joe Onoratofb0ca672009-09-14 17:55:46 -0400365 mRollo.clearSelectedIcon();
Joe Onorato85a02a82009-09-08 12:34:22 -0700366 if (amount > 0.001f) {
Joe Onoratoc5acd422009-10-01 14:21:24 -0700367 // set in readback, so we're correct even before the next frame
368 mRollo.mReadback.zoom = mRollo.mState.zoomTarget = amount;
Joe Onorato7bb17492009-09-24 17:51:01 -0700369 if (!animate) {
Joe Onoratoc5acd422009-10-01 14:21:24 -0700370 mRollo.mState.zoom = amount;
Joe Onorato7bb17492009-09-24 17:51:01 -0700371 mRollo.mReadback.save();
372 }
Joe Onorato85a02a82009-09-08 12:34:22 -0700373 } else {
Joe Onorato7bb17492009-09-24 17:51:01 -0700374 mRollo.mState.zoomTarget = 0;
375 if (!animate) {
376 mRollo.mReadback.zoom = mRollo.mState.zoom = 0;
377 mRollo.mReadback.save();
378 }
Joe Onoratoc567acb2009-08-31 14:34:43 -0700379 }
Joe Onoratofb0ca672009-09-14 17:55:46 -0400380 mRollo.mState.save();
Joe Onorato7bb17492009-09-24 17:51:01 -0700381 if (!animate) {
382 mRollo.mInvokeSetZoom.execute();
383 } else {
384 mRollo.mInvokeSetZoomTarget.execute();
385 }
Joe Onorato8e099e22009-09-25 17:30:47 -0700386 mReadZoom.removeMessages(1);
387 mReadZoom.sendEmptyMessageDelayed(1, 1000);
Joe Onoratofb0ca672009-09-14 17:55:46 -0400388 }
389
Joe Onorato8e099e22009-09-25 17:30:47 -0700390 Handler mReadZoom = new Handler() {
391 public void handleMessage(Message msg) {
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700392 if(mRollo != null && mRollo.mReadback != null) {
393 // FIXME: These checks may indicate other problems.
394 mRollo.mReadback.read();
395 }
Joe Onorato8e099e22009-09-25 17:30:47 -0700396 }
397 };
398
Joe Onoratofb0ca672009-09-14 17:55:46 -0400399 public boolean isVisible() {
Joe Onorato7bb17492009-09-24 17:51:01 -0700400 if (mRollo == null) {
401 return false;
402 }
Joe Onorato8e099e22009-09-25 17:30:47 -0700403 //mRollo.mReadback.read();
Joe Onorato7bb17492009-09-24 17:51:01 -0700404 return mRollo.mReadback.zoom > 0.001f;
Joe Onoratofb0ca672009-09-14 17:55:46 -0400405 }
Joe Onoratoc567acb2009-08-31 14:34:43 -0700406
Joe Onorato93839052009-08-06 20:34:32 -0700407 @Override
408 public boolean onTrackballEvent(MotionEvent ev)
409 {
410 float x = ev.getX();
411 float y = ev.getY();
412 //Float tx = new Float(x);
413 //Float ty = new Float(y);
414 //Log.e("rs", "tbe " + tx.toString() + ", " + ty.toString());
415
416
417 return true;
418 }
419
Joe Onorato9c1289c2009-08-17 11:03:03 -0400420 public void setApps(ArrayList<ApplicationInfo> list) {
421 mAllAppsList = list;
422 if (mRollo != null) {
423 mRollo.setApps(list);
424 }
Joe Onoratoc567acb2009-08-31 14:34:43 -0700425 mPageCount = countPages(list.size());
Joe Onorato6665c0f2009-09-02 15:27:24 -0700426 Log.d(TAG, "setApps mRollo=" + mRollo + " list=" + list);
Joe Onoratofb0ca672009-09-14 17:55:46 -0400427 mLocks &= ~LOCK_ICONS_PENDING;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700428 }
429
430 private void invokeIcon(int index) {
431 Log.d(TAG, "launch it!!!! index=" + index);
Joe Onoratoc567acb2009-08-31 14:34:43 -0700432 }
433
434 private static int countPages(int iconCount) {
435 int iconsPerPage = Defines.COLUMNS_PER_PAGE * Defines.ROWS_PER_PAGE;
436 int pages = iconCount / iconsPerPage;
437 if (pages*iconsPerPage != iconCount) {
438 pages++;
439 }
440 return pages;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400441 }
442
Joe Onorato93839052009-08-06 20:34:32 -0700443 public class RolloRS {
Joe Onoratobf15cb42009-08-07 14:33:40 -0700444
Joe Onorato1feb3a82009-08-08 22:32:00 -0700445 // Allocations ======
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700446
Joe Onorato93839052009-08-06 20:34:32 -0700447 private int mWidth;
448 private int mHeight;
449
450 private Resources mRes;
Joe Onorato93839052009-08-06 20:34:32 -0700451 private Script mScript;
Jason Sams86c87ed2009-09-18 13:55:55 -0700452
453 private Script.Invokable mInvokeMove;
454 private Script.Invokable mInvokeFling;
Joe Onorato7bb17492009-09-24 17:51:01 -0700455 private Script.Invokable mInvokeSetZoomTarget;
456 private Script.Invokable mInvokeSetZoom;
Joe Onorato360d0352009-09-28 14:37:53 -0400457 private Script.Invokable mInvokeTouchUp;
Jason Sams86c87ed2009-09-18 13:55:55 -0700458
Jason Samscd689e12009-09-29 15:28:22 -0700459 private ProgramStore mPSIcons;
Joe Onorato93839052009-08-06 20:34:32 -0700460 private ProgramStore mPSText;
Jason Samscd689e12009-09-29 15:28:22 -0700461 private ProgramFragment mPFColor;
462 private ProgramFragment mPFTexLinear;
463 private ProgramFragment mPFTexNearest;
Joe Onorato93839052009-08-06 20:34:32 -0700464 private ProgramVertex mPV;
Joe Onorato93839052009-08-06 20:34:32 -0700465 private ProgramVertex mPVOrtho;
Joe Onorato93839052009-08-06 20:34:32 -0700466
Joe Onoratobcbeab82009-10-01 21:45:43 -0700467 private Allocation mHomeButton;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700468
Joe Onoratobf15cb42009-08-07 14:33:40 -0700469 private Allocation[] mIcons;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700470 private int[] mIconIds;
Joe Onorato93839052009-08-06 20:34:32 -0700471 private Allocation mAllocIconID;
472
Joe Onoratobf15cb42009-08-07 14:33:40 -0700473 private Allocation[] mLabels;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700474 private int[] mLabelIds;
Joe Onorato93839052009-08-06 20:34:32 -0700475 private Allocation mAllocLabelID;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700476 private Allocation mSelectedIcon;
Joe Onorato93839052009-08-06 20:34:32 -0700477
Joe Onorato6665c0f2009-09-02 15:27:24 -0700478 private int[] mTouchYBorders;
479 private Allocation mAllocTouchYBorders;
480 private int[] mTouchXBorders;
481 private Allocation mAllocTouchXBorders;
482
483 private Bitmap mSelectionBitmap;
Joe Onorato1291a8c2009-09-15 15:07:25 -0400484 private Canvas mSelectionCanvas;
Joe Onorato93839052009-08-06 20:34:32 -0700485
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700486 Params mParams;
Joe Onorato1feb3a82009-08-08 22:32:00 -0700487 State mState;
Joe Onorato7bb17492009-09-24 17:51:01 -0700488 Readback mReadback;
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700489
Jason Sams78aebd82009-09-15 13:06:59 -0700490 class BaseAlloc {
491 Allocation mAlloc;
492 Type mType;
493
494 void save() {
495 mAlloc.data(this);
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700496 }
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700497 }
498
Jason Sams476339d2009-09-29 18:14:38 -0700499 private boolean checkClickOK() {
500 //android.util.Log.e("rs", "check click " + Float.toString(mReadback.velocity) + ", " + Float.toString(mReadback.posX));
501 return (Math.abs(mReadback.velocity) < 0.1f) &&
502 (Math.abs(mReadback.posX - Math.round(mReadback.posX)) < 0.1f);
503 }
504
Jason Sams78aebd82009-09-15 13:06:59 -0700505 class Params extends BaseAlloc {
506 Params() {
507 mType = Type.createFromClass(mRS, Params.class, 1, "ParamsClass");
508 mAlloc = Allocation.createTyped(mRS, mType);
509 save();
Joe Onorato1feb3a82009-08-08 22:32:00 -0700510 }
Jason Sams78aebd82009-09-15 13:06:59 -0700511 public int bubbleWidth;
512 public int bubbleHeight;
513 public int bubbleBitmapWidth;
514 public int bubbleBitmapHeight;
Joe Onoratobcbeab82009-10-01 21:45:43 -0700515
516 public int homeButtonId;
517 public int homeButtonWidth;
518 public int homeButtonHeight;
519 public int homeButtonTextureWidth;
520 public int homeButtonTextureHeight;
Jason Sams78aebd82009-09-15 13:06:59 -0700521 }
522
523 class State extends BaseAlloc {
Jason Sams86c87ed2009-09-18 13:55:55 -0700524 public float newPositionX;
525 public int newTouchDown;
Jason Sams86c87ed2009-09-18 13:55:55 -0700526 public float flingVelocityX;
Jason Sams78aebd82009-09-15 13:06:59 -0700527 public int iconCount;
Jason Sams78aebd82009-09-15 13:06:59 -0700528 public int selectedIconIndex = -1;
529 public int selectedIconTexture;
Joe Onorato7bb17492009-09-24 17:51:01 -0700530 public float zoomTarget;
Jason Sams78aebd82009-09-15 13:06:59 -0700531 public float zoom;
532
533 State() {
534 mType = Type.createFromClass(mRS, State.class, 1, "StateClass");
535 mAlloc = Allocation.createTyped(mRS, mType);
536 save();
537 }
Joe Onorato1feb3a82009-08-08 22:32:00 -0700538 }
539
Joe Onorato7bb17492009-09-24 17:51:01 -0700540 class Readback extends BaseAlloc {
541 public float posX;
542 public float velocity;
543 public float zoom;
544
545 Readback() {
546 mType = Type.createFromClass(mRS, Readback.class, 1, "ReadbackClass");
547 mAlloc = Allocation.createTyped(mRS, mType);
548 save();
549 }
550
551 void read() {
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700552 if(mAlloc != null) {
553 mAlloc.read(this);
554 }
Joe Onorato7bb17492009-09-24 17:51:01 -0700555 }
556 }
557
Joe Onorato1feb3a82009-08-08 22:32:00 -0700558 public RolloRS() {
559 }
560
561 public void init(Resources res, int width, int height) {
562 mRes = res;
563 mWidth = width;
564 mHeight = height;
Joe Onoratobcbeab82009-10-01 21:45:43 -0700565 mDefines.recompute(width, height);
Jason Samscd689e12009-09-29 15:28:22 -0700566 initProgramVertex();
567 initProgramFragment();
568 initProgramStore();
Joe Onorato1feb3a82009-08-08 22:32:00 -0700569 initGl();
570 initData();
Joe Onorato6665c0f2009-09-02 15:27:24 -0700571 initTouchState();
Joe Onorato1feb3a82009-08-08 22:32:00 -0700572 initRs();
573 }
574
Jason Samscd689e12009-09-29 15:28:22 -0700575 private void initProgramVertex() {
576 ProgramVertex.MatrixAllocation pva = new ProgramVertex.MatrixAllocation(mRS);
577 pva.setupProjectionNormalized(mWidth, mHeight);
Joe Onorato93839052009-08-06 20:34:32 -0700578
579 ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null);
580 mPV = pvb.create();
581 mPV.setName("PV");
Jason Samscd689e12009-09-29 15:28:22 -0700582 mPV.bindAllocation(pva);
Joe Onorato93839052009-08-06 20:34:32 -0700583
Jason Samscd689e12009-09-29 15:28:22 -0700584 pva = new ProgramVertex.MatrixAllocation(mRS);
585 pva.setupOrthoWindow(mWidth, mHeight);
Joe Onorato93839052009-08-06 20:34:32 -0700586 pvb.setTextureMatrixEnable(true);
587 mPVOrtho = pvb.create();
588 mPVOrtho.setName("PVOrtho");
Jason Samscd689e12009-09-29 15:28:22 -0700589 mPVOrtho.bindAllocation(pva);
Joe Onorato93839052009-08-06 20:34:32 -0700590
591 mRS.contextBindProgramVertex(mPV);
Jason Samscd689e12009-09-29 15:28:22 -0700592 }
Joe Onorato93839052009-08-06 20:34:32 -0700593
Jason Samscd689e12009-09-29 15:28:22 -0700594 private void initProgramFragment() {
595 Sampler.Builder sb = new Sampler.Builder(mRS);
596 sb.setMin(Sampler.Value.LINEAR);
597 sb.setMag(Sampler.Value.LINEAR);
598 sb.setWrapS(Sampler.Value.CLAMP);
599 sb.setWrapT(Sampler.Value.CLAMP);
600 Sampler linear = sb.create();
601
602 sb.setMin(Sampler.Value.NEAREST);
603 sb.setMag(Sampler.Value.NEAREST);
604 Sampler nearest = sb.create();
605
606 ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null);
607 mPFColor = bf.create();
608 mPFColor.setName("PFColor");
609
610 bf.setTexEnable(true, 0);
611 bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0);
612 mPFTexLinear = bf.create();
613 mPFTexLinear.setName("PFTexLinear");
614 mPFTexLinear.bindSampler(linear, 0);
615
616 mPFTexNearest = bf.create();
617 mPFTexNearest.setName("PFTexNearest");
618 mPFTexNearest.bindSampler(nearest, 0);
619 }
620
621 private void initProgramStore() {
622 ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null);
623 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
624 bs.setDitherEnable(true);
625 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
626 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
627 mPSIcons = bs.create();
628 mPSIcons.setName("PSIcons");
629
630 //bs.setDitherEnable(false);
631 //mPSText = bs.create();
632 //mPSText.setName("PSText");
633 }
634
635 private void initGl() {
Joe Onorato6665c0f2009-09-02 15:27:24 -0700636 mTouchXBorders = new int[Defines.COLUMNS_PER_PAGE+1];
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700637 mAllocTouchXBorders = Allocation.createSized(mRS, Element.USER_I32(mRS),
Joe Onorato6665c0f2009-09-02 15:27:24 -0700638 mTouchXBorders.length);
639 mAllocTouchXBorders.data(mTouchXBorders);
640
641 mTouchYBorders = new int[Defines.ROWS_PER_PAGE+1];
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700642 mAllocTouchYBorders = Allocation.createSized(mRS, Element.USER_I32(mRS),
Joe Onorato6665c0f2009-09-02 15:27:24 -0700643 mTouchYBorders.length);
644 mAllocTouchYBorders.data(mTouchYBorders);
Joe Onoratobf15cb42009-08-07 14:33:40 -0700645 }
Jason Sams78aebd82009-09-15 13:06:59 -0700646
Joe Onorato1feb3a82009-08-08 22:32:00 -0700647 private void initData() {
Jason Sams78aebd82009-09-15 13:06:59 -0700648 mParams = new Params();
649 mState = new State();
Joe Onorato7bb17492009-09-24 17:51:01 -0700650 mReadback = new Readback();
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700651
Joe Onoratobf15cb42009-08-07 14:33:40 -0700652 final Utilities.BubbleText bubble = new Utilities.BubbleText(getContext());
Joe Onorato93839052009-08-06 20:34:32 -0700653
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700654 mParams.bubbleWidth = bubble.getBubbleWidth();
655 mParams.bubbleHeight = bubble.getMaxBubbleHeight();
656 mParams.bubbleBitmapWidth = bubble.getBitmapWidth();
657 mParams.bubbleBitmapHeight = bubble.getBitmapHeight();
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700658
Joe Onoratobcbeab82009-10-01 21:45:43 -0700659 mHomeButton = Allocation.createFromBitmapResource(mRS, mRes,
660 R.drawable.home_button, Element.RGBA_8888(mRS), false);
661 mHomeButton.uploadToTexture(0);
662 mParams.homeButtonId = mHomeButton.getID();
663 mParams.homeButtonWidth = 76;
664 mParams.homeButtonHeight = 68;
665 mParams.homeButtonTextureWidth = 128;
666 mParams.homeButtonTextureHeight = 128;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700667
Joe Onorato1feb3a82009-08-08 22:32:00 -0700668 mParams.save();
669 mState.save();
Joe Onorato7bb17492009-09-24 17:51:01 -0700670 mReadback.save();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400671
Joe Onorato1291a8c2009-09-15 15:07:25 -0400672 mSelectionBitmap = Bitmap.createBitmap(Defines.ICON_TEXTURE_WIDTH_PX,
673 Defines.ICON_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
674 mSelectionCanvas = new Canvas(mSelectionBitmap);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700675
676 Log.d(TAG, "initData calling mRollo.setApps");
Joe Onorato9c1289c2009-08-17 11:03:03 -0400677 setApps(null);
Joe Onorato93839052009-08-06 20:34:32 -0700678 }
679
Joe Onorato1feb3a82009-08-08 22:32:00 -0700680 private void initRs() {
Joe Onorato93839052009-08-06 20:34:32 -0700681 ScriptC.Builder sb = new ScriptC.Builder(mRS);
682 sb.setScript(mRes, R.raw.rollo);
Joe Onorato93839052009-08-06 20:34:32 -0700683 sb.setRoot(true);
Joe Onoratobcbeab82009-10-01 21:45:43 -0700684 sb.addDefines(mDefines);
Jason Sams78aebd82009-09-15 13:06:59 -0700685 sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS);
686 sb.setType(mState.mType, "state", Defines.ALLOC_STATE);
Joe Onorato7bb17492009-09-24 17:51:01 -0700687 sb.setType(mReadback.mType, "readback", Defines.ALLOC_READBACK);
Jason Sams86c87ed2009-09-18 13:55:55 -0700688 mInvokeMove = sb.addInvokable("move");
689 mInvokeFling = sb.addInvokable("fling");
Joe Onorato7bb17492009-09-24 17:51:01 -0700690 mInvokeSetZoomTarget = sb.addInvokable("setZoomTarget");
691 mInvokeSetZoom = sb.addInvokable("setZoom");
Joe Onorato360d0352009-09-28 14:37:53 -0400692 mInvokeTouchUp = sb.addInvokable("touchUp");
Joe Onorato93839052009-08-06 20:34:32 -0700693 mScript = sb.create();
694 mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
695
Jason Sams78aebd82009-09-15 13:06:59 -0700696 mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
697 mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
Joe Onorato7bb17492009-09-24 17:51:01 -0700698 mScript.bindAllocation(mReadback.mAlloc, Defines.ALLOC_READBACK);
Joe Onoratod769a632009-08-11 17:09:02 -0700699 mScript.bindAllocation(mAllocIconID, Defines.ALLOC_ICON_IDS);
Joe Onoratod769a632009-08-11 17:09:02 -0700700 mScript.bindAllocation(mAllocLabelID, Defines.ALLOC_LABEL_IDS);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700701 mScript.bindAllocation(mAllocTouchXBorders, Defines.ALLOC_X_BORDERS);
702 mScript.bindAllocation(mAllocTouchYBorders, Defines.ALLOC_Y_BORDERS);
Joe Onorato93839052009-08-06 20:34:32 -0700703
704 mRS.contextBindRootScript(mScript);
705 }
Joe Onorato93839052009-08-06 20:34:32 -0700706
Joe Onorato9c1289c2009-08-17 11:03:03 -0400707 private void setApps(ArrayList<ApplicationInfo> list) {
708 final int count = list != null ? list.size() : 0;
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700709 int allocCount = count;
710 if(allocCount < 1) {
711 allocCount = 1;
712 }
713
Joe Onorato9c1289c2009-08-17 11:03:03 -0400714 mIcons = new Allocation[count];
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700715 mIconIds = new int[allocCount];
716 mAllocIconID = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400717
718 mLabels = new Allocation[count];
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700719 mLabelIds = new int[allocCount];
720 mAllocLabelID = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400721
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700722 Element ie8888 = Element.RGBA_8888(mRS);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400723
724 Utilities.BubbleText bubble = new Utilities.BubbleText(getContext());
725
726 for (int i=0; i<count; i++) {
727 final ApplicationInfo item = list.get(i);
728
729 mIcons[i] = Allocation.createFromBitmap(mRS, item.iconBitmap,
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700730 Element.RGBA_8888(mRS), false);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400731 mLabels[i] = Allocation.createFromBitmap(mRS, item.titleBitmap,
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700732 Element.RGBA_8888(mRS), false);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400733
734 mIcons[i].uploadToTexture(0);
735 mLabels[i].uploadToTexture(0);
736
Joe Onorato6665c0f2009-09-02 15:27:24 -0700737 mIconIds[i] = mIcons[i].getID();
738 mLabelIds[i] = mLabels[i].getID();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400739 }
740
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700741 mAllocIconID.data(mIconIds);
742 mAllocLabelID.data(mLabelIds);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400743
744 mState.iconCount = count;
745
Joe Onorato9c1289c2009-08-17 11:03:03 -0400746 if (mScript != null) { // wtf
747 mScript.bindAllocation(mAllocIconID, Defines.ALLOC_ICON_IDS);
748 mScript.bindAllocation(mAllocLabelID, Defines.ALLOC_LABEL_IDS);
749 }
750
751 mState.save();
752 }
Joe Onorato6665c0f2009-09-02 15:27:24 -0700753
754 void initTouchState() {
755 int width = getWidth();
756 int height = getHeight();
757
758 int iconsSize;
759 if (width < height) {
760 iconsSize = width;
761 } else {
762 iconsSize = height;
763 }
764 int cellHeight = iconsSize / Defines.ROWS_PER_PAGE;
765 int cellWidth = iconsSize / Defines.COLUMNS_PER_PAGE;
766
Joe Onorato56848b02009-09-25 13:59:59 -0700767 int centerY = (height / 2) - (int)(cellHeight * 0.2f);
768 mTouchYBorders[0] = centerY - (int)(2.8f * cellHeight);
769 mTouchYBorders[1] = centerY - (int)(1.25f * cellHeight);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700770 mTouchYBorders[2] = centerY;
Joe Onorato56848b02009-09-25 13:59:59 -0700771 mTouchYBorders[3] = centerY + (int)(1.25f * cellHeight);;
772 mTouchYBorders[4] = centerY + (int)(2.6f * cellHeight);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700773
774 mAllocTouchYBorders.data(mTouchYBorders);
Jason Sams78aebd82009-09-15 13:06:59 -0700775
Joe Onorato6665c0f2009-09-02 15:27:24 -0700776 int centerX = (width / 2);
777 mTouchXBorders[0] = centerX - (2 * cellWidth);
Joe Onorato56848b02009-09-25 13:59:59 -0700778 mTouchXBorders[1] = centerX - (int)(0.85f * cellWidth);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700779 mTouchXBorders[2] = centerX;
Joe Onorato56848b02009-09-25 13:59:59 -0700780 mTouchXBorders[3] = centerX + (int)(0.85f * cellWidth);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700781 mTouchXBorders[4] = centerX + (2 * cellWidth);
782
783 mAllocTouchXBorders.data(mTouchXBorders);
784 }
785
Jason Sams86c87ed2009-09-18 13:55:55 -0700786 int chooseTappedIcon(int x, int y, float page) {
787 int currentPage = (int)page;
788
Joe Onorato6665c0f2009-09-02 15:27:24 -0700789 int col = -1;
790 int row = -1;
791
792 for (int i=0; i<Defines.COLUMNS_PER_PAGE; i++) {
793 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
794 col = i;
795 break;
796 }
797 }
798 for (int i=0; i<Defines.ROWS_PER_PAGE; i++) {
799 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
800 row = i;
801 break;
802 }
803 }
804
805 if (row < 0 || col < 0) {
806 return -1;
807 }
808
Jason Sams78aebd82009-09-15 13:06:59 -0700809 return (currentPage * Defines.ROWS_PER_PAGE * Defines.COLUMNS_PER_PAGE)
Joe Onorato6665c0f2009-09-02 15:27:24 -0700810 + (row * Defines.ROWS_PER_PAGE) + col;
811 }
812
813 /**
814 * You need to call save() on mState on your own after calling this.
815 */
Jason Sams86c87ed2009-09-18 13:55:55 -0700816 void selectIcon(int x, int y, float pos) {
817 int index = chooseTappedIcon(x, y, pos);
Joe Onorato1291a8c2009-09-15 15:07:25 -0400818 selectIcon(index);
819 }
820
821 void selectIcon(int index) {
822 Log.d(TAG, "selectIcon index=" + index);
823 int iconCount = mAllAppsList.size();
Joe Onorato6665c0f2009-09-02 15:27:24 -0700824 if (index < 0 || index >= iconCount) {
825 mState.selectedIconIndex = -1;
826 return;
827 } else {
828 mState.selectedIconIndex = index;
Joe Onorato1291a8c2009-09-15 15:07:25 -0400829
830 Bitmap selectionBitmap = mSelectionBitmap;
831
832 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
833 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
834 mAllAppsList.get(index).iconBitmap);
835
836 mSelectedIcon = Allocation.createFromBitmap(mRS, selectionBitmap,
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700837 Element.RGBA_8888(mRS), false);
Joe Onorato1291a8c2009-09-15 15:07:25 -0400838 mSelectedIcon.uploadToTexture(0);
839 mState.selectedIconTexture = mSelectedIcon.getID();
Joe Onorato6665c0f2009-09-02 15:27:24 -0700840 }
841 }
842
843 /**
844 * You need to call save() on mState on your own after calling this.
845 */
846 void clearSelectedIcon() {
Joe Onorato2ca51dc2009-09-16 11:44:14 -0400847 mState.selectedIconIndex = -1;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700848 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400849 }
Joe Onorato93839052009-08-06 20:34:32 -0700850}
851
852