blob: 3f3b45254d9ea63d29785d5f39f096fd123f626e [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
Joe Onoratocb9f7982009-10-31 16:32:02 -040019import android.content.ComponentName;
Joe Onorato93839052009-08-06 20:34:32 -070020import android.content.Context;
21import android.content.res.Resources;
22import android.graphics.Bitmap;
Joe Onorato93839052009-08-06 20:34:32 -070023import android.graphics.Canvas;
Mike Cleron4a5c1e12009-11-03 10:17:05 -080024import android.graphics.PixelFormat;
Mike Cleron7d5d7462009-10-20 14:06:00 -070025import android.graphics.Rect;
Joe Onoratod769a632009-08-11 17:09:02 -070026import android.os.SystemClock;
Mike Cleron4a5c1e12009-11-03 10:17:05 -080027import android.renderscript.Allocation;
28import android.renderscript.Dimension;
29import android.renderscript.Element;
30import android.renderscript.ProgramFragment;
31import android.renderscript.ProgramStore;
32import android.renderscript.ProgramVertex;
33import android.renderscript.RSSurfaceView;
34import android.renderscript.RenderScript;
35import android.renderscript.Sampler;
36import android.renderscript.Script;
37import android.renderscript.ScriptC;
38import android.renderscript.SimpleMesh;
39import android.renderscript.Type;
Joe Onorato93839052009-08-06 20:34:32 -070040import android.util.AttributeSet;
41import android.util.Log;
Joe Onoratod769a632009-08-11 17:09:02 -070042import android.view.KeyEvent;
43import android.view.MotionEvent;
Joe Onoratob39e51a2009-10-28 15:47:49 -040044import android.view.SoundEffectConstants;
Joe Onorato93839052009-08-06 20:34:32 -070045import android.view.SurfaceHolder;
Joe Onoratod769a632009-08-11 17:09:02 -070046import android.view.VelocityTracker;
Mike Cleron4a5c1e12009-11-03 10:17:05 -080047import android.view.View;
Joe Onoratod769a632009-08-11 17:09:02 -070048import android.view.ViewConfiguration;
Mike Cleron4a5c1e12009-11-03 10:17:05 -080049
50import java.util.ArrayList;
51import java.util.Collections;
52import java.util.Comparator;
Joe Onorato93839052009-08-06 20:34:32 -070053
54
Joe Onorato6665c0f2009-09-02 15:27:24 -070055public class AllAppsView extends RSSurfaceView
Joe Onorato5162ea92009-09-03 09:39:42 -070056 implements View.OnClickListener, View.OnLongClickListener, DragSource {
Joe Onorato9c1289c2009-08-17 11:03:03 -040057 private static final String TAG = "Launcher.AllAppsView";
58
Joe Onoratofb0ca672009-09-14 17:55:46 -040059 /** Bit for mLocks for when there are icons being loaded. */
60 private static final int LOCK_ICONS_PENDING = 1;
61
Joe Onorato68ffd102009-10-15 17:59:43 -070062 private static final int TRACKING_NONE = 0;
63 private static final int TRACKING_FLING = 1;
64 private static final int TRACKING_HOME = 2;
Joe Onoratobcbeab82009-10-01 21:45:43 -070065
Joe Onorato6665c0f2009-09-02 15:27:24 -070066 private Launcher mLauncher;
Joe Onorato5162ea92009-09-03 09:39:42 -070067 private DragController mDragController;
Joe Onoratofb0ca672009-09-14 17:55:46 -040068
69 /** When this is 0, modifications are allowed, when it's not, they're not.
70 * TODO: What about scrolling? */
71 private int mLocks = LOCK_ICONS_PENDING;
Joe Onorato6665c0f2009-09-02 15:27:24 -070072
Joe Onorato82ca5502009-10-15 16:59:23 -070073 private int mSlop;
Joe Onoratof7b0e012009-10-01 14:09:15 -070074 private int mMaxFlingVelocity;
75
Joe Onoratobcbeab82009-10-01 21:45:43 -070076 private Defines mDefines = new Defines();
Joe Onorato1feb3a82009-08-08 22:32:00 -070077 private RenderScript mRS;
78 private RolloRS mRollo;
Joe Onorato9c1289c2009-08-17 11:03:03 -040079 private ArrayList<ApplicationInfo> mAllAppsList;
Jason Sams2e19c052009-10-20 18:19:55 -070080
Mike Cleron7d5d7462009-10-20 14:06:00 -070081 /**
82 * True when we are using arrow keys or trackball to drive navigation
83 */
84 private boolean mArrowNavigation = false;
Jason Sams2e19c052009-10-20 18:19:55 -070085
Mike Cleron4a5c1e12009-11-03 10:17:05 -080086 /**
87 * Used to keep track of the selection when AllAppsView loses window focus
88 */
89 private int mLastSelectedIcon;
90
Joe Onorato6665c0f2009-09-02 15:27:24 -070091 private boolean mStartedScrolling;
Joe Onoratod769a632009-08-11 17:09:02 -070092 private VelocityTracker mVelocity;
Joe Onoratobcbeab82009-10-01 21:45:43 -070093 private int mTouchTracking;
Joe Onorato5162ea92009-09-03 09:39:42 -070094 private int mMotionDownRawX;
95 private int mMotionDownRawY;
Joe Onorato82ca5502009-10-15 16:59:23 -070096 private int mDownIconIndex = -1;
97 private int mCurrentIconIndex = -1;
Mike Cleron4a5c1e12009-11-03 10:17:05 -080098
Joe Onorato1feb3a82009-08-08 22:32:00 -070099
Joe Onorato6665c0f2009-09-02 15:27:24 -0700100 static class Defines {
Joe Onoratoc567acb2009-08-31 14:34:43 -0700101 public static final int ALLOC_PARAMS = 0;
102 public static final int ALLOC_STATE = 1;
Joe Onorato7bb17492009-09-24 17:51:01 -0700103 public static final int ALLOC_ICON_IDS = 3;
104 public static final int ALLOC_LABEL_IDS = 4;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700105
106 public static final int COLUMNS_PER_PAGE = 4;
107 public static final int ROWS_PER_PAGE = 4;
Jason Sams78aebd82009-09-15 13:06:59 -0700108
Joe Onorato6665c0f2009-09-02 15:27:24 -0700109 public static final int ICON_WIDTH_PX = 64;
110 public static final int ICON_TEXTURE_WIDTH_PX = 128;
111
112 public static final int ICON_HEIGHT_PX = 64;
113 public static final int ICON_TEXTURE_HEIGHT_PX = 128;
Joe Onoratobcbeab82009-10-01 21:45:43 -0700114
115 public int SCREEN_WIDTH_PX;
116 public int SCREEN_HEIGHT_PX;
117
Joe Onoratobcbeab82009-10-01 21:45:43 -0700118 public void recompute(int w, int h) {
119 SCREEN_WIDTH_PX = 480;
120 SCREEN_HEIGHT_PX = 800;
Joe Onoratobcbeab82009-10-01 21:45:43 -0700121 }
Joe Onoratoc567acb2009-08-31 14:34:43 -0700122 }
Joe Onorato7c312c12009-08-13 21:36:53 -0700123
124 public AllAppsView(Context context, AttributeSet attrs) {
125 super(context, attrs);
Joe Onorato93839052009-08-06 20:34:32 -0700126 setFocusable(true);
Joe Onoratob39e51a2009-10-28 15:47:49 -0400127 setSoundEffectsEnabled(false);
Joe Onorato93839052009-08-06 20:34:32 -0700128 getHolder().setFormat(PixelFormat.TRANSLUCENT);
Joe Onoratof7b0e012009-10-01 14:09:15 -0700129 final ViewConfiguration config = ViewConfiguration.get(context);
Joe Onorato82ca5502009-10-15 16:59:23 -0700130 mSlop = config.getScaledTouchSlop();
Joe Onoratof7b0e012009-10-01 14:09:15 -0700131 mMaxFlingVelocity = config.getScaledMaximumFlingVelocity();
132
Joe Onorato6665c0f2009-09-02 15:27:24 -0700133 setOnClickListener(this);
134 setOnLongClickListener(this);
Dianne Hackborne52a1b52009-09-30 22:36:20 -0700135 setZOrderOnTop(true);
Jason Samsfd22dac2009-09-20 17:24:16 -0700136 getHolder().setFormat(PixelFormat.TRANSLUCENT);
Joe Onorato93839052009-08-06 20:34:32 -0700137 }
138
Joe Onoratob39e51a2009-10-28 15:47:49 -0400139 /**
140 * If you have an attached click listener, View always plays the click sound!?!?
141 * Deal with sound effects by hand.
142 */
143 public void reallyPlaySoundEffect(int sound) {
144 boolean old = isSoundEffectsEnabled();
145 setSoundEffectsEnabled(true);
146 playSoundEffect(sound);
147 setSoundEffectsEnabled(old);
148 }
149
Joe Onorato7c312c12009-08-13 21:36:53 -0700150 public AllAppsView(Context context, AttributeSet attrs, int defStyle) {
151 this(context, attrs);
Joe Onorato93839052009-08-06 20:34:32 -0700152 }
153
Joe Onorato6665c0f2009-09-02 15:27:24 -0700154 public void setLauncher(Launcher launcher) {
155 mLauncher = launcher;
Joe Onorato93839052009-08-06 20:34:32 -0700156 }
157
Joe Onorato1feb3a82009-08-08 22:32:00 -0700158 @Override
Joe Onorato7bb17492009-09-24 17:51:01 -0700159 public void surfaceDestroyed(SurfaceHolder holder) {
160 super.surfaceDestroyed(holder);
Jason Sams20df7c72009-11-05 12:30:24 -0800161 mRollo.mHasSurface = false;
Joe Onorato7bb17492009-09-24 17:51:01 -0700162 }
163
164 @Override
Joe Onorato93839052009-08-06 20:34:32 -0700165 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
Joe Onorato080d9b62009-11-02 12:01:11 -0500166 Log.d(TAG, "starting surfaceChanged");
Joe Onorato6665c0f2009-09-02 15:27:24 -0700167 long startTime = SystemClock.uptimeMillis();
168
Joe Onorato080d9b62009-11-02 12:01:11 -0500169 super.surfaceChanged(holder, format, w, h);
170
Jason Sams90396672009-11-03 13:59:34 -0800171 if (mRS == null) {
Jason Sams81134792009-10-27 15:38:42 -0700172
Jason Sams90396672009-11-03 13:59:34 -0800173 mRS = createRenderScript(true);
174 mRollo = new RolloRS();
Jason Sams20df7c72009-11-05 12:30:24 -0800175 mRollo.mHasSurface = true;
Jason Sams90396672009-11-03 13:59:34 -0800176 mRollo.init(getResources(), w, h);
177 if (mAllAppsList != null) {
178 mRollo.setApps(mAllAppsList);
179 Log.d(TAG, "surfaceChanged... calling mRollo.setApps");
180 }
Jason Sams20df7c72009-11-05 12:30:24 -0800181 } else {
182 mRollo.mHasSurface = true;
183 mRollo.dirtyCheck();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400184 }
Joe Onoratoc567acb2009-08-31 14:34:43 -0700185
186 Resources res = getContext().getResources();
187 int barHeight = (int)res.getDimension(R.dimen.button_bar_height);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700188
189 long endTime = SystemClock.uptimeMillis();
190 Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
Joe Onorato93839052009-08-06 20:34:32 -0700191 }
Jason Sams2e19c052009-10-20 18:19:55 -0700192
Joe Onorato93839052009-08-06 20:34:32 -0700193 @Override
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800194 public void onWindowFocusChanged(boolean hasWindowFocus) {
195 super.onWindowFocusChanged(hasWindowFocus);
196 if (mArrowNavigation) {
197 if (!hasWindowFocus) {
198 // Clear selection when we lose window focus
199 mLastSelectedIcon = mRollo.mState.selectedIconIndex;
200 mRollo.clearSelectedIcon();
201 mRollo.mState.save();
202 } else if (hasWindowFocus) {
203 if (mRollo.mState.iconCount > 0) {
204 int selection = mLastSelectedIcon;
205 final int firstIcon = Math.round(mRollo.mMessageProc.mPosX) *
206 Defines.COLUMNS_PER_PAGE;
207 if (selection < 0 || // No selection
208 selection < firstIcon || // off the top of the screen
209 selection >= mRollo.mState.iconCount || // past last icon
210 selection >= firstIcon + // past last icon on screen
211 (Defines.COLUMNS_PER_PAGE * Defines.ROWS_PER_PAGE)) {
212 selection = firstIcon;
213 }
214
215 // Select the first icon when we gain window focus
Joe Onoratoc61cff92009-11-08 11:54:39 -0500216 mRollo.selectIcon(selection, false);
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800217 mRollo.mState.save();
218 }
219 }
220 }
221 }
222
223 @Override
Mike Cleron7d5d7462009-10-20 14:06:00 -0700224 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
225 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
Joe Onorato859b3a72009-10-28 15:17:01 -0400226
227 if (!isVisible()) {
228 return;
229 }
230
Mike Cleron7d5d7462009-10-20 14:06:00 -0700231 if (gainFocus) {
232 if (!mArrowNavigation && mRollo.mState.iconCount > 0) {
233 // Select the first icon when we gain keyboard focus
234 mArrowNavigation = true;
Joe Onoratoc61cff92009-11-08 11:54:39 -0500235 mRollo.selectIcon(Math.round(mRollo.mMessageProc.mPosX) * Defines.COLUMNS_PER_PAGE,
236 false);
Mike Cleron7d5d7462009-10-20 14:06:00 -0700237 mRollo.mState.save();
238 }
239 } else {
240 if (mArrowNavigation) {
241 // Clear selection when we lose focus
242 mRollo.clearSelectedIcon();
243 mRollo.mState.save();
244 mArrowNavigation = false;
245 }
246 }
247 }
248
249 @Override
250 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Sams2e19c052009-10-20 18:19:55 -0700251
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800252 boolean handled = false;
253
Joe Onorato859b3a72009-10-28 15:17:01 -0400254 if (!isVisible()) {
255 return false;
256 }
Joe Onoratoa13f5742009-11-02 17:15:19 -0500257 final int iconCount = mRollo.mState.iconCount;
258
Mike Cleron7d5d7462009-10-20 14:06:00 -0700259 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
260 if (mArrowNavigation) {
261 int whichApp = mRollo.mState.selectedIconIndex;
262 if (whichApp >= 0) {
263 ApplicationInfo app = mAllAppsList.get(whichApp);
264 mLauncher.startActivitySafely(app.intent);
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800265 handled = true;
Mike Cleron7d5d7462009-10-20 14:06:00 -0700266 }
267 }
268 }
Jason Sams2e19c052009-10-20 18:19:55 -0700269
Joe Onoratoa13f5742009-11-02 17:15:19 -0500270 if (mArrowNavigation && iconCount > 0) {
Mike Cleron7d5d7462009-10-20 14:06:00 -0700271 mArrowNavigation = true;
Jason Sams2e19c052009-10-20 18:19:55 -0700272
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800273 int currentSelection = mRollo.mState.selectedIconIndex;
274 int currentTopRow = Math.round(mRollo.mMessageProc.mPosX);
Jason Sams2e19c052009-10-20 18:19:55 -0700275
Mike Cleron7d5d7462009-10-20 14:06:00 -0700276 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE-1
Joe Onoratoa13f5742009-11-02 17:15:19 -0500277 final int currentPageCol = currentSelection % Defines.COLUMNS_PER_PAGE;
Jason Sams2e19c052009-10-20 18:19:55 -0700278
Mike Cleron7d5d7462009-10-20 14:06:00 -0700279 // The row of the current selection, in the range 0..ROWS_PER_PAGE-1
Joe Onoratoa13f5742009-11-02 17:15:19 -0500280 final int currentPageRow = (currentSelection - (currentTopRow*Defines.COLUMNS_PER_PAGE))
Mike Cleron7d5d7462009-10-20 14:06:00 -0700281 / Defines.ROWS_PER_PAGE;
Jason Sams2e19c052009-10-20 18:19:55 -0700282
Mike Cleron7d5d7462009-10-20 14:06:00 -0700283 int newSelection = currentSelection;
284
285 switch (keyCode) {
286 case KeyEvent.KEYCODE_DPAD_UP:
287 if (currentPageRow > 0) {
288 newSelection = currentSelection - Defines.COLUMNS_PER_PAGE;
289 } else if (currentTopRow > 0) {
Jason Sams2e19c052009-10-20 18:19:55 -0700290 newSelection = currentSelection - Defines.COLUMNS_PER_PAGE;
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800291 mRollo.moveTo(newSelection / Defines.COLUMNS_PER_PAGE);
Mike Cleron7d5d7462009-10-20 14:06:00 -0700292 }
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800293 handled = true;
Mike Cleron7d5d7462009-10-20 14:06:00 -0700294 break;
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800295
Joe Onoratoa13f5742009-11-02 17:15:19 -0500296 case KeyEvent.KEYCODE_DPAD_DOWN: {
297 final int rowCount = iconCount / Defines.COLUMNS_PER_PAGE
298 + (iconCount % Defines.COLUMNS_PER_PAGE == 0 ? 0 : 1);
299 final int currentRow = currentSelection / Defines.COLUMNS_PER_PAGE;
300 if (currentRow < rowCount-1) {
301 newSelection = currentSelection + Defines.COLUMNS_PER_PAGE;
302 if (newSelection >= iconCount) {
303 // Go from D to G in this arrangement:
304 // A B C D
305 // E F G
306 newSelection = iconCount - 1;
307 }
308 if (currentPageRow >= Defines.ROWS_PER_PAGE - 1) {
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800309 mRollo.moveTo((newSelection / Defines.COLUMNS_PER_PAGE) -
310 Defines.ROWS_PER_PAGE + 1);
Mike Cleron7d5d7462009-10-20 14:06:00 -0700311 }
312 }
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800313 handled = true;
Mike Cleron7d5d7462009-10-20 14:06:00 -0700314 break;
Joe Onoratoa13f5742009-11-02 17:15:19 -0500315 }
Mike Cleron7d5d7462009-10-20 14:06:00 -0700316 case KeyEvent.KEYCODE_DPAD_LEFT:
317 if (currentPageCol > 0) {
318 newSelection = currentSelection - 1;
319 }
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800320 handled = true;
Mike Cleron7d5d7462009-10-20 14:06:00 -0700321 break;
322 case KeyEvent.KEYCODE_DPAD_RIGHT:
Jason Sams2e19c052009-10-20 18:19:55 -0700323 if ((currentPageCol < Defines.COLUMNS_PER_PAGE - 1) &&
Joe Onoratoa13f5742009-11-02 17:15:19 -0500324 (currentSelection < iconCount - 1)) {
Mike Cleron7d5d7462009-10-20 14:06:00 -0700325 newSelection = currentSelection + 1;
326 }
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800327 handled = true;
Mike Cleron7d5d7462009-10-20 14:06:00 -0700328 break;
329 }
330 if (newSelection != currentSelection) {
Joe Onoratoc61cff92009-11-08 11:54:39 -0500331 mRollo.selectIcon(newSelection, false);
Mike Cleron7d5d7462009-10-20 14:06:00 -0700332 mRollo.mState.save();
333 }
334 }
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800335 return handled;
Joe Onorato93839052009-08-06 20:34:32 -0700336 }
337
Joe Onorato93839052009-08-06 20:34:32 -0700338 @Override
339 public boolean onTouchEvent(MotionEvent ev)
340 {
Mike Cleron7d5d7462009-10-20 14:06:00 -0700341 mArrowNavigation = false;
Jason Sams2e19c052009-10-20 18:19:55 -0700342
Joe Onorato7bb17492009-09-24 17:51:01 -0700343 if (!isVisible()) {
Joe Onorato85a02a82009-09-08 12:34:22 -0700344 return true;
Joe Onoratoe3406a22009-09-03 14:36:25 -0700345 }
346
Joe Onoratofb0ca672009-09-14 17:55:46 -0400347 if (mLocks != 0) {
Joe Onorato85a02a82009-09-08 12:34:22 -0700348 return true;
349 }
350
351 super.onTouchEvent(ev);
352
Joe Onoratofb0ca672009-09-14 17:55:46 -0400353 int x = (int)ev.getX();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700354 int y = (int)ev.getY();
355
Joe Onoratobcbeab82009-10-01 21:45:43 -0700356 int action = ev.getAction();
357 switch (action) {
Joe Onoratofb0ca672009-09-14 17:55:46 -0400358 case MotionEvent.ACTION_DOWN:
Joe Onoratobcbeab82009-10-01 21:45:43 -0700359 if (y > mRollo.mTouchYBorders[mRollo.mTouchYBorders.length-1]) {
360 mTouchTracking = TRACKING_HOME;
Joe Onoratod63458b2009-10-15 21:19:09 -0700361 mRollo.setHomeSelected(true);
362 mRollo.mState.save();
Mike Cleron7d5d7462009-10-20 14:06:00 -0700363 mCurrentIconIndex = -1;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700364 } else {
Joe Onoratobcbeab82009-10-01 21:45:43 -0700365 mTouchTracking = TRACKING_FLING;
366
367 mMotionDownRawX = (int)ev.getRawX();
368 mMotionDownRawY = (int)ev.getRawY();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700369
Mike Cleron7d5d7462009-10-20 14:06:00 -0700370 mRollo.mState.newPositionX = ev.getRawY() / getHeight();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700371 mRollo.mState.newTouchDown = 1;
372
373 if (!mRollo.checkClickOK()) {
374 mRollo.clearSelectedIcon();
375 } else {
Joe Onorato82ca5502009-10-15 16:59:23 -0700376 mDownIconIndex = mCurrentIconIndex
Joe Onoratoc61cff92009-11-08 11:54:39 -0500377 = mRollo.selectIcon(x, y, mRollo.mMessageProc.mPosX, true);
Joe Onorato82ca5502009-10-15 16:59:23 -0700378 if (mDownIconIndex < 0) {
379 // if nothing was selected, no long press.
380 cancelLongPress();
381 }
Joe Onoratobcbeab82009-10-01 21:45:43 -0700382 }
383 mRollo.mState.save();
Jason Samsd8152b92009-10-13 17:19:10 -0700384 mRollo.move();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700385 mVelocity = VelocityTracker.obtain();
386 mVelocity.addMovement(ev);
387 mStartedScrolling = false;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700388 }
Joe Onoratofb0ca672009-09-14 17:55:46 -0400389 break;
390 case MotionEvent.ACTION_MOVE:
391 case MotionEvent.ACTION_OUTSIDE:
Joe Onoratobcbeab82009-10-01 21:45:43 -0700392 if (mTouchTracking == TRACKING_HOME) {
Joe Onoratod63458b2009-10-15 21:19:09 -0700393 mRollo.setHomeSelected(y > mRollo.mTouchYBorders[mRollo.mTouchYBorders.length-1]);
394 mRollo.mState.save();
Joe Onorato68ffd102009-10-15 17:59:43 -0700395 } else if (mTouchTracking == TRACKING_FLING) {
Joe Onorato82ca5502009-10-15 16:59:23 -0700396 int rawX = (int)ev.getRawX();
397 int rawY = (int)ev.getRawY();
398 int slop;
Jason Sams37e7c2b2009-10-19 12:55:43 -0700399 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsd8152b92009-10-13 17:19:10 -0700400
Joe Onorato82ca5502009-10-15 16:59:23 -0700401 if (!mStartedScrolling && slop < mSlop) {
402 // don't update anything so when we do start scrolling
Joe Onoratobcbeab82009-10-01 21:45:43 -0700403 // below, we get the right delta.
Joe Onorato82ca5502009-10-15 16:59:23 -0700404 mCurrentIconIndex = mRollo.chooseTappedIcon(x, y, mRollo.mMessageProc.mPosX);
405 if (mDownIconIndex != mCurrentIconIndex) {
406 // If a different icon is selected, don't allow it to be picked up.
407 // This handles off-axis dragging.
408 cancelLongPress();
409 mCurrentIconIndex = -1;
410 }
Joe Onoratobcbeab82009-10-01 21:45:43 -0700411 } else {
Joe Onorato82ca5502009-10-15 16:59:23 -0700412 if (!mStartedScrolling) {
413 cancelLongPress();
414 mCurrentIconIndex = -1;
415 }
Mike Cleron7d5d7462009-10-20 14:06:00 -0700416 mRollo.mState.newPositionX = ev.getRawY() / getHeight();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700417 mRollo.mState.newTouchDown = 1;
Jason Samsd8152b92009-10-13 17:19:10 -0700418 mRollo.move();
Jason Sams86c87ed2009-09-18 13:55:55 -0700419
Joe Onoratobcbeab82009-10-01 21:45:43 -0700420 mStartedScrolling = true;
421 mRollo.clearSelectedIcon();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700422 mVelocity.addMovement(ev);
423 mRollo.mState.save();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700424 }
Joe Onoratofb0ca672009-09-14 17:55:46 -0400425 }
426 break;
427 case MotionEvent.ACTION_UP:
428 case MotionEvent.ACTION_CANCEL:
Joe Onoratobcbeab82009-10-01 21:45:43 -0700429 if (mTouchTracking == TRACKING_HOME) {
430 if (action == MotionEvent.ACTION_UP) {
431 if (y > mRollo.mTouchYBorders[mRollo.mTouchYBorders.length-1]) {
Joe Onoratob39e51a2009-10-28 15:47:49 -0400432 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
Joe Onoratobcbeab82009-10-01 21:45:43 -0700433 mLauncher.closeAllApps(true);
434 }
Joe Onoratod63458b2009-10-15 21:19:09 -0700435 mRollo.setHomeSelected(false);
436 mRollo.mState.save();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700437 }
Mike Cleron7d5d7462009-10-20 14:06:00 -0700438 mCurrentIconIndex = -1;
Joe Onorato68ffd102009-10-15 17:59:43 -0700439 } else if (mTouchTracking == TRACKING_FLING) {
Joe Onoratobcbeab82009-10-01 21:45:43 -0700440 mRollo.mState.newTouchDown = 0;
Mike Cleron7d5d7462009-10-20 14:06:00 -0700441 mRollo.mState.newPositionX = ev.getRawY() / getHeight();
Jason Sams476339d2009-09-29 18:14:38 -0700442
Jason Sams12c14a82009-10-06 14:33:15 -0700443 mVelocity.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Jason Sams37e7c2b2009-10-19 12:55:43 -0700444 mRollo.mState.flingVelocity = mVelocity.getYVelocity() / getHeight();
Jason Sams12c14a82009-10-06 14:33:15 -0700445 mRollo.clearSelectedIcon();
446 mRollo.mState.save();
Jason Samsd8152b92009-10-13 17:19:10 -0700447 mRollo.fling();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700448
Joe Onorato539ed9d2009-10-02 10:22:14 -0700449 if (mVelocity != null) {
450 mVelocity.recycle();
451 mVelocity = null;
452 }
Joe Onoratobcbeab82009-10-01 21:45:43 -0700453 }
Joe Onorato68ffd102009-10-15 17:59:43 -0700454 mTouchTracking = TRACKING_NONE;
455 break;
Joe Onorato93839052009-08-06 20:34:32 -0700456 }
Joe Onorato6665c0f2009-09-02 15:27:24 -0700457
458 return true;
Joe Onorato93839052009-08-06 20:34:32 -0700459 }
460
Joe Onorato6665c0f2009-09-02 15:27:24 -0700461 public void onClick(View v) {
Joe Onorato7bb17492009-09-24 17:51:01 -0700462 if (mLocks != 0 || !isVisible()) {
Joe Onoratofb0ca672009-09-14 17:55:46 -0400463 return;
464 }
Joe Onorato82ca5502009-10-15 16:59:23 -0700465 if (mRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
466 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
Joe Onoratob39e51a2009-10-28 15:47:49 -0400467 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
Joe Onorato82ca5502009-10-15 16:59:23 -0700468 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700469 mLauncher.startActivitySafely(app.intent);
470 }
471 }
472
473 public boolean onLongClick(View v) {
Joe Onorato7bb17492009-09-24 17:51:01 -0700474 if (mLocks != 0 || !isVisible()) {
Joe Onoratofb0ca672009-09-14 17:55:46 -0400475 return true;
476 }
Joe Onorato82ca5502009-10-15 16:59:23 -0700477 if (mRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
478 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
479 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onorato5162ea92009-09-03 09:39:42 -0700480
481 // We don't really have an accurate location to use. This will do.
Joe Onoratobcbeab82009-10-01 21:45:43 -0700482 int screenX = mMotionDownRawX - (mDefines.ICON_WIDTH_PX / 2);
483 int screenY = mMotionDownRawY - mDefines.ICON_HEIGHT_PX;
Joe Onorato5162ea92009-09-03 09:39:42 -0700484
Joe Onoratobcbeab82009-10-01 21:45:43 -0700485 int left = (mDefines.ICON_TEXTURE_WIDTH_PX - mDefines.ICON_WIDTH_PX) / 2;
486 int top = (mDefines.ICON_TEXTURE_HEIGHT_PX - mDefines.ICON_HEIGHT_PX) / 2;
Joe Onorato5162ea92009-09-03 09:39:42 -0700487 mDragController.startDrag(app.iconBitmap, screenX, screenY,
Joe Onoratobcbeab82009-10-01 21:45:43 -0700488 left, top, mDefines.ICON_WIDTH_PX, mDefines.ICON_HEIGHT_PX,
Joe Onorato5162ea92009-09-03 09:39:42 -0700489 this, app, DragController.DRAG_ACTION_COPY);
Joe Onoratoe3406a22009-09-03 14:36:25 -0700490
Joe Onorato7bb17492009-09-24 17:51:01 -0700491 mLauncher.closeAllApps(true);
Joe Onorato5162ea92009-09-03 09:39:42 -0700492 }
Joe Onorato6665c0f2009-09-02 15:27:24 -0700493 return true;
494 }
495
Joe Onorato5162ea92009-09-03 09:39:42 -0700496 public void setDragController(DragController dragger) {
497 mDragController = dragger;
498 }
499
500 public void onDropCompleted(View target, boolean success) {
501 }
502
Joe Onorato4db52312009-10-06 11:17:43 -0700503 /**
504 * Zoom to the specifed amount.
505 *
506 * @param amount [0..1] 0 is hidden, 1 is open
Joe Onorato4db52312009-10-06 11:17:43 -0700507 */
Jason Sams12c14a82009-10-06 14:33:15 -0700508 public void zoom(float amount) {
Joe Onorato7bb17492009-09-24 17:51:01 -0700509 if (mRollo == null) {
510 return;
511 }
512
Joe Onoratofb0ca672009-09-14 17:55:46 -0400513 cancelLongPress();
Joe Onoratofb0ca672009-09-14 17:55:46 -0400514 mRollo.clearSelectedIcon();
Joe Onorato1d708e72009-10-15 21:29:21 -0700515 mRollo.setHomeSelected(false);
Joe Onorato85a02a82009-09-08 12:34:22 -0700516 if (amount > 0.001f) {
Joe Onoratoc5acd422009-10-01 14:21:24 -0700517 // set in readback, so we're correct even before the next frame
Jason Sams12c14a82009-10-06 14:33:15 -0700518 mRollo.mState.zoomTarget = amount;
Joe Onorato85a02a82009-09-08 12:34:22 -0700519 } else {
Joe Onorato7bb17492009-09-24 17:51:01 -0700520 mRollo.mState.zoomTarget = 0;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700521 }
Joe Onoratofb0ca672009-09-14 17:55:46 -0400522 mRollo.mState.save();
Joe Onoratofb0ca672009-09-14 17:55:46 -0400523 }
524
525 public boolean isVisible() {
Joe Onorato7bb17492009-09-24 17:51:01 -0700526 if (mRollo == null) {
527 return false;
528 }
Jason Sams12c14a82009-10-06 14:33:15 -0700529 return mRollo.mMessageProc.mZoom > 0.001f;
Joe Onoratofb0ca672009-09-14 17:55:46 -0400530 }
Joe Onoratoc567acb2009-08-31 14:34:43 -0700531
Mike Cleronb6082fa02009-10-19 17:03:36 -0700532 /*
Joe Onorato93839052009-08-06 20:34:32 -0700533 @Override
534 public boolean onTrackballEvent(MotionEvent ev)
535 {
536 float x = ev.getX();
537 float y = ev.getY();
538 //Float tx = new Float(x);
539 //Float ty = new Float(y);
540 //Log.e("rs", "tbe " + tx.toString() + ", " + ty.toString());
541
542
543 return true;
544 }
Mike Cleronb6082fa02009-10-19 17:03:36 -0700545 */
Joe Onorato93839052009-08-06 20:34:32 -0700546
Joe Onorato9c1289c2009-08-17 11:03:03 -0400547 public void setApps(ArrayList<ApplicationInfo> list) {
548 mAllAppsList = list;
549 if (mRollo != null) {
550 mRollo.setApps(list);
551 }
Joe Onoratofb0ca672009-09-14 17:55:46 -0400552 mLocks &= ~LOCK_ICONS_PENDING;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700553 }
554
Joe Onoratoa8138d52009-10-06 19:25:30 -0700555 public void addApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2d804762009-11-05 16:02:32 -0500556 if (mAllAppsList == null) {
557 // Not done loading yet. We'll find out about it later.
558 return;
559 }
560
Joe Onoratoa8138d52009-10-06 19:25:30 -0700561 final int N = list.size();
562 if (mRollo != null) {
563 mRollo.reallocAppsList(mRollo.mState.iconCount + N);
564 }
565
566 for (int i=0; i<N; i++) {
567 final ApplicationInfo item = list.get(i);
568 int index = Collections.binarySearch(mAllAppsList, item, mAppNameComp);
569 if (index < 0) {
570 index = -(index+1);
571 }
Joe Onorato0ace11a2009-11-05 15:41:27 -0500572 Log.d(TAG, "Adding app '" + item + "' at index " + index + " mRollo=" + mRollo);
Joe Onoratoa8138d52009-10-06 19:25:30 -0700573 mAllAppsList.add(index, item);
574 if (mRollo != null) {
575 mRollo.addApp(index, item);
576 mRollo.mState.iconCount++;
577 }
578 }
579
580 if (mRollo != null) {
581 mRollo.saveAppsList();
582 }
Joe Onoratoc567acb2009-08-31 14:34:43 -0700583 }
584
Joe Onoratoa8138d52009-10-06 19:25:30 -0700585 public void removeApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2d804762009-11-05 16:02:32 -0500586 if (mAllAppsList == null) {
587 // Not done loading yet. We'll find out about it later.
588 return;
589 }
590
Joe Onoratoa8138d52009-10-06 19:25:30 -0700591 final int N = list.size();
592 for (int i=0; i<N; i++) {
593 final ApplicationInfo item = list.get(i);
Joe Onoratocb9f7982009-10-31 16:32:02 -0400594 int index = findAppByComponent(mAllAppsList, item);
Joe Onoratoa8138d52009-10-06 19:25:30 -0700595 if (index >= 0) {
596 mAllAppsList.remove(index);
597 if (mRollo != null) {
598 mRollo.removeApp(index);
599 mRollo.mState.iconCount--;
600 }
601 } else {
602 Log.e(TAG, "couldn't find a match for item \"" + item + "\"");
603 // Try to recover. This should keep us from crashing for now.
604 }
605 }
606
607 if (mRollo != null) {
608 mRollo.saveAppsList();
609 }
610 }
611
612 public void updateApps(String packageName, ArrayList<ApplicationInfo> list) {
613 // Just remove and add, because they may need to be re-sorted.
614 removeApps(list);
615 addApps(list);
616 }
617
618 private Comparator<ApplicationInfo> mAppNameComp = new Comparator<ApplicationInfo>() {
619 public int compare(ApplicationInfo a, ApplicationInfo b) {
620 int result = a.title.toString().compareTo(b.toString());
621 if (result != 0) {
622 return result;
623 }
624 return a.intent.getComponent().compareTo(b.intent.getComponent());
625 }
626 };
627
Joe Onoratocb9f7982009-10-31 16:32:02 -0400628 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
629 ComponentName component = item.intent.getComponent();
630 final int N = list.size();
631 for (int i=0; i<N; i++) {
632 ApplicationInfo x = list.get(i);
633 if (x.intent.getComponent().equals(component)) {
634 return i;
635 }
Joe Onoratoa8138d52009-10-06 19:25:30 -0700636 }
Joe Onoratocb9f7982009-10-31 16:32:02 -0400637 return -1;
638 }
Joe Onoratoa8138d52009-10-06 19:25:30 -0700639
Joe Onoratoc567acb2009-08-31 14:34:43 -0700640 private static int countPages(int iconCount) {
641 int iconsPerPage = Defines.COLUMNS_PER_PAGE * Defines.ROWS_PER_PAGE;
642 int pages = iconCount / iconsPerPage;
643 if (pages*iconsPerPage != iconCount) {
644 pages++;
645 }
646 return pages;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400647 }
648
Joe Onorato93839052009-08-06 20:34:32 -0700649 public class RolloRS {
Joe Onoratobf15cb42009-08-07 14:33:40 -0700650
Joe Onorato1feb3a82009-08-08 22:32:00 -0700651 // Allocations ======
Joe Onorato93839052009-08-06 20:34:32 -0700652 private int mWidth;
653 private int mHeight;
654
655 private Resources mRes;
Jason Sams37e7c2b2009-10-19 12:55:43 -0700656 private Script mScript;
657 private Script.Invokable mInvokeMove;
Jason Samsc1c521e2009-10-19 14:45:45 -0700658 private Script.Invokable mInvokeMoveTo;
Jason Sams37e7c2b2009-10-19 12:55:43 -0700659 private Script.Invokable mInvokeFling;
660 private Script.Invokable mInvokeResetWAR;
Jason Sams86c87ed2009-09-18 13:55:55 -0700661
Jason Samsc1c521e2009-10-19 14:45:45 -0700662
Jason Samscd689e12009-09-29 15:28:22 -0700663 private ProgramStore mPSIcons;
Joe Onorato93839052009-08-06 20:34:32 -0700664 private ProgramStore mPSText;
Jason Samscd689e12009-09-29 15:28:22 -0700665 private ProgramFragment mPFColor;
Jason Samsc8514792009-10-29 14:27:29 -0700666 private ProgramFragment mPFTexMip;
667 private ProgramFragment mPFTexNearest;
Joe Onorato93839052009-08-06 20:34:32 -0700668 private ProgramVertex mPV;
Joe Onorato93839052009-08-06 20:34:32 -0700669 private ProgramVertex mPVOrtho;
Jason Sams0aa71662009-10-02 18:43:18 -0700670 private SimpleMesh mMesh;
Jason Samsd8152b92009-10-13 17:19:10 -0700671 private SimpleMesh mMesh2;
Joe Onorato93839052009-08-06 20:34:32 -0700672
Joe Onoratod63458b2009-10-15 21:19:09 -0700673 private Allocation mHomeButtonNormal;
674 private Allocation mHomeButtonPressed;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700675
Joe Onoratobf15cb42009-08-07 14:33:40 -0700676 private Allocation[] mIcons;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700677 private int[] mIconIds;
Joe Onoratoa8138d52009-10-06 19:25:30 -0700678 private Allocation mAllocIconIds;
Joe Onorato93839052009-08-06 20:34:32 -0700679
Joe Onoratobf15cb42009-08-07 14:33:40 -0700680 private Allocation[] mLabels;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700681 private int[] mLabelIds;
Joe Onoratoa8138d52009-10-06 19:25:30 -0700682 private Allocation mAllocLabelIds;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700683 private Allocation mSelectedIcon;
Joe Onorato93839052009-08-06 20:34:32 -0700684
Joe Onorato6665c0f2009-09-02 15:27:24 -0700685 private int[] mTouchYBorders;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700686 private int[] mTouchXBorders;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700687
688 private Bitmap mSelectionBitmap;
Joe Onorato1291a8c2009-09-15 15:07:25 -0400689 private Canvas mSelectionCanvas;
Joe Onorato93839052009-08-06 20:34:32 -0700690
Jason Sams20df7c72009-11-05 12:30:24 -0800691 boolean mHasSurface = false;
692 private boolean mAppsDirty = false;
Jason Samsd8152b92009-10-13 17:19:10 -0700693
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700694 Params mParams;
Joe Onorato1feb3a82009-08-08 22:32:00 -0700695 State mState;
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700696
Jason Sams78aebd82009-09-15 13:06:59 -0700697 class BaseAlloc {
698 Allocation mAlloc;
699 Type mType;
700
701 void save() {
702 mAlloc.data(this);
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700703 }
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700704 }
705
Jason Sams12c14a82009-10-06 14:33:15 -0700706 class AAMessage extends RenderScript.RSMessage {
707 public void run() {
708 mPosX = ((float)mData[0]) / (1 << 16);
709 mVelocity = ((float)mData[1]) / (1 << 16);
710 mZoom = ((float)mData[2]) / (1 << 16);
711 //Log.d("rs", "new msg " + mPosX + " " + mVelocity + " " + mZoom);
712 }
713 float mZoom;
714 float mPosX;
715 float mVelocity;
716 }
717 AAMessage mMessageProc;
718
Jason Sams476339d2009-09-29 18:14:38 -0700719 private boolean checkClickOK() {
720 //android.util.Log.e("rs", "check click " + Float.toString(mReadback.velocity) + ", " + Float.toString(mReadback.posX));
Jason Sams2e19c052009-10-20 18:19:55 -0700721 return (Math.abs(mMessageProc.mVelocity) < 0.4f) &&
722 (Math.abs(mMessageProc.mPosX - Math.round(mMessageProc.mPosX)) < 0.4f);
Jason Sams476339d2009-09-29 18:14:38 -0700723 }
724
Jason Sams78aebd82009-09-15 13:06:59 -0700725 class Params extends BaseAlloc {
726 Params() {
727 mType = Type.createFromClass(mRS, Params.class, 1, "ParamsClass");
728 mAlloc = Allocation.createTyped(mRS, mType);
729 save();
Joe Onorato1feb3a82009-08-08 22:32:00 -0700730 }
Jason Sams78aebd82009-09-15 13:06:59 -0700731 public int bubbleWidth;
732 public int bubbleHeight;
733 public int bubbleBitmapWidth;
734 public int bubbleBitmapHeight;
Joe Onoratobcbeab82009-10-01 21:45:43 -0700735
Joe Onoratobcbeab82009-10-01 21:45:43 -0700736 public int homeButtonWidth;
737 public int homeButtonHeight;
738 public int homeButtonTextureWidth;
739 public int homeButtonTextureHeight;
Jason Sams78aebd82009-09-15 13:06:59 -0700740 }
741
742 class State extends BaseAlloc {
Jason Sams86c87ed2009-09-18 13:55:55 -0700743 public float newPositionX;
744 public int newTouchDown;
Jason Sams37e7c2b2009-10-19 12:55:43 -0700745 public float flingVelocity;
Jason Sams78aebd82009-09-15 13:06:59 -0700746 public int iconCount;
Jason Sams78aebd82009-09-15 13:06:59 -0700747 public int selectedIconIndex = -1;
748 public int selectedIconTexture;
Joe Onorato7bb17492009-09-24 17:51:01 -0700749 public float zoomTarget;
Joe Onoratod63458b2009-10-15 21:19:09 -0700750 public int homeButtonId;
Jason Samsc1c521e2009-10-19 14:45:45 -0700751 public float targetPos;
Jason Sams78aebd82009-09-15 13:06:59 -0700752
753 State() {
754 mType = Type.createFromClass(mRS, State.class, 1, "StateClass");
755 mAlloc = Allocation.createTyped(mRS, mType);
756 save();
757 }
Joe Onorato1feb3a82009-08-08 22:32:00 -0700758 }
759
760 public RolloRS() {
761 }
762
763 public void init(Resources res, int width, int height) {
764 mRes = res;
765 mWidth = width;
766 mHeight = height;
Joe Onoratobcbeab82009-10-01 21:45:43 -0700767 mDefines.recompute(width, height);
Jason Samscd689e12009-09-29 15:28:22 -0700768 initProgramVertex();
769 initProgramFragment();
770 initProgramStore();
Jason Sams0aa71662009-10-02 18:43:18 -0700771 initMesh();
Joe Onorato1feb3a82009-08-08 22:32:00 -0700772 initGl();
773 initData();
Joe Onorato6665c0f2009-09-02 15:27:24 -0700774 initTouchState();
Joe Onorato1feb3a82009-08-08 22:32:00 -0700775 initRs();
776 }
777
Jason Sams0aa71662009-10-02 18:43:18 -0700778 public void initMesh() {
779 SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(mRS, 3,
780 SimpleMesh.TriangleMeshBuilder.TEXTURE_0 | SimpleMesh.TriangleMeshBuilder.COLOR);
781
Jason Samsd8152b92009-10-13 17:19:10 -0700782 float y = 0;
783 float z = 0;
784 for (int ct=0; ct < 200; ct++) {
785 float angle = 0;
786 float maxAngle = 3.14f * 0.16f;
787 float l = 1.f;
788
789 l = 1 - ((ct-5) * 0.10f);
790 if (ct > 7) {
791 angle = maxAngle * (ct - 7) * 0.2f;
792 angle = Math.min(angle, maxAngle);
793 }
Jason Samsc8514792009-10-29 14:27:29 -0700794 l = Math.max(0.4f, l);
Jason Samsd8152b92009-10-13 17:19:10 -0700795 l = Math.min(1.0f, l);
796
797 y += 0.1f * Math.cos(angle);
798 z += 0.1f * Math.sin(angle);
799
800 float t = 0.1f * ct;
801 float ds = 0.08f;
802 tm.setColor(l, l, l, 0.99f);
803 tm.setTexture(ds, t);
804 tm.addVertex(-0.5f, y, z);
805 tm.setTexture(1 - ds, t);
806 tm.addVertex(0.5f, y, z);
807 }
808 for (int ct=0; ct < (200 * 2 - 2); ct+= 2) {
809 tm.addTriangle(ct, ct+1, ct+2);
810 tm.addTriangle(ct+1, ct+3, ct+2);
811 }
812 mMesh2 = tm.create();
Jason Sams37e7c2b2009-10-19 12:55:43 -0700813 mMesh2.setName("SMMesh");
Jason Samsd8152b92009-10-13 17:19:10 -0700814 }
815
Jason Samscd689e12009-09-29 15:28:22 -0700816 private void initProgramVertex() {
817 ProgramVertex.MatrixAllocation pva = new ProgramVertex.MatrixAllocation(mRS);
818 pva.setupProjectionNormalized(mWidth, mHeight);
Joe Onorato93839052009-08-06 20:34:32 -0700819
820 ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null);
Jason Sams0aa71662009-10-02 18:43:18 -0700821 pvb.setTextureMatrixEnable(true);
Joe Onorato93839052009-08-06 20:34:32 -0700822 mPV = pvb.create();
823 mPV.setName("PV");
Jason Samscd689e12009-09-29 15:28:22 -0700824 mPV.bindAllocation(pva);
Joe Onorato93839052009-08-06 20:34:32 -0700825
Jason Sams37e7c2b2009-10-19 12:55:43 -0700826 //pva = new ProgramVertex.MatrixAllocation(mRS);
827 //pva.setupOrthoWindow(mWidth, mHeight);
828 //pvb.setTextureMatrixEnable(true);
829 //mPVOrtho = pvb.create();
830 //mPVOrtho.setName("PVOrtho");
831 //mPVOrtho.bindAllocation(pva);
Joe Onorato93839052009-08-06 20:34:32 -0700832
833 mRS.contextBindProgramVertex(mPV);
Jason Samscd689e12009-09-29 15:28:22 -0700834 }
Joe Onorato93839052009-08-06 20:34:32 -0700835
Jason Samscd689e12009-09-29 15:28:22 -0700836 private void initProgramFragment() {
837 Sampler.Builder sb = new Sampler.Builder(mRS);
Jason Samsc8514792009-10-29 14:27:29 -0700838 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
Jason Samscd689e12009-09-29 15:28:22 -0700839 sb.setMag(Sampler.Value.LINEAR);
840 sb.setWrapS(Sampler.Value.CLAMP);
841 sb.setWrapT(Sampler.Value.CLAMP);
842 Sampler linear = sb.create();
843
844 sb.setMin(Sampler.Value.NEAREST);
845 sb.setMag(Sampler.Value.NEAREST);
846 Sampler nearest = sb.create();
847
848 ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null);
Jason Sams37e7c2b2009-10-19 12:55:43 -0700849 //mPFColor = bf.create();
850 //mPFColor.setName("PFColor");
Jason Samscd689e12009-09-29 15:28:22 -0700851
852 bf.setTexEnable(true, 0);
853 bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0);
Jason Samsc8514792009-10-29 14:27:29 -0700854 mPFTexMip = bf.create();
855 mPFTexMip.setName("PFTexMip");
856 mPFTexMip.bindSampler(linear, 0);
857
858 mPFTexNearest = bf.create();
859 mPFTexNearest.setName("PFTexNearest");
860 mPFTexNearest.bindSampler(nearest, 0);
Jason Samscd689e12009-09-29 15:28:22 -0700861 }
862
863 private void initProgramStore() {
864 ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null);
865 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
Jason Sams12c14a82009-10-06 14:33:15 -0700866 bs.setColorMask(true,true,true,false);
Jason Samscd689e12009-09-29 15:28:22 -0700867 bs.setDitherEnable(true);
868 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
869 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
870 mPSIcons = bs.create();
871 mPSIcons.setName("PSIcons");
872
873 //bs.setDitherEnable(false);
874 //mPSText = bs.create();
875 //mPSText.setName("PSText");
876 }
877
878 private void initGl() {
Joe Onorato6665c0f2009-09-02 15:27:24 -0700879 mTouchXBorders = new int[Defines.COLUMNS_PER_PAGE+1];
Joe Onorato6665c0f2009-09-02 15:27:24 -0700880 mTouchYBorders = new int[Defines.ROWS_PER_PAGE+1];
Joe Onoratobf15cb42009-08-07 14:33:40 -0700881 }
Jason Sams78aebd82009-09-15 13:06:59 -0700882
Joe Onorato1feb3a82009-08-08 22:32:00 -0700883 private void initData() {
Jason Sams78aebd82009-09-15 13:06:59 -0700884 mParams = new Params();
885 mState = new State();
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700886
Joe Onoratobf15cb42009-08-07 14:33:40 -0700887 final Utilities.BubbleText bubble = new Utilities.BubbleText(getContext());
Joe Onorato93839052009-08-06 20:34:32 -0700888
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700889 mParams.bubbleWidth = bubble.getBubbleWidth();
890 mParams.bubbleHeight = bubble.getMaxBubbleHeight();
891 mParams.bubbleBitmapWidth = bubble.getBitmapWidth();
892 mParams.bubbleBitmapHeight = bubble.getBitmapHeight();
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700893
Joe Onoratod63458b2009-10-15 21:19:09 -0700894 mHomeButtonNormal = Allocation.createFromBitmapResource(mRS, mRes,
895 R.drawable.home_button_normal, Element.RGBA_8888(mRS), false);
896 mHomeButtonNormal.uploadToTexture(0);
897 mHomeButtonPressed = Allocation.createFromBitmapResource(mRS, mRes,
898 R.drawable.home_button_pressed, Element.RGBA_8888(mRS), false);
899 mHomeButtonPressed.uploadToTexture(0);
Joe Onoratobcbeab82009-10-01 21:45:43 -0700900 mParams.homeButtonWidth = 76;
901 mParams.homeButtonHeight = 68;
902 mParams.homeButtonTextureWidth = 128;
903 mParams.homeButtonTextureHeight = 128;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700904
Joe Onoratod63458b2009-10-15 21:19:09 -0700905 mState.homeButtonId = mHomeButtonNormal.getID();
906
Joe Onorato1feb3a82009-08-08 22:32:00 -0700907 mParams.save();
908 mState.save();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400909
Joe Onorato1291a8c2009-09-15 15:07:25 -0400910 mSelectionBitmap = Bitmap.createBitmap(Defines.ICON_TEXTURE_WIDTH_PX,
911 Defines.ICON_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
912 mSelectionCanvas = new Canvas(mSelectionBitmap);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700913
Joe Onorato9c1289c2009-08-17 11:03:03 -0400914 setApps(null);
Joe Onorato93839052009-08-06 20:34:32 -0700915 }
916
Jason Sams37e7c2b2009-10-19 12:55:43 -0700917 private void initScript(int id) {
918 }
919
920 private void initRs() {
Joe Onorato93839052009-08-06 20:34:32 -0700921 ScriptC.Builder sb = new ScriptC.Builder(mRS);
Jason Sams37e7c2b2009-10-19 12:55:43 -0700922 sb.setScript(mRes, R.raw.rollo3);
Joe Onorato93839052009-08-06 20:34:32 -0700923 sb.setRoot(true);
Joe Onoratobcbeab82009-10-01 21:45:43 -0700924 sb.addDefines(mDefines);
Jason Sams78aebd82009-09-15 13:06:59 -0700925 sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS);
926 sb.setType(mState.mType, "state", Defines.ALLOC_STATE);
Jason Sams37e7c2b2009-10-19 12:55:43 -0700927 mInvokeMove = sb.addInvokable("move");
928 mInvokeFling = sb.addInvokable("fling");
Jason Samsc1c521e2009-10-19 14:45:45 -0700929 mInvokeMoveTo = sb.addInvokable("moveTo");
Jason Sams37e7c2b2009-10-19 12:55:43 -0700930 mInvokeResetWAR = sb.addInvokable("resetHWWar");
931 mScript = sb.create();
932 mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
933 mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
934 mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
935 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
936 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
Joe Onorato93839052009-08-06 20:34:32 -0700937
Jason Sams12c14a82009-10-06 14:33:15 -0700938 mMessageProc = new AAMessage();
939 mRS.mMessageCallback = mMessageProc;
Jason Sams37e7c2b2009-10-19 12:55:43 -0700940 mRS.contextBindRootScript(mScript);
Joe Onorato93839052009-08-06 20:34:32 -0700941 }
Joe Onorato93839052009-08-06 20:34:32 -0700942
Jason Sams20df7c72009-11-05 12:30:24 -0800943 private void uploadApps(ArrayList<ApplicationInfo> list) {
944 for (int i=0; i < mState.iconCount; i++) {
945 uploadAppIcon(i, list.get(i));
946 }
947 }
948
949 void dirtyCheck() {
950 if (mAppsDirty && mHasSurface) {
951 uploadApps(mAllAppsList);
952 saveAppsList();
953 mAppsDirty = false;
954 }
955 }
956
Joe Onorato9c1289c2009-08-17 11:03:03 -0400957 private void setApps(ArrayList<ApplicationInfo> list) {
958 final int count = list != null ? list.size() : 0;
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700959 int allocCount = count;
Joe Onoratoa8138d52009-10-06 19:25:30 -0700960 if (allocCount < 1) {
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700961 allocCount = 1;
962 }
963
Joe Onorato9c1289c2009-08-17 11:03:03 -0400964 mIcons = new Allocation[count];
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700965 mIconIds = new int[allocCount];
Joe Onoratoa8138d52009-10-06 19:25:30 -0700966 mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400967
968 mLabels = new Allocation[count];
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700969 mLabelIds = new int[allocCount];
Joe Onoratoa8138d52009-10-06 19:25:30 -0700970 mAllocLabelIds = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400971
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700972 Element ie8888 = Element.RGBA_8888(mRS);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400973
974 Utilities.BubbleText bubble = new Utilities.BubbleText(getContext());
975
Joe Onorato9c1289c2009-08-17 11:03:03 -0400976 mState.iconCount = count;
Jason Sams20df7c72009-11-05 12:30:24 -0800977 uploadApps(list);
Joe Onoratoa8138d52009-10-06 19:25:30 -0700978 saveAppsList();
979 }
980
Jason Samsc8514792009-10-29 14:27:29 -0700981 private void frameBitmapAllocMips(Allocation alloc, int w, int h) {
982 int black[] = new int[w > h ? w : h];
983 Allocation.Adapter2D a = alloc.createAdapter2D();
984 int mip = 0;
985 while (w > 1 || h > 1) {
986 a.subData(0, 0, 1, h, black);
987 a.subData(w-1, 0, 1, h, black);
988 a.subData(0, 0, w, 1, black);
989 a.subData(0, h-1, w, 1, black);
990 mip++;
991 w = (w + 1) >> 1;
992 h = (h + 1) >> 1;
993 a.setConstraint(Dimension.LOD, mip);
994 }
995 a.subData(0, 0, 1, 1, black);
996 }
997
Joe Onoratoa8138d52009-10-06 19:25:30 -0700998 private void uploadAppIcon(int index, ApplicationInfo item) {
999 mIcons[index] = Allocation.createFromBitmap(mRS, item.iconBitmap,
Jason Samsc8514792009-10-29 14:27:29 -07001000 Element.RGBA_8888(mRS), true);
1001 frameBitmapAllocMips(mIcons[index], item.iconBitmap.getWidth(), item.iconBitmap.getHeight());
1002
Joe Onoratoa8138d52009-10-06 19:25:30 -07001003 mLabels[index] = Allocation.createFromBitmap(mRS, item.titleBitmap,
Jason Samsc8514792009-10-29 14:27:29 -07001004 Element.RGBA_8888(mRS), true);
1005 frameBitmapAllocMips(mLabels[index], item.titleBitmap.getWidth(), item.titleBitmap.getHeight());
Joe Onoratoa8138d52009-10-06 19:25:30 -07001006
1007 mIcons[index].uploadToTexture(0);
1008 mLabels[index].uploadToTexture(0);
1009
1010 mIconIds[index] = mIcons[index].getID();
1011 mLabelIds[index] = mLabels[index].getID();
1012 }
1013
1014 /**
1015 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1016 * fill in the values and call saveAppsList().
1017 */
1018 private void reallocAppsList(int count) {
1019 Allocation[] icons = new Allocation[count];
1020 int[] iconIds = new int[count];
1021 mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), count);
1022
1023 Allocation[] labels = new Allocation[count];
1024 int[] labelIds = new int[count];
1025 mAllocLabelIds = Allocation.createSized(mRS, Element.USER_I32(mRS), count);
1026
1027 final int oldCount = mIcons.length;
1028
1029 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1030 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1031 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1032 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
1033
1034 mIcons = icons;
1035 mIconIds = iconIds;
1036 mLabels = labels;
1037 mLabelIds = labelIds;
1038 }
1039
1040 /**
1041 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1042 */
1043 private void addApp(int index, ApplicationInfo item) {
1044 final int count = mState.iconCount - index;
1045 final int dest = index + 1;
1046
1047 System.arraycopy(mIcons, index, mIcons, dest, count);
1048 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1049 System.arraycopy(mLabels, index, mLabels, dest, count);
1050 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
1051
Jason Sams20df7c72009-11-05 12:30:24 -08001052 if (mHasSurface ) {
1053 uploadAppIcon(index, item);
1054 } else {
1055 mAppsDirty = true;
1056 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07001057 }
1058
1059 /**
1060 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1061 */
1062 private void removeApp(int index) {
1063 final int count = mState.iconCount - index - 1;
1064 final int src = index + 1;
1065
1066 System.arraycopy(mIcons, src, mIcons, index, count);
1067 System.arraycopy(mIconIds, src, mIconIds, index, count);
1068 System.arraycopy(mLabels, src, mLabels, index, count);
1069 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
1070
1071 final int last = mState.iconCount - 1;
1072 mIcons[last] = null;
1073 mIconIds[last] = 0;
1074 mLabels[last] = null;
1075 mLabelIds[last] = 0;
1076 }
1077
1078 /**
1079 * Send the apps list structures to RS.
1080 */
1081 private void saveAppsList() {
1082 mRS.contextBindRootScript(null);
Jason Samsd8152b92009-10-13 17:19:10 -07001083
Joe Onoratoa8138d52009-10-06 19:25:30 -07001084 mAllocIconIds.data(mIconIds);
1085 mAllocLabelIds.data(mLabelIds);
1086
Jason Sams37e7c2b2009-10-19 12:55:43 -07001087 if (mScript != null) { // this happens when we init it
1088 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1089 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001090 }
1091
1092 mState.save();
Joe Onoratoa8138d52009-10-06 19:25:30 -07001093
1094 // Note: mScript may be null if we haven't initialized it yet.
1095 // In that case, this is a no-op.
Jason Sams37e7c2b2009-10-19 12:55:43 -07001096 if (mInvokeResetWAR != null) {
1097 mInvokeResetWAR.execute();
Jason Sams41b61c82009-10-15 15:40:54 -07001098 }
Jason Sams37e7c2b2009-10-19 12:55:43 -07001099 mRS.contextBindRootScript(mScript);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001100 }
Joe Onorato6665c0f2009-09-02 15:27:24 -07001101
1102 void initTouchState() {
1103 int width = getWidth();
1104 int height = getHeight();
Jason Sams37e7c2b2009-10-19 12:55:43 -07001105 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE;
1106 int cellWidth = width / Defines.COLUMNS_PER_PAGE;
Joe Onorato6665c0f2009-09-02 15:27:24 -07001107
Jason Sams37e7c2b2009-10-19 12:55:43 -07001108 int centerY = (height / 2);
1109 mTouchYBorders[0] = centerY - (cellHeight * 2);
1110 mTouchYBorders[1] = centerY - cellHeight;
Joe Onorato6665c0f2009-09-02 15:27:24 -07001111 mTouchYBorders[2] = centerY;
Jason Sams37e7c2b2009-10-19 12:55:43 -07001112 mTouchYBorders[3] = centerY + cellHeight;
1113 mTouchYBorders[4] = centerY + (cellHeight * 2);
Jason Sams78aebd82009-09-15 13:06:59 -07001114
Joe Onorato6665c0f2009-09-02 15:27:24 -07001115 int centerX = (width / 2);
Jason Sams37e7c2b2009-10-19 12:55:43 -07001116 mTouchXBorders[0] = 0;
1117 mTouchXBorders[1] = centerX - (width / 4);
Joe Onorato6665c0f2009-09-02 15:27:24 -07001118 mTouchXBorders[2] = centerX;
Jason Sams37e7c2b2009-10-19 12:55:43 -07001119 mTouchXBorders[3] = centerX + (width / 4);
1120 mTouchXBorders[4] = width;
Joe Onorato6665c0f2009-09-02 15:27:24 -07001121 }
1122
Joe Onorato664457d2009-10-28 16:30:34 -04001123 void fling() {
1124 mInvokeFling.execute();
1125 }
1126
1127 void move() {
1128 mInvokeMove.execute();
1129 }
1130
1131 void moveTo(float row) {
1132 mState.targetPos = row;
1133 mState.save();
1134 mInvokeMoveTo.execute();
1135 }
1136
Jason Sams37e7c2b2009-10-19 12:55:43 -07001137 int chooseTappedIcon(int x, int y, float pos) {
1138 // Adjust for scroll position if not zero.
1139 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
Jason Sams86c87ed2009-09-18 13:55:55 -07001140
Joe Onorato6665c0f2009-09-02 15:27:24 -07001141 int col = -1;
1142 int row = -1;
Joe Onorato6665c0f2009-09-02 15:27:24 -07001143 for (int i=0; i<Defines.COLUMNS_PER_PAGE; i++) {
1144 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
1145 col = i;
1146 break;
1147 }
1148 }
1149 for (int i=0; i<Defines.ROWS_PER_PAGE; i++) {
1150 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
1151 row = i;
1152 break;
1153 }
1154 }
1155
1156 if (row < 0 || col < 0) {
1157 return -1;
1158 }
1159
Joe Onorato664457d2009-10-28 16:30:34 -04001160 int index = (((int)pos) * Defines.COLUMNS_PER_PAGE)
Joe Onorato6665c0f2009-09-02 15:27:24 -07001161 + (row * Defines.ROWS_PER_PAGE) + col;
Joe Onorato6665c0f2009-09-02 15:27:24 -07001162
Joe Onorato664457d2009-10-28 16:30:34 -04001163 if (index >= mState.iconCount) {
1164 return -1;
1165 } else {
1166 return index;
1167 }
Jason Samsc1c521e2009-10-19 14:45:45 -07001168 }
1169
Joe Onorato6665c0f2009-09-02 15:27:24 -07001170 /**
1171 * You need to call save() on mState on your own after calling this.
Joe Onorato82ca5502009-10-15 16:59:23 -07001172 *
1173 * @return the index of the icon that was selected.
Joe Onorato6665c0f2009-09-02 15:27:24 -07001174 */
Joe Onoratoc61cff92009-11-08 11:54:39 -05001175 int selectIcon(int x, int y, float pos, boolean selected) {
Joe Onorato82ca5502009-10-15 16:59:23 -07001176 final int index = chooseTappedIcon(x, y, pos);
Joe Onoratoc61cff92009-11-08 11:54:39 -05001177 selectIcon(index, selected);
Joe Onorato82ca5502009-10-15 16:59:23 -07001178 return index;
Joe Onorato1291a8c2009-09-15 15:07:25 -04001179 }
1180
Joe Onoratoc61cff92009-11-08 11:54:39 -05001181 /**
1182 * Select the icon at the given index.
1183 *
1184 * @param index The index.
1185 * @param selected True if selected, false if just focused (they get different colors).
1186 */
1187 void selectIcon(int index, boolean selected) {
Joe Onorato2d804762009-11-05 16:02:32 -05001188 if (mAllAppsList == null || index < 0 || index >= mAllAppsList.size()) {
Joe Onorato6665c0f2009-09-02 15:27:24 -07001189 mState.selectedIconIndex = -1;
Joe Onorato6665c0f2009-09-02 15:27:24 -07001190 } else {
1191 mState.selectedIconIndex = index;
Joe Onorato1291a8c2009-09-15 15:07:25 -04001192
1193 Bitmap selectionBitmap = mSelectionBitmap;
1194
1195 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
Joe Onoratoc61cff92009-11-08 11:54:39 -05001196 selectionBitmap.getWidth(), selectionBitmap.getHeight(), selected,
Joe Onorato1291a8c2009-09-15 15:07:25 -04001197 mAllAppsList.get(index).iconBitmap);
1198
1199 mSelectedIcon = Allocation.createFromBitmap(mRS, selectionBitmap,
Jason Sams0a8dc2c2009-09-27 17:51:44 -07001200 Element.RGBA_8888(mRS), false);
Joe Onorato1291a8c2009-09-15 15:07:25 -04001201 mSelectedIcon.uploadToTexture(0);
1202 mState.selectedIconTexture = mSelectedIcon.getID();
Joe Onorato6665c0f2009-09-02 15:27:24 -07001203 }
1204 }
1205
1206 /**
1207 * You need to call save() on mState on your own after calling this.
1208 */
1209 void clearSelectedIcon() {
Joe Onorato2ca51dc2009-09-16 11:44:14 -04001210 mState.selectedIconIndex = -1;
Joe Onorato6665c0f2009-09-02 15:27:24 -07001211 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07001212
Joe Onoratod63458b2009-10-15 21:19:09 -07001213 void setHomeSelected(boolean pressed) {
1214 if (pressed) {
1215 mState.homeButtonId = mHomeButtonPressed.getID();
1216 } else {
1217 mState.homeButtonId = mHomeButtonNormal.getID();
1218 }
1219 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001220 }
Joe Onorato93839052009-08-06 20:34:32 -07001221}
1222
1223