blob: 37eb21636b5bd49c65ff2f6619e4085efcb309be [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
216 mRollo.selectIcon(selection);
217 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;
235 mRollo.selectIcon(Math.round(mRollo.mMessageProc.mPosX) * Defines.COLUMNS_PER_PAGE);
236 mRollo.mState.save();
237 }
238 } else {
239 if (mArrowNavigation) {
240 // Clear selection when we lose focus
241 mRollo.clearSelectedIcon();
242 mRollo.mState.save();
243 mArrowNavigation = false;
244 }
245 }
246 }
247
248 @Override
249 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Sams2e19c052009-10-20 18:19:55 -0700250
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800251 boolean handled = false;
252
Joe Onorato859b3a72009-10-28 15:17:01 -0400253 if (!isVisible()) {
254 return false;
255 }
Joe Onoratoa13f5742009-11-02 17:15:19 -0500256 final int iconCount = mRollo.mState.iconCount;
257
Mike Cleron7d5d7462009-10-20 14:06:00 -0700258 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
259 if (mArrowNavigation) {
260 int whichApp = mRollo.mState.selectedIconIndex;
261 if (whichApp >= 0) {
262 ApplicationInfo app = mAllAppsList.get(whichApp);
263 mLauncher.startActivitySafely(app.intent);
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800264 handled = true;
Mike Cleron7d5d7462009-10-20 14:06:00 -0700265 }
266 }
267 }
Jason Sams2e19c052009-10-20 18:19:55 -0700268
Joe Onoratoa13f5742009-11-02 17:15:19 -0500269 if (mArrowNavigation && iconCount > 0) {
Mike Cleron7d5d7462009-10-20 14:06:00 -0700270 mArrowNavigation = true;
Jason Sams2e19c052009-10-20 18:19:55 -0700271
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800272 int currentSelection = mRollo.mState.selectedIconIndex;
273 int currentTopRow = Math.round(mRollo.mMessageProc.mPosX);
Jason Sams2e19c052009-10-20 18:19:55 -0700274
Mike Cleron7d5d7462009-10-20 14:06:00 -0700275 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE-1
Joe Onoratoa13f5742009-11-02 17:15:19 -0500276 final int currentPageCol = currentSelection % Defines.COLUMNS_PER_PAGE;
Jason Sams2e19c052009-10-20 18:19:55 -0700277
Mike Cleron7d5d7462009-10-20 14:06:00 -0700278 // The row of the current selection, in the range 0..ROWS_PER_PAGE-1
Joe Onoratoa13f5742009-11-02 17:15:19 -0500279 final int currentPageRow = (currentSelection - (currentTopRow*Defines.COLUMNS_PER_PAGE))
Mike Cleron7d5d7462009-10-20 14:06:00 -0700280 / Defines.ROWS_PER_PAGE;
Jason Sams2e19c052009-10-20 18:19:55 -0700281
Mike Cleron7d5d7462009-10-20 14:06:00 -0700282 int newSelection = currentSelection;
283
284 switch (keyCode) {
285 case KeyEvent.KEYCODE_DPAD_UP:
286 if (currentPageRow > 0) {
287 newSelection = currentSelection - Defines.COLUMNS_PER_PAGE;
288 } else if (currentTopRow > 0) {
Jason Sams2e19c052009-10-20 18:19:55 -0700289 newSelection = currentSelection - Defines.COLUMNS_PER_PAGE;
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800290 mRollo.moveTo(newSelection / Defines.COLUMNS_PER_PAGE);
Mike Cleron7d5d7462009-10-20 14:06:00 -0700291 }
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800292 handled = true;
Mike Cleron7d5d7462009-10-20 14:06:00 -0700293 break;
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800294
Joe Onoratoa13f5742009-11-02 17:15:19 -0500295 case KeyEvent.KEYCODE_DPAD_DOWN: {
296 final int rowCount = iconCount / Defines.COLUMNS_PER_PAGE
297 + (iconCount % Defines.COLUMNS_PER_PAGE == 0 ? 0 : 1);
298 final int currentRow = currentSelection / Defines.COLUMNS_PER_PAGE;
299 if (currentRow < rowCount-1) {
300 newSelection = currentSelection + Defines.COLUMNS_PER_PAGE;
301 if (newSelection >= iconCount) {
302 // Go from D to G in this arrangement:
303 // A B C D
304 // E F G
305 newSelection = iconCount - 1;
306 }
307 if (currentPageRow >= Defines.ROWS_PER_PAGE - 1) {
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800308 mRollo.moveTo((newSelection / Defines.COLUMNS_PER_PAGE) -
309 Defines.ROWS_PER_PAGE + 1);
Mike Cleron7d5d7462009-10-20 14:06:00 -0700310 }
311 }
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800312 handled = true;
Mike Cleron7d5d7462009-10-20 14:06:00 -0700313 break;
Joe Onoratoa13f5742009-11-02 17:15:19 -0500314 }
Mike Cleron7d5d7462009-10-20 14:06:00 -0700315 case KeyEvent.KEYCODE_DPAD_LEFT:
316 if (currentPageCol > 0) {
317 newSelection = currentSelection - 1;
318 }
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800319 handled = true;
Mike Cleron7d5d7462009-10-20 14:06:00 -0700320 break;
321 case KeyEvent.KEYCODE_DPAD_RIGHT:
Jason Sams2e19c052009-10-20 18:19:55 -0700322 if ((currentPageCol < Defines.COLUMNS_PER_PAGE - 1) &&
Joe Onoratoa13f5742009-11-02 17:15:19 -0500323 (currentSelection < iconCount - 1)) {
Mike Cleron7d5d7462009-10-20 14:06:00 -0700324 newSelection = currentSelection + 1;
325 }
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800326 handled = true;
Mike Cleron7d5d7462009-10-20 14:06:00 -0700327 break;
328 }
329 if (newSelection != currentSelection) {
330 mRollo.selectIcon(newSelection);
331 mRollo.mState.save();
332 }
333 }
Mike Cleron4a5c1e12009-11-03 10:17:05 -0800334 return handled;
Joe Onorato93839052009-08-06 20:34:32 -0700335 }
336
Joe Onorato93839052009-08-06 20:34:32 -0700337 @Override
338 public boolean onTouchEvent(MotionEvent ev)
339 {
Mike Cleron7d5d7462009-10-20 14:06:00 -0700340 mArrowNavigation = false;
Jason Sams2e19c052009-10-20 18:19:55 -0700341
Joe Onorato7bb17492009-09-24 17:51:01 -0700342 if (!isVisible()) {
Joe Onorato85a02a82009-09-08 12:34:22 -0700343 return true;
Joe Onoratoe3406a22009-09-03 14:36:25 -0700344 }
345
Joe Onoratofb0ca672009-09-14 17:55:46 -0400346 if (mLocks != 0) {
Joe Onorato85a02a82009-09-08 12:34:22 -0700347 return true;
348 }
349
350 super.onTouchEvent(ev);
351
Joe Onoratofb0ca672009-09-14 17:55:46 -0400352 int x = (int)ev.getX();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700353 int y = (int)ev.getY();
354
Joe Onoratobcbeab82009-10-01 21:45:43 -0700355 int action = ev.getAction();
356 switch (action) {
Joe Onoratofb0ca672009-09-14 17:55:46 -0400357 case MotionEvent.ACTION_DOWN:
Joe Onoratobcbeab82009-10-01 21:45:43 -0700358 if (y > mRollo.mTouchYBorders[mRollo.mTouchYBorders.length-1]) {
359 mTouchTracking = TRACKING_HOME;
Joe Onoratod63458b2009-10-15 21:19:09 -0700360 mRollo.setHomeSelected(true);
361 mRollo.mState.save();
Mike Cleron7d5d7462009-10-20 14:06:00 -0700362 mCurrentIconIndex = -1;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700363 } else {
Joe Onoratobcbeab82009-10-01 21:45:43 -0700364 mTouchTracking = TRACKING_FLING;
365
366 mMotionDownRawX = (int)ev.getRawX();
367 mMotionDownRawY = (int)ev.getRawY();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700368
Mike Cleron7d5d7462009-10-20 14:06:00 -0700369 mRollo.mState.newPositionX = ev.getRawY() / getHeight();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700370 mRollo.mState.newTouchDown = 1;
371
372 if (!mRollo.checkClickOK()) {
373 mRollo.clearSelectedIcon();
374 } else {
Joe Onorato82ca5502009-10-15 16:59:23 -0700375 mDownIconIndex = mCurrentIconIndex
376 = mRollo.selectIcon(x, y, mRollo.mMessageProc.mPosX);
377 if (mDownIconIndex < 0) {
378 // if nothing was selected, no long press.
379 cancelLongPress();
380 }
Joe Onoratobcbeab82009-10-01 21:45:43 -0700381 }
382 mRollo.mState.save();
Jason Samsd8152b92009-10-13 17:19:10 -0700383 mRollo.move();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700384 mVelocity = VelocityTracker.obtain();
385 mVelocity.addMovement(ev);
386 mStartedScrolling = false;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700387 }
Joe Onoratofb0ca672009-09-14 17:55:46 -0400388 break;
389 case MotionEvent.ACTION_MOVE:
390 case MotionEvent.ACTION_OUTSIDE:
Joe Onoratobcbeab82009-10-01 21:45:43 -0700391 if (mTouchTracking == TRACKING_HOME) {
Joe Onoratod63458b2009-10-15 21:19:09 -0700392 mRollo.setHomeSelected(y > mRollo.mTouchYBorders[mRollo.mTouchYBorders.length-1]);
393 mRollo.mState.save();
Joe Onorato68ffd102009-10-15 17:59:43 -0700394 } else if (mTouchTracking == TRACKING_FLING) {
Joe Onorato82ca5502009-10-15 16:59:23 -0700395 int rawX = (int)ev.getRawX();
396 int rawY = (int)ev.getRawY();
397 int slop;
Jason Sams37e7c2b2009-10-19 12:55:43 -0700398 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsd8152b92009-10-13 17:19:10 -0700399
Joe Onorato82ca5502009-10-15 16:59:23 -0700400 if (!mStartedScrolling && slop < mSlop) {
401 // don't update anything so when we do start scrolling
Joe Onoratobcbeab82009-10-01 21:45:43 -0700402 // below, we get the right delta.
Joe Onorato82ca5502009-10-15 16:59:23 -0700403 mCurrentIconIndex = mRollo.chooseTappedIcon(x, y, mRollo.mMessageProc.mPosX);
404 if (mDownIconIndex != mCurrentIconIndex) {
405 // If a different icon is selected, don't allow it to be picked up.
406 // This handles off-axis dragging.
407 cancelLongPress();
408 mCurrentIconIndex = -1;
409 }
Joe Onoratobcbeab82009-10-01 21:45:43 -0700410 } else {
Joe Onorato82ca5502009-10-15 16:59:23 -0700411 if (!mStartedScrolling) {
412 cancelLongPress();
413 mCurrentIconIndex = -1;
414 }
Mike Cleron7d5d7462009-10-20 14:06:00 -0700415 mRollo.mState.newPositionX = ev.getRawY() / getHeight();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700416 mRollo.mState.newTouchDown = 1;
Jason Samsd8152b92009-10-13 17:19:10 -0700417 mRollo.move();
Jason Sams86c87ed2009-09-18 13:55:55 -0700418
Joe Onoratobcbeab82009-10-01 21:45:43 -0700419 mStartedScrolling = true;
420 mRollo.clearSelectedIcon();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700421 mVelocity.addMovement(ev);
422 mRollo.mState.save();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700423 }
Joe Onoratofb0ca672009-09-14 17:55:46 -0400424 }
425 break;
426 case MotionEvent.ACTION_UP:
427 case MotionEvent.ACTION_CANCEL:
Joe Onoratobcbeab82009-10-01 21:45:43 -0700428 if (mTouchTracking == TRACKING_HOME) {
429 if (action == MotionEvent.ACTION_UP) {
430 if (y > mRollo.mTouchYBorders[mRollo.mTouchYBorders.length-1]) {
Joe Onoratob39e51a2009-10-28 15:47:49 -0400431 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
Joe Onoratobcbeab82009-10-01 21:45:43 -0700432 mLauncher.closeAllApps(true);
433 }
Joe Onoratod63458b2009-10-15 21:19:09 -0700434 mRollo.setHomeSelected(false);
435 mRollo.mState.save();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700436 }
Mike Cleron7d5d7462009-10-20 14:06:00 -0700437 mCurrentIconIndex = -1;
Joe Onorato68ffd102009-10-15 17:59:43 -0700438 } else if (mTouchTracking == TRACKING_FLING) {
Joe Onoratobcbeab82009-10-01 21:45:43 -0700439 mRollo.mState.newTouchDown = 0;
Mike Cleron7d5d7462009-10-20 14:06:00 -0700440 mRollo.mState.newPositionX = ev.getRawY() / getHeight();
Jason Sams476339d2009-09-29 18:14:38 -0700441
Jason Sams12c14a82009-10-06 14:33:15 -0700442 mVelocity.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Jason Sams37e7c2b2009-10-19 12:55:43 -0700443 mRollo.mState.flingVelocity = mVelocity.getYVelocity() / getHeight();
Jason Sams12c14a82009-10-06 14:33:15 -0700444 mRollo.clearSelectedIcon();
445 mRollo.mState.save();
Jason Samsd8152b92009-10-13 17:19:10 -0700446 mRollo.fling();
Joe Onoratobcbeab82009-10-01 21:45:43 -0700447
Joe Onorato539ed9d2009-10-02 10:22:14 -0700448 if (mVelocity != null) {
449 mVelocity.recycle();
450 mVelocity = null;
451 }
Joe Onoratobcbeab82009-10-01 21:45:43 -0700452 }
Joe Onorato68ffd102009-10-15 17:59:43 -0700453 mTouchTracking = TRACKING_NONE;
454 break;
Joe Onorato93839052009-08-06 20:34:32 -0700455 }
Joe Onorato6665c0f2009-09-02 15:27:24 -0700456
457 return true;
Joe Onorato93839052009-08-06 20:34:32 -0700458 }
459
Joe Onorato6665c0f2009-09-02 15:27:24 -0700460 public void onClick(View v) {
Joe Onorato7bb17492009-09-24 17:51:01 -0700461 if (mLocks != 0 || !isVisible()) {
Joe Onoratofb0ca672009-09-14 17:55:46 -0400462 return;
463 }
Joe Onorato82ca5502009-10-15 16:59:23 -0700464 if (mRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
465 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
Joe Onoratob39e51a2009-10-28 15:47:49 -0400466 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
Joe Onorato82ca5502009-10-15 16:59:23 -0700467 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700468 mLauncher.startActivitySafely(app.intent);
469 }
470 }
471
472 public boolean onLongClick(View v) {
Joe Onorato7bb17492009-09-24 17:51:01 -0700473 if (mLocks != 0 || !isVisible()) {
Joe Onoratofb0ca672009-09-14 17:55:46 -0400474 return true;
475 }
Joe Onorato82ca5502009-10-15 16:59:23 -0700476 if (mRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
477 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
478 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onorato5162ea92009-09-03 09:39:42 -0700479
480 // We don't really have an accurate location to use. This will do.
Joe Onoratobcbeab82009-10-01 21:45:43 -0700481 int screenX = mMotionDownRawX - (mDefines.ICON_WIDTH_PX / 2);
482 int screenY = mMotionDownRawY - mDefines.ICON_HEIGHT_PX;
Joe Onorato5162ea92009-09-03 09:39:42 -0700483
Joe Onoratobcbeab82009-10-01 21:45:43 -0700484 int left = (mDefines.ICON_TEXTURE_WIDTH_PX - mDefines.ICON_WIDTH_PX) / 2;
485 int top = (mDefines.ICON_TEXTURE_HEIGHT_PX - mDefines.ICON_HEIGHT_PX) / 2;
Joe Onorato5162ea92009-09-03 09:39:42 -0700486 mDragController.startDrag(app.iconBitmap, screenX, screenY,
Joe Onoratobcbeab82009-10-01 21:45:43 -0700487 left, top, mDefines.ICON_WIDTH_PX, mDefines.ICON_HEIGHT_PX,
Joe Onorato5162ea92009-09-03 09:39:42 -0700488 this, app, DragController.DRAG_ACTION_COPY);
Joe Onoratoe3406a22009-09-03 14:36:25 -0700489
Joe Onorato7bb17492009-09-24 17:51:01 -0700490 mLauncher.closeAllApps(true);
Joe Onorato5162ea92009-09-03 09:39:42 -0700491 }
Joe Onorato6665c0f2009-09-02 15:27:24 -0700492 return true;
493 }
494
Joe Onorato5162ea92009-09-03 09:39:42 -0700495 public void setDragController(DragController dragger) {
496 mDragController = dragger;
497 }
498
499 public void onDropCompleted(View target, boolean success) {
500 }
501
Joe Onorato4db52312009-10-06 11:17:43 -0700502 /**
503 * Zoom to the specifed amount.
504 *
505 * @param amount [0..1] 0 is hidden, 1 is open
Joe Onorato4db52312009-10-06 11:17:43 -0700506 */
Jason Sams12c14a82009-10-06 14:33:15 -0700507 public void zoom(float amount) {
Joe Onorato7bb17492009-09-24 17:51:01 -0700508 if (mRollo == null) {
509 return;
510 }
511
Joe Onoratofb0ca672009-09-14 17:55:46 -0400512 cancelLongPress();
Joe Onoratofb0ca672009-09-14 17:55:46 -0400513 mRollo.clearSelectedIcon();
Joe Onorato1d708e72009-10-15 21:29:21 -0700514 mRollo.setHomeSelected(false);
Joe Onorato85a02a82009-09-08 12:34:22 -0700515 if (amount > 0.001f) {
Joe Onoratoc5acd422009-10-01 14:21:24 -0700516 // set in readback, so we're correct even before the next frame
Jason Sams12c14a82009-10-06 14:33:15 -0700517 mRollo.mState.zoomTarget = amount;
Joe Onorato85a02a82009-09-08 12:34:22 -0700518 } else {
Joe Onorato7bb17492009-09-24 17:51:01 -0700519 mRollo.mState.zoomTarget = 0;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700520 }
Joe Onoratofb0ca672009-09-14 17:55:46 -0400521 mRollo.mState.save();
Joe Onoratofb0ca672009-09-14 17:55:46 -0400522 }
523
524 public boolean isVisible() {
Joe Onorato7bb17492009-09-24 17:51:01 -0700525 if (mRollo == null) {
526 return false;
527 }
Jason Sams12c14a82009-10-06 14:33:15 -0700528 return mRollo.mMessageProc.mZoom > 0.001f;
Joe Onoratofb0ca672009-09-14 17:55:46 -0400529 }
Joe Onoratoc567acb2009-08-31 14:34:43 -0700530
Mike Cleronb6082fa02009-10-19 17:03:36 -0700531 /*
Joe Onorato93839052009-08-06 20:34:32 -0700532 @Override
533 public boolean onTrackballEvent(MotionEvent ev)
534 {
535 float x = ev.getX();
536 float y = ev.getY();
537 //Float tx = new Float(x);
538 //Float ty = new Float(y);
539 //Log.e("rs", "tbe " + tx.toString() + ", " + ty.toString());
540
541
542 return true;
543 }
Mike Cleronb6082fa02009-10-19 17:03:36 -0700544 */
Joe Onorato93839052009-08-06 20:34:32 -0700545
Joe Onorato9c1289c2009-08-17 11:03:03 -0400546 public void setApps(ArrayList<ApplicationInfo> list) {
547 mAllAppsList = list;
548 if (mRollo != null) {
549 mRollo.setApps(list);
550 }
Joe Onoratofb0ca672009-09-14 17:55:46 -0400551 mLocks &= ~LOCK_ICONS_PENDING;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700552 }
553
Joe Onoratoa8138d52009-10-06 19:25:30 -0700554 public void addApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2d804762009-11-05 16:02:32 -0500555 if (mAllAppsList == null) {
556 // Not done loading yet. We'll find out about it later.
557 return;
558 }
559
Joe Onoratoa8138d52009-10-06 19:25:30 -0700560 final int N = list.size();
561 if (mRollo != null) {
562 mRollo.reallocAppsList(mRollo.mState.iconCount + N);
563 }
564
565 for (int i=0; i<N; i++) {
566 final ApplicationInfo item = list.get(i);
567 int index = Collections.binarySearch(mAllAppsList, item, mAppNameComp);
568 if (index < 0) {
569 index = -(index+1);
570 }
Joe Onorato0ace11a2009-11-05 15:41:27 -0500571 Log.d(TAG, "Adding app '" + item + "' at index " + index + " mRollo=" + mRollo);
Joe Onoratoa8138d52009-10-06 19:25:30 -0700572 mAllAppsList.add(index, item);
573 if (mRollo != null) {
574 mRollo.addApp(index, item);
575 mRollo.mState.iconCount++;
576 }
577 }
578
579 if (mRollo != null) {
580 mRollo.saveAppsList();
581 }
Joe Onoratoc567acb2009-08-31 14:34:43 -0700582 }
583
Joe Onoratoa8138d52009-10-06 19:25:30 -0700584 public void removeApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2d804762009-11-05 16:02:32 -0500585 if (mAllAppsList == null) {
586 // Not done loading yet. We'll find out about it later.
587 return;
588 }
589
Joe Onoratoa8138d52009-10-06 19:25:30 -0700590 final int N = list.size();
591 for (int i=0; i<N; i++) {
592 final ApplicationInfo item = list.get(i);
Joe Onoratocb9f7982009-10-31 16:32:02 -0400593 int index = findAppByComponent(mAllAppsList, item);
Joe Onoratoa8138d52009-10-06 19:25:30 -0700594 if (index >= 0) {
595 mAllAppsList.remove(index);
596 if (mRollo != null) {
597 mRollo.removeApp(index);
598 mRollo.mState.iconCount--;
599 }
600 } else {
601 Log.e(TAG, "couldn't find a match for item \"" + item + "\"");
602 // Try to recover. This should keep us from crashing for now.
603 }
604 }
605
606 if (mRollo != null) {
607 mRollo.saveAppsList();
608 }
609 }
610
611 public void updateApps(String packageName, ArrayList<ApplicationInfo> list) {
612 // Just remove and add, because they may need to be re-sorted.
613 removeApps(list);
614 addApps(list);
615 }
616
617 private Comparator<ApplicationInfo> mAppNameComp = new Comparator<ApplicationInfo>() {
618 public int compare(ApplicationInfo a, ApplicationInfo b) {
619 int result = a.title.toString().compareTo(b.toString());
620 if (result != 0) {
621 return result;
622 }
623 return a.intent.getComponent().compareTo(b.intent.getComponent());
624 }
625 };
626
Joe Onoratocb9f7982009-10-31 16:32:02 -0400627 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
628 ComponentName component = item.intent.getComponent();
629 final int N = list.size();
630 for (int i=0; i<N; i++) {
631 ApplicationInfo x = list.get(i);
632 if (x.intent.getComponent().equals(component)) {
633 return i;
634 }
Joe Onoratoa8138d52009-10-06 19:25:30 -0700635 }
Joe Onoratocb9f7982009-10-31 16:32:02 -0400636 return -1;
637 }
Joe Onoratoa8138d52009-10-06 19:25:30 -0700638
Joe Onoratoc567acb2009-08-31 14:34:43 -0700639 private static int countPages(int iconCount) {
640 int iconsPerPage = Defines.COLUMNS_PER_PAGE * Defines.ROWS_PER_PAGE;
641 int pages = iconCount / iconsPerPage;
642 if (pages*iconsPerPage != iconCount) {
643 pages++;
644 }
645 return pages;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400646 }
647
Joe Onorato93839052009-08-06 20:34:32 -0700648 public class RolloRS {
Joe Onoratobf15cb42009-08-07 14:33:40 -0700649
Joe Onorato1feb3a82009-08-08 22:32:00 -0700650 // Allocations ======
Joe Onorato93839052009-08-06 20:34:32 -0700651 private int mWidth;
652 private int mHeight;
653
654 private Resources mRes;
Jason Sams37e7c2b2009-10-19 12:55:43 -0700655 private Script mScript;
656 private Script.Invokable mInvokeMove;
Jason Samsc1c521e2009-10-19 14:45:45 -0700657 private Script.Invokable mInvokeMoveTo;
Jason Sams37e7c2b2009-10-19 12:55:43 -0700658 private Script.Invokable mInvokeFling;
659 private Script.Invokable mInvokeResetWAR;
Jason Sams86c87ed2009-09-18 13:55:55 -0700660
Jason Samsc1c521e2009-10-19 14:45:45 -0700661
Jason Samscd689e12009-09-29 15:28:22 -0700662 private ProgramStore mPSIcons;
Joe Onorato93839052009-08-06 20:34:32 -0700663 private ProgramStore mPSText;
Jason Samscd689e12009-09-29 15:28:22 -0700664 private ProgramFragment mPFColor;
Jason Samsc8514792009-10-29 14:27:29 -0700665 private ProgramFragment mPFTexMip;
666 private ProgramFragment mPFTexNearest;
Joe Onorato93839052009-08-06 20:34:32 -0700667 private ProgramVertex mPV;
Joe Onorato93839052009-08-06 20:34:32 -0700668 private ProgramVertex mPVOrtho;
Jason Sams0aa71662009-10-02 18:43:18 -0700669 private SimpleMesh mMesh;
Jason Samsd8152b92009-10-13 17:19:10 -0700670 private SimpleMesh mMesh2;
Joe Onorato93839052009-08-06 20:34:32 -0700671
Joe Onoratod63458b2009-10-15 21:19:09 -0700672 private Allocation mHomeButtonNormal;
673 private Allocation mHomeButtonPressed;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700674
Joe Onoratobf15cb42009-08-07 14:33:40 -0700675 private Allocation[] mIcons;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700676 private int[] mIconIds;
Joe Onoratoa8138d52009-10-06 19:25:30 -0700677 private Allocation mAllocIconIds;
Joe Onorato93839052009-08-06 20:34:32 -0700678
Joe Onoratobf15cb42009-08-07 14:33:40 -0700679 private Allocation[] mLabels;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700680 private int[] mLabelIds;
Joe Onoratoa8138d52009-10-06 19:25:30 -0700681 private Allocation mAllocLabelIds;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700682 private Allocation mSelectedIcon;
Joe Onorato93839052009-08-06 20:34:32 -0700683
Joe Onorato6665c0f2009-09-02 15:27:24 -0700684 private int[] mTouchYBorders;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700685 private int[] mTouchXBorders;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700686
687 private Bitmap mSelectionBitmap;
Joe Onorato1291a8c2009-09-15 15:07:25 -0400688 private Canvas mSelectionCanvas;
Joe Onorato93839052009-08-06 20:34:32 -0700689
Jason Sams20df7c72009-11-05 12:30:24 -0800690 boolean mHasSurface = false;
691 private boolean mAppsDirty = false;
Jason Samsd8152b92009-10-13 17:19:10 -0700692
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700693 Params mParams;
Joe Onorato1feb3a82009-08-08 22:32:00 -0700694 State mState;
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700695
Jason Sams78aebd82009-09-15 13:06:59 -0700696 class BaseAlloc {
697 Allocation mAlloc;
698 Type mType;
699
700 void save() {
701 mAlloc.data(this);
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700702 }
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700703 }
704
Jason Sams12c14a82009-10-06 14:33:15 -0700705 class AAMessage extends RenderScript.RSMessage {
706 public void run() {
707 mPosX = ((float)mData[0]) / (1 << 16);
708 mVelocity = ((float)mData[1]) / (1 << 16);
709 mZoom = ((float)mData[2]) / (1 << 16);
710 //Log.d("rs", "new msg " + mPosX + " " + mVelocity + " " + mZoom);
711 }
712 float mZoom;
713 float mPosX;
714 float mVelocity;
715 }
716 AAMessage mMessageProc;
717
Jason Sams476339d2009-09-29 18:14:38 -0700718 private boolean checkClickOK() {
719 //android.util.Log.e("rs", "check click " + Float.toString(mReadback.velocity) + ", " + Float.toString(mReadback.posX));
Jason Sams2e19c052009-10-20 18:19:55 -0700720 return (Math.abs(mMessageProc.mVelocity) < 0.4f) &&
721 (Math.abs(mMessageProc.mPosX - Math.round(mMessageProc.mPosX)) < 0.4f);
Jason Sams476339d2009-09-29 18:14:38 -0700722 }
723
Jason Sams78aebd82009-09-15 13:06:59 -0700724 class Params extends BaseAlloc {
725 Params() {
726 mType = Type.createFromClass(mRS, Params.class, 1, "ParamsClass");
727 mAlloc = Allocation.createTyped(mRS, mType);
728 save();
Joe Onorato1feb3a82009-08-08 22:32:00 -0700729 }
Jason Sams78aebd82009-09-15 13:06:59 -0700730 public int bubbleWidth;
731 public int bubbleHeight;
732 public int bubbleBitmapWidth;
733 public int bubbleBitmapHeight;
Joe Onoratobcbeab82009-10-01 21:45:43 -0700734
Joe Onoratobcbeab82009-10-01 21:45:43 -0700735 public int homeButtonWidth;
736 public int homeButtonHeight;
737 public int homeButtonTextureWidth;
738 public int homeButtonTextureHeight;
Jason Sams78aebd82009-09-15 13:06:59 -0700739 }
740
741 class State extends BaseAlloc {
Jason Sams86c87ed2009-09-18 13:55:55 -0700742 public float newPositionX;
743 public int newTouchDown;
Jason Sams37e7c2b2009-10-19 12:55:43 -0700744 public float flingVelocity;
Jason Sams78aebd82009-09-15 13:06:59 -0700745 public int iconCount;
Jason Sams78aebd82009-09-15 13:06:59 -0700746 public int selectedIconIndex = -1;
747 public int selectedIconTexture;
Joe Onorato7bb17492009-09-24 17:51:01 -0700748 public float zoomTarget;
Joe Onoratod63458b2009-10-15 21:19:09 -0700749 public int homeButtonId;
Jason Samsc1c521e2009-10-19 14:45:45 -0700750 public float targetPos;
Jason Sams78aebd82009-09-15 13:06:59 -0700751
752 State() {
753 mType = Type.createFromClass(mRS, State.class, 1, "StateClass");
754 mAlloc = Allocation.createTyped(mRS, mType);
755 save();
756 }
Joe Onorato1feb3a82009-08-08 22:32:00 -0700757 }
758
759 public RolloRS() {
760 }
761
762 public void init(Resources res, int width, int height) {
763 mRes = res;
764 mWidth = width;
765 mHeight = height;
Joe Onoratobcbeab82009-10-01 21:45:43 -0700766 mDefines.recompute(width, height);
Jason Samscd689e12009-09-29 15:28:22 -0700767 initProgramVertex();
768 initProgramFragment();
769 initProgramStore();
Jason Sams0aa71662009-10-02 18:43:18 -0700770 initMesh();
Joe Onorato1feb3a82009-08-08 22:32:00 -0700771 initGl();
772 initData();
Joe Onorato6665c0f2009-09-02 15:27:24 -0700773 initTouchState();
Joe Onorato1feb3a82009-08-08 22:32:00 -0700774 initRs();
775 }
776
Jason Sams0aa71662009-10-02 18:43:18 -0700777 public void initMesh() {
778 SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(mRS, 3,
779 SimpleMesh.TriangleMeshBuilder.TEXTURE_0 | SimpleMesh.TriangleMeshBuilder.COLOR);
780
Jason Samsd8152b92009-10-13 17:19:10 -0700781 float y = 0;
782 float z = 0;
783 for (int ct=0; ct < 200; ct++) {
784 float angle = 0;
785 float maxAngle = 3.14f * 0.16f;
786 float l = 1.f;
787
788 l = 1 - ((ct-5) * 0.10f);
789 if (ct > 7) {
790 angle = maxAngle * (ct - 7) * 0.2f;
791 angle = Math.min(angle, maxAngle);
792 }
Jason Samsc8514792009-10-29 14:27:29 -0700793 l = Math.max(0.4f, l);
Jason Samsd8152b92009-10-13 17:19:10 -0700794 l = Math.min(1.0f, l);
795
796 y += 0.1f * Math.cos(angle);
797 z += 0.1f * Math.sin(angle);
798
799 float t = 0.1f * ct;
800 float ds = 0.08f;
801 tm.setColor(l, l, l, 0.99f);
802 tm.setTexture(ds, t);
803 tm.addVertex(-0.5f, y, z);
804 tm.setTexture(1 - ds, t);
805 tm.addVertex(0.5f, y, z);
806 }
807 for (int ct=0; ct < (200 * 2 - 2); ct+= 2) {
808 tm.addTriangle(ct, ct+1, ct+2);
809 tm.addTriangle(ct+1, ct+3, ct+2);
810 }
811 mMesh2 = tm.create();
Jason Sams37e7c2b2009-10-19 12:55:43 -0700812 mMesh2.setName("SMMesh");
Jason Samsd8152b92009-10-13 17:19:10 -0700813 }
814
Jason Samscd689e12009-09-29 15:28:22 -0700815 private void initProgramVertex() {
816 ProgramVertex.MatrixAllocation pva = new ProgramVertex.MatrixAllocation(mRS);
817 pva.setupProjectionNormalized(mWidth, mHeight);
Joe Onorato93839052009-08-06 20:34:32 -0700818
819 ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null);
Jason Sams0aa71662009-10-02 18:43:18 -0700820 pvb.setTextureMatrixEnable(true);
Joe Onorato93839052009-08-06 20:34:32 -0700821 mPV = pvb.create();
822 mPV.setName("PV");
Jason Samscd689e12009-09-29 15:28:22 -0700823 mPV.bindAllocation(pva);
Joe Onorato93839052009-08-06 20:34:32 -0700824
Jason Sams37e7c2b2009-10-19 12:55:43 -0700825 //pva = new ProgramVertex.MatrixAllocation(mRS);
826 //pva.setupOrthoWindow(mWidth, mHeight);
827 //pvb.setTextureMatrixEnable(true);
828 //mPVOrtho = pvb.create();
829 //mPVOrtho.setName("PVOrtho");
830 //mPVOrtho.bindAllocation(pva);
Joe Onorato93839052009-08-06 20:34:32 -0700831
832 mRS.contextBindProgramVertex(mPV);
Jason Samscd689e12009-09-29 15:28:22 -0700833 }
Joe Onorato93839052009-08-06 20:34:32 -0700834
Jason Samscd689e12009-09-29 15:28:22 -0700835 private void initProgramFragment() {
836 Sampler.Builder sb = new Sampler.Builder(mRS);
Jason Samsc8514792009-10-29 14:27:29 -0700837 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
Jason Samscd689e12009-09-29 15:28:22 -0700838 sb.setMag(Sampler.Value.LINEAR);
839 sb.setWrapS(Sampler.Value.CLAMP);
840 sb.setWrapT(Sampler.Value.CLAMP);
841 Sampler linear = sb.create();
842
843 sb.setMin(Sampler.Value.NEAREST);
844 sb.setMag(Sampler.Value.NEAREST);
845 Sampler nearest = sb.create();
846
847 ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null);
Jason Sams37e7c2b2009-10-19 12:55:43 -0700848 //mPFColor = bf.create();
849 //mPFColor.setName("PFColor");
Jason Samscd689e12009-09-29 15:28:22 -0700850
851 bf.setTexEnable(true, 0);
852 bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0);
Jason Samsc8514792009-10-29 14:27:29 -0700853 mPFTexMip = bf.create();
854 mPFTexMip.setName("PFTexMip");
855 mPFTexMip.bindSampler(linear, 0);
856
857 mPFTexNearest = bf.create();
858 mPFTexNearest.setName("PFTexNearest");
859 mPFTexNearest.bindSampler(nearest, 0);
Jason Samscd689e12009-09-29 15:28:22 -0700860 }
861
862 private void initProgramStore() {
863 ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null);
864 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
Jason Sams12c14a82009-10-06 14:33:15 -0700865 bs.setColorMask(true,true,true,false);
Jason Samscd689e12009-09-29 15:28:22 -0700866 bs.setDitherEnable(true);
867 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
868 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
869 mPSIcons = bs.create();
870 mPSIcons.setName("PSIcons");
871
872 //bs.setDitherEnable(false);
873 //mPSText = bs.create();
874 //mPSText.setName("PSText");
875 }
876
877 private void initGl() {
Joe Onorato6665c0f2009-09-02 15:27:24 -0700878 mTouchXBorders = new int[Defines.COLUMNS_PER_PAGE+1];
Joe Onorato6665c0f2009-09-02 15:27:24 -0700879 mTouchYBorders = new int[Defines.ROWS_PER_PAGE+1];
Joe Onoratobf15cb42009-08-07 14:33:40 -0700880 }
Jason Sams78aebd82009-09-15 13:06:59 -0700881
Joe Onorato1feb3a82009-08-08 22:32:00 -0700882 private void initData() {
Jason Sams78aebd82009-09-15 13:06:59 -0700883 mParams = new Params();
884 mState = new State();
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700885
Joe Onoratobf15cb42009-08-07 14:33:40 -0700886 final Utilities.BubbleText bubble = new Utilities.BubbleText(getContext());
Joe Onorato93839052009-08-06 20:34:32 -0700887
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700888 mParams.bubbleWidth = bubble.getBubbleWidth();
889 mParams.bubbleHeight = bubble.getMaxBubbleHeight();
890 mParams.bubbleBitmapWidth = bubble.getBitmapWidth();
891 mParams.bubbleBitmapHeight = bubble.getBitmapHeight();
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700892
Joe Onoratod63458b2009-10-15 21:19:09 -0700893 mHomeButtonNormal = Allocation.createFromBitmapResource(mRS, mRes,
894 R.drawable.home_button_normal, Element.RGBA_8888(mRS), false);
895 mHomeButtonNormal.uploadToTexture(0);
896 mHomeButtonPressed = Allocation.createFromBitmapResource(mRS, mRes,
897 R.drawable.home_button_pressed, Element.RGBA_8888(mRS), false);
898 mHomeButtonPressed.uploadToTexture(0);
Joe Onoratobcbeab82009-10-01 21:45:43 -0700899 mParams.homeButtonWidth = 76;
900 mParams.homeButtonHeight = 68;
901 mParams.homeButtonTextureWidth = 128;
902 mParams.homeButtonTextureHeight = 128;
Joe Onoratoc567acb2009-08-31 14:34:43 -0700903
Joe Onoratod63458b2009-10-15 21:19:09 -0700904 mState.homeButtonId = mHomeButtonNormal.getID();
905
Joe Onorato1feb3a82009-08-08 22:32:00 -0700906 mParams.save();
907 mState.save();
Joe Onorato9c1289c2009-08-17 11:03:03 -0400908
Joe Onorato1291a8c2009-09-15 15:07:25 -0400909 mSelectionBitmap = Bitmap.createBitmap(Defines.ICON_TEXTURE_WIDTH_PX,
910 Defines.ICON_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
911 mSelectionCanvas = new Canvas(mSelectionBitmap);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700912
Joe Onorato9c1289c2009-08-17 11:03:03 -0400913 setApps(null);
Joe Onorato93839052009-08-06 20:34:32 -0700914 }
915
Jason Sams37e7c2b2009-10-19 12:55:43 -0700916 private void initScript(int id) {
917 }
918
919 private void initRs() {
Joe Onorato93839052009-08-06 20:34:32 -0700920 ScriptC.Builder sb = new ScriptC.Builder(mRS);
Jason Sams37e7c2b2009-10-19 12:55:43 -0700921 sb.setScript(mRes, R.raw.rollo3);
Joe Onorato93839052009-08-06 20:34:32 -0700922 sb.setRoot(true);
Joe Onoratobcbeab82009-10-01 21:45:43 -0700923 sb.addDefines(mDefines);
Jason Sams78aebd82009-09-15 13:06:59 -0700924 sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS);
925 sb.setType(mState.mType, "state", Defines.ALLOC_STATE);
Jason Sams37e7c2b2009-10-19 12:55:43 -0700926 mInvokeMove = sb.addInvokable("move");
927 mInvokeFling = sb.addInvokable("fling");
Jason Samsc1c521e2009-10-19 14:45:45 -0700928 mInvokeMoveTo = sb.addInvokable("moveTo");
Jason Sams37e7c2b2009-10-19 12:55:43 -0700929 mInvokeResetWAR = sb.addInvokable("resetHWWar");
930 mScript = sb.create();
931 mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
932 mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
933 mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
934 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
935 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
Joe Onorato93839052009-08-06 20:34:32 -0700936
Jason Sams12c14a82009-10-06 14:33:15 -0700937 mMessageProc = new AAMessage();
938 mRS.mMessageCallback = mMessageProc;
Jason Sams37e7c2b2009-10-19 12:55:43 -0700939 mRS.contextBindRootScript(mScript);
Joe Onorato93839052009-08-06 20:34:32 -0700940 }
Joe Onorato93839052009-08-06 20:34:32 -0700941
Jason Sams20df7c72009-11-05 12:30:24 -0800942 private void uploadApps(ArrayList<ApplicationInfo> list) {
943 for (int i=0; i < mState.iconCount; i++) {
944 uploadAppIcon(i, list.get(i));
945 }
946 }
947
948 void dirtyCheck() {
949 if (mAppsDirty && mHasSurface) {
950 uploadApps(mAllAppsList);
951 saveAppsList();
952 mAppsDirty = false;
953 }
954 }
955
Joe Onorato9c1289c2009-08-17 11:03:03 -0400956 private void setApps(ArrayList<ApplicationInfo> list) {
957 final int count = list != null ? list.size() : 0;
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700958 int allocCount = count;
Joe Onoratoa8138d52009-10-06 19:25:30 -0700959 if (allocCount < 1) {
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700960 allocCount = 1;
961 }
962
Joe Onorato9c1289c2009-08-17 11:03:03 -0400963 mIcons = new Allocation[count];
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700964 mIconIds = new int[allocCount];
Joe Onoratoa8138d52009-10-06 19:25:30 -0700965 mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400966
967 mLabels = new Allocation[count];
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700968 mLabelIds = new int[allocCount];
Joe Onoratoa8138d52009-10-06 19:25:30 -0700969 mAllocLabelIds = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400970
Jason Sams0a8dc2c2009-09-27 17:51:44 -0700971 Element ie8888 = Element.RGBA_8888(mRS);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400972
973 Utilities.BubbleText bubble = new Utilities.BubbleText(getContext());
974
Joe Onorato9c1289c2009-08-17 11:03:03 -0400975 mState.iconCount = count;
Jason Sams20df7c72009-11-05 12:30:24 -0800976 uploadApps(list);
Joe Onoratoa8138d52009-10-06 19:25:30 -0700977 saveAppsList();
978 }
979
Jason Samsc8514792009-10-29 14:27:29 -0700980 private void frameBitmapAllocMips(Allocation alloc, int w, int h) {
981 int black[] = new int[w > h ? w : h];
982 Allocation.Adapter2D a = alloc.createAdapter2D();
983 int mip = 0;
984 while (w > 1 || h > 1) {
985 a.subData(0, 0, 1, h, black);
986 a.subData(w-1, 0, 1, h, black);
987 a.subData(0, 0, w, 1, black);
988 a.subData(0, h-1, w, 1, black);
989 mip++;
990 w = (w + 1) >> 1;
991 h = (h + 1) >> 1;
992 a.setConstraint(Dimension.LOD, mip);
993 }
994 a.subData(0, 0, 1, 1, black);
995 }
996
Joe Onoratoa8138d52009-10-06 19:25:30 -0700997 private void uploadAppIcon(int index, ApplicationInfo item) {
998 mIcons[index] = Allocation.createFromBitmap(mRS, item.iconBitmap,
Jason Samsc8514792009-10-29 14:27:29 -0700999 Element.RGBA_8888(mRS), true);
1000 frameBitmapAllocMips(mIcons[index], item.iconBitmap.getWidth(), item.iconBitmap.getHeight());
1001
Joe Onoratoa8138d52009-10-06 19:25:30 -07001002 mLabels[index] = Allocation.createFromBitmap(mRS, item.titleBitmap,
Jason Samsc8514792009-10-29 14:27:29 -07001003 Element.RGBA_8888(mRS), true);
1004 frameBitmapAllocMips(mLabels[index], item.titleBitmap.getWidth(), item.titleBitmap.getHeight());
Joe Onoratoa8138d52009-10-06 19:25:30 -07001005
1006 mIcons[index].uploadToTexture(0);
1007 mLabels[index].uploadToTexture(0);
1008
1009 mIconIds[index] = mIcons[index].getID();
1010 mLabelIds[index] = mLabels[index].getID();
1011 }
1012
1013 /**
1014 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1015 * fill in the values and call saveAppsList().
1016 */
1017 private void reallocAppsList(int count) {
1018 Allocation[] icons = new Allocation[count];
1019 int[] iconIds = new int[count];
1020 mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), count);
1021
1022 Allocation[] labels = new Allocation[count];
1023 int[] labelIds = new int[count];
1024 mAllocLabelIds = Allocation.createSized(mRS, Element.USER_I32(mRS), count);
1025
1026 final int oldCount = mIcons.length;
1027
1028 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1029 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1030 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1031 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
1032
1033 mIcons = icons;
1034 mIconIds = iconIds;
1035 mLabels = labels;
1036 mLabelIds = labelIds;
1037 }
1038
1039 /**
1040 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1041 */
1042 private void addApp(int index, ApplicationInfo item) {
1043 final int count = mState.iconCount - index;
1044 final int dest = index + 1;
1045
1046 System.arraycopy(mIcons, index, mIcons, dest, count);
1047 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1048 System.arraycopy(mLabels, index, mLabels, dest, count);
1049 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
1050
Jason Sams20df7c72009-11-05 12:30:24 -08001051 if (mHasSurface ) {
1052 uploadAppIcon(index, item);
1053 } else {
1054 mAppsDirty = true;
1055 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07001056 }
1057
1058 /**
1059 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1060 */
1061 private void removeApp(int index) {
1062 final int count = mState.iconCount - index - 1;
1063 final int src = index + 1;
1064
1065 System.arraycopy(mIcons, src, mIcons, index, count);
1066 System.arraycopy(mIconIds, src, mIconIds, index, count);
1067 System.arraycopy(mLabels, src, mLabels, index, count);
1068 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
1069
1070 final int last = mState.iconCount - 1;
1071 mIcons[last] = null;
1072 mIconIds[last] = 0;
1073 mLabels[last] = null;
1074 mLabelIds[last] = 0;
1075 }
1076
1077 /**
1078 * Send the apps list structures to RS.
1079 */
1080 private void saveAppsList() {
1081 mRS.contextBindRootScript(null);
Jason Samsd8152b92009-10-13 17:19:10 -07001082
Joe Onoratoa8138d52009-10-06 19:25:30 -07001083 mAllocIconIds.data(mIconIds);
1084 mAllocLabelIds.data(mLabelIds);
1085
Jason Sams37e7c2b2009-10-19 12:55:43 -07001086 if (mScript != null) { // this happens when we init it
1087 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1088 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001089 }
1090
1091 mState.save();
Joe Onoratoa8138d52009-10-06 19:25:30 -07001092
1093 // Note: mScript may be null if we haven't initialized it yet.
1094 // In that case, this is a no-op.
Jason Sams37e7c2b2009-10-19 12:55:43 -07001095 if (mInvokeResetWAR != null) {
1096 mInvokeResetWAR.execute();
Jason Sams41b61c82009-10-15 15:40:54 -07001097 }
Jason Sams37e7c2b2009-10-19 12:55:43 -07001098 mRS.contextBindRootScript(mScript);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001099 }
Joe Onorato6665c0f2009-09-02 15:27:24 -07001100
1101 void initTouchState() {
1102 int width = getWidth();
1103 int height = getHeight();
Jason Sams37e7c2b2009-10-19 12:55:43 -07001104 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE;
1105 int cellWidth = width / Defines.COLUMNS_PER_PAGE;
Joe Onorato6665c0f2009-09-02 15:27:24 -07001106
Jason Sams37e7c2b2009-10-19 12:55:43 -07001107 int centerY = (height / 2);
1108 mTouchYBorders[0] = centerY - (cellHeight * 2);
1109 mTouchYBorders[1] = centerY - cellHeight;
Joe Onorato6665c0f2009-09-02 15:27:24 -07001110 mTouchYBorders[2] = centerY;
Jason Sams37e7c2b2009-10-19 12:55:43 -07001111 mTouchYBorders[3] = centerY + cellHeight;
1112 mTouchYBorders[4] = centerY + (cellHeight * 2);
Jason Sams78aebd82009-09-15 13:06:59 -07001113
Joe Onorato6665c0f2009-09-02 15:27:24 -07001114 int centerX = (width / 2);
Jason Sams37e7c2b2009-10-19 12:55:43 -07001115 mTouchXBorders[0] = 0;
1116 mTouchXBorders[1] = centerX - (width / 4);
Joe Onorato6665c0f2009-09-02 15:27:24 -07001117 mTouchXBorders[2] = centerX;
Jason Sams37e7c2b2009-10-19 12:55:43 -07001118 mTouchXBorders[3] = centerX + (width / 4);
1119 mTouchXBorders[4] = width;
Joe Onorato6665c0f2009-09-02 15:27:24 -07001120 }
1121
Joe Onorato664457d2009-10-28 16:30:34 -04001122 void fling() {
1123 mInvokeFling.execute();
1124 }
1125
1126 void move() {
1127 mInvokeMove.execute();
1128 }
1129
1130 void moveTo(float row) {
1131 mState.targetPos = row;
1132 mState.save();
1133 mInvokeMoveTo.execute();
1134 }
1135
Jason Sams37e7c2b2009-10-19 12:55:43 -07001136 int chooseTappedIcon(int x, int y, float pos) {
1137 // Adjust for scroll position if not zero.
1138 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
Jason Sams86c87ed2009-09-18 13:55:55 -07001139
Joe Onorato6665c0f2009-09-02 15:27:24 -07001140 int col = -1;
1141 int row = -1;
Joe Onorato6665c0f2009-09-02 15:27:24 -07001142 for (int i=0; i<Defines.COLUMNS_PER_PAGE; i++) {
1143 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
1144 col = i;
1145 break;
1146 }
1147 }
1148 for (int i=0; i<Defines.ROWS_PER_PAGE; i++) {
1149 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
1150 row = i;
1151 break;
1152 }
1153 }
1154
1155 if (row < 0 || col < 0) {
1156 return -1;
1157 }
1158
Joe Onorato664457d2009-10-28 16:30:34 -04001159 int index = (((int)pos) * Defines.COLUMNS_PER_PAGE)
Joe Onorato6665c0f2009-09-02 15:27:24 -07001160 + (row * Defines.ROWS_PER_PAGE) + col;
Joe Onorato6665c0f2009-09-02 15:27:24 -07001161
Joe Onorato664457d2009-10-28 16:30:34 -04001162 if (index >= mState.iconCount) {
1163 return -1;
1164 } else {
1165 return index;
1166 }
Jason Samsc1c521e2009-10-19 14:45:45 -07001167 }
1168
Joe Onorato6665c0f2009-09-02 15:27:24 -07001169 /**
1170 * You need to call save() on mState on your own after calling this.
Joe Onorato82ca5502009-10-15 16:59:23 -07001171 *
1172 * @return the index of the icon that was selected.
Joe Onorato6665c0f2009-09-02 15:27:24 -07001173 */
Joe Onorato82ca5502009-10-15 16:59:23 -07001174 int selectIcon(int x, int y, float pos) {
1175 final int index = chooseTappedIcon(x, y, pos);
Joe Onorato1291a8c2009-09-15 15:07:25 -04001176 selectIcon(index);
Joe Onorato82ca5502009-10-15 16:59:23 -07001177 return index;
Joe Onorato1291a8c2009-09-15 15:07:25 -04001178 }
1179
1180 void selectIcon(int index) {
Joe Onorato2d804762009-11-05 16:02:32 -05001181 if (mAllAppsList == null || index < 0 || index >= mAllAppsList.size()) {
Joe Onorato6665c0f2009-09-02 15:27:24 -07001182 mState.selectedIconIndex = -1;
Joe Onorato6665c0f2009-09-02 15:27:24 -07001183 } else {
1184 mState.selectedIconIndex = index;
Joe Onorato1291a8c2009-09-15 15:07:25 -04001185
1186 Bitmap selectionBitmap = mSelectionBitmap;
1187
1188 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1189 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1190 mAllAppsList.get(index).iconBitmap);
1191
1192 mSelectedIcon = Allocation.createFromBitmap(mRS, selectionBitmap,
Jason Sams0a8dc2c2009-09-27 17:51:44 -07001193 Element.RGBA_8888(mRS), false);
Joe Onorato1291a8c2009-09-15 15:07:25 -04001194 mSelectedIcon.uploadToTexture(0);
1195 mState.selectedIconTexture = mSelectedIcon.getID();
Joe Onorato6665c0f2009-09-02 15:27:24 -07001196 }
1197 }
1198
1199 /**
1200 * You need to call save() on mState on your own after calling this.
1201 */
1202 void clearSelectedIcon() {
Joe Onorato2ca51dc2009-09-16 11:44:14 -04001203 mState.selectedIconIndex = -1;
Joe Onorato6665c0f2009-09-02 15:27:24 -07001204 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07001205
Joe Onoratod63458b2009-10-15 21:19:09 -07001206 void setHomeSelected(boolean pressed) {
1207 if (pressed) {
1208 mState.homeButtonId = mHomeButtonPressed.getID();
1209 } else {
1210 mState.homeButtonId = mHomeButtonNormal.getID();
1211 }
1212 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04001213 }
Joe Onorato93839052009-08-06 20:34:32 -07001214}
1215
1216