blob: b75d08a87008285f20fddbbf065199736fef0941 [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);
152 sRS = createRenderScript(sc);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800153 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700154 createRenderScript(sRS);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800155 }
156
Romain Guy060b5c82010-03-04 10:07:38 -0800157 final DisplayMetrics metrics = getResources().getDisplayMetrics();
158 final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
159 mColumnsPerPage = isPortrait ? Defines.COLUMNS_PER_PAGE_PORTRAIT :
160 Defines.COLUMNS_PER_PAGE_LANDSCAPE;
161 mRowsPerPage = isPortrait ? Defines.ROWS_PER_PAGE_PORTRAIT :
162 Defines.ROWS_PER_PAGE_LANDSCAPE;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800163
Joe Onorato2cc62e82010-03-17 20:23:53 -0700164 if (sRollo != null) {
165 sRollo.mAllApps = this;
166 sRollo.mRes = getResources();
167 sRollo.mInitialize = true;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800168 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500169 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800170
Romain Guy060b5c82010-03-04 10:07:38 -0800171 @SuppressWarnings({"UnusedDeclaration"})
172 public AllApps3D(Context context, AttributeSet attrs, int defStyle) {
173 this(context, attrs);
174 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800175
Romain Guy13c2e7b2010-03-10 19:45:00 -0800176 public void surrender() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400177 if (sRS != null) {
178 sRS.contextSetSurface(0, 0, null);
179 sRS.mMessageCallback = null;
180 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800181 mSurrendered = true;
182 }
183
Daniel Sandler388f6792010-03-02 14:08:08 -0500184 /**
185 * Note that this implementation prohibits this view from ever being reattached.
186 */
187 @Override
188 protected void onDetachedFromWindow() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700189 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800190 if (!mSurrendered) {
Joe Onorato96da4012010-03-17 20:03:24 -0700191 Log.i(TAG, "onDetachedFromWindow");
Romain Guy13c2e7b2010-03-10 19:45:00 -0800192 destroyRenderScript();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700193 sRS = null;
194 sRollo = null;
thigobr1f43a312010-10-22 18:13:26 -0200195 super.onDetachedFromWindow();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800196 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500197 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800198
Daniel Sandler388f6792010-03-02 14:08:08 -0500199 /**
200 * If you have an attached click listener, View always plays the click sound!?!?
201 * Deal with sound effects by hand.
202 */
203 public void reallyPlaySoundEffect(int sound) {
204 boolean old = isSoundEffectsEnabled();
205 setSoundEffectsEnabled(true);
206 playSoundEffect(sound);
207 setSoundEffectsEnabled(old);
208 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800209
Daniel Sandler388f6792010-03-02 14:08:08 -0500210 public void setLauncher(Launcher launcher) {
211 mLauncher = launcher;
212 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800213
Daniel Sandler388f6792010-03-02 14:08:08 -0500214 @Override
215 public void surfaceDestroyed(SurfaceHolder holder) {
216 super.surfaceDestroyed(holder);
217 // Without this, we leak mMessageCallback which leaks the context.
Romain Guy13c2e7b2010-03-10 19:45:00 -0800218 if (!mSurrendered) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700219 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800220 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500221 // We may lose any callbacks that are pending, so make sure that we re-sync that
222 // on the next surfaceChanged.
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700223 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500224 mHaveSurface = false;
225 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800226
Daniel Sandler388f6792010-03-02 14:08:08 -0500227 @Override
228 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
229 //long startTime = SystemClock.uptimeMillis();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800230
Daniel Sandler388f6792010-03-02 14:08:08 -0500231 super.surfaceChanged(holder, format, w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800232
Romain Guy13c2e7b2010-03-10 19:45:00 -0800233 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800234
Daniel Sandler388f6792010-03-02 14:08:08 -0500235 mHaveSurface = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800236
Joe Onorato2cc62e82010-03-17 20:23:53 -0700237 if (sRollo == null) {
238 sRollo = new RolloRS(this);
239 sRollo.init(getResources(), w, h);
Daniel Sandler388f6792010-03-02 14:08:08 -0500240 if (mAllAppsList != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700241 sRollo.setApps(mAllAppsList);
Daniel Sandler388f6792010-03-02 14:08:08 -0500242 }
243 if (mShouldGainFocus) {
244 gainFocus();
245 mShouldGainFocus = false;
246 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700247 } else if (sRollo.mInitialize) {
248 sRollo.initGl();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700249 sRollo.mInitialize = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500250 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800251
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700252 initTouchState(w, h);
253
Joe Onorato2cc62e82010-03-17 20:23:53 -0700254 sRollo.dirtyCheck();
255 sRollo.resize(w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800256
Jason Sams14f67ed2010-05-11 14:02:43 -0700257 Log.d(TAG, "sc " + sRS);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700258 if (sRS != null) {
259 sRS.mMessageCallback = mMessageProc = new AAMessage();
Daniel Sandler388f6792010-03-02 14:08:08 -0500260 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800261
Daniel Sandler388f6792010-03-02 14:08:08 -0500262 //long endTime = SystemClock.uptimeMillis();
263 //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
264 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800265
Daniel Sandler388f6792010-03-02 14:08:08 -0500266 @Override
267 public void onWindowFocusChanged(boolean hasWindowFocus) {
268 super.onWindowFocusChanged(hasWindowFocus);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800269
270 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800271
Daniel Sandler388f6792010-03-02 14:08:08 -0500272 if (mArrowNavigation) {
273 if (!hasWindowFocus) {
274 // Clear selection when we lose window focus
Jason Sams14f67ed2010-05-11 14:02:43 -0700275 mLastSelectedIcon = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700276 sRollo.setHomeSelected(SELECTED_NONE);
277 sRollo.clearSelectedIcon();
Romain Guy060b5c82010-03-04 10:07:38 -0800278 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700279 if (sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500280 if (mLastSelection == SELECTION_ICONS) {
281 int selection = mLastSelectedIcon;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700282 final int firstIcon = Math.round(sRollo.mScrollPos) * mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500283 if (selection < 0 || // No selection
284 selection < firstIcon || // off the top of the screen
Jason Sams14f67ed2010-05-11 14:02:43 -0700285 selection >= sRollo.mScript.get_gIconCount() || // past last icon
Daniel Sandler388f6792010-03-02 14:08:08 -0500286 selection >= firstIcon + // past last icon on screen
Romain Guy060b5c82010-03-04 10:07:38 -0800287 (mColumnsPerPage * mRowsPerPage)) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500288 selection = firstIcon;
289 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800290
Daniel Sandler388f6792010-03-02 14:08:08 -0500291 // Select the first icon when we gain window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700292 sRollo.selectIcon(selection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500293 } else if (mLastSelection == SELECTION_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700294 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500295 }
296 }
297 }
298 }
299 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800300
Daniel Sandler388f6792010-03-02 14:08:08 -0500301 @Override
302 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
303 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800304
Romain Guy13c2e7b2010-03-10 19:45:00 -0800305 if (!isVisible() || mSurrendered) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500306 return;
307 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800308
Daniel Sandler388f6792010-03-02 14:08:08 -0500309 if (gainFocus) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700310 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500311 gainFocus();
312 } else {
313 mShouldGainFocus = true;
314 }
315 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700316 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500317 if (mArrowNavigation) {
318 // Clear selection when we lose focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700319 sRollo.clearSelectedIcon();
320 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500321 mArrowNavigation = false;
322 }
323 } else {
324 mShouldGainFocus = false;
325 }
326 }
327 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800328
Daniel Sandler388f6792010-03-02 14:08:08 -0500329 private void gainFocus() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700330 if (!mArrowNavigation && sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500331 // Select the first icon when we gain keyboard focus
332 mArrowNavigation = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700333 sRollo.selectIcon(Math.round(sRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500334 }
335 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800336
Daniel Sandler388f6792010-03-02 14:08:08 -0500337 @Override
338 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800339
Daniel Sandler388f6792010-03-02 14:08:08 -0500340 boolean handled = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800341
Daniel Sandler388f6792010-03-02 14:08:08 -0500342 if (!isVisible()) {
343 return false;
344 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700345 final int iconCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800346
Daniel Sandler388f6792010-03-02 14:08:08 -0500347 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
348 if (mArrowNavigation) {
349 if (mLastSelection == SELECTION_HOME) {
350 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
351 mLauncher.closeAllApps(true);
352 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700353 int whichApp = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500354 if (whichApp >= 0) {
355 ApplicationInfo app = mAllAppsList.get(whichApp);
Joe Onoratof984e852010-03-25 09:47:45 -0700356 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500357 handled = true;
358 }
359 }
360 }
361 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800362
Daniel Sandler388f6792010-03-02 14:08:08 -0500363 if (iconCount > 0) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800364 final boolean isPortrait = getWidth() < getHeight();
Jason Sams14f67ed2010-05-11 14:02:43 -0700365
Daniel Sandler388f6792010-03-02 14:08:08 -0500366 mArrowNavigation = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800367
Jason Sams14f67ed2010-05-11 14:02:43 -0700368 int currentSelection = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700369 int currentTopRow = Math.round(sRollo.mScrollPos);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800370
Romain Guy060b5c82010-03-04 10:07:38 -0800371 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1
372 final int currentPageCol = currentSelection % mColumnsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800373
Romain Guy060b5c82010-03-04 10:07:38 -0800374 // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1
Romain Guy6a42cf32010-03-12 16:03:52 -0800375 final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage))
Romain Guy060b5c82010-03-04 10:07:38 -0800376 / mRowsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800377
Daniel Sandler388f6792010-03-02 14:08:08 -0500378 int newSelection = currentSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800379
Daniel Sandler388f6792010-03-02 14:08:08 -0500380 switch (keyCode) {
381 case KeyEvent.KEYCODE_DPAD_UP:
382 if (mLastSelection == SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800383 if (isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700384 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guy6a42cf32010-03-12 16:03:52 -0800385 int lastRowCount = iconCount % mColumnsPerPage;
386 if (lastRowCount == 0) {
387 lastRowCount = mColumnsPerPage;
388 }
389 newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2);
390 if (newSelection >= iconCount) {
391 newSelection = iconCount-1;
392 }
393 int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
394 if (target < 0) {
395 target = 0;
396 }
397 if (currentTopRow != target) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700398 sRollo.moveTo(target);
Romain Guy6a42cf32010-03-12 16:03:52 -0800399 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500400 }
401 } else {
402 if (currentPageRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800403 newSelection = currentSelection - mColumnsPerPage;
Romain Guy6a42cf32010-03-12 16:03:52 -0800404 if (currentTopRow > newSelection / mColumnsPerPage) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700405 sRollo.moveTo(newSelection / mColumnsPerPage);
Romain Guy6a42cf32010-03-12 16:03:52 -0800406 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500407 } else if (currentTopRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800408 newSelection = currentSelection - mColumnsPerPage;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700409 sRollo.moveTo(newSelection / mColumnsPerPage);
Daniel Sandler388f6792010-03-02 14:08:08 -0500410 } else if (currentPageRow != 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800411 newSelection = currentTopRow * mRowsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500412 }
413 }
414 handled = true;
415 break;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800416
Daniel Sandler388f6792010-03-02 14:08:08 -0500417 case KeyEvent.KEYCODE_DPAD_DOWN: {
Romain Guy060b5c82010-03-04 10:07:38 -0800418 final int rowCount = iconCount / mColumnsPerPage
419 + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
420 final int currentRow = currentSelection / mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500421 if (mLastSelection != SELECTION_HOME) {
422 if (currentRow < rowCount-1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700423 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500424 if (currentSelection < 0) {
425 newSelection = 0;
426 } else {
Romain Guy060b5c82010-03-04 10:07:38 -0800427 newSelection = currentSelection + mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500428 }
429 if (newSelection >= iconCount) {
430 // Go from D to G in this arrangement:
431 // A B C D
432 // E F G
433 newSelection = iconCount - 1;
434 }
Romain Guy060b5c82010-03-04 10:07:38 -0800435 if (currentPageRow >= mRowsPerPage - 1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700436 sRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -0500437 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800438 } else if (isPortrait) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500439 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700440 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500441 }
442 }
443 handled = true;
444 break;
445 }
446 case KeyEvent.KEYCODE_DPAD_LEFT:
447 if (mLastSelection != SELECTION_HOME) {
448 if (currentPageCol > 0) {
449 newSelection = currentSelection - 1;
450 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800451 } else if (!isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700452 newSelection = ((int) (sRollo.mScrollPos) * mColumnsPerPage) +
Romain Guy6a42cf32010-03-12 16:03:52 -0800453 (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700454 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500455 }
456 handled = true;
457 break;
458 case KeyEvent.KEYCODE_DPAD_RIGHT:
459 if (mLastSelection != SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800460 if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 ||
461 currentSelection == iconCount - 1)) {
462 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700463 sRollo.setHomeSelected(SELECTED_FOCUSED);
Romain Guy6a42cf32010-03-12 16:03:52 -0800464 } else if ((currentPageCol < mColumnsPerPage - 1) &&
Daniel Sandler388f6792010-03-02 14:08:08 -0500465 (currentSelection < iconCount - 1)) {
466 newSelection = currentSelection + 1;
467 }
468 }
469 handled = true;
470 break;
471 }
472 if (newSelection != currentSelection) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700473 sRollo.selectIcon(newSelection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500474 }
475 }
476 return handled;
477 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800478
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700479 void initTouchState(int width, int height) {
480 boolean isPortrait = width < height;
481
482 int[] viewPos = new int[2];
483 getLocationOnScreen(viewPos);
484
485 mTouchXBorders = new int[mColumnsPerPage + 1];
486 mTouchYBorders = new int[mRowsPerPage + 1];
487
488 // TODO: Put this in a config file/define
489 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE_PORTRAIT;
490 if (!isPortrait) cellHeight -= 12;
491 int centerY = (int) (height * (isPortrait ? 0.5f : 0.47f));
492 if (!isPortrait) centerY += cellHeight / 2;
493 int half = (int) Math.floor((mRowsPerPage + 1) / 2);
494 int end = mTouchYBorders.length - (half + 1);
495
496 for (int i = -half; i <= end; i++) {
497 mTouchYBorders[i + half] = centerY + (i * cellHeight) - viewPos[1];
498 }
499
500 int x = 0;
501 // TODO: Put this in a config file/define
502 int columnWidth = 120;
503 for (int i = 0; i < mColumnsPerPage + 1; i++) {
504 mTouchXBorders[i] = x - viewPos[0];
505 x += columnWidth;
506 }
507 }
508
509 int chooseTappedIcon(int x, int y) {
510 float pos = sRollo != null ? sRollo.mScrollPos : 0;
511
512 int oldY = y;
513
514 // Adjust for scroll position if not zero.
515 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
516
517 int col = -1;
518 int row = -1;
519 final int columnsCount = mColumnsPerPage;
520 for (int i=0; i< columnsCount; i++) {
521 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
522 col = i;
523 break;
524 }
525 }
526 final int rowsCount = mRowsPerPage;
527 for (int i=0; i< rowsCount; i++) {
528 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
529 row = i;
530 break;
531 }
532 }
533
534 if (row < 0 || col < 0) {
535 return -1;
536 }
537
538 int index = (((int) pos) * columnsCount) + (row * columnsCount) + col;
539
540 if (index >= mAllAppsList.size()) {
541 return -1;
542 } else {
543 return index;
544 }
545 }
546
Daniel Sandler388f6792010-03-02 14:08:08 -0500547 @Override
548 public boolean onTouchEvent(MotionEvent ev)
549 {
550 mArrowNavigation = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800551
Daniel Sandler388f6792010-03-02 14:08:08 -0500552 if (!isVisible()) {
553 return true;
554 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800555
Daniel Sandler388f6792010-03-02 14:08:08 -0500556 if (mLocks != 0) {
557 return true;
558 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800559
Daniel Sandler388f6792010-03-02 14:08:08 -0500560 super.onTouchEvent(ev);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800561
Daniel Sandler388f6792010-03-02 14:08:08 -0500562 int x = (int)ev.getX();
563 int y = (int)ev.getY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800564
Romain Guyce115852010-03-04 12:15:37 -0800565 final boolean isPortrait = getWidth() < getHeight();
Daniel Sandler388f6792010-03-02 14:08:08 -0500566 int action = ev.getAction();
567 switch (action) {
568 case MotionEvent.ACTION_DOWN:
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700569 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
570 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500571 mTouchTracking = TRACKING_HOME;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700572 sRollo.setHomeSelected(SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500573 mCurrentIconIndex = -1;
574 } else {
575 mTouchTracking = TRACKING_FLING;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800576
Daniel Sandler388f6792010-03-02 14:08:08 -0500577 mMotionDownRawX = (int)ev.getRawX();
578 mMotionDownRawY = (int)ev.getRawY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800579
Joe Onorato2cc62e82010-03-17 20:23:53 -0700580 if (!sRollo.checkClickOK()) {
581 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500582 } else {
583 mDownIconIndex = mCurrentIconIndex
Joe Onorato2cc62e82010-03-17 20:23:53 -0700584 = sRollo.selectIcon(x, y, SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500585 if (mDownIconIndex < 0) {
586 // if nothing was selected, no long press.
587 cancelLongPress();
588 }
589 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700590 sRollo.move(ev.getRawY() / getHeight());
Daniel Sandler388f6792010-03-02 14:08:08 -0500591 mVelocityTracker = VelocityTracker.obtain();
592 mVelocityTracker.addMovement(ev);
593 mStartedScrolling = false;
594 }
595 break;
596 case MotionEvent.ACTION_MOVE:
597 case MotionEvent.ACTION_OUTSIDE:
598 if (mTouchTracking == TRACKING_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700599 sRollo.setHomeSelected((isPortrait &&
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700600 y > mTouchYBorders[mTouchYBorders.length-1]) || (!isPortrait
601 && x > mTouchXBorders[mTouchXBorders.length-1])
Daniel Sandler388f6792010-03-02 14:08:08 -0500602 ? SELECTED_PRESSED : SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500603 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500604 int rawY = (int)ev.getRawY();
605 int slop;
606 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800607
Daniel Sandler388f6792010-03-02 14:08:08 -0500608 if (!mStartedScrolling && slop < mSlop) {
609 // don't update anything so when we do start scrolling
610 // below, we get the right delta.
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700611 mCurrentIconIndex = chooseTappedIcon(x, y);
Daniel Sandler388f6792010-03-02 14:08:08 -0500612 if (mDownIconIndex != mCurrentIconIndex) {
613 // If a different icon is selected, don't allow it to be picked up.
614 // This handles off-axis dragging.
615 cancelLongPress();
616 mCurrentIconIndex = -1;
617 }
618 } else {
619 if (!mStartedScrolling) {
620 cancelLongPress();
621 mCurrentIconIndex = -1;
622 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700623 sRollo.move(ev.getRawY() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800624
Daniel Sandler388f6792010-03-02 14:08:08 -0500625 mStartedScrolling = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700626 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500627 mVelocityTracker.addMovement(ev);
Daniel Sandler388f6792010-03-02 14:08:08 -0500628 }
629 }
630 break;
631 case MotionEvent.ACTION_UP:
632 case MotionEvent.ACTION_CANCEL:
633 if (mTouchTracking == TRACKING_HOME) {
634 if (action == MotionEvent.ACTION_UP) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700635 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
636 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500637 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
638 mLauncher.closeAllApps(true);
639 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700640 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500641 }
642 mCurrentIconIndex = -1;
643 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500644 mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700645 sRollo.clearSelectedIcon();
Jason Sams60a55bb2010-06-18 15:11:19 -0700646 sRollo.fling(ev.getRawY() / getHeight(),
647 mVelocityTracker.getYVelocity() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800648
Daniel Sandler388f6792010-03-02 14:08:08 -0500649 if (mVelocityTracker != null) {
650 mVelocityTracker.recycle();
651 mVelocityTracker = null;
652 }
653 }
654 mTouchTracking = TRACKING_NONE;
655 break;
656 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800657
Daniel Sandler388f6792010-03-02 14:08:08 -0500658 return true;
659 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800660
Daniel Sandler388f6792010-03-02 14:08:08 -0500661 public void onClick(View v) {
662 if (mLocks != 0 || !isVisible()) {
663 return;
664 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700665 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500666 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
667 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
668 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onoratof984e852010-03-25 09:47:45 -0700669 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500670 }
671 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800672
Daniel Sandler388f6792010-03-02 14:08:08 -0500673 public boolean onLongClick(View v) {
Joe Onorato6b4adbc2010-09-01 12:13:25 -0700674 // We don't accept long click events in these cases
675 // - If the workspace isn't ready to accept a drop
676 // - If we're not done loading (because we might be confused about which item
677 // to pick up
678 // - If we're not visible
679 if (!isVisible() || mLauncher.isWorkspaceLocked() || mLocks != 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500680 return true;
681 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700682 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500683 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
684 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800685
Daniel Sandler388f6792010-03-02 14:08:08 -0500686 Bitmap bmp = app.iconBitmap;
687 final int w = bmp.getWidth();
688 final int h = bmp.getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800689
Daniel Sandler388f6792010-03-02 14:08:08 -0500690 // We don't really have an accurate location to use. This will do.
691 int screenX = mMotionDownRawX - (w / 2);
692 int screenY = mMotionDownRawY - h;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800693
Daniel Sandler388f6792010-03-02 14:08:08 -0500694 mDragController.startDrag(bmp, screenX, screenY,
695 0, 0, w, h, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800696
Daniel Sandler388f6792010-03-02 14:08:08 -0500697 mLauncher.closeAllApps(true);
698 }
699 return true;
700 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800701
Daniel Sandler388f6792010-03-02 14:08:08 -0500702 @Override
703 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
704 if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
705 if (!isVisible()) {
706 return false;
707 }
708 String text = null;
709 int index;
710 int count = mAllAppsList.size() + 1; // +1 is home
711 int pos = -1;
712 switch (mLastSelection) {
713 case SELECTION_ICONS:
Jason Sams14f67ed2010-05-11 14:02:43 -0700714 index = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500715 if (index >= 0) {
716 ApplicationInfo info = mAllAppsList.get(index);
717 if (info.title != null) {
718 text = info.title.toString();
719 pos = index;
720 }
721 }
722 break;
723 case SELECTION_HOME:
724 text = getContext().getString(R.string.all_apps_home_button_label);
725 pos = count;
726 break;
727 }
728 if (text != null) {
729 event.setEnabled(true);
730 event.getText().add(text);
731 //event.setContentDescription(text);
732 event.setItemCount(count);
733 event.setCurrentItemIndex(pos);
734 }
735 }
736 return false;
737 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800738
Patrick Dubroya669d792010-11-23 14:40:33 -0800739 @Override
Daniel Sandler388f6792010-03-02 14:08:08 -0500740 public void setDragController(DragController dragger) {
741 mDragController = dragger;
742 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800743
Patrick Dubroya669d792010-11-23 14:40:33 -0800744 @Override
745 public void onDragViewVisible() {
746 }
747
748 @Override
Daniel Sandler388f6792010-03-02 14:08:08 -0500749 public void onDropCompleted(View target, boolean success) {
750 }
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
Daniel Sandler388f6792010-03-02 14:08:08 -0500904 class AAMessage extends RenderScript.RSMessage {
905 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;
Daniel Sandler388f6792010-03-02 14:08:08 -0500938 private ProgramVertex.MatrixAllocation 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;
947 private int[] mIconIds;
948 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800949
Daniel Sandler388f6792010-03-02 14:08:08 -0500950 private Allocation[] mLabels;
951 private int[] mLabelIds;
952 private Allocation mAllocLabelIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800953
Daniel Sandler388f6792010-03-02 14:08:08 -0500954 private Bitmap mSelectionBitmap;
955 private Canvas mSelectionCanvas;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800956
Jason Sams14f67ed2010-05-11 14:02:43 -0700957 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800958
Romain Guy13c2e7b2010-03-10 19:45:00 -0800959 AllApps3D mAllApps;
960 boolean mInitialize;
961
Daniel Sandler388f6792010-03-02 14:08:08 -0500962 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -0800963 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -0800964 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -0500965 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800966
967 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400968 if (sRS != null) {
969 sRS.contextBindRootScript(null);
970 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800971 }
972
973 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400974 if (sRS != null) {
975 sRS.contextBindRootScript(mScript);
976 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800977 }
978
Romain Guy13c2e7b2010-03-10 19:45:00 -0800979 public RolloRS(AllApps3D allApps) {
980 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -0500981 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800982
Daniel Sandler388f6792010-03-02 14:08:08 -0500983 public void init(Resources res, int width, int height) {
984 mRes = res;
985 mWidth = width;
986 mHeight = height;
Stephen Hinesb2d69862010-09-16 17:21:50 -0700987 mScript = new ScriptC_allapps(sRS, mRes, R.raw.allapps, true);
Jason Sams14f67ed2010-05-11 14:02:43 -0700988
Daniel Sandler388f6792010-03-02 14:08:08 -0500989 initProgramVertex();
990 initProgramFragment();
991 initProgramStore();
992 initGl();
993 initData();
Jason Sams14f67ed2010-05-11 14:02:43 -0700994
995 mScript.bind_gIconIDs(mAllocIconIds);
996 mScript.bind_gLabelIDs(mAllocLabelIds);
Jason Sams14f67ed2010-05-11 14:02:43 -0700997 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -0500998 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800999
Daniel Sandler388f6792010-03-02 14:08:08 -05001000 public void initMesh() {
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001001 Mesh.TriangleMeshBuilder tm = new Mesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001002
Daniel Sandler388f6792010-03-02 14:08:08 -05001003 for (int ct=0; ct < 16; ct++) {
1004 float pos = (1.f / (16.f - 1)) * ct;
1005 tm.addVertex(0.0f, pos);
1006 tm.addVertex(1.0f, pos);
1007 }
1008 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1009 tm.addTriangle(ct, ct+1, ct+2);
1010 tm.addTriangle(ct+1, ct+3, ct+2);
1011 }
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001012 mMesh = tm.create(true);
Jason Sams14f67ed2010-05-11 14:02:43 -07001013 mScript.set_gSMCell(mMesh);
Daniel Sandler388f6792010-03-02 14:08:08 -05001014 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001015
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001016 Matrix4f getProjectionMatrix(int w, int h) {
1017 // range -1,1 in the narrow axis at z = 0.
1018 Matrix4f m1 = new Matrix4f();
1019 Matrix4f m2 = new Matrix4f();
1020
1021 if(w > h) {
1022 float aspect = ((float)w) / h;
1023 m1.loadFrustum(-aspect,aspect, -1,1, 1,100);
1024 } else {
1025 float aspect = ((float)h) / w;
1026 m1.loadFrustum(-1,1, -aspect,aspect, 1,100);
1027 }
1028
1029 m2.loadRotate(180, 0, 1, 0);
1030 m1.loadMultiply(m1, m2);
1031
1032 m2.loadScale(-2, 2, 1);
1033 m1.loadMultiply(m1, m2);
1034
1035 m2.loadTranslate(0, 0, 2);
1036 m1.loadMultiply(m1, m2);
1037 return m1;
1038 }
1039
Daniel Sandler388f6792010-03-02 14:08:08 -05001040 void resize(int w, int h) {
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001041 Matrix4f proj = getProjectionMatrix(w, h);
1042 mPVA.loadProjection(proj);
1043
1044 if (mUniformAlloc != null) {
1045 ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
1046 i.Proj = proj;
1047 i.ScaleOffset.x = (2.f / 480.f);
1048 i.ScaleOffset.y = 0;
1049 i.ScaleOffset.z = -((float)w / 2) - 0.25f;
1050 i.ScaleOffset.w = -380.25f;
1051 i.BendPos.x = 120.f;
1052 i.BendPos.y = 680.f;
1053 if (w > h) {
1054 i.ScaleOffset.z = 40.f;
1055 i.ScaleOffset.w = h - 40.f;
1056 i.BendPos.y = 1.f;
1057 }
1058 mUniformAlloc.set(i, 0, true);
1059 }
1060
Daniel Sandler388f6792010-03-02 14:08:08 -05001061 mWidth = w;
1062 mHeight = h;
1063 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001064
Daniel Sandler388f6792010-03-02 14:08:08 -05001065 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001066 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001067 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001068
Joe Onorato2cc62e82010-03-17 20:23:53 -07001069 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001070 pvb.setTextureMatrixEnable(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001071 ProgramVertex pv = pvb.create();
1072 pv.bindAllocation(mPVA);
1073 sRS.contextBindProgramVertex(pv);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001074
Jason Sams14f67ed2010-05-11 14:02:43 -07001075 mUniformAlloc = new ScriptField_VpConsts(sRS, 1);
1076 mScript.bind_vpConstants(mUniformAlloc);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001077
Daniel Sandler388f6792010-03-02 14:08:08 -05001078 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001079 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001080 String t = "varying vec4 varColor;\n" +
Alex Sakhartchouk2f3b0b62010-10-06 09:32:12 -07001081 "varying vec2 varTex0;\n" +
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001082 "void main() {\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001083 // Animation
1084 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001085
Romain Guy060b5c82010-03-04 10:07:38 -08001086 " float bendY1 = UNI_BendPos.x;\n" +
1087 " float bendY2 = UNI_BendPos.y;\n" +
1088 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1089 " float bendDistance = bendY1 * 0.4;\n" +
1090 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001091
Romain Guy060b5c82010-03-04 10:07:38 -08001092 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1093 " float aDy = cos(bendAngle);\n" +
1094 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001095
Romain Guy060b5c82010-03-04 10:07:38 -08001096 " float scale = (2.0 / 480.0);\n" +
1097 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1098 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1099 " float y = 0.0;\n" +
1100 " float z = 0.0;\n" +
1101 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001102
Romain Guy060b5c82010-03-04 10:07:38 -08001103 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1104 " y += cv * aDy;\n" +
1105 " z += -cv * aDz;\n" +
1106 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1107 " lum += cv / bendDistance * distanceDimLevel;\n" +
1108 " y += cv * cos(cv * bendStep);\n" +
1109 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001110
Romain Guy060b5c82010-03-04 10:07:38 -08001111 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1112 " y += cv * aDy;\n" +
1113 " z += cv * aDz;\n" +
1114 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1115 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1116 " y += cv * cos(cv * bendStep);\n" +
1117 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001118
Romain Guy060b5c82010-03-04 10:07:38 -08001119 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001120
Romain Guy060b5c82010-03-04 10:07:38 -08001121 " vec4 pos;\n" +
1122 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1123 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1124 " pos.z = z * UNI_ScaleOffset.x;\n" +
1125 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001126
Romain Guy060b5c82010-03-04 10:07:38 -08001127 " pos.x *= 1.0 + ani * 4.0;\n" +
1128 " pos.y *= 1.0 + ani * 4.0;\n" +
1129 " pos.z -= ani * 1.5;\n" +
1130 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001131
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001132 " gl_Position = UNI_Proj * pos;\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001133 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1134 " varTex0.xy = ATTRIB_position;\n" +
1135 " varTex0.y = 1.0 - varTex0.y;\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001136 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001137 sb.setShader(t);
1138 sb.addConstant(mUniformAlloc.getType());
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001139 sb.addInput(mMesh.getVertexAllocation(0).getType().getElement());
Jason Sams60a55bb2010-06-18 15:11:19 -07001140 ProgramVertex pvc = sb.create();
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001141 pvc.bindConstants(mUniformAlloc.getAllocation(), 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001142
Jason Sams60a55bb2010-06-18 15:11:19 -07001143 mScript.set_gPVCurve(pvc);
Daniel Sandler388f6792010-03-02 14:08:08 -05001144 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001145
Daniel Sandler388f6792010-03-02 14:08:08 -05001146 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001147 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001148 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1149 sb.setMag(Sampler.Value.NEAREST);
1150 sb.setWrapS(Sampler.Value.CLAMP);
1151 sb.setWrapT(Sampler.Value.CLAMP);
1152 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001153
Daniel Sandler388f6792010-03-02 14:08:08 -05001154 sb.setMin(Sampler.Value.NEAREST);
1155 sb.setMag(Sampler.Value.NEAREST);
1156 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001157
Joe Onorato2cc62e82010-03-17 20:23:53 -07001158 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001159 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1160 ProgramFragment.Builder.Format.RGBA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001161 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001162 ProgramFragment pfTexMip = bf.create();
1163 pfTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001164
Jason Sams070ada82010-08-04 17:53:07 -07001165 bf.setVaryingColor(false);
Jason Sams60a55bb2010-06-18 15:11:19 -07001166 ProgramFragment pfTexNearest = bf.create();
1167 pfTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001168
Daniel Sandler388f6792010-03-02 14:08:08 -05001169 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1170 ProgramFragment.Builder.Format.ALPHA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001171 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001172 ProgramFragment pfTexMipAlpha = bf.create();
1173 pfTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001174
Jason Sams60a55bb2010-06-18 15:11:19 -07001175 mScript.set_gPFTexNearest(pfTexNearest);
1176 mScript.set_gPFTexMip(pfTexMip);
1177 mScript.set_gPFTexMipAlpha(pfTexMipAlpha);
Daniel Sandler388f6792010-03-02 14:08:08 -05001178 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001179
Daniel Sandler388f6792010-03-02 14:08:08 -05001180 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001181 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001182 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1183 bs.setColorMask(true,true,true,false);
1184 bs.setDitherEnable(true);
1185 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1186 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Jason Sams14f67ed2010-05-11 14:02:43 -07001187 mScript.set_gPS(bs.create());
Daniel Sandler388f6792010-03-02 14:08:08 -05001188 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001189
Daniel Sandler388f6792010-03-02 14:08:08 -05001190 private void initGl() {
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 initData() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001194 mScript.set_COLUMNS_PER_PAGE_PORTRAIT(Defines.COLUMNS_PER_PAGE_PORTRAIT);
1195 mScript.set_ROWS_PER_PAGE_PORTRAIT(Defines.ROWS_PER_PAGE_PORTRAIT);
1196 mScript.set_COLUMNS_PER_PAGE_LANDSCAPE(Defines.COLUMNS_PER_PAGE_LANDSCAPE);
1197 mScript.set_ROWS_PER_PAGE_LANDSCAPE(Defines.ROWS_PER_PAGE_LANDSCAPE);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001198
Joe Onorato2cc62e82010-03-17 20:23:53 -07001199 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1200 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001201 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001202 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1203 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001204 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001205 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1206 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001207 mHomeButtonPressed.uploadToTexture(0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001208
Jason Sams14f67ed2010-05-11 14:02:43 -07001209 mScript.set_gHomeButton(mHomeButtonNormal);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001210
Daniel Sandler388f6792010-03-02 14:08:08 -05001211 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1212 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1213 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001214
Daniel Sandler388f6792010-03-02 14:08:08 -05001215 setApps(null);
1216 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001217
Daniel Sandler388f6792010-03-02 14:08:08 -05001218 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001219 if (sZoomDirty) {
1220 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001221 }
1222 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001223
Romain Guy060b5c82010-03-04 10:07:38 -08001224 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001225 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001226 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001227 final int count = list != null ? list.size() : 0;
1228 int allocCount = count;
1229 if (allocCount < 1) {
1230 allocCount = 1;
1231 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001232
Daniel Sandler388f6792010-03-02 14:08:08 -05001233 mIcons = new Allocation[count];
1234 mIconIds = new int[allocCount];
Jason Sams98994c42010-06-01 15:54:10 -07001235 mAllocIconIds = Allocation.createSized(sRS, Element.I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001236
Daniel Sandler388f6792010-03-02 14:08:08 -05001237 mLabels = new Allocation[count];
1238 mLabelIds = new int[allocCount];
Jason Sams98994c42010-06-01 15:54:10 -07001239 mAllocLabelIds = Allocation.createSized(sRS, Element.I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001240
Jason Sams14f67ed2010-05-11 14:02:43 -07001241 mScript.set_gIconCount(count);
1242 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001243 createAppIconAllocations(i, list.get(i));
1244 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001245 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001246 uploadAppIcon(i, list.get(i));
1247 }
1248 saveAppsList();
Jason Sams14f67ed2010-05-11 14:02:43 -07001249 android.util.Log.e("rs", "setApps");
Joe Onorato2cc62e82010-03-17 20:23:53 -07001250 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001251 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001252
Daniel Sandler388f6792010-03-02 14:08:08 -05001253 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001254 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001255 sRollo.clearSelectedIcon();
1256 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001257 }
Jason Sams60a55bb2010-06-18 15:11:19 -07001258 sRollo.mScript.invoke_setZoom(zoom, animate ? 1 : 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001259 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001260
Daniel Sandler388f6792010-03-02 14:08:08 -05001261 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001262 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1263 Element.RGBA_8888(sRS), false);
1264 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1265 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001266 mIconIds[index] = mIcons[index].getID();
1267 mLabelIds[index] = mLabels[index].getID();
1268 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001269
Daniel Sandler388f6792010-03-02 14:08:08 -05001270 private void uploadAppIcon(int index, ApplicationInfo item) {
1271 if (mIconIds[index] != mIcons[index].getID()) {
1272 throw new IllegalStateException("uploadAppIcon index=" + index
1273 + " mIcons[index].getID=" + mIcons[index].getID()
1274 + " mIconsIds[index]=" + mIconIds[index]
1275 + " item=" + item);
1276 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001277 mIcons[index].uploadToTexture(true, 0);
1278 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001279 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001280
Daniel Sandler388f6792010-03-02 14:08:08 -05001281 /**
1282 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1283 * fill in the values and call saveAppsList().
1284 */
1285 private void reallocAppsList(int count) {
1286 Allocation[] icons = new Allocation[count];
1287 int[] iconIds = new int[count];
Jason Sams98994c42010-06-01 15:54:10 -07001288 mAllocIconIds = Allocation.createSized(sRS, Element.I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001289
Daniel Sandler388f6792010-03-02 14:08:08 -05001290 Allocation[] labels = new Allocation[count];
1291 int[] labelIds = new int[count];
Jason Sams98994c42010-06-01 15:54:10 -07001292 mAllocLabelIds = Allocation.createSized(sRS, Element.I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001293
Jason Sams14f67ed2010-05-11 14:02:43 -07001294 final int oldCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001295
Daniel Sandler388f6792010-03-02 14:08:08 -05001296 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1297 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1298 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1299 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001300
Daniel Sandler388f6792010-03-02 14:08:08 -05001301 mIcons = icons;
1302 mIconIds = iconIds;
1303 mLabels = labels;
1304 mLabelIds = labelIds;
1305 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001306
Daniel Sandler388f6792010-03-02 14:08:08 -05001307 /**
1308 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1309 */
1310 private void addApp(int index, ApplicationInfo item) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001311 final int count = mScript.get_gIconCount() - index;
Daniel Sandler388f6792010-03-02 14:08:08 -05001312 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001313
Daniel Sandler388f6792010-03-02 14:08:08 -05001314 System.arraycopy(mIcons, index, mIcons, dest, count);
1315 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1316 System.arraycopy(mLabels, index, mLabels, dest, count);
1317 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001318
Daniel Sandler388f6792010-03-02 14:08:08 -05001319 createAppIconAllocations(index, item);
1320 uploadAppIcon(index, item);
Jason Sams14f67ed2010-05-11 14:02:43 -07001321
1322 mScript.set_gIconCount(mScript.get_gIconCount() + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001323 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001324
Daniel Sandler388f6792010-03-02 14:08:08 -05001325 /**
1326 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1327 */
1328 private void removeApp(int index) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001329 final int count = mScript.get_gIconCount() - index - 1;
Daniel Sandler388f6792010-03-02 14:08:08 -05001330 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001331
Daniel Sandler388f6792010-03-02 14:08:08 -05001332 System.arraycopy(mIcons, src, mIcons, index, count);
1333 System.arraycopy(mIconIds, src, mIconIds, index, count);
1334 System.arraycopy(mLabels, src, mLabels, index, count);
1335 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001336
Jason Sams14f67ed2010-05-11 14:02:43 -07001337 mScript.set_gIconCount(mScript.get_gIconCount() - 1);
1338 final int last = mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001339
Daniel Sandler388f6792010-03-02 14:08:08 -05001340 mIcons[last] = null;
1341 mIconIds[last] = 0;
1342 mLabels[last] = null;
1343 mLabelIds[last] = 0;
1344 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001345
Daniel Sandler388f6792010-03-02 14:08:08 -05001346 /**
1347 * Send the apps list structures to RS.
1348 */
1349 private void saveAppsList() {
1350 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1351 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001352 mAllocIconIds.data(mIconIds);
1353 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001354
Jason Sams14f67ed2010-05-11 14:02:43 -07001355 mScript.bind_gIconIDs(mAllocIconIds);
1356 mScript.bind_gLabelIDs(mAllocLabelIds);
Daniel Sandler388f6792010-03-02 14:08:08 -05001357 }
1358 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001359
Jason Sams60a55bb2010-06-18 15:11:19 -07001360 void fling(float pos, float v) {
1361 mScript.invoke_fling(pos, v);
Daniel Sandler388f6792010-03-02 14:08:08 -05001362 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001363
Jason Sams60a55bb2010-06-18 15:11:19 -07001364 void move(float pos) {
1365 mScript.invoke_move(pos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001366 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001367
Daniel Sandler388f6792010-03-02 14:08:08 -05001368 void moveTo(float row) {
Jason Sams60a55bb2010-06-18 15:11:19 -07001369 mScript.invoke_moveTo(row);
Daniel Sandler388f6792010-03-02 14:08:08 -05001370 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001371
Daniel Sandler388f6792010-03-02 14:08:08 -05001372 /**
1373 * You need to call save() on mState on your own after calling this.
1374 *
1375 * @return the index of the icon that was selected.
1376 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001377 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001378 if (mAllApps != null) {
1379 final int index = mAllApps.chooseTappedIcon(x, y);
1380 selectIcon(index, pressed);
1381 return index;
1382 } else {
1383 return -1;
1384 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001385 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001386
Daniel Sandler388f6792010-03-02 14:08:08 -05001387 /**
1388 * Select the icon at the given index.
1389 *
1390 * @param index The index.
1391 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1392 */
1393 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001394 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1395 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001396 if (mAllApps != null) {
1397 mAllApps.mRestoreFocusIndex = index;
1398 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001399 mScript.set_gSelectedIconIndex(-1);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001400 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1401 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001402 }
1403 } else {
1404 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001405 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001406 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001407
Jason Sams14f67ed2010-05-11 14:02:43 -07001408 int prev = mScript.get_gSelectedIconIndex();
1409 mScript.set_gSelectedIconIndex(index);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001410
Romain Guy13c2e7b2010-03-10 19:45:00 -08001411 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001412 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001413
Daniel Sandler388f6792010-03-02 14:08:08 -05001414 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1415 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1416 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001417
Jason Sams60a55bb2010-06-18 15:11:19 -07001418 Allocation si = Allocation.createFromBitmap(sRS, selectionBitmap,
Joe Onorato2cc62e82010-03-17 20:23:53 -07001419 Element.RGBA_8888(sRS), false);
Jason Sams60a55bb2010-06-18 15:11:19 -07001420 si.uploadToTexture(0);
1421 mScript.set_gSelectedIconTexture(si);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001422
Daniel Sandler388f6792010-03-02 14:08:08 -05001423 if (prev != index) {
1424 if (info.title != null && info.title.length() > 0) {
1425 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001426 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001427 }
1428 }
1429 }
1430 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001431
Daniel Sandler388f6792010-03-02 14:08:08 -05001432 /**
1433 * You need to call save() on mState on your own after calling this.
1434 */
1435 void clearSelectedIcon() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001436 mScript.set_gSelectedIconIndex(-1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001437 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001438
Daniel Sandler388f6792010-03-02 14:08:08 -05001439 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001440 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001441 switch (mode) {
1442 case SELECTED_NONE:
Jason Sams14f67ed2010-05-11 14:02:43 -07001443 mScript.set_gHomeButton(mHomeButtonNormal);
Daniel Sandler388f6792010-03-02 14:08:08 -05001444 break;
1445 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001446 mAllApps.mLastSelection = SELECTION_HOME;
Jason Sams14f67ed2010-05-11 14:02:43 -07001447 mScript.set_gHomeButton(mHomeButtonFocused);
Daniel Sandler388f6792010-03-02 14:08:08 -05001448 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001449 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001450 }
1451 break;
1452 case SELECTED_PRESSED:
Jason Sams14f67ed2010-05-11 14:02:43 -07001453 mScript.set_gHomeButton(mHomeButtonPressed);
Daniel Sandler388f6792010-03-02 14:08:08 -05001454 break;
1455 }
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, "sRollo.mWidth=" + mWidth);
1460 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1461 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001462 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001463 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001464 }
1465 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001466 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001467 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001468 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001469 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001470 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001471 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001472 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Jason Sams14f67ed2010-05-11 14:02:43 -07001473 //Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1474 //Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1475 //Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1476 //Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1477 //Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1478 //Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1479 //Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1480 //Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1481 //Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001482 }
1483 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001484
Daniel Sandler388f6792010-03-02 14:08:08 -05001485 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001486 Log.d(TAG, "sRS=" + sRS);
1487 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001488 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001489 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1490 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001491 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1492 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1493 Log.d(TAG, "mLastSelection=" + mLastSelection);
1494 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1495 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1496 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1497 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001498 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1499 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001500 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001501 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001502 Log.d(TAG, "mVelocity=" + mVelocity);
1503 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001504 if (sRollo != null) {
1505 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001506 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001507 if (sRS != null) {
1508 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001509 }
1510 }
1511}