blob: be3b114727174311722f777e1b7a02f7e6925993 [file] [log] [blame]
Daniel Sandler388f6792010-03-02 14:08:08 -05001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher2;
18
19import android.content.ComponentName;
20import android.content.Context;
21import android.content.res.Resources;
22import android.graphics.Bitmap;
23import android.graphics.Canvas;
24import android.graphics.PixelFormat;
25import android.graphics.Rect;
Daniel Sandler388f6792010-03-02 14:08:08 -050026import android.renderscript.Allocation;
Daniel Sandler388f6792010-03-02 14:08:08 -050027import android.renderscript.Element;
28import android.renderscript.ProgramFragment;
29import android.renderscript.ProgramStore;
30import android.renderscript.ProgramVertex;
31import android.renderscript.RSSurfaceView;
32import android.renderscript.RenderScriptGL;
33import android.renderscript.RenderScript;
34import android.renderscript.Sampler;
35import android.renderscript.Script;
36import android.renderscript.ScriptC;
37import android.renderscript.SimpleMesh;
38import android.renderscript.Type;
39import android.util.AttributeSet;
Romain Guy060b5c82010-03-04 10:07:38 -080040import android.util.DisplayMetrics;
Daniel Sandler388f6792010-03-02 14:08:08 -050041import android.util.Log;
42import android.view.KeyEvent;
43import android.view.MotionEvent;
44import android.view.SoundEffectConstants;
45import android.view.SurfaceHolder;
46import android.view.VelocityTracker;
47import android.view.View;
48import android.view.ViewConfiguration;
49import android.view.accessibility.AccessibilityEvent;
50
51import java.util.ArrayList;
52import java.util.Arrays;
53import java.util.Collections;
Daniel Sandler388f6792010-03-02 14:08:08 -050054
Romain Guyedcce092010-03-04 13:03:17 -080055import com.android.launcher.R;
56
Daniel Sandler388f6792010-03-02 14:08:08 -050057public class AllApps3D extends RSSurfaceView
58 implements AllAppsView, View.OnClickListener, View.OnLongClickListener, DragSource {
59 private static final String TAG = "Launcher.AllApps3D";
60
61 /** Bit for mLocks for when there are icons being loaded. */
62 private static final int LOCK_ICONS_PENDING = 1;
63
64 private static final int TRACKING_NONE = 0;
65 private static final int TRACKING_FLING = 1;
66 private static final int TRACKING_HOME = 2;
67
68 private static final int SELECTED_NONE = 0;
69 private static final int SELECTED_FOCUSED = 1;
70 private static final int SELECTED_PRESSED = 2;
71
72 private static final int SELECTION_NONE = 0;
73 private static final int SELECTION_ICONS = 1;
74 private static final int SELECTION_HOME = 2;
75
Daniel Sandlerdca66122010-04-13 16:23:58 -040076 private static final int BATCH_SIZE = 0; // give us all the apps at once
77
Daniel Sandler388f6792010-03-02 14:08:08 -050078 private Launcher mLauncher;
79 private DragController mDragController;
80
81 /** When this is 0, modifications are allowed, when it's not, they're not.
82 * TODO: What about scrolling? */
83 private int mLocks = LOCK_ICONS_PENDING;
84
85 private int mSlop;
86 private int mMaxFlingVelocity;
87
88 private Defines mDefines = new Defines();
Daniel Sandler388f6792010-03-02 14:08:08 -050089 private ArrayList<ApplicationInfo> mAllAppsList;
90
Joe Onorato2cc62e82010-03-17 20:23:53 -070091 private static RenderScriptGL sRS;
92 private static RolloRS sRollo;
Jason Samsdd8cd8b2010-03-11 12:38:48 -080093
Joe Onoratoeffc4a82010-04-15 11:48:13 -070094 private static boolean sZoomDirty = false;
95 private static boolean sAnimateNextZoom;
96 private static float sNextZoom;
97
Daniel Sandler388f6792010-03-02 14:08:08 -050098 /**
99 * True when we are using arrow keys or trackball to drive navigation
100 */
101 private boolean mArrowNavigation = false;
102 private boolean mStartedScrolling;
103
104 /**
105 * Used to keep track of the selection when AllAppsView loses window focus.
106 * One of the SELECTION_ constants.
107 */
108 private int mLastSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800109
Daniel Sandler388f6792010-03-02 14:08:08 -0500110 /**
111 * Used to keep track of the selection when AllAppsView loses window focus
112 */
113 private int mLastSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800114
Daniel Sandler388f6792010-03-02 14:08:08 -0500115 private VelocityTracker mVelocityTracker;
116 private int mTouchTracking;
117 private int mMotionDownRawX;
118 private int mMotionDownRawY;
119 private int mDownIconIndex = -1;
120 private int mCurrentIconIndex = -1;
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700121 private int[] mTouchYBorders;
122 private int[] mTouchXBorders;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800123
Daniel Sandler388f6792010-03-02 14:08:08 -0500124 private boolean mShouldGainFocus;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800125
Daniel Sandler388f6792010-03-02 14:08:08 -0500126 private boolean mHaveSurface = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500127 private float mZoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500128 private float mVelocity;
129 private AAMessage mMessageProc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800130
Romain Guy060b5c82010-03-04 10:07:38 -0800131 private int mColumnsPerPage;
132 private int mRowsPerPage;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800133 private boolean mSurrendered;
134
Romain Guyc16fea72010-03-12 17:17:56 -0800135 private int mRestoreFocusIndex = -1;
136
Romain Guy060b5c82010-03-04 10:07:38 -0800137 @SuppressWarnings({"UnusedDeclaration"})
Daniel Sandler388f6792010-03-02 14:08:08 -0500138 static class Defines {
139 public static final int ALLOC_PARAMS = 0;
140 public static final int ALLOC_STATE = 1;
141 public static final int ALLOC_ICON_IDS = 3;
142 public static final int ALLOC_LABEL_IDS = 4;
143 public static final int ALLOC_VP_CONSTANTS = 5;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800144
Romain Guy060b5c82010-03-04 10:07:38 -0800145 public static final int COLUMNS_PER_PAGE_PORTRAIT = 4;
146 public static final int ROWS_PER_PAGE_PORTRAIT = 4;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800147
Romain Guy060b5c82010-03-04 10:07:38 -0800148 public static final int COLUMNS_PER_PAGE_LANDSCAPE = 6;
149 public static final int ROWS_PER_PAGE_LANDSCAPE = 3;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800150
Daniel Sandler388f6792010-03-02 14:08:08 -0500151 public static final int ICON_WIDTH_PX = 64;
152 public static final int ICON_TEXTURE_WIDTH_PX = 74;
153 public static final int SELECTION_TEXTURE_WIDTH_PX = 74 + 20;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800154
Daniel Sandler388f6792010-03-02 14:08:08 -0500155 public static final int ICON_HEIGHT_PX = 64;
156 public static final int ICON_TEXTURE_HEIGHT_PX = 74;
157 public static final int SELECTION_TEXTURE_HEIGHT_PX = 74 + 20;
158 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800159
Daniel Sandler388f6792010-03-02 14:08:08 -0500160 public AllApps3D(Context context, AttributeSet attrs) {
161 super(context, attrs);
162 setFocusable(true);
163 setSoundEffectsEnabled(false);
164 getHolder().setFormat(PixelFormat.TRANSLUCENT);
165 final ViewConfiguration config = ViewConfiguration.get(context);
166 mSlop = config.getScaledTouchSlop();
167 mMaxFlingVelocity = config.getScaledMaximumFlingVelocity();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800168
Daniel Sandler388f6792010-03-02 14:08:08 -0500169 setOnClickListener(this);
170 setOnLongClickListener(this);
171 setZOrderOnTop(true);
172 getHolder().setFormat(PixelFormat.TRANSLUCENT);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800173
Joe Onorato2cc62e82010-03-17 20:23:53 -0700174 if (sRS == null) {
175 sRS = createRenderScript(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800176 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700177 createRenderScript(sRS);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800178 }
179
Romain Guy060b5c82010-03-04 10:07:38 -0800180 final DisplayMetrics metrics = getResources().getDisplayMetrics();
181 final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
182 mColumnsPerPage = isPortrait ? Defines.COLUMNS_PER_PAGE_PORTRAIT :
183 Defines.COLUMNS_PER_PAGE_LANDSCAPE;
184 mRowsPerPage = isPortrait ? Defines.ROWS_PER_PAGE_PORTRAIT :
185 Defines.ROWS_PER_PAGE_LANDSCAPE;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800186
Joe Onorato2cc62e82010-03-17 20:23:53 -0700187 if (sRollo != null) {
188 sRollo.mAllApps = this;
189 sRollo.mRes = getResources();
190 sRollo.mInitialize = true;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800191 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500192 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800193
Romain Guy060b5c82010-03-04 10:07:38 -0800194 @SuppressWarnings({"UnusedDeclaration"})
195 public AllApps3D(Context context, AttributeSet attrs, int defStyle) {
196 this(context, attrs);
197 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800198
Romain Guy13c2e7b2010-03-10 19:45:00 -0800199 public void surrender() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400200 if (sRS != null) {
201 sRS.contextSetSurface(0, 0, null);
202 sRS.mMessageCallback = null;
203 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800204 mSurrendered = true;
205 }
206
Daniel Sandler388f6792010-03-02 14:08:08 -0500207 /**
208 * Note that this implementation prohibits this view from ever being reattached.
209 */
210 @Override
211 protected void onDetachedFromWindow() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700212 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800213 if (!mSurrendered) {
Joe Onorato96da4012010-03-17 20:03:24 -0700214 Log.i(TAG, "onDetachedFromWindow");
Romain Guy13c2e7b2010-03-10 19:45:00 -0800215 destroyRenderScript();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700216 sRS = null;
217 sRollo = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800218 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500219 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800220
Daniel Sandler388f6792010-03-02 14:08:08 -0500221 /**
222 * If you have an attached click listener, View always plays the click sound!?!?
223 * Deal with sound effects by hand.
224 */
225 public void reallyPlaySoundEffect(int sound) {
226 boolean old = isSoundEffectsEnabled();
227 setSoundEffectsEnabled(true);
228 playSoundEffect(sound);
229 setSoundEffectsEnabled(old);
230 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800231
Daniel Sandler388f6792010-03-02 14:08:08 -0500232 public void setLauncher(Launcher launcher) {
233 mLauncher = launcher;
234 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800235
Daniel Sandler388f6792010-03-02 14:08:08 -0500236 @Override
237 public void surfaceDestroyed(SurfaceHolder holder) {
238 super.surfaceDestroyed(holder);
239 // Without this, we leak mMessageCallback which leaks the context.
Romain Guy13c2e7b2010-03-10 19:45:00 -0800240 if (!mSurrendered) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700241 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800242 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500243 // We may lose any callbacks that are pending, so make sure that we re-sync that
244 // on the next surfaceChanged.
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700245 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500246 mHaveSurface = false;
247 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800248
Daniel Sandler388f6792010-03-02 14:08:08 -0500249 @Override
250 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
251 //long startTime = SystemClock.uptimeMillis();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800252
Daniel Sandler388f6792010-03-02 14:08:08 -0500253 super.surfaceChanged(holder, format, w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800254
Romain Guy13c2e7b2010-03-10 19:45:00 -0800255 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800256
Daniel Sandler388f6792010-03-02 14:08:08 -0500257 mHaveSurface = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800258
Joe Onorato2cc62e82010-03-17 20:23:53 -0700259 if (sRollo == null) {
260 sRollo = new RolloRS(this);
261 sRollo.init(getResources(), w, h);
Daniel Sandler388f6792010-03-02 14:08:08 -0500262 if (mAllAppsList != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700263 sRollo.setApps(mAllAppsList);
Daniel Sandler388f6792010-03-02 14:08:08 -0500264 }
265 if (mShouldGainFocus) {
266 gainFocus();
267 mShouldGainFocus = false;
268 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700269 } else if (sRollo.mInitialize) {
270 sRollo.initGl();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700271 sRollo.mInitialize = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500272 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800273
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700274 initTouchState(w, h);
275
Joe Onorato2cc62e82010-03-17 20:23:53 -0700276 sRollo.dirtyCheck();
277 sRollo.resize(w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800278
Joe Onorato2cc62e82010-03-17 20:23:53 -0700279 if (sRS != null) {
280 sRS.mMessageCallback = mMessageProc = new AAMessage();
Daniel Sandler388f6792010-03-02 14:08:08 -0500281 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800282
Joe Onorato2cc62e82010-03-17 20:23:53 -0700283 if (sRollo.mUniformAlloc != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500284 float tf[] = new float[] {72.f, 72.f,
285 120.f, 120.f, 0.f, 0.f,
286 120.f, 680.f,
287 (2.f / 480.f), 0, -((float)w / 2) - 0.25f, -380.25f};
288 if (w > h) {
289 tf[6] = 40.f;
290 tf[7] = h - 40.f;
291 tf[9] = 1.f;
292 tf[10] = -((float)w / 2) - 0.25f;
293 tf[11] = -((float)h / 2) - 0.25f;
294 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800295
Joe Onorato2cc62e82010-03-17 20:23:53 -0700296 sRollo.mUniformAlloc.data(tf);
Daniel Sandler388f6792010-03-02 14:08:08 -0500297 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800298
Daniel Sandler388f6792010-03-02 14:08:08 -0500299 //long endTime = SystemClock.uptimeMillis();
300 //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
301 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800302
Daniel Sandler388f6792010-03-02 14:08:08 -0500303 @Override
304 public void onWindowFocusChanged(boolean hasWindowFocus) {
305 super.onWindowFocusChanged(hasWindowFocus);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800306
307 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800308
Daniel Sandler388f6792010-03-02 14:08:08 -0500309 if (mArrowNavigation) {
310 if (!hasWindowFocus) {
311 // Clear selection when we lose window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700312 mLastSelectedIcon = sRollo.mState.selectedIconIndex;
313 sRollo.setHomeSelected(SELECTED_NONE);
314 sRollo.clearSelectedIcon();
315 sRollo.mState.save();
Romain Guy060b5c82010-03-04 10:07:38 -0800316 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700317 if (sRollo.mState.iconCount > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500318 if (mLastSelection == SELECTION_ICONS) {
319 int selection = mLastSelectedIcon;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700320 final int firstIcon = Math.round(sRollo.mScrollPos) * mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500321 if (selection < 0 || // No selection
322 selection < firstIcon || // off the top of the screen
Joe Onorato2cc62e82010-03-17 20:23:53 -0700323 selection >= sRollo.mState.iconCount || // past last icon
Daniel Sandler388f6792010-03-02 14:08:08 -0500324 selection >= firstIcon + // past last icon on screen
Romain Guy060b5c82010-03-04 10:07:38 -0800325 (mColumnsPerPage * mRowsPerPage)) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500326 selection = firstIcon;
327 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800328
Daniel Sandler388f6792010-03-02 14:08:08 -0500329 // Select the first icon when we gain window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700330 sRollo.selectIcon(selection, SELECTED_FOCUSED);
331 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500332 } else if (mLastSelection == SELECTION_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700333 sRollo.setHomeSelected(SELECTED_FOCUSED);
334 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500335 }
336 }
337 }
338 }
339 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800340
Daniel Sandler388f6792010-03-02 14:08:08 -0500341 @Override
342 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
343 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800344
Romain Guy13c2e7b2010-03-10 19:45:00 -0800345 if (!isVisible() || mSurrendered) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500346 return;
347 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800348
Daniel Sandler388f6792010-03-02 14:08:08 -0500349 if (gainFocus) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700350 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500351 gainFocus();
352 } else {
353 mShouldGainFocus = true;
354 }
355 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700356 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500357 if (mArrowNavigation) {
358 // Clear selection when we lose focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700359 sRollo.clearSelectedIcon();
360 sRollo.setHomeSelected(SELECTED_NONE);
361 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500362 mArrowNavigation = false;
363 }
364 } else {
365 mShouldGainFocus = false;
366 }
367 }
368 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800369
Daniel Sandler388f6792010-03-02 14:08:08 -0500370 private void gainFocus() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700371 if (!mArrowNavigation && sRollo.mState.iconCount > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500372 // Select the first icon when we gain keyboard focus
373 mArrowNavigation = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700374 sRollo.selectIcon(Math.round(sRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED);
375 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500376 }
377 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800378
Daniel Sandler388f6792010-03-02 14:08:08 -0500379 @Override
380 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800381
Daniel Sandler388f6792010-03-02 14:08:08 -0500382 boolean handled = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800383
Daniel Sandler388f6792010-03-02 14:08:08 -0500384 if (!isVisible()) {
385 return false;
386 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700387 final int iconCount = sRollo.mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800388
Daniel Sandler388f6792010-03-02 14:08:08 -0500389 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
390 if (mArrowNavigation) {
391 if (mLastSelection == SELECTION_HOME) {
392 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
393 mLauncher.closeAllApps(true);
394 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700395 int whichApp = sRollo.mState.selectedIconIndex;
Daniel Sandler388f6792010-03-02 14:08:08 -0500396 if (whichApp >= 0) {
397 ApplicationInfo app = mAllAppsList.get(whichApp);
Joe Onoratof984e852010-03-25 09:47:45 -0700398 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500399 handled = true;
400 }
401 }
402 }
403 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800404
Daniel Sandler388f6792010-03-02 14:08:08 -0500405 if (iconCount > 0) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800406 final boolean isPortrait = getWidth() < getHeight();
407
Daniel Sandler388f6792010-03-02 14:08:08 -0500408 mArrowNavigation = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800409
Joe Onorato2cc62e82010-03-17 20:23:53 -0700410 int currentSelection = sRollo.mState.selectedIconIndex;
411 int currentTopRow = Math.round(sRollo.mScrollPos);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800412
Romain Guy060b5c82010-03-04 10:07:38 -0800413 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1
414 final int currentPageCol = currentSelection % mColumnsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800415
Romain Guy060b5c82010-03-04 10:07:38 -0800416 // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1
Romain Guy6a42cf32010-03-12 16:03:52 -0800417 final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage))
Romain Guy060b5c82010-03-04 10:07:38 -0800418 / mRowsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800419
Daniel Sandler388f6792010-03-02 14:08:08 -0500420 int newSelection = currentSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800421
Daniel Sandler388f6792010-03-02 14:08:08 -0500422 switch (keyCode) {
423 case KeyEvent.KEYCODE_DPAD_UP:
424 if (mLastSelection == SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800425 if (isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700426 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guy6a42cf32010-03-12 16:03:52 -0800427 int lastRowCount = iconCount % mColumnsPerPage;
428 if (lastRowCount == 0) {
429 lastRowCount = mColumnsPerPage;
430 }
431 newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2);
432 if (newSelection >= iconCount) {
433 newSelection = iconCount-1;
434 }
435 int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
436 if (target < 0) {
437 target = 0;
438 }
439 if (currentTopRow != target) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700440 sRollo.moveTo(target);
Romain Guy6a42cf32010-03-12 16:03:52 -0800441 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500442 }
443 } else {
444 if (currentPageRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800445 newSelection = currentSelection - mColumnsPerPage;
Romain Guy6a42cf32010-03-12 16:03:52 -0800446 if (currentTopRow > newSelection / mColumnsPerPage) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700447 sRollo.moveTo(newSelection / mColumnsPerPage);
Romain Guy6a42cf32010-03-12 16:03:52 -0800448 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500449 } else if (currentTopRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800450 newSelection = currentSelection - mColumnsPerPage;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700451 sRollo.moveTo(newSelection / mColumnsPerPage);
Daniel Sandler388f6792010-03-02 14:08:08 -0500452 } else if (currentPageRow != 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800453 newSelection = currentTopRow * mRowsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500454 }
455 }
456 handled = true;
457 break;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800458
Daniel Sandler388f6792010-03-02 14:08:08 -0500459 case KeyEvent.KEYCODE_DPAD_DOWN: {
Romain Guy060b5c82010-03-04 10:07:38 -0800460 final int rowCount = iconCount / mColumnsPerPage
461 + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
462 final int currentRow = currentSelection / mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500463 if (mLastSelection != SELECTION_HOME) {
464 if (currentRow < rowCount-1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700465 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500466 if (currentSelection < 0) {
467 newSelection = 0;
468 } else {
Romain Guy060b5c82010-03-04 10:07:38 -0800469 newSelection = currentSelection + mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500470 }
471 if (newSelection >= iconCount) {
472 // Go from D to G in this arrangement:
473 // A B C D
474 // E F G
475 newSelection = iconCount - 1;
476 }
Romain Guy060b5c82010-03-04 10:07:38 -0800477 if (currentPageRow >= mRowsPerPage - 1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700478 sRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -0500479 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800480 } else if (isPortrait) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500481 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700482 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500483 }
484 }
485 handled = true;
486 break;
487 }
488 case KeyEvent.KEYCODE_DPAD_LEFT:
489 if (mLastSelection != SELECTION_HOME) {
490 if (currentPageCol > 0) {
491 newSelection = currentSelection - 1;
492 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800493 } else if (!isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700494 newSelection = ((int) (sRollo.mScrollPos) * mColumnsPerPage) +
Romain Guy6a42cf32010-03-12 16:03:52 -0800495 (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700496 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500497 }
498 handled = true;
499 break;
500 case KeyEvent.KEYCODE_DPAD_RIGHT:
501 if (mLastSelection != SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800502 if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 ||
503 currentSelection == iconCount - 1)) {
504 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700505 sRollo.setHomeSelected(SELECTED_FOCUSED);
Romain Guy6a42cf32010-03-12 16:03:52 -0800506 } else if ((currentPageCol < mColumnsPerPage - 1) &&
Daniel Sandler388f6792010-03-02 14:08:08 -0500507 (currentSelection < iconCount - 1)) {
508 newSelection = currentSelection + 1;
509 }
510 }
511 handled = true;
512 break;
513 }
514 if (newSelection != currentSelection) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700515 sRollo.selectIcon(newSelection, SELECTED_FOCUSED);
516 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500517 }
518 }
519 return handled;
520 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800521
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700522 void initTouchState(int width, int height) {
523 boolean isPortrait = width < height;
524
525 int[] viewPos = new int[2];
526 getLocationOnScreen(viewPos);
527
528 mTouchXBorders = new int[mColumnsPerPage + 1];
529 mTouchYBorders = new int[mRowsPerPage + 1];
530
531 // TODO: Put this in a config file/define
532 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE_PORTRAIT;
533 if (!isPortrait) cellHeight -= 12;
534 int centerY = (int) (height * (isPortrait ? 0.5f : 0.47f));
535 if (!isPortrait) centerY += cellHeight / 2;
536 int half = (int) Math.floor((mRowsPerPage + 1) / 2);
537 int end = mTouchYBorders.length - (half + 1);
538
539 for (int i = -half; i <= end; i++) {
540 mTouchYBorders[i + half] = centerY + (i * cellHeight) - viewPos[1];
541 }
542
543 int x = 0;
544 // TODO: Put this in a config file/define
545 int columnWidth = 120;
546 for (int i = 0; i < mColumnsPerPage + 1; i++) {
547 mTouchXBorders[i] = x - viewPos[0];
548 x += columnWidth;
549 }
550 }
551
552 int chooseTappedIcon(int x, int y) {
553 float pos = sRollo != null ? sRollo.mScrollPos : 0;
554
555 int oldY = y;
556
557 // Adjust for scroll position if not zero.
558 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
559
560 int col = -1;
561 int row = -1;
562 final int columnsCount = mColumnsPerPage;
563 for (int i=0; i< columnsCount; i++) {
564 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
565 col = i;
566 break;
567 }
568 }
569 final int rowsCount = mRowsPerPage;
570 for (int i=0; i< rowsCount; i++) {
571 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
572 row = i;
573 break;
574 }
575 }
576
577 if (row < 0 || col < 0) {
578 return -1;
579 }
580
581 int index = (((int) pos) * columnsCount) + (row * columnsCount) + col;
582
583 if (index >= mAllAppsList.size()) {
584 return -1;
585 } else {
586 return index;
587 }
588 }
589
Daniel Sandler388f6792010-03-02 14:08:08 -0500590 @Override
591 public boolean onTouchEvent(MotionEvent ev)
592 {
593 mArrowNavigation = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800594
Daniel Sandler388f6792010-03-02 14:08:08 -0500595 if (!isVisible()) {
596 return true;
597 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800598
Daniel Sandler388f6792010-03-02 14:08:08 -0500599 if (mLocks != 0) {
600 return true;
601 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800602
Daniel Sandler388f6792010-03-02 14:08:08 -0500603 super.onTouchEvent(ev);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800604
Daniel Sandler388f6792010-03-02 14:08:08 -0500605 int x = (int)ev.getX();
606 int y = (int)ev.getY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800607
Romain Guyce115852010-03-04 12:15:37 -0800608 final boolean isPortrait = getWidth() < getHeight();
Daniel Sandler388f6792010-03-02 14:08:08 -0500609 int action = ev.getAction();
610 switch (action) {
611 case MotionEvent.ACTION_DOWN:
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700612 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
613 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500614 mTouchTracking = TRACKING_HOME;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700615 sRollo.setHomeSelected(SELECTED_PRESSED);
616 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500617 mCurrentIconIndex = -1;
618 } else {
619 mTouchTracking = TRACKING_FLING;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800620
Daniel Sandler388f6792010-03-02 14:08:08 -0500621 mMotionDownRawX = (int)ev.getRawX();
622 mMotionDownRawY = (int)ev.getRawY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800623
Joe Onorato2cc62e82010-03-17 20:23:53 -0700624 sRollo.mState.newPositionX = ev.getRawY() / getHeight();
625 sRollo.mState.newTouchDown = 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800626
Joe Onorato2cc62e82010-03-17 20:23:53 -0700627 if (!sRollo.checkClickOK()) {
628 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500629 } else {
630 mDownIconIndex = mCurrentIconIndex
Joe Onorato2cc62e82010-03-17 20:23:53 -0700631 = sRollo.selectIcon(x, y, SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500632 if (mDownIconIndex < 0) {
633 // if nothing was selected, no long press.
634 cancelLongPress();
635 }
636 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700637 sRollo.mState.save();
638 sRollo.move();
Daniel Sandler388f6792010-03-02 14:08:08 -0500639 mVelocityTracker = VelocityTracker.obtain();
640 mVelocityTracker.addMovement(ev);
641 mStartedScrolling = false;
642 }
643 break;
644 case MotionEvent.ACTION_MOVE:
645 case MotionEvent.ACTION_OUTSIDE:
646 if (mTouchTracking == TRACKING_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700647 sRollo.setHomeSelected((isPortrait &&
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700648 y > mTouchYBorders[mTouchYBorders.length-1]) || (!isPortrait
649 && x > mTouchXBorders[mTouchXBorders.length-1])
Daniel Sandler388f6792010-03-02 14:08:08 -0500650 ? SELECTED_PRESSED : SELECTED_NONE);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700651 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500652 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500653 int rawY = (int)ev.getRawY();
654 int slop;
655 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800656
Daniel Sandler388f6792010-03-02 14:08:08 -0500657 if (!mStartedScrolling && slop < mSlop) {
658 // don't update anything so when we do start scrolling
659 // below, we get the right delta.
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700660 mCurrentIconIndex = chooseTappedIcon(x, y);
Daniel Sandler388f6792010-03-02 14:08:08 -0500661 if (mDownIconIndex != mCurrentIconIndex) {
662 // If a different icon is selected, don't allow it to be picked up.
663 // This handles off-axis dragging.
664 cancelLongPress();
665 mCurrentIconIndex = -1;
666 }
667 } else {
668 if (!mStartedScrolling) {
669 cancelLongPress();
670 mCurrentIconIndex = -1;
671 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700672 sRollo.mState.newPositionX = ev.getRawY() / getHeight();
673 sRollo.mState.newTouchDown = 1;
674 sRollo.move();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800675
Daniel Sandler388f6792010-03-02 14:08:08 -0500676 mStartedScrolling = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700677 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500678 mVelocityTracker.addMovement(ev);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700679 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500680 }
681 }
682 break;
683 case MotionEvent.ACTION_UP:
684 case MotionEvent.ACTION_CANCEL:
685 if (mTouchTracking == TRACKING_HOME) {
686 if (action == MotionEvent.ACTION_UP) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700687 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
688 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500689 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
690 mLauncher.closeAllApps(true);
691 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700692 sRollo.setHomeSelected(SELECTED_NONE);
693 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500694 }
695 mCurrentIconIndex = -1;
696 } else if (mTouchTracking == TRACKING_FLING) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700697 sRollo.mState.newTouchDown = 0;
698 sRollo.mState.newPositionX = ev.getRawY() / getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800699
Daniel Sandler388f6792010-03-02 14:08:08 -0500700 mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700701 sRollo.mState.flingVelocity = mVelocityTracker.getYVelocity() / getHeight();
702 sRollo.clearSelectedIcon();
703 sRollo.mState.save();
704 sRollo.fling();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800705
Daniel Sandler388f6792010-03-02 14:08:08 -0500706 if (mVelocityTracker != null) {
707 mVelocityTracker.recycle();
708 mVelocityTracker = null;
709 }
710 }
711 mTouchTracking = TRACKING_NONE;
712 break;
713 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800714
Daniel Sandler388f6792010-03-02 14:08:08 -0500715 return true;
716 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800717
Daniel Sandler388f6792010-03-02 14:08:08 -0500718 public void onClick(View v) {
719 if (mLocks != 0 || !isVisible()) {
720 return;
721 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700722 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500723 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
724 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
725 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onoratof984e852010-03-25 09:47:45 -0700726 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500727 }
728 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800729
Daniel Sandler388f6792010-03-02 14:08:08 -0500730 public boolean onLongClick(View v) {
731 if (mLocks != 0 || !isVisible()) {
732 return true;
733 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700734 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500735 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
736 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800737
Daniel Sandler388f6792010-03-02 14:08:08 -0500738 Bitmap bmp = app.iconBitmap;
739 final int w = bmp.getWidth();
740 final int h = bmp.getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800741
Daniel Sandler388f6792010-03-02 14:08:08 -0500742 // We don't really have an accurate location to use. This will do.
743 int screenX = mMotionDownRawX - (w / 2);
744 int screenY = mMotionDownRawY - h;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800745
Daniel Sandler388f6792010-03-02 14:08:08 -0500746 mDragController.startDrag(bmp, screenX, screenY,
747 0, 0, w, h, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800748
Daniel Sandler388f6792010-03-02 14:08:08 -0500749 mLauncher.closeAllApps(true);
750 }
751 return true;
752 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800753
Daniel Sandler388f6792010-03-02 14:08:08 -0500754 @Override
755 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
756 if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
757 if (!isVisible()) {
758 return false;
759 }
760 String text = null;
761 int index;
762 int count = mAllAppsList.size() + 1; // +1 is home
763 int pos = -1;
764 switch (mLastSelection) {
765 case SELECTION_ICONS:
Joe Onorato2cc62e82010-03-17 20:23:53 -0700766 index = sRollo.mState.selectedIconIndex;
Daniel Sandler388f6792010-03-02 14:08:08 -0500767 if (index >= 0) {
768 ApplicationInfo info = mAllAppsList.get(index);
769 if (info.title != null) {
770 text = info.title.toString();
771 pos = index;
772 }
773 }
774 break;
775 case SELECTION_HOME:
776 text = getContext().getString(R.string.all_apps_home_button_label);
777 pos = count;
778 break;
779 }
780 if (text != null) {
781 event.setEnabled(true);
782 event.getText().add(text);
783 //event.setContentDescription(text);
784 event.setItemCount(count);
785 event.setCurrentItemIndex(pos);
786 }
787 }
788 return false;
789 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800790
Daniel Sandler388f6792010-03-02 14:08:08 -0500791 public void setDragController(DragController dragger) {
792 mDragController = dragger;
793 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800794
Daniel Sandler388f6792010-03-02 14:08:08 -0500795 public void onDropCompleted(View target, boolean success) {
796 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800797
Daniel Sandler388f6792010-03-02 14:08:08 -0500798 /**
799 * Zoom to the specifed level.
800 *
801 * @param zoom [0..1] 0 is hidden, 1 is open
802 */
803 public void zoom(float zoom, boolean animate) {
804 cancelLongPress();
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700805 sNextZoom = zoom;
806 sAnimateNextZoom = animate;
Daniel Sandler388f6792010-03-02 14:08:08 -0500807 // if we do setZoom while we don't have a surface, we won't
808 // get the callbacks that actually set mZoom.
Joe Onorato2cc62e82010-03-17 20:23:53 -0700809 if (sRollo == null || !mHaveSurface) {
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700810 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500811 mZoom = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500812 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700813 sRollo.setZoom(zoom, animate);
Daniel Sandler388f6792010-03-02 14:08:08 -0500814 }
815 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800816
Joe Onorato878f0862010-03-22 12:22:22 -0400817 /**
818 * If sRollo is null, then we're not visible. This is also used to guard against
819 * sRollo being null.
820 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500821 public boolean isVisible() {
Joe Onorato878f0862010-03-22 12:22:22 -0400822 return sRollo != null && mZoom > 0.001f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500823 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800824
Daniel Sandler388f6792010-03-02 14:08:08 -0500825 public boolean isOpaque() {
826 return mZoom > 0.999f;
827 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800828
Daniel Sandler388f6792010-03-02 14:08:08 -0500829 public void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700830 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500831 // We've been removed from the window. Don't bother with all this.
832 return;
833 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800834
Daniel Sandler707b0f72010-04-15 16:41:31 -0400835 if (list != null) {
836 Collections.sort(list, LauncherModel.APP_NAME_COMPARATOR);
837 }
838
Romain Guy13c2e7b2010-03-10 19:45:00 -0800839 boolean reload = false;
840 if (mAllAppsList == null) {
841 reload = true;
842 } else if (list.size() != mAllAppsList.size()) {
843 reload = true;
844 } else {
845 final int count = list.size();
846 for (int i = 0; i < count; i++) {
847 if (list.get(i) != mAllAppsList.get(i)) {
848 reload = true;
849 break;
850 }
851 }
852 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800853
Daniel Sandler388f6792010-03-02 14:08:08 -0500854 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700855 if (sRollo != null && reload) {
856 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500857 }
Romain Guyc16fea72010-03-12 17:17:56 -0800858
859 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700860 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
861 sRollo.mState.save();
Romain Guyc16fea72010-03-12 17:17:56 -0800862 mRestoreFocusIndex = -1;
863 }
864
Daniel Sandler388f6792010-03-02 14:08:08 -0500865 mLocks &= ~LOCK_ICONS_PENDING;
866 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800867
Daniel Sandler388f6792010-03-02 14:08:08 -0500868 public void addApps(ArrayList<ApplicationInfo> list) {
869 if (mAllAppsList == null) {
870 // Not done loading yet. We'll find out about it later.
871 return;
872 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700873 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500874 // We've been removed from the window. Don't bother with all this.
875 return;
876 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800877
Daniel Sandler388f6792010-03-02 14:08:08 -0500878 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700879 if (sRollo != null) {
880 sRollo.pause();
881 sRollo.reallocAppsList(sRollo.mState.iconCount + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500882 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800883
Daniel Sandler388f6792010-03-02 14:08:08 -0500884 for (int i=0; i<N; i++) {
885 final ApplicationInfo item = list.get(i);
886 int index = Collections.binarySearch(mAllAppsList, item,
887 LauncherModel.APP_NAME_COMPARATOR);
888 if (index < 0) {
889 index = -(index+1);
890 }
891 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700892 if (sRollo != null) {
893 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500894 }
895 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800896
Joe Onorato2cc62e82010-03-17 20:23:53 -0700897 if (sRollo != null) {
898 sRollo.saveAppsList();
899 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500900 }
901 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800902
Daniel Sandler388f6792010-03-02 14:08:08 -0500903 public void removeApps(ArrayList<ApplicationInfo> list) {
904 if (mAllAppsList == null) {
905 // Not done loading yet. We'll find out about it later.
906 return;
907 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800908
Joe Onorato2cc62e82010-03-17 20:23:53 -0700909 if (sRollo != null) {
910 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800911 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500912 final int N = list.size();
913 for (int i=0; i<N; i++) {
914 final ApplicationInfo item = list.get(i);
915 int index = findAppByComponent(mAllAppsList, item);
916 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500917 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700918 if (sRollo != null) {
919 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500920 }
921 } else {
922 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
923 // Try to recover. This should keep us from crashing for now.
924 }
925 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800926
Joe Onorato2cc62e82010-03-17 20:23:53 -0700927 if (sRollo != null) {
928 sRollo.saveAppsList();
929 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500930 }
931 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800932
Joe Onorato64e6be72010-03-05 15:05:52 -0500933 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500934 // Just remove and add, because they may need to be re-sorted.
935 removeApps(list);
936 addApps(list);
937 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800938
Daniel Sandler388f6792010-03-02 14:08:08 -0500939 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
940 ComponentName component = item.intent.getComponent();
941 final int N = list.size();
942 for (int i=0; i<N; i++) {
943 ApplicationInfo x = list.get(i);
944 if (x.intent.getComponent().equals(component)) {
945 return i;
946 }
947 }
948 return -1;
949 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800950
Romain Guy060b5c82010-03-04 10:07:38 -0800951 /*
Daniel Sandler388f6792010-03-02 14:08:08 -0500952 private static int countPages(int iconCount) {
Romain Guy060b5c82010-03-04 10:07:38 -0800953 int iconsPerPage = getColumnsCount() * Defines.ROWS_PER_PAGE_PORTRAIT;
Daniel Sandler388f6792010-03-02 14:08:08 -0500954 int pages = iconCount / iconsPerPage;
955 if (pages*iconsPerPage != iconCount) {
956 pages++;
957 }
958 return pages;
959 }
Romain Guy060b5c82010-03-04 10:07:38 -0800960 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500961
962 class AAMessage extends RenderScript.RSMessage {
963 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700964 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500965 mVelocity = ((float)mData[1]) / (1 << 16);
966 mZoom = ((float)mData[2]) / (1 << 16);
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700967 sZoomDirty = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500968 }
969 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800970
Romain Guy13c2e7b2010-03-10 19:45:00 -0800971 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500972 // Allocations ======
973 private int mWidth;
974 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800975
Daniel Sandler388f6792010-03-02 14:08:08 -0500976 private Resources mRes;
977 private Script mScript;
978 private Script.Invokable mInvokeMove;
979 private Script.Invokable mInvokeMoveTo;
980 private Script.Invokable mInvokeFling;
981 private Script.Invokable mInvokeResetWAR;
982 private Script.Invokable mInvokeSetZoom;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800983
Daniel Sandler388f6792010-03-02 14:08:08 -0500984 private ProgramStore mPSIcons;
985 private ProgramFragment mPFTexMip;
986 private ProgramFragment mPFTexMipAlpha;
987 private ProgramFragment mPFTexNearest;
988 private ProgramVertex mPV;
989 private ProgramVertex mPVCurve;
990 private SimpleMesh mMesh;
991 private ProgramVertex.MatrixAllocation mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800992
Daniel Sandler388f6792010-03-02 14:08:08 -0500993 private Allocation mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800994
Daniel Sandler388f6792010-03-02 14:08:08 -0500995 private Allocation mHomeButtonNormal;
996 private Allocation mHomeButtonFocused;
997 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800998
Daniel Sandler388f6792010-03-02 14:08:08 -0500999 private Allocation[] mIcons;
1000 private int[] mIconIds;
1001 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001002
Daniel Sandler388f6792010-03-02 14:08:08 -05001003 private Allocation[] mLabels;
1004 private int[] mLabelIds;
1005 private Allocation mAllocLabelIds;
1006 private Allocation mSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001007
Daniel Sandler388f6792010-03-02 14:08:08 -05001008 private Bitmap mSelectionBitmap;
1009 private Canvas mSelectionCanvas;
Romain Guy6a42cf32010-03-12 16:03:52 -08001010
1011 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001012
Daniel Sandler388f6792010-03-02 14:08:08 -05001013 Params mParams;
1014 State mState;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001015
Romain Guy13c2e7b2010-03-10 19:45:00 -08001016 AllApps3D mAllApps;
1017 boolean mInitialize;
1018
Daniel Sandler388f6792010-03-02 14:08:08 -05001019 class BaseAlloc {
1020 Allocation mAlloc;
1021 Type mType;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001022
Daniel Sandler388f6792010-03-02 14:08:08 -05001023 void save() {
1024 mAlloc.data(this);
1025 }
1026 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001027
Daniel Sandler388f6792010-03-02 14:08:08 -05001028 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001029 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -08001030 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -05001031 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001032
1033 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001034 if (sRS != null) {
1035 sRS.contextBindRootScript(null);
1036 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001037 }
1038
1039 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001040 if (sRS != null) {
1041 sRS.contextBindRootScript(mScript);
1042 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001043 }
1044
Daniel Sandler388f6792010-03-02 14:08:08 -05001045 class Params extends BaseAlloc {
1046 Params() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001047 mType = Type.createFromClass(sRS, Params.class, 1, "ParamsClass");
1048 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001049 save();
1050 }
1051 public int bubbleWidth;
1052 public int bubbleHeight;
1053 public int bubbleBitmapWidth;
1054 public int bubbleBitmapHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001055
Daniel Sandler388f6792010-03-02 14:08:08 -05001056 public int homeButtonWidth;
1057 public int homeButtonHeight;
1058 public int homeButtonTextureWidth;
1059 public int homeButtonTextureHeight;
1060 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001061
Daniel Sandler388f6792010-03-02 14:08:08 -05001062 class State extends BaseAlloc {
1063 public float newPositionX;
1064 public int newTouchDown;
1065 public float flingVelocity;
1066 public int iconCount;
1067 public int selectedIconIndex = -1;
1068 public int selectedIconTexture;
1069 public float zoomTarget;
1070 public int homeButtonId;
1071 public float targetPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001072
Daniel Sandler388f6792010-03-02 14:08:08 -05001073 State() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001074 mType = Type.createFromClass(sRS, State.class, 1, "StateClass");
1075 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001076 save();
1077 }
1078 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001079
Romain Guy13c2e7b2010-03-10 19:45:00 -08001080 public RolloRS(AllApps3D allApps) {
1081 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -05001082 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001083
Daniel Sandler388f6792010-03-02 14:08:08 -05001084 public void init(Resources res, int width, int height) {
1085 mRes = res;
1086 mWidth = width;
1087 mHeight = height;
1088 initProgramVertex();
1089 initProgramFragment();
1090 initProgramStore();
1091 initGl();
1092 initData();
Daniel Sandler388f6792010-03-02 14:08:08 -05001093 initRs();
1094 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001095
Daniel Sandler388f6792010-03-02 14:08:08 -05001096 public void initMesh() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001097 SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001098
Daniel Sandler388f6792010-03-02 14:08:08 -05001099 for (int ct=0; ct < 16; ct++) {
1100 float pos = (1.f / (16.f - 1)) * ct;
1101 tm.addVertex(0.0f, pos);
1102 tm.addVertex(1.0f, pos);
1103 }
1104 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1105 tm.addTriangle(ct, ct+1, ct+2);
1106 tm.addTriangle(ct+1, ct+3, ct+2);
1107 }
1108 mMesh = tm.create();
1109 mMesh.setName("SMCell");
1110 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001111
Daniel Sandler388f6792010-03-02 14:08:08 -05001112 void resize(int w, int h) {
1113 mPVA.setupProjectionNormalized(w, h);
1114 mWidth = w;
1115 mHeight = h;
1116 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001117
Daniel Sandler388f6792010-03-02 14:08:08 -05001118 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001119 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001120 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001121
Joe Onorato2cc62e82010-03-17 20:23:53 -07001122 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001123 pvb.setTextureMatrixEnable(true);
1124 mPV = pvb.create();
1125 mPV.setName("PV");
1126 mPV.bindAllocation(mPVA);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001127
Joe Onorato2cc62e82010-03-17 20:23:53 -07001128 Element.Builder eb = new Element.Builder(sRS);
1129 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "ImgSize");
1130 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "Position");
1131 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "BendPos");
1132 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "ScaleOffset");
Daniel Sandler388f6792010-03-02 14:08:08 -05001133 Element e = eb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001134
Joe Onorato2cc62e82010-03-17 20:23:53 -07001135 mUniformAlloc = Allocation.createSized(sRS, e, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001136
Daniel Sandler388f6792010-03-02 14:08:08 -05001137 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001138 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Romain Guy060b5c82010-03-04 10:07:38 -08001139 String t = "void main() {\n" +
1140 // Animation
1141 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001142
Romain Guy060b5c82010-03-04 10:07:38 -08001143 " float bendY1 = UNI_BendPos.x;\n" +
1144 " float bendY2 = UNI_BendPos.y;\n" +
1145 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1146 " float bendDistance = bendY1 * 0.4;\n" +
1147 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001148
Romain Guy060b5c82010-03-04 10:07:38 -08001149 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1150 " float aDy = cos(bendAngle);\n" +
1151 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001152
Romain Guy060b5c82010-03-04 10:07:38 -08001153 " float scale = (2.0 / 480.0);\n" +
1154 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1155 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1156 " float y = 0.0;\n" +
1157 " float z = 0.0;\n" +
1158 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001159
Romain Guy060b5c82010-03-04 10:07:38 -08001160 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1161 " y += cv * aDy;\n" +
1162 " z += -cv * aDz;\n" +
1163 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1164 " lum += cv / bendDistance * distanceDimLevel;\n" +
1165 " y += cv * cos(cv * bendStep);\n" +
1166 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001167
Romain Guy060b5c82010-03-04 10:07:38 -08001168 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1169 " y += cv * aDy;\n" +
1170 " z += cv * aDz;\n" +
1171 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1172 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1173 " y += cv * cos(cv * bendStep);\n" +
1174 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001175
Romain Guy060b5c82010-03-04 10:07:38 -08001176 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001177
Romain Guy060b5c82010-03-04 10:07:38 -08001178 " vec4 pos;\n" +
1179 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1180 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1181 " pos.z = z * UNI_ScaleOffset.x;\n" +
1182 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001183
Romain Guy060b5c82010-03-04 10:07:38 -08001184 " pos.x *= 1.0 + ani * 4.0;\n" +
1185 " pos.y *= 1.0 + ani * 4.0;\n" +
1186 " pos.z -= ani * 1.5;\n" +
1187 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001188
Romain Guy060b5c82010-03-04 10:07:38 -08001189 " gl_Position = UNI_MVP * pos;\n" +
1190 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1191 " varTex0.xy = ATTRIB_position;\n" +
1192 " varTex0.y = 1.0 - varTex0.y;\n" +
1193 " varTex0.zw = vec2(0.0, 0.0);\n" +
1194 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001195 sb.setShader(t);
1196 sb.addConstant(mUniformAlloc.getType());
1197 sb.addInput(mMesh.getVertexType(0).getElement());
1198 mPVCurve = sb.create();
1199 mPVCurve.setName("PVCurve");
1200 mPVCurve.bindAllocation(mPVA);
1201 mPVCurve.bindConstants(mUniformAlloc, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001202
Joe Onorato2cc62e82010-03-17 20:23:53 -07001203 sRS.contextBindProgramVertex(mPV);
Daniel Sandler388f6792010-03-02 14:08:08 -05001204 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001205
Daniel Sandler388f6792010-03-02 14:08:08 -05001206 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001207 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001208 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1209 sb.setMag(Sampler.Value.NEAREST);
1210 sb.setWrapS(Sampler.Value.CLAMP);
1211 sb.setWrapT(Sampler.Value.CLAMP);
1212 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001213
Daniel Sandler388f6792010-03-02 14:08:08 -05001214 sb.setMin(Sampler.Value.NEAREST);
1215 sb.setMag(Sampler.Value.NEAREST);
1216 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001217
Joe Onorato2cc62e82010-03-17 20:23:53 -07001218 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001219 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1220 ProgramFragment.Builder.Format.RGBA, 0);
1221 mPFTexMip = bf.create();
1222 mPFTexMip.setName("PFTexMip");
1223 mPFTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001224
Daniel Sandler388f6792010-03-02 14:08:08 -05001225 mPFTexNearest = bf.create();
1226 mPFTexNearest.setName("PFTexNearest");
1227 mPFTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001228
Daniel Sandler388f6792010-03-02 14:08:08 -05001229 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1230 ProgramFragment.Builder.Format.ALPHA, 0);
1231 mPFTexMipAlpha = bf.create();
1232 mPFTexMipAlpha.setName("PFTexMipAlpha");
1233 mPFTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001234
Daniel Sandler388f6792010-03-02 14:08:08 -05001235 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001236
Daniel Sandler388f6792010-03-02 14:08:08 -05001237 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001238 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001239 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1240 bs.setColorMask(true,true,true,false);
1241 bs.setDitherEnable(true);
1242 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1243 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
1244 mPSIcons = bs.create();
1245 mPSIcons.setName("PSIcons");
1246 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001247
Daniel Sandler388f6792010-03-02 14:08:08 -05001248 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001249 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001250
Daniel Sandler388f6792010-03-02 14:08:08 -05001251 private void initData() {
1252 mParams = new Params();
1253 mState = new State();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001254
Romain Guy13c2e7b2010-03-10 19:45:00 -08001255 final Utilities.BubbleText bubble = new Utilities.BubbleText(mAllApps.getContext());
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001256
Daniel Sandler388f6792010-03-02 14:08:08 -05001257 mParams.bubbleWidth = bubble.getBubbleWidth();
1258 mParams.bubbleHeight = bubble.getMaxBubbleHeight();
1259 mParams.bubbleBitmapWidth = bubble.getBitmapWidth();
1260 mParams.bubbleBitmapHeight = bubble.getBitmapHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001261
Joe Onorato2cc62e82010-03-17 20:23:53 -07001262 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1263 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001264 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001265 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1266 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001267 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001268 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1269 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001270 mHomeButtonPressed.uploadToTexture(0);
1271 mParams.homeButtonWidth = 76;
1272 mParams.homeButtonHeight = 68;
1273 mParams.homeButtonTextureWidth = 128;
1274 mParams.homeButtonTextureHeight = 128;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001275
Daniel Sandler388f6792010-03-02 14:08:08 -05001276 mState.homeButtonId = mHomeButtonNormal.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001277
Daniel Sandler388f6792010-03-02 14:08:08 -05001278 mParams.save();
1279 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001280
Daniel Sandler388f6792010-03-02 14:08:08 -05001281 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1282 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1283 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001284
Daniel Sandler388f6792010-03-02 14:08:08 -05001285 setApps(null);
1286 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001287
Daniel Sandler388f6792010-03-02 14:08:08 -05001288 private void initRs() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001289 ScriptC.Builder sb = new ScriptC.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001290 sb.setScript(mRes, R.raw.allapps);
1291 sb.setRoot(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001292 sb.addDefines(mAllApps.mDefines);
Daniel Sandler388f6792010-03-02 14:08:08 -05001293 sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS);
1294 sb.setType(mState.mType, "state", Defines.ALLOC_STATE);
1295 sb.setType(mUniformAlloc.getType(), "vpConstants", Defines.ALLOC_VP_CONSTANTS);
1296 mInvokeMove = sb.addInvokable("move");
1297 mInvokeFling = sb.addInvokable("fling");
1298 mInvokeMoveTo = sb.addInvokable("moveTo");
1299 mInvokeResetWAR = sb.addInvokable("resetHWWar");
1300 mInvokeSetZoom = sb.addInvokable("setZoom");
1301 mScript = sb.create();
1302 mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1303 mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
1304 mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
1305 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1306 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
1307 mScript.bindAllocation(mUniformAlloc, Defines.ALLOC_VP_CONSTANTS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001308
Joe Onorato2cc62e82010-03-17 20:23:53 -07001309 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -05001310 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001311
Daniel Sandler388f6792010-03-02 14:08:08 -05001312 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001313 if (sZoomDirty) {
1314 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001315 }
1316 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001317
Romain Guy060b5c82010-03-04 10:07:38 -08001318 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001319 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001320 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001321 final int count = list != null ? list.size() : 0;
1322 int allocCount = count;
1323 if (allocCount < 1) {
1324 allocCount = 1;
1325 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001326
Daniel Sandler388f6792010-03-02 14:08:08 -05001327 mIcons = new Allocation[count];
1328 mIconIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001329 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001330
Daniel Sandler388f6792010-03-02 14:08:08 -05001331 mLabels = new Allocation[count];
1332 mLabelIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001333 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001334
Daniel Sandler388f6792010-03-02 14:08:08 -05001335 mState.iconCount = count;
1336 for (int i=0; i < mState.iconCount; i++) {
1337 createAppIconAllocations(i, list.get(i));
1338 }
1339 for (int i=0; i < mState.iconCount; i++) {
1340 uploadAppIcon(i, list.get(i));
1341 }
1342 saveAppsList();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001343 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001344 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001345
Daniel Sandler388f6792010-03-02 14:08:08 -05001346 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001347 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001348 sRollo.clearSelectedIcon();
1349 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001350 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001351 if (zoom > 0.001f) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001352 sRollo.mState.zoomTarget = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -05001353 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001354 sRollo.mState.zoomTarget = 0;
Daniel Sandler388f6792010-03-02 14:08:08 -05001355 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001356 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -05001357 if (!animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001358 sRollo.mInvokeSetZoom.execute();
Daniel Sandler388f6792010-03-02 14:08:08 -05001359 }
1360 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001361
Daniel Sandler388f6792010-03-02 14:08:08 -05001362 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001363 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1364 Element.RGBA_8888(sRS), false);
1365 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1366 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001367 mIconIds[index] = mIcons[index].getID();
1368 mLabelIds[index] = mLabels[index].getID();
1369 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001370
Daniel Sandler388f6792010-03-02 14:08:08 -05001371 private void uploadAppIcon(int index, ApplicationInfo item) {
1372 if (mIconIds[index] != mIcons[index].getID()) {
1373 throw new IllegalStateException("uploadAppIcon index=" + index
1374 + " mIcons[index].getID=" + mIcons[index].getID()
1375 + " mIconsIds[index]=" + mIconIds[index]
1376 + " item=" + item);
1377 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001378 mIcons[index].uploadToTexture(true, 0);
1379 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001380 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001381
Daniel Sandler388f6792010-03-02 14:08:08 -05001382 /**
1383 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1384 * fill in the values and call saveAppsList().
1385 */
1386 private void reallocAppsList(int count) {
1387 Allocation[] icons = new Allocation[count];
1388 int[] iconIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001389 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001390
Daniel Sandler388f6792010-03-02 14:08:08 -05001391 Allocation[] labels = new Allocation[count];
1392 int[] labelIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001393 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001394
Joe Onorato2cc62e82010-03-17 20:23:53 -07001395 final int oldCount = sRollo.mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001396
Daniel Sandler388f6792010-03-02 14:08:08 -05001397 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1398 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1399 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1400 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001401
Daniel Sandler388f6792010-03-02 14:08:08 -05001402 mIcons = icons;
1403 mIconIds = iconIds;
1404 mLabels = labels;
1405 mLabelIds = labelIds;
1406 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001407
Daniel Sandler388f6792010-03-02 14:08:08 -05001408 /**
1409 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1410 */
1411 private void addApp(int index, ApplicationInfo item) {
1412 final int count = mState.iconCount - index;
1413 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001414
Daniel Sandler388f6792010-03-02 14:08:08 -05001415 System.arraycopy(mIcons, index, mIcons, dest, count);
1416 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1417 System.arraycopy(mLabels, index, mLabels, dest, count);
1418 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001419
Daniel Sandler388f6792010-03-02 14:08:08 -05001420 createAppIconAllocations(index, item);
1421 uploadAppIcon(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001422 sRollo.mState.iconCount++;
Daniel Sandler388f6792010-03-02 14:08:08 -05001423 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001424
Daniel Sandler388f6792010-03-02 14:08:08 -05001425 /**
1426 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1427 */
1428 private void removeApp(int index) {
1429 final int count = mState.iconCount - index - 1;
1430 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001431
Daniel Sandler388f6792010-03-02 14:08:08 -05001432 System.arraycopy(mIcons, src, mIcons, index, count);
1433 System.arraycopy(mIconIds, src, mIconIds, index, count);
1434 System.arraycopy(mLabels, src, mLabels, index, count);
1435 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001436
Joe Onorato2cc62e82010-03-17 20:23:53 -07001437 sRollo.mState.iconCount--;
Daniel Sandler388f6792010-03-02 14:08:08 -05001438 final int last = mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001439
Daniel Sandler388f6792010-03-02 14:08:08 -05001440 mIcons[last] = null;
1441 mIconIds[last] = 0;
1442 mLabels[last] = null;
1443 mLabelIds[last] = 0;
1444 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001445
Daniel Sandler388f6792010-03-02 14:08:08 -05001446 /**
1447 * Send the apps list structures to RS.
1448 */
1449 private void saveAppsList() {
1450 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1451 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001452 mAllocIconIds.data(mIconIds);
1453 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001454
Daniel Sandler388f6792010-03-02 14:08:08 -05001455 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1456 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001457
Daniel Sandler388f6792010-03-02 14:08:08 -05001458 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001459
Daniel Sandler388f6792010-03-02 14:08:08 -05001460 // Note: mScript may be null if we haven't initialized it yet.
1461 // In that case, this is a no-op.
1462 if (mInvokeResetWAR != null) {
1463 mInvokeResetWAR.execute();
1464 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001465 }
1466 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001467
Daniel Sandler388f6792010-03-02 14:08:08 -05001468 void fling() {
1469 mInvokeFling.execute();
1470 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001471
Daniel Sandler388f6792010-03-02 14:08:08 -05001472 void move() {
1473 mInvokeMove.execute();
1474 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001475
Daniel Sandler388f6792010-03-02 14:08:08 -05001476 void moveTo(float row) {
1477 mState.targetPos = row;
1478 mState.save();
1479 mInvokeMoveTo.execute();
1480 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001481
Daniel Sandler388f6792010-03-02 14:08:08 -05001482 /**
1483 * You need to call save() on mState on your own after calling this.
1484 *
1485 * @return the index of the icon that was selected.
1486 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001487 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001488 if (mAllApps != null) {
1489 final int index = mAllApps.chooseTappedIcon(x, y);
1490 selectIcon(index, pressed);
1491 return index;
1492 } else {
1493 return -1;
1494 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001495 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001496
Daniel Sandler388f6792010-03-02 14:08:08 -05001497 /**
1498 * Select the icon at the given index.
1499 *
1500 * @param index The index.
1501 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1502 */
1503 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001504 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1505 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001506 if (mAllApps != null) {
1507 mAllApps.mRestoreFocusIndex = index;
1508 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001509 mState.selectedIconIndex = -1;
Romain Guy13c2e7b2010-03-10 19:45:00 -08001510 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1511 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001512 }
1513 } else {
1514 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001515 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001516 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001517
Daniel Sandler388f6792010-03-02 14:08:08 -05001518 int prev = mState.selectedIconIndex;
1519 mState.selectedIconIndex = index;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001520
Romain Guy13c2e7b2010-03-10 19:45:00 -08001521 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001522 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001523
Daniel Sandler388f6792010-03-02 14:08:08 -05001524 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1525 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1526 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001527
Joe Onorato2cc62e82010-03-17 20:23:53 -07001528 mSelectedIcon = Allocation.createFromBitmap(sRS, selectionBitmap,
1529 Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001530 mSelectedIcon.uploadToTexture(0);
1531 mState.selectedIconTexture = mSelectedIcon.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001532
Daniel Sandler388f6792010-03-02 14:08:08 -05001533 if (prev != index) {
1534 if (info.title != null && info.title.length() > 0) {
1535 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001536 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001537 }
1538 }
1539 }
1540 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001541
Daniel Sandler388f6792010-03-02 14:08:08 -05001542 /**
1543 * You need to call save() on mState on your own after calling this.
1544 */
1545 void clearSelectedIcon() {
1546 mState.selectedIconIndex = -1;
1547 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001548
Daniel Sandler388f6792010-03-02 14:08:08 -05001549 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001550 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001551 switch (mode) {
1552 case SELECTED_NONE:
1553 mState.homeButtonId = mHomeButtonNormal.getID();
1554 break;
1555 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001556 mAllApps.mLastSelection = SELECTION_HOME;
Daniel Sandler388f6792010-03-02 14:08:08 -05001557 mState.homeButtonId = mHomeButtonFocused.getID();
1558 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001559 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001560 }
1561 break;
1562 case SELECTED_PRESSED:
1563 mState.homeButtonId = mHomeButtonPressed.getID();
1564 break;
1565 }
1566 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001567
Daniel Sandler388f6792010-03-02 14:08:08 -05001568 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001569 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1570 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1571 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001572 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001573 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001574 }
1575 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001576 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001577 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001578 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001579 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001580 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001581 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001582 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Joe Onorato2cc62e82010-03-17 20:23:53 -07001583 Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1584 Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1585 Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1586 Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1587 Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1588 Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1589 Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1590 Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1591 Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
1592 Log.d(TAG, "sRollo.mParams.bubbleWidth=" + mParams.bubbleWidth);
1593 Log.d(TAG, "sRollo.mParams.bubbleHeight=" + mParams.bubbleHeight);
1594 Log.d(TAG, "sRollo.mParams.bubbleBitmapWidth=" + mParams.bubbleBitmapWidth);
1595 Log.d(TAG, "sRollo.mParams.bubbleBitmapHeight=" + mParams.bubbleBitmapHeight);
1596 Log.d(TAG, "sRollo.mParams.homeButtonWidth=" + mParams.homeButtonWidth);
1597 Log.d(TAG, "sRollo.mParams.homeButtonHeight=" + mParams.homeButtonHeight);
1598 Log.d(TAG, "sRollo.mParams.homeButtonTextureWidth=" + mParams.homeButtonTextureWidth);
1599 Log.d(TAG, "sRollo.mParams.homeButtonTextureHeight=" + mParams.homeButtonTextureHeight);
Daniel Sandler388f6792010-03-02 14:08:08 -05001600 }
1601 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001602
Daniel Sandlerdca66122010-04-13 16:23:58 -04001603 public int getAppBatchSize() {
1604 return BATCH_SIZE;
1605 }
1606
Daniel Sandler388f6792010-03-02 14:08:08 -05001607 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001608 Log.d(TAG, "sRS=" + sRS);
1609 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001610 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001611 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1612 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001613 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1614 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1615 Log.d(TAG, "mLastSelection=" + mLastSelection);
1616 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1617 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1618 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1619 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001620 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1621 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001622 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001623 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001624 Log.d(TAG, "mVelocity=" + mVelocity);
1625 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001626 if (sRollo != null) {
1627 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001628 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001629 if (sRS != null) {
1630 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001631 }
1632 }
1633}
1634
1635