blob: 653ac289ae0a57d8b03b0bf1acec6e307952804c [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;
Joe Onorato539ed9d2009-10-02 10:22:14 -0700291 if (mVelocity != null) {
292 mVelocity.recycle();
293 mVelocity = null;
294 }
Joe Onoratobcbeab82009-10-01 21:45:43 -0700295 break;
296 }
Joe Onorato93839052009-08-06 20:34:32 -0700297 }
Joe Onorato6665c0f2009-09-02 15:27:24 -0700298
299 return true;
Joe Onorato93839052009-08-06 20:34:32 -0700300 }
301
Joe Onorato6665c0f2009-09-02 15:27:24 -0700302 public void onClick(View v) {
Joe Onorato7bb17492009-09-24 17:51:01 -0700303 if (mLocks != 0 || !isVisible()) {
Joe Onoratofb0ca672009-09-14 17:55:46 -0400304 return;
305 }
Joe Onorato6665c0f2009-09-02 15:27:24 -0700306 int index = mRollo.mState.selectedIconIndex;
Jason Sams476339d2009-09-29 18:14:38 -0700307 if (mRollo.checkClickOK() && index >= 0 && index < mAllAppsList.size()) {
Joe Onorato6665c0f2009-09-02 15:27:24 -0700308 ApplicationInfo app = mAllAppsList.get(index);
309 mLauncher.startActivitySafely(app.intent);
310 }
311 }
312
313 public boolean onLongClick(View v) {
Joe Onorato7bb17492009-09-24 17:51:01 -0700314 if (mLocks != 0 || !isVisible()) {
Joe Onoratofb0ca672009-09-14 17:55:46 -0400315 return true;
316 }
Joe Onorato5162ea92009-09-03 09:39:42 -0700317 int index = mRollo.mState.selectedIconIndex;
Jason Sams476339d2009-09-29 18:14:38 -0700318 Log.d(TAG, "long click! velocity=" + mRollo.mReadback.velocity + " index=" + index);
319 if (mRollo.checkClickOK() && index >= 0 && index < mAllAppsList.size()) {
Joe Onorato5162ea92009-09-03 09:39:42 -0700320 ApplicationInfo app = mAllAppsList.get(index);
321
322 // We don't really have an accurate location to use. This will do.
Joe Onoratobcbeab82009-10-01 21:45:43 -0700323 int screenX = mMotionDownRawX - (mDefines.ICON_WIDTH_PX / 2);
324 int screenY = mMotionDownRawY - mDefines.ICON_HEIGHT_PX;
Joe Onorato5162ea92009-09-03 09:39:42 -0700325
Joe Onoratobcbeab82009-10-01 21:45:43 -0700326 int left = (mDefines.ICON_TEXTURE_WIDTH_PX - mDefines.ICON_WIDTH_PX) / 2;
327 int top = (mDefines.ICON_TEXTURE_HEIGHT_PX - mDefines.ICON_HEIGHT_PX) / 2;
Joe Onorato5162ea92009-09-03 09:39:42 -0700328 mDragController.startDrag(app.iconBitmap, screenX, screenY,
Joe Onoratobcbeab82009-10-01 21:45:43 -0700329 left, top, mDefines.ICON_WIDTH_PX, mDefines.ICON_HEIGHT_PX,
Joe Onorato5162ea92009-09-03 09:39:42 -0700330 this, app, DragController.DRAG_ACTION_COPY);
Joe Onoratoe3406a22009-09-03 14:36:25 -0700331
Joe Onorato7bb17492009-09-24 17:51:01 -0700332 mLauncher.closeAllApps(true);
Joe Onorato5162ea92009-09-03 09:39:42 -0700333 }
Joe Onorato6665c0f2009-09-02 15:27:24 -0700334 return true;
335 }
336
Joe Onorato5162ea92009-09-03 09:39:42 -0700337 public void setDragController(DragController dragger) {
338 mDragController = dragger;
339 }
340
341 public void onDropCompleted(View target, boolean success) {
342 }
343
Joe Onorato360d0352009-09-28 14:37:53 -0400344 public void setZoomSwipeInProgress(boolean swiping, boolean touchStillDown) {
345 mZoomSwipeInProgress = swiping;
346 if (!touchStillDown) {
347 mRollo.mState.newTouchDown = 0;
348 mRollo.mState.save();
349 mRollo.mInvokeTouchUp.execute();
350 }
351 }
352
Joe Onorato7bb17492009-09-24 17:51:01 -0700353 public void setZoomTarget(float amount) {
354 zoom(amount, true);
Jason Samsfd22dac2009-09-20 17:24:16 -0700355 }
356
Joe Onorato7bb17492009-09-24 17:51:01 -0700357 public void setZoom(float amount) {
358 zoom(amount, false);
359 }
360
361 private void zoom(float amount, boolean animate) {
362 if (mRollo == null) {
363 return;
364 }
365
Joe Onoratofb0ca672009-09-14 17:55:46 -0400366 cancelLongPress();
Joe Onoratofb0ca672009-09-14 17:55:46 -0400367 mRollo.clearSelectedIcon();
Joe Onorato85a02a82009-09-08 12:34:22 -0700368 if (amount > 0.001f) {
Joe Onoratoc5acd422009-10-01 14:21:24 -0700369 // set in readback, so we're correct even before the next frame
370 mRollo.mReadback.zoom = mRollo.mState.zoomTarget = amount;
Joe Onorato7bb17492009-09-24 17:51:01 -0700371 if (!animate) {
Joe Onoratoc5acd422009-10-01 14:21:24 -0700372 mRollo.mState.zoom = amount;
Joe Onorato7bb17492009-09-24 17:51:01 -0700373 mRollo.mReadback.save();
374 }
Joe Onorato85a02a82009-09-08 12:34:22 -0700375 } else {
Joe Onorato7bb17492009-09-24 17:51:01 -0700376 mRollo.mState.zoomTarget = 0;
377 if (!animate) {
378 mRollo.mReadback.zoom = mRollo.mState.zoom = 0;
379 mRollo.mReadback.save();
380 }
Joe Onoratoc567acb2009-08-31 14:34:43 -0700381 }
Joe Onoratofb0ca672009-09-14 17:55:46 -0400382 mRollo.mState.save();
Joe Onorato7bb17492009-09-24 17:51:01 -0700383 if (!animate) {
384 mRollo.mInvokeSetZoom.execute();
385 } else {
386 mRollo.mInvokeSetZoomTarget.execute();
387 }
Joe Onorato8e099e22009-09-25 17:30:47 -0700388 mReadZoom.removeMessages(1);
389 mReadZoom.sendEmptyMessageDelayed(1, 1000);
Joe Onoratofb0ca672009-09-14 17:55:46 -0400390 }
391
Joe Onorato8e099e22009-09-25 17:30:47 -0700392 Handler mReadZoom = new Handler() {
393 public void handleMessage(Message msg) {
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700394 if(mRollo != null && mRollo.mReadback != null) {
395 // FIXME: These checks may indicate other problems.
396 mRollo.mReadback.read();
397 }
Joe Onorato8e099e22009-09-25 17:30:47 -0700398 }
399 };
400
Joe Onoratofb0ca672009-09-14 17:55:46 -0400401 public boolean isVisible() {
Joe Onorato7bb17492009-09-24 17:51:01 -0700402 if (mRollo == null) {
403 return false;
404 }
Joe Onorato8e099e22009-09-25 17:30:47 -0700405 //mRollo.mReadback.read();
Joe Onorato7bb17492009-09-24 17:51:01 -0700406 return mRollo.mReadback.zoom > 0.001f;
Joe Onoratofb0ca672009-09-14 17:55:46 -0400407 }
Joe Onoratoc567acb2009-08-31 14:34:43 -0700408
Joe Onorato93839052009-08-06 20:34:32 -0700409 @Override
410 public boolean onTrackballEvent(MotionEvent ev)
411 {
412 float x = ev.getX();
413 float y = ev.getY();
414 //Float tx = new Float(x);
415 //Float ty = new Float(y);
416 //Log.e("rs", "tbe " + tx.toString() + ", " + ty.toString());
417
418
419 return true;
420 }
421
Joe Onorato9c1289c2009-08-17 11:03:03 -0400422 public void setApps(ArrayList<ApplicationInfo> list) {
423 mAllAppsList = list;
424 if (mRollo != null) {
425 mRollo.setApps(list);
426 }
Joe Onoratoc567acb2009-08-31 14:34:43 -0700427 mPageCount = countPages(list.size());
Joe Onorato6665c0f2009-09-02 15:27:24 -0700428 Log.d(TAG, "setApps mRollo=" + mRollo + " list=" + list);
Joe Onoratofb0ca672009-09-14 17:55:46 -0400429 mLocks &= ~LOCK_ICONS_PENDING;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700430 }
431
432 private void invokeIcon(int index) {
433 Log.d(TAG, "launch it!!!! index=" + index);
Joe Onoratoc567acb2009-08-31 14:34:43 -0700434 }
435
436 private static int countPages(int iconCount) {
437 int iconsPerPage = Defines.COLUMNS_PER_PAGE * Defines.ROWS_PER_PAGE;
438 int pages = iconCount / iconsPerPage;
439 if (pages*iconsPerPage != iconCount) {
440 pages++;
441 }
442 return pages;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400443 }
444
Joe Onorato93839052009-08-06 20:34:32 -0700445 public class RolloRS {
Joe Onoratobf15cb42009-08-07 14:33:40 -0700446
Joe Onorato1feb3a82009-08-08 22:32:00 -0700447 // Allocations ======
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700448
Joe Onorato93839052009-08-06 20:34:32 -0700449 private int mWidth;
450 private int mHeight;
451
452 private Resources mRes;
Joe Onorato93839052009-08-06 20:34:32 -0700453 private Script mScript;
Jason Sams86c87ed2009-09-18 13:55:55 -0700454
455 private Script.Invokable mInvokeMove;
456 private Script.Invokable mInvokeFling;
Joe Onorato7bb17492009-09-24 17:51:01 -0700457 private Script.Invokable mInvokeSetZoomTarget;
458 private Script.Invokable mInvokeSetZoom;
Joe Onorato360d0352009-09-28 14:37:53 -0400459 private Script.Invokable mInvokeTouchUp;
Jason Sams86c87ed2009-09-18 13:55:55 -0700460
Jason Samscd689e12009-09-29 15:28:22 -0700461 private ProgramStore mPSIcons;
Joe Onorato93839052009-08-06 20:34:32 -0700462 private ProgramStore mPSText;
Jason Samscd689e12009-09-29 15:28:22 -0700463 private ProgramFragment mPFColor;
464 private ProgramFragment mPFTexLinear;
465 private ProgramFragment mPFTexNearest;
Joe Onorato93839052009-08-06 20:34:32 -0700466 private ProgramVertex mPV;
Joe Onorato93839052009-08-06 20:34:32 -0700467 private ProgramVertex mPVOrtho;
Joe Onorato93839052009-08-06 20:34:32 -0700468
Joe Onoratobcbeab82009-10-01 21:45:43 -0700469 private Allocation mHomeButton;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700470
Joe Onoratobf15cb42009-08-07 14:33:40 -0700471 private Allocation[] mIcons;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700472 private int[] mIconIds;
Joe Onorato93839052009-08-06 20:34:32 -0700473 private Allocation mAllocIconID;
474
Joe Onoratobf15cb42009-08-07 14:33:40 -0700475 private Allocation[] mLabels;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700476 private int[] mLabelIds;
Joe Onorato93839052009-08-06 20:34:32 -0700477 private Allocation mAllocLabelID;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700478 private Allocation mSelectedIcon;
Joe Onorato93839052009-08-06 20:34:32 -0700479
Joe Onorato6665c0f2009-09-02 15:27:24 -0700480 private int[] mTouchYBorders;
481 private Allocation mAllocTouchYBorders;
482 private int[] mTouchXBorders;
483 private Allocation mAllocTouchXBorders;
484
485 private Bitmap mSelectionBitmap;
Joe Onorato1291a8c2009-09-15 15:07:25 -0400486 private Canvas mSelectionCanvas;
Joe Onorato93839052009-08-06 20:34:32 -0700487
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700488 Params mParams;
Joe Onorato1feb3a82009-08-08 22:32:00 -0700489 State mState;
Joe Onorato7bb17492009-09-24 17:51:01 -0700490 Readback mReadback;
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700491
Jason Sams78aebd82009-09-15 13:06:59 -0700492 class BaseAlloc {
493 Allocation mAlloc;
494 Type mType;
495
496 void save() {
497 mAlloc.data(this);
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700498 }
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700499 }
500
Jason Sams476339d2009-09-29 18:14:38 -0700501 private boolean checkClickOK() {
502 //android.util.Log.e("rs", "check click " + Float.toString(mReadback.velocity) + ", " + Float.toString(mReadback.posX));
503 return (Math.abs(mReadback.velocity) < 0.1f) &&
504 (Math.abs(mReadback.posX - Math.round(mReadback.posX)) < 0.1f);
505 }
506
Jason Sams78aebd82009-09-15 13:06:59 -0700507 class Params extends BaseAlloc {
508 Params() {
509 mType = Type.createFromClass(mRS, Params.class, 1, "ParamsClass");
510 mAlloc = Allocation.createTyped(mRS, mType);
511 save();
Joe Onorato1feb3a82009-08-08 22:32:00 -0700512 }
Jason Sams78aebd82009-09-15 13:06:59 -0700513 public int bubbleWidth;
514 public int bubbleHeight;
515 public int bubbleBitmapWidth;
516 public int bubbleBitmapHeight;
Joe Onoratobcbeab82009-10-01 21:45:43 -0700517
518 public int homeButtonId;
519 public int homeButtonWidth;
520 public int homeButtonHeight;
521 public int homeButtonTextureWidth;
522 public int homeButtonTextureHeight;
Jason Sams78aebd82009-09-15 13:06:59 -0700523 }
524
525 class State extends BaseAlloc {
Jason Sams86c87ed2009-09-18 13:55:55 -0700526 public float newPositionX;
527 public int newTouchDown;
Jason Sams86c87ed2009-09-18 13:55:55 -0700528 public float flingVelocityX;
Jason Sams78aebd82009-09-15 13:06:59 -0700529 public int iconCount;
Jason Sams78aebd82009-09-15 13:06:59 -0700530 public int selectedIconIndex = -1;
531 public int selectedIconTexture;
Joe Onorato7bb17492009-09-24 17:51:01 -0700532 public float zoomTarget;
Jason Sams78aebd82009-09-15 13:06:59 -0700533 public float zoom;
534
535 State() {
536 mType = Type.createFromClass(mRS, State.class, 1, "StateClass");
537 mAlloc = Allocation.createTyped(mRS, mType);
538 save();
539 }
Joe Onorato1feb3a82009-08-08 22:32:00 -0700540 }
541
Joe Onorato7bb17492009-09-24 17:51:01 -0700542 class Readback extends BaseAlloc {
543 public float posX;
544 public float velocity;
545 public float zoom;
546
547 Readback() {
548 mType = Type.createFromClass(mRS, Readback.class, 1, "ReadbackClass");
549 mAlloc = Allocation.createTyped(mRS, mType);
550 save();
551 }
552
553 void read() {
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700554 if(mAlloc != null) {
555 mAlloc.read(this);
556 }
Joe Onorato7bb17492009-09-24 17:51:01 -0700557 }
558 }
559
Joe Onorato1feb3a82009-08-08 22:32:00 -0700560 public RolloRS() {
561 }
562
563 public void init(Resources res, int width, int height) {
564 mRes = res;
565 mWidth = width;
566 mHeight = height;
Joe Onoratobcbeab82009-10-01 21:45:43 -0700567 mDefines.recompute(width, height);
Jason Samscd689e12009-09-29 15:28:22 -0700568 initProgramVertex();
569 initProgramFragment();
570 initProgramStore();
Joe Onorato1feb3a82009-08-08 22:32:00 -0700571 initGl();
572 initData();
Joe Onorato6665c0f2009-09-02 15:27:24 -0700573 initTouchState();
Joe Onorato1feb3a82009-08-08 22:32:00 -0700574 initRs();
575 }
576
Jason Samscd689e12009-09-29 15:28:22 -0700577 private void initProgramVertex() {
578 ProgramVertex.MatrixAllocation pva = new ProgramVertex.MatrixAllocation(mRS);
579 pva.setupProjectionNormalized(mWidth, mHeight);
Joe Onorato93839052009-08-06 20:34:32 -0700580
581 ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null);
582 mPV = pvb.create();
583 mPV.setName("PV");
Jason Samscd689e12009-09-29 15:28:22 -0700584 mPV.bindAllocation(pva);
Joe Onorato93839052009-08-06 20:34:32 -0700585
Jason Samscd689e12009-09-29 15:28:22 -0700586 pva = new ProgramVertex.MatrixAllocation(mRS);
587 pva.setupOrthoWindow(mWidth, mHeight);
Joe Onorato93839052009-08-06 20:34:32 -0700588 pvb.setTextureMatrixEnable(true);
589 mPVOrtho = pvb.create();
590 mPVOrtho.setName("PVOrtho");
Jason Samscd689e12009-09-29 15:28:22 -0700591 mPVOrtho.bindAllocation(pva);
Joe Onorato93839052009-08-06 20:34:32 -0700592
593 mRS.contextBindProgramVertex(mPV);
Jason Samscd689e12009-09-29 15:28:22 -0700594 }
Joe Onorato93839052009-08-06 20:34:32 -0700595
Jason Samscd689e12009-09-29 15:28:22 -0700596 private void initProgramFragment() {
597 Sampler.Builder sb = new Sampler.Builder(mRS);
598 sb.setMin(Sampler.Value.LINEAR);
599 sb.setMag(Sampler.Value.LINEAR);
600 sb.setWrapS(Sampler.Value.CLAMP);
601 sb.setWrapT(Sampler.Value.CLAMP);
602 Sampler linear = sb.create();
603
604 sb.setMin(Sampler.Value.NEAREST);
605 sb.setMag(Sampler.Value.NEAREST);
606 Sampler nearest = sb.create();
607
608 ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null);
609 mPFColor = bf.create();
610 mPFColor.setName("PFColor");
611
612 bf.setTexEnable(true, 0);
613 bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0);
614 mPFTexLinear = bf.create();
615 mPFTexLinear.setName("PFTexLinear");
616 mPFTexLinear.bindSampler(linear, 0);
617
618 mPFTexNearest = bf.create();
619 mPFTexNearest.setName("PFTexNearest");
620 mPFTexNearest.bindSampler(nearest, 0);
621 }
622
623 private void initProgramStore() {
624 ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null);
625 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
626 bs.setDitherEnable(true);
627 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
628 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
629 mPSIcons = bs.create();
630 mPSIcons.setName("PSIcons");
631
632 //bs.setDitherEnable(false);
633 //mPSText = bs.create();
634 //mPSText.setName("PSText");
635 }
636
637 private void initGl() {
Joe Onorato6665c0f2009-09-02 15:27:24 -0700638 mTouchXBorders = new int[Defines.COLUMNS_PER_PAGE+1];
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700639 mAllocTouchXBorders = Allocation.createSized(mRS, Element.USER_I32(mRS),
Joe Onorato6665c0f2009-09-02 15:27:24 -0700640 mTouchXBorders.length);
641 mAllocTouchXBorders.data(mTouchXBorders);
642
643 mTouchYBorders = new int[Defines.ROWS_PER_PAGE+1];
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700644 mAllocTouchYBorders = Allocation.createSized(mRS, Element.USER_I32(mRS),
Joe Onorato6665c0f2009-09-02 15:27:24 -0700645 mTouchYBorders.length);
646 mAllocTouchYBorders.data(mTouchYBorders);
Joe Onoratobf15cb42009-08-07 14:33:40 -0700647 }
Jason Sams78aebd82009-09-15 13:06:59 -0700648
Joe Onorato1feb3a82009-08-08 22:32:00 -0700649 private void initData() {
Jason Sams78aebd82009-09-15 13:06:59 -0700650 mParams = new Params();
651 mState = new State();
Joe Onorato7bb17492009-09-24 17:51:01 -0700652 mReadback = new Readback();
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700653
Joe Onoratobf15cb42009-08-07 14:33:40 -0700654 final Utilities.BubbleText bubble = new Utilities.BubbleText(getContext());
Joe Onorato93839052009-08-06 20:34:32 -0700655
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700656 mParams.bubbleWidth = bubble.getBubbleWidth();
657 mParams.bubbleHeight = bubble.getMaxBubbleHeight();
658 mParams.bubbleBitmapWidth = bubble.getBitmapWidth();
659 mParams.bubbleBitmapHeight = bubble.getBitmapHeight();
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700660
Joe Onoratobcbeab82009-10-01 21:45:43 -0700661 mHomeButton = Allocation.createFromBitmapResource(mRS, mRes,
662 R.drawable.home_button, Element.RGBA_8888(mRS), false);
663 mHomeButton.uploadToTexture(0);
664 mParams.homeButtonId = mHomeButton.getID();
665 mParams.homeButtonWidth = 76;
666 mParams.homeButtonHeight = 68;
667 mParams.homeButtonTextureWidth = 128;
668 mParams.homeButtonTextureHeight = 128;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700669
Joe Onorato1feb3a82009-08-08 22:32:00 -0700670 mParams.save();
671 mState.save();
Joe Onorato7bb17492009-09-24 17:51:01 -0700672 mReadback.save();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400673
Joe Onorato1291a8c2009-09-15 15:07:25 -0400674 mSelectionBitmap = Bitmap.createBitmap(Defines.ICON_TEXTURE_WIDTH_PX,
675 Defines.ICON_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
676 mSelectionCanvas = new Canvas(mSelectionBitmap);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700677
678 Log.d(TAG, "initData calling mRollo.setApps");
Joe Onorato9c1289c2009-08-17 11:03:03 -0400679 setApps(null);
Joe Onorato93839052009-08-06 20:34:32 -0700680 }
681
Joe Onorato1feb3a82009-08-08 22:32:00 -0700682 private void initRs() {
Joe Onorato93839052009-08-06 20:34:32 -0700683 ScriptC.Builder sb = new ScriptC.Builder(mRS);
684 sb.setScript(mRes, R.raw.rollo);
Joe Onorato93839052009-08-06 20:34:32 -0700685 sb.setRoot(true);
Joe Onoratobcbeab82009-10-01 21:45:43 -0700686 sb.addDefines(mDefines);
Jason Sams78aebd82009-09-15 13:06:59 -0700687 sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS);
688 sb.setType(mState.mType, "state", Defines.ALLOC_STATE);
Joe Onorato7bb17492009-09-24 17:51:01 -0700689 sb.setType(mReadback.mType, "readback", Defines.ALLOC_READBACK);
Jason Sams86c87ed2009-09-18 13:55:55 -0700690 mInvokeMove = sb.addInvokable("move");
691 mInvokeFling = sb.addInvokable("fling");
Joe Onorato7bb17492009-09-24 17:51:01 -0700692 mInvokeSetZoomTarget = sb.addInvokable("setZoomTarget");
693 mInvokeSetZoom = sb.addInvokable("setZoom");
Joe Onorato360d0352009-09-28 14:37:53 -0400694 mInvokeTouchUp = sb.addInvokable("touchUp");
Joe Onorato93839052009-08-06 20:34:32 -0700695 mScript = sb.create();
696 mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
697
Jason Sams78aebd82009-09-15 13:06:59 -0700698 mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
699 mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
Joe Onorato7bb17492009-09-24 17:51:01 -0700700 mScript.bindAllocation(mReadback.mAlloc, Defines.ALLOC_READBACK);
Joe Onoratod769a632009-08-11 17:09:02 -0700701 mScript.bindAllocation(mAllocIconID, Defines.ALLOC_ICON_IDS);
Joe Onoratod769a632009-08-11 17:09:02 -0700702 mScript.bindAllocation(mAllocLabelID, Defines.ALLOC_LABEL_IDS);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700703 mScript.bindAllocation(mAllocTouchXBorders, Defines.ALLOC_X_BORDERS);
704 mScript.bindAllocation(mAllocTouchYBorders, Defines.ALLOC_Y_BORDERS);
Joe Onorato93839052009-08-06 20:34:32 -0700705
706 mRS.contextBindRootScript(mScript);
707 }
Joe Onorato93839052009-08-06 20:34:32 -0700708
Joe Onorato9c1289c2009-08-17 11:03:03 -0400709 private void setApps(ArrayList<ApplicationInfo> list) {
710 final int count = list != null ? list.size() : 0;
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700711 int allocCount = count;
712 if(allocCount < 1) {
713 allocCount = 1;
714 }
715
Joe Onorato9c1289c2009-08-17 11:03:03 -0400716 mIcons = new Allocation[count];
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700717 mIconIds = new int[allocCount];
718 mAllocIconID = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400719
720 mLabels = new Allocation[count];
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700721 mLabelIds = new int[allocCount];
722 mAllocLabelID = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400723
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700724 Element ie8888 = Element.RGBA_8888(mRS);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400725
726 Utilities.BubbleText bubble = new Utilities.BubbleText(getContext());
727
728 for (int i=0; i<count; i++) {
729 final ApplicationInfo item = list.get(i);
730
731 mIcons[i] = Allocation.createFromBitmap(mRS, item.iconBitmap,
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700732 Element.RGBA_8888(mRS), false);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400733 mLabels[i] = Allocation.createFromBitmap(mRS, item.titleBitmap,
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700734 Element.RGBA_8888(mRS), false);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400735
736 mIcons[i].uploadToTexture(0);
737 mLabels[i].uploadToTexture(0);
738
Joe Onorato6665c0f2009-09-02 15:27:24 -0700739 mIconIds[i] = mIcons[i].getID();
740 mLabelIds[i] = mLabels[i].getID();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400741 }
742
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700743 mAllocIconID.data(mIconIds);
744 mAllocLabelID.data(mLabelIds);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400745
746 mState.iconCount = count;
747
Joe Onorato9c1289c2009-08-17 11:03:03 -0400748 if (mScript != null) { // wtf
749 mScript.bindAllocation(mAllocIconID, Defines.ALLOC_ICON_IDS);
750 mScript.bindAllocation(mAllocLabelID, Defines.ALLOC_LABEL_IDS);
751 }
752
753 mState.save();
754 }
Joe Onorato6665c0f2009-09-02 15:27:24 -0700755
756 void initTouchState() {
757 int width = getWidth();
758 int height = getHeight();
759
760 int iconsSize;
761 if (width < height) {
762 iconsSize = width;
763 } else {
764 iconsSize = height;
765 }
766 int cellHeight = iconsSize / Defines.ROWS_PER_PAGE;
767 int cellWidth = iconsSize / Defines.COLUMNS_PER_PAGE;
768
Joe Onorato56848b02009-09-25 13:59:59 -0700769 int centerY = (height / 2) - (int)(cellHeight * 0.2f);
770 mTouchYBorders[0] = centerY - (int)(2.8f * cellHeight);
771 mTouchYBorders[1] = centerY - (int)(1.25f * cellHeight);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700772 mTouchYBorders[2] = centerY;
Joe Onorato56848b02009-09-25 13:59:59 -0700773 mTouchYBorders[3] = centerY + (int)(1.25f * cellHeight);;
774 mTouchYBorders[4] = centerY + (int)(2.6f * cellHeight);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700775
776 mAllocTouchYBorders.data(mTouchYBorders);
Jason Sams78aebd82009-09-15 13:06:59 -0700777
Joe Onorato6665c0f2009-09-02 15:27:24 -0700778 int centerX = (width / 2);
779 mTouchXBorders[0] = centerX - (2 * cellWidth);
Joe Onorato56848b02009-09-25 13:59:59 -0700780 mTouchXBorders[1] = centerX - (int)(0.85f * cellWidth);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700781 mTouchXBorders[2] = centerX;
Joe Onorato56848b02009-09-25 13:59:59 -0700782 mTouchXBorders[3] = centerX + (int)(0.85f * cellWidth);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700783 mTouchXBorders[4] = centerX + (2 * cellWidth);
784
785 mAllocTouchXBorders.data(mTouchXBorders);
786 }
787
Jason Sams86c87ed2009-09-18 13:55:55 -0700788 int chooseTappedIcon(int x, int y, float page) {
789 int currentPage = (int)page;
790
Joe Onorato6665c0f2009-09-02 15:27:24 -0700791 int col = -1;
792 int row = -1;
793
794 for (int i=0; i<Defines.COLUMNS_PER_PAGE; i++) {
795 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
796 col = i;
797 break;
798 }
799 }
800 for (int i=0; i<Defines.ROWS_PER_PAGE; i++) {
801 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
802 row = i;
803 break;
804 }
805 }
806
807 if (row < 0 || col < 0) {
808 return -1;
809 }
810
Jason Sams78aebd82009-09-15 13:06:59 -0700811 return (currentPage * Defines.ROWS_PER_PAGE * Defines.COLUMNS_PER_PAGE)
Joe Onorato6665c0f2009-09-02 15:27:24 -0700812 + (row * Defines.ROWS_PER_PAGE) + col;
813 }
814
815 /**
816 * You need to call save() on mState on your own after calling this.
817 */
Jason Sams86c87ed2009-09-18 13:55:55 -0700818 void selectIcon(int x, int y, float pos) {
819 int index = chooseTappedIcon(x, y, pos);
Joe Onorato1291a8c2009-09-15 15:07:25 -0400820 selectIcon(index);
821 }
822
823 void selectIcon(int index) {
824 Log.d(TAG, "selectIcon index=" + index);
825 int iconCount = mAllAppsList.size();
Joe Onorato6665c0f2009-09-02 15:27:24 -0700826 if (index < 0 || index >= iconCount) {
827 mState.selectedIconIndex = -1;
828 return;
829 } else {
830 mState.selectedIconIndex = index;
Joe Onorato1291a8c2009-09-15 15:07:25 -0400831
832 Bitmap selectionBitmap = mSelectionBitmap;
833
834 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
835 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
836 mAllAppsList.get(index).iconBitmap);
837
838 mSelectedIcon = Allocation.createFromBitmap(mRS, selectionBitmap,
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700839 Element.RGBA_8888(mRS), false);
Joe Onorato1291a8c2009-09-15 15:07:25 -0400840 mSelectedIcon.uploadToTexture(0);
841 mState.selectedIconTexture = mSelectedIcon.getID();
Joe Onorato6665c0f2009-09-02 15:27:24 -0700842 }
843 }
844
845 /**
846 * You need to call save() on mState on your own after calling this.
847 */
848 void clearSelectedIcon() {
Joe Onorato2ca51dc2009-09-16 11:44:14 -0400849 mState.selectedIconIndex = -1;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700850 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400851 }
Joe Onorato93839052009-08-06 20:34:32 -0700852}
853
854