blob: 0e512c6d97dd287800204fbc3ea7700452b3e660 [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
Joe Onorato2cc62e82010-03-17 20:23:53 -0700158 if (sRollo != null) {
159 sRollo.mAllApps = this;
160 sRollo.mRes = getResources();
161 sRollo.mInitialize = true;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800162 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500163 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800164
Romain Guy060b5c82010-03-04 10:07:38 -0800165 @SuppressWarnings({"UnusedDeclaration"})
166 public AllApps3D(Context context, AttributeSet attrs, int defStyle) {
167 this(context, attrs);
168 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800169
Romain Guy13c2e7b2010-03-10 19:45:00 -0800170 public void surrender() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400171 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -0800172 sRS.setSurface(null, 0, 0);
173 sRS.setMessageHandler(null);
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400174 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800175 mSurrendered = true;
176 }
177
Daniel Sandler388f6792010-03-02 14:08:08 -0500178 /**
179 * Note that this implementation prohibits this view from ever being reattached.
180 */
181 @Override
182 protected void onDetachedFromWindow() {
Jason Sams4dfea092010-12-06 17:38:58 -0800183 sRS.setMessageHandler(null);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800184 if (!mSurrendered) {
Joe Onorato96da4012010-03-17 20:03:24 -0700185 Log.i(TAG, "onDetachedFromWindow");
Jason Sams4dfea092010-12-06 17:38:58 -0800186 destroyRenderScriptGL();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700187 sRS = null;
188 sRollo = null;
thigobr1f43a312010-10-22 18:13:26 -0200189 super.onDetachedFromWindow();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800190 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500191 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800192
Daniel Sandler388f6792010-03-02 14:08:08 -0500193 /**
194 * If you have an attached click listener, View always plays the click sound!?!?
195 * Deal with sound effects by hand.
196 */
197 public void reallyPlaySoundEffect(int sound) {
198 boolean old = isSoundEffectsEnabled();
199 setSoundEffectsEnabled(true);
200 playSoundEffect(sound);
201 setSoundEffectsEnabled(old);
202 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800203
Winson Chung785d2eb2011-04-14 16:08:02 -0700204 @Override
205 public void setup(Launcher launcher, DragController dragController) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500206 mLauncher = launcher;
Winson Chung785d2eb2011-04-14 16:08:02 -0700207 mDragController = dragController;
Daniel Sandler388f6792010-03-02 14:08:08 -0500208 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800209
Daniel Sandler388f6792010-03-02 14:08:08 -0500210 @Override
211 public void surfaceDestroyed(SurfaceHolder holder) {
212 super.surfaceDestroyed(holder);
213 // Without this, we leak mMessageCallback which leaks the context.
Romain Guy13c2e7b2010-03-10 19:45:00 -0800214 if (!mSurrendered) {
Jason Sams4dfea092010-12-06 17:38:58 -0800215 sRS.setMessageHandler(null);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800216 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500217 // We may lose any callbacks that are pending, so make sure that we re-sync that
218 // on the next surfaceChanged.
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700219 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500220 mHaveSurface = false;
221 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800222
Daniel Sandler388f6792010-03-02 14:08:08 -0500223 @Override
224 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
225 //long startTime = SystemClock.uptimeMillis();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800226
Daniel Sandler388f6792010-03-02 14:08:08 -0500227 super.surfaceChanged(holder, format, w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800228
Marco Nelissen876668c2011-04-22 13:18:53 -0700229 final boolean isPortrait = w < h;
230 mColumnsPerPage = isPortrait ? Defines.COLUMNS_PER_PAGE_PORTRAIT :
231 Defines.COLUMNS_PER_PAGE_LANDSCAPE;
232 mRowsPerPage = isPortrait ? Defines.ROWS_PER_PAGE_PORTRAIT :
233 Defines.ROWS_PER_PAGE_LANDSCAPE;
234
Romain Guy13c2e7b2010-03-10 19:45:00 -0800235 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800236
Daniel Sandler388f6792010-03-02 14:08:08 -0500237 mHaveSurface = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800238
Joe Onorato2cc62e82010-03-17 20:23:53 -0700239 if (sRollo == null) {
240 sRollo = new RolloRS(this);
241 sRollo.init(getResources(), w, h);
Daniel Sandler388f6792010-03-02 14:08:08 -0500242 if (mAllAppsList != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700243 sRollo.setApps(mAllAppsList);
Daniel Sandler388f6792010-03-02 14:08:08 -0500244 }
245 if (mShouldGainFocus) {
246 gainFocus();
247 mShouldGainFocus = false;
248 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700249 } else if (sRollo.mInitialize) {
250 sRollo.initGl();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700251 sRollo.mInitialize = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500252 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800253
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700254 initTouchState(w, h);
255
Joe Onorato2cc62e82010-03-17 20:23:53 -0700256 sRollo.dirtyCheck();
257 sRollo.resize(w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800258
Jason Sams14f67ed2010-05-11 14:02:43 -0700259 Log.d(TAG, "sc " + sRS);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700260 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -0800261 mMessageProc = new AAMessage();
262 sRS.setMessageHandler(mMessageProc);
Daniel Sandler388f6792010-03-02 14:08:08 -0500263 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800264
Daniel Sandler388f6792010-03-02 14:08:08 -0500265 //long endTime = SystemClock.uptimeMillis();
266 //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
267 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800268
Daniel Sandler388f6792010-03-02 14:08:08 -0500269 @Override
270 public void onWindowFocusChanged(boolean hasWindowFocus) {
271 super.onWindowFocusChanged(hasWindowFocus);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800272
273 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800274
Daniel Sandler388f6792010-03-02 14:08:08 -0500275 if (mArrowNavigation) {
276 if (!hasWindowFocus) {
277 // Clear selection when we lose window focus
Jason Sams14f67ed2010-05-11 14:02:43 -0700278 mLastSelectedIcon = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700279 sRollo.setHomeSelected(SELECTED_NONE);
280 sRollo.clearSelectedIcon();
Romain Guy060b5c82010-03-04 10:07:38 -0800281 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700282 if (sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500283 if (mLastSelection == SELECTION_ICONS) {
284 int selection = mLastSelectedIcon;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700285 final int firstIcon = Math.round(sRollo.mScrollPos) * mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500286 if (selection < 0 || // No selection
287 selection < firstIcon || // off the top of the screen
Jason Sams14f67ed2010-05-11 14:02:43 -0700288 selection >= sRollo.mScript.get_gIconCount() || // past last icon
Daniel Sandler388f6792010-03-02 14:08:08 -0500289 selection >= firstIcon + // past last icon on screen
Romain Guy060b5c82010-03-04 10:07:38 -0800290 (mColumnsPerPage * mRowsPerPage)) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500291 selection = firstIcon;
292 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800293
Daniel Sandler388f6792010-03-02 14:08:08 -0500294 // Select the first icon when we gain window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700295 sRollo.selectIcon(selection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500296 } else if (mLastSelection == SELECTION_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700297 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500298 }
299 }
300 }
301 }
302 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800303
Daniel Sandler388f6792010-03-02 14:08:08 -0500304 @Override
305 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
306 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800307
Romain Guy13c2e7b2010-03-10 19:45:00 -0800308 if (!isVisible() || mSurrendered) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500309 return;
310 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800311
Daniel Sandler388f6792010-03-02 14:08:08 -0500312 if (gainFocus) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700313 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500314 gainFocus();
315 } else {
316 mShouldGainFocus = true;
317 }
318 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700319 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500320 if (mArrowNavigation) {
321 // Clear selection when we lose focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700322 sRollo.clearSelectedIcon();
323 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500324 mArrowNavigation = false;
325 }
326 } else {
327 mShouldGainFocus = false;
328 }
329 }
330 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800331
Daniel Sandler388f6792010-03-02 14:08:08 -0500332 private void gainFocus() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700333 if (!mArrowNavigation && sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500334 // Select the first icon when we gain keyboard focus
335 mArrowNavigation = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700336 sRollo.selectIcon(Math.round(sRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500337 }
338 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800339
Daniel Sandler388f6792010-03-02 14:08:08 -0500340 @Override
341 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800342
Daniel Sandler388f6792010-03-02 14:08:08 -0500343 boolean handled = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800344
Daniel Sandler388f6792010-03-02 14:08:08 -0500345 if (!isVisible()) {
346 return false;
347 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700348 final int iconCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800349
Daniel Sandler388f6792010-03-02 14:08:08 -0500350 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
351 if (mArrowNavigation) {
352 if (mLastSelection == SELECTION_HOME) {
353 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
Winson Chung097eb0a2011-03-18 16:56:08 -0700354 mLauncher.showWorkspace(true);
Daniel Sandler388f6792010-03-02 14:08:08 -0500355 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700356 int whichApp = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500357 if (whichApp >= 0) {
358 ApplicationInfo app = mAllAppsList.get(whichApp);
Joe Onoratof984e852010-03-25 09:47:45 -0700359 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500360 handled = true;
361 }
362 }
363 }
364 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800365
Daniel Sandler388f6792010-03-02 14:08:08 -0500366 if (iconCount > 0) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800367 final boolean isPortrait = getWidth() < getHeight();
Jason Sams14f67ed2010-05-11 14:02:43 -0700368
Daniel Sandler388f6792010-03-02 14:08:08 -0500369 mArrowNavigation = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800370
Jason Sams14f67ed2010-05-11 14:02:43 -0700371 int currentSelection = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700372 int currentTopRow = Math.round(sRollo.mScrollPos);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800373
Romain Guy060b5c82010-03-04 10:07:38 -0800374 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1
375 final int currentPageCol = currentSelection % mColumnsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800376
Romain Guy060b5c82010-03-04 10:07:38 -0800377 // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1
Romain Guy6a42cf32010-03-12 16:03:52 -0800378 final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage))
Romain Guy060b5c82010-03-04 10:07:38 -0800379 / mRowsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800380
Daniel Sandler388f6792010-03-02 14:08:08 -0500381 int newSelection = currentSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800382
Daniel Sandler388f6792010-03-02 14:08:08 -0500383 switch (keyCode) {
384 case KeyEvent.KEYCODE_DPAD_UP:
385 if (mLastSelection == SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800386 if (isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700387 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guy6a42cf32010-03-12 16:03:52 -0800388 int lastRowCount = iconCount % mColumnsPerPage;
389 if (lastRowCount == 0) {
390 lastRowCount = mColumnsPerPage;
391 }
392 newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2);
393 if (newSelection >= iconCount) {
394 newSelection = iconCount-1;
395 }
396 int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
397 if (target < 0) {
398 target = 0;
399 }
400 if (currentTopRow != target) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700401 sRollo.moveTo(target);
Romain Guy6a42cf32010-03-12 16:03:52 -0800402 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500403 }
404 } else {
405 if (currentPageRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800406 newSelection = currentSelection - mColumnsPerPage;
Romain Guy6a42cf32010-03-12 16:03:52 -0800407 if (currentTopRow > newSelection / mColumnsPerPage) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700408 sRollo.moveTo(newSelection / mColumnsPerPage);
Romain Guy6a42cf32010-03-12 16:03:52 -0800409 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500410 } else if (currentTopRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800411 newSelection = currentSelection - mColumnsPerPage;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700412 sRollo.moveTo(newSelection / mColumnsPerPage);
Daniel Sandler388f6792010-03-02 14:08:08 -0500413 } else if (currentPageRow != 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800414 newSelection = currentTopRow * mRowsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500415 }
416 }
417 handled = true;
418 break;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800419
Daniel Sandler388f6792010-03-02 14:08:08 -0500420 case KeyEvent.KEYCODE_DPAD_DOWN: {
Romain Guy060b5c82010-03-04 10:07:38 -0800421 final int rowCount = iconCount / mColumnsPerPage
422 + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
423 final int currentRow = currentSelection / mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500424 if (mLastSelection != SELECTION_HOME) {
425 if (currentRow < rowCount-1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700426 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500427 if (currentSelection < 0) {
428 newSelection = 0;
429 } else {
Romain Guy060b5c82010-03-04 10:07:38 -0800430 newSelection = currentSelection + mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500431 }
432 if (newSelection >= iconCount) {
433 // Go from D to G in this arrangement:
434 // A B C D
435 // E F G
436 newSelection = iconCount - 1;
437 }
Romain Guy060b5c82010-03-04 10:07:38 -0800438 if (currentPageRow >= mRowsPerPage - 1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700439 sRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -0500440 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800441 } else if (isPortrait) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500442 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700443 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500444 }
445 }
446 handled = true;
447 break;
448 }
449 case KeyEvent.KEYCODE_DPAD_LEFT:
450 if (mLastSelection != SELECTION_HOME) {
451 if (currentPageCol > 0) {
452 newSelection = currentSelection - 1;
453 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800454 } else if (!isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700455 newSelection = ((int) (sRollo.mScrollPos) * mColumnsPerPage) +
Romain Guy6a42cf32010-03-12 16:03:52 -0800456 (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700457 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500458 }
459 handled = true;
460 break;
461 case KeyEvent.KEYCODE_DPAD_RIGHT:
462 if (mLastSelection != SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800463 if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 ||
464 currentSelection == iconCount - 1)) {
465 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700466 sRollo.setHomeSelected(SELECTED_FOCUSED);
Romain Guy6a42cf32010-03-12 16:03:52 -0800467 } else if ((currentPageCol < mColumnsPerPage - 1) &&
Daniel Sandler388f6792010-03-02 14:08:08 -0500468 (currentSelection < iconCount - 1)) {
469 newSelection = currentSelection + 1;
470 }
471 }
472 handled = true;
473 break;
474 }
475 if (newSelection != currentSelection) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700476 sRollo.selectIcon(newSelection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500477 }
478 }
479 return handled;
480 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800481
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700482 void initTouchState(int width, int height) {
483 boolean isPortrait = width < height;
484
485 int[] viewPos = new int[2];
486 getLocationOnScreen(viewPos);
487
488 mTouchXBorders = new int[mColumnsPerPage + 1];
489 mTouchYBorders = new int[mRowsPerPage + 1];
490
491 // TODO: Put this in a config file/define
492 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE_PORTRAIT;
493 if (!isPortrait) cellHeight -= 12;
494 int centerY = (int) (height * (isPortrait ? 0.5f : 0.47f));
495 if (!isPortrait) centerY += cellHeight / 2;
496 int half = (int) Math.floor((mRowsPerPage + 1) / 2);
497 int end = mTouchYBorders.length - (half + 1);
498
499 for (int i = -half; i <= end; i++) {
500 mTouchYBorders[i + half] = centerY + (i * cellHeight) - viewPos[1];
501 }
502
503 int x = 0;
504 // TODO: Put this in a config file/define
505 int columnWidth = 120;
506 for (int i = 0; i < mColumnsPerPage + 1; i++) {
507 mTouchXBorders[i] = x - viewPos[0];
508 x += columnWidth;
509 }
510 }
511
512 int chooseTappedIcon(int x, int y) {
513 float pos = sRollo != null ? sRollo.mScrollPos : 0;
514
515 int oldY = y;
516
517 // Adjust for scroll position if not zero.
518 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
519
520 int col = -1;
521 int row = -1;
522 final int columnsCount = mColumnsPerPage;
523 for (int i=0; i< columnsCount; i++) {
524 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
525 col = i;
526 break;
527 }
528 }
529 final int rowsCount = mRowsPerPage;
530 for (int i=0; i< rowsCount; i++) {
531 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
532 row = i;
533 break;
534 }
535 }
536
537 if (row < 0 || col < 0) {
538 return -1;
539 }
540
541 int index = (((int) pos) * columnsCount) + (row * columnsCount) + col;
542
543 if (index >= mAllAppsList.size()) {
544 return -1;
545 } else {
546 return index;
547 }
548 }
549
Daniel Sandler388f6792010-03-02 14:08:08 -0500550 @Override
551 public boolean onTouchEvent(MotionEvent ev)
552 {
553 mArrowNavigation = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800554
Daniel Sandler388f6792010-03-02 14:08:08 -0500555 if (!isVisible()) {
556 return true;
557 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800558
Daniel Sandler388f6792010-03-02 14:08:08 -0500559 if (mLocks != 0) {
560 return true;
561 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800562
Daniel Sandler388f6792010-03-02 14:08:08 -0500563 super.onTouchEvent(ev);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800564
Daniel Sandler388f6792010-03-02 14:08:08 -0500565 int x = (int)ev.getX();
566 int y = (int)ev.getY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800567
Romain Guyce115852010-03-04 12:15:37 -0800568 final boolean isPortrait = getWidth() < getHeight();
Daniel Sandler388f6792010-03-02 14:08:08 -0500569 int action = ev.getAction();
570 switch (action) {
571 case MotionEvent.ACTION_DOWN:
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700572 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
573 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500574 mTouchTracking = TRACKING_HOME;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700575 sRollo.setHomeSelected(SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500576 mCurrentIconIndex = -1;
577 } else {
578 mTouchTracking = TRACKING_FLING;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800579
Daniel Sandler388f6792010-03-02 14:08:08 -0500580 mMotionDownRawX = (int)ev.getRawX();
581 mMotionDownRawY = (int)ev.getRawY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800582
Joe Onorato2cc62e82010-03-17 20:23:53 -0700583 if (!sRollo.checkClickOK()) {
584 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500585 } else {
586 mDownIconIndex = mCurrentIconIndex
Joe Onorato2cc62e82010-03-17 20:23:53 -0700587 = sRollo.selectIcon(x, y, SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500588 if (mDownIconIndex < 0) {
589 // if nothing was selected, no long press.
590 cancelLongPress();
591 }
592 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700593 sRollo.move(ev.getRawY() / getHeight());
Daniel Sandler388f6792010-03-02 14:08:08 -0500594 mVelocityTracker = VelocityTracker.obtain();
595 mVelocityTracker.addMovement(ev);
596 mStartedScrolling = false;
597 }
598 break;
599 case MotionEvent.ACTION_MOVE:
600 case MotionEvent.ACTION_OUTSIDE:
601 if (mTouchTracking == TRACKING_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700602 sRollo.setHomeSelected((isPortrait &&
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700603 y > mTouchYBorders[mTouchYBorders.length-1]) || (!isPortrait
604 && x > mTouchXBorders[mTouchXBorders.length-1])
Daniel Sandler388f6792010-03-02 14:08:08 -0500605 ? SELECTED_PRESSED : SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500606 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500607 int rawY = (int)ev.getRawY();
608 int slop;
609 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800610
Daniel Sandler388f6792010-03-02 14:08:08 -0500611 if (!mStartedScrolling && slop < mSlop) {
612 // don't update anything so when we do start scrolling
613 // below, we get the right delta.
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700614 mCurrentIconIndex = chooseTappedIcon(x, y);
Daniel Sandler388f6792010-03-02 14:08:08 -0500615 if (mDownIconIndex != mCurrentIconIndex) {
616 // If a different icon is selected, don't allow it to be picked up.
617 // This handles off-axis dragging.
618 cancelLongPress();
619 mCurrentIconIndex = -1;
620 }
621 } else {
622 if (!mStartedScrolling) {
623 cancelLongPress();
624 mCurrentIconIndex = -1;
625 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700626 sRollo.move(ev.getRawY() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800627
Daniel Sandler388f6792010-03-02 14:08:08 -0500628 mStartedScrolling = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700629 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500630 mVelocityTracker.addMovement(ev);
Daniel Sandler388f6792010-03-02 14:08:08 -0500631 }
632 }
633 break;
634 case MotionEvent.ACTION_UP:
635 case MotionEvent.ACTION_CANCEL:
636 if (mTouchTracking == TRACKING_HOME) {
637 if (action == MotionEvent.ACTION_UP) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700638 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
639 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500640 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
Winson Chung097eb0a2011-03-18 16:56:08 -0700641 mLauncher.showWorkspace(true);
Daniel Sandler388f6792010-03-02 14:08:08 -0500642 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700643 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500644 }
645 mCurrentIconIndex = -1;
646 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500647 mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700648 sRollo.clearSelectedIcon();
Jason Sams60a55bb2010-06-18 15:11:19 -0700649 sRollo.fling(ev.getRawY() / getHeight(),
650 mVelocityTracker.getYVelocity() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800651
Daniel Sandler388f6792010-03-02 14:08:08 -0500652 if (mVelocityTracker != null) {
653 mVelocityTracker.recycle();
654 mVelocityTracker = null;
655 }
656 }
657 mTouchTracking = TRACKING_NONE;
658 break;
659 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800660
Daniel Sandler388f6792010-03-02 14:08:08 -0500661 return true;
662 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800663
Daniel Sandler388f6792010-03-02 14:08:08 -0500664 public void onClick(View v) {
665 if (mLocks != 0 || !isVisible()) {
666 return;
667 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700668 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500669 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
670 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
671 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onoratof984e852010-03-25 09:47:45 -0700672 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500673 }
674 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800675
Daniel Sandler388f6792010-03-02 14:08:08 -0500676 public boolean onLongClick(View v) {
Joe Onorato6b4adbc2010-09-01 12:13:25 -0700677 // We don't accept long click events in these cases
678 // - If the workspace isn't ready to accept a drop
679 // - If we're not done loading (because we might be confused about which item
680 // to pick up
681 // - If we're not visible
682 if (!isVisible() || mLauncher.isWorkspaceLocked() || mLocks != 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500683 return true;
684 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700685 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500686 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
687 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800688
Patrick Dubroy5f445422011-02-18 14:35:21 -0800689 final Bitmap bmp = app.iconBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800690
Daniel Sandler388f6792010-03-02 14:08:08 -0500691 // We don't really have an accurate location to use. This will do.
Patrick Dubroy5f445422011-02-18 14:35:21 -0800692 int screenX = mMotionDownRawX - (bmp.getWidth() / 2);
693 int screenY = mMotionDownRawY - bmp.getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800694
Winson Chung097eb0a2011-03-18 16:56:08 -0700695 mLauncher.lockScreenOrientation();
696 mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, bmp);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800697 mDragController.startDrag(
698 bmp, screenX, screenY, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800699
Winson Chung097eb0a2011-03-18 16:56:08 -0700700 mLauncher.showWorkspace(true);
Daniel Sandler388f6792010-03-02 14:08:08 -0500701 }
702 return true;
703 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800704
Daniel Sandler388f6792010-03-02 14:08:08 -0500705 @Override
706 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
707 if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
708 if (!isVisible()) {
709 return false;
710 }
711 String text = null;
712 int index;
713 int count = mAllAppsList.size() + 1; // +1 is home
714 int pos = -1;
715 switch (mLastSelection) {
716 case SELECTION_ICONS:
Jason Sams14f67ed2010-05-11 14:02:43 -0700717 index = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500718 if (index >= 0) {
719 ApplicationInfo info = mAllAppsList.get(index);
720 if (info.title != null) {
721 text = info.title.toString();
722 pos = index;
723 }
724 }
725 break;
726 case SELECTION_HOME:
727 text = getContext().getString(R.string.all_apps_home_button_label);
728 pos = count;
729 break;
730 }
731 if (text != null) {
732 event.setEnabled(true);
733 event.getText().add(text);
734 //event.setContentDescription(text);
735 event.setItemCount(count);
736 event.setCurrentItemIndex(pos);
737 }
738 }
739 return false;
740 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800741
Patrick Dubroya669d792010-11-23 14:40:33 -0800742 @Override
Patrick Dubroya669d792010-11-23 14:40:33 -0800743 public void onDragViewVisible() {
744 }
745
746 @Override
Patrick Dubroy5f445422011-02-18 14:35:21 -0800747 public void onDropCompleted(View target, Object dragInfo, boolean success) {
Winson Chung097eb0a2011-03-18 16:56:08 -0700748 mLauncher.getWorkspace().onDragStopped(success);
749 mLauncher.unlockScreenOrientation();
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;
Marco Nelissen876668c2011-04-22 13:18:53 -07001048 if (w < h) {
1049 // portrait
1050 i.ScaleOffset.w = -380.25f;
1051 i.BendPos.x = 120.f; // bottom of screen
1052 i.BendPos.y = h - 82.f; // top of screen
1053 } else {
1054 // landscape
1055 i.ScaleOffset.w = -206.25f;
1056 i.BendPos.x = 50.f;
1057 i.BendPos.y = h - 30.f;
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001058 }
1059 mUniformAlloc.set(i, 0, true);
1060 }
1061
Daniel Sandler388f6792010-03-02 14:08:08 -05001062 mWidth = w;
1063 mHeight = h;
1064 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001065
Daniel Sandler388f6792010-03-02 14:08:08 -05001066 private void initProgramVertex() {
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001067 mPVA = new ProgramVertexFixedFunction.Constants(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001068 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001069
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001070 ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001071 pvb.setTextureMatrixEnable(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001072 ProgramVertex pv = pvb.create();
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001073 ((ProgramVertexFixedFunction)pv).bindConstants(mPVA);
Jason Sams4dfea092010-12-06 17:38:58 -08001074 sRS.bindProgramVertex(pv);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001075
Jason Sams14f67ed2010-05-11 14:02:43 -07001076 mUniformAlloc = new ScriptField_VpConsts(sRS, 1);
1077 mScript.bind_vpConstants(mUniformAlloc);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001078
Daniel Sandler388f6792010-03-02 14:08:08 -05001079 initMesh();
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001080 ProgramVertex.Builder sb = new ProgramVertex.Builder(sRS);
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001081 String t = "varying vec4 varColor;\n" +
Alex Sakhartchouk2f3b0b62010-10-06 09:32:12 -07001082 "varying vec2 varTex0;\n" +
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001083 "void main() {\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001084 // Animation
1085 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001086
Romain Guy060b5c82010-03-04 10:07:38 -08001087 " float bendY1 = UNI_BendPos.x;\n" +
1088 " float bendY2 = UNI_BendPos.y;\n" +
1089 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1090 " float bendDistance = bendY1 * 0.4;\n" +
1091 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001092
Romain Guy060b5c82010-03-04 10:07:38 -08001093 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1094 " float aDy = cos(bendAngle);\n" +
1095 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001096
Marco Nelissen876668c2011-04-22 13:18:53 -07001097 " float scale = (2.0 / " + mWidth + ".0);\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001098 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1099 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1100 " float y = 0.0;\n" +
1101 " float z = 0.0;\n" +
1102 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001103
Romain Guy060b5c82010-03-04 10:07:38 -08001104 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1105 " y += cv * aDy;\n" +
1106 " z += -cv * aDz;\n" +
1107 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1108 " lum += cv / bendDistance * distanceDimLevel;\n" +
1109 " y += cv * cos(cv * bendStep);\n" +
1110 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001111
Romain Guy060b5c82010-03-04 10:07:38 -08001112 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1113 " y += cv * aDy;\n" +
1114 " z += cv * aDz;\n" +
1115 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1116 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1117 " y += cv * cos(cv * bendStep);\n" +
1118 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001119
Romain Guy060b5c82010-03-04 10:07:38 -08001120 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001121
Romain Guy060b5c82010-03-04 10:07:38 -08001122 " vec4 pos;\n" +
1123 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1124 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1125 " pos.z = z * UNI_ScaleOffset.x;\n" +
1126 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001127
Romain Guy060b5c82010-03-04 10:07:38 -08001128 " pos.x *= 1.0 + ani * 4.0;\n" +
1129 " pos.y *= 1.0 + ani * 4.0;\n" +
1130 " pos.z -= ani * 1.5;\n" +
1131 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001132
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001133 " gl_Position = UNI_Proj * pos;\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001134 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1135 " varTex0.xy = ATTRIB_position;\n" +
1136 " varTex0.y = 1.0 - varTex0.y;\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001137 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001138 sb.setShader(t);
1139 sb.addConstant(mUniformAlloc.getType());
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001140 sb.addInput(mMesh.getVertexAllocation(0).getType().getElement());
Jason Sams60a55bb2010-06-18 15:11:19 -07001141 ProgramVertex pvc = sb.create();
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001142 pvc.bindConstants(mUniformAlloc.getAllocation(), 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001143
Jason Sams60a55bb2010-06-18 15:11:19 -07001144 mScript.set_gPVCurve(pvc);
Daniel Sandler388f6792010-03-02 14:08:08 -05001145 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001146
Daniel Sandler388f6792010-03-02 14:08:08 -05001147 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001148 Sampler.Builder sb = new Sampler.Builder(sRS);
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001149 sb.setMinification(Sampler.Value.LINEAR_MIP_LINEAR);
1150 sb.setMagnification(Sampler.Value.NEAREST);
Daniel Sandler388f6792010-03-02 14:08:08 -05001151 sb.setWrapS(Sampler.Value.CLAMP);
1152 sb.setWrapT(Sampler.Value.CLAMP);
1153 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001154
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001155 sb.setMinification(Sampler.Value.NEAREST);
1156 sb.setMagnification(Sampler.Value.NEAREST);
Daniel Sandler388f6792010-03-02 14:08:08 -05001157 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001158
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001159 ProgramFragmentFixedFunction.Builder bf = new ProgramFragmentFixedFunction.Builder(sRS);
1160 bf.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
1161 ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001162 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001163 ProgramFragment pfTexMip = bf.create();
1164 pfTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001165
Jason Sams070ada82010-08-04 17:53:07 -07001166 bf.setVaryingColor(false);
Jason Sams60a55bb2010-06-18 15:11:19 -07001167 ProgramFragment pfTexNearest = bf.create();
1168 pfTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001169
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001170 bf.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
1171 ProgramFragmentFixedFunction.Builder.Format.ALPHA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001172 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001173 ProgramFragment pfTexMipAlpha = bf.create();
1174 pfTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001175
Jason Sams60a55bb2010-06-18 15:11:19 -07001176 mScript.set_gPFTexNearest(pfTexNearest);
1177 mScript.set_gPFTexMip(pfTexMip);
1178 mScript.set_gPFTexMipAlpha(pfTexMipAlpha);
Daniel Sandler388f6792010-03-02 14:08:08 -05001179 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001180
Daniel Sandler388f6792010-03-02 14:08:08 -05001181 private void initProgramStore() {
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001182 ProgramStore.Builder bs = new ProgramStore.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001183 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001184 bs.setColorMaskEnabled(true,true,true,false);
1185 bs.setDitherEnabled(true);
Daniel Sandler388f6792010-03-02 14:08:08 -05001186 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1187 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Jason Sams14f67ed2010-05-11 14:02:43 -07001188 mScript.set_gPS(bs.create());
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 initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001192 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001193
Daniel Sandler388f6792010-03-02 14:08:08 -05001194 private void initData() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001195 mScript.set_COLUMNS_PER_PAGE_PORTRAIT(Defines.COLUMNS_PER_PAGE_PORTRAIT);
1196 mScript.set_ROWS_PER_PAGE_PORTRAIT(Defines.ROWS_PER_PAGE_PORTRAIT);
1197 mScript.set_COLUMNS_PER_PAGE_LANDSCAPE(Defines.COLUMNS_PER_PAGE_LANDSCAPE);
1198 mScript.set_ROWS_PER_PAGE_LANDSCAPE(Defines.ROWS_PER_PAGE_LANDSCAPE);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001199
Joe Onorato2cc62e82010-03-17 20:23:53 -07001200 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
Jason Sams735a8242010-12-14 19:24:21 -08001201 R.drawable.home_button_normal);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001202 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
Jason Sams735a8242010-12-14 19:24:21 -08001203 R.drawable.home_button_focused);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001204 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
Jason Sams735a8242010-12-14 19:24:21 -08001205 R.drawable.home_button_pressed);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001206
Jason Sams14f67ed2010-05-11 14:02:43 -07001207 mScript.set_gHomeButton(mHomeButtonNormal);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001208
Daniel Sandler388f6792010-03-02 14:08:08 -05001209 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1210 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1211 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001212
Daniel Sandler388f6792010-03-02 14:08:08 -05001213 setApps(null);
1214 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001215
Daniel Sandler388f6792010-03-02 14:08:08 -05001216 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001217 if (sZoomDirty) {
1218 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001219 }
1220 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001221
Romain Guy060b5c82010-03-04 10:07:38 -08001222 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001223 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001224 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001225 final int count = list != null ? list.size() : 0;
1226 int allocCount = count;
1227 if (allocCount < 1) {
1228 allocCount = 1;
1229 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001230
Daniel Sandler388f6792010-03-02 14:08:08 -05001231 mIcons = new Allocation[count];
Jason Sams4dfea092010-12-06 17:38:58 -08001232 mAllocIcons = Allocation.createSized(sRS, Element.ALLOCATION(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001233
Daniel Sandler388f6792010-03-02 14:08:08 -05001234 mLabels = new Allocation[count];
Jason Sams4dfea092010-12-06 17:38:58 -08001235 mAllocLabels = Allocation.createSized(sRS, Element.ALLOCATION(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001236
Jason Sams14f67ed2010-05-11 14:02:43 -07001237 mScript.set_gIconCount(count);
1238 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001239 createAppIconAllocations(i, list.get(i));
1240 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001241 saveAppsList();
Jason Sams14f67ed2010-05-11 14:02:43 -07001242 android.util.Log.e("rs", "setApps");
Joe Onorato2cc62e82010-03-17 20:23:53 -07001243 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001244 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001245
Daniel Sandler388f6792010-03-02 14:08:08 -05001246 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001247 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001248 sRollo.clearSelectedIcon();
1249 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001250 }
Jason Sams60a55bb2010-06-18 15:11:19 -07001251 sRollo.mScript.invoke_setZoom(zoom, animate ? 1 : 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001252 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001253
Daniel Sandler388f6792010-03-02 14:08:08 -05001254 private void createAppIconAllocations(int index, ApplicationInfo item) {
Jason Sams95d2d2d2010-12-16 12:19:04 -08001255 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1256 Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
1257 Allocation.USAGE_GRAPHICS_TEXTURE);
1258 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1259 Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
1260 Allocation.USAGE_GRAPHICS_TEXTURE);
Daniel Sandler388f6792010-03-02 14:08:08 -05001261 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001262
Daniel Sandler388f6792010-03-02 14:08:08 -05001263 /**
1264 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1265 * fill in the values and call saveAppsList().
1266 */
1267 private void reallocAppsList(int count) {
1268 Allocation[] icons = new Allocation[count];
Jason Sams4dfea092010-12-06 17:38:58 -08001269 mAllocIcons = Allocation.createSized(sRS, Element.ALLOCATION(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001270
Daniel Sandler388f6792010-03-02 14:08:08 -05001271 Allocation[] labels = new Allocation[count];
Jason Sams4dfea092010-12-06 17:38:58 -08001272 mAllocLabels = Allocation.createSized(sRS, Element.ALLOCATION(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001273
Jason Sams14f67ed2010-05-11 14:02:43 -07001274 final int oldCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001275
Daniel Sandler388f6792010-03-02 14:08:08 -05001276 System.arraycopy(mIcons, 0, icons, 0, oldCount);
Daniel Sandler388f6792010-03-02 14:08:08 -05001277 System.arraycopy(mLabels, 0, labels, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001278
Daniel Sandler388f6792010-03-02 14:08:08 -05001279 mIcons = icons;
Daniel Sandler388f6792010-03-02 14:08:08 -05001280 mLabels = labels;
Daniel Sandler388f6792010-03-02 14:08:08 -05001281 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001282
Daniel Sandler388f6792010-03-02 14:08:08 -05001283 /**
1284 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1285 */
1286 private void addApp(int index, ApplicationInfo item) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001287 final int count = mScript.get_gIconCount() - index;
Daniel Sandler388f6792010-03-02 14:08:08 -05001288 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001289
Daniel Sandler388f6792010-03-02 14:08:08 -05001290 System.arraycopy(mIcons, index, mIcons, dest, count);
Daniel Sandler388f6792010-03-02 14:08:08 -05001291 System.arraycopy(mLabels, index, mLabels, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001292
Daniel Sandler388f6792010-03-02 14:08:08 -05001293 createAppIconAllocations(index, item);
Jason Sams14f67ed2010-05-11 14:02:43 -07001294
1295 mScript.set_gIconCount(mScript.get_gIconCount() + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001296 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001297
Daniel Sandler388f6792010-03-02 14:08:08 -05001298 /**
1299 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1300 */
1301 private void removeApp(int index) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001302 final int count = mScript.get_gIconCount() - index - 1;
Daniel Sandler388f6792010-03-02 14:08:08 -05001303 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001304
Daniel Sandler388f6792010-03-02 14:08:08 -05001305 System.arraycopy(mIcons, src, mIcons, index, count);
Daniel Sandler388f6792010-03-02 14:08:08 -05001306 System.arraycopy(mLabels, src, mLabels, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001307
Jason Sams14f67ed2010-05-11 14:02:43 -07001308 mScript.set_gIconCount(mScript.get_gIconCount() - 1);
1309 final int last = mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001310
Daniel Sandler388f6792010-03-02 14:08:08 -05001311 mIcons[last] = null;
Daniel Sandler388f6792010-03-02 14:08:08 -05001312 mLabels[last] = null;
Daniel Sandler388f6792010-03-02 14:08:08 -05001313 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001314
Daniel Sandler388f6792010-03-02 14:08:08 -05001315 /**
1316 * Send the apps list structures to RS.
1317 */
1318 private void saveAppsList() {
1319 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
Jason Sams4dfea092010-12-06 17:38:58 -08001320 if (mScript != null && mAllocIcons != null) {
1321 if (mIcons.length > 0) {
1322 mAllocIcons.copyFrom(mIcons);
1323 mAllocLabels.copyFrom(mLabels);
1324 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001325
Jason Sams4dfea092010-12-06 17:38:58 -08001326 mScript.bind_gIcons(mAllocIcons);
1327 mScript.bind_gLabels(mAllocLabels);
Daniel Sandler388f6792010-03-02 14:08:08 -05001328 }
1329 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001330
Jason Sams60a55bb2010-06-18 15:11:19 -07001331 void fling(float pos, float v) {
1332 mScript.invoke_fling(pos, v);
Daniel Sandler388f6792010-03-02 14:08:08 -05001333 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001334
Jason Sams60a55bb2010-06-18 15:11:19 -07001335 void move(float pos) {
1336 mScript.invoke_move(pos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001337 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001338
Daniel Sandler388f6792010-03-02 14:08:08 -05001339 void moveTo(float row) {
Jason Sams60a55bb2010-06-18 15:11:19 -07001340 mScript.invoke_moveTo(row);
Daniel Sandler388f6792010-03-02 14:08:08 -05001341 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001342
Daniel Sandler388f6792010-03-02 14:08:08 -05001343 /**
1344 * You need to call save() on mState on your own after calling this.
1345 *
1346 * @return the index of the icon that was selected.
1347 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001348 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001349 if (mAllApps != null) {
1350 final int index = mAllApps.chooseTappedIcon(x, y);
1351 selectIcon(index, pressed);
1352 return index;
1353 } else {
1354 return -1;
1355 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001356 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001357
Daniel Sandler388f6792010-03-02 14:08:08 -05001358 /**
1359 * Select the icon at the given index.
1360 *
1361 * @param index The index.
1362 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1363 */
1364 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001365 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1366 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001367 if (mAllApps != null) {
1368 mAllApps.mRestoreFocusIndex = index;
1369 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001370 mScript.set_gSelectedIconIndex(-1);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001371 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1372 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001373 }
1374 } else {
1375 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001376 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001377 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001378
Jason Sams14f67ed2010-05-11 14:02:43 -07001379 int prev = mScript.get_gSelectedIconIndex();
1380 mScript.set_gSelectedIconIndex(index);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001381
Romain Guy13c2e7b2010-03-10 19:45:00 -08001382 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001383 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001384
Daniel Sandler388f6792010-03-02 14:08:08 -05001385 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1386 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1387 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001388
Jason Sams735a8242010-12-14 19:24:21 -08001389 Allocation si = Allocation.createFromBitmap(sRS, selectionBitmap);
Jason Sams60a55bb2010-06-18 15:11:19 -07001390 mScript.set_gSelectedIconTexture(si);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001391
Daniel Sandler388f6792010-03-02 14:08:08 -05001392 if (prev != index) {
1393 if (info.title != null && info.title.length() > 0) {
1394 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001395 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001396 }
1397 }
1398 }
1399 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001400
Daniel Sandler388f6792010-03-02 14:08:08 -05001401 /**
1402 * You need to call save() on mState on your own after calling this.
1403 */
1404 void clearSelectedIcon() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001405 mScript.set_gSelectedIconIndex(-1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001406 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001407
Daniel Sandler388f6792010-03-02 14:08:08 -05001408 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001409 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001410 switch (mode) {
1411 case SELECTED_NONE:
Jason Sams14f67ed2010-05-11 14:02:43 -07001412 mScript.set_gHomeButton(mHomeButtonNormal);
Daniel Sandler388f6792010-03-02 14:08:08 -05001413 break;
1414 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001415 mAllApps.mLastSelection = SELECTION_HOME;
Jason Sams14f67ed2010-05-11 14:02:43 -07001416 mScript.set_gHomeButton(mHomeButtonFocused);
Daniel Sandler388f6792010-03-02 14:08:08 -05001417 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001418 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001419 }
1420 break;
1421 case SELECTED_PRESSED:
Jason Sams14f67ed2010-05-11 14:02:43 -07001422 mScript.set_gHomeButton(mHomeButtonPressed);
Daniel Sandler388f6792010-03-02 14:08:08 -05001423 break;
1424 }
1425 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001426
Daniel Sandler388f6792010-03-02 14:08:08 -05001427 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001428 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1429 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1430 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001431 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001432 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001433 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001434 //Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1435 //Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1436 //Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1437 //Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1438 //Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1439 //Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1440 //Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1441 //Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1442 //Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001443 }
1444 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001445
Daniel Sandler388f6792010-03-02 14:08:08 -05001446 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001447 Log.d(TAG, "sRS=" + sRS);
1448 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001449 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001450 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1451 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001452 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1453 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1454 Log.d(TAG, "mLastSelection=" + mLastSelection);
1455 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1456 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1457 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1458 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001459 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1460 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001461 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001462 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001463 Log.d(TAG, "mVelocity=" + mVelocity);
1464 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001465 if (sRollo != null) {
1466 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001467 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001468 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -08001469 sRS.contextDump();
Daniel Sandler388f6792010-03-02 14:08:08 -05001470 }
1471 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001472
1473 public void reset() {
1474 // Do nothing
1475 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001476}