blob: 8467b3953a36e7c8b788bf8f488b2b1e396d317f [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
Joe Onorato878f0862010-03-22 12:22:22 -0400812 /**
813 * If sRollo is null, then we're not visible. This is also used to guard against
814 * sRollo being null.
815 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500816 public boolean isVisible() {
Joe Onorato878f0862010-03-22 12:22:22 -0400817 return sRollo != null && mZoom > 0.001f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500818 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800819
Daniel Sandler388f6792010-03-02 14:08:08 -0500820 public boolean isOpaque() {
821 return mZoom > 0.999f;
822 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800823
Daniel Sandler388f6792010-03-02 14:08:08 -0500824 public void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700825 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500826 // We've been removed from the window. Don't bother with all this.
827 return;
828 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800829
830 boolean reload = false;
831 if (mAllAppsList == null) {
832 reload = true;
833 } else if (list.size() != mAllAppsList.size()) {
834 reload = true;
835 } else {
836 final int count = list.size();
837 for (int i = 0; i < count; i++) {
838 if (list.get(i) != mAllAppsList.get(i)) {
839 reload = true;
840 break;
841 }
842 }
843 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800844
Daniel Sandler388f6792010-03-02 14:08:08 -0500845 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700846 if (sRollo != null && reload) {
847 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500848 }
Romain Guyc16fea72010-03-12 17:17:56 -0800849
850 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700851 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
852 sRollo.mState.save();
Romain Guyc16fea72010-03-12 17:17:56 -0800853 mRestoreFocusIndex = -1;
854 }
855
Daniel Sandler388f6792010-03-02 14:08:08 -0500856 mLocks &= ~LOCK_ICONS_PENDING;
857 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800858
Daniel Sandler388f6792010-03-02 14:08:08 -0500859 public void addApps(ArrayList<ApplicationInfo> list) {
860 if (mAllAppsList == null) {
861 // Not done loading yet. We'll find out about it later.
862 return;
863 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700864 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500865 // We've been removed from the window. Don't bother with all this.
866 return;
867 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800868
Daniel Sandler388f6792010-03-02 14:08:08 -0500869 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700870 if (sRollo != null) {
871 sRollo.pause();
872 sRollo.reallocAppsList(sRollo.mState.iconCount + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500873 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800874
Daniel Sandler388f6792010-03-02 14:08:08 -0500875 for (int i=0; i<N; i++) {
876 final ApplicationInfo item = list.get(i);
877 int index = Collections.binarySearch(mAllAppsList, item,
878 LauncherModel.APP_NAME_COMPARATOR);
879 if (index < 0) {
880 index = -(index+1);
881 }
882 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700883 if (sRollo != null) {
884 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500885 }
886 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800887
Joe Onorato2cc62e82010-03-17 20:23:53 -0700888 if (sRollo != null) {
889 sRollo.saveAppsList();
890 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500891 }
892 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800893
Daniel Sandler388f6792010-03-02 14:08:08 -0500894 public void removeApps(ArrayList<ApplicationInfo> list) {
895 if (mAllAppsList == null) {
896 // Not done loading yet. We'll find out about it later.
897 return;
898 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800899
Joe Onorato2cc62e82010-03-17 20:23:53 -0700900 if (sRollo != null) {
901 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800902 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500903 final int N = list.size();
904 for (int i=0; i<N; i++) {
905 final ApplicationInfo item = list.get(i);
906 int index = findAppByComponent(mAllAppsList, item);
907 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500908 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700909 if (sRollo != null) {
910 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500911 }
912 } else {
913 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
914 // Try to recover. This should keep us from crashing for now.
915 }
916 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800917
Joe Onorato2cc62e82010-03-17 20:23:53 -0700918 if (sRollo != null) {
919 sRollo.saveAppsList();
920 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500921 }
922 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800923
Joe Onorato64e6be72010-03-05 15:05:52 -0500924 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500925 // Just remove and add, because they may need to be re-sorted.
926 removeApps(list);
927 addApps(list);
928 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800929
Daniel Sandler388f6792010-03-02 14:08:08 -0500930 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
931 ComponentName component = item.intent.getComponent();
932 final int N = list.size();
933 for (int i=0; i<N; i++) {
934 ApplicationInfo x = list.get(i);
935 if (x.intent.getComponent().equals(component)) {
936 return i;
937 }
938 }
939 return -1;
940 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800941
Romain Guy060b5c82010-03-04 10:07:38 -0800942 /*
Daniel Sandler388f6792010-03-02 14:08:08 -0500943 private static int countPages(int iconCount) {
Romain Guy060b5c82010-03-04 10:07:38 -0800944 int iconsPerPage = getColumnsCount() * Defines.ROWS_PER_PAGE_PORTRAIT;
Daniel Sandler388f6792010-03-02 14:08:08 -0500945 int pages = iconCount / iconsPerPage;
946 if (pages*iconsPerPage != iconCount) {
947 pages++;
948 }
949 return pages;
950 }
Romain Guy060b5c82010-03-04 10:07:38 -0800951 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500952
953 class AAMessage extends RenderScript.RSMessage {
954 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700955 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500956 mVelocity = ((float)mData[1]) / (1 << 16);
957 mZoom = ((float)mData[2]) / (1 << 16);
958 mZoomDirty = false;
959 }
960 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800961
Romain Guy13c2e7b2010-03-10 19:45:00 -0800962 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500963 // Allocations ======
964 private int mWidth;
965 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800966
Daniel Sandler388f6792010-03-02 14:08:08 -0500967 private Resources mRes;
968 private Script mScript;
969 private Script.Invokable mInvokeMove;
970 private Script.Invokable mInvokeMoveTo;
971 private Script.Invokable mInvokeFling;
972 private Script.Invokable mInvokeResetWAR;
973 private Script.Invokable mInvokeSetZoom;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800974
Daniel Sandler388f6792010-03-02 14:08:08 -0500975 private ProgramStore mPSIcons;
976 private ProgramFragment mPFTexMip;
977 private ProgramFragment mPFTexMipAlpha;
978 private ProgramFragment mPFTexNearest;
979 private ProgramVertex mPV;
980 private ProgramVertex mPVCurve;
981 private SimpleMesh mMesh;
982 private ProgramVertex.MatrixAllocation mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800983
Daniel Sandler388f6792010-03-02 14:08:08 -0500984 private Allocation mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800985
Daniel Sandler388f6792010-03-02 14:08:08 -0500986 private Allocation mHomeButtonNormal;
987 private Allocation mHomeButtonFocused;
988 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800989
Daniel Sandler388f6792010-03-02 14:08:08 -0500990 private Allocation[] mIcons;
991 private int[] mIconIds;
992 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800993
Daniel Sandler388f6792010-03-02 14:08:08 -0500994 private Allocation[] mLabels;
995 private int[] mLabelIds;
996 private Allocation mAllocLabelIds;
997 private Allocation mSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800998
Daniel Sandler388f6792010-03-02 14:08:08 -0500999 private Bitmap mSelectionBitmap;
1000 private Canvas mSelectionCanvas;
Romain Guy6a42cf32010-03-12 16:03:52 -08001001
1002 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001003
Daniel Sandler388f6792010-03-02 14:08:08 -05001004 Params mParams;
1005 State mState;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001006
Romain Guy13c2e7b2010-03-10 19:45:00 -08001007 AllApps3D mAllApps;
1008 boolean mInitialize;
1009
Daniel Sandler388f6792010-03-02 14:08:08 -05001010 class BaseAlloc {
1011 Allocation mAlloc;
1012 Type mType;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001013
Daniel Sandler388f6792010-03-02 14:08:08 -05001014 void save() {
1015 mAlloc.data(this);
1016 }
1017 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001018
Daniel Sandler388f6792010-03-02 14:08:08 -05001019 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001020 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -08001021 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -05001022 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001023
1024 void pause() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001025 sRS.contextBindRootScript(null);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001026 }
1027
1028 void resume() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001029 sRS.contextBindRootScript(mScript);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001030 }
1031
Daniel Sandler388f6792010-03-02 14:08:08 -05001032 class Params extends BaseAlloc {
1033 Params() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001034 mType = Type.createFromClass(sRS, Params.class, 1, "ParamsClass");
1035 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001036 save();
1037 }
1038 public int bubbleWidth;
1039 public int bubbleHeight;
1040 public int bubbleBitmapWidth;
1041 public int bubbleBitmapHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001042
Daniel Sandler388f6792010-03-02 14:08:08 -05001043 public int homeButtonWidth;
1044 public int homeButtonHeight;
1045 public int homeButtonTextureWidth;
1046 public int homeButtonTextureHeight;
1047 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001048
Daniel Sandler388f6792010-03-02 14:08:08 -05001049 class State extends BaseAlloc {
1050 public float newPositionX;
1051 public int newTouchDown;
1052 public float flingVelocity;
1053 public int iconCount;
1054 public int selectedIconIndex = -1;
1055 public int selectedIconTexture;
1056 public float zoomTarget;
1057 public int homeButtonId;
1058 public float targetPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001059
Daniel Sandler388f6792010-03-02 14:08:08 -05001060 State() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001061 mType = Type.createFromClass(sRS, State.class, 1, "StateClass");
1062 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001063 save();
1064 }
1065 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001066
Romain Guy13c2e7b2010-03-10 19:45:00 -08001067 public RolloRS(AllApps3D allApps) {
1068 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -05001069 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001070
Daniel Sandler388f6792010-03-02 14:08:08 -05001071 public void init(Resources res, int width, int height) {
1072 mRes = res;
1073 mWidth = width;
1074 mHeight = height;
1075 initProgramVertex();
1076 initProgramFragment();
1077 initProgramStore();
1078 initGl();
1079 initData();
Daniel Sandler388f6792010-03-02 14:08:08 -05001080 initRs();
1081 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001082
Daniel Sandler388f6792010-03-02 14:08:08 -05001083 public void initMesh() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001084 SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001085
Daniel Sandler388f6792010-03-02 14:08:08 -05001086 for (int ct=0; ct < 16; ct++) {
1087 float pos = (1.f / (16.f - 1)) * ct;
1088 tm.addVertex(0.0f, pos);
1089 tm.addVertex(1.0f, pos);
1090 }
1091 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1092 tm.addTriangle(ct, ct+1, ct+2);
1093 tm.addTriangle(ct+1, ct+3, ct+2);
1094 }
1095 mMesh = tm.create();
1096 mMesh.setName("SMCell");
1097 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001098
Daniel Sandler388f6792010-03-02 14:08:08 -05001099 void resize(int w, int h) {
1100 mPVA.setupProjectionNormalized(w, h);
1101 mWidth = w;
1102 mHeight = h;
1103 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001104
Daniel Sandler388f6792010-03-02 14:08:08 -05001105 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001106 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001107 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001108
Joe Onorato2cc62e82010-03-17 20:23:53 -07001109 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001110 pvb.setTextureMatrixEnable(true);
1111 mPV = pvb.create();
1112 mPV.setName("PV");
1113 mPV.bindAllocation(mPVA);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001114
Joe Onorato2cc62e82010-03-17 20:23:53 -07001115 Element.Builder eb = new Element.Builder(sRS);
1116 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "ImgSize");
1117 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "Position");
1118 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "BendPos");
1119 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "ScaleOffset");
Daniel Sandler388f6792010-03-02 14:08:08 -05001120 Element e = eb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001121
Joe Onorato2cc62e82010-03-17 20:23:53 -07001122 mUniformAlloc = Allocation.createSized(sRS, e, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001123
Daniel Sandler388f6792010-03-02 14:08:08 -05001124 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001125 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Romain Guy060b5c82010-03-04 10:07:38 -08001126 String t = "void main() {\n" +
1127 // Animation
1128 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001129
Romain Guy060b5c82010-03-04 10:07:38 -08001130 " float bendY1 = UNI_BendPos.x;\n" +
1131 " float bendY2 = UNI_BendPos.y;\n" +
1132 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1133 " float bendDistance = bendY1 * 0.4;\n" +
1134 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001135
Romain Guy060b5c82010-03-04 10:07:38 -08001136 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1137 " float aDy = cos(bendAngle);\n" +
1138 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001139
Romain Guy060b5c82010-03-04 10:07:38 -08001140 " float scale = (2.0 / 480.0);\n" +
1141 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1142 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1143 " float y = 0.0;\n" +
1144 " float z = 0.0;\n" +
1145 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001146
Romain Guy060b5c82010-03-04 10:07:38 -08001147 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1148 " y += cv * aDy;\n" +
1149 " z += -cv * aDz;\n" +
1150 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1151 " lum += cv / bendDistance * distanceDimLevel;\n" +
1152 " y += cv * cos(cv * bendStep);\n" +
1153 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001154
Romain Guy060b5c82010-03-04 10:07:38 -08001155 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1156 " y += cv * aDy;\n" +
1157 " z += cv * aDz;\n" +
1158 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1159 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1160 " y += cv * cos(cv * bendStep);\n" +
1161 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001162
Romain Guy060b5c82010-03-04 10:07:38 -08001163 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001164
Romain Guy060b5c82010-03-04 10:07:38 -08001165 " vec4 pos;\n" +
1166 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1167 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1168 " pos.z = z * UNI_ScaleOffset.x;\n" +
1169 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001170
Romain Guy060b5c82010-03-04 10:07:38 -08001171 " pos.x *= 1.0 + ani * 4.0;\n" +
1172 " pos.y *= 1.0 + ani * 4.0;\n" +
1173 " pos.z -= ani * 1.5;\n" +
1174 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001175
Romain Guy060b5c82010-03-04 10:07:38 -08001176 " gl_Position = UNI_MVP * pos;\n" +
1177 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1178 " varTex0.xy = ATTRIB_position;\n" +
1179 " varTex0.y = 1.0 - varTex0.y;\n" +
1180 " varTex0.zw = vec2(0.0, 0.0);\n" +
1181 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001182 sb.setShader(t);
1183 sb.addConstant(mUniformAlloc.getType());
1184 sb.addInput(mMesh.getVertexType(0).getElement());
1185 mPVCurve = sb.create();
1186 mPVCurve.setName("PVCurve");
1187 mPVCurve.bindAllocation(mPVA);
1188 mPVCurve.bindConstants(mUniformAlloc, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001189
Joe Onorato2cc62e82010-03-17 20:23:53 -07001190 sRS.contextBindProgramVertex(mPV);
Daniel Sandler388f6792010-03-02 14:08:08 -05001191 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001192
Daniel Sandler388f6792010-03-02 14:08:08 -05001193 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001194 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001195 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1196 sb.setMag(Sampler.Value.NEAREST);
1197 sb.setWrapS(Sampler.Value.CLAMP);
1198 sb.setWrapT(Sampler.Value.CLAMP);
1199 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001200
Daniel Sandler388f6792010-03-02 14:08:08 -05001201 sb.setMin(Sampler.Value.NEAREST);
1202 sb.setMag(Sampler.Value.NEAREST);
1203 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001204
Joe Onorato2cc62e82010-03-17 20:23:53 -07001205 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001206 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1207 ProgramFragment.Builder.Format.RGBA, 0);
1208 mPFTexMip = bf.create();
1209 mPFTexMip.setName("PFTexMip");
1210 mPFTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001211
Daniel Sandler388f6792010-03-02 14:08:08 -05001212 mPFTexNearest = bf.create();
1213 mPFTexNearest.setName("PFTexNearest");
1214 mPFTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001215
Daniel Sandler388f6792010-03-02 14:08:08 -05001216 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1217 ProgramFragment.Builder.Format.ALPHA, 0);
1218 mPFTexMipAlpha = bf.create();
1219 mPFTexMipAlpha.setName("PFTexMipAlpha");
1220 mPFTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001221
Daniel Sandler388f6792010-03-02 14:08:08 -05001222 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001223
Daniel Sandler388f6792010-03-02 14:08:08 -05001224 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001225 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001226 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1227 bs.setColorMask(true,true,true,false);
1228 bs.setDitherEnable(true);
1229 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1230 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
1231 mPSIcons = bs.create();
1232 mPSIcons.setName("PSIcons");
1233 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001234
Daniel Sandler388f6792010-03-02 14:08:08 -05001235 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001236 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001237
Daniel Sandler388f6792010-03-02 14:08:08 -05001238 private void initData() {
1239 mParams = new Params();
1240 mState = new State();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001241
Romain Guy13c2e7b2010-03-10 19:45:00 -08001242 final Utilities.BubbleText bubble = new Utilities.BubbleText(mAllApps.getContext());
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001243
Daniel Sandler388f6792010-03-02 14:08:08 -05001244 mParams.bubbleWidth = bubble.getBubbleWidth();
1245 mParams.bubbleHeight = bubble.getMaxBubbleHeight();
1246 mParams.bubbleBitmapWidth = bubble.getBitmapWidth();
1247 mParams.bubbleBitmapHeight = bubble.getBitmapHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001248
Joe Onorato2cc62e82010-03-17 20:23:53 -07001249 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1250 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001251 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001252 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1253 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001254 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001255 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1256 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001257 mHomeButtonPressed.uploadToTexture(0);
1258 mParams.homeButtonWidth = 76;
1259 mParams.homeButtonHeight = 68;
1260 mParams.homeButtonTextureWidth = 128;
1261 mParams.homeButtonTextureHeight = 128;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001262
Daniel Sandler388f6792010-03-02 14:08:08 -05001263 mState.homeButtonId = mHomeButtonNormal.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001264
Daniel Sandler388f6792010-03-02 14:08:08 -05001265 mParams.save();
1266 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001267
Daniel Sandler388f6792010-03-02 14:08:08 -05001268 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1269 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1270 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001271
Daniel Sandler388f6792010-03-02 14:08:08 -05001272 setApps(null);
1273 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001274
Daniel Sandler388f6792010-03-02 14:08:08 -05001275 private void initRs() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001276 ScriptC.Builder sb = new ScriptC.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001277 sb.setScript(mRes, R.raw.allapps);
1278 sb.setRoot(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001279 sb.addDefines(mAllApps.mDefines);
Daniel Sandler388f6792010-03-02 14:08:08 -05001280 sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS);
1281 sb.setType(mState.mType, "state", Defines.ALLOC_STATE);
1282 sb.setType(mUniformAlloc.getType(), "vpConstants", Defines.ALLOC_VP_CONSTANTS);
1283 mInvokeMove = sb.addInvokable("move");
1284 mInvokeFling = sb.addInvokable("fling");
1285 mInvokeMoveTo = sb.addInvokable("moveTo");
1286 mInvokeResetWAR = sb.addInvokable("resetHWWar");
1287 mInvokeSetZoom = sb.addInvokable("setZoom");
1288 mScript = sb.create();
1289 mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1290 mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
1291 mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
1292 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1293 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
1294 mScript.bindAllocation(mUniformAlloc, Defines.ALLOC_VP_CONSTANTS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001295
Joe Onorato2cc62e82010-03-17 20:23:53 -07001296 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -05001297 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001298
Daniel Sandler388f6792010-03-02 14:08:08 -05001299 void dirtyCheck() {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001300 if (mAllApps.mZoomDirty) {
1301 setZoom(mAllApps.mNextZoom, mAllApps.mAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001302 }
1303 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001304
Romain Guy060b5c82010-03-04 10:07:38 -08001305 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001306 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001307 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001308 final int count = list != null ? list.size() : 0;
1309 int allocCount = count;
1310 if (allocCount < 1) {
1311 allocCount = 1;
1312 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001313
Daniel Sandler388f6792010-03-02 14:08:08 -05001314 mIcons = new Allocation[count];
1315 mIconIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001316 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001317
Daniel Sandler388f6792010-03-02 14:08:08 -05001318 mLabels = new Allocation[count];
1319 mLabelIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001320 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001321
Daniel Sandler388f6792010-03-02 14:08:08 -05001322 mState.iconCount = count;
1323 for (int i=0; i < mState.iconCount; i++) {
1324 createAppIconAllocations(i, list.get(i));
1325 }
1326 for (int i=0; i < mState.iconCount; i++) {
1327 uploadAppIcon(i, list.get(i));
1328 }
1329 saveAppsList();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001330 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001331 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001332
Daniel Sandler388f6792010-03-02 14:08:08 -05001333 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001334 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001335 sRollo.clearSelectedIcon();
1336 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001337 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001338 if (zoom > 0.001f) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001339 sRollo.mState.zoomTarget = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -05001340 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001341 sRollo.mState.zoomTarget = 0;
Daniel Sandler388f6792010-03-02 14:08:08 -05001342 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001343 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -05001344 if (!animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001345 sRollo.mInvokeSetZoom.execute();
Daniel Sandler388f6792010-03-02 14:08:08 -05001346 }
1347 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001348
Daniel Sandler388f6792010-03-02 14:08:08 -05001349 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001350 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1351 Element.RGBA_8888(sRS), false);
1352 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1353 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001354 mIconIds[index] = mIcons[index].getID();
1355 mLabelIds[index] = mLabels[index].getID();
1356 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001357
Daniel Sandler388f6792010-03-02 14:08:08 -05001358 private void uploadAppIcon(int index, ApplicationInfo item) {
1359 if (mIconIds[index] != mIcons[index].getID()) {
1360 throw new IllegalStateException("uploadAppIcon index=" + index
1361 + " mIcons[index].getID=" + mIcons[index].getID()
1362 + " mIconsIds[index]=" + mIconIds[index]
1363 + " item=" + item);
1364 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001365 mIcons[index].uploadToTexture(true, 0);
1366 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001367 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001368
Daniel Sandler388f6792010-03-02 14:08:08 -05001369 /**
1370 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1371 * fill in the values and call saveAppsList().
1372 */
1373 private void reallocAppsList(int count) {
1374 Allocation[] icons = new Allocation[count];
1375 int[] iconIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001376 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001377
Daniel Sandler388f6792010-03-02 14:08:08 -05001378 Allocation[] labels = new Allocation[count];
1379 int[] labelIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001380 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001381
Joe Onorato2cc62e82010-03-17 20:23:53 -07001382 final int oldCount = sRollo.mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001383
Daniel Sandler388f6792010-03-02 14:08:08 -05001384 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1385 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1386 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1387 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001388
Daniel Sandler388f6792010-03-02 14:08:08 -05001389 mIcons = icons;
1390 mIconIds = iconIds;
1391 mLabels = labels;
1392 mLabelIds = labelIds;
1393 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001394
Daniel Sandler388f6792010-03-02 14:08:08 -05001395 /**
1396 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1397 */
1398 private void addApp(int index, ApplicationInfo item) {
1399 final int count = mState.iconCount - index;
1400 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001401
Daniel Sandler388f6792010-03-02 14:08:08 -05001402 System.arraycopy(mIcons, index, mIcons, dest, count);
1403 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1404 System.arraycopy(mLabels, index, mLabels, dest, count);
1405 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001406
Daniel Sandler388f6792010-03-02 14:08:08 -05001407 createAppIconAllocations(index, item);
1408 uploadAppIcon(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001409 sRollo.mState.iconCount++;
Daniel Sandler388f6792010-03-02 14:08:08 -05001410 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001411
Daniel Sandler388f6792010-03-02 14:08:08 -05001412 /**
1413 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1414 */
1415 private void removeApp(int index) {
1416 final int count = mState.iconCount - index - 1;
1417 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001418
Daniel Sandler388f6792010-03-02 14:08:08 -05001419 System.arraycopy(mIcons, src, mIcons, index, count);
1420 System.arraycopy(mIconIds, src, mIconIds, index, count);
1421 System.arraycopy(mLabels, src, mLabels, index, count);
1422 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001423
Joe Onorato2cc62e82010-03-17 20:23:53 -07001424 sRollo.mState.iconCount--;
Daniel Sandler388f6792010-03-02 14:08:08 -05001425 final int last = mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001426
Daniel Sandler388f6792010-03-02 14:08:08 -05001427 mIcons[last] = null;
1428 mIconIds[last] = 0;
1429 mLabels[last] = null;
1430 mLabelIds[last] = 0;
1431 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001432
Daniel Sandler388f6792010-03-02 14:08:08 -05001433 /**
1434 * Send the apps list structures to RS.
1435 */
1436 private void saveAppsList() {
1437 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1438 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001439 mAllocIconIds.data(mIconIds);
1440 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001441
Daniel Sandler388f6792010-03-02 14:08:08 -05001442 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1443 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001444
Daniel Sandler388f6792010-03-02 14:08:08 -05001445 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001446
Daniel Sandler388f6792010-03-02 14:08:08 -05001447 // Note: mScript may be null if we haven't initialized it yet.
1448 // In that case, this is a no-op.
1449 if (mInvokeResetWAR != null) {
1450 mInvokeResetWAR.execute();
1451 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001452 }
1453 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001454
Daniel Sandler388f6792010-03-02 14:08:08 -05001455 void fling() {
1456 mInvokeFling.execute();
1457 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001458
Daniel Sandler388f6792010-03-02 14:08:08 -05001459 void move() {
1460 mInvokeMove.execute();
1461 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001462
Daniel Sandler388f6792010-03-02 14:08:08 -05001463 void moveTo(float row) {
1464 mState.targetPos = row;
1465 mState.save();
1466 mInvokeMoveTo.execute();
1467 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001468
Daniel Sandler388f6792010-03-02 14:08:08 -05001469 /**
1470 * You need to call save() on mState on your own after calling this.
1471 *
1472 * @return the index of the icon that was selected.
1473 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001474 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001475 if (mAllApps != null) {
1476 final int index = mAllApps.chooseTappedIcon(x, y);
1477 selectIcon(index, pressed);
1478 return index;
1479 } else {
1480 return -1;
1481 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001482 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001483
Daniel Sandler388f6792010-03-02 14:08:08 -05001484 /**
1485 * Select the icon at the given index.
1486 *
1487 * @param index The index.
1488 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1489 */
1490 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001491 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1492 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001493 if (mAllApps != null) {
1494 mAllApps.mRestoreFocusIndex = index;
1495 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001496 mState.selectedIconIndex = -1;
Romain Guy13c2e7b2010-03-10 19:45:00 -08001497 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1498 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001499 }
1500 } else {
1501 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001502 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001503 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001504
Daniel Sandler388f6792010-03-02 14:08:08 -05001505 int prev = mState.selectedIconIndex;
1506 mState.selectedIconIndex = index;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001507
Romain Guy13c2e7b2010-03-10 19:45:00 -08001508 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001509 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001510
Daniel Sandler388f6792010-03-02 14:08:08 -05001511 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1512 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1513 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001514
Joe Onorato2cc62e82010-03-17 20:23:53 -07001515 mSelectedIcon = Allocation.createFromBitmap(sRS, selectionBitmap,
1516 Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001517 mSelectedIcon.uploadToTexture(0);
1518 mState.selectedIconTexture = mSelectedIcon.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001519
Daniel Sandler388f6792010-03-02 14:08:08 -05001520 if (prev != index) {
1521 if (info.title != null && info.title.length() > 0) {
1522 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001523 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001524 }
1525 }
1526 }
1527 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001528
Daniel Sandler388f6792010-03-02 14:08:08 -05001529 /**
1530 * You need to call save() on mState on your own after calling this.
1531 */
1532 void clearSelectedIcon() {
1533 mState.selectedIconIndex = -1;
1534 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001535
Daniel Sandler388f6792010-03-02 14:08:08 -05001536 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001537 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001538 switch (mode) {
1539 case SELECTED_NONE:
1540 mState.homeButtonId = mHomeButtonNormal.getID();
1541 break;
1542 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001543 mAllApps.mLastSelection = SELECTION_HOME;
Daniel Sandler388f6792010-03-02 14:08:08 -05001544 mState.homeButtonId = mHomeButtonFocused.getID();
1545 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001546 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001547 }
1548 break;
1549 case SELECTED_PRESSED:
1550 mState.homeButtonId = mHomeButtonPressed.getID();
1551 break;
1552 }
1553 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001554
Daniel Sandler388f6792010-03-02 14:08:08 -05001555 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001556 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1557 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1558 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001559 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001560 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001561 }
1562 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001563 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001564 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001565 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001566 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001567 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001568 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001569 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Joe Onorato2cc62e82010-03-17 20:23:53 -07001570 Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1571 Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1572 Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1573 Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1574 Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1575 Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1576 Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1577 Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1578 Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
1579 Log.d(TAG, "sRollo.mParams.bubbleWidth=" + mParams.bubbleWidth);
1580 Log.d(TAG, "sRollo.mParams.bubbleHeight=" + mParams.bubbleHeight);
1581 Log.d(TAG, "sRollo.mParams.bubbleBitmapWidth=" + mParams.bubbleBitmapWidth);
1582 Log.d(TAG, "sRollo.mParams.bubbleBitmapHeight=" + mParams.bubbleBitmapHeight);
1583 Log.d(TAG, "sRollo.mParams.homeButtonWidth=" + mParams.homeButtonWidth);
1584 Log.d(TAG, "sRollo.mParams.homeButtonHeight=" + mParams.homeButtonHeight);
1585 Log.d(TAG, "sRollo.mParams.homeButtonTextureWidth=" + mParams.homeButtonTextureWidth);
1586 Log.d(TAG, "sRollo.mParams.homeButtonTextureHeight=" + mParams.homeButtonTextureHeight);
Daniel Sandler388f6792010-03-02 14:08:08 -05001587 }
1588 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001589
Daniel Sandler388f6792010-03-02 14:08:08 -05001590 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001591 Log.d(TAG, "sRS=" + sRS);
1592 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001593 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001594 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1595 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001596 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1597 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1598 Log.d(TAG, "mLastSelection=" + mLastSelection);
1599 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1600 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1601 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1602 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
1603 Log.d(TAG, "mZoomDirty=" + mZoomDirty);
1604 Log.d(TAG, "mAnimateNextZoom=" + mAnimateNextZoom);
1605 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001606 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001607 Log.d(TAG, "mVelocity=" + mVelocity);
1608 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001609 if (sRollo != null) {
1610 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001611 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001612 if (sRS != null) {
1613 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001614 }
1615 }
1616}
1617
1618