blob: 9d3de0b79cd3ddb3d8b1d8ba449427cf30fe501a [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
835 boolean reload = false;
836 if (mAllAppsList == null) {
837 reload = true;
838 } else if (list.size() != mAllAppsList.size()) {
839 reload = true;
840 } else {
841 final int count = list.size();
842 for (int i = 0; i < count; i++) {
843 if (list.get(i) != mAllAppsList.get(i)) {
844 reload = true;
845 break;
846 }
847 }
848 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800849
Daniel Sandler388f6792010-03-02 14:08:08 -0500850 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700851 if (sRollo != null && reload) {
852 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500853 }
Romain Guyc16fea72010-03-12 17:17:56 -0800854
855 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700856 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
857 sRollo.mState.save();
Romain Guyc16fea72010-03-12 17:17:56 -0800858 mRestoreFocusIndex = -1;
859 }
860
Daniel Sandler388f6792010-03-02 14:08:08 -0500861 mLocks &= ~LOCK_ICONS_PENDING;
862 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800863
Daniel Sandler388f6792010-03-02 14:08:08 -0500864 public void addApps(ArrayList<ApplicationInfo> list) {
865 if (mAllAppsList == null) {
866 // Not done loading yet. We'll find out about it later.
867 return;
868 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700869 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500870 // We've been removed from the window. Don't bother with all this.
871 return;
872 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800873
Daniel Sandler388f6792010-03-02 14:08:08 -0500874 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700875 if (sRollo != null) {
876 sRollo.pause();
877 sRollo.reallocAppsList(sRollo.mState.iconCount + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500878 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800879
Daniel Sandler388f6792010-03-02 14:08:08 -0500880 for (int i=0; i<N; i++) {
881 final ApplicationInfo item = list.get(i);
882 int index = Collections.binarySearch(mAllAppsList, item,
883 LauncherModel.APP_NAME_COMPARATOR);
884 if (index < 0) {
885 index = -(index+1);
886 }
887 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700888 if (sRollo != null) {
889 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500890 }
891 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800892
Joe Onorato2cc62e82010-03-17 20:23:53 -0700893 if (sRollo != null) {
894 sRollo.saveAppsList();
895 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500896 }
897 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800898
Daniel Sandler388f6792010-03-02 14:08:08 -0500899 public void removeApps(ArrayList<ApplicationInfo> list) {
900 if (mAllAppsList == null) {
901 // Not done loading yet. We'll find out about it later.
902 return;
903 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800904
Joe Onorato2cc62e82010-03-17 20:23:53 -0700905 if (sRollo != null) {
906 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800907 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500908 final int N = list.size();
909 for (int i=0; i<N; i++) {
910 final ApplicationInfo item = list.get(i);
911 int index = findAppByComponent(mAllAppsList, item);
912 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500913 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700914 if (sRollo != null) {
915 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500916 }
917 } else {
918 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
919 // Try to recover. This should keep us from crashing for now.
920 }
921 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800922
Joe Onorato2cc62e82010-03-17 20:23:53 -0700923 if (sRollo != null) {
924 sRollo.saveAppsList();
925 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500926 }
927 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800928
Joe Onorato64e6be72010-03-05 15:05:52 -0500929 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500930 // Just remove and add, because they may need to be re-sorted.
931 removeApps(list);
932 addApps(list);
933 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800934
Daniel Sandler388f6792010-03-02 14:08:08 -0500935 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
936 ComponentName component = item.intent.getComponent();
937 final int N = list.size();
938 for (int i=0; i<N; i++) {
939 ApplicationInfo x = list.get(i);
940 if (x.intent.getComponent().equals(component)) {
941 return i;
942 }
943 }
944 return -1;
945 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800946
Romain Guy060b5c82010-03-04 10:07:38 -0800947 /*
Daniel Sandler388f6792010-03-02 14:08:08 -0500948 private static int countPages(int iconCount) {
Romain Guy060b5c82010-03-04 10:07:38 -0800949 int iconsPerPage = getColumnsCount() * Defines.ROWS_PER_PAGE_PORTRAIT;
Daniel Sandler388f6792010-03-02 14:08:08 -0500950 int pages = iconCount / iconsPerPage;
951 if (pages*iconsPerPage != iconCount) {
952 pages++;
953 }
954 return pages;
955 }
Romain Guy060b5c82010-03-04 10:07:38 -0800956 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500957
958 class AAMessage extends RenderScript.RSMessage {
959 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700960 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500961 mVelocity = ((float)mData[1]) / (1 << 16);
962 mZoom = ((float)mData[2]) / (1 << 16);
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700963 sZoomDirty = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500964 }
965 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800966
Romain Guy13c2e7b2010-03-10 19:45:00 -0800967 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500968 // Allocations ======
969 private int mWidth;
970 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800971
Daniel Sandler388f6792010-03-02 14:08:08 -0500972 private Resources mRes;
973 private Script mScript;
974 private Script.Invokable mInvokeMove;
975 private Script.Invokable mInvokeMoveTo;
976 private Script.Invokable mInvokeFling;
977 private Script.Invokable mInvokeResetWAR;
978 private Script.Invokable mInvokeSetZoom;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800979
Daniel Sandler388f6792010-03-02 14:08:08 -0500980 private ProgramStore mPSIcons;
981 private ProgramFragment mPFTexMip;
982 private ProgramFragment mPFTexMipAlpha;
983 private ProgramFragment mPFTexNearest;
984 private ProgramVertex mPV;
985 private ProgramVertex mPVCurve;
986 private SimpleMesh mMesh;
987 private ProgramVertex.MatrixAllocation mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800988
Daniel Sandler388f6792010-03-02 14:08:08 -0500989 private Allocation mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800990
Daniel Sandler388f6792010-03-02 14:08:08 -0500991 private Allocation mHomeButtonNormal;
992 private Allocation mHomeButtonFocused;
993 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800994
Daniel Sandler388f6792010-03-02 14:08:08 -0500995 private Allocation[] mIcons;
996 private int[] mIconIds;
997 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800998
Daniel Sandler388f6792010-03-02 14:08:08 -0500999 private Allocation[] mLabels;
1000 private int[] mLabelIds;
1001 private Allocation mAllocLabelIds;
1002 private Allocation mSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001003
Daniel Sandler388f6792010-03-02 14:08:08 -05001004 private Bitmap mSelectionBitmap;
1005 private Canvas mSelectionCanvas;
Romain Guy6a42cf32010-03-12 16:03:52 -08001006
1007 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001008
Daniel Sandler388f6792010-03-02 14:08:08 -05001009 Params mParams;
1010 State mState;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001011
Romain Guy13c2e7b2010-03-10 19:45:00 -08001012 AllApps3D mAllApps;
1013 boolean mInitialize;
1014
Daniel Sandler388f6792010-03-02 14:08:08 -05001015 class BaseAlloc {
1016 Allocation mAlloc;
1017 Type mType;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001018
Daniel Sandler388f6792010-03-02 14:08:08 -05001019 void save() {
1020 mAlloc.data(this);
1021 }
1022 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001023
Daniel Sandler388f6792010-03-02 14:08:08 -05001024 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001025 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -08001026 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -05001027 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001028
1029 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001030 if (sRS != null) {
1031 sRS.contextBindRootScript(null);
1032 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001033 }
1034
1035 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001036 if (sRS != null) {
1037 sRS.contextBindRootScript(mScript);
1038 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001039 }
1040
Daniel Sandler388f6792010-03-02 14:08:08 -05001041 class Params extends BaseAlloc {
1042 Params() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001043 mType = Type.createFromClass(sRS, Params.class, 1, "ParamsClass");
1044 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001045 save();
1046 }
1047 public int bubbleWidth;
1048 public int bubbleHeight;
1049 public int bubbleBitmapWidth;
1050 public int bubbleBitmapHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001051
Daniel Sandler388f6792010-03-02 14:08:08 -05001052 public int homeButtonWidth;
1053 public int homeButtonHeight;
1054 public int homeButtonTextureWidth;
1055 public int homeButtonTextureHeight;
1056 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001057
Daniel Sandler388f6792010-03-02 14:08:08 -05001058 class State extends BaseAlloc {
1059 public float newPositionX;
1060 public int newTouchDown;
1061 public float flingVelocity;
1062 public int iconCount;
1063 public int selectedIconIndex = -1;
1064 public int selectedIconTexture;
1065 public float zoomTarget;
1066 public int homeButtonId;
1067 public float targetPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001068
Daniel Sandler388f6792010-03-02 14:08:08 -05001069 State() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001070 mType = Type.createFromClass(sRS, State.class, 1, "StateClass");
1071 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001072 save();
1073 }
1074 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001075
Romain Guy13c2e7b2010-03-10 19:45:00 -08001076 public RolloRS(AllApps3D allApps) {
1077 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -05001078 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001079
Daniel Sandler388f6792010-03-02 14:08:08 -05001080 public void init(Resources res, int width, int height) {
1081 mRes = res;
1082 mWidth = width;
1083 mHeight = height;
1084 initProgramVertex();
1085 initProgramFragment();
1086 initProgramStore();
1087 initGl();
1088 initData();
Daniel Sandler388f6792010-03-02 14:08:08 -05001089 initRs();
1090 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001091
Daniel Sandler388f6792010-03-02 14:08:08 -05001092 public void initMesh() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001093 SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001094
Daniel Sandler388f6792010-03-02 14:08:08 -05001095 for (int ct=0; ct < 16; ct++) {
1096 float pos = (1.f / (16.f - 1)) * ct;
1097 tm.addVertex(0.0f, pos);
1098 tm.addVertex(1.0f, pos);
1099 }
1100 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1101 tm.addTriangle(ct, ct+1, ct+2);
1102 tm.addTriangle(ct+1, ct+3, ct+2);
1103 }
1104 mMesh = tm.create();
1105 mMesh.setName("SMCell");
1106 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001107
Daniel Sandler388f6792010-03-02 14:08:08 -05001108 void resize(int w, int h) {
1109 mPVA.setupProjectionNormalized(w, h);
1110 mWidth = w;
1111 mHeight = h;
1112 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001113
Daniel Sandler388f6792010-03-02 14:08:08 -05001114 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001115 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001116 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001117
Joe Onorato2cc62e82010-03-17 20:23:53 -07001118 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001119 pvb.setTextureMatrixEnable(true);
1120 mPV = pvb.create();
1121 mPV.setName("PV");
1122 mPV.bindAllocation(mPVA);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001123
Joe Onorato2cc62e82010-03-17 20:23:53 -07001124 Element.Builder eb = new Element.Builder(sRS);
1125 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "ImgSize");
1126 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "Position");
1127 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "BendPos");
1128 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "ScaleOffset");
Daniel Sandler388f6792010-03-02 14:08:08 -05001129 Element e = eb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001130
Joe Onorato2cc62e82010-03-17 20:23:53 -07001131 mUniformAlloc = Allocation.createSized(sRS, e, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001132
Daniel Sandler388f6792010-03-02 14:08:08 -05001133 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001134 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Romain Guy060b5c82010-03-04 10:07:38 -08001135 String t = "void main() {\n" +
1136 // Animation
1137 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001138
Romain Guy060b5c82010-03-04 10:07:38 -08001139 " float bendY1 = UNI_BendPos.x;\n" +
1140 " float bendY2 = UNI_BendPos.y;\n" +
1141 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1142 " float bendDistance = bendY1 * 0.4;\n" +
1143 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001144
Romain Guy060b5c82010-03-04 10:07:38 -08001145 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1146 " float aDy = cos(bendAngle);\n" +
1147 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001148
Romain Guy060b5c82010-03-04 10:07:38 -08001149 " float scale = (2.0 / 480.0);\n" +
1150 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1151 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1152 " float y = 0.0;\n" +
1153 " float z = 0.0;\n" +
1154 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001155
Romain Guy060b5c82010-03-04 10:07:38 -08001156 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1157 " y += cv * aDy;\n" +
1158 " z += -cv * aDz;\n" +
1159 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1160 " lum += cv / bendDistance * distanceDimLevel;\n" +
1161 " y += cv * cos(cv * bendStep);\n" +
1162 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001163
Romain Guy060b5c82010-03-04 10:07:38 -08001164 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1165 " y += cv * aDy;\n" +
1166 " z += cv * aDz;\n" +
1167 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1168 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1169 " y += cv * cos(cv * bendStep);\n" +
1170 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001171
Romain Guy060b5c82010-03-04 10:07:38 -08001172 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001173
Romain Guy060b5c82010-03-04 10:07:38 -08001174 " vec4 pos;\n" +
1175 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1176 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1177 " pos.z = z * UNI_ScaleOffset.x;\n" +
1178 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001179
Romain Guy060b5c82010-03-04 10:07:38 -08001180 " pos.x *= 1.0 + ani * 4.0;\n" +
1181 " pos.y *= 1.0 + ani * 4.0;\n" +
1182 " pos.z -= ani * 1.5;\n" +
1183 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001184
Romain Guy060b5c82010-03-04 10:07:38 -08001185 " gl_Position = UNI_MVP * pos;\n" +
1186 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1187 " varTex0.xy = ATTRIB_position;\n" +
1188 " varTex0.y = 1.0 - varTex0.y;\n" +
1189 " varTex0.zw = vec2(0.0, 0.0);\n" +
1190 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001191 sb.setShader(t);
1192 sb.addConstant(mUniformAlloc.getType());
1193 sb.addInput(mMesh.getVertexType(0).getElement());
1194 mPVCurve = sb.create();
1195 mPVCurve.setName("PVCurve");
1196 mPVCurve.bindAllocation(mPVA);
1197 mPVCurve.bindConstants(mUniformAlloc, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001198
Joe Onorato2cc62e82010-03-17 20:23:53 -07001199 sRS.contextBindProgramVertex(mPV);
Daniel Sandler388f6792010-03-02 14:08:08 -05001200 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001201
Daniel Sandler388f6792010-03-02 14:08:08 -05001202 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001203 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001204 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1205 sb.setMag(Sampler.Value.NEAREST);
1206 sb.setWrapS(Sampler.Value.CLAMP);
1207 sb.setWrapT(Sampler.Value.CLAMP);
1208 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001209
Daniel Sandler388f6792010-03-02 14:08:08 -05001210 sb.setMin(Sampler.Value.NEAREST);
1211 sb.setMag(Sampler.Value.NEAREST);
1212 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001213
Joe Onorato2cc62e82010-03-17 20:23:53 -07001214 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001215 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1216 ProgramFragment.Builder.Format.RGBA, 0);
1217 mPFTexMip = bf.create();
1218 mPFTexMip.setName("PFTexMip");
1219 mPFTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001220
Daniel Sandler388f6792010-03-02 14:08:08 -05001221 mPFTexNearest = bf.create();
1222 mPFTexNearest.setName("PFTexNearest");
1223 mPFTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001224
Daniel Sandler388f6792010-03-02 14:08:08 -05001225 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1226 ProgramFragment.Builder.Format.ALPHA, 0);
1227 mPFTexMipAlpha = bf.create();
1228 mPFTexMipAlpha.setName("PFTexMipAlpha");
1229 mPFTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001230
Daniel Sandler388f6792010-03-02 14:08:08 -05001231 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001232
Daniel Sandler388f6792010-03-02 14:08:08 -05001233 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001234 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001235 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1236 bs.setColorMask(true,true,true,false);
1237 bs.setDitherEnable(true);
1238 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1239 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
1240 mPSIcons = bs.create();
1241 mPSIcons.setName("PSIcons");
1242 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001243
Daniel Sandler388f6792010-03-02 14:08:08 -05001244 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001245 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001246
Daniel Sandler388f6792010-03-02 14:08:08 -05001247 private void initData() {
1248 mParams = new Params();
1249 mState = new State();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001250
Romain Guy13c2e7b2010-03-10 19:45:00 -08001251 final Utilities.BubbleText bubble = new Utilities.BubbleText(mAllApps.getContext());
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001252
Daniel Sandler388f6792010-03-02 14:08:08 -05001253 mParams.bubbleWidth = bubble.getBubbleWidth();
1254 mParams.bubbleHeight = bubble.getMaxBubbleHeight();
1255 mParams.bubbleBitmapWidth = bubble.getBitmapWidth();
1256 mParams.bubbleBitmapHeight = bubble.getBitmapHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001257
Joe Onorato2cc62e82010-03-17 20:23:53 -07001258 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1259 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001260 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001261 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1262 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001263 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001264 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1265 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001266 mHomeButtonPressed.uploadToTexture(0);
1267 mParams.homeButtonWidth = 76;
1268 mParams.homeButtonHeight = 68;
1269 mParams.homeButtonTextureWidth = 128;
1270 mParams.homeButtonTextureHeight = 128;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001271
Daniel Sandler388f6792010-03-02 14:08:08 -05001272 mState.homeButtonId = mHomeButtonNormal.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001273
Daniel Sandler388f6792010-03-02 14:08:08 -05001274 mParams.save();
1275 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001276
Daniel Sandler388f6792010-03-02 14:08:08 -05001277 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1278 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1279 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001280
Daniel Sandler388f6792010-03-02 14:08:08 -05001281 setApps(null);
1282 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001283
Daniel Sandler388f6792010-03-02 14:08:08 -05001284 private void initRs() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001285 ScriptC.Builder sb = new ScriptC.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001286 sb.setScript(mRes, R.raw.allapps);
1287 sb.setRoot(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001288 sb.addDefines(mAllApps.mDefines);
Daniel Sandler388f6792010-03-02 14:08:08 -05001289 sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS);
1290 sb.setType(mState.mType, "state", Defines.ALLOC_STATE);
1291 sb.setType(mUniformAlloc.getType(), "vpConstants", Defines.ALLOC_VP_CONSTANTS);
1292 mInvokeMove = sb.addInvokable("move");
1293 mInvokeFling = sb.addInvokable("fling");
1294 mInvokeMoveTo = sb.addInvokable("moveTo");
1295 mInvokeResetWAR = sb.addInvokable("resetHWWar");
1296 mInvokeSetZoom = sb.addInvokable("setZoom");
1297 mScript = sb.create();
1298 mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1299 mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
1300 mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
1301 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1302 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
1303 mScript.bindAllocation(mUniformAlloc, Defines.ALLOC_VP_CONSTANTS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001304
Joe Onorato2cc62e82010-03-17 20:23:53 -07001305 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -05001306 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001307
Daniel Sandler388f6792010-03-02 14:08:08 -05001308 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001309 if (sZoomDirty) {
1310 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001311 }
1312 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001313
Romain Guy060b5c82010-03-04 10:07:38 -08001314 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001315 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001316 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001317 final int count = list != null ? list.size() : 0;
1318 int allocCount = count;
1319 if (allocCount < 1) {
1320 allocCount = 1;
1321 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001322
Daniel Sandler388f6792010-03-02 14:08:08 -05001323 mIcons = new Allocation[count];
1324 mIconIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001325 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001326
Daniel Sandler388f6792010-03-02 14:08:08 -05001327 mLabels = new Allocation[count];
1328 mLabelIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001329 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001330
Daniel Sandler388f6792010-03-02 14:08:08 -05001331 mState.iconCount = count;
1332 for (int i=0; i < mState.iconCount; i++) {
1333 createAppIconAllocations(i, list.get(i));
1334 }
1335 for (int i=0; i < mState.iconCount; i++) {
1336 uploadAppIcon(i, list.get(i));
1337 }
1338 saveAppsList();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001339 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001340 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001341
Daniel Sandler388f6792010-03-02 14:08:08 -05001342 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001343 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001344 sRollo.clearSelectedIcon();
1345 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001346 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001347 if (zoom > 0.001f) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001348 sRollo.mState.zoomTarget = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -05001349 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001350 sRollo.mState.zoomTarget = 0;
Daniel Sandler388f6792010-03-02 14:08:08 -05001351 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001352 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -05001353 if (!animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001354 sRollo.mInvokeSetZoom.execute();
Daniel Sandler388f6792010-03-02 14:08:08 -05001355 }
1356 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001357
Daniel Sandler388f6792010-03-02 14:08:08 -05001358 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001359 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1360 Element.RGBA_8888(sRS), false);
1361 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1362 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001363 mIconIds[index] = mIcons[index].getID();
1364 mLabelIds[index] = mLabels[index].getID();
1365 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001366
Daniel Sandler388f6792010-03-02 14:08:08 -05001367 private void uploadAppIcon(int index, ApplicationInfo item) {
1368 if (mIconIds[index] != mIcons[index].getID()) {
1369 throw new IllegalStateException("uploadAppIcon index=" + index
1370 + " mIcons[index].getID=" + mIcons[index].getID()
1371 + " mIconsIds[index]=" + mIconIds[index]
1372 + " item=" + item);
1373 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001374 mIcons[index].uploadToTexture(true, 0);
1375 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001376 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001377
Daniel Sandler388f6792010-03-02 14:08:08 -05001378 /**
1379 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1380 * fill in the values and call saveAppsList().
1381 */
1382 private void reallocAppsList(int count) {
1383 Allocation[] icons = new Allocation[count];
1384 int[] iconIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001385 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001386
Daniel Sandler388f6792010-03-02 14:08:08 -05001387 Allocation[] labels = new Allocation[count];
1388 int[] labelIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001389 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001390
Joe Onorato2cc62e82010-03-17 20:23:53 -07001391 final int oldCount = sRollo.mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001392
Daniel Sandler388f6792010-03-02 14:08:08 -05001393 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1394 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1395 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1396 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001397
Daniel Sandler388f6792010-03-02 14:08:08 -05001398 mIcons = icons;
1399 mIconIds = iconIds;
1400 mLabels = labels;
1401 mLabelIds = labelIds;
1402 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001403
Daniel Sandler388f6792010-03-02 14:08:08 -05001404 /**
1405 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1406 */
1407 private void addApp(int index, ApplicationInfo item) {
1408 final int count = mState.iconCount - index;
1409 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001410
Daniel Sandler388f6792010-03-02 14:08:08 -05001411 System.arraycopy(mIcons, index, mIcons, dest, count);
1412 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1413 System.arraycopy(mLabels, index, mLabels, dest, count);
1414 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001415
Daniel Sandler388f6792010-03-02 14:08:08 -05001416 createAppIconAllocations(index, item);
1417 uploadAppIcon(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001418 sRollo.mState.iconCount++;
Daniel Sandler388f6792010-03-02 14:08:08 -05001419 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001420
Daniel Sandler388f6792010-03-02 14:08:08 -05001421 /**
1422 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1423 */
1424 private void removeApp(int index) {
1425 final int count = mState.iconCount - index - 1;
1426 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001427
Daniel Sandler388f6792010-03-02 14:08:08 -05001428 System.arraycopy(mIcons, src, mIcons, index, count);
1429 System.arraycopy(mIconIds, src, mIconIds, index, count);
1430 System.arraycopy(mLabels, src, mLabels, index, count);
1431 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001432
Joe Onorato2cc62e82010-03-17 20:23:53 -07001433 sRollo.mState.iconCount--;
Daniel Sandler388f6792010-03-02 14:08:08 -05001434 final int last = mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001435
Daniel Sandler388f6792010-03-02 14:08:08 -05001436 mIcons[last] = null;
1437 mIconIds[last] = 0;
1438 mLabels[last] = null;
1439 mLabelIds[last] = 0;
1440 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001441
Daniel Sandler388f6792010-03-02 14:08:08 -05001442 /**
1443 * Send the apps list structures to RS.
1444 */
1445 private void saveAppsList() {
1446 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1447 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001448 mAllocIconIds.data(mIconIds);
1449 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001450
Daniel Sandler388f6792010-03-02 14:08:08 -05001451 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1452 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001453
Daniel Sandler388f6792010-03-02 14:08:08 -05001454 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001455
Daniel Sandler388f6792010-03-02 14:08:08 -05001456 // Note: mScript may be null if we haven't initialized it yet.
1457 // In that case, this is a no-op.
1458 if (mInvokeResetWAR != null) {
1459 mInvokeResetWAR.execute();
1460 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001461 }
1462 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001463
Daniel Sandler388f6792010-03-02 14:08:08 -05001464 void fling() {
1465 mInvokeFling.execute();
1466 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001467
Daniel Sandler388f6792010-03-02 14:08:08 -05001468 void move() {
1469 mInvokeMove.execute();
1470 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001471
Daniel Sandler388f6792010-03-02 14:08:08 -05001472 void moveTo(float row) {
1473 mState.targetPos = row;
1474 mState.save();
1475 mInvokeMoveTo.execute();
1476 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001477
Daniel Sandler388f6792010-03-02 14:08:08 -05001478 /**
1479 * You need to call save() on mState on your own after calling this.
1480 *
1481 * @return the index of the icon that was selected.
1482 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001483 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001484 if (mAllApps != null) {
1485 final int index = mAllApps.chooseTappedIcon(x, y);
1486 selectIcon(index, pressed);
1487 return index;
1488 } else {
1489 return -1;
1490 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001491 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001492
Daniel Sandler388f6792010-03-02 14:08:08 -05001493 /**
1494 * Select the icon at the given index.
1495 *
1496 * @param index The index.
1497 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1498 */
1499 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001500 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1501 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001502 if (mAllApps != null) {
1503 mAllApps.mRestoreFocusIndex = index;
1504 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001505 mState.selectedIconIndex = -1;
Romain Guy13c2e7b2010-03-10 19:45:00 -08001506 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1507 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001508 }
1509 } else {
1510 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001511 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001512 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001513
Daniel Sandler388f6792010-03-02 14:08:08 -05001514 int prev = mState.selectedIconIndex;
1515 mState.selectedIconIndex = index;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001516
Romain Guy13c2e7b2010-03-10 19:45:00 -08001517 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001518 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001519
Daniel Sandler388f6792010-03-02 14:08:08 -05001520 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1521 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1522 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001523
Joe Onorato2cc62e82010-03-17 20:23:53 -07001524 mSelectedIcon = Allocation.createFromBitmap(sRS, selectionBitmap,
1525 Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001526 mSelectedIcon.uploadToTexture(0);
1527 mState.selectedIconTexture = mSelectedIcon.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001528
Daniel Sandler388f6792010-03-02 14:08:08 -05001529 if (prev != index) {
1530 if (info.title != null && info.title.length() > 0) {
1531 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001532 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001533 }
1534 }
1535 }
1536 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001537
Daniel Sandler388f6792010-03-02 14:08:08 -05001538 /**
1539 * You need to call save() on mState on your own after calling this.
1540 */
1541 void clearSelectedIcon() {
1542 mState.selectedIconIndex = -1;
1543 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001544
Daniel Sandler388f6792010-03-02 14:08:08 -05001545 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001546 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001547 switch (mode) {
1548 case SELECTED_NONE:
1549 mState.homeButtonId = mHomeButtonNormal.getID();
1550 break;
1551 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001552 mAllApps.mLastSelection = SELECTION_HOME;
Daniel Sandler388f6792010-03-02 14:08:08 -05001553 mState.homeButtonId = mHomeButtonFocused.getID();
1554 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001555 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001556 }
1557 break;
1558 case SELECTED_PRESSED:
1559 mState.homeButtonId = mHomeButtonPressed.getID();
1560 break;
1561 }
1562 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001563
Daniel Sandler388f6792010-03-02 14:08:08 -05001564 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001565 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1566 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1567 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001568 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001569 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001570 }
1571 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001572 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001573 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001574 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001575 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001576 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001577 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001578 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Joe Onorato2cc62e82010-03-17 20:23:53 -07001579 Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1580 Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1581 Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1582 Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1583 Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1584 Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1585 Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1586 Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1587 Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
1588 Log.d(TAG, "sRollo.mParams.bubbleWidth=" + mParams.bubbleWidth);
1589 Log.d(TAG, "sRollo.mParams.bubbleHeight=" + mParams.bubbleHeight);
1590 Log.d(TAG, "sRollo.mParams.bubbleBitmapWidth=" + mParams.bubbleBitmapWidth);
1591 Log.d(TAG, "sRollo.mParams.bubbleBitmapHeight=" + mParams.bubbleBitmapHeight);
1592 Log.d(TAG, "sRollo.mParams.homeButtonWidth=" + mParams.homeButtonWidth);
1593 Log.d(TAG, "sRollo.mParams.homeButtonHeight=" + mParams.homeButtonHeight);
1594 Log.d(TAG, "sRollo.mParams.homeButtonTextureWidth=" + mParams.homeButtonTextureWidth);
1595 Log.d(TAG, "sRollo.mParams.homeButtonTextureHeight=" + mParams.homeButtonTextureHeight);
Daniel Sandler388f6792010-03-02 14:08:08 -05001596 }
1597 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001598
Daniel Sandlerdca66122010-04-13 16:23:58 -04001599 public int getAppBatchSize() {
1600 return BATCH_SIZE;
1601 }
1602
Daniel Sandler388f6792010-03-02 14:08:08 -05001603 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001604 Log.d(TAG, "sRS=" + sRS);
1605 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001606 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001607 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1608 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001609 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1610 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1611 Log.d(TAG, "mLastSelection=" + mLastSelection);
1612 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1613 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1614 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1615 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001616 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1617 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001618 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001619 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001620 Log.d(TAG, "mVelocity=" + mVelocity);
1621 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001622 if (sRollo != null) {
1623 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001624 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001625 if (sRS != null) {
1626 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001627 }
1628 }
1629}
1630
1631