blob: 499025443ebc7fa6b66e0a8427b3ff2274a76749 [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
Winson Chungaafa03c2010-06-11 17:34:16 -070019import java.util.ArrayList;
20import java.util.Arrays;
21import java.util.Collections;
22
Alex Sakhartchouk95252b42010-09-13 20:44:01 -070023import com.android.launcher.R;
24
Daniel Sandler388f6792010-03-02 14:08:08 -050025import android.content.ComponentName;
26import android.content.Context;
27import android.content.res.Resources;
28import android.graphics.Bitmap;
29import android.graphics.Canvas;
30import android.graphics.PixelFormat;
31import android.graphics.Rect;
Alex Sakhartchouk95252b42010-09-13 20:44:01 -070032import android.renderscript.*;
Daniel Sandler388f6792010-03-02 14:08:08 -050033import android.util.AttributeSet;
Romain Guy060b5c82010-03-04 10:07:38 -080034import android.util.DisplayMetrics;
Daniel Sandler388f6792010-03-02 14:08:08 -050035import android.util.Log;
36import android.view.KeyEvent;
37import android.view.MotionEvent;
38import android.view.SoundEffectConstants;
39import android.view.SurfaceHolder;
40import android.view.VelocityTracker;
41import android.view.View;
42import android.view.ViewConfiguration;
43import android.view.accessibility.AccessibilityEvent;
44
Daniel Sandler388f6792010-03-02 14:08:08 -050045public class AllApps3D extends RSSurfaceView
46 implements AllAppsView, View.OnClickListener, View.OnLongClickListener, DragSource {
47 private static final String TAG = "Launcher.AllApps3D";
48
49 /** Bit for mLocks for when there are icons being loaded. */
50 private static final int LOCK_ICONS_PENDING = 1;
51
52 private static final int TRACKING_NONE = 0;
53 private static final int TRACKING_FLING = 1;
54 private static final int TRACKING_HOME = 2;
55
56 private static final int SELECTED_NONE = 0;
57 private static final int SELECTED_FOCUSED = 1;
58 private static final int SELECTED_PRESSED = 2;
59
60 private static final int SELECTION_NONE = 0;
61 private static final int SELECTION_ICONS = 1;
62 private static final int SELECTION_HOME = 2;
63
64 private Launcher mLauncher;
65 private DragController mDragController;
66
67 /** When this is 0, modifications are allowed, when it's not, they're not.
68 * TODO: What about scrolling? */
69 private int mLocks = LOCK_ICONS_PENDING;
70
71 private int mSlop;
72 private int mMaxFlingVelocity;
73
74 private Defines mDefines = new Defines();
Daniel Sandler388f6792010-03-02 14:08:08 -050075 private ArrayList<ApplicationInfo> mAllAppsList;
76
Joe Onorato2cc62e82010-03-17 20:23:53 -070077 private static RenderScriptGL sRS;
78 private static RolloRS sRollo;
Jason Samsdd8cd8b2010-03-11 12:38:48 -080079
Joe Onoratoeffc4a82010-04-15 11:48:13 -070080 private static boolean sZoomDirty = false;
81 private static boolean sAnimateNextZoom;
82 private static float sNextZoom;
83
Daniel Sandler388f6792010-03-02 14:08:08 -050084 /**
85 * True when we are using arrow keys or trackball to drive navigation
86 */
87 private boolean mArrowNavigation = false;
88 private boolean mStartedScrolling;
89
90 /**
91 * Used to keep track of the selection when AllAppsView loses window focus.
92 * One of the SELECTION_ constants.
93 */
94 private int mLastSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -080095
Daniel Sandler388f6792010-03-02 14:08:08 -050096 /**
97 * Used to keep track of the selection when AllAppsView loses window focus
98 */
99 private int mLastSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800100
Daniel Sandler388f6792010-03-02 14:08:08 -0500101 private VelocityTracker mVelocityTracker;
102 private int mTouchTracking;
103 private int mMotionDownRawX;
104 private int mMotionDownRawY;
105 private int mDownIconIndex = -1;
106 private int mCurrentIconIndex = -1;
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700107 private int[] mTouchYBorders;
108 private int[] mTouchXBorders;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800109
Daniel Sandler388f6792010-03-02 14:08:08 -0500110 private boolean mShouldGainFocus;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800111
Daniel Sandler388f6792010-03-02 14:08:08 -0500112 private boolean mHaveSurface = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500113 private float mZoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500114 private float mVelocity;
115 private AAMessage mMessageProc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800116
Romain Guy060b5c82010-03-04 10:07:38 -0800117 private int mColumnsPerPage;
118 private int mRowsPerPage;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800119 private boolean mSurrendered;
120
Romain Guyc16fea72010-03-12 17:17:56 -0800121 private int mRestoreFocusIndex = -1;
Jason Sams14f67ed2010-05-11 14:02:43 -0700122
Romain Guy060b5c82010-03-04 10:07:38 -0800123 @SuppressWarnings({"UnusedDeclaration"})
Daniel Sandler388f6792010-03-02 14:08:08 -0500124 static class Defines {
Romain Guy060b5c82010-03-04 10:07:38 -0800125 public static final int COLUMNS_PER_PAGE_PORTRAIT = 4;
126 public static final int ROWS_PER_PAGE_PORTRAIT = 4;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800127
Romain Guy060b5c82010-03-04 10:07:38 -0800128 public static final int COLUMNS_PER_PAGE_LANDSCAPE = 6;
129 public static final int ROWS_PER_PAGE_LANDSCAPE = 3;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800130
Daniel Sandler388f6792010-03-02 14:08:08 -0500131 public static final int SELECTION_TEXTURE_WIDTH_PX = 74 + 20;
Daniel Sandler388f6792010-03-02 14:08:08 -0500132 public static final int SELECTION_TEXTURE_HEIGHT_PX = 74 + 20;
133 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800134
Daniel Sandler388f6792010-03-02 14:08:08 -0500135 public AllApps3D(Context context, AttributeSet attrs) {
136 super(context, attrs);
137 setFocusable(true);
138 setSoundEffectsEnabled(false);
Daniel Sandler388f6792010-03-02 14:08:08 -0500139 final ViewConfiguration config = ViewConfiguration.get(context);
140 mSlop = config.getScaledTouchSlop();
141 mMaxFlingVelocity = config.getScaledMaximumFlingVelocity();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800142
Daniel Sandler388f6792010-03-02 14:08:08 -0500143 setOnClickListener(this);
144 setOnLongClickListener(this);
145 setZOrderOnTop(true);
146 getHolder().setFormat(PixelFormat.TRANSLUCENT);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800147
Joe Onorato2cc62e82010-03-17 20:23:53 -0700148 if (sRS == null) {
Jason Samse5806ba2010-10-10 13:07:24 -0700149 RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
150 sc.setDepth(16, 16);
151 sc.setAlpha(8, 8);
Jason Sams4dfea092010-12-06 17:38:58 -0800152 sRS = createRenderScriptGL(sc);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800153 } else {
Jason Sams4dfea092010-12-06 17:38:58 -0800154 // Is this even possible?
155 setRenderScriptGL(sRS);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800156 }
157
Romain Guy060b5c82010-03-04 10:07:38 -0800158 final DisplayMetrics metrics = getResources().getDisplayMetrics();
159 final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
160 mColumnsPerPage = isPortrait ? Defines.COLUMNS_PER_PAGE_PORTRAIT :
161 Defines.COLUMNS_PER_PAGE_LANDSCAPE;
162 mRowsPerPage = isPortrait ? Defines.ROWS_PER_PAGE_PORTRAIT :
163 Defines.ROWS_PER_PAGE_LANDSCAPE;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800164
Joe Onorato2cc62e82010-03-17 20:23:53 -0700165 if (sRollo != null) {
166 sRollo.mAllApps = this;
167 sRollo.mRes = getResources();
168 sRollo.mInitialize = true;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800169 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500170 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800171
Romain Guy060b5c82010-03-04 10:07:38 -0800172 @SuppressWarnings({"UnusedDeclaration"})
173 public AllApps3D(Context context, AttributeSet attrs, int defStyle) {
174 this(context, attrs);
175 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800176
Romain Guy13c2e7b2010-03-10 19:45:00 -0800177 public void surrender() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400178 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -0800179 sRS.setSurface(null, 0, 0);
180 sRS.setMessageHandler(null);
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400181 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800182 mSurrendered = true;
183 }
184
Daniel Sandler388f6792010-03-02 14:08:08 -0500185 /**
186 * Note that this implementation prohibits this view from ever being reattached.
187 */
188 @Override
189 protected void onDetachedFromWindow() {
Jason Sams4dfea092010-12-06 17:38:58 -0800190 sRS.setMessageHandler(null);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800191 if (!mSurrendered) {
Joe Onorato96da4012010-03-17 20:03:24 -0700192 Log.i(TAG, "onDetachedFromWindow");
Jason Sams4dfea092010-12-06 17:38:58 -0800193 destroyRenderScriptGL();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700194 sRS = null;
195 sRollo = null;
thigobr1f43a312010-10-22 18:13:26 -0200196 super.onDetachedFromWindow();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800197 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500198 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800199
Daniel Sandler388f6792010-03-02 14:08:08 -0500200 /**
201 * If you have an attached click listener, View always plays the click sound!?!?
202 * Deal with sound effects by hand.
203 */
204 public void reallyPlaySoundEffect(int sound) {
205 boolean old = isSoundEffectsEnabled();
206 setSoundEffectsEnabled(true);
207 playSoundEffect(sound);
208 setSoundEffectsEnabled(old);
209 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800210
Winson Chung785d2eb2011-04-14 16:08:02 -0700211 @Override
212 public void setup(Launcher launcher, DragController dragController) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500213 mLauncher = launcher;
Winson Chung785d2eb2011-04-14 16:08:02 -0700214 mDragController = dragController;
Daniel Sandler388f6792010-03-02 14:08:08 -0500215 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800216
Daniel Sandler388f6792010-03-02 14:08:08 -0500217 @Override
218 public void surfaceDestroyed(SurfaceHolder holder) {
219 super.surfaceDestroyed(holder);
220 // Without this, we leak mMessageCallback which leaks the context.
Romain Guy13c2e7b2010-03-10 19:45:00 -0800221 if (!mSurrendered) {
Jason Sams4dfea092010-12-06 17:38:58 -0800222 sRS.setMessageHandler(null);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800223 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500224 // We may lose any callbacks that are pending, so make sure that we re-sync that
225 // on the next surfaceChanged.
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700226 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500227 mHaveSurface = false;
228 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800229
Daniel Sandler388f6792010-03-02 14:08:08 -0500230 @Override
231 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
232 //long startTime = SystemClock.uptimeMillis();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800233
Daniel Sandler388f6792010-03-02 14:08:08 -0500234 super.surfaceChanged(holder, format, w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800235
Romain Guy13c2e7b2010-03-10 19:45:00 -0800236 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800237
Daniel Sandler388f6792010-03-02 14:08:08 -0500238 mHaveSurface = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800239
Joe Onorato2cc62e82010-03-17 20:23:53 -0700240 if (sRollo == null) {
241 sRollo = new RolloRS(this);
242 sRollo.init(getResources(), w, h);
Daniel Sandler388f6792010-03-02 14:08:08 -0500243 if (mAllAppsList != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700244 sRollo.setApps(mAllAppsList);
Daniel Sandler388f6792010-03-02 14:08:08 -0500245 }
246 if (mShouldGainFocus) {
247 gainFocus();
248 mShouldGainFocus = false;
249 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700250 } else if (sRollo.mInitialize) {
251 sRollo.initGl();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700252 sRollo.mInitialize = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500253 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800254
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700255 initTouchState(w, h);
256
Joe Onorato2cc62e82010-03-17 20:23:53 -0700257 sRollo.dirtyCheck();
258 sRollo.resize(w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800259
Jason Sams14f67ed2010-05-11 14:02:43 -0700260 Log.d(TAG, "sc " + sRS);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700261 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -0800262 mMessageProc = new AAMessage();
263 sRS.setMessageHandler(mMessageProc);
Daniel Sandler388f6792010-03-02 14:08:08 -0500264 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800265
Daniel Sandler388f6792010-03-02 14:08:08 -0500266 //long endTime = SystemClock.uptimeMillis();
267 //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
268 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800269
Daniel Sandler388f6792010-03-02 14:08:08 -0500270 @Override
271 public void onWindowFocusChanged(boolean hasWindowFocus) {
272 super.onWindowFocusChanged(hasWindowFocus);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800273
274 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800275
Daniel Sandler388f6792010-03-02 14:08:08 -0500276 if (mArrowNavigation) {
277 if (!hasWindowFocus) {
278 // Clear selection when we lose window focus
Jason Sams14f67ed2010-05-11 14:02:43 -0700279 mLastSelectedIcon = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700280 sRollo.setHomeSelected(SELECTED_NONE);
281 sRollo.clearSelectedIcon();
Romain Guy060b5c82010-03-04 10:07:38 -0800282 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700283 if (sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500284 if (mLastSelection == SELECTION_ICONS) {
285 int selection = mLastSelectedIcon;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700286 final int firstIcon = Math.round(sRollo.mScrollPos) * mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500287 if (selection < 0 || // No selection
288 selection < firstIcon || // off the top of the screen
Jason Sams14f67ed2010-05-11 14:02:43 -0700289 selection >= sRollo.mScript.get_gIconCount() || // past last icon
Daniel Sandler388f6792010-03-02 14:08:08 -0500290 selection >= firstIcon + // past last icon on screen
Romain Guy060b5c82010-03-04 10:07:38 -0800291 (mColumnsPerPage * mRowsPerPage)) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500292 selection = firstIcon;
293 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800294
Daniel Sandler388f6792010-03-02 14:08:08 -0500295 // Select the first icon when we gain window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700296 sRollo.selectIcon(selection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500297 } else if (mLastSelection == SELECTION_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700298 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500299 }
300 }
301 }
302 }
303 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800304
Daniel Sandler388f6792010-03-02 14:08:08 -0500305 @Override
306 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
307 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800308
Romain Guy13c2e7b2010-03-10 19:45:00 -0800309 if (!isVisible() || mSurrendered) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500310 return;
311 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800312
Daniel Sandler388f6792010-03-02 14:08:08 -0500313 if (gainFocus) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700314 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500315 gainFocus();
316 } else {
317 mShouldGainFocus = true;
318 }
319 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700320 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500321 if (mArrowNavigation) {
322 // Clear selection when we lose focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700323 sRollo.clearSelectedIcon();
324 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500325 mArrowNavigation = false;
326 }
327 } else {
328 mShouldGainFocus = false;
329 }
330 }
331 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800332
Daniel Sandler388f6792010-03-02 14:08:08 -0500333 private void gainFocus() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700334 if (!mArrowNavigation && sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500335 // Select the first icon when we gain keyboard focus
336 mArrowNavigation = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700337 sRollo.selectIcon(Math.round(sRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500338 }
339 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800340
Daniel Sandler388f6792010-03-02 14:08:08 -0500341 @Override
342 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800343
Daniel Sandler388f6792010-03-02 14:08:08 -0500344 boolean handled = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800345
Daniel Sandler388f6792010-03-02 14:08:08 -0500346 if (!isVisible()) {
347 return false;
348 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700349 final int iconCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800350
Daniel Sandler388f6792010-03-02 14:08:08 -0500351 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
352 if (mArrowNavigation) {
353 if (mLastSelection == SELECTION_HOME) {
354 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
Winson Chung097eb0a2011-03-18 16:56:08 -0700355 mLauncher.showWorkspace(true);
Daniel Sandler388f6792010-03-02 14:08:08 -0500356 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700357 int whichApp = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500358 if (whichApp >= 0) {
359 ApplicationInfo app = mAllAppsList.get(whichApp);
Joe Onoratof984e852010-03-25 09:47:45 -0700360 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500361 handled = true;
362 }
363 }
364 }
365 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800366
Daniel Sandler388f6792010-03-02 14:08:08 -0500367 if (iconCount > 0) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800368 final boolean isPortrait = getWidth() < getHeight();
Jason Sams14f67ed2010-05-11 14:02:43 -0700369
Daniel Sandler388f6792010-03-02 14:08:08 -0500370 mArrowNavigation = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800371
Jason Sams14f67ed2010-05-11 14:02:43 -0700372 int currentSelection = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700373 int currentTopRow = Math.round(sRollo.mScrollPos);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800374
Romain Guy060b5c82010-03-04 10:07:38 -0800375 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1
376 final int currentPageCol = currentSelection % mColumnsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800377
Romain Guy060b5c82010-03-04 10:07:38 -0800378 // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1
Romain Guy6a42cf32010-03-12 16:03:52 -0800379 final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage))
Romain Guy060b5c82010-03-04 10:07:38 -0800380 / mRowsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800381
Daniel Sandler388f6792010-03-02 14:08:08 -0500382 int newSelection = currentSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800383
Daniel Sandler388f6792010-03-02 14:08:08 -0500384 switch (keyCode) {
385 case KeyEvent.KEYCODE_DPAD_UP:
386 if (mLastSelection == SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800387 if (isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700388 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guy6a42cf32010-03-12 16:03:52 -0800389 int lastRowCount = iconCount % mColumnsPerPage;
390 if (lastRowCount == 0) {
391 lastRowCount = mColumnsPerPage;
392 }
393 newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2);
394 if (newSelection >= iconCount) {
395 newSelection = iconCount-1;
396 }
397 int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
398 if (target < 0) {
399 target = 0;
400 }
401 if (currentTopRow != target) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700402 sRollo.moveTo(target);
Romain Guy6a42cf32010-03-12 16:03:52 -0800403 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500404 }
405 } else {
406 if (currentPageRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800407 newSelection = currentSelection - mColumnsPerPage;
Romain Guy6a42cf32010-03-12 16:03:52 -0800408 if (currentTopRow > newSelection / mColumnsPerPage) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700409 sRollo.moveTo(newSelection / mColumnsPerPage);
Romain Guy6a42cf32010-03-12 16:03:52 -0800410 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500411 } else if (currentTopRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800412 newSelection = currentSelection - mColumnsPerPage;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700413 sRollo.moveTo(newSelection / mColumnsPerPage);
Daniel Sandler388f6792010-03-02 14:08:08 -0500414 } else if (currentPageRow != 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800415 newSelection = currentTopRow * mRowsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500416 }
417 }
418 handled = true;
419 break;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800420
Daniel Sandler388f6792010-03-02 14:08:08 -0500421 case KeyEvent.KEYCODE_DPAD_DOWN: {
Romain Guy060b5c82010-03-04 10:07:38 -0800422 final int rowCount = iconCount / mColumnsPerPage
423 + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
424 final int currentRow = currentSelection / mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500425 if (mLastSelection != SELECTION_HOME) {
426 if (currentRow < rowCount-1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700427 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500428 if (currentSelection < 0) {
429 newSelection = 0;
430 } else {
Romain Guy060b5c82010-03-04 10:07:38 -0800431 newSelection = currentSelection + mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500432 }
433 if (newSelection >= iconCount) {
434 // Go from D to G in this arrangement:
435 // A B C D
436 // E F G
437 newSelection = iconCount - 1;
438 }
Romain Guy060b5c82010-03-04 10:07:38 -0800439 if (currentPageRow >= mRowsPerPage - 1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700440 sRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -0500441 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800442 } else if (isPortrait) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500443 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700444 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500445 }
446 }
447 handled = true;
448 break;
449 }
450 case KeyEvent.KEYCODE_DPAD_LEFT:
451 if (mLastSelection != SELECTION_HOME) {
452 if (currentPageCol > 0) {
453 newSelection = currentSelection - 1;
454 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800455 } else if (!isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700456 newSelection = ((int) (sRollo.mScrollPos) * mColumnsPerPage) +
Romain Guy6a42cf32010-03-12 16:03:52 -0800457 (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700458 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500459 }
460 handled = true;
461 break;
462 case KeyEvent.KEYCODE_DPAD_RIGHT:
463 if (mLastSelection != SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800464 if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 ||
465 currentSelection == iconCount - 1)) {
466 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700467 sRollo.setHomeSelected(SELECTED_FOCUSED);
Romain Guy6a42cf32010-03-12 16:03:52 -0800468 } else if ((currentPageCol < mColumnsPerPage - 1) &&
Daniel Sandler388f6792010-03-02 14:08:08 -0500469 (currentSelection < iconCount - 1)) {
470 newSelection = currentSelection + 1;
471 }
472 }
473 handled = true;
474 break;
475 }
476 if (newSelection != currentSelection) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700477 sRollo.selectIcon(newSelection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500478 }
479 }
480 return handled;
481 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800482
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700483 void initTouchState(int width, int height) {
484 boolean isPortrait = width < height;
485
486 int[] viewPos = new int[2];
487 getLocationOnScreen(viewPos);
488
489 mTouchXBorders = new int[mColumnsPerPage + 1];
490 mTouchYBorders = new int[mRowsPerPage + 1];
491
492 // TODO: Put this in a config file/define
493 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE_PORTRAIT;
494 if (!isPortrait) cellHeight -= 12;
495 int centerY = (int) (height * (isPortrait ? 0.5f : 0.47f));
496 if (!isPortrait) centerY += cellHeight / 2;
497 int half = (int) Math.floor((mRowsPerPage + 1) / 2);
498 int end = mTouchYBorders.length - (half + 1);
499
500 for (int i = -half; i <= end; i++) {
501 mTouchYBorders[i + half] = centerY + (i * cellHeight) - viewPos[1];
502 }
503
504 int x = 0;
505 // TODO: Put this in a config file/define
506 int columnWidth = 120;
507 for (int i = 0; i < mColumnsPerPage + 1; i++) {
508 mTouchXBorders[i] = x - viewPos[0];
509 x += columnWidth;
510 }
511 }
512
513 int chooseTappedIcon(int x, int y) {
514 float pos = sRollo != null ? sRollo.mScrollPos : 0;
515
516 int oldY = y;
517
518 // Adjust for scroll position if not zero.
519 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
520
521 int col = -1;
522 int row = -1;
523 final int columnsCount = mColumnsPerPage;
524 for (int i=0; i< columnsCount; i++) {
525 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
526 col = i;
527 break;
528 }
529 }
530 final int rowsCount = mRowsPerPage;
531 for (int i=0; i< rowsCount; i++) {
532 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
533 row = i;
534 break;
535 }
536 }
537
538 if (row < 0 || col < 0) {
539 return -1;
540 }
541
542 int index = (((int) pos) * columnsCount) + (row * columnsCount) + col;
543
544 if (index >= mAllAppsList.size()) {
545 return -1;
546 } else {
547 return index;
548 }
549 }
550
Daniel Sandler388f6792010-03-02 14:08:08 -0500551 @Override
552 public boolean onTouchEvent(MotionEvent ev)
553 {
554 mArrowNavigation = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800555
Daniel Sandler388f6792010-03-02 14:08:08 -0500556 if (!isVisible()) {
557 return true;
558 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800559
Daniel Sandler388f6792010-03-02 14:08:08 -0500560 if (mLocks != 0) {
561 return true;
562 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800563
Daniel Sandler388f6792010-03-02 14:08:08 -0500564 super.onTouchEvent(ev);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800565
Daniel Sandler388f6792010-03-02 14:08:08 -0500566 int x = (int)ev.getX();
567 int y = (int)ev.getY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800568
Romain Guyce115852010-03-04 12:15:37 -0800569 final boolean isPortrait = getWidth() < getHeight();
Daniel Sandler388f6792010-03-02 14:08:08 -0500570 int action = ev.getAction();
571 switch (action) {
572 case MotionEvent.ACTION_DOWN:
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700573 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
574 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500575 mTouchTracking = TRACKING_HOME;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700576 sRollo.setHomeSelected(SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500577 mCurrentIconIndex = -1;
578 } else {
579 mTouchTracking = TRACKING_FLING;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800580
Daniel Sandler388f6792010-03-02 14:08:08 -0500581 mMotionDownRawX = (int)ev.getRawX();
582 mMotionDownRawY = (int)ev.getRawY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800583
Joe Onorato2cc62e82010-03-17 20:23:53 -0700584 if (!sRollo.checkClickOK()) {
585 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500586 } else {
587 mDownIconIndex = mCurrentIconIndex
Joe Onorato2cc62e82010-03-17 20:23:53 -0700588 = sRollo.selectIcon(x, y, SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500589 if (mDownIconIndex < 0) {
590 // if nothing was selected, no long press.
591 cancelLongPress();
592 }
593 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700594 sRollo.move(ev.getRawY() / getHeight());
Daniel Sandler388f6792010-03-02 14:08:08 -0500595 mVelocityTracker = VelocityTracker.obtain();
596 mVelocityTracker.addMovement(ev);
597 mStartedScrolling = false;
598 }
599 break;
600 case MotionEvent.ACTION_MOVE:
601 case MotionEvent.ACTION_OUTSIDE:
602 if (mTouchTracking == TRACKING_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700603 sRollo.setHomeSelected((isPortrait &&
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700604 y > mTouchYBorders[mTouchYBorders.length-1]) || (!isPortrait
605 && x > mTouchXBorders[mTouchXBorders.length-1])
Daniel Sandler388f6792010-03-02 14:08:08 -0500606 ? SELECTED_PRESSED : SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500607 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500608 int rawY = (int)ev.getRawY();
609 int slop;
610 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800611
Daniel Sandler388f6792010-03-02 14:08:08 -0500612 if (!mStartedScrolling && slop < mSlop) {
613 // don't update anything so when we do start scrolling
614 // below, we get the right delta.
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700615 mCurrentIconIndex = chooseTappedIcon(x, y);
Daniel Sandler388f6792010-03-02 14:08:08 -0500616 if (mDownIconIndex != mCurrentIconIndex) {
617 // If a different icon is selected, don't allow it to be picked up.
618 // This handles off-axis dragging.
619 cancelLongPress();
620 mCurrentIconIndex = -1;
621 }
622 } else {
623 if (!mStartedScrolling) {
624 cancelLongPress();
625 mCurrentIconIndex = -1;
626 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700627 sRollo.move(ev.getRawY() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800628
Daniel Sandler388f6792010-03-02 14:08:08 -0500629 mStartedScrolling = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700630 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500631 mVelocityTracker.addMovement(ev);
Daniel Sandler388f6792010-03-02 14:08:08 -0500632 }
633 }
634 break;
635 case MotionEvent.ACTION_UP:
636 case MotionEvent.ACTION_CANCEL:
637 if (mTouchTracking == TRACKING_HOME) {
638 if (action == MotionEvent.ACTION_UP) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700639 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
640 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500641 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
Winson Chung097eb0a2011-03-18 16:56:08 -0700642 mLauncher.showWorkspace(true);
Daniel Sandler388f6792010-03-02 14:08:08 -0500643 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700644 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500645 }
646 mCurrentIconIndex = -1;
647 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500648 mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700649 sRollo.clearSelectedIcon();
Jason Sams60a55bb2010-06-18 15:11:19 -0700650 sRollo.fling(ev.getRawY() / getHeight(),
651 mVelocityTracker.getYVelocity() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800652
Daniel Sandler388f6792010-03-02 14:08:08 -0500653 if (mVelocityTracker != null) {
654 mVelocityTracker.recycle();
655 mVelocityTracker = null;
656 }
657 }
658 mTouchTracking = TRACKING_NONE;
659 break;
660 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800661
Daniel Sandler388f6792010-03-02 14:08:08 -0500662 return true;
663 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800664
Daniel Sandler388f6792010-03-02 14:08:08 -0500665 public void onClick(View v) {
666 if (mLocks != 0 || !isVisible()) {
667 return;
668 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700669 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500670 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
671 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
672 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onoratof984e852010-03-25 09:47:45 -0700673 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500674 }
675 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800676
Daniel Sandler388f6792010-03-02 14:08:08 -0500677 public boolean onLongClick(View v) {
Joe Onorato6b4adbc2010-09-01 12:13:25 -0700678 // We don't accept long click events in these cases
679 // - If the workspace isn't ready to accept a drop
680 // - If we're not done loading (because we might be confused about which item
681 // to pick up
682 // - If we're not visible
683 if (!isVisible() || mLauncher.isWorkspaceLocked() || mLocks != 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500684 return true;
685 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700686 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500687 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
688 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800689
Patrick Dubroy5f445422011-02-18 14:35:21 -0800690 final Bitmap bmp = app.iconBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800691
Daniel Sandler388f6792010-03-02 14:08:08 -0500692 // We don't really have an accurate location to use. This will do.
Patrick Dubroy5f445422011-02-18 14:35:21 -0800693 int screenX = mMotionDownRawX - (bmp.getWidth() / 2);
694 int screenY = mMotionDownRawY - bmp.getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800695
Winson Chung097eb0a2011-03-18 16:56:08 -0700696 mLauncher.lockScreenOrientation();
697 mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, bmp);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800698 mDragController.startDrag(
699 bmp, screenX, screenY, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800700
Winson Chung097eb0a2011-03-18 16:56:08 -0700701 mLauncher.showWorkspace(true);
Daniel Sandler388f6792010-03-02 14:08:08 -0500702 }
703 return true;
704 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800705
Daniel Sandler388f6792010-03-02 14:08:08 -0500706 @Override
707 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
708 if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
709 if (!isVisible()) {
710 return false;
711 }
712 String text = null;
713 int index;
714 int count = mAllAppsList.size() + 1; // +1 is home
715 int pos = -1;
716 switch (mLastSelection) {
717 case SELECTION_ICONS:
Jason Sams14f67ed2010-05-11 14:02:43 -0700718 index = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500719 if (index >= 0) {
720 ApplicationInfo info = mAllAppsList.get(index);
721 if (info.title != null) {
722 text = info.title.toString();
723 pos = index;
724 }
725 }
726 break;
727 case SELECTION_HOME:
728 text = getContext().getString(R.string.all_apps_home_button_label);
729 pos = count;
730 break;
731 }
732 if (text != null) {
733 event.setEnabled(true);
734 event.getText().add(text);
735 //event.setContentDescription(text);
736 event.setItemCount(count);
737 event.setCurrentItemIndex(pos);
738 }
739 }
740 return false;
741 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800742
Patrick Dubroya669d792010-11-23 14:40:33 -0800743 @Override
Patrick Dubroya669d792010-11-23 14:40:33 -0800744 public void onDragViewVisible() {
745 }
746
747 @Override
Patrick Dubroy5f445422011-02-18 14:35:21 -0800748 public void onDropCompleted(View target, Object dragInfo, boolean success) {
Winson Chung097eb0a2011-03-18 16:56:08 -0700749 mLauncher.getWorkspace().onDragStopped(success);
750 mLauncher.unlockScreenOrientation();
Daniel Sandler388f6792010-03-02 14:08:08 -0500751 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800752
Daniel Sandler388f6792010-03-02 14:08:08 -0500753 /**
754 * Zoom to the specifed level.
755 *
756 * @param zoom [0..1] 0 is hidden, 1 is open
757 */
758 public void zoom(float zoom, boolean animate) {
759 cancelLongPress();
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700760 sNextZoom = zoom;
761 sAnimateNextZoom = animate;
Daniel Sandler388f6792010-03-02 14:08:08 -0500762 // if we do setZoom while we don't have a surface, we won't
763 // get the callbacks that actually set mZoom.
Joe Onorato2cc62e82010-03-17 20:23:53 -0700764 if (sRollo == null || !mHaveSurface) {
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700765 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500766 mZoom = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500767 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700768 sRollo.setZoom(zoom, animate);
Daniel Sandler388f6792010-03-02 14:08:08 -0500769 }
770 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800771
Joe Onorato878f0862010-03-22 12:22:22 -0400772 /**
773 * If sRollo is null, then we're not visible. This is also used to guard against
774 * sRollo being null.
775 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500776 public boolean isVisible() {
Joe Onorato878f0862010-03-22 12:22:22 -0400777 return sRollo != null && mZoom > 0.001f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500778 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800779
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700780 public boolean isAnimating() {
781 return isVisible() && mZoom <= 0.999f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500782 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800783
Daniel Sandler388f6792010-03-02 14:08:08 -0500784 public void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700785 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500786 // We've been removed from the window. Don't bother with all this.
787 return;
788 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800789
Daniel Sandler707b0f72010-04-15 16:41:31 -0400790 if (list != null) {
791 Collections.sort(list, LauncherModel.APP_NAME_COMPARATOR);
792 }
793
Romain Guy13c2e7b2010-03-10 19:45:00 -0800794 boolean reload = false;
795 if (mAllAppsList == null) {
796 reload = true;
797 } else if (list.size() != mAllAppsList.size()) {
798 reload = true;
799 } else {
800 final int count = list.size();
801 for (int i = 0; i < count; i++) {
802 if (list.get(i) != mAllAppsList.get(i)) {
803 reload = true;
804 break;
805 }
806 }
807 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800808
Daniel Sandler388f6792010-03-02 14:08:08 -0500809 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700810 if (sRollo != null && reload) {
811 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500812 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700813
Romain Guyc16fea72010-03-12 17:17:56 -0800814 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700815 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
Romain Guyc16fea72010-03-12 17:17:56 -0800816 mRestoreFocusIndex = -1;
817 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700818
Daniel Sandler388f6792010-03-02 14:08:08 -0500819 mLocks &= ~LOCK_ICONS_PENDING;
820 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800821
Daniel Sandler388f6792010-03-02 14:08:08 -0500822 public void addApps(ArrayList<ApplicationInfo> list) {
823 if (mAllAppsList == null) {
824 // Not done loading yet. We'll find out about it later.
825 return;
826 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700827 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500828 // We've been removed from the window. Don't bother with all this.
829 return;
830 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800831
Daniel Sandler388f6792010-03-02 14:08:08 -0500832 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700833 if (sRollo != null) {
834 sRollo.pause();
Jason Sams14f67ed2010-05-11 14:02:43 -0700835 sRollo.reallocAppsList(sRollo.mScript.get_gIconCount() + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500836 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800837
Daniel Sandler388f6792010-03-02 14:08:08 -0500838 for (int i=0; i<N; i++) {
839 final ApplicationInfo item = list.get(i);
840 int index = Collections.binarySearch(mAllAppsList, item,
841 LauncherModel.APP_NAME_COMPARATOR);
842 if (index < 0) {
843 index = -(index+1);
844 }
845 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700846 if (sRollo != null) {
847 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500848 }
849 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800850
Joe Onorato2cc62e82010-03-17 20:23:53 -0700851 if (sRollo != null) {
852 sRollo.saveAppsList();
853 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500854 }
855 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800856
Daniel Sandler388f6792010-03-02 14:08:08 -0500857 public void removeApps(ArrayList<ApplicationInfo> list) {
858 if (mAllAppsList == null) {
859 // Not done loading yet. We'll find out about it later.
860 return;
861 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800862
Joe Onorato2cc62e82010-03-17 20:23:53 -0700863 if (sRollo != null) {
864 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800865 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500866 final int N = list.size();
867 for (int i=0; i<N; i++) {
868 final ApplicationInfo item = list.get(i);
869 int index = findAppByComponent(mAllAppsList, item);
870 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500871 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700872 if (sRollo != null) {
873 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500874 }
875 } else {
876 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
877 // Try to recover. This should keep us from crashing for now.
878 }
879 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800880
Joe Onorato2cc62e82010-03-17 20:23:53 -0700881 if (sRollo != null) {
882 sRollo.saveAppsList();
883 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500884 }
885 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800886
Joe Onorato64e6be72010-03-05 15:05:52 -0500887 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500888 // Just remove and add, because they may need to be re-sorted.
889 removeApps(list);
890 addApps(list);
891 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800892
Daniel Sandler388f6792010-03-02 14:08:08 -0500893 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
894 ComponentName component = item.intent.getComponent();
895 final int N = list.size();
896 for (int i=0; i<N; i++) {
897 ApplicationInfo x = list.get(i);
898 if (x.intent.getComponent().equals(component)) {
899 return i;
900 }
901 }
902 return -1;
903 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800904
Jason Sams4dfea092010-12-06 17:38:58 -0800905 class AAMessage extends RenderScript.RSMessageHandler {
Daniel Sandler388f6792010-03-02 14:08:08 -0500906 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700907 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500908 mVelocity = ((float)mData[1]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700909
910 boolean lastVisible = isVisible();
Daniel Sandler388f6792010-03-02 14:08:08 -0500911 mZoom = ((float)mData[2]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700912
913 final boolean visible = isVisible();
914 if (visible != lastVisible) {
915 post(new Runnable() {
916 public void run() {
917 if (visible) {
918 showSurface();
919 } else {
920 hideSurface();
921 }
922 }
923 });
924 }
925
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700926 sZoomDirty = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500927 }
928 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800929
Romain Guy13c2e7b2010-03-10 19:45:00 -0800930 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500931 // Allocations ======
932 private int mWidth;
933 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800934
Daniel Sandler388f6792010-03-02 14:08:08 -0500935 private Resources mRes;
Stephen Hinesb2d69862010-09-16 17:21:50 -0700936 ScriptC_allapps mScript;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800937
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700938 private Mesh mMesh;
Alex Sakhartchoukc3842422010-12-21 14:43:30 -0800939 private ProgramVertexFixedFunction.Constants mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800940
Jason Sams14f67ed2010-05-11 14:02:43 -0700941 private ScriptField_VpConsts mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800942
Daniel Sandler388f6792010-03-02 14:08:08 -0500943 private Allocation mHomeButtonNormal;
944 private Allocation mHomeButtonFocused;
945 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800946
Daniel Sandler388f6792010-03-02 14:08:08 -0500947 private Allocation[] mIcons;
Jason Sams4dfea092010-12-06 17:38:58 -0800948 private Allocation mAllocIcons;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800949
Daniel Sandler388f6792010-03-02 14:08:08 -0500950 private Allocation[] mLabels;
Jason Sams4dfea092010-12-06 17:38:58 -0800951 private Allocation mAllocLabels;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800952
Daniel Sandler388f6792010-03-02 14:08:08 -0500953 private Bitmap mSelectionBitmap;
954 private Canvas mSelectionCanvas;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800955
Jason Sams14f67ed2010-05-11 14:02:43 -0700956 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800957
Romain Guy13c2e7b2010-03-10 19:45:00 -0800958 AllApps3D mAllApps;
959 boolean mInitialize;
960
Daniel Sandler388f6792010-03-02 14:08:08 -0500961 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -0800962 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -0800963 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -0500964 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800965
966 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400967 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -0800968 sRS.bindRootScript(null);
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400969 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800970 }
971
972 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400973 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -0800974 sRS.bindRootScript(mScript);
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400975 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800976 }
977
Romain Guy13c2e7b2010-03-10 19:45:00 -0800978 public RolloRS(AllApps3D allApps) {
979 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -0500980 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800981
Daniel Sandler388f6792010-03-02 14:08:08 -0500982 public void init(Resources res, int width, int height) {
983 mRes = res;
984 mWidth = width;
985 mHeight = height;
Jason Sams4dfea092010-12-06 17:38:58 -0800986 mScript = new ScriptC_allapps(sRS, mRes, R.raw.allapps);
Jason Sams14f67ed2010-05-11 14:02:43 -0700987
Daniel Sandler388f6792010-03-02 14:08:08 -0500988 initProgramVertex();
989 initProgramFragment();
990 initProgramStore();
991 initGl();
992 initData();
Jason Sams14f67ed2010-05-11 14:02:43 -0700993
Jason Sams4dfea092010-12-06 17:38:58 -0800994 mScript.bind_gIcons(mAllocIcons);
995 mScript.bind_gLabels(mAllocLabels);
996 sRS.bindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -0500997 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800998
Daniel Sandler388f6792010-03-02 14:08:08 -0500999 public void initMesh() {
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001000 Mesh.TriangleMeshBuilder tm = new Mesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001001
Daniel Sandler388f6792010-03-02 14:08:08 -05001002 for (int ct=0; ct < 16; ct++) {
1003 float pos = (1.f / (16.f - 1)) * ct;
1004 tm.addVertex(0.0f, pos);
1005 tm.addVertex(1.0f, pos);
1006 }
1007 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1008 tm.addTriangle(ct, ct+1, ct+2);
1009 tm.addTriangle(ct+1, ct+3, ct+2);
1010 }
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001011 mMesh = tm.create(true);
Jason Sams14f67ed2010-05-11 14:02:43 -07001012 mScript.set_gSMCell(mMesh);
Daniel Sandler388f6792010-03-02 14:08:08 -05001013 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001014
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001015 Matrix4f getProjectionMatrix(int w, int h) {
1016 // range -1,1 in the narrow axis at z = 0.
1017 Matrix4f m1 = new Matrix4f();
1018 Matrix4f m2 = new Matrix4f();
1019
1020 if(w > h) {
1021 float aspect = ((float)w) / h;
1022 m1.loadFrustum(-aspect,aspect, -1,1, 1,100);
1023 } else {
1024 float aspect = ((float)h) / w;
1025 m1.loadFrustum(-1,1, -aspect,aspect, 1,100);
1026 }
1027
1028 m2.loadRotate(180, 0, 1, 0);
1029 m1.loadMultiply(m1, m2);
1030
1031 m2.loadScale(-2, 2, 1);
1032 m1.loadMultiply(m1, m2);
1033
1034 m2.loadTranslate(0, 0, 2);
1035 m1.loadMultiply(m1, m2);
1036 return m1;
1037 }
1038
Daniel Sandler388f6792010-03-02 14:08:08 -05001039 void resize(int w, int h) {
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001040 Matrix4f proj = getProjectionMatrix(w, h);
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001041 mPVA.setProjection(proj);
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001042
1043 if (mUniformAlloc != null) {
1044 ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
1045 i.Proj = proj;
1046 i.ScaleOffset.x = (2.f / 480.f);
1047 i.ScaleOffset.y = 0;
1048 i.ScaleOffset.z = -((float)w / 2) - 0.25f;
1049 i.ScaleOffset.w = -380.25f;
1050 i.BendPos.x = 120.f;
1051 i.BendPos.y = 680.f;
1052 if (w > h) {
1053 i.ScaleOffset.z = 40.f;
1054 i.ScaleOffset.w = h - 40.f;
1055 i.BendPos.y = 1.f;
1056 }
1057 mUniformAlloc.set(i, 0, true);
1058 }
1059
Daniel Sandler388f6792010-03-02 14:08:08 -05001060 mWidth = w;
1061 mHeight = h;
1062 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001063
Daniel Sandler388f6792010-03-02 14:08:08 -05001064 private void initProgramVertex() {
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001065 mPVA = new ProgramVertexFixedFunction.Constants(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001066 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001067
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001068 ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001069 pvb.setTextureMatrixEnable(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001070 ProgramVertex pv = pvb.create();
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001071 ((ProgramVertexFixedFunction)pv).bindConstants(mPVA);
Jason Sams4dfea092010-12-06 17:38:58 -08001072 sRS.bindProgramVertex(pv);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001073
Jason Sams14f67ed2010-05-11 14:02:43 -07001074 mUniformAlloc = new ScriptField_VpConsts(sRS, 1);
1075 mScript.bind_vpConstants(mUniformAlloc);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001076
Daniel Sandler388f6792010-03-02 14:08:08 -05001077 initMesh();
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001078 ProgramVertex.Builder sb = new ProgramVertex.Builder(sRS);
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001079 String t = "varying vec4 varColor;\n" +
Alex Sakhartchouk2f3b0b62010-10-06 09:32:12 -07001080 "varying vec2 varTex0;\n" +
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001081 "void main() {\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001082 // Animation
1083 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001084
Romain Guy060b5c82010-03-04 10:07:38 -08001085 " float bendY1 = UNI_BendPos.x;\n" +
1086 " float bendY2 = UNI_BendPos.y;\n" +
1087 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1088 " float bendDistance = bendY1 * 0.4;\n" +
1089 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001090
Romain Guy060b5c82010-03-04 10:07:38 -08001091 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1092 " float aDy = cos(bendAngle);\n" +
1093 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001094
Romain Guy060b5c82010-03-04 10:07:38 -08001095 " float scale = (2.0 / 480.0);\n" +
1096 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1097 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1098 " float y = 0.0;\n" +
1099 " float z = 0.0;\n" +
1100 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001101
Romain Guy060b5c82010-03-04 10:07:38 -08001102 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1103 " y += cv * aDy;\n" +
1104 " z += -cv * aDz;\n" +
1105 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1106 " lum += cv / bendDistance * distanceDimLevel;\n" +
1107 " y += cv * cos(cv * bendStep);\n" +
1108 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001109
Romain Guy060b5c82010-03-04 10:07:38 -08001110 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1111 " y += cv * aDy;\n" +
1112 " z += cv * aDz;\n" +
1113 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1114 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1115 " y += cv * cos(cv * bendStep);\n" +
1116 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001117
Romain Guy060b5c82010-03-04 10:07:38 -08001118 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001119
Romain Guy060b5c82010-03-04 10:07:38 -08001120 " vec4 pos;\n" +
1121 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1122 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1123 " pos.z = z * UNI_ScaleOffset.x;\n" +
1124 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001125
Romain Guy060b5c82010-03-04 10:07:38 -08001126 " pos.x *= 1.0 + ani * 4.0;\n" +
1127 " pos.y *= 1.0 + ani * 4.0;\n" +
1128 " pos.z -= ani * 1.5;\n" +
1129 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001130
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001131 " gl_Position = UNI_Proj * pos;\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001132 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1133 " varTex0.xy = ATTRIB_position;\n" +
1134 " varTex0.y = 1.0 - varTex0.y;\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001135 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001136 sb.setShader(t);
1137 sb.addConstant(mUniformAlloc.getType());
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001138 sb.addInput(mMesh.getVertexAllocation(0).getType().getElement());
Jason Sams60a55bb2010-06-18 15:11:19 -07001139 ProgramVertex pvc = sb.create();
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001140 pvc.bindConstants(mUniformAlloc.getAllocation(), 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001141
Jason Sams60a55bb2010-06-18 15:11:19 -07001142 mScript.set_gPVCurve(pvc);
Daniel Sandler388f6792010-03-02 14:08:08 -05001143 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001144
Daniel Sandler388f6792010-03-02 14:08:08 -05001145 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001146 Sampler.Builder sb = new Sampler.Builder(sRS);
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001147 sb.setMinification(Sampler.Value.LINEAR_MIP_LINEAR);
1148 sb.setMagnification(Sampler.Value.NEAREST);
Daniel Sandler388f6792010-03-02 14:08:08 -05001149 sb.setWrapS(Sampler.Value.CLAMP);
1150 sb.setWrapT(Sampler.Value.CLAMP);
1151 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001152
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001153 sb.setMinification(Sampler.Value.NEAREST);
1154 sb.setMagnification(Sampler.Value.NEAREST);
Daniel Sandler388f6792010-03-02 14:08:08 -05001155 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001156
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001157 ProgramFragmentFixedFunction.Builder bf = new ProgramFragmentFixedFunction.Builder(sRS);
1158 bf.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
1159 ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001160 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001161 ProgramFragment pfTexMip = bf.create();
1162 pfTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001163
Jason Sams070ada82010-08-04 17:53:07 -07001164 bf.setVaryingColor(false);
Jason Sams60a55bb2010-06-18 15:11:19 -07001165 ProgramFragment pfTexNearest = bf.create();
1166 pfTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001167
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001168 bf.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
1169 ProgramFragmentFixedFunction.Builder.Format.ALPHA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001170 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001171 ProgramFragment pfTexMipAlpha = bf.create();
1172 pfTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001173
Jason Sams60a55bb2010-06-18 15:11:19 -07001174 mScript.set_gPFTexNearest(pfTexNearest);
1175 mScript.set_gPFTexMip(pfTexMip);
1176 mScript.set_gPFTexMipAlpha(pfTexMipAlpha);
Daniel Sandler388f6792010-03-02 14:08:08 -05001177 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001178
Daniel Sandler388f6792010-03-02 14:08:08 -05001179 private void initProgramStore() {
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001180 ProgramStore.Builder bs = new ProgramStore.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001181 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001182 bs.setColorMaskEnabled(true,true,true,false);
1183 bs.setDitherEnabled(true);
Daniel Sandler388f6792010-03-02 14:08:08 -05001184 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1185 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Jason Sams14f67ed2010-05-11 14:02:43 -07001186 mScript.set_gPS(bs.create());
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 initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001190 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001191
Daniel Sandler388f6792010-03-02 14:08:08 -05001192 private void initData() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001193 mScript.set_COLUMNS_PER_PAGE_PORTRAIT(Defines.COLUMNS_PER_PAGE_PORTRAIT);
1194 mScript.set_ROWS_PER_PAGE_PORTRAIT(Defines.ROWS_PER_PAGE_PORTRAIT);
1195 mScript.set_COLUMNS_PER_PAGE_LANDSCAPE(Defines.COLUMNS_PER_PAGE_LANDSCAPE);
1196 mScript.set_ROWS_PER_PAGE_LANDSCAPE(Defines.ROWS_PER_PAGE_LANDSCAPE);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001197
Joe Onorato2cc62e82010-03-17 20:23:53 -07001198 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
Jason Sams735a8242010-12-14 19:24:21 -08001199 R.drawable.home_button_normal);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001200 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
Jason Sams735a8242010-12-14 19:24:21 -08001201 R.drawable.home_button_focused);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001202 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
Jason Sams735a8242010-12-14 19:24:21 -08001203 R.drawable.home_button_pressed);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001204
Jason Sams14f67ed2010-05-11 14:02:43 -07001205 mScript.set_gHomeButton(mHomeButtonNormal);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001206
Daniel Sandler388f6792010-03-02 14:08:08 -05001207 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1208 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1209 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001210
Daniel Sandler388f6792010-03-02 14:08:08 -05001211 setApps(null);
1212 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001213
Daniel Sandler388f6792010-03-02 14:08:08 -05001214 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001215 if (sZoomDirty) {
1216 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001217 }
1218 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001219
Romain Guy060b5c82010-03-04 10:07:38 -08001220 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001221 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001222 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001223 final int count = list != null ? list.size() : 0;
1224 int allocCount = count;
1225 if (allocCount < 1) {
1226 allocCount = 1;
1227 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001228
Daniel Sandler388f6792010-03-02 14:08:08 -05001229 mIcons = new Allocation[count];
Jason Sams4dfea092010-12-06 17:38:58 -08001230 mAllocIcons = Allocation.createSized(sRS, Element.ALLOCATION(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001231
Daniel Sandler388f6792010-03-02 14:08:08 -05001232 mLabels = new Allocation[count];
Jason Sams4dfea092010-12-06 17:38:58 -08001233 mAllocLabels = Allocation.createSized(sRS, Element.ALLOCATION(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001234
Jason Sams14f67ed2010-05-11 14:02:43 -07001235 mScript.set_gIconCount(count);
1236 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001237 createAppIconAllocations(i, list.get(i));
1238 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001239 saveAppsList();
Jason Sams14f67ed2010-05-11 14:02:43 -07001240 android.util.Log.e("rs", "setApps");
Joe Onorato2cc62e82010-03-17 20:23:53 -07001241 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001242 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001243
Daniel Sandler388f6792010-03-02 14:08:08 -05001244 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001245 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001246 sRollo.clearSelectedIcon();
1247 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001248 }
Jason Sams60a55bb2010-06-18 15:11:19 -07001249 sRollo.mScript.invoke_setZoom(zoom, animate ? 1 : 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001250 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001251
Daniel Sandler388f6792010-03-02 14:08:08 -05001252 private void createAppIconAllocations(int index, ApplicationInfo item) {
Jason Sams95d2d2d2010-12-16 12:19:04 -08001253 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1254 Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
1255 Allocation.USAGE_GRAPHICS_TEXTURE);
1256 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1257 Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
1258 Allocation.USAGE_GRAPHICS_TEXTURE);
Daniel Sandler388f6792010-03-02 14:08:08 -05001259 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001260
Daniel Sandler388f6792010-03-02 14:08:08 -05001261 /**
1262 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1263 * fill in the values and call saveAppsList().
1264 */
1265 private void reallocAppsList(int count) {
1266 Allocation[] icons = new Allocation[count];
Jason Sams4dfea092010-12-06 17:38:58 -08001267 mAllocIcons = Allocation.createSized(sRS, Element.ALLOCATION(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001268
Daniel Sandler388f6792010-03-02 14:08:08 -05001269 Allocation[] labels = new Allocation[count];
Jason Sams4dfea092010-12-06 17:38:58 -08001270 mAllocLabels = Allocation.createSized(sRS, Element.ALLOCATION(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001271
Jason Sams14f67ed2010-05-11 14:02:43 -07001272 final int oldCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001273
Daniel Sandler388f6792010-03-02 14:08:08 -05001274 System.arraycopy(mIcons, 0, icons, 0, oldCount);
Daniel Sandler388f6792010-03-02 14:08:08 -05001275 System.arraycopy(mLabels, 0, labels, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001276
Daniel Sandler388f6792010-03-02 14:08:08 -05001277 mIcons = icons;
Daniel Sandler388f6792010-03-02 14:08:08 -05001278 mLabels = labels;
Daniel Sandler388f6792010-03-02 14:08:08 -05001279 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001280
Daniel Sandler388f6792010-03-02 14:08:08 -05001281 /**
1282 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1283 */
1284 private void addApp(int index, ApplicationInfo item) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001285 final int count = mScript.get_gIconCount() - index;
Daniel Sandler388f6792010-03-02 14:08:08 -05001286 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001287
Daniel Sandler388f6792010-03-02 14:08:08 -05001288 System.arraycopy(mIcons, index, mIcons, dest, count);
Daniel Sandler388f6792010-03-02 14:08:08 -05001289 System.arraycopy(mLabels, index, mLabels, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001290
Daniel Sandler388f6792010-03-02 14:08:08 -05001291 createAppIconAllocations(index, item);
Jason Sams14f67ed2010-05-11 14:02:43 -07001292
1293 mScript.set_gIconCount(mScript.get_gIconCount() + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001294 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001295
Daniel Sandler388f6792010-03-02 14:08:08 -05001296 /**
1297 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1298 */
1299 private void removeApp(int index) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001300 final int count = mScript.get_gIconCount() - index - 1;
Daniel Sandler388f6792010-03-02 14:08:08 -05001301 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001302
Daniel Sandler388f6792010-03-02 14:08:08 -05001303 System.arraycopy(mIcons, src, mIcons, index, count);
Daniel Sandler388f6792010-03-02 14:08:08 -05001304 System.arraycopy(mLabels, src, mLabels, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001305
Jason Sams14f67ed2010-05-11 14:02:43 -07001306 mScript.set_gIconCount(mScript.get_gIconCount() - 1);
1307 final int last = mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001308
Daniel Sandler388f6792010-03-02 14:08:08 -05001309 mIcons[last] = null;
Daniel Sandler388f6792010-03-02 14:08:08 -05001310 mLabels[last] = null;
Daniel Sandler388f6792010-03-02 14:08:08 -05001311 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001312
Daniel Sandler388f6792010-03-02 14:08:08 -05001313 /**
1314 * Send the apps list structures to RS.
1315 */
1316 private void saveAppsList() {
1317 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
Jason Sams4dfea092010-12-06 17:38:58 -08001318 if (mScript != null && mAllocIcons != null) {
1319 if (mIcons.length > 0) {
1320 mAllocIcons.copyFrom(mIcons);
1321 mAllocLabels.copyFrom(mLabels);
1322 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001323
Jason Sams4dfea092010-12-06 17:38:58 -08001324 mScript.bind_gIcons(mAllocIcons);
1325 mScript.bind_gLabels(mAllocLabels);
Daniel Sandler388f6792010-03-02 14:08:08 -05001326 }
1327 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001328
Jason Sams60a55bb2010-06-18 15:11:19 -07001329 void fling(float pos, float v) {
1330 mScript.invoke_fling(pos, v);
Daniel Sandler388f6792010-03-02 14:08:08 -05001331 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001332
Jason Sams60a55bb2010-06-18 15:11:19 -07001333 void move(float pos) {
1334 mScript.invoke_move(pos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001335 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001336
Daniel Sandler388f6792010-03-02 14:08:08 -05001337 void moveTo(float row) {
Jason Sams60a55bb2010-06-18 15:11:19 -07001338 mScript.invoke_moveTo(row);
Daniel Sandler388f6792010-03-02 14:08:08 -05001339 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001340
Daniel Sandler388f6792010-03-02 14:08:08 -05001341 /**
1342 * You need to call save() on mState on your own after calling this.
1343 *
1344 * @return the index of the icon that was selected.
1345 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001346 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001347 if (mAllApps != null) {
1348 final int index = mAllApps.chooseTappedIcon(x, y);
1349 selectIcon(index, pressed);
1350 return index;
1351 } else {
1352 return -1;
1353 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001354 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001355
Daniel Sandler388f6792010-03-02 14:08:08 -05001356 /**
1357 * Select the icon at the given index.
1358 *
1359 * @param index The index.
1360 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1361 */
1362 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001363 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1364 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001365 if (mAllApps != null) {
1366 mAllApps.mRestoreFocusIndex = index;
1367 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001368 mScript.set_gSelectedIconIndex(-1);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001369 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1370 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001371 }
1372 } else {
1373 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001374 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001375 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001376
Jason Sams14f67ed2010-05-11 14:02:43 -07001377 int prev = mScript.get_gSelectedIconIndex();
1378 mScript.set_gSelectedIconIndex(index);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001379
Romain Guy13c2e7b2010-03-10 19:45:00 -08001380 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001381 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001382
Daniel Sandler388f6792010-03-02 14:08:08 -05001383 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1384 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1385 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001386
Jason Sams735a8242010-12-14 19:24:21 -08001387 Allocation si = Allocation.createFromBitmap(sRS, selectionBitmap);
Jason Sams60a55bb2010-06-18 15:11:19 -07001388 mScript.set_gSelectedIconTexture(si);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001389
Daniel Sandler388f6792010-03-02 14:08:08 -05001390 if (prev != index) {
1391 if (info.title != null && info.title.length() > 0) {
1392 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001393 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001394 }
1395 }
1396 }
1397 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001398
Daniel Sandler388f6792010-03-02 14:08:08 -05001399 /**
1400 * You need to call save() on mState on your own after calling this.
1401 */
1402 void clearSelectedIcon() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001403 mScript.set_gSelectedIconIndex(-1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001404 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001405
Daniel Sandler388f6792010-03-02 14:08:08 -05001406 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001407 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001408 switch (mode) {
1409 case SELECTED_NONE:
Jason Sams14f67ed2010-05-11 14:02:43 -07001410 mScript.set_gHomeButton(mHomeButtonNormal);
Daniel Sandler388f6792010-03-02 14:08:08 -05001411 break;
1412 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001413 mAllApps.mLastSelection = SELECTION_HOME;
Jason Sams14f67ed2010-05-11 14:02:43 -07001414 mScript.set_gHomeButton(mHomeButtonFocused);
Daniel Sandler388f6792010-03-02 14:08:08 -05001415 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001416 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001417 }
1418 break;
1419 case SELECTED_PRESSED:
Jason Sams14f67ed2010-05-11 14:02:43 -07001420 mScript.set_gHomeButton(mHomeButtonPressed);
Daniel Sandler388f6792010-03-02 14:08:08 -05001421 break;
1422 }
1423 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001424
Daniel Sandler388f6792010-03-02 14:08:08 -05001425 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001426 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1427 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1428 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001429 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001430 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001431 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001432 //Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1433 //Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1434 //Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1435 //Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1436 //Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1437 //Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1438 //Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1439 //Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1440 //Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001441 }
1442 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001443
Daniel Sandler388f6792010-03-02 14:08:08 -05001444 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001445 Log.d(TAG, "sRS=" + sRS);
1446 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001447 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001448 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1449 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001450 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1451 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1452 Log.d(TAG, "mLastSelection=" + mLastSelection);
1453 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1454 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1455 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1456 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001457 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1458 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001459 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001460 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001461 Log.d(TAG, "mVelocity=" + mVelocity);
1462 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001463 if (sRollo != null) {
1464 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001465 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001466 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -08001467 sRS.contextDump();
Daniel Sandler388f6792010-03-02 14:08:08 -05001468 }
1469 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001470
1471 public void reset() {
1472 // Do nothing
1473 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001474}