blob: 837ddbbabb5fdf343693bc809ba5a69d6e5c3fe7 [file] [log] [blame]
Daniel Sandler388f6792010-03-02 14:08:08 -05001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher2;
18
19import android.content.ComponentName;
20import android.content.Context;
21import android.content.res.Resources;
22import android.graphics.Bitmap;
23import android.graphics.Canvas;
24import android.graphics.PixelFormat;
25import android.graphics.Rect;
Adam Cohenc0dcf592011-06-01 15:30:43 -070026import android.renderscript.Allocation;
27import android.renderscript.Element;
28import android.renderscript.Matrix4f;
29import android.renderscript.Mesh;
30import android.renderscript.ProgramFragment;
31import android.renderscript.ProgramFragmentFixedFunction;
32import android.renderscript.ProgramStore;
33import android.renderscript.ProgramVertex;
34import android.renderscript.ProgramVertexFixedFunction;
35import android.renderscript.RSSurfaceView;
36import android.renderscript.RenderScript;
37import android.renderscript.RenderScriptGL;
38import android.renderscript.Sampler;
Daniel Sandler388f6792010-03-02 14:08:08 -050039import android.util.AttributeSet;
40import android.util.Log;
41import android.view.KeyEvent;
42import android.view.MotionEvent;
43import android.view.SoundEffectConstants;
44import android.view.SurfaceHolder;
45import android.view.VelocityTracker;
46import android.view.View;
47import android.view.ViewConfiguration;
48import android.view.accessibility.AccessibilityEvent;
49
Adam Cohenc0dcf592011-06-01 15:30:43 -070050import com.android.launcher.R;
51import com.android.launcher2.DropTarget.DragObject;
52
53import java.util.ArrayList;
54import java.util.Arrays;
55import java.util.Collections;
56
Daniel Sandler388f6792010-03-02 14:08:08 -050057public class AllApps3D extends RSSurfaceView
58 implements AllAppsView, View.OnClickListener, View.OnLongClickListener, DragSource {
59 private static final String TAG = "Launcher.AllApps3D";
60
61 /** Bit for mLocks for when there are icons being loaded. */
62 private static final int LOCK_ICONS_PENDING = 1;
63
64 private static final int TRACKING_NONE = 0;
65 private static final int TRACKING_FLING = 1;
66 private static final int TRACKING_HOME = 2;
67
68 private static final int SELECTED_NONE = 0;
69 private static final int SELECTED_FOCUSED = 1;
70 private static final int SELECTED_PRESSED = 2;
71
72 private static final int SELECTION_NONE = 0;
73 private static final int SELECTION_ICONS = 1;
74 private static final int SELECTION_HOME = 2;
75
76 private Launcher mLauncher;
77 private DragController mDragController;
78
79 /** When this is 0, modifications are allowed, when it's not, they're not.
80 * TODO: What about scrolling? */
81 private int mLocks = LOCK_ICONS_PENDING;
82
83 private int mSlop;
84 private int mMaxFlingVelocity;
85
86 private Defines mDefines = new Defines();
Daniel Sandler388f6792010-03-02 14:08:08 -050087 private ArrayList<ApplicationInfo> mAllAppsList;
88
Joe Onorato2cc62e82010-03-17 20:23:53 -070089 private static RenderScriptGL sRS;
90 private static RolloRS sRollo;
Jason Samsdd8cd8b2010-03-11 12:38:48 -080091
Joe Onoratoeffc4a82010-04-15 11:48:13 -070092 private static boolean sZoomDirty = false;
93 private static boolean sAnimateNextZoom;
94 private static float sNextZoom;
95
Daniel Sandler388f6792010-03-02 14:08:08 -050096 /**
97 * True when we are using arrow keys or trackball to drive navigation
98 */
99 private boolean mArrowNavigation = false;
100 private boolean mStartedScrolling;
101
102 /**
103 * Used to keep track of the selection when AllAppsView loses window focus.
104 * One of the SELECTION_ constants.
105 */
106 private int mLastSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800107
Daniel Sandler388f6792010-03-02 14:08:08 -0500108 /**
109 * Used to keep track of the selection when AllAppsView loses window focus
110 */
111 private int mLastSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800112
Daniel Sandler388f6792010-03-02 14:08:08 -0500113 private VelocityTracker mVelocityTracker;
114 private int mTouchTracking;
115 private int mMotionDownRawX;
116 private int mMotionDownRawY;
117 private int mDownIconIndex = -1;
118 private int mCurrentIconIndex = -1;
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700119 private int[] mTouchYBorders;
120 private int[] mTouchXBorders;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800121
Daniel Sandler388f6792010-03-02 14:08:08 -0500122 private boolean mShouldGainFocus;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800123
Daniel Sandler388f6792010-03-02 14:08:08 -0500124 private boolean mHaveSurface = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500125 private float mZoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500126 private float mVelocity;
127 private AAMessage mMessageProc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800128
Romain Guy060b5c82010-03-04 10:07:38 -0800129 private int mColumnsPerPage;
130 private int mRowsPerPage;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800131 private boolean mSurrendered;
132
Romain Guyc16fea72010-03-12 17:17:56 -0800133 private int mRestoreFocusIndex = -1;
Jason Sams14f67ed2010-05-11 14:02:43 -0700134
Romain Guy060b5c82010-03-04 10:07:38 -0800135 @SuppressWarnings({"UnusedDeclaration"})
Daniel Sandler388f6792010-03-02 14:08:08 -0500136 static class Defines {
Romain Guy060b5c82010-03-04 10:07:38 -0800137 public static final int COLUMNS_PER_PAGE_PORTRAIT = 4;
138 public static final int ROWS_PER_PAGE_PORTRAIT = 4;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800139
Romain Guy060b5c82010-03-04 10:07:38 -0800140 public static final int COLUMNS_PER_PAGE_LANDSCAPE = 6;
141 public static final int ROWS_PER_PAGE_LANDSCAPE = 3;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800142
Daniel Sandler388f6792010-03-02 14:08:08 -0500143 public static final int SELECTION_TEXTURE_WIDTH_PX = 74 + 20;
Daniel Sandler388f6792010-03-02 14:08:08 -0500144 public static final int SELECTION_TEXTURE_HEIGHT_PX = 74 + 20;
145 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800146
Daniel Sandler388f6792010-03-02 14:08:08 -0500147 public AllApps3D(Context context, AttributeSet attrs) {
148 super(context, attrs);
149 setFocusable(true);
150 setSoundEffectsEnabled(false);
Daniel Sandler388f6792010-03-02 14:08:08 -0500151 final ViewConfiguration config = ViewConfiguration.get(context);
152 mSlop = config.getScaledTouchSlop();
153 mMaxFlingVelocity = config.getScaledMaximumFlingVelocity();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800154
Daniel Sandler388f6792010-03-02 14:08:08 -0500155 setOnClickListener(this);
156 setOnLongClickListener(this);
157 setZOrderOnTop(true);
158 getHolder().setFormat(PixelFormat.TRANSLUCENT);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800159
Joe Onorato2cc62e82010-03-17 20:23:53 -0700160 if (sRS == null) {
Jason Samse5806ba2010-10-10 13:07:24 -0700161 RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
162 sc.setDepth(16, 16);
163 sc.setAlpha(8, 8);
Jason Sams4dfea092010-12-06 17:38:58 -0800164 sRS = createRenderScriptGL(sc);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800165 } else {
Jason Sams4dfea092010-12-06 17:38:58 -0800166 // Is this even possible?
167 setRenderScriptGL(sRS);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800168 }
169
Joe Onorato2cc62e82010-03-17 20:23:53 -0700170 if (sRollo != null) {
171 sRollo.mAllApps = this;
172 sRollo.mRes = getResources();
173 sRollo.mInitialize = true;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800174 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500175 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800176
Romain Guy060b5c82010-03-04 10:07:38 -0800177 @SuppressWarnings({"UnusedDeclaration"})
178 public AllApps3D(Context context, AttributeSet attrs, int defStyle) {
179 this(context, attrs);
180 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800181
Romain Guy13c2e7b2010-03-10 19:45:00 -0800182 public void surrender() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400183 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -0800184 sRS.setSurface(null, 0, 0);
185 sRS.setMessageHandler(null);
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400186 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800187 mSurrendered = true;
188 }
189
Daniel Sandler388f6792010-03-02 14:08:08 -0500190 /**
191 * Note that this implementation prohibits this view from ever being reattached.
192 */
193 @Override
194 protected void onDetachedFromWindow() {
Jason Sams4dfea092010-12-06 17:38:58 -0800195 sRS.setMessageHandler(null);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800196 if (!mSurrendered) {
Joe Onorato96da4012010-03-17 20:03:24 -0700197 Log.i(TAG, "onDetachedFromWindow");
Jason Sams4dfea092010-12-06 17:38:58 -0800198 destroyRenderScriptGL();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700199 sRS = null;
200 sRollo = null;
thigobr1f43a312010-10-22 18:13:26 -0200201 super.onDetachedFromWindow();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800202 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500203 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800204
Daniel Sandler388f6792010-03-02 14:08:08 -0500205 /**
206 * If you have an attached click listener, View always plays the click sound!?!?
207 * Deal with sound effects by hand.
208 */
209 public void reallyPlaySoundEffect(int sound) {
210 boolean old = isSoundEffectsEnabled();
211 setSoundEffectsEnabled(true);
212 playSoundEffect(sound);
213 setSoundEffectsEnabled(old);
214 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800215
Winson Chung785d2eb2011-04-14 16:08:02 -0700216 @Override
217 public void setup(Launcher launcher, DragController dragController) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500218 mLauncher = launcher;
Winson Chung785d2eb2011-04-14 16:08:02 -0700219 mDragController = dragController;
Daniel Sandler388f6792010-03-02 14:08:08 -0500220 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800221
Daniel Sandler388f6792010-03-02 14:08:08 -0500222 @Override
223 public void surfaceDestroyed(SurfaceHolder holder) {
224 super.surfaceDestroyed(holder);
225 // Without this, we leak mMessageCallback which leaks the context.
Romain Guy13c2e7b2010-03-10 19:45:00 -0800226 if (!mSurrendered) {
Jason Sams4dfea092010-12-06 17:38:58 -0800227 sRS.setMessageHandler(null);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800228 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500229 // We may lose any callbacks that are pending, so make sure that we re-sync that
230 // on the next surfaceChanged.
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700231 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500232 mHaveSurface = false;
233 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800234
Daniel Sandler388f6792010-03-02 14:08:08 -0500235 @Override
236 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
237 //long startTime = SystemClock.uptimeMillis();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800238
Daniel Sandler388f6792010-03-02 14:08:08 -0500239 super.surfaceChanged(holder, format, w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800240
Marco Nelissen876668c2011-04-22 13:18:53 -0700241 final boolean isPortrait = w < h;
242 mColumnsPerPage = isPortrait ? Defines.COLUMNS_PER_PAGE_PORTRAIT :
243 Defines.COLUMNS_PER_PAGE_LANDSCAPE;
244 mRowsPerPage = isPortrait ? Defines.ROWS_PER_PAGE_PORTRAIT :
245 Defines.ROWS_PER_PAGE_LANDSCAPE;
246
Romain Guy13c2e7b2010-03-10 19:45:00 -0800247 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800248
Daniel Sandler388f6792010-03-02 14:08:08 -0500249 mHaveSurface = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800250
Joe Onorato2cc62e82010-03-17 20:23:53 -0700251 if (sRollo == null) {
252 sRollo = new RolloRS(this);
253 sRollo.init(getResources(), w, h);
Daniel Sandler388f6792010-03-02 14:08:08 -0500254 if (mAllAppsList != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700255 sRollo.setApps(mAllAppsList);
Daniel Sandler388f6792010-03-02 14:08:08 -0500256 }
257 if (mShouldGainFocus) {
258 gainFocus();
259 mShouldGainFocus = false;
260 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700261 } else if (sRollo.mInitialize) {
262 sRollo.initGl();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700263 sRollo.mInitialize = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500264 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800265
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700266 initTouchState(w, h);
267
Joe Onorato2cc62e82010-03-17 20:23:53 -0700268 sRollo.dirtyCheck();
269 sRollo.resize(w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800270
Jason Sams14f67ed2010-05-11 14:02:43 -0700271 Log.d(TAG, "sc " + sRS);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700272 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -0800273 mMessageProc = new AAMessage();
274 sRS.setMessageHandler(mMessageProc);
Daniel Sandler388f6792010-03-02 14:08:08 -0500275 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800276
Daniel Sandler388f6792010-03-02 14:08:08 -0500277 //long endTime = SystemClock.uptimeMillis();
278 //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
279 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800280
Daniel Sandler388f6792010-03-02 14:08:08 -0500281 @Override
282 public void onWindowFocusChanged(boolean hasWindowFocus) {
283 super.onWindowFocusChanged(hasWindowFocus);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800284
285 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800286
Daniel Sandler388f6792010-03-02 14:08:08 -0500287 if (mArrowNavigation) {
288 if (!hasWindowFocus) {
289 // Clear selection when we lose window focus
Jason Sams14f67ed2010-05-11 14:02:43 -0700290 mLastSelectedIcon = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700291 sRollo.setHomeSelected(SELECTED_NONE);
292 sRollo.clearSelectedIcon();
Romain Guy060b5c82010-03-04 10:07:38 -0800293 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700294 if (sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500295 if (mLastSelection == SELECTION_ICONS) {
296 int selection = mLastSelectedIcon;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700297 final int firstIcon = Math.round(sRollo.mScrollPos) * mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500298 if (selection < 0 || // No selection
299 selection < firstIcon || // off the top of the screen
Jason Sams14f67ed2010-05-11 14:02:43 -0700300 selection >= sRollo.mScript.get_gIconCount() || // past last icon
Daniel Sandler388f6792010-03-02 14:08:08 -0500301 selection >= firstIcon + // past last icon on screen
Romain Guy060b5c82010-03-04 10:07:38 -0800302 (mColumnsPerPage * mRowsPerPage)) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500303 selection = firstIcon;
304 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800305
Daniel Sandler388f6792010-03-02 14:08:08 -0500306 // Select the first icon when we gain window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700307 sRollo.selectIcon(selection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500308 } else if (mLastSelection == SELECTION_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700309 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500310 }
311 }
312 }
313 }
314 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800315
Daniel Sandler388f6792010-03-02 14:08:08 -0500316 @Override
317 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
318 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800319
Romain Guy13c2e7b2010-03-10 19:45:00 -0800320 if (!isVisible() || mSurrendered) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500321 return;
322 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800323
Daniel Sandler388f6792010-03-02 14:08:08 -0500324 if (gainFocus) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700325 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500326 gainFocus();
327 } else {
328 mShouldGainFocus = true;
329 }
330 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700331 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500332 if (mArrowNavigation) {
333 // Clear selection when we lose focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700334 sRollo.clearSelectedIcon();
335 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500336 mArrowNavigation = false;
337 }
338 } else {
339 mShouldGainFocus = false;
340 }
341 }
342 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800343
Daniel Sandler388f6792010-03-02 14:08:08 -0500344 private void gainFocus() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700345 if (!mArrowNavigation && sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500346 // Select the first icon when we gain keyboard focus
347 mArrowNavigation = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700348 sRollo.selectIcon(Math.round(sRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500349 }
350 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800351
Daniel Sandler388f6792010-03-02 14:08:08 -0500352 @Override
353 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800354
Daniel Sandler388f6792010-03-02 14:08:08 -0500355 boolean handled = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800356
Daniel Sandler388f6792010-03-02 14:08:08 -0500357 if (!isVisible()) {
358 return false;
359 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700360 final int iconCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800361
Daniel Sandler388f6792010-03-02 14:08:08 -0500362 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
363 if (mArrowNavigation) {
364 if (mLastSelection == SELECTION_HOME) {
365 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
Winson Chung097eb0a2011-03-18 16:56:08 -0700366 mLauncher.showWorkspace(true);
Daniel Sandler388f6792010-03-02 14:08:08 -0500367 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700368 int whichApp = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500369 if (whichApp >= 0) {
370 ApplicationInfo app = mAllAppsList.get(whichApp);
Joe Onoratof984e852010-03-25 09:47:45 -0700371 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500372 handled = true;
373 }
374 }
375 }
376 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800377
Daniel Sandler388f6792010-03-02 14:08:08 -0500378 if (iconCount > 0) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800379 final boolean isPortrait = getWidth() < getHeight();
Jason Sams14f67ed2010-05-11 14:02:43 -0700380
Daniel Sandler388f6792010-03-02 14:08:08 -0500381 mArrowNavigation = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800382
Jason Sams14f67ed2010-05-11 14:02:43 -0700383 int currentSelection = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700384 int currentTopRow = Math.round(sRollo.mScrollPos);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800385
Romain Guy060b5c82010-03-04 10:07:38 -0800386 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1
387 final int currentPageCol = currentSelection % mColumnsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800388
Romain Guy060b5c82010-03-04 10:07:38 -0800389 // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1
Romain Guy6a42cf32010-03-12 16:03:52 -0800390 final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage))
Romain Guy060b5c82010-03-04 10:07:38 -0800391 / mRowsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800392
Daniel Sandler388f6792010-03-02 14:08:08 -0500393 int newSelection = currentSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800394
Daniel Sandler388f6792010-03-02 14:08:08 -0500395 switch (keyCode) {
396 case KeyEvent.KEYCODE_DPAD_UP:
397 if (mLastSelection == SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800398 if (isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700399 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guy6a42cf32010-03-12 16:03:52 -0800400 int lastRowCount = iconCount % mColumnsPerPage;
401 if (lastRowCount == 0) {
402 lastRowCount = mColumnsPerPage;
403 }
404 newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2);
405 if (newSelection >= iconCount) {
406 newSelection = iconCount-1;
407 }
408 int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
409 if (target < 0) {
410 target = 0;
411 }
412 if (currentTopRow != target) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700413 sRollo.moveTo(target);
Romain Guy6a42cf32010-03-12 16:03:52 -0800414 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500415 }
416 } else {
417 if (currentPageRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800418 newSelection = currentSelection - mColumnsPerPage;
Romain Guy6a42cf32010-03-12 16:03:52 -0800419 if (currentTopRow > newSelection / mColumnsPerPage) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700420 sRollo.moveTo(newSelection / mColumnsPerPage);
Romain Guy6a42cf32010-03-12 16:03:52 -0800421 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500422 } else if (currentTopRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800423 newSelection = currentSelection - mColumnsPerPage;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700424 sRollo.moveTo(newSelection / mColumnsPerPage);
Daniel Sandler388f6792010-03-02 14:08:08 -0500425 } else if (currentPageRow != 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800426 newSelection = currentTopRow * mRowsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500427 }
428 }
429 handled = true;
430 break;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800431
Daniel Sandler388f6792010-03-02 14:08:08 -0500432 case KeyEvent.KEYCODE_DPAD_DOWN: {
Romain Guy060b5c82010-03-04 10:07:38 -0800433 final int rowCount = iconCount / mColumnsPerPage
434 + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
435 final int currentRow = currentSelection / mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500436 if (mLastSelection != SELECTION_HOME) {
437 if (currentRow < rowCount-1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700438 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500439 if (currentSelection < 0) {
440 newSelection = 0;
441 } else {
Romain Guy060b5c82010-03-04 10:07:38 -0800442 newSelection = currentSelection + mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500443 }
444 if (newSelection >= iconCount) {
445 // Go from D to G in this arrangement:
446 // A B C D
447 // E F G
448 newSelection = iconCount - 1;
449 }
Romain Guy060b5c82010-03-04 10:07:38 -0800450 if (currentPageRow >= mRowsPerPage - 1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700451 sRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -0500452 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800453 } else if (isPortrait) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500454 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700455 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500456 }
457 }
458 handled = true;
459 break;
460 }
461 case KeyEvent.KEYCODE_DPAD_LEFT:
462 if (mLastSelection != SELECTION_HOME) {
463 if (currentPageCol > 0) {
464 newSelection = currentSelection - 1;
465 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800466 } else if (!isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700467 newSelection = ((int) (sRollo.mScrollPos) * mColumnsPerPage) +
Romain Guy6a42cf32010-03-12 16:03:52 -0800468 (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700469 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500470 }
471 handled = true;
472 break;
473 case KeyEvent.KEYCODE_DPAD_RIGHT:
474 if (mLastSelection != SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800475 if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 ||
476 currentSelection == iconCount - 1)) {
477 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700478 sRollo.setHomeSelected(SELECTED_FOCUSED);
Romain Guy6a42cf32010-03-12 16:03:52 -0800479 } else if ((currentPageCol < mColumnsPerPage - 1) &&
Daniel Sandler388f6792010-03-02 14:08:08 -0500480 (currentSelection < iconCount - 1)) {
481 newSelection = currentSelection + 1;
482 }
483 }
484 handled = true;
485 break;
486 }
487 if (newSelection != currentSelection) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700488 sRollo.selectIcon(newSelection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500489 }
490 }
491 return handled;
492 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800493
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700494 void initTouchState(int width, int height) {
495 boolean isPortrait = width < height;
496
497 int[] viewPos = new int[2];
498 getLocationOnScreen(viewPos);
499
500 mTouchXBorders = new int[mColumnsPerPage + 1];
501 mTouchYBorders = new int[mRowsPerPage + 1];
502
503 // TODO: Put this in a config file/define
504 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE_PORTRAIT;
505 if (!isPortrait) cellHeight -= 12;
506 int centerY = (int) (height * (isPortrait ? 0.5f : 0.47f));
507 if (!isPortrait) centerY += cellHeight / 2;
508 int half = (int) Math.floor((mRowsPerPage + 1) / 2);
509 int end = mTouchYBorders.length - (half + 1);
510
511 for (int i = -half; i <= end; i++) {
512 mTouchYBorders[i + half] = centerY + (i * cellHeight) - viewPos[1];
513 }
514
515 int x = 0;
516 // TODO: Put this in a config file/define
517 int columnWidth = 120;
518 for (int i = 0; i < mColumnsPerPage + 1; i++) {
519 mTouchXBorders[i] = x - viewPos[0];
520 x += columnWidth;
521 }
522 }
523
524 int chooseTappedIcon(int x, int y) {
525 float pos = sRollo != null ? sRollo.mScrollPos : 0;
526
527 int oldY = y;
528
529 // Adjust for scroll position if not zero.
530 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
531
532 int col = -1;
533 int row = -1;
534 final int columnsCount = mColumnsPerPage;
535 for (int i=0; i< columnsCount; i++) {
536 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
537 col = i;
538 break;
539 }
540 }
541 final int rowsCount = mRowsPerPage;
542 for (int i=0; i< rowsCount; i++) {
543 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
544 row = i;
545 break;
546 }
547 }
548
549 if (row < 0 || col < 0) {
550 return -1;
551 }
552
553 int index = (((int) pos) * columnsCount) + (row * columnsCount) + col;
554
555 if (index >= mAllAppsList.size()) {
556 return -1;
557 } else {
558 return index;
559 }
560 }
561
Daniel Sandler388f6792010-03-02 14:08:08 -0500562 @Override
563 public boolean onTouchEvent(MotionEvent ev)
564 {
565 mArrowNavigation = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800566
Daniel Sandler388f6792010-03-02 14:08:08 -0500567 if (!isVisible()) {
568 return true;
569 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800570
Daniel Sandler388f6792010-03-02 14:08:08 -0500571 if (mLocks != 0) {
572 return true;
573 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800574
Daniel Sandler388f6792010-03-02 14:08:08 -0500575 super.onTouchEvent(ev);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800576
Daniel Sandler388f6792010-03-02 14:08:08 -0500577 int x = (int)ev.getX();
578 int y = (int)ev.getY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800579
Romain Guyce115852010-03-04 12:15:37 -0800580 final boolean isPortrait = getWidth() < getHeight();
Daniel Sandler388f6792010-03-02 14:08:08 -0500581 int action = ev.getAction();
582 switch (action) {
583 case MotionEvent.ACTION_DOWN:
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700584 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
585 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500586 mTouchTracking = TRACKING_HOME;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700587 sRollo.setHomeSelected(SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500588 mCurrentIconIndex = -1;
589 } else {
590 mTouchTracking = TRACKING_FLING;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800591
Daniel Sandler388f6792010-03-02 14:08:08 -0500592 mMotionDownRawX = (int)ev.getRawX();
593 mMotionDownRawY = (int)ev.getRawY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800594
Joe Onorato2cc62e82010-03-17 20:23:53 -0700595 if (!sRollo.checkClickOK()) {
596 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500597 } else {
598 mDownIconIndex = mCurrentIconIndex
Joe Onorato2cc62e82010-03-17 20:23:53 -0700599 = sRollo.selectIcon(x, y, SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500600 if (mDownIconIndex < 0) {
601 // if nothing was selected, no long press.
602 cancelLongPress();
603 }
604 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700605 sRollo.move(ev.getRawY() / getHeight());
Daniel Sandler388f6792010-03-02 14:08:08 -0500606 mVelocityTracker = VelocityTracker.obtain();
607 mVelocityTracker.addMovement(ev);
608 mStartedScrolling = false;
609 }
610 break;
611 case MotionEvent.ACTION_MOVE:
612 case MotionEvent.ACTION_OUTSIDE:
613 if (mTouchTracking == TRACKING_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700614 sRollo.setHomeSelected((isPortrait &&
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700615 y > mTouchYBorders[mTouchYBorders.length-1]) || (!isPortrait
616 && x > mTouchXBorders[mTouchXBorders.length-1])
Daniel Sandler388f6792010-03-02 14:08:08 -0500617 ? SELECTED_PRESSED : SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500618 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500619 int rawY = (int)ev.getRawY();
620 int slop;
621 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800622
Daniel Sandler388f6792010-03-02 14:08:08 -0500623 if (!mStartedScrolling && slop < mSlop) {
624 // don't update anything so when we do start scrolling
625 // below, we get the right delta.
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700626 mCurrentIconIndex = chooseTappedIcon(x, y);
Daniel Sandler388f6792010-03-02 14:08:08 -0500627 if (mDownIconIndex != mCurrentIconIndex) {
628 // If a different icon is selected, don't allow it to be picked up.
629 // This handles off-axis dragging.
630 cancelLongPress();
631 mCurrentIconIndex = -1;
632 }
633 } else {
634 if (!mStartedScrolling) {
635 cancelLongPress();
636 mCurrentIconIndex = -1;
637 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700638 sRollo.move(ev.getRawY() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800639
Daniel Sandler388f6792010-03-02 14:08:08 -0500640 mStartedScrolling = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700641 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500642 mVelocityTracker.addMovement(ev);
Daniel Sandler388f6792010-03-02 14:08:08 -0500643 }
644 }
645 break;
646 case MotionEvent.ACTION_UP:
647 case MotionEvent.ACTION_CANCEL:
648 if (mTouchTracking == TRACKING_HOME) {
649 if (action == MotionEvent.ACTION_UP) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700650 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
651 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500652 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
Winson Chung097eb0a2011-03-18 16:56:08 -0700653 mLauncher.showWorkspace(true);
Daniel Sandler388f6792010-03-02 14:08:08 -0500654 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700655 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500656 }
657 mCurrentIconIndex = -1;
658 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500659 mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700660 sRollo.clearSelectedIcon();
Jason Sams60a55bb2010-06-18 15:11:19 -0700661 sRollo.fling(ev.getRawY() / getHeight(),
662 mVelocityTracker.getYVelocity() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800663
Daniel Sandler388f6792010-03-02 14:08:08 -0500664 if (mVelocityTracker != null) {
665 mVelocityTracker.recycle();
666 mVelocityTracker = null;
667 }
668 }
669 mTouchTracking = TRACKING_NONE;
670 break;
671 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800672
Daniel Sandler388f6792010-03-02 14:08:08 -0500673 return true;
674 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800675
Daniel Sandler388f6792010-03-02 14:08:08 -0500676 public void onClick(View v) {
677 if (mLocks != 0 || !isVisible()) {
678 return;
679 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700680 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500681 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
682 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
683 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onoratof984e852010-03-25 09:47:45 -0700684 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500685 }
686 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800687
Daniel Sandler388f6792010-03-02 14:08:08 -0500688 public boolean onLongClick(View v) {
Joe Onorato6b4adbc2010-09-01 12:13:25 -0700689 // We don't accept long click events in these cases
690 // - If the workspace isn't ready to accept a drop
691 // - If we're not done loading (because we might be confused about which item
692 // to pick up
693 // - If we're not visible
694 if (!isVisible() || mLauncher.isWorkspaceLocked() || mLocks != 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500695 return true;
696 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700697 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500698 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
699 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800700
Patrick Dubroy5f445422011-02-18 14:35:21 -0800701 final Bitmap bmp = app.iconBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800702
Daniel Sandler388f6792010-03-02 14:08:08 -0500703 // We don't really have an accurate location to use. This will do.
Patrick Dubroy5f445422011-02-18 14:35:21 -0800704 int screenX = mMotionDownRawX - (bmp.getWidth() / 2);
705 int screenY = mMotionDownRawY - bmp.getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800706
Winson Chung097eb0a2011-03-18 16:56:08 -0700707 mLauncher.lockScreenOrientation();
708 mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, bmp);
Patrick Dubroy5f445422011-02-18 14:35:21 -0800709 mDragController.startDrag(
710 bmp, screenX, screenY, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800711
Winson Chung097eb0a2011-03-18 16:56:08 -0700712 mLauncher.showWorkspace(true);
Daniel Sandler388f6792010-03-02 14:08:08 -0500713 }
714 return true;
715 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800716
Daniel Sandler388f6792010-03-02 14:08:08 -0500717 @Override
718 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
719 if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
720 if (!isVisible()) {
721 return false;
722 }
723 String text = null;
724 int index;
725 int count = mAllAppsList.size() + 1; // +1 is home
726 int pos = -1;
727 switch (mLastSelection) {
728 case SELECTION_ICONS:
Jason Sams14f67ed2010-05-11 14:02:43 -0700729 index = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500730 if (index >= 0) {
731 ApplicationInfo info = mAllAppsList.get(index);
732 if (info.title != null) {
733 text = info.title.toString();
734 pos = index;
735 }
736 }
737 break;
738 case SELECTION_HOME:
739 text = getContext().getString(R.string.all_apps_home_button_label);
740 pos = count;
741 break;
742 }
743 if (text != null) {
744 event.setEnabled(true);
745 event.getText().add(text);
746 //event.setContentDescription(text);
747 event.setItemCount(count);
748 event.setCurrentItemIndex(pos);
749 }
750 }
751 return false;
752 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800753
Patrick Dubroya669d792010-11-23 14:40:33 -0800754 @Override
Patrick Dubroya669d792010-11-23 14:40:33 -0800755 public void onDragViewVisible() {
756 }
757
758 @Override
Adam Cohenc0dcf592011-06-01 15:30:43 -0700759 public void onDropCompleted(View target, DragObject d, boolean success) {
Winson Chung097eb0a2011-03-18 16:56:08 -0700760 mLauncher.getWorkspace().onDragStopped(success);
761 mLauncher.unlockScreenOrientation();
Daniel Sandler388f6792010-03-02 14:08:08 -0500762 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800763
Daniel Sandler388f6792010-03-02 14:08:08 -0500764 /**
765 * Zoom to the specifed level.
766 *
767 * @param zoom [0..1] 0 is hidden, 1 is open
768 */
769 public void zoom(float zoom, boolean animate) {
770 cancelLongPress();
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700771 sNextZoom = zoom;
772 sAnimateNextZoom = animate;
Daniel Sandler388f6792010-03-02 14:08:08 -0500773 // if we do setZoom while we don't have a surface, we won't
774 // get the callbacks that actually set mZoom.
Joe Onorato2cc62e82010-03-17 20:23:53 -0700775 if (sRollo == null || !mHaveSurface) {
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700776 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500777 mZoom = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500778 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700779 sRollo.setZoom(zoom, animate);
Daniel Sandler388f6792010-03-02 14:08:08 -0500780 }
781 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800782
Joe Onorato878f0862010-03-22 12:22:22 -0400783 /**
784 * If sRollo is null, then we're not visible. This is also used to guard against
785 * sRollo being null.
786 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500787 public boolean isVisible() {
Joe Onorato878f0862010-03-22 12:22:22 -0400788 return sRollo != null && mZoom > 0.001f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500789 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800790
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700791 public boolean isAnimating() {
792 return isVisible() && mZoom <= 0.999f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500793 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800794
Daniel Sandler388f6792010-03-02 14:08:08 -0500795 public void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700796 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500797 // We've been removed from the window. Don't bother with all this.
798 return;
799 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800800
Daniel Sandler707b0f72010-04-15 16:41:31 -0400801 if (list != null) {
802 Collections.sort(list, LauncherModel.APP_NAME_COMPARATOR);
803 }
804
Romain Guy13c2e7b2010-03-10 19:45:00 -0800805 boolean reload = false;
806 if (mAllAppsList == null) {
807 reload = true;
808 } else if (list.size() != mAllAppsList.size()) {
809 reload = true;
810 } else {
811 final int count = list.size();
812 for (int i = 0; i < count; i++) {
813 if (list.get(i) != mAllAppsList.get(i)) {
814 reload = true;
815 break;
816 }
817 }
818 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800819
Daniel Sandler388f6792010-03-02 14:08:08 -0500820 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700821 if (sRollo != null && reload) {
822 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500823 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700824
Romain Guyc16fea72010-03-12 17:17:56 -0800825 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700826 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
Romain Guyc16fea72010-03-12 17:17:56 -0800827 mRestoreFocusIndex = -1;
828 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700829
Daniel Sandler388f6792010-03-02 14:08:08 -0500830 mLocks &= ~LOCK_ICONS_PENDING;
831 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800832
Daniel Sandler388f6792010-03-02 14:08:08 -0500833 public void addApps(ArrayList<ApplicationInfo> list) {
834 if (mAllAppsList == null) {
835 // Not done loading yet. We'll find out about it later.
836 return;
837 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700838 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500839 // We've been removed from the window. Don't bother with all this.
840 return;
841 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800842
Daniel Sandler388f6792010-03-02 14:08:08 -0500843 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700844 if (sRollo != null) {
845 sRollo.pause();
Jason Sams14f67ed2010-05-11 14:02:43 -0700846 sRollo.reallocAppsList(sRollo.mScript.get_gIconCount() + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500847 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800848
Daniel Sandler388f6792010-03-02 14:08:08 -0500849 for (int i=0; i<N; i++) {
850 final ApplicationInfo item = list.get(i);
851 int index = Collections.binarySearch(mAllAppsList, item,
852 LauncherModel.APP_NAME_COMPARATOR);
853 if (index < 0) {
854 index = -(index+1);
855 }
856 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700857 if (sRollo != null) {
858 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500859 }
860 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800861
Joe Onorato2cc62e82010-03-17 20:23:53 -0700862 if (sRollo != null) {
863 sRollo.saveAppsList();
864 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500865 }
866 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800867
Daniel Sandler388f6792010-03-02 14:08:08 -0500868 public void removeApps(ArrayList<ApplicationInfo> list) {
869 if (mAllAppsList == null) {
870 // Not done loading yet. We'll find out about it later.
871 return;
872 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800873
Joe Onorato2cc62e82010-03-17 20:23:53 -0700874 if (sRollo != null) {
875 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800876 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500877 final int N = list.size();
878 for (int i=0; i<N; i++) {
879 final ApplicationInfo item = list.get(i);
880 int index = findAppByComponent(mAllAppsList, item);
881 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500882 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700883 if (sRollo != null) {
884 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500885 }
886 } else {
887 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
888 // Try to recover. This should keep us from crashing for now.
889 }
890 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800891
Joe Onorato2cc62e82010-03-17 20:23:53 -0700892 if (sRollo != null) {
893 sRollo.saveAppsList();
894 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500895 }
896 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800897
Joe Onorato64e6be72010-03-05 15:05:52 -0500898 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500899 // Just remove and add, because they may need to be re-sorted.
900 removeApps(list);
901 addApps(list);
902 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800903
Daniel Sandler388f6792010-03-02 14:08:08 -0500904 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
905 ComponentName component = item.intent.getComponent();
906 final int N = list.size();
907 for (int i=0; i<N; i++) {
908 ApplicationInfo x = list.get(i);
909 if (x.intent.getComponent().equals(component)) {
910 return i;
911 }
912 }
913 return -1;
914 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800915
Jason Sams4dfea092010-12-06 17:38:58 -0800916 class AAMessage extends RenderScript.RSMessageHandler {
Daniel Sandler388f6792010-03-02 14:08:08 -0500917 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700918 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500919 mVelocity = ((float)mData[1]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700920
921 boolean lastVisible = isVisible();
Daniel Sandler388f6792010-03-02 14:08:08 -0500922 mZoom = ((float)mData[2]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700923
924 final boolean visible = isVisible();
925 if (visible != lastVisible) {
926 post(new Runnable() {
927 public void run() {
928 if (visible) {
929 showSurface();
930 } else {
931 hideSurface();
932 }
933 }
934 });
935 }
936
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700937 sZoomDirty = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500938 }
939 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800940
Romain Guy13c2e7b2010-03-10 19:45:00 -0800941 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500942 // Allocations ======
943 private int mWidth;
944 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800945
Daniel Sandler388f6792010-03-02 14:08:08 -0500946 private Resources mRes;
Stephen Hinesb2d69862010-09-16 17:21:50 -0700947 ScriptC_allapps mScript;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800948
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700949 private Mesh mMesh;
Alex Sakhartchoukc3842422010-12-21 14:43:30 -0800950 private ProgramVertexFixedFunction.Constants mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800951
Jason Sams14f67ed2010-05-11 14:02:43 -0700952 private ScriptField_VpConsts mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800953
Daniel Sandler388f6792010-03-02 14:08:08 -0500954 private Allocation mHomeButtonNormal;
955 private Allocation mHomeButtonFocused;
956 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800957
Daniel Sandler388f6792010-03-02 14:08:08 -0500958 private Allocation[] mIcons;
Jason Sams4dfea092010-12-06 17:38:58 -0800959 private Allocation mAllocIcons;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800960
Daniel Sandler388f6792010-03-02 14:08:08 -0500961 private Allocation[] mLabels;
Jason Sams4dfea092010-12-06 17:38:58 -0800962 private Allocation mAllocLabels;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800963
Daniel Sandler388f6792010-03-02 14:08:08 -0500964 private Bitmap mSelectionBitmap;
965 private Canvas mSelectionCanvas;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800966
Jason Sams14f67ed2010-05-11 14:02:43 -0700967 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800968
Romain Guy13c2e7b2010-03-10 19:45:00 -0800969 AllApps3D mAllApps;
970 boolean mInitialize;
971
Daniel Sandler388f6792010-03-02 14:08:08 -0500972 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -0800973 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -0800974 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -0500975 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800976
977 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400978 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -0800979 sRS.bindRootScript(null);
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400980 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800981 }
982
983 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400984 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -0800985 sRS.bindRootScript(mScript);
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400986 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800987 }
988
Romain Guy13c2e7b2010-03-10 19:45:00 -0800989 public RolloRS(AllApps3D allApps) {
990 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -0500991 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800992
Daniel Sandler388f6792010-03-02 14:08:08 -0500993 public void init(Resources res, int width, int height) {
994 mRes = res;
995 mWidth = width;
996 mHeight = height;
Jason Sams4dfea092010-12-06 17:38:58 -0800997 mScript = new ScriptC_allapps(sRS, mRes, R.raw.allapps);
Jason Sams14f67ed2010-05-11 14:02:43 -0700998
Daniel Sandler388f6792010-03-02 14:08:08 -0500999 initProgramVertex();
1000 initProgramFragment();
1001 initProgramStore();
1002 initGl();
1003 initData();
Jason Sams14f67ed2010-05-11 14:02:43 -07001004
Jason Sams4dfea092010-12-06 17:38:58 -08001005 mScript.bind_gIcons(mAllocIcons);
1006 mScript.bind_gLabels(mAllocLabels);
1007 sRS.bindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -05001008 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001009
Daniel Sandler388f6792010-03-02 14:08:08 -05001010 public void initMesh() {
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001011 Mesh.TriangleMeshBuilder tm = new Mesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001012
Daniel Sandler388f6792010-03-02 14:08:08 -05001013 for (int ct=0; ct < 16; ct++) {
1014 float pos = (1.f / (16.f - 1)) * ct;
1015 tm.addVertex(0.0f, pos);
1016 tm.addVertex(1.0f, pos);
1017 }
1018 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1019 tm.addTriangle(ct, ct+1, ct+2);
1020 tm.addTriangle(ct+1, ct+3, ct+2);
1021 }
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001022 mMesh = tm.create(true);
Jason Sams14f67ed2010-05-11 14:02:43 -07001023 mScript.set_gSMCell(mMesh);
Daniel Sandler388f6792010-03-02 14:08:08 -05001024 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001025
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001026 Matrix4f getProjectionMatrix(int w, int h) {
1027 // range -1,1 in the narrow axis at z = 0.
1028 Matrix4f m1 = new Matrix4f();
1029 Matrix4f m2 = new Matrix4f();
1030
1031 if(w > h) {
1032 float aspect = ((float)w) / h;
1033 m1.loadFrustum(-aspect,aspect, -1,1, 1,100);
1034 } else {
1035 float aspect = ((float)h) / w;
1036 m1.loadFrustum(-1,1, -aspect,aspect, 1,100);
1037 }
1038
1039 m2.loadRotate(180, 0, 1, 0);
1040 m1.loadMultiply(m1, m2);
1041
1042 m2.loadScale(-2, 2, 1);
1043 m1.loadMultiply(m1, m2);
1044
1045 m2.loadTranslate(0, 0, 2);
1046 m1.loadMultiply(m1, m2);
1047 return m1;
1048 }
1049
Daniel Sandler388f6792010-03-02 14:08:08 -05001050 void resize(int w, int h) {
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001051 Matrix4f proj = getProjectionMatrix(w, h);
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001052 mPVA.setProjection(proj);
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001053
1054 if (mUniformAlloc != null) {
1055 ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
1056 i.Proj = proj;
1057 i.ScaleOffset.x = (2.f / 480.f);
1058 i.ScaleOffset.y = 0;
1059 i.ScaleOffset.z = -((float)w / 2) - 0.25f;
Marco Nelissen876668c2011-04-22 13:18:53 -07001060 if (w < h) {
1061 // portrait
1062 i.ScaleOffset.w = -380.25f;
1063 i.BendPos.x = 120.f; // bottom of screen
1064 i.BendPos.y = h - 82.f; // top of screen
1065 } else {
1066 // landscape
1067 i.ScaleOffset.w = -206.25f;
1068 i.BendPos.x = 50.f;
1069 i.BendPos.y = h - 30.f;
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001070 }
1071 mUniformAlloc.set(i, 0, true);
1072 }
1073
Daniel Sandler388f6792010-03-02 14:08:08 -05001074 mWidth = w;
1075 mHeight = h;
1076 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001077
Daniel Sandler388f6792010-03-02 14:08:08 -05001078 private void initProgramVertex() {
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001079 mPVA = new ProgramVertexFixedFunction.Constants(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001080 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001081
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001082 ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001083 pvb.setTextureMatrixEnable(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001084 ProgramVertex pv = pvb.create();
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001085 ((ProgramVertexFixedFunction)pv).bindConstants(mPVA);
Jason Sams4dfea092010-12-06 17:38:58 -08001086 sRS.bindProgramVertex(pv);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001087
Jason Sams14f67ed2010-05-11 14:02:43 -07001088 mUniformAlloc = new ScriptField_VpConsts(sRS, 1);
1089 mScript.bind_vpConstants(mUniformAlloc);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001090
Daniel Sandler388f6792010-03-02 14:08:08 -05001091 initMesh();
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001092 ProgramVertex.Builder sb = new ProgramVertex.Builder(sRS);
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001093 String t = "varying vec4 varColor;\n" +
Alex Sakhartchouk2f3b0b62010-10-06 09:32:12 -07001094 "varying vec2 varTex0;\n" +
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001095 "void main() {\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001096 // Animation
1097 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001098
Romain Guy060b5c82010-03-04 10:07:38 -08001099 " float bendY1 = UNI_BendPos.x;\n" +
1100 " float bendY2 = UNI_BendPos.y;\n" +
1101 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1102 " float bendDistance = bendY1 * 0.4;\n" +
1103 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001104
Romain Guy060b5c82010-03-04 10:07:38 -08001105 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1106 " float aDy = cos(bendAngle);\n" +
1107 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001108
Marco Nelissen876668c2011-04-22 13:18:53 -07001109 " float scale = (2.0 / " + mWidth + ".0);\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001110 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1111 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1112 " float y = 0.0;\n" +
1113 " float z = 0.0;\n" +
1114 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001115
Romain Guy060b5c82010-03-04 10:07:38 -08001116 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1117 " y += cv * aDy;\n" +
1118 " z += -cv * aDz;\n" +
1119 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1120 " lum += cv / bendDistance * distanceDimLevel;\n" +
1121 " y += cv * cos(cv * bendStep);\n" +
1122 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001123
Romain Guy060b5c82010-03-04 10:07:38 -08001124 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1125 " y += cv * aDy;\n" +
1126 " z += cv * aDz;\n" +
1127 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1128 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1129 " y += cv * cos(cv * bendStep);\n" +
1130 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001131
Romain Guy060b5c82010-03-04 10:07:38 -08001132 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001133
Romain Guy060b5c82010-03-04 10:07:38 -08001134 " vec4 pos;\n" +
1135 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1136 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1137 " pos.z = z * UNI_ScaleOffset.x;\n" +
1138 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001139
Romain Guy060b5c82010-03-04 10:07:38 -08001140 " pos.x *= 1.0 + ani * 4.0;\n" +
1141 " pos.y *= 1.0 + ani * 4.0;\n" +
1142 " pos.z -= ani * 1.5;\n" +
1143 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001144
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001145 " gl_Position = UNI_Proj * pos;\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001146 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1147 " varTex0.xy = ATTRIB_position;\n" +
1148 " varTex0.y = 1.0 - varTex0.y;\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001149 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001150 sb.setShader(t);
1151 sb.addConstant(mUniformAlloc.getType());
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001152 sb.addInput(mMesh.getVertexAllocation(0).getType().getElement());
Jason Sams60a55bb2010-06-18 15:11:19 -07001153 ProgramVertex pvc = sb.create();
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001154 pvc.bindConstants(mUniformAlloc.getAllocation(), 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001155
Jason Sams60a55bb2010-06-18 15:11:19 -07001156 mScript.set_gPVCurve(pvc);
Daniel Sandler388f6792010-03-02 14:08:08 -05001157 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001158
Daniel Sandler388f6792010-03-02 14:08:08 -05001159 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001160 Sampler.Builder sb = new Sampler.Builder(sRS);
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001161 sb.setMinification(Sampler.Value.LINEAR_MIP_LINEAR);
1162 sb.setMagnification(Sampler.Value.NEAREST);
Daniel Sandler388f6792010-03-02 14:08:08 -05001163 sb.setWrapS(Sampler.Value.CLAMP);
1164 sb.setWrapT(Sampler.Value.CLAMP);
1165 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001166
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001167 sb.setMinification(Sampler.Value.NEAREST);
1168 sb.setMagnification(Sampler.Value.NEAREST);
Daniel Sandler388f6792010-03-02 14:08:08 -05001169 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001170
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001171 ProgramFragmentFixedFunction.Builder bf = new ProgramFragmentFixedFunction.Builder(sRS);
1172 bf.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
1173 ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001174 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001175 ProgramFragment pfTexMip = bf.create();
1176 pfTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001177
Jason Sams070ada82010-08-04 17:53:07 -07001178 bf.setVaryingColor(false);
Jason Sams60a55bb2010-06-18 15:11:19 -07001179 ProgramFragment pfTexNearest = bf.create();
1180 pfTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001181
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001182 bf.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
1183 ProgramFragmentFixedFunction.Builder.Format.ALPHA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001184 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001185 ProgramFragment pfTexMipAlpha = bf.create();
1186 pfTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001187
Jason Sams60a55bb2010-06-18 15:11:19 -07001188 mScript.set_gPFTexNearest(pfTexNearest);
1189 mScript.set_gPFTexMip(pfTexMip);
1190 mScript.set_gPFTexMipAlpha(pfTexMipAlpha);
Daniel Sandler388f6792010-03-02 14:08:08 -05001191 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001192
Daniel Sandler388f6792010-03-02 14:08:08 -05001193 private void initProgramStore() {
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001194 ProgramStore.Builder bs = new ProgramStore.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001195 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
Alex Sakhartchoukc3842422010-12-21 14:43:30 -08001196 bs.setColorMaskEnabled(true,true,true,false);
1197 bs.setDitherEnabled(true);
Daniel Sandler388f6792010-03-02 14:08:08 -05001198 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1199 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Jason Sams14f67ed2010-05-11 14:02:43 -07001200 mScript.set_gPS(bs.create());
Daniel Sandler388f6792010-03-02 14:08:08 -05001201 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001202
Daniel Sandler388f6792010-03-02 14:08:08 -05001203 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001204 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001205
Daniel Sandler388f6792010-03-02 14:08:08 -05001206 private void initData() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001207 mScript.set_COLUMNS_PER_PAGE_PORTRAIT(Defines.COLUMNS_PER_PAGE_PORTRAIT);
1208 mScript.set_ROWS_PER_PAGE_PORTRAIT(Defines.ROWS_PER_PAGE_PORTRAIT);
1209 mScript.set_COLUMNS_PER_PAGE_LANDSCAPE(Defines.COLUMNS_PER_PAGE_LANDSCAPE);
1210 mScript.set_ROWS_PER_PAGE_LANDSCAPE(Defines.ROWS_PER_PAGE_LANDSCAPE);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001211
Joe Onorato2cc62e82010-03-17 20:23:53 -07001212 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
Jason Sams735a8242010-12-14 19:24:21 -08001213 R.drawable.home_button_normal);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001214 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
Jason Sams735a8242010-12-14 19:24:21 -08001215 R.drawable.home_button_focused);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001216 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
Jason Sams735a8242010-12-14 19:24:21 -08001217 R.drawable.home_button_pressed);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001218
Jason Sams14f67ed2010-05-11 14:02:43 -07001219 mScript.set_gHomeButton(mHomeButtonNormal);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001220
Daniel Sandler388f6792010-03-02 14:08:08 -05001221 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1222 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1223 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001224
Daniel Sandler388f6792010-03-02 14:08:08 -05001225 setApps(null);
1226 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001227
Daniel Sandler388f6792010-03-02 14:08:08 -05001228 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001229 if (sZoomDirty) {
1230 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001231 }
1232 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001233
Romain Guy060b5c82010-03-04 10:07:38 -08001234 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001235 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001236 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001237 final int count = list != null ? list.size() : 0;
1238 int allocCount = count;
1239 if (allocCount < 1) {
1240 allocCount = 1;
1241 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001242
Daniel Sandler388f6792010-03-02 14:08:08 -05001243 mIcons = new Allocation[count];
Jason Sams4dfea092010-12-06 17:38:58 -08001244 mAllocIcons = Allocation.createSized(sRS, Element.ALLOCATION(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001245
Daniel Sandler388f6792010-03-02 14:08:08 -05001246 mLabels = new Allocation[count];
Jason Sams4dfea092010-12-06 17:38:58 -08001247 mAllocLabels = Allocation.createSized(sRS, Element.ALLOCATION(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001248
Jason Sams14f67ed2010-05-11 14:02:43 -07001249 mScript.set_gIconCount(count);
1250 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001251 createAppIconAllocations(i, list.get(i));
1252 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001253 saveAppsList();
Jason Sams14f67ed2010-05-11 14:02:43 -07001254 android.util.Log.e("rs", "setApps");
Joe Onorato2cc62e82010-03-17 20:23:53 -07001255 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001256 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001257
Daniel Sandler388f6792010-03-02 14:08:08 -05001258 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001259 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001260 sRollo.clearSelectedIcon();
1261 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001262 }
Jason Sams60a55bb2010-06-18 15:11:19 -07001263 sRollo.mScript.invoke_setZoom(zoom, animate ? 1 : 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001264 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001265
Daniel Sandler388f6792010-03-02 14:08:08 -05001266 private void createAppIconAllocations(int index, ApplicationInfo item) {
Jason Sams95d2d2d2010-12-16 12:19:04 -08001267 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1268 Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
1269 Allocation.USAGE_GRAPHICS_TEXTURE);
1270 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1271 Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
1272 Allocation.USAGE_GRAPHICS_TEXTURE);
Daniel Sandler388f6792010-03-02 14:08:08 -05001273 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001274
Daniel Sandler388f6792010-03-02 14:08:08 -05001275 /**
1276 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1277 * fill in the values and call saveAppsList().
1278 */
1279 private void reallocAppsList(int count) {
1280 Allocation[] icons = new Allocation[count];
Jason Sams4dfea092010-12-06 17:38:58 -08001281 mAllocIcons = Allocation.createSized(sRS, Element.ALLOCATION(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001282
Daniel Sandler388f6792010-03-02 14:08:08 -05001283 Allocation[] labels = new Allocation[count];
Jason Sams4dfea092010-12-06 17:38:58 -08001284 mAllocLabels = Allocation.createSized(sRS, Element.ALLOCATION(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001285
Jason Sams14f67ed2010-05-11 14:02:43 -07001286 final int oldCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001287
Daniel Sandler388f6792010-03-02 14:08:08 -05001288 System.arraycopy(mIcons, 0, icons, 0, oldCount);
Daniel Sandler388f6792010-03-02 14:08:08 -05001289 System.arraycopy(mLabels, 0, labels, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001290
Daniel Sandler388f6792010-03-02 14:08:08 -05001291 mIcons = icons;
Daniel Sandler388f6792010-03-02 14:08:08 -05001292 mLabels = labels;
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 new app. Make sure you call saveAppsList when done.
1297 */
1298 private void addApp(int index, ApplicationInfo item) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001299 final int count = mScript.get_gIconCount() - index;
Daniel Sandler388f6792010-03-02 14:08:08 -05001300 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001301
Daniel Sandler388f6792010-03-02 14:08:08 -05001302 System.arraycopy(mIcons, index, mIcons, dest, count);
Daniel Sandler388f6792010-03-02 14:08:08 -05001303 System.arraycopy(mLabels, index, mLabels, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001304
Daniel Sandler388f6792010-03-02 14:08:08 -05001305 createAppIconAllocations(index, item);
Jason Sams14f67ed2010-05-11 14:02:43 -07001306
1307 mScript.set_gIconCount(mScript.get_gIconCount() + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001308 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001309
Daniel Sandler388f6792010-03-02 14:08:08 -05001310 /**
1311 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1312 */
1313 private void removeApp(int index) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001314 final int count = mScript.get_gIconCount() - index - 1;
Daniel Sandler388f6792010-03-02 14:08:08 -05001315 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001316
Daniel Sandler388f6792010-03-02 14:08:08 -05001317 System.arraycopy(mIcons, src, mIcons, index, count);
Daniel Sandler388f6792010-03-02 14:08:08 -05001318 System.arraycopy(mLabels, src, mLabels, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001319
Jason Sams14f67ed2010-05-11 14:02:43 -07001320 mScript.set_gIconCount(mScript.get_gIconCount() - 1);
1321 final int last = mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001322
Daniel Sandler388f6792010-03-02 14:08:08 -05001323 mIcons[last] = null;
Daniel Sandler388f6792010-03-02 14:08:08 -05001324 mLabels[last] = null;
Daniel Sandler388f6792010-03-02 14:08:08 -05001325 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001326
Daniel Sandler388f6792010-03-02 14:08:08 -05001327 /**
1328 * Send the apps list structures to RS.
1329 */
1330 private void saveAppsList() {
1331 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
Jason Sams4dfea092010-12-06 17:38:58 -08001332 if (mScript != null && mAllocIcons != null) {
1333 if (mIcons.length > 0) {
1334 mAllocIcons.copyFrom(mIcons);
1335 mAllocLabels.copyFrom(mLabels);
1336 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001337
Jason Sams4dfea092010-12-06 17:38:58 -08001338 mScript.bind_gIcons(mAllocIcons);
1339 mScript.bind_gLabels(mAllocLabels);
Daniel Sandler388f6792010-03-02 14:08:08 -05001340 }
1341 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001342
Jason Sams60a55bb2010-06-18 15:11:19 -07001343 void fling(float pos, float v) {
1344 mScript.invoke_fling(pos, v);
Daniel Sandler388f6792010-03-02 14:08:08 -05001345 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001346
Jason Sams60a55bb2010-06-18 15:11:19 -07001347 void move(float pos) {
1348 mScript.invoke_move(pos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001349 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001350
Daniel Sandler388f6792010-03-02 14:08:08 -05001351 void moveTo(float row) {
Jason Sams60a55bb2010-06-18 15:11:19 -07001352 mScript.invoke_moveTo(row);
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 * You need to call save() on mState on your own after calling this.
1357 *
1358 * @return the index of the icon that was selected.
1359 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001360 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001361 if (mAllApps != null) {
1362 final int index = mAllApps.chooseTappedIcon(x, y);
1363 selectIcon(index, pressed);
1364 return index;
1365 } else {
1366 return -1;
1367 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001368 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001369
Daniel Sandler388f6792010-03-02 14:08:08 -05001370 /**
1371 * Select the icon at the given index.
1372 *
1373 * @param index The index.
1374 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1375 */
1376 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001377 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1378 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001379 if (mAllApps != null) {
1380 mAllApps.mRestoreFocusIndex = index;
1381 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001382 mScript.set_gSelectedIconIndex(-1);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001383 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1384 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001385 }
1386 } else {
1387 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001388 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001389 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001390
Jason Sams14f67ed2010-05-11 14:02:43 -07001391 int prev = mScript.get_gSelectedIconIndex();
1392 mScript.set_gSelectedIconIndex(index);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001393
Romain Guy13c2e7b2010-03-10 19:45:00 -08001394 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001395 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001396
Daniel Sandler388f6792010-03-02 14:08:08 -05001397 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1398 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1399 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001400
Jason Sams735a8242010-12-14 19:24:21 -08001401 Allocation si = Allocation.createFromBitmap(sRS, selectionBitmap);
Jason Sams60a55bb2010-06-18 15:11:19 -07001402 mScript.set_gSelectedIconTexture(si);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001403
Daniel Sandler388f6792010-03-02 14:08:08 -05001404 if (prev != index) {
1405 if (info.title != null && info.title.length() > 0) {
1406 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001407 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001408 }
1409 }
1410 }
1411 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001412
Daniel Sandler388f6792010-03-02 14:08:08 -05001413 /**
1414 * You need to call save() on mState on your own after calling this.
1415 */
1416 void clearSelectedIcon() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001417 mScript.set_gSelectedIconIndex(-1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001418 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001419
Daniel Sandler388f6792010-03-02 14:08:08 -05001420 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001421 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001422 switch (mode) {
1423 case SELECTED_NONE:
Jason Sams14f67ed2010-05-11 14:02:43 -07001424 mScript.set_gHomeButton(mHomeButtonNormal);
Daniel Sandler388f6792010-03-02 14:08:08 -05001425 break;
1426 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001427 mAllApps.mLastSelection = SELECTION_HOME;
Jason Sams14f67ed2010-05-11 14:02:43 -07001428 mScript.set_gHomeButton(mHomeButtonFocused);
Daniel Sandler388f6792010-03-02 14:08:08 -05001429 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001430 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001431 }
1432 break;
1433 case SELECTED_PRESSED:
Jason Sams14f67ed2010-05-11 14:02:43 -07001434 mScript.set_gHomeButton(mHomeButtonPressed);
Daniel Sandler388f6792010-03-02 14:08:08 -05001435 break;
1436 }
1437 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001438
Daniel Sandler388f6792010-03-02 14:08:08 -05001439 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001440 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1441 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1442 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001443 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001444 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001445 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001446 //Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1447 //Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1448 //Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1449 //Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1450 //Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1451 //Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1452 //Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1453 //Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1454 //Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001455 }
1456 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001457
Daniel Sandler388f6792010-03-02 14:08:08 -05001458 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001459 Log.d(TAG, "sRS=" + sRS);
1460 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001461 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001462 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1463 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001464 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1465 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1466 Log.d(TAG, "mLastSelection=" + mLastSelection);
1467 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1468 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1469 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1470 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001471 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1472 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001473 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001474 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001475 Log.d(TAG, "mVelocity=" + mVelocity);
1476 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001477 if (sRollo != null) {
1478 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001479 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001480 if (sRS != null) {
Jason Sams4dfea092010-12-06 17:38:58 -08001481 sRS.contextDump();
Daniel Sandler388f6792010-03-02 14:08:08 -05001482 }
1483 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001484
1485 public void reset() {
1486 // Do nothing
1487 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001488}