blob: 5b17b10341694cdb79e1b0db501e611b462eca30 [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
76 private Launcher mLauncher;
77 private DragController mDragController;
78
79 /** When this is 0, modifications are allowed, when it's not, they're not.
80 * TODO: What about scrolling? */
81 private int mLocks = LOCK_ICONS_PENDING;
82
83 private int mSlop;
84 private int mMaxFlingVelocity;
85
86 private Defines mDefines = new Defines();
Daniel Sandler388f6792010-03-02 14:08:08 -050087 private ArrayList<ApplicationInfo> mAllAppsList;
88
Joe Onorato2cc62e82010-03-17 20:23:53 -070089 private static RenderScriptGL sRS;
90 private static RolloRS sRollo;
Jason Samsdd8cd8b2010-03-11 12:38:48 -080091
Daniel Sandler388f6792010-03-02 14:08:08 -050092 /**
93 * True when we are using arrow keys or trackball to drive navigation
94 */
95 private boolean mArrowNavigation = false;
96 private boolean mStartedScrolling;
97
98 /**
99 * Used to keep track of the selection when AllAppsView loses window focus.
100 * One of the SELECTION_ constants.
101 */
102 private int mLastSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800103
Daniel Sandler388f6792010-03-02 14:08:08 -0500104 /**
105 * Used to keep track of the selection when AllAppsView loses window focus
106 */
107 private int mLastSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800108
Daniel Sandler388f6792010-03-02 14:08:08 -0500109 private VelocityTracker mVelocityTracker;
110 private int mTouchTracking;
111 private int mMotionDownRawX;
112 private int mMotionDownRawY;
113 private int mDownIconIndex = -1;
114 private int mCurrentIconIndex = -1;
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700115 private int[] mTouchYBorders;
116 private int[] mTouchXBorders;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800117
Daniel Sandler388f6792010-03-02 14:08:08 -0500118 private boolean mShouldGainFocus;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800119
Daniel Sandler388f6792010-03-02 14:08:08 -0500120 private boolean mHaveSurface = false;
121 private boolean mZoomDirty = false;
122 private boolean mAnimateNextZoom;
123 private float mNextZoom;
124 private float mZoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500125 private float mVelocity;
126 private AAMessage mMessageProc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800127
Romain Guy060b5c82010-03-04 10:07:38 -0800128 private int mColumnsPerPage;
129 private int mRowsPerPage;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800130 private boolean mSurrendered;
131
Romain Guyc16fea72010-03-12 17:17:56 -0800132 private int mRestoreFocusIndex = -1;
133
Romain Guy060b5c82010-03-04 10:07:38 -0800134 @SuppressWarnings({"UnusedDeclaration"})
Daniel Sandler388f6792010-03-02 14:08:08 -0500135 static class Defines {
136 public static final int ALLOC_PARAMS = 0;
137 public static final int ALLOC_STATE = 1;
138 public static final int ALLOC_ICON_IDS = 3;
139 public static final int ALLOC_LABEL_IDS = 4;
140 public static final int ALLOC_VP_CONSTANTS = 5;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800141
Romain Guy060b5c82010-03-04 10:07:38 -0800142 public static final int COLUMNS_PER_PAGE_PORTRAIT = 4;
143 public static final int ROWS_PER_PAGE_PORTRAIT = 4;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800144
Romain Guy060b5c82010-03-04 10:07:38 -0800145 public static final int COLUMNS_PER_PAGE_LANDSCAPE = 6;
146 public static final int ROWS_PER_PAGE_LANDSCAPE = 3;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800147
Daniel Sandler388f6792010-03-02 14:08:08 -0500148 public static final int ICON_WIDTH_PX = 64;
149 public static final int ICON_TEXTURE_WIDTH_PX = 74;
150 public static final int SELECTION_TEXTURE_WIDTH_PX = 74 + 20;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800151
Daniel Sandler388f6792010-03-02 14:08:08 -0500152 public static final int ICON_HEIGHT_PX = 64;
153 public static final int ICON_TEXTURE_HEIGHT_PX = 74;
154 public static final int SELECTION_TEXTURE_HEIGHT_PX = 74 + 20;
155 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800156
Daniel Sandler388f6792010-03-02 14:08:08 -0500157 public AllApps3D(Context context, AttributeSet attrs) {
158 super(context, attrs);
159 setFocusable(true);
160 setSoundEffectsEnabled(false);
161 getHolder().setFormat(PixelFormat.TRANSLUCENT);
162 final ViewConfiguration config = ViewConfiguration.get(context);
163 mSlop = config.getScaledTouchSlop();
164 mMaxFlingVelocity = config.getScaledMaximumFlingVelocity();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800165
Daniel Sandler388f6792010-03-02 14:08:08 -0500166 setOnClickListener(this);
167 setOnLongClickListener(this);
168 setZOrderOnTop(true);
169 getHolder().setFormat(PixelFormat.TRANSLUCENT);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800170
Joe Onorato2cc62e82010-03-17 20:23:53 -0700171 if (sRS == null) {
172 sRS = createRenderScript(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800173 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700174 createRenderScript(sRS);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800175 }
176
Romain Guy060b5c82010-03-04 10:07:38 -0800177 final DisplayMetrics metrics = getResources().getDisplayMetrics();
178 final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
179 mColumnsPerPage = isPortrait ? Defines.COLUMNS_PER_PAGE_PORTRAIT :
180 Defines.COLUMNS_PER_PAGE_LANDSCAPE;
181 mRowsPerPage = isPortrait ? Defines.ROWS_PER_PAGE_PORTRAIT :
182 Defines.ROWS_PER_PAGE_LANDSCAPE;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800183
Joe Onorato2cc62e82010-03-17 20:23:53 -0700184 if (sRollo != null) {
185 sRollo.mAllApps = this;
186 sRollo.mRes = getResources();
187 sRollo.mInitialize = true;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800188 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500189 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800190
Romain Guy060b5c82010-03-04 10:07:38 -0800191 @SuppressWarnings({"UnusedDeclaration"})
192 public AllApps3D(Context context, AttributeSet attrs, int defStyle) {
193 this(context, attrs);
194 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800195
Romain Guy13c2e7b2010-03-10 19:45:00 -0800196 public void surrender() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700197 sRS.contextSetSurface(0, 0, null);
198 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800199 mSurrendered = true;
200 }
201
Daniel Sandler388f6792010-03-02 14:08:08 -0500202 /**
203 * Note that this implementation prohibits this view from ever being reattached.
204 */
205 @Override
206 protected void onDetachedFromWindow() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700207 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800208 if (!mSurrendered) {
Joe Onorato96da4012010-03-17 20:03:24 -0700209 Log.i(TAG, "onDetachedFromWindow");
Romain Guy13c2e7b2010-03-10 19:45:00 -0800210 destroyRenderScript();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700211 sRS = null;
212 sRollo = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800213 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500214 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800215
Daniel Sandler388f6792010-03-02 14:08:08 -0500216 /**
217 * If you have an attached click listener, View always plays the click sound!?!?
218 * Deal with sound effects by hand.
219 */
220 public void reallyPlaySoundEffect(int sound) {
221 boolean old = isSoundEffectsEnabled();
222 setSoundEffectsEnabled(true);
223 playSoundEffect(sound);
224 setSoundEffectsEnabled(old);
225 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800226
Daniel Sandler388f6792010-03-02 14:08:08 -0500227 public void setLauncher(Launcher launcher) {
228 mLauncher = launcher;
229 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800230
Daniel Sandler388f6792010-03-02 14:08:08 -0500231 @Override
232 public void surfaceDestroyed(SurfaceHolder holder) {
233 super.surfaceDestroyed(holder);
234 // Without this, we leak mMessageCallback which leaks the context.
Romain Guy13c2e7b2010-03-10 19:45:00 -0800235 if (!mSurrendered) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700236 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800237 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500238 // We may lose any callbacks that are pending, so make sure that we re-sync that
239 // on the next surfaceChanged.
240 mZoomDirty = true;
241 mHaveSurface = false;
242 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800243
Daniel Sandler388f6792010-03-02 14:08:08 -0500244 @Override
245 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
246 //long startTime = SystemClock.uptimeMillis();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800247
Daniel Sandler388f6792010-03-02 14:08:08 -0500248 super.surfaceChanged(holder, format, w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800249
Romain Guy13c2e7b2010-03-10 19:45:00 -0800250 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800251
Daniel Sandler388f6792010-03-02 14:08:08 -0500252 mHaveSurface = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800253
Joe Onorato2cc62e82010-03-17 20:23:53 -0700254 if (sRollo == null) {
255 sRollo = new RolloRS(this);
256 sRollo.init(getResources(), w, h);
Daniel Sandler388f6792010-03-02 14:08:08 -0500257 if (mAllAppsList != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700258 sRollo.setApps(mAllAppsList);
Daniel Sandler388f6792010-03-02 14:08:08 -0500259 }
260 if (mShouldGainFocus) {
261 gainFocus();
262 mShouldGainFocus = false;
263 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700264 } else if (sRollo.mInitialize) {
265 sRollo.initGl();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700266 sRollo.mInitialize = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500267 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800268
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700269 initTouchState(w, h);
270
Joe Onorato2cc62e82010-03-17 20:23:53 -0700271 sRollo.dirtyCheck();
272 sRollo.resize(w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800273
Joe Onorato2cc62e82010-03-17 20:23:53 -0700274 if (sRS != null) {
275 sRS.mMessageCallback = mMessageProc = new AAMessage();
Daniel Sandler388f6792010-03-02 14:08:08 -0500276 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800277
Joe Onorato2cc62e82010-03-17 20:23:53 -0700278 if (sRollo.mUniformAlloc != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500279 float tf[] = new float[] {72.f, 72.f,
280 120.f, 120.f, 0.f, 0.f,
281 120.f, 680.f,
282 (2.f / 480.f), 0, -((float)w / 2) - 0.25f, -380.25f};
283 if (w > h) {
284 tf[6] = 40.f;
285 tf[7] = h - 40.f;
286 tf[9] = 1.f;
287 tf[10] = -((float)w / 2) - 0.25f;
288 tf[11] = -((float)h / 2) - 0.25f;
289 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800290
Joe Onorato2cc62e82010-03-17 20:23:53 -0700291 sRollo.mUniformAlloc.data(tf);
Daniel Sandler388f6792010-03-02 14:08:08 -0500292 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800293
Daniel Sandler388f6792010-03-02 14:08:08 -0500294 //long endTime = SystemClock.uptimeMillis();
295 //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
296 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800297
Daniel Sandler388f6792010-03-02 14:08:08 -0500298 @Override
299 public void onWindowFocusChanged(boolean hasWindowFocus) {
300 super.onWindowFocusChanged(hasWindowFocus);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800301
302 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800303
Daniel Sandler388f6792010-03-02 14:08:08 -0500304 if (mArrowNavigation) {
305 if (!hasWindowFocus) {
306 // Clear selection when we lose window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700307 mLastSelectedIcon = sRollo.mState.selectedIconIndex;
308 sRollo.setHomeSelected(SELECTED_NONE);
309 sRollo.clearSelectedIcon();
310 sRollo.mState.save();
Romain Guy060b5c82010-03-04 10:07:38 -0800311 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700312 if (sRollo.mState.iconCount > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500313 if (mLastSelection == SELECTION_ICONS) {
314 int selection = mLastSelectedIcon;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700315 final int firstIcon = Math.round(sRollo.mScrollPos) * mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500316 if (selection < 0 || // No selection
317 selection < firstIcon || // off the top of the screen
Joe Onorato2cc62e82010-03-17 20:23:53 -0700318 selection >= sRollo.mState.iconCount || // past last icon
Daniel Sandler388f6792010-03-02 14:08:08 -0500319 selection >= firstIcon + // past last icon on screen
Romain Guy060b5c82010-03-04 10:07:38 -0800320 (mColumnsPerPage * mRowsPerPage)) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500321 selection = firstIcon;
322 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800323
Daniel Sandler388f6792010-03-02 14:08:08 -0500324 // Select the first icon when we gain window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700325 sRollo.selectIcon(selection, SELECTED_FOCUSED);
326 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500327 } else if (mLastSelection == SELECTION_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700328 sRollo.setHomeSelected(SELECTED_FOCUSED);
329 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500330 }
331 }
332 }
333 }
334 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800335
Daniel Sandler388f6792010-03-02 14:08:08 -0500336 @Override
337 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
338 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800339
Romain Guy13c2e7b2010-03-10 19:45:00 -0800340 if (!isVisible() || mSurrendered) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500341 return;
342 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800343
Daniel Sandler388f6792010-03-02 14:08:08 -0500344 if (gainFocus) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700345 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500346 gainFocus();
347 } else {
348 mShouldGainFocus = true;
349 }
350 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700351 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500352 if (mArrowNavigation) {
353 // Clear selection when we lose focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700354 sRollo.clearSelectedIcon();
355 sRollo.setHomeSelected(SELECTED_NONE);
356 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500357 mArrowNavigation = false;
358 }
359 } else {
360 mShouldGainFocus = false;
361 }
362 }
363 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800364
Daniel Sandler388f6792010-03-02 14:08:08 -0500365 private void gainFocus() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700366 if (!mArrowNavigation && sRollo.mState.iconCount > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500367 // Select the first icon when we gain keyboard focus
368 mArrowNavigation = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700369 sRollo.selectIcon(Math.round(sRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED);
370 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500371 }
372 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800373
Daniel Sandler388f6792010-03-02 14:08:08 -0500374 @Override
375 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800376
Daniel Sandler388f6792010-03-02 14:08:08 -0500377 boolean handled = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800378
Daniel Sandler388f6792010-03-02 14:08:08 -0500379 if (!isVisible()) {
380 return false;
381 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700382 final int iconCount = sRollo.mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800383
Daniel Sandler388f6792010-03-02 14:08:08 -0500384 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
385 if (mArrowNavigation) {
386 if (mLastSelection == SELECTION_HOME) {
387 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
388 mLauncher.closeAllApps(true);
389 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700390 int whichApp = sRollo.mState.selectedIconIndex;
Daniel Sandler388f6792010-03-02 14:08:08 -0500391 if (whichApp >= 0) {
392 ApplicationInfo app = mAllAppsList.get(whichApp);
393 mLauncher.startActivitySafely(app.intent);
394 handled = true;
395 }
396 }
397 }
398 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800399
Daniel Sandler388f6792010-03-02 14:08:08 -0500400 if (iconCount > 0) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800401 final boolean isPortrait = getWidth() < getHeight();
402
Daniel Sandler388f6792010-03-02 14:08:08 -0500403 mArrowNavigation = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800404
Joe Onorato2cc62e82010-03-17 20:23:53 -0700405 int currentSelection = sRollo.mState.selectedIconIndex;
406 int currentTopRow = Math.round(sRollo.mScrollPos);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800407
Romain Guy060b5c82010-03-04 10:07:38 -0800408 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1
409 final int currentPageCol = currentSelection % mColumnsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800410
Romain Guy060b5c82010-03-04 10:07:38 -0800411 // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1
Romain Guy6a42cf32010-03-12 16:03:52 -0800412 final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage))
Romain Guy060b5c82010-03-04 10:07:38 -0800413 / mRowsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800414
Daniel Sandler388f6792010-03-02 14:08:08 -0500415 int newSelection = currentSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800416
Daniel Sandler388f6792010-03-02 14:08:08 -0500417 switch (keyCode) {
418 case KeyEvent.KEYCODE_DPAD_UP:
419 if (mLastSelection == SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800420 if (isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700421 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guy6a42cf32010-03-12 16:03:52 -0800422 int lastRowCount = iconCount % mColumnsPerPage;
423 if (lastRowCount == 0) {
424 lastRowCount = mColumnsPerPage;
425 }
426 newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2);
427 if (newSelection >= iconCount) {
428 newSelection = iconCount-1;
429 }
430 int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
431 if (target < 0) {
432 target = 0;
433 }
434 if (currentTopRow != target) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700435 sRollo.moveTo(target);
Romain Guy6a42cf32010-03-12 16:03:52 -0800436 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500437 }
438 } else {
439 if (currentPageRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800440 newSelection = currentSelection - mColumnsPerPage;
Romain Guy6a42cf32010-03-12 16:03:52 -0800441 if (currentTopRow > newSelection / mColumnsPerPage) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700442 sRollo.moveTo(newSelection / mColumnsPerPage);
Romain Guy6a42cf32010-03-12 16:03:52 -0800443 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500444 } else if (currentTopRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800445 newSelection = currentSelection - mColumnsPerPage;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700446 sRollo.moveTo(newSelection / mColumnsPerPage);
Daniel Sandler388f6792010-03-02 14:08:08 -0500447 } else if (currentPageRow != 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800448 newSelection = currentTopRow * mRowsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500449 }
450 }
451 handled = true;
452 break;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800453
Daniel Sandler388f6792010-03-02 14:08:08 -0500454 case KeyEvent.KEYCODE_DPAD_DOWN: {
Romain Guy060b5c82010-03-04 10:07:38 -0800455 final int rowCount = iconCount / mColumnsPerPage
456 + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
457 final int currentRow = currentSelection / mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500458 if (mLastSelection != SELECTION_HOME) {
459 if (currentRow < rowCount-1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700460 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500461 if (currentSelection < 0) {
462 newSelection = 0;
463 } else {
Romain Guy060b5c82010-03-04 10:07:38 -0800464 newSelection = currentSelection + mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500465 }
466 if (newSelection >= iconCount) {
467 // Go from D to G in this arrangement:
468 // A B C D
469 // E F G
470 newSelection = iconCount - 1;
471 }
Romain Guy060b5c82010-03-04 10:07:38 -0800472 if (currentPageRow >= mRowsPerPage - 1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700473 sRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -0500474 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800475 } else if (isPortrait) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500476 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700477 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500478 }
479 }
480 handled = true;
481 break;
482 }
483 case KeyEvent.KEYCODE_DPAD_LEFT:
484 if (mLastSelection != SELECTION_HOME) {
485 if (currentPageCol > 0) {
486 newSelection = currentSelection - 1;
487 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800488 } else if (!isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700489 newSelection = ((int) (sRollo.mScrollPos) * mColumnsPerPage) +
Romain Guy6a42cf32010-03-12 16:03:52 -0800490 (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700491 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500492 }
493 handled = true;
494 break;
495 case KeyEvent.KEYCODE_DPAD_RIGHT:
496 if (mLastSelection != SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800497 if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 ||
498 currentSelection == iconCount - 1)) {
499 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700500 sRollo.setHomeSelected(SELECTED_FOCUSED);
Romain Guy6a42cf32010-03-12 16:03:52 -0800501 } else if ((currentPageCol < mColumnsPerPage - 1) &&
Daniel Sandler388f6792010-03-02 14:08:08 -0500502 (currentSelection < iconCount - 1)) {
503 newSelection = currentSelection + 1;
504 }
505 }
506 handled = true;
507 break;
508 }
509 if (newSelection != currentSelection) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700510 sRollo.selectIcon(newSelection, SELECTED_FOCUSED);
511 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500512 }
513 }
514 return handled;
515 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800516
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700517 void initTouchState(int width, int height) {
518 boolean isPortrait = width < height;
519
520 int[] viewPos = new int[2];
521 getLocationOnScreen(viewPos);
522
523 mTouchXBorders = new int[mColumnsPerPage + 1];
524 mTouchYBorders = new int[mRowsPerPage + 1];
525
526 // TODO: Put this in a config file/define
527 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE_PORTRAIT;
528 if (!isPortrait) cellHeight -= 12;
529 int centerY = (int) (height * (isPortrait ? 0.5f : 0.47f));
530 if (!isPortrait) centerY += cellHeight / 2;
531 int half = (int) Math.floor((mRowsPerPage + 1) / 2);
532 int end = mTouchYBorders.length - (half + 1);
533
534 for (int i = -half; i <= end; i++) {
535 mTouchYBorders[i + half] = centerY + (i * cellHeight) - viewPos[1];
536 }
537
538 int x = 0;
539 // TODO: Put this in a config file/define
540 int columnWidth = 120;
541 for (int i = 0; i < mColumnsPerPage + 1; i++) {
542 mTouchXBorders[i] = x - viewPos[0];
543 x += columnWidth;
544 }
545 }
546
547 int chooseTappedIcon(int x, int y) {
548 float pos = sRollo != null ? sRollo.mScrollPos : 0;
549
550 int oldY = y;
551
552 // Adjust for scroll position if not zero.
553 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
554
555 int col = -1;
556 int row = -1;
557 final int columnsCount = mColumnsPerPage;
558 for (int i=0; i< columnsCount; i++) {
559 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
560 col = i;
561 break;
562 }
563 }
564 final int rowsCount = mRowsPerPage;
565 for (int i=0; i< rowsCount; i++) {
566 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
567 row = i;
568 break;
569 }
570 }
571
572 if (row < 0 || col < 0) {
573 return -1;
574 }
575
576 int index = (((int) pos) * columnsCount) + (row * columnsCount) + col;
577
578 if (index >= mAllAppsList.size()) {
579 return -1;
580 } else {
581 return index;
582 }
583 }
584
Daniel Sandler388f6792010-03-02 14:08:08 -0500585 @Override
586 public boolean onTouchEvent(MotionEvent ev)
587 {
588 mArrowNavigation = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800589
Daniel Sandler388f6792010-03-02 14:08:08 -0500590 if (!isVisible()) {
591 return true;
592 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800593
Daniel Sandler388f6792010-03-02 14:08:08 -0500594 if (mLocks != 0) {
595 return true;
596 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800597
Daniel Sandler388f6792010-03-02 14:08:08 -0500598 super.onTouchEvent(ev);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800599
Daniel Sandler388f6792010-03-02 14:08:08 -0500600 int x = (int)ev.getX();
601 int y = (int)ev.getY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800602
Romain Guyce115852010-03-04 12:15:37 -0800603 final boolean isPortrait = getWidth() < getHeight();
Daniel Sandler388f6792010-03-02 14:08:08 -0500604 int action = ev.getAction();
605 switch (action) {
606 case MotionEvent.ACTION_DOWN:
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700607 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
608 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500609 mTouchTracking = TRACKING_HOME;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700610 sRollo.setHomeSelected(SELECTED_PRESSED);
611 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500612 mCurrentIconIndex = -1;
613 } else {
614 mTouchTracking = TRACKING_FLING;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800615
Daniel Sandler388f6792010-03-02 14:08:08 -0500616 mMotionDownRawX = (int)ev.getRawX();
617 mMotionDownRawY = (int)ev.getRawY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800618
Joe Onorato2cc62e82010-03-17 20:23:53 -0700619 sRollo.mState.newPositionX = ev.getRawY() / getHeight();
620 sRollo.mState.newTouchDown = 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800621
Joe Onorato2cc62e82010-03-17 20:23:53 -0700622 if (!sRollo.checkClickOK()) {
623 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500624 } else {
625 mDownIconIndex = mCurrentIconIndex
Joe Onorato2cc62e82010-03-17 20:23:53 -0700626 = sRollo.selectIcon(x, y, SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500627 if (mDownIconIndex < 0) {
628 // if nothing was selected, no long press.
629 cancelLongPress();
630 }
631 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700632 sRollo.mState.save();
633 sRollo.move();
Daniel Sandler388f6792010-03-02 14:08:08 -0500634 mVelocityTracker = VelocityTracker.obtain();
635 mVelocityTracker.addMovement(ev);
636 mStartedScrolling = false;
637 }
638 break;
639 case MotionEvent.ACTION_MOVE:
640 case MotionEvent.ACTION_OUTSIDE:
641 if (mTouchTracking == TRACKING_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700642 sRollo.setHomeSelected((isPortrait &&
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700643 y > mTouchYBorders[mTouchYBorders.length-1]) || (!isPortrait
644 && x > mTouchXBorders[mTouchXBorders.length-1])
Daniel Sandler388f6792010-03-02 14:08:08 -0500645 ? SELECTED_PRESSED : SELECTED_NONE);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700646 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500647 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500648 int rawY = (int)ev.getRawY();
649 int slop;
650 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800651
Daniel Sandler388f6792010-03-02 14:08:08 -0500652 if (!mStartedScrolling && slop < mSlop) {
653 // don't update anything so when we do start scrolling
654 // below, we get the right delta.
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700655 mCurrentIconIndex = chooseTappedIcon(x, y);
Daniel Sandler388f6792010-03-02 14:08:08 -0500656 if (mDownIconIndex != mCurrentIconIndex) {
657 // If a different icon is selected, don't allow it to be picked up.
658 // This handles off-axis dragging.
659 cancelLongPress();
660 mCurrentIconIndex = -1;
661 }
662 } else {
663 if (!mStartedScrolling) {
664 cancelLongPress();
665 mCurrentIconIndex = -1;
666 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700667 sRollo.mState.newPositionX = ev.getRawY() / getHeight();
668 sRollo.mState.newTouchDown = 1;
669 sRollo.move();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800670
Daniel Sandler388f6792010-03-02 14:08:08 -0500671 mStartedScrolling = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700672 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500673 mVelocityTracker.addMovement(ev);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700674 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500675 }
676 }
677 break;
678 case MotionEvent.ACTION_UP:
679 case MotionEvent.ACTION_CANCEL:
680 if (mTouchTracking == TRACKING_HOME) {
681 if (action == MotionEvent.ACTION_UP) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700682 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
683 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500684 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
685 mLauncher.closeAllApps(true);
686 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700687 sRollo.setHomeSelected(SELECTED_NONE);
688 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500689 }
690 mCurrentIconIndex = -1;
691 } else if (mTouchTracking == TRACKING_FLING) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700692 sRollo.mState.newTouchDown = 0;
693 sRollo.mState.newPositionX = ev.getRawY() / getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800694
Daniel Sandler388f6792010-03-02 14:08:08 -0500695 mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700696 sRollo.mState.flingVelocity = mVelocityTracker.getYVelocity() / getHeight();
697 sRollo.clearSelectedIcon();
698 sRollo.mState.save();
699 sRollo.fling();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800700
Daniel Sandler388f6792010-03-02 14:08:08 -0500701 if (mVelocityTracker != null) {
702 mVelocityTracker.recycle();
703 mVelocityTracker = null;
704 }
705 }
706 mTouchTracking = TRACKING_NONE;
707 break;
708 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800709
Daniel Sandler388f6792010-03-02 14:08:08 -0500710 return true;
711 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800712
Daniel Sandler388f6792010-03-02 14:08:08 -0500713 public void onClick(View v) {
714 if (mLocks != 0 || !isVisible()) {
715 return;
716 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700717 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500718 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
719 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
720 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
721 mLauncher.startActivitySafely(app.intent);
722 }
723 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800724
Daniel Sandler388f6792010-03-02 14:08:08 -0500725 public boolean onLongClick(View v) {
726 if (mLocks != 0 || !isVisible()) {
727 return true;
728 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700729 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500730 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
731 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800732
Daniel Sandler388f6792010-03-02 14:08:08 -0500733 Bitmap bmp = app.iconBitmap;
734 final int w = bmp.getWidth();
735 final int h = bmp.getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800736
Daniel Sandler388f6792010-03-02 14:08:08 -0500737 // We don't really have an accurate location to use. This will do.
738 int screenX = mMotionDownRawX - (w / 2);
739 int screenY = mMotionDownRawY - h;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800740
Daniel Sandler388f6792010-03-02 14:08:08 -0500741 mDragController.startDrag(bmp, screenX, screenY,
742 0, 0, w, h, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800743
Daniel Sandler388f6792010-03-02 14:08:08 -0500744 mLauncher.closeAllApps(true);
745 }
746 return true;
747 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800748
Daniel Sandler388f6792010-03-02 14:08:08 -0500749 @Override
750 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
751 if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
752 if (!isVisible()) {
753 return false;
754 }
755 String text = null;
756 int index;
757 int count = mAllAppsList.size() + 1; // +1 is home
758 int pos = -1;
759 switch (mLastSelection) {
760 case SELECTION_ICONS:
Joe Onorato2cc62e82010-03-17 20:23:53 -0700761 index = sRollo.mState.selectedIconIndex;
Daniel Sandler388f6792010-03-02 14:08:08 -0500762 if (index >= 0) {
763 ApplicationInfo info = mAllAppsList.get(index);
764 if (info.title != null) {
765 text = info.title.toString();
766 pos = index;
767 }
768 }
769 break;
770 case SELECTION_HOME:
771 text = getContext().getString(R.string.all_apps_home_button_label);
772 pos = count;
773 break;
774 }
775 if (text != null) {
776 event.setEnabled(true);
777 event.getText().add(text);
778 //event.setContentDescription(text);
779 event.setItemCount(count);
780 event.setCurrentItemIndex(pos);
781 }
782 }
783 return false;
784 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800785
Daniel Sandler388f6792010-03-02 14:08:08 -0500786 public void setDragController(DragController dragger) {
787 mDragController = dragger;
788 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800789
Daniel Sandler388f6792010-03-02 14:08:08 -0500790 public void onDropCompleted(View target, boolean success) {
791 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800792
Daniel Sandler388f6792010-03-02 14:08:08 -0500793 /**
794 * Zoom to the specifed level.
795 *
796 * @param zoom [0..1] 0 is hidden, 1 is open
797 */
798 public void zoom(float zoom, boolean animate) {
799 cancelLongPress();
800 mNextZoom = zoom;
801 mAnimateNextZoom = animate;
802 // if we do setZoom while we don't have a surface, we won't
803 // get the callbacks that actually set mZoom.
Joe Onorato2cc62e82010-03-17 20:23:53 -0700804 if (sRollo == null || !mHaveSurface) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500805 mZoomDirty = true;
806 mZoom = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500807 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700808 sRollo.setZoom(zoom, animate);
Daniel Sandler388f6792010-03-02 14:08:08 -0500809 }
810 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800811
Daniel Sandler388f6792010-03-02 14:08:08 -0500812 public boolean isVisible() {
813 return mZoom > 0.001f;
814 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800815
Daniel Sandler388f6792010-03-02 14:08:08 -0500816 public boolean isOpaque() {
817 return mZoom > 0.999f;
818 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800819
Daniel Sandler388f6792010-03-02 14:08:08 -0500820 public void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700821 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500822 // We've been removed from the window. Don't bother with all this.
823 return;
824 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800825
826 boolean reload = false;
827 if (mAllAppsList == null) {
828 reload = true;
829 } else if (list.size() != mAllAppsList.size()) {
830 reload = true;
831 } else {
832 final int count = list.size();
833 for (int i = 0; i < count; i++) {
834 if (list.get(i) != mAllAppsList.get(i)) {
835 reload = true;
836 break;
837 }
838 }
839 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800840
Daniel Sandler388f6792010-03-02 14:08:08 -0500841 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700842 if (sRollo != null && reload) {
843 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500844 }
Romain Guyc16fea72010-03-12 17:17:56 -0800845
846 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700847 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
848 sRollo.mState.save();
Romain Guyc16fea72010-03-12 17:17:56 -0800849 mRestoreFocusIndex = -1;
850 }
851
Daniel Sandler388f6792010-03-02 14:08:08 -0500852 mLocks &= ~LOCK_ICONS_PENDING;
853 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800854
Daniel Sandler388f6792010-03-02 14:08:08 -0500855 public void addApps(ArrayList<ApplicationInfo> list) {
856 if (mAllAppsList == null) {
857 // Not done loading yet. We'll find out about it later.
858 return;
859 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700860 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500861 // We've been removed from the window. Don't bother with all this.
862 return;
863 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800864
Daniel Sandler388f6792010-03-02 14:08:08 -0500865 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700866 if (sRollo != null) {
867 sRollo.pause();
868 sRollo.reallocAppsList(sRollo.mState.iconCount + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500869 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800870
Daniel Sandler388f6792010-03-02 14:08:08 -0500871 for (int i=0; i<N; i++) {
872 final ApplicationInfo item = list.get(i);
873 int index = Collections.binarySearch(mAllAppsList, item,
874 LauncherModel.APP_NAME_COMPARATOR);
875 if (index < 0) {
876 index = -(index+1);
877 }
878 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700879 if (sRollo != null) {
880 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500881 }
882 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800883
Joe Onorato2cc62e82010-03-17 20:23:53 -0700884 if (sRollo != null) {
885 sRollo.saveAppsList();
886 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500887 }
888 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800889
Daniel Sandler388f6792010-03-02 14:08:08 -0500890 public void removeApps(ArrayList<ApplicationInfo> list) {
891 if (mAllAppsList == null) {
892 // Not done loading yet. We'll find out about it later.
893 return;
894 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800895
Joe Onorato2cc62e82010-03-17 20:23:53 -0700896 if (sRollo != null) {
897 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800898 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500899 final int N = list.size();
900 for (int i=0; i<N; i++) {
901 final ApplicationInfo item = list.get(i);
902 int index = findAppByComponent(mAllAppsList, item);
903 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500904 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700905 if (sRollo != null) {
906 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500907 }
908 } else {
909 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
910 // Try to recover. This should keep us from crashing for now.
911 }
912 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800913
Joe Onorato2cc62e82010-03-17 20:23:53 -0700914 if (sRollo != null) {
915 sRollo.saveAppsList();
916 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500917 }
918 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800919
Joe Onorato64e6be72010-03-05 15:05:52 -0500920 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500921 // Just remove and add, because they may need to be re-sorted.
922 removeApps(list);
923 addApps(list);
924 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800925
Daniel Sandler388f6792010-03-02 14:08:08 -0500926 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
927 ComponentName component = item.intent.getComponent();
928 final int N = list.size();
929 for (int i=0; i<N; i++) {
930 ApplicationInfo x = list.get(i);
931 if (x.intent.getComponent().equals(component)) {
932 return i;
933 }
934 }
935 return -1;
936 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800937
Romain Guy060b5c82010-03-04 10:07:38 -0800938 /*
Daniel Sandler388f6792010-03-02 14:08:08 -0500939 private static int countPages(int iconCount) {
Romain Guy060b5c82010-03-04 10:07:38 -0800940 int iconsPerPage = getColumnsCount() * Defines.ROWS_PER_PAGE_PORTRAIT;
Daniel Sandler388f6792010-03-02 14:08:08 -0500941 int pages = iconCount / iconsPerPage;
942 if (pages*iconsPerPage != iconCount) {
943 pages++;
944 }
945 return pages;
946 }
Romain Guy060b5c82010-03-04 10:07:38 -0800947 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500948
949 class AAMessage extends RenderScript.RSMessage {
950 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700951 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500952 mVelocity = ((float)mData[1]) / (1 << 16);
953 mZoom = ((float)mData[2]) / (1 << 16);
954 mZoomDirty = false;
955 }
956 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800957
Romain Guy13c2e7b2010-03-10 19:45:00 -0800958 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500959 // Allocations ======
960 private int mWidth;
961 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800962
Daniel Sandler388f6792010-03-02 14:08:08 -0500963 private Resources mRes;
964 private Script mScript;
965 private Script.Invokable mInvokeMove;
966 private Script.Invokable mInvokeMoveTo;
967 private Script.Invokable mInvokeFling;
968 private Script.Invokable mInvokeResetWAR;
969 private Script.Invokable mInvokeSetZoom;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800970
Daniel Sandler388f6792010-03-02 14:08:08 -0500971 private ProgramStore mPSIcons;
972 private ProgramFragment mPFTexMip;
973 private ProgramFragment mPFTexMipAlpha;
974 private ProgramFragment mPFTexNearest;
975 private ProgramVertex mPV;
976 private ProgramVertex mPVCurve;
977 private SimpleMesh mMesh;
978 private ProgramVertex.MatrixAllocation mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800979
Daniel Sandler388f6792010-03-02 14:08:08 -0500980 private Allocation mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800981
Daniel Sandler388f6792010-03-02 14:08:08 -0500982 private Allocation mHomeButtonNormal;
983 private Allocation mHomeButtonFocused;
984 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800985
Daniel Sandler388f6792010-03-02 14:08:08 -0500986 private Allocation[] mIcons;
987 private int[] mIconIds;
988 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800989
Daniel Sandler388f6792010-03-02 14:08:08 -0500990 private Allocation[] mLabels;
991 private int[] mLabelIds;
992 private Allocation mAllocLabelIds;
993 private Allocation mSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800994
Daniel Sandler388f6792010-03-02 14:08:08 -0500995 private Bitmap mSelectionBitmap;
996 private Canvas mSelectionCanvas;
Romain Guy6a42cf32010-03-12 16:03:52 -0800997
998 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800999
Daniel Sandler388f6792010-03-02 14:08:08 -05001000 Params mParams;
1001 State mState;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001002
Romain Guy13c2e7b2010-03-10 19:45:00 -08001003 AllApps3D mAllApps;
1004 boolean mInitialize;
1005
Daniel Sandler388f6792010-03-02 14:08:08 -05001006 class BaseAlloc {
1007 Allocation mAlloc;
1008 Type mType;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001009
Daniel Sandler388f6792010-03-02 14:08:08 -05001010 void save() {
1011 mAlloc.data(this);
1012 }
1013 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001014
Daniel Sandler388f6792010-03-02 14:08:08 -05001015 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001016 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -08001017 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -05001018 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001019
1020 void pause() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001021 sRS.contextBindRootScript(null);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001022 }
1023
1024 void resume() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001025 sRS.contextBindRootScript(mScript);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001026 }
1027
Daniel Sandler388f6792010-03-02 14:08:08 -05001028 class Params extends BaseAlloc {
1029 Params() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001030 mType = Type.createFromClass(sRS, Params.class, 1, "ParamsClass");
1031 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001032 save();
1033 }
1034 public int bubbleWidth;
1035 public int bubbleHeight;
1036 public int bubbleBitmapWidth;
1037 public int bubbleBitmapHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001038
Daniel Sandler388f6792010-03-02 14:08:08 -05001039 public int homeButtonWidth;
1040 public int homeButtonHeight;
1041 public int homeButtonTextureWidth;
1042 public int homeButtonTextureHeight;
1043 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001044
Daniel Sandler388f6792010-03-02 14:08:08 -05001045 class State extends BaseAlloc {
1046 public float newPositionX;
1047 public int newTouchDown;
1048 public float flingVelocity;
1049 public int iconCount;
1050 public int selectedIconIndex = -1;
1051 public int selectedIconTexture;
1052 public float zoomTarget;
1053 public int homeButtonId;
1054 public float targetPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001055
Daniel Sandler388f6792010-03-02 14:08:08 -05001056 State() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001057 mType = Type.createFromClass(sRS, State.class, 1, "StateClass");
1058 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001059 save();
1060 }
1061 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001062
Romain Guy13c2e7b2010-03-10 19:45:00 -08001063 public RolloRS(AllApps3D allApps) {
1064 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -05001065 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001066
Daniel Sandler388f6792010-03-02 14:08:08 -05001067 public void init(Resources res, int width, int height) {
1068 mRes = res;
1069 mWidth = width;
1070 mHeight = height;
1071 initProgramVertex();
1072 initProgramFragment();
1073 initProgramStore();
1074 initGl();
1075 initData();
Daniel Sandler388f6792010-03-02 14:08:08 -05001076 initRs();
1077 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001078
Daniel Sandler388f6792010-03-02 14:08:08 -05001079 public void initMesh() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001080 SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001081
Daniel Sandler388f6792010-03-02 14:08:08 -05001082 for (int ct=0; ct < 16; ct++) {
1083 float pos = (1.f / (16.f - 1)) * ct;
1084 tm.addVertex(0.0f, pos);
1085 tm.addVertex(1.0f, pos);
1086 }
1087 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1088 tm.addTriangle(ct, ct+1, ct+2);
1089 tm.addTriangle(ct+1, ct+3, ct+2);
1090 }
1091 mMesh = tm.create();
1092 mMesh.setName("SMCell");
1093 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001094
Daniel Sandler388f6792010-03-02 14:08:08 -05001095 void resize(int w, int h) {
1096 mPVA.setupProjectionNormalized(w, h);
1097 mWidth = w;
1098 mHeight = h;
1099 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001100
Daniel Sandler388f6792010-03-02 14:08:08 -05001101 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001102 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001103 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001104
Joe Onorato2cc62e82010-03-17 20:23:53 -07001105 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001106 pvb.setTextureMatrixEnable(true);
1107 mPV = pvb.create();
1108 mPV.setName("PV");
1109 mPV.bindAllocation(mPVA);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001110
Joe Onorato2cc62e82010-03-17 20:23:53 -07001111 Element.Builder eb = new Element.Builder(sRS);
1112 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "ImgSize");
1113 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "Position");
1114 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "BendPos");
1115 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "ScaleOffset");
Daniel Sandler388f6792010-03-02 14:08:08 -05001116 Element e = eb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001117
Joe Onorato2cc62e82010-03-17 20:23:53 -07001118 mUniformAlloc = Allocation.createSized(sRS, e, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001119
Daniel Sandler388f6792010-03-02 14:08:08 -05001120 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001121 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Romain Guy060b5c82010-03-04 10:07:38 -08001122 String t = "void main() {\n" +
1123 // Animation
1124 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001125
Romain Guy060b5c82010-03-04 10:07:38 -08001126 " float bendY1 = UNI_BendPos.x;\n" +
1127 " float bendY2 = UNI_BendPos.y;\n" +
1128 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1129 " float bendDistance = bendY1 * 0.4;\n" +
1130 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001131
Romain Guy060b5c82010-03-04 10:07:38 -08001132 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1133 " float aDy = cos(bendAngle);\n" +
1134 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001135
Romain Guy060b5c82010-03-04 10:07:38 -08001136 " float scale = (2.0 / 480.0);\n" +
1137 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1138 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1139 " float y = 0.0;\n" +
1140 " float z = 0.0;\n" +
1141 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001142
Romain Guy060b5c82010-03-04 10:07:38 -08001143 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1144 " y += cv * aDy;\n" +
1145 " z += -cv * aDz;\n" +
1146 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1147 " lum += cv / bendDistance * distanceDimLevel;\n" +
1148 " y += cv * cos(cv * bendStep);\n" +
1149 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001150
Romain Guy060b5c82010-03-04 10:07:38 -08001151 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1152 " y += cv * aDy;\n" +
1153 " z += cv * aDz;\n" +
1154 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1155 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1156 " y += cv * cos(cv * bendStep);\n" +
1157 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001158
Romain Guy060b5c82010-03-04 10:07:38 -08001159 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001160
Romain Guy060b5c82010-03-04 10:07:38 -08001161 " vec4 pos;\n" +
1162 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1163 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1164 " pos.z = z * UNI_ScaleOffset.x;\n" +
1165 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001166
Romain Guy060b5c82010-03-04 10:07:38 -08001167 " pos.x *= 1.0 + ani * 4.0;\n" +
1168 " pos.y *= 1.0 + ani * 4.0;\n" +
1169 " pos.z -= ani * 1.5;\n" +
1170 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001171
Romain Guy060b5c82010-03-04 10:07:38 -08001172 " gl_Position = UNI_MVP * pos;\n" +
1173 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1174 " varTex0.xy = ATTRIB_position;\n" +
1175 " varTex0.y = 1.0 - varTex0.y;\n" +
1176 " varTex0.zw = vec2(0.0, 0.0);\n" +
1177 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001178 sb.setShader(t);
1179 sb.addConstant(mUniformAlloc.getType());
1180 sb.addInput(mMesh.getVertexType(0).getElement());
1181 mPVCurve = sb.create();
1182 mPVCurve.setName("PVCurve");
1183 mPVCurve.bindAllocation(mPVA);
1184 mPVCurve.bindConstants(mUniformAlloc, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001185
Joe Onorato2cc62e82010-03-17 20:23:53 -07001186 sRS.contextBindProgramVertex(mPV);
Daniel Sandler388f6792010-03-02 14:08:08 -05001187 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001188
Daniel Sandler388f6792010-03-02 14:08:08 -05001189 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001190 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001191 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1192 sb.setMag(Sampler.Value.NEAREST);
1193 sb.setWrapS(Sampler.Value.CLAMP);
1194 sb.setWrapT(Sampler.Value.CLAMP);
1195 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001196
Daniel Sandler388f6792010-03-02 14:08:08 -05001197 sb.setMin(Sampler.Value.NEAREST);
1198 sb.setMag(Sampler.Value.NEAREST);
1199 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001200
Joe Onorato2cc62e82010-03-17 20:23:53 -07001201 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001202 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1203 ProgramFragment.Builder.Format.RGBA, 0);
1204 mPFTexMip = bf.create();
1205 mPFTexMip.setName("PFTexMip");
1206 mPFTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001207
Daniel Sandler388f6792010-03-02 14:08:08 -05001208 mPFTexNearest = bf.create();
1209 mPFTexNearest.setName("PFTexNearest");
1210 mPFTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001211
Daniel Sandler388f6792010-03-02 14:08:08 -05001212 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1213 ProgramFragment.Builder.Format.ALPHA, 0);
1214 mPFTexMipAlpha = bf.create();
1215 mPFTexMipAlpha.setName("PFTexMipAlpha");
1216 mPFTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001217
Daniel Sandler388f6792010-03-02 14:08:08 -05001218 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001219
Daniel Sandler388f6792010-03-02 14:08:08 -05001220 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001221 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001222 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1223 bs.setColorMask(true,true,true,false);
1224 bs.setDitherEnable(true);
1225 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1226 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
1227 mPSIcons = bs.create();
1228 mPSIcons.setName("PSIcons");
1229 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001230
Daniel Sandler388f6792010-03-02 14:08:08 -05001231 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001232 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001233
Daniel Sandler388f6792010-03-02 14:08:08 -05001234 private void initData() {
1235 mParams = new Params();
1236 mState = new State();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001237
Romain Guy13c2e7b2010-03-10 19:45:00 -08001238 final Utilities.BubbleText bubble = new Utilities.BubbleText(mAllApps.getContext());
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001239
Daniel Sandler388f6792010-03-02 14:08:08 -05001240 mParams.bubbleWidth = bubble.getBubbleWidth();
1241 mParams.bubbleHeight = bubble.getMaxBubbleHeight();
1242 mParams.bubbleBitmapWidth = bubble.getBitmapWidth();
1243 mParams.bubbleBitmapHeight = bubble.getBitmapHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001244
Joe Onorato2cc62e82010-03-17 20:23:53 -07001245 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1246 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001247 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001248 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1249 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001250 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001251 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1252 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001253 mHomeButtonPressed.uploadToTexture(0);
1254 mParams.homeButtonWidth = 76;
1255 mParams.homeButtonHeight = 68;
1256 mParams.homeButtonTextureWidth = 128;
1257 mParams.homeButtonTextureHeight = 128;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001258
Daniel Sandler388f6792010-03-02 14:08:08 -05001259 mState.homeButtonId = mHomeButtonNormal.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001260
Daniel Sandler388f6792010-03-02 14:08:08 -05001261 mParams.save();
1262 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001263
Daniel Sandler388f6792010-03-02 14:08:08 -05001264 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1265 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1266 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001267
Daniel Sandler388f6792010-03-02 14:08:08 -05001268 setApps(null);
1269 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001270
Daniel Sandler388f6792010-03-02 14:08:08 -05001271 private void initRs() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001272 ScriptC.Builder sb = new ScriptC.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001273 sb.setScript(mRes, R.raw.allapps);
1274 sb.setRoot(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001275 sb.addDefines(mAllApps.mDefines);
Daniel Sandler388f6792010-03-02 14:08:08 -05001276 sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS);
1277 sb.setType(mState.mType, "state", Defines.ALLOC_STATE);
1278 sb.setType(mUniformAlloc.getType(), "vpConstants", Defines.ALLOC_VP_CONSTANTS);
1279 mInvokeMove = sb.addInvokable("move");
1280 mInvokeFling = sb.addInvokable("fling");
1281 mInvokeMoveTo = sb.addInvokable("moveTo");
1282 mInvokeResetWAR = sb.addInvokable("resetHWWar");
1283 mInvokeSetZoom = sb.addInvokable("setZoom");
1284 mScript = sb.create();
1285 mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1286 mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
1287 mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
1288 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1289 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
1290 mScript.bindAllocation(mUniformAlloc, Defines.ALLOC_VP_CONSTANTS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001291
Joe Onorato2cc62e82010-03-17 20:23:53 -07001292 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -05001293 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001294
Daniel Sandler388f6792010-03-02 14:08:08 -05001295 void dirtyCheck() {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001296 if (mAllApps.mZoomDirty) {
1297 setZoom(mAllApps.mNextZoom, mAllApps.mAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001298 }
1299 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001300
Romain Guy060b5c82010-03-04 10:07:38 -08001301 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001302 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001303 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001304 final int count = list != null ? list.size() : 0;
1305 int allocCount = count;
1306 if (allocCount < 1) {
1307 allocCount = 1;
1308 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001309
Daniel Sandler388f6792010-03-02 14:08:08 -05001310 mIcons = new Allocation[count];
1311 mIconIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001312 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001313
Daniel Sandler388f6792010-03-02 14:08:08 -05001314 mLabels = new Allocation[count];
1315 mLabelIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001316 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001317
Daniel Sandler388f6792010-03-02 14:08:08 -05001318 mState.iconCount = count;
1319 for (int i=0; i < mState.iconCount; i++) {
1320 createAppIconAllocations(i, list.get(i));
1321 }
1322 for (int i=0; i < mState.iconCount; i++) {
1323 uploadAppIcon(i, list.get(i));
1324 }
1325 saveAppsList();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001326 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001327 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001328
Daniel Sandler388f6792010-03-02 14:08:08 -05001329 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001330 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001331 sRollo.clearSelectedIcon();
1332 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001333 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001334 if (zoom > 0.001f) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001335 sRollo.mState.zoomTarget = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -05001336 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001337 sRollo.mState.zoomTarget = 0;
Daniel Sandler388f6792010-03-02 14:08:08 -05001338 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001339 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -05001340 if (!animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001341 sRollo.mInvokeSetZoom.execute();
Daniel Sandler388f6792010-03-02 14:08:08 -05001342 }
1343 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001344
Daniel Sandler388f6792010-03-02 14:08:08 -05001345 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001346 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1347 Element.RGBA_8888(sRS), false);
1348 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1349 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001350 mIconIds[index] = mIcons[index].getID();
1351 mLabelIds[index] = mLabels[index].getID();
1352 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001353
Daniel Sandler388f6792010-03-02 14:08:08 -05001354 private void uploadAppIcon(int index, ApplicationInfo item) {
1355 if (mIconIds[index] != mIcons[index].getID()) {
1356 throw new IllegalStateException("uploadAppIcon index=" + index
1357 + " mIcons[index].getID=" + mIcons[index].getID()
1358 + " mIconsIds[index]=" + mIconIds[index]
1359 + " item=" + item);
1360 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001361 mIcons[index].uploadToTexture(true, 0);
1362 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001363 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001364
Daniel Sandler388f6792010-03-02 14:08:08 -05001365 /**
1366 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1367 * fill in the values and call saveAppsList().
1368 */
1369 private void reallocAppsList(int count) {
1370 Allocation[] icons = new Allocation[count];
1371 int[] iconIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001372 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001373
Daniel Sandler388f6792010-03-02 14:08:08 -05001374 Allocation[] labels = new Allocation[count];
1375 int[] labelIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001376 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001377
Joe Onorato2cc62e82010-03-17 20:23:53 -07001378 final int oldCount = sRollo.mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001379
Daniel Sandler388f6792010-03-02 14:08:08 -05001380 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1381 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1382 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1383 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001384
Daniel Sandler388f6792010-03-02 14:08:08 -05001385 mIcons = icons;
1386 mIconIds = iconIds;
1387 mLabels = labels;
1388 mLabelIds = labelIds;
1389 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001390
Daniel Sandler388f6792010-03-02 14:08:08 -05001391 /**
1392 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1393 */
1394 private void addApp(int index, ApplicationInfo item) {
1395 final int count = mState.iconCount - index;
1396 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001397
Daniel Sandler388f6792010-03-02 14:08:08 -05001398 System.arraycopy(mIcons, index, mIcons, dest, count);
1399 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1400 System.arraycopy(mLabels, index, mLabels, dest, count);
1401 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001402
Daniel Sandler388f6792010-03-02 14:08:08 -05001403 createAppIconAllocations(index, item);
1404 uploadAppIcon(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001405 sRollo.mState.iconCount++;
Daniel Sandler388f6792010-03-02 14:08:08 -05001406 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001407
Daniel Sandler388f6792010-03-02 14:08:08 -05001408 /**
1409 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1410 */
1411 private void removeApp(int index) {
1412 final int count = mState.iconCount - index - 1;
1413 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001414
Daniel Sandler388f6792010-03-02 14:08:08 -05001415 System.arraycopy(mIcons, src, mIcons, index, count);
1416 System.arraycopy(mIconIds, src, mIconIds, index, count);
1417 System.arraycopy(mLabels, src, mLabels, index, count);
1418 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001419
Joe Onorato2cc62e82010-03-17 20:23:53 -07001420 sRollo.mState.iconCount--;
Daniel Sandler388f6792010-03-02 14:08:08 -05001421 final int last = mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001422
Daniel Sandler388f6792010-03-02 14:08:08 -05001423 mIcons[last] = null;
1424 mIconIds[last] = 0;
1425 mLabels[last] = null;
1426 mLabelIds[last] = 0;
1427 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001428
Daniel Sandler388f6792010-03-02 14:08:08 -05001429 /**
1430 * Send the apps list structures to RS.
1431 */
1432 private void saveAppsList() {
1433 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1434 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001435 mAllocIconIds.data(mIconIds);
1436 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001437
Daniel Sandler388f6792010-03-02 14:08:08 -05001438 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1439 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001440
Daniel Sandler388f6792010-03-02 14:08:08 -05001441 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001442
Daniel Sandler388f6792010-03-02 14:08:08 -05001443 // Note: mScript may be null if we haven't initialized it yet.
1444 // In that case, this is a no-op.
1445 if (mInvokeResetWAR != null) {
1446 mInvokeResetWAR.execute();
1447 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001448 }
1449 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001450
Daniel Sandler388f6792010-03-02 14:08:08 -05001451 void fling() {
1452 mInvokeFling.execute();
1453 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001454
Daniel Sandler388f6792010-03-02 14:08:08 -05001455 void move() {
1456 mInvokeMove.execute();
1457 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001458
Daniel Sandler388f6792010-03-02 14:08:08 -05001459 void moveTo(float row) {
1460 mState.targetPos = row;
1461 mState.save();
1462 mInvokeMoveTo.execute();
1463 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001464
Daniel Sandler388f6792010-03-02 14:08:08 -05001465 /**
1466 * You need to call save() on mState on your own after calling this.
1467 *
1468 * @return the index of the icon that was selected.
1469 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001470 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001471 if (mAllApps != null) {
1472 final int index = mAllApps.chooseTappedIcon(x, y);
1473 selectIcon(index, pressed);
1474 return index;
1475 } else {
1476 return -1;
1477 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001478 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001479
Daniel Sandler388f6792010-03-02 14:08:08 -05001480 /**
1481 * Select the icon at the given index.
1482 *
1483 * @param index The index.
1484 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1485 */
1486 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001487 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1488 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001489 if (mAllApps != null) {
1490 mAllApps.mRestoreFocusIndex = index;
1491 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001492 mState.selectedIconIndex = -1;
Romain Guy13c2e7b2010-03-10 19:45:00 -08001493 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1494 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001495 }
1496 } else {
1497 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001498 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001499 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001500
Daniel Sandler388f6792010-03-02 14:08:08 -05001501 int prev = mState.selectedIconIndex;
1502 mState.selectedIconIndex = index;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001503
Romain Guy13c2e7b2010-03-10 19:45:00 -08001504 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001505 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001506
Daniel Sandler388f6792010-03-02 14:08:08 -05001507 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1508 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1509 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001510
Joe Onorato2cc62e82010-03-17 20:23:53 -07001511 mSelectedIcon = Allocation.createFromBitmap(sRS, selectionBitmap,
1512 Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001513 mSelectedIcon.uploadToTexture(0);
1514 mState.selectedIconTexture = mSelectedIcon.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001515
Daniel Sandler388f6792010-03-02 14:08:08 -05001516 if (prev != index) {
1517 if (info.title != null && info.title.length() > 0) {
1518 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001519 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001520 }
1521 }
1522 }
1523 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001524
Daniel Sandler388f6792010-03-02 14:08:08 -05001525 /**
1526 * You need to call save() on mState on your own after calling this.
1527 */
1528 void clearSelectedIcon() {
1529 mState.selectedIconIndex = -1;
1530 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001531
Daniel Sandler388f6792010-03-02 14:08:08 -05001532 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001533 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001534 switch (mode) {
1535 case SELECTED_NONE:
1536 mState.homeButtonId = mHomeButtonNormal.getID();
1537 break;
1538 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001539 mAllApps.mLastSelection = SELECTION_HOME;
Daniel Sandler388f6792010-03-02 14:08:08 -05001540 mState.homeButtonId = mHomeButtonFocused.getID();
1541 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001542 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001543 }
1544 break;
1545 case SELECTED_PRESSED:
1546 mState.homeButtonId = mHomeButtonPressed.getID();
1547 break;
1548 }
1549 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001550
Daniel Sandler388f6792010-03-02 14:08:08 -05001551 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001552 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1553 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1554 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001555 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001556 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001557 }
1558 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001559 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001560 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001561 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001562 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001563 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001564 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001565 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Joe Onorato2cc62e82010-03-17 20:23:53 -07001566 Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1567 Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1568 Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1569 Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1570 Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1571 Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1572 Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1573 Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1574 Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
1575 Log.d(TAG, "sRollo.mParams.bubbleWidth=" + mParams.bubbleWidth);
1576 Log.d(TAG, "sRollo.mParams.bubbleHeight=" + mParams.bubbleHeight);
1577 Log.d(TAG, "sRollo.mParams.bubbleBitmapWidth=" + mParams.bubbleBitmapWidth);
1578 Log.d(TAG, "sRollo.mParams.bubbleBitmapHeight=" + mParams.bubbleBitmapHeight);
1579 Log.d(TAG, "sRollo.mParams.homeButtonWidth=" + mParams.homeButtonWidth);
1580 Log.d(TAG, "sRollo.mParams.homeButtonHeight=" + mParams.homeButtonHeight);
1581 Log.d(TAG, "sRollo.mParams.homeButtonTextureWidth=" + mParams.homeButtonTextureWidth);
1582 Log.d(TAG, "sRollo.mParams.homeButtonTextureHeight=" + mParams.homeButtonTextureHeight);
Daniel Sandler388f6792010-03-02 14:08:08 -05001583 }
1584 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001585
Daniel Sandler388f6792010-03-02 14:08:08 -05001586 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001587 Log.d(TAG, "sRS=" + sRS);
1588 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001589 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001590 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1591 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001592 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1593 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1594 Log.d(TAG, "mLastSelection=" + mLastSelection);
1595 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1596 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1597 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1598 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
1599 Log.d(TAG, "mZoomDirty=" + mZoomDirty);
1600 Log.d(TAG, "mAnimateNextZoom=" + mAnimateNextZoom);
1601 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001602 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001603 Log.d(TAG, "mVelocity=" + mVelocity);
1604 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001605 if (sRollo != null) {
1606 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001607 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001608 if (sRS != null) {
1609 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001610 }
1611 }
1612}
1613
1614