blob: 29f49afc262bdd118c083eccdfbf9aa6925a325d [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
Daniel Sandler388f6792010-03-02 14:08:08 -0500211 public void setLauncher(Launcher launcher) {
212 mLauncher = launcher;
213 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800214
Daniel Sandler388f6792010-03-02 14:08:08 -0500215 @Override
216 public void surfaceDestroyed(SurfaceHolder holder) {
217 super.surfaceDestroyed(holder);
218 // Without this, we leak mMessageCallback which leaks the context.
Romain Guy13c2e7b2010-03-10 19:45:00 -0800219 if (!mSurrendered) {
Jason Sams4dfea092010-12-06 17:38:58 -0800220 sRS.setMessageHandler(null);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800221 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500222 // We may lose any callbacks that are pending, so make sure that we re-sync that
223 // on the next surfaceChanged.
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700224 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500225 mHaveSurface = false;
226 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800227
Daniel Sandler388f6792010-03-02 14:08:08 -0500228 @Override
229 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
230 //long startTime = SystemClock.uptimeMillis();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800231
Daniel Sandler388f6792010-03-02 14:08:08 -0500232 super.surfaceChanged(holder, format, w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800233
Romain Guy13c2e7b2010-03-10 19:45:00 -0800234 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800235
Daniel Sandler388f6792010-03-02 14:08:08 -0500236 mHaveSurface = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800237
Joe Onorato2cc62e82010-03-17 20:23:53 -0700238 if (sRollo == null) {
239 sRollo = new RolloRS(this);
240 sRollo.init(getResources(), w, h);
Daniel Sandler388f6792010-03-02 14:08:08 -0500241 if (mAllAppsList != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700242 sRollo.setApps(mAllAppsList);
Daniel Sandler388f6792010-03-02 14:08:08 -0500243 }
244 if (mShouldGainFocus) {
245 gainFocus();
246 mShouldGainFocus = false;
247 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700248 } else if (sRollo.mInitialize) {
249 sRollo.initGl();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700250 sRollo.mInitialize = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500251 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800252
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700253 initTouchState(w, h);
254
Joe Onorato2cc62e82010-03-17 20:23:53 -0700255 sRollo.dirtyCheck();
256 sRollo.resize(w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800257
Jason Sams14f67ed2010-05-11 14:02:43 -0700258 Log.d(TAG, "sc " + sRS);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700259 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -0800260 mMessageProc = new AAMessage();
261 sRS.setMessageHandler(mMessageProc);
Daniel Sandler388f6792010-03-02 14:08:08 -0500262 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800263
Daniel Sandler388f6792010-03-02 14:08:08 -0500264 //long endTime = SystemClock.uptimeMillis();
265 //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
266 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800267
Daniel Sandler388f6792010-03-02 14:08:08 -0500268 @Override
269 public void onWindowFocusChanged(boolean hasWindowFocus) {
270 super.onWindowFocusChanged(hasWindowFocus);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800271
272 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800273
Daniel Sandler388f6792010-03-02 14:08:08 -0500274 if (mArrowNavigation) {
275 if (!hasWindowFocus) {
276 // Clear selection when we lose window focus
Jason Sams14f67ed2010-05-11 14:02:43 -0700277 mLastSelectedIcon = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700278 sRollo.setHomeSelected(SELECTED_NONE);
279 sRollo.clearSelectedIcon();
Romain Guy060b5c82010-03-04 10:07:38 -0800280 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700281 if (sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500282 if (mLastSelection == SELECTION_ICONS) {
283 int selection = mLastSelectedIcon;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700284 final int firstIcon = Math.round(sRollo.mScrollPos) * mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500285 if (selection < 0 || // No selection
286 selection < firstIcon || // off the top of the screen
Jason Sams14f67ed2010-05-11 14:02:43 -0700287 selection >= sRollo.mScript.get_gIconCount() || // past last icon
Daniel Sandler388f6792010-03-02 14:08:08 -0500288 selection >= firstIcon + // past last icon on screen
Romain Guy060b5c82010-03-04 10:07:38 -0800289 (mColumnsPerPage * mRowsPerPage)) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500290 selection = firstIcon;
291 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800292
Daniel Sandler388f6792010-03-02 14:08:08 -0500293 // Select the first icon when we gain window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700294 sRollo.selectIcon(selection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500295 } else if (mLastSelection == SELECTION_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700296 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500297 }
298 }
299 }
300 }
301 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800302
Daniel Sandler388f6792010-03-02 14:08:08 -0500303 @Override
304 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
305 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800306
Romain Guy13c2e7b2010-03-10 19:45:00 -0800307 if (!isVisible() || mSurrendered) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500308 return;
309 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800310
Daniel Sandler388f6792010-03-02 14:08:08 -0500311 if (gainFocus) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700312 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500313 gainFocus();
314 } else {
315 mShouldGainFocus = true;
316 }
317 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700318 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500319 if (mArrowNavigation) {
320 // Clear selection when we lose focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700321 sRollo.clearSelectedIcon();
322 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500323 mArrowNavigation = false;
324 }
325 } else {
326 mShouldGainFocus = false;
327 }
328 }
329 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800330
Daniel Sandler388f6792010-03-02 14:08:08 -0500331 private void gainFocus() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700332 if (!mArrowNavigation && sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500333 // Select the first icon when we gain keyboard focus
334 mArrowNavigation = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700335 sRollo.selectIcon(Math.round(sRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500336 }
337 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800338
Daniel Sandler388f6792010-03-02 14:08:08 -0500339 @Override
340 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800341
Daniel Sandler388f6792010-03-02 14:08:08 -0500342 boolean handled = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800343
Daniel Sandler388f6792010-03-02 14:08:08 -0500344 if (!isVisible()) {
345 return false;
346 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700347 final int iconCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800348
Daniel Sandler388f6792010-03-02 14:08:08 -0500349 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
350 if (mArrowNavigation) {
351 if (mLastSelection == SELECTION_HOME) {
352 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
353 mLauncher.closeAllApps(true);
354 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700355 int whichApp = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500356 if (whichApp >= 0) {
357 ApplicationInfo app = mAllAppsList.get(whichApp);
Joe Onoratof984e852010-03-25 09:47:45 -0700358 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500359 handled = true;
360 }
361 }
362 }
363 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800364
Daniel Sandler388f6792010-03-02 14:08:08 -0500365 if (iconCount > 0) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800366 final boolean isPortrait = getWidth() < getHeight();
Jason Sams14f67ed2010-05-11 14:02:43 -0700367
Daniel Sandler388f6792010-03-02 14:08:08 -0500368 mArrowNavigation = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800369
Jason Sams14f67ed2010-05-11 14:02:43 -0700370 int currentSelection = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700371 int currentTopRow = Math.round(sRollo.mScrollPos);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800372
Romain Guy060b5c82010-03-04 10:07:38 -0800373 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1
374 final int currentPageCol = currentSelection % mColumnsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800375
Romain Guy060b5c82010-03-04 10:07:38 -0800376 // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1
Romain Guy6a42cf32010-03-12 16:03:52 -0800377 final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage))
Romain Guy060b5c82010-03-04 10:07:38 -0800378 / mRowsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800379
Daniel Sandler388f6792010-03-02 14:08:08 -0500380 int newSelection = currentSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800381
Daniel Sandler388f6792010-03-02 14:08:08 -0500382 switch (keyCode) {
383 case KeyEvent.KEYCODE_DPAD_UP:
384 if (mLastSelection == SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800385 if (isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700386 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guy6a42cf32010-03-12 16:03:52 -0800387 int lastRowCount = iconCount % mColumnsPerPage;
388 if (lastRowCount == 0) {
389 lastRowCount = mColumnsPerPage;
390 }
391 newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2);
392 if (newSelection >= iconCount) {
393 newSelection = iconCount-1;
394 }
395 int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
396 if (target < 0) {
397 target = 0;
398 }
399 if (currentTopRow != target) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700400 sRollo.moveTo(target);
Romain Guy6a42cf32010-03-12 16:03:52 -0800401 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500402 }
403 } else {
404 if (currentPageRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800405 newSelection = currentSelection - mColumnsPerPage;
Romain Guy6a42cf32010-03-12 16:03:52 -0800406 if (currentTopRow > newSelection / mColumnsPerPage) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700407 sRollo.moveTo(newSelection / mColumnsPerPage);
Romain Guy6a42cf32010-03-12 16:03:52 -0800408 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500409 } else if (currentTopRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800410 newSelection = currentSelection - mColumnsPerPage;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700411 sRollo.moveTo(newSelection / mColumnsPerPage);
Daniel Sandler388f6792010-03-02 14:08:08 -0500412 } else if (currentPageRow != 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800413 newSelection = currentTopRow * mRowsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500414 }
415 }
416 handled = true;
417 break;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800418
Daniel Sandler388f6792010-03-02 14:08:08 -0500419 case KeyEvent.KEYCODE_DPAD_DOWN: {
Romain Guy060b5c82010-03-04 10:07:38 -0800420 final int rowCount = iconCount / mColumnsPerPage
421 + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
422 final int currentRow = currentSelection / mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500423 if (mLastSelection != SELECTION_HOME) {
424 if (currentRow < rowCount-1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700425 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500426 if (currentSelection < 0) {
427 newSelection = 0;
428 } else {
Romain Guy060b5c82010-03-04 10:07:38 -0800429 newSelection = currentSelection + mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500430 }
431 if (newSelection >= iconCount) {
432 // Go from D to G in this arrangement:
433 // A B C D
434 // E F G
435 newSelection = iconCount - 1;
436 }
Romain Guy060b5c82010-03-04 10:07:38 -0800437 if (currentPageRow >= mRowsPerPage - 1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700438 sRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -0500439 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800440 } else if (isPortrait) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500441 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700442 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500443 }
444 }
445 handled = true;
446 break;
447 }
448 case KeyEvent.KEYCODE_DPAD_LEFT:
449 if (mLastSelection != SELECTION_HOME) {
450 if (currentPageCol > 0) {
451 newSelection = currentSelection - 1;
452 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800453 } else if (!isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700454 newSelection = ((int) (sRollo.mScrollPos) * mColumnsPerPage) +
Romain Guy6a42cf32010-03-12 16:03:52 -0800455 (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700456 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500457 }
458 handled = true;
459 break;
460 case KeyEvent.KEYCODE_DPAD_RIGHT:
461 if (mLastSelection != SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800462 if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 ||
463 currentSelection == iconCount - 1)) {
464 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700465 sRollo.setHomeSelected(SELECTED_FOCUSED);
Romain Guy6a42cf32010-03-12 16:03:52 -0800466 } else if ((currentPageCol < mColumnsPerPage - 1) &&
Daniel Sandler388f6792010-03-02 14:08:08 -0500467 (currentSelection < iconCount - 1)) {
468 newSelection = currentSelection + 1;
469 }
470 }
471 handled = true;
472 break;
473 }
474 if (newSelection != currentSelection) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700475 sRollo.selectIcon(newSelection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500476 }
477 }
478 return handled;
479 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800480
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700481 void initTouchState(int width, int height) {
482 boolean isPortrait = width < height;
483
484 int[] viewPos = new int[2];
485 getLocationOnScreen(viewPos);
486
487 mTouchXBorders = new int[mColumnsPerPage + 1];
488 mTouchYBorders = new int[mRowsPerPage + 1];
489
490 // TODO: Put this in a config file/define
491 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE_PORTRAIT;
492 if (!isPortrait) cellHeight -= 12;
493 int centerY = (int) (height * (isPortrait ? 0.5f : 0.47f));
494 if (!isPortrait) centerY += cellHeight / 2;
495 int half = (int) Math.floor((mRowsPerPage + 1) / 2);
496 int end = mTouchYBorders.length - (half + 1);
497
498 for (int i = -half; i <= end; i++) {
499 mTouchYBorders[i + half] = centerY + (i * cellHeight) - viewPos[1];
500 }
501
502 int x = 0;
503 // TODO: Put this in a config file/define
504 int columnWidth = 120;
505 for (int i = 0; i < mColumnsPerPage + 1; i++) {
506 mTouchXBorders[i] = x - viewPos[0];
507 x += columnWidth;
508 }
509 }
510
511 int chooseTappedIcon(int x, int y) {
512 float pos = sRollo != null ? sRollo.mScrollPos : 0;
513
514 int oldY = y;
515
516 // Adjust for scroll position if not zero.
517 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
518
519 int col = -1;
520 int row = -1;
521 final int columnsCount = mColumnsPerPage;
522 for (int i=0; i< columnsCount; i++) {
523 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
524 col = i;
525 break;
526 }
527 }
528 final int rowsCount = mRowsPerPage;
529 for (int i=0; i< rowsCount; i++) {
530 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
531 row = i;
532 break;
533 }
534 }
535
536 if (row < 0 || col < 0) {
537 return -1;
538 }
539
540 int index = (((int) pos) * columnsCount) + (row * columnsCount) + col;
541
542 if (index >= mAllAppsList.size()) {
543 return -1;
544 } else {
545 return index;
546 }
547 }
548
Daniel Sandler388f6792010-03-02 14:08:08 -0500549 @Override
550 public boolean onTouchEvent(MotionEvent ev)
551 {
552 mArrowNavigation = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800553
Daniel Sandler388f6792010-03-02 14:08:08 -0500554 if (!isVisible()) {
555 return true;
556 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800557
Daniel Sandler388f6792010-03-02 14:08:08 -0500558 if (mLocks != 0) {
559 return true;
560 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800561
Daniel Sandler388f6792010-03-02 14:08:08 -0500562 super.onTouchEvent(ev);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800563
Daniel Sandler388f6792010-03-02 14:08:08 -0500564 int x = (int)ev.getX();
565 int y = (int)ev.getY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800566
Romain Guyce115852010-03-04 12:15:37 -0800567 final boolean isPortrait = getWidth() < getHeight();
Daniel Sandler388f6792010-03-02 14:08:08 -0500568 int action = ev.getAction();
569 switch (action) {
570 case MotionEvent.ACTION_DOWN:
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700571 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
572 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500573 mTouchTracking = TRACKING_HOME;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700574 sRollo.setHomeSelected(SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500575 mCurrentIconIndex = -1;
576 } else {
577 mTouchTracking = TRACKING_FLING;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800578
Daniel Sandler388f6792010-03-02 14:08:08 -0500579 mMotionDownRawX = (int)ev.getRawX();
580 mMotionDownRawY = (int)ev.getRawY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800581
Joe Onorato2cc62e82010-03-17 20:23:53 -0700582 if (!sRollo.checkClickOK()) {
583 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500584 } else {
585 mDownIconIndex = mCurrentIconIndex
Joe Onorato2cc62e82010-03-17 20:23:53 -0700586 = sRollo.selectIcon(x, y, SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500587 if (mDownIconIndex < 0) {
588 // if nothing was selected, no long press.
589 cancelLongPress();
590 }
591 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700592 sRollo.move(ev.getRawY() / getHeight());
Daniel Sandler388f6792010-03-02 14:08:08 -0500593 mVelocityTracker = VelocityTracker.obtain();
594 mVelocityTracker.addMovement(ev);
595 mStartedScrolling = false;
596 }
597 break;
598 case MotionEvent.ACTION_MOVE:
599 case MotionEvent.ACTION_OUTSIDE:
600 if (mTouchTracking == TRACKING_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700601 sRollo.setHomeSelected((isPortrait &&
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700602 y > mTouchYBorders[mTouchYBorders.length-1]) || (!isPortrait
603 && x > mTouchXBorders[mTouchXBorders.length-1])
Daniel Sandler388f6792010-03-02 14:08:08 -0500604 ? SELECTED_PRESSED : SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500605 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500606 int rawY = (int)ev.getRawY();
607 int slop;
608 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800609
Daniel Sandler388f6792010-03-02 14:08:08 -0500610 if (!mStartedScrolling && slop < mSlop) {
611 // don't update anything so when we do start scrolling
612 // below, we get the right delta.
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700613 mCurrentIconIndex = chooseTappedIcon(x, y);
Daniel Sandler388f6792010-03-02 14:08:08 -0500614 if (mDownIconIndex != mCurrentIconIndex) {
615 // If a different icon is selected, don't allow it to be picked up.
616 // This handles off-axis dragging.
617 cancelLongPress();
618 mCurrentIconIndex = -1;
619 }
620 } else {
621 if (!mStartedScrolling) {
622 cancelLongPress();
623 mCurrentIconIndex = -1;
624 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700625 sRollo.move(ev.getRawY() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800626
Daniel Sandler388f6792010-03-02 14:08:08 -0500627 mStartedScrolling = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700628 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500629 mVelocityTracker.addMovement(ev);
Daniel Sandler388f6792010-03-02 14:08:08 -0500630 }
631 }
632 break;
633 case MotionEvent.ACTION_UP:
634 case MotionEvent.ACTION_CANCEL:
635 if (mTouchTracking == TRACKING_HOME) {
636 if (action == MotionEvent.ACTION_UP) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700637 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
638 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500639 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
640 mLauncher.closeAllApps(true);
641 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700642 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500643 }
644 mCurrentIconIndex = -1;
645 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500646 mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700647 sRollo.clearSelectedIcon();
Jason Sams60a55bb2010-06-18 15:11:19 -0700648 sRollo.fling(ev.getRawY() / getHeight(),
649 mVelocityTracker.getYVelocity() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800650
Daniel Sandler388f6792010-03-02 14:08:08 -0500651 if (mVelocityTracker != null) {
652 mVelocityTracker.recycle();
653 mVelocityTracker = null;
654 }
655 }
656 mTouchTracking = TRACKING_NONE;
657 break;
658 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800659
Daniel Sandler388f6792010-03-02 14:08:08 -0500660 return true;
661 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800662
Daniel Sandler388f6792010-03-02 14:08:08 -0500663 public void onClick(View v) {
664 if (mLocks != 0 || !isVisible()) {
665 return;
666 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700667 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500668 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
669 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
670 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onoratof984e852010-03-25 09:47:45 -0700671 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500672 }
673 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800674
Daniel Sandler388f6792010-03-02 14:08:08 -0500675 public boolean onLongClick(View v) {
Joe Onorato6b4adbc2010-09-01 12:13:25 -0700676 // We don't accept long click events in these cases
677 // - If the workspace isn't ready to accept a drop
678 // - If we're not done loading (because we might be confused about which item
679 // to pick up
680 // - If we're not visible
681 if (!isVisible() || mLauncher.isWorkspaceLocked() || mLocks != 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500682 return true;
683 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700684 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500685 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
686 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800687
Patrick Dubroy5f445422011-02-18 14:35:21 -0800688 final Bitmap bmp = app.iconBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800689
Daniel Sandler388f6792010-03-02 14:08:08 -0500690 // We don't really have an accurate location to use. This will do.
Patrick Dubroy5f445422011-02-18 14:35:21 -0800691 int screenX = mMotionDownRawX - (bmp.getWidth() / 2);
692 int screenY = mMotionDownRawY - bmp.getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800693
Patrick Dubroy5f445422011-02-18 14:35:21 -0800694 mDragController.startDrag(
695 bmp, screenX, screenY, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800696
Daniel Sandler388f6792010-03-02 14:08:08 -0500697 mLauncher.closeAllApps(true);
698 }
699 return true;
700 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800701
Daniel Sandler388f6792010-03-02 14:08:08 -0500702 @Override
703 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
704 if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
705 if (!isVisible()) {
706 return false;
707 }
708 String text = null;
709 int index;
710 int count = mAllAppsList.size() + 1; // +1 is home
711 int pos = -1;
712 switch (mLastSelection) {
713 case SELECTION_ICONS:
Jason Sams14f67ed2010-05-11 14:02:43 -0700714 index = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500715 if (index >= 0) {
716 ApplicationInfo info = mAllAppsList.get(index);
717 if (info.title != null) {
718 text = info.title.toString();
719 pos = index;
720 }
721 }
722 break;
723 case SELECTION_HOME:
724 text = getContext().getString(R.string.all_apps_home_button_label);
725 pos = count;
726 break;
727 }
728 if (text != null) {
729 event.setEnabled(true);
730 event.getText().add(text);
731 //event.setContentDescription(text);
732 event.setItemCount(count);
733 event.setCurrentItemIndex(pos);
734 }
735 }
736 return false;
737 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800738
Patrick Dubroya669d792010-11-23 14:40:33 -0800739 @Override
Daniel Sandler388f6792010-03-02 14:08:08 -0500740 public void setDragController(DragController dragger) {
741 mDragController = dragger;
742 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800743
Patrick Dubroya669d792010-11-23 14:40:33 -0800744 @Override
745 public void onDragViewVisible() {
746 }
747
748 @Override
Patrick Dubroy5f445422011-02-18 14:35:21 -0800749 public void onDropCompleted(View target, Object dragInfo, boolean success) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500750 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800751
Daniel Sandler388f6792010-03-02 14:08:08 -0500752 /**
753 * Zoom to the specifed level.
754 *
755 * @param zoom [0..1] 0 is hidden, 1 is open
756 */
757 public void zoom(float zoom, boolean animate) {
758 cancelLongPress();
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700759 sNextZoom = zoom;
760 sAnimateNextZoom = animate;
Daniel Sandler388f6792010-03-02 14:08:08 -0500761 // if we do setZoom while we don't have a surface, we won't
762 // get the callbacks that actually set mZoom.
Joe Onorato2cc62e82010-03-17 20:23:53 -0700763 if (sRollo == null || !mHaveSurface) {
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700764 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500765 mZoom = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500766 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700767 sRollo.setZoom(zoom, animate);
Daniel Sandler388f6792010-03-02 14:08:08 -0500768 }
769 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800770
Joe Onorato878f0862010-03-22 12:22:22 -0400771 /**
772 * If sRollo is null, then we're not visible. This is also used to guard against
773 * sRollo being null.
774 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500775 public boolean isVisible() {
Joe Onorato878f0862010-03-22 12:22:22 -0400776 return sRollo != null && mZoom > 0.001f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500777 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800778
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700779 public boolean isAnimating() {
780 return isVisible() && mZoom <= 0.999f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500781 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800782
Daniel Sandler388f6792010-03-02 14:08:08 -0500783 public void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700784 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500785 // We've been removed from the window. Don't bother with all this.
786 return;
787 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800788
Daniel Sandler707b0f72010-04-15 16:41:31 -0400789 if (list != null) {
790 Collections.sort(list, LauncherModel.APP_NAME_COMPARATOR);
791 }
792
Romain Guy13c2e7b2010-03-10 19:45:00 -0800793 boolean reload = false;
794 if (mAllAppsList == null) {
795 reload = true;
796 } else if (list.size() != mAllAppsList.size()) {
797 reload = true;
798 } else {
799 final int count = list.size();
800 for (int i = 0; i < count; i++) {
801 if (list.get(i) != mAllAppsList.get(i)) {
802 reload = true;
803 break;
804 }
805 }
806 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800807
Daniel Sandler388f6792010-03-02 14:08:08 -0500808 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700809 if (sRollo != null && reload) {
810 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500811 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700812
Romain Guyc16fea72010-03-12 17:17:56 -0800813 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700814 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
Romain Guyc16fea72010-03-12 17:17:56 -0800815 mRestoreFocusIndex = -1;
816 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700817
Daniel Sandler388f6792010-03-02 14:08:08 -0500818 mLocks &= ~LOCK_ICONS_PENDING;
819 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800820
Daniel Sandler388f6792010-03-02 14:08:08 -0500821 public void addApps(ArrayList<ApplicationInfo> list) {
822 if (mAllAppsList == null) {
823 // Not done loading yet. We'll find out about it later.
824 return;
825 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700826 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500827 // We've been removed from the window. Don't bother with all this.
828 return;
829 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800830
Daniel Sandler388f6792010-03-02 14:08:08 -0500831 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700832 if (sRollo != null) {
833 sRollo.pause();
Jason Sams14f67ed2010-05-11 14:02:43 -0700834 sRollo.reallocAppsList(sRollo.mScript.get_gIconCount() + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500835 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800836
Daniel Sandler388f6792010-03-02 14:08:08 -0500837 for (int i=0; i<N; i++) {
838 final ApplicationInfo item = list.get(i);
839 int index = Collections.binarySearch(mAllAppsList, item,
840 LauncherModel.APP_NAME_COMPARATOR);
841 if (index < 0) {
842 index = -(index+1);
843 }
844 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700845 if (sRollo != null) {
846 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500847 }
848 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800849
Joe Onorato2cc62e82010-03-17 20:23:53 -0700850 if (sRollo != null) {
851 sRollo.saveAppsList();
852 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500853 }
854 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800855
Daniel Sandler388f6792010-03-02 14:08:08 -0500856 public void removeApps(ArrayList<ApplicationInfo> list) {
857 if (mAllAppsList == null) {
858 // Not done loading yet. We'll find out about it later.
859 return;
860 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800861
Joe Onorato2cc62e82010-03-17 20:23:53 -0700862 if (sRollo != null) {
863 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800864 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500865 final int N = list.size();
866 for (int i=0; i<N; i++) {
867 final ApplicationInfo item = list.get(i);
868 int index = findAppByComponent(mAllAppsList, item);
869 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500870 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700871 if (sRollo != null) {
872 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500873 }
874 } else {
875 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
876 // Try to recover. This should keep us from crashing for now.
877 }
878 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800879
Joe Onorato2cc62e82010-03-17 20:23:53 -0700880 if (sRollo != null) {
881 sRollo.saveAppsList();
882 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500883 }
884 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800885
Joe Onorato64e6be72010-03-05 15:05:52 -0500886 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500887 // Just remove and add, because they may need to be re-sorted.
888 removeApps(list);
889 addApps(list);
890 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800891
Daniel Sandler388f6792010-03-02 14:08:08 -0500892 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
893 ComponentName component = item.intent.getComponent();
894 final int N = list.size();
895 for (int i=0; i<N; i++) {
896 ApplicationInfo x = list.get(i);
897 if (x.intent.getComponent().equals(component)) {
898 return i;
899 }
900 }
901 return -1;
902 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800903
Jason Sams4dfea092010-12-06 17:38:58 -0800904 class AAMessage extends RenderScript.RSMessageHandler {
Daniel Sandler388f6792010-03-02 14:08:08 -0500905 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700906 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500907 mVelocity = ((float)mData[1]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700908
909 boolean lastVisible = isVisible();
Daniel Sandler388f6792010-03-02 14:08:08 -0500910 mZoom = ((float)mData[2]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700911
912 final boolean visible = isVisible();
913 if (visible != lastVisible) {
914 post(new Runnable() {
915 public void run() {
916 if (visible) {
917 showSurface();
918 } else {
919 hideSurface();
920 }
921 }
922 });
923 }
924
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700925 sZoomDirty = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500926 }
927 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800928
Romain Guy13c2e7b2010-03-10 19:45:00 -0800929 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500930 // Allocations ======
931 private int mWidth;
932 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800933
Daniel Sandler388f6792010-03-02 14:08:08 -0500934 private Resources mRes;
Stephen Hinesb2d69862010-09-16 17:21:50 -0700935 ScriptC_allapps mScript;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800936
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700937 private Mesh mMesh;
Alex Sakhartchoukc3842422010-12-21 14:43:30 -0800938 private ProgramVertexFixedFunction.Constants mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800939
Jason Sams14f67ed2010-05-11 14:02:43 -0700940 private ScriptField_VpConsts mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800941
Daniel Sandler388f6792010-03-02 14:08:08 -0500942 private Allocation mHomeButtonNormal;
943 private Allocation mHomeButtonFocused;
944 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800945
Daniel Sandler388f6792010-03-02 14:08:08 -0500946 private Allocation[] mIcons;
Jason Sams4dfea092010-12-06 17:38:58 -0800947 private Allocation mAllocIcons;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800948
Daniel Sandler388f6792010-03-02 14:08:08 -0500949 private Allocation[] mLabels;
Jason Sams4dfea092010-12-06 17:38:58 -0800950 private Allocation mAllocLabels;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800951
Daniel Sandler388f6792010-03-02 14:08:08 -0500952 private Bitmap mSelectionBitmap;
953 private Canvas mSelectionCanvas;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800954
Jason Sams14f67ed2010-05-11 14:02:43 -0700955 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800956
Romain Guy13c2e7b2010-03-10 19:45:00 -0800957 AllApps3D mAllApps;
958 boolean mInitialize;
959
Daniel Sandler388f6792010-03-02 14:08:08 -0500960 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -0800961 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -0800962 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -0500963 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800964
965 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400966 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -0800967 sRS.bindRootScript(null);
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400968 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800969 }
970
971 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400972 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -0800973 sRS.bindRootScript(mScript);
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400974 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800975 }
976
Romain Guy13c2e7b2010-03-10 19:45:00 -0800977 public RolloRS(AllApps3D allApps) {
978 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -0500979 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800980
Daniel Sandler388f6792010-03-02 14:08:08 -0500981 public void init(Resources res, int width, int height) {
982 mRes = res;
983 mWidth = width;
984 mHeight = height;
Jason Sams4dfea092010-12-06 17:38:58 -0800985 mScript = new ScriptC_allapps(sRS, mRes, R.raw.allapps);
Jason Sams14f67ed2010-05-11 14:02:43 -0700986
Daniel Sandler388f6792010-03-02 14:08:08 -0500987 initProgramVertex();
988 initProgramFragment();
989 initProgramStore();
990 initGl();
991 initData();
Jason Sams14f67ed2010-05-11 14:02:43 -0700992
Jason Sams4dfea092010-12-06 17:38:58 -0800993 mScript.bind_gIcons(mAllocIcons);
994 mScript.bind_gLabels(mAllocLabels);
995 sRS.bindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -0500996 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800997
Daniel Sandler388f6792010-03-02 14:08:08 -0500998 public void initMesh() {
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700999 Mesh.TriangleMeshBuilder tm = new Mesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001000
Daniel Sandler388f6792010-03-02 14:08:08 -05001001 for (int ct=0; ct < 16; ct++) {
1002 float pos = (1.f / (16.f - 1)) * ct;
1003 tm.addVertex(0.0f, pos);
1004 tm.addVertex(1.0f, pos);
1005 }
1006 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1007 tm.addTriangle(ct, ct+1, ct+2);
1008 tm.addTriangle(ct+1, ct+3, ct+2);
1009 }
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001010 mMesh = tm.create(true);
Jason Sams14f67ed2010-05-11 14:02:43 -07001011 mScript.set_gSMCell(mMesh);
Daniel Sandler388f6792010-03-02 14:08:08 -05001012 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001013
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001014 Matrix4f getProjectionMatrix(int w, int h) {
1015 // range -1,1 in the narrow axis at z = 0.
1016 Matrix4f m1 = new Matrix4f();
1017 Matrix4f m2 = new Matrix4f();
1018
1019 if(w > h) {
1020 float aspect = ((float)w) / h;
1021 m1.loadFrustum(-aspect,aspect, -1,1, 1,100);
1022 } else {
1023 float aspect = ((float)h) / w;
1024 m1.loadFrustum(-1,1, -aspect,aspect, 1,100);
1025 }
1026
1027 m2.loadRotate(180, 0, 1, 0);
1028 m1.loadMultiply(m1, m2);
1029
1030 m2.loadScale(-2, 2, 1);
1031 m1.loadMultiply(m1, m2);
1032
1033 m2.loadTranslate(0, 0, 2);
1034 m1.loadMultiply(m1, m2);
1035 return m1;
1036 }
1037
Daniel Sandler388f6792010-03-02 14:08:08 -05001038 void resize(int w, int h) {
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001039 Matrix4f proj = getProjectionMatrix(w, h);
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001040 mPVA.setProjection(proj);
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001041
1042 if (mUniformAlloc != null) {
1043 ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
1044 i.Proj = proj;
1045 i.ScaleOffset.x = (2.f / 480.f);
1046 i.ScaleOffset.y = 0;
1047 i.ScaleOffset.z = -((float)w / 2) - 0.25f;
1048 i.ScaleOffset.w = -380.25f;
1049 i.BendPos.x = 120.f;
1050 i.BendPos.y = 680.f;
1051 if (w > h) {
1052 i.ScaleOffset.z = 40.f;
1053 i.ScaleOffset.w = h - 40.f;
1054 i.BendPos.y = 1.f;
1055 }
1056 mUniformAlloc.set(i, 0, true);
1057 }
1058
Daniel Sandler388f6792010-03-02 14:08:08 -05001059 mWidth = w;
1060 mHeight = h;
1061 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001062
Daniel Sandler388f6792010-03-02 14:08:08 -05001063 private void initProgramVertex() {
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001064 mPVA = new ProgramVertexFixedFunction.Constants(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001065 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001066
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001067 ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001068 pvb.setTextureMatrixEnable(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001069 ProgramVertex pv = pvb.create();
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001070 ((ProgramVertexFixedFunction)pv).bindConstants(mPVA);
Jason Sams4dfea092010-12-06 17:38:58 -08001071 sRS.bindProgramVertex(pv);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001072
Jason Sams14f67ed2010-05-11 14:02:43 -07001073 mUniformAlloc = new ScriptField_VpConsts(sRS, 1);
1074 mScript.bind_vpConstants(mUniformAlloc);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001075
Daniel Sandler388f6792010-03-02 14:08:08 -05001076 initMesh();
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001077 ProgramVertex.Builder sb = new ProgramVertex.Builder(sRS);
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001078 String t = "varying vec4 varColor;\n" +
Alex Sakhartchouk2f3b0b62010-10-06 09:32:12 -07001079 "varying vec2 varTex0;\n" +
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001080 "void main() {\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001081 // Animation
1082 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001083
Romain Guy060b5c82010-03-04 10:07:38 -08001084 " float bendY1 = UNI_BendPos.x;\n" +
1085 " float bendY2 = UNI_BendPos.y;\n" +
1086 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1087 " float bendDistance = bendY1 * 0.4;\n" +
1088 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001089
Romain Guy060b5c82010-03-04 10:07:38 -08001090 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1091 " float aDy = cos(bendAngle);\n" +
1092 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001093
Romain Guy060b5c82010-03-04 10:07:38 -08001094 " float scale = (2.0 / 480.0);\n" +
1095 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1096 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1097 " float y = 0.0;\n" +
1098 " float z = 0.0;\n" +
1099 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001100
Romain Guy060b5c82010-03-04 10:07:38 -08001101 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1102 " y += cv * aDy;\n" +
1103 " z += -cv * aDz;\n" +
1104 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1105 " lum += cv / bendDistance * distanceDimLevel;\n" +
1106 " y += cv * cos(cv * bendStep);\n" +
1107 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001108
Romain Guy060b5c82010-03-04 10:07:38 -08001109 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1110 " y += cv * aDy;\n" +
1111 " z += cv * aDz;\n" +
1112 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1113 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1114 " y += cv * cos(cv * bendStep);\n" +
1115 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001116
Romain Guy060b5c82010-03-04 10:07:38 -08001117 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001118
Romain Guy060b5c82010-03-04 10:07:38 -08001119 " vec4 pos;\n" +
1120 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1121 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1122 " pos.z = z * UNI_ScaleOffset.x;\n" +
1123 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001124
Romain Guy060b5c82010-03-04 10:07:38 -08001125 " pos.x *= 1.0 + ani * 4.0;\n" +
1126 " pos.y *= 1.0 + ani * 4.0;\n" +
1127 " pos.z -= ani * 1.5;\n" +
1128 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001129
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001130 " gl_Position = UNI_Proj * pos;\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001131 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1132 " varTex0.xy = ATTRIB_position;\n" +
1133 " varTex0.y = 1.0 - varTex0.y;\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001134 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001135 sb.setShader(t);
1136 sb.addConstant(mUniformAlloc.getType());
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001137 sb.addInput(mMesh.getVertexAllocation(0).getType().getElement());
Jason Sams60a55bb2010-06-18 15:11:19 -07001138 ProgramVertex pvc = sb.create();
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001139 pvc.bindConstants(mUniformAlloc.getAllocation(), 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001140
Jason Sams60a55bb2010-06-18 15:11:19 -07001141 mScript.set_gPVCurve(pvc);
Daniel Sandler388f6792010-03-02 14:08:08 -05001142 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001143
Daniel Sandler388f6792010-03-02 14:08:08 -05001144 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001145 Sampler.Builder sb = new Sampler.Builder(sRS);
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001146 sb.setMinification(Sampler.Value.LINEAR_MIP_LINEAR);
1147 sb.setMagnification(Sampler.Value.NEAREST);
Daniel Sandler388f6792010-03-02 14:08:08 -05001148 sb.setWrapS(Sampler.Value.CLAMP);
1149 sb.setWrapT(Sampler.Value.CLAMP);
1150 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001151
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001152 sb.setMinification(Sampler.Value.NEAREST);
1153 sb.setMagnification(Sampler.Value.NEAREST);
Daniel Sandler388f6792010-03-02 14:08:08 -05001154 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001155
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001156 ProgramFragmentFixedFunction.Builder bf = new ProgramFragmentFixedFunction.Builder(sRS);
1157 bf.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
1158 ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001159 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001160 ProgramFragment pfTexMip = bf.create();
1161 pfTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001162
Jason Sams070ada82010-08-04 17:53:07 -07001163 bf.setVaryingColor(false);
Jason Sams60a55bb2010-06-18 15:11:19 -07001164 ProgramFragment pfTexNearest = bf.create();
1165 pfTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001166
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001167 bf.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
1168 ProgramFragmentFixedFunction.Builder.Format.ALPHA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001169 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001170 ProgramFragment pfTexMipAlpha = bf.create();
1171 pfTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001172
Jason Sams60a55bb2010-06-18 15:11:19 -07001173 mScript.set_gPFTexNearest(pfTexNearest);
1174 mScript.set_gPFTexMip(pfTexMip);
1175 mScript.set_gPFTexMipAlpha(pfTexMipAlpha);
Daniel Sandler388f6792010-03-02 14:08:08 -05001176 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001177
Daniel Sandler388f6792010-03-02 14:08:08 -05001178 private void initProgramStore() {
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001179 ProgramStore.Builder bs = new ProgramStore.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001180 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001181 bs.setColorMaskEnabled(true,true,true,false);
1182 bs.setDitherEnabled(true);
Daniel Sandler388f6792010-03-02 14:08:08 -05001183 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1184 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Jason Sams14f67ed2010-05-11 14:02:43 -07001185 mScript.set_gPS(bs.create());
Daniel Sandler388f6792010-03-02 14:08:08 -05001186 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001187
Daniel Sandler388f6792010-03-02 14:08:08 -05001188 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001189 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001190
Daniel Sandler388f6792010-03-02 14:08:08 -05001191 private void initData() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001192 mScript.set_COLUMNS_PER_PAGE_PORTRAIT(Defines.COLUMNS_PER_PAGE_PORTRAIT);
1193 mScript.set_ROWS_PER_PAGE_PORTRAIT(Defines.ROWS_PER_PAGE_PORTRAIT);
1194 mScript.set_COLUMNS_PER_PAGE_LANDSCAPE(Defines.COLUMNS_PER_PAGE_LANDSCAPE);
1195 mScript.set_ROWS_PER_PAGE_LANDSCAPE(Defines.ROWS_PER_PAGE_LANDSCAPE);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001196
Joe Onorato2cc62e82010-03-17 20:23:53 -07001197 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
Jason Sams735a8242010-12-14 19:24:21 -08001198 R.drawable.home_button_normal);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001199 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
Jason Sams735a8242010-12-14 19:24:21 -08001200 R.drawable.home_button_focused);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001201 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
Jason Sams735a8242010-12-14 19:24:21 -08001202 R.drawable.home_button_pressed);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001203
Jason Sams14f67ed2010-05-11 14:02:43 -07001204 mScript.set_gHomeButton(mHomeButtonNormal);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001205
Daniel Sandler388f6792010-03-02 14:08:08 -05001206 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1207 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1208 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001209
Daniel Sandler388f6792010-03-02 14:08:08 -05001210 setApps(null);
1211 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001212
Daniel Sandler388f6792010-03-02 14:08:08 -05001213 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001214 if (sZoomDirty) {
1215 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001216 }
1217 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001218
Romain Guy060b5c82010-03-04 10:07:38 -08001219 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001220 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001221 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001222 final int count = list != null ? list.size() : 0;
1223 int allocCount = count;
1224 if (allocCount < 1) {
1225 allocCount = 1;
1226 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001227
Daniel Sandler388f6792010-03-02 14:08:08 -05001228 mIcons = new Allocation[count];
Jason Sams4dfea092010-12-06 17:38:58 -08001229 mAllocIcons = Allocation.createSized(sRS, Element.ALLOCATION(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001230
Daniel Sandler388f6792010-03-02 14:08:08 -05001231 mLabels = new Allocation[count];
Jason Sams4dfea092010-12-06 17:38:58 -08001232 mAllocLabels = Allocation.createSized(sRS, Element.ALLOCATION(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001233
Jason Sams14f67ed2010-05-11 14:02:43 -07001234 mScript.set_gIconCount(count);
1235 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001236 createAppIconAllocations(i, list.get(i));
1237 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001238 saveAppsList();
Jason Sams14f67ed2010-05-11 14:02:43 -07001239 android.util.Log.e("rs", "setApps");
Joe Onorato2cc62e82010-03-17 20:23:53 -07001240 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001241 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001242
Daniel Sandler388f6792010-03-02 14:08:08 -05001243 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001244 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001245 sRollo.clearSelectedIcon();
1246 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001247 }
Jason Sams60a55bb2010-06-18 15:11:19 -07001248 sRollo.mScript.invoke_setZoom(zoom, animate ? 1 : 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001249 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001250
Daniel Sandler388f6792010-03-02 14:08:08 -05001251 private void createAppIconAllocations(int index, ApplicationInfo item) {
Jason Sams95d2d2d2010-12-16 12:19:04 -08001252 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1253 Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
1254 Allocation.USAGE_GRAPHICS_TEXTURE);
1255 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1256 Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
1257 Allocation.USAGE_GRAPHICS_TEXTURE);
Daniel Sandler388f6792010-03-02 14:08:08 -05001258 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001259
Daniel Sandler388f6792010-03-02 14:08:08 -05001260 /**
1261 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1262 * fill in the values and call saveAppsList().
1263 */
1264 private void reallocAppsList(int count) {
1265 Allocation[] icons = new Allocation[count];
Jason Sams4dfea092010-12-06 17:38:58 -08001266 mAllocIcons = Allocation.createSized(sRS, Element.ALLOCATION(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001267
Daniel Sandler388f6792010-03-02 14:08:08 -05001268 Allocation[] labels = new Allocation[count];
Jason Sams4dfea092010-12-06 17:38:58 -08001269 mAllocLabels = Allocation.createSized(sRS, Element.ALLOCATION(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001270
Jason Sams14f67ed2010-05-11 14:02:43 -07001271 final int oldCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001272
Daniel Sandler388f6792010-03-02 14:08:08 -05001273 System.arraycopy(mIcons, 0, icons, 0, oldCount);
Daniel Sandler388f6792010-03-02 14:08:08 -05001274 System.arraycopy(mLabels, 0, labels, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001275
Daniel Sandler388f6792010-03-02 14:08:08 -05001276 mIcons = icons;
Daniel Sandler388f6792010-03-02 14:08:08 -05001277 mLabels = labels;
Daniel Sandler388f6792010-03-02 14:08:08 -05001278 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001279
Daniel Sandler388f6792010-03-02 14:08:08 -05001280 /**
1281 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1282 */
1283 private void addApp(int index, ApplicationInfo item) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001284 final int count = mScript.get_gIconCount() - index;
Daniel Sandler388f6792010-03-02 14:08:08 -05001285 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001286
Daniel Sandler388f6792010-03-02 14:08:08 -05001287 System.arraycopy(mIcons, index, mIcons, dest, count);
Daniel Sandler388f6792010-03-02 14:08:08 -05001288 System.arraycopy(mLabels, index, mLabels, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001289
Daniel Sandler388f6792010-03-02 14:08:08 -05001290 createAppIconAllocations(index, item);
Jason Sams14f67ed2010-05-11 14:02:43 -07001291
1292 mScript.set_gIconCount(mScript.get_gIconCount() + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001293 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001294
Daniel Sandler388f6792010-03-02 14:08:08 -05001295 /**
1296 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1297 */
1298 private void removeApp(int index) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001299 final int count = mScript.get_gIconCount() - index - 1;
Daniel Sandler388f6792010-03-02 14:08:08 -05001300 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001301
Daniel Sandler388f6792010-03-02 14:08:08 -05001302 System.arraycopy(mIcons, src, mIcons, index, count);
Daniel Sandler388f6792010-03-02 14:08:08 -05001303 System.arraycopy(mLabels, src, mLabels, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001304
Jason Sams14f67ed2010-05-11 14:02:43 -07001305 mScript.set_gIconCount(mScript.get_gIconCount() - 1);
1306 final int last = mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001307
Daniel Sandler388f6792010-03-02 14:08:08 -05001308 mIcons[last] = null;
Daniel Sandler388f6792010-03-02 14:08:08 -05001309 mLabels[last] = null;
Daniel Sandler388f6792010-03-02 14:08:08 -05001310 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001311
Daniel Sandler388f6792010-03-02 14:08:08 -05001312 /**
1313 * Send the apps list structures to RS.
1314 */
1315 private void saveAppsList() {
1316 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
Jason Sams4dfea092010-12-06 17:38:58 -08001317 if (mScript != null && mAllocIcons != null) {
1318 if (mIcons.length > 0) {
1319 mAllocIcons.copyFrom(mIcons);
1320 mAllocLabels.copyFrom(mLabels);
1321 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001322
Jason Sams4dfea092010-12-06 17:38:58 -08001323 mScript.bind_gIcons(mAllocIcons);
1324 mScript.bind_gLabels(mAllocLabels);
Daniel Sandler388f6792010-03-02 14:08:08 -05001325 }
1326 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001327
Jason Sams60a55bb2010-06-18 15:11:19 -07001328 void fling(float pos, float v) {
1329 mScript.invoke_fling(pos, v);
Daniel Sandler388f6792010-03-02 14:08:08 -05001330 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001331
Jason Sams60a55bb2010-06-18 15:11:19 -07001332 void move(float pos) {
1333 mScript.invoke_move(pos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001334 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001335
Daniel Sandler388f6792010-03-02 14:08:08 -05001336 void moveTo(float row) {
Jason Sams60a55bb2010-06-18 15:11:19 -07001337 mScript.invoke_moveTo(row);
Daniel Sandler388f6792010-03-02 14:08:08 -05001338 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001339
Daniel Sandler388f6792010-03-02 14:08:08 -05001340 /**
1341 * You need to call save() on mState on your own after calling this.
1342 *
1343 * @return the index of the icon that was selected.
1344 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001345 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001346 if (mAllApps != null) {
1347 final int index = mAllApps.chooseTappedIcon(x, y);
1348 selectIcon(index, pressed);
1349 return index;
1350 } else {
1351 return -1;
1352 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001353 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001354
Daniel Sandler388f6792010-03-02 14:08:08 -05001355 /**
1356 * Select the icon at the given index.
1357 *
1358 * @param index The index.
1359 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1360 */
1361 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001362 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1363 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001364 if (mAllApps != null) {
1365 mAllApps.mRestoreFocusIndex = index;
1366 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001367 mScript.set_gSelectedIconIndex(-1);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001368 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1369 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001370 }
1371 } else {
1372 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001373 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001374 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001375
Jason Sams14f67ed2010-05-11 14:02:43 -07001376 int prev = mScript.get_gSelectedIconIndex();
1377 mScript.set_gSelectedIconIndex(index);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001378
Romain Guy13c2e7b2010-03-10 19:45:00 -08001379 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001380 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001381
Daniel Sandler388f6792010-03-02 14:08:08 -05001382 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1383 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1384 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001385
Jason Sams735a8242010-12-14 19:24:21 -08001386 Allocation si = Allocation.createFromBitmap(sRS, selectionBitmap);
Jason Sams60a55bb2010-06-18 15:11:19 -07001387 mScript.set_gSelectedIconTexture(si);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001388
Daniel Sandler388f6792010-03-02 14:08:08 -05001389 if (prev != index) {
1390 if (info.title != null && info.title.length() > 0) {
1391 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001392 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001393 }
1394 }
1395 }
1396 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001397
Daniel Sandler388f6792010-03-02 14:08:08 -05001398 /**
1399 * You need to call save() on mState on your own after calling this.
1400 */
1401 void clearSelectedIcon() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001402 mScript.set_gSelectedIconIndex(-1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001403 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001404
Daniel Sandler388f6792010-03-02 14:08:08 -05001405 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001406 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001407 switch (mode) {
1408 case SELECTED_NONE:
Jason Sams14f67ed2010-05-11 14:02:43 -07001409 mScript.set_gHomeButton(mHomeButtonNormal);
Daniel Sandler388f6792010-03-02 14:08:08 -05001410 break;
1411 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001412 mAllApps.mLastSelection = SELECTION_HOME;
Jason Sams14f67ed2010-05-11 14:02:43 -07001413 mScript.set_gHomeButton(mHomeButtonFocused);
Daniel Sandler388f6792010-03-02 14:08:08 -05001414 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001415 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001416 }
1417 break;
1418 case SELECTED_PRESSED:
Jason Sams14f67ed2010-05-11 14:02:43 -07001419 mScript.set_gHomeButton(mHomeButtonPressed);
Daniel Sandler388f6792010-03-02 14:08:08 -05001420 break;
1421 }
1422 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001423
Daniel Sandler388f6792010-03-02 14:08:08 -05001424 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001425 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1426 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1427 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001428 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001429 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001430 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001431 //Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1432 //Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1433 //Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1434 //Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1435 //Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1436 //Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1437 //Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1438 //Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1439 //Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001440 }
1441 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001442
Daniel Sandler388f6792010-03-02 14:08:08 -05001443 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001444 Log.d(TAG, "sRS=" + sRS);
1445 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001446 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001447 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1448 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001449 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1450 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1451 Log.d(TAG, "mLastSelection=" + mLastSelection);
1452 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1453 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1454 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1455 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001456 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1457 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001458 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001459 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001460 Log.d(TAG, "mVelocity=" + mVelocity);
1461 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001462 if (sRollo != null) {
1463 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001464 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001465 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -08001466 sRS.contextDump();
Daniel Sandler388f6792010-03-02 14:08:08 -05001467 }
1468 }
1469}