blob: 3599775cada4fc0216e65e0d655dd04660ffd4b7 [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;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800195 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500196 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800197
Daniel Sandler388f6792010-03-02 14:08:08 -0500198 /**
199 * If you have an attached click listener, View always plays the click sound!?!?
200 * Deal with sound effects by hand.
201 */
202 public void reallyPlaySoundEffect(int sound) {
203 boolean old = isSoundEffectsEnabled();
204 setSoundEffectsEnabled(true);
205 playSoundEffect(sound);
206 setSoundEffectsEnabled(old);
207 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800208
Daniel Sandler388f6792010-03-02 14:08:08 -0500209 public void setLauncher(Launcher launcher) {
210 mLauncher = launcher;
211 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800212
Daniel Sandler388f6792010-03-02 14:08:08 -0500213 @Override
214 public void surfaceDestroyed(SurfaceHolder holder) {
215 super.surfaceDestroyed(holder);
216 // Without this, we leak mMessageCallback which leaks the context.
Romain Guy13c2e7b2010-03-10 19:45:00 -0800217 if (!mSurrendered) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700218 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800219 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500220 // We may lose any callbacks that are pending, so make sure that we re-sync that
221 // on the next surfaceChanged.
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700222 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500223 mHaveSurface = false;
224 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800225
Daniel Sandler388f6792010-03-02 14:08:08 -0500226 @Override
227 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
228 //long startTime = SystemClock.uptimeMillis();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800229
Daniel Sandler388f6792010-03-02 14:08:08 -0500230 super.surfaceChanged(holder, format, w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800231
Romain Guy13c2e7b2010-03-10 19:45:00 -0800232 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800233
Daniel Sandler388f6792010-03-02 14:08:08 -0500234 mHaveSurface = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800235
Joe Onorato2cc62e82010-03-17 20:23:53 -0700236 if (sRollo == null) {
237 sRollo = new RolloRS(this);
238 sRollo.init(getResources(), w, h);
Daniel Sandler388f6792010-03-02 14:08:08 -0500239 if (mAllAppsList != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700240 sRollo.setApps(mAllAppsList);
Daniel Sandler388f6792010-03-02 14:08:08 -0500241 }
242 if (mShouldGainFocus) {
243 gainFocus();
244 mShouldGainFocus = false;
245 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700246 } else if (sRollo.mInitialize) {
247 sRollo.initGl();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700248 sRollo.mInitialize = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500249 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800250
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700251 initTouchState(w, h);
252
Joe Onorato2cc62e82010-03-17 20:23:53 -0700253 sRollo.dirtyCheck();
254 sRollo.resize(w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800255
Jason Sams14f67ed2010-05-11 14:02:43 -0700256 Log.d(TAG, "sc " + sRS);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700257 if (sRS != null) {
258 sRS.mMessageCallback = mMessageProc = new AAMessage();
Daniel Sandler388f6792010-03-02 14:08:08 -0500259 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800260
Daniel Sandler388f6792010-03-02 14:08:08 -0500261 //long endTime = SystemClock.uptimeMillis();
262 //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
263 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800264
Daniel Sandler388f6792010-03-02 14:08:08 -0500265 @Override
266 public void onWindowFocusChanged(boolean hasWindowFocus) {
267 super.onWindowFocusChanged(hasWindowFocus);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800268
269 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800270
Daniel Sandler388f6792010-03-02 14:08:08 -0500271 if (mArrowNavigation) {
272 if (!hasWindowFocus) {
273 // Clear selection when we lose window focus
Jason Sams14f67ed2010-05-11 14:02:43 -0700274 mLastSelectedIcon = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700275 sRollo.setHomeSelected(SELECTED_NONE);
276 sRollo.clearSelectedIcon();
Romain Guy060b5c82010-03-04 10:07:38 -0800277 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700278 if (sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500279 if (mLastSelection == SELECTION_ICONS) {
280 int selection = mLastSelectedIcon;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700281 final int firstIcon = Math.round(sRollo.mScrollPos) * mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500282 if (selection < 0 || // No selection
283 selection < firstIcon || // off the top of the screen
Jason Sams14f67ed2010-05-11 14:02:43 -0700284 selection >= sRollo.mScript.get_gIconCount() || // past last icon
Daniel Sandler388f6792010-03-02 14:08:08 -0500285 selection >= firstIcon + // past last icon on screen
Romain Guy060b5c82010-03-04 10:07:38 -0800286 (mColumnsPerPage * mRowsPerPage)) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500287 selection = firstIcon;
288 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800289
Daniel Sandler388f6792010-03-02 14:08:08 -0500290 // Select the first icon when we gain window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700291 sRollo.selectIcon(selection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500292 } else if (mLastSelection == SELECTION_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700293 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500294 }
295 }
296 }
297 }
298 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800299
Daniel Sandler388f6792010-03-02 14:08:08 -0500300 @Override
301 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
302 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800303
Romain Guy13c2e7b2010-03-10 19:45:00 -0800304 if (!isVisible() || mSurrendered) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500305 return;
306 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800307
Daniel Sandler388f6792010-03-02 14:08:08 -0500308 if (gainFocus) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700309 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500310 gainFocus();
311 } else {
312 mShouldGainFocus = true;
313 }
314 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700315 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500316 if (mArrowNavigation) {
317 // Clear selection when we lose focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700318 sRollo.clearSelectedIcon();
319 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500320 mArrowNavigation = false;
321 }
322 } else {
323 mShouldGainFocus = false;
324 }
325 }
326 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800327
Daniel Sandler388f6792010-03-02 14:08:08 -0500328 private void gainFocus() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700329 if (!mArrowNavigation && sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500330 // Select the first icon when we gain keyboard focus
331 mArrowNavigation = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700332 sRollo.selectIcon(Math.round(sRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500333 }
334 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800335
Daniel Sandler388f6792010-03-02 14:08:08 -0500336 @Override
337 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800338
Daniel Sandler388f6792010-03-02 14:08:08 -0500339 boolean handled = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800340
Daniel Sandler388f6792010-03-02 14:08:08 -0500341 if (!isVisible()) {
342 return false;
343 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700344 final int iconCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800345
Daniel Sandler388f6792010-03-02 14:08:08 -0500346 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
347 if (mArrowNavigation) {
348 if (mLastSelection == SELECTION_HOME) {
349 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
350 mLauncher.closeAllApps(true);
351 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700352 int whichApp = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500353 if (whichApp >= 0) {
354 ApplicationInfo app = mAllAppsList.get(whichApp);
Joe Onoratof984e852010-03-25 09:47:45 -0700355 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500356 handled = true;
357 }
358 }
359 }
360 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800361
Daniel Sandler388f6792010-03-02 14:08:08 -0500362 if (iconCount > 0) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800363 final boolean isPortrait = getWidth() < getHeight();
Jason Sams14f67ed2010-05-11 14:02:43 -0700364
Daniel Sandler388f6792010-03-02 14:08:08 -0500365 mArrowNavigation = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800366
Jason Sams14f67ed2010-05-11 14:02:43 -0700367 int currentSelection = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700368 int currentTopRow = Math.round(sRollo.mScrollPos);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800369
Romain Guy060b5c82010-03-04 10:07:38 -0800370 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1
371 final int currentPageCol = currentSelection % mColumnsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800372
Romain Guy060b5c82010-03-04 10:07:38 -0800373 // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1
Romain Guy6a42cf32010-03-12 16:03:52 -0800374 final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage))
Romain Guy060b5c82010-03-04 10:07:38 -0800375 / mRowsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800376
Daniel Sandler388f6792010-03-02 14:08:08 -0500377 int newSelection = currentSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800378
Daniel Sandler388f6792010-03-02 14:08:08 -0500379 switch (keyCode) {
380 case KeyEvent.KEYCODE_DPAD_UP:
381 if (mLastSelection == SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800382 if (isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700383 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guy6a42cf32010-03-12 16:03:52 -0800384 int lastRowCount = iconCount % mColumnsPerPage;
385 if (lastRowCount == 0) {
386 lastRowCount = mColumnsPerPage;
387 }
388 newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2);
389 if (newSelection >= iconCount) {
390 newSelection = iconCount-1;
391 }
392 int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
393 if (target < 0) {
394 target = 0;
395 }
396 if (currentTopRow != target) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700397 sRollo.moveTo(target);
Romain Guy6a42cf32010-03-12 16:03:52 -0800398 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500399 }
400 } else {
401 if (currentPageRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800402 newSelection = currentSelection - mColumnsPerPage;
Romain Guy6a42cf32010-03-12 16:03:52 -0800403 if (currentTopRow > newSelection / mColumnsPerPage) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700404 sRollo.moveTo(newSelection / mColumnsPerPage);
Romain Guy6a42cf32010-03-12 16:03:52 -0800405 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500406 } else if (currentTopRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800407 newSelection = currentSelection - mColumnsPerPage;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700408 sRollo.moveTo(newSelection / mColumnsPerPage);
Daniel Sandler388f6792010-03-02 14:08:08 -0500409 } else if (currentPageRow != 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800410 newSelection = currentTopRow * mRowsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500411 }
412 }
413 handled = true;
414 break;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800415
Daniel Sandler388f6792010-03-02 14:08:08 -0500416 case KeyEvent.KEYCODE_DPAD_DOWN: {
Romain Guy060b5c82010-03-04 10:07:38 -0800417 final int rowCount = iconCount / mColumnsPerPage
418 + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
419 final int currentRow = currentSelection / mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500420 if (mLastSelection != SELECTION_HOME) {
421 if (currentRow < rowCount-1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700422 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500423 if (currentSelection < 0) {
424 newSelection = 0;
425 } else {
Romain Guy060b5c82010-03-04 10:07:38 -0800426 newSelection = currentSelection + mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500427 }
428 if (newSelection >= iconCount) {
429 // Go from D to G in this arrangement:
430 // A B C D
431 // E F G
432 newSelection = iconCount - 1;
433 }
Romain Guy060b5c82010-03-04 10:07:38 -0800434 if (currentPageRow >= mRowsPerPage - 1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700435 sRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -0500436 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800437 } else if (isPortrait) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500438 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700439 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500440 }
441 }
442 handled = true;
443 break;
444 }
445 case KeyEvent.KEYCODE_DPAD_LEFT:
446 if (mLastSelection != SELECTION_HOME) {
447 if (currentPageCol > 0) {
448 newSelection = currentSelection - 1;
449 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800450 } else if (!isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700451 newSelection = ((int) (sRollo.mScrollPos) * mColumnsPerPage) +
Romain Guy6a42cf32010-03-12 16:03:52 -0800452 (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700453 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500454 }
455 handled = true;
456 break;
457 case KeyEvent.KEYCODE_DPAD_RIGHT:
458 if (mLastSelection != SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800459 if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 ||
460 currentSelection == iconCount - 1)) {
461 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700462 sRollo.setHomeSelected(SELECTED_FOCUSED);
Romain Guy6a42cf32010-03-12 16:03:52 -0800463 } else if ((currentPageCol < mColumnsPerPage - 1) &&
Daniel Sandler388f6792010-03-02 14:08:08 -0500464 (currentSelection < iconCount - 1)) {
465 newSelection = currentSelection + 1;
466 }
467 }
468 handled = true;
469 break;
470 }
471 if (newSelection != currentSelection) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700472 sRollo.selectIcon(newSelection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500473 }
474 }
475 return handled;
476 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800477
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700478 void initTouchState(int width, int height) {
479 boolean isPortrait = width < height;
480
481 int[] viewPos = new int[2];
482 getLocationOnScreen(viewPos);
483
484 mTouchXBorders = new int[mColumnsPerPage + 1];
485 mTouchYBorders = new int[mRowsPerPage + 1];
486
487 // TODO: Put this in a config file/define
488 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE_PORTRAIT;
489 if (!isPortrait) cellHeight -= 12;
490 int centerY = (int) (height * (isPortrait ? 0.5f : 0.47f));
491 if (!isPortrait) centerY += cellHeight / 2;
492 int half = (int) Math.floor((mRowsPerPage + 1) / 2);
493 int end = mTouchYBorders.length - (half + 1);
494
495 for (int i = -half; i <= end; i++) {
496 mTouchYBorders[i + half] = centerY + (i * cellHeight) - viewPos[1];
497 }
498
499 int x = 0;
500 // TODO: Put this in a config file/define
501 int columnWidth = 120;
502 for (int i = 0; i < mColumnsPerPage + 1; i++) {
503 mTouchXBorders[i] = x - viewPos[0];
504 x += columnWidth;
505 }
506 }
507
508 int chooseTappedIcon(int x, int y) {
509 float pos = sRollo != null ? sRollo.mScrollPos : 0;
510
511 int oldY = y;
512
513 // Adjust for scroll position if not zero.
514 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
515
516 int col = -1;
517 int row = -1;
518 final int columnsCount = mColumnsPerPage;
519 for (int i=0; i< columnsCount; i++) {
520 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
521 col = i;
522 break;
523 }
524 }
525 final int rowsCount = mRowsPerPage;
526 for (int i=0; i< rowsCount; i++) {
527 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
528 row = i;
529 break;
530 }
531 }
532
533 if (row < 0 || col < 0) {
534 return -1;
535 }
536
537 int index = (((int) pos) * columnsCount) + (row * columnsCount) + col;
538
539 if (index >= mAllAppsList.size()) {
540 return -1;
541 } else {
542 return index;
543 }
544 }
545
Daniel Sandler388f6792010-03-02 14:08:08 -0500546 @Override
547 public boolean onTouchEvent(MotionEvent ev)
548 {
549 mArrowNavigation = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800550
Daniel Sandler388f6792010-03-02 14:08:08 -0500551 if (!isVisible()) {
552 return true;
553 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800554
Daniel Sandler388f6792010-03-02 14:08:08 -0500555 if (mLocks != 0) {
556 return true;
557 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800558
Daniel Sandler388f6792010-03-02 14:08:08 -0500559 super.onTouchEvent(ev);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800560
Daniel Sandler388f6792010-03-02 14:08:08 -0500561 int x = (int)ev.getX();
562 int y = (int)ev.getY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800563
Romain Guyce115852010-03-04 12:15:37 -0800564 final boolean isPortrait = getWidth() < getHeight();
Daniel Sandler388f6792010-03-02 14:08:08 -0500565 int action = ev.getAction();
566 switch (action) {
567 case MotionEvent.ACTION_DOWN:
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700568 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
569 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500570 mTouchTracking = TRACKING_HOME;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700571 sRollo.setHomeSelected(SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500572 mCurrentIconIndex = -1;
573 } else {
574 mTouchTracking = TRACKING_FLING;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800575
Daniel Sandler388f6792010-03-02 14:08:08 -0500576 mMotionDownRawX = (int)ev.getRawX();
577 mMotionDownRawY = (int)ev.getRawY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800578
Joe Onorato2cc62e82010-03-17 20:23:53 -0700579 if (!sRollo.checkClickOK()) {
580 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500581 } else {
582 mDownIconIndex = mCurrentIconIndex
Joe Onorato2cc62e82010-03-17 20:23:53 -0700583 = sRollo.selectIcon(x, y, SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500584 if (mDownIconIndex < 0) {
585 // if nothing was selected, no long press.
586 cancelLongPress();
587 }
588 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700589 sRollo.move(ev.getRawY() / getHeight());
Daniel Sandler388f6792010-03-02 14:08:08 -0500590 mVelocityTracker = VelocityTracker.obtain();
591 mVelocityTracker.addMovement(ev);
592 mStartedScrolling = false;
593 }
594 break;
595 case MotionEvent.ACTION_MOVE:
596 case MotionEvent.ACTION_OUTSIDE:
597 if (mTouchTracking == TRACKING_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700598 sRollo.setHomeSelected((isPortrait &&
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700599 y > mTouchYBorders[mTouchYBorders.length-1]) || (!isPortrait
600 && x > mTouchXBorders[mTouchXBorders.length-1])
Daniel Sandler388f6792010-03-02 14:08:08 -0500601 ? SELECTED_PRESSED : SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500602 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500603 int rawY = (int)ev.getRawY();
604 int slop;
605 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800606
Daniel Sandler388f6792010-03-02 14:08:08 -0500607 if (!mStartedScrolling && slop < mSlop) {
608 // don't update anything so when we do start scrolling
609 // below, we get the right delta.
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700610 mCurrentIconIndex = chooseTappedIcon(x, y);
Daniel Sandler388f6792010-03-02 14:08:08 -0500611 if (mDownIconIndex != mCurrentIconIndex) {
612 // If a different icon is selected, don't allow it to be picked up.
613 // This handles off-axis dragging.
614 cancelLongPress();
615 mCurrentIconIndex = -1;
616 }
617 } else {
618 if (!mStartedScrolling) {
619 cancelLongPress();
620 mCurrentIconIndex = -1;
621 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700622 sRollo.move(ev.getRawY() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800623
Daniel Sandler388f6792010-03-02 14:08:08 -0500624 mStartedScrolling = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700625 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500626 mVelocityTracker.addMovement(ev);
Daniel Sandler388f6792010-03-02 14:08:08 -0500627 }
628 }
629 break;
630 case MotionEvent.ACTION_UP:
631 case MotionEvent.ACTION_CANCEL:
632 if (mTouchTracking == TRACKING_HOME) {
633 if (action == MotionEvent.ACTION_UP) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700634 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
635 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500636 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
637 mLauncher.closeAllApps(true);
638 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700639 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500640 }
641 mCurrentIconIndex = -1;
642 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500643 mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700644 sRollo.clearSelectedIcon();
Jason Sams60a55bb2010-06-18 15:11:19 -0700645 sRollo.fling(ev.getRawY() / getHeight(),
646 mVelocityTracker.getYVelocity() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800647
Daniel Sandler388f6792010-03-02 14:08:08 -0500648 if (mVelocityTracker != null) {
649 mVelocityTracker.recycle();
650 mVelocityTracker = null;
651 }
652 }
653 mTouchTracking = TRACKING_NONE;
654 break;
655 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800656
Daniel Sandler388f6792010-03-02 14:08:08 -0500657 return true;
658 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800659
Daniel Sandler388f6792010-03-02 14:08:08 -0500660 public void onClick(View v) {
661 if (mLocks != 0 || !isVisible()) {
662 return;
663 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700664 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500665 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
666 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
667 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onoratof984e852010-03-25 09:47:45 -0700668 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500669 }
670 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800671
Daniel Sandler388f6792010-03-02 14:08:08 -0500672 public boolean onLongClick(View v) {
Joe Onorato6b4adbc2010-09-01 12:13:25 -0700673 // We don't accept long click events in these cases
674 // - If the workspace isn't ready to accept a drop
675 // - If we're not done loading (because we might be confused about which item
676 // to pick up
677 // - If we're not visible
678 if (!isVisible() || mLauncher.isWorkspaceLocked() || mLocks != 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500679 return true;
680 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700681 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500682 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
683 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800684
Daniel Sandler388f6792010-03-02 14:08:08 -0500685 Bitmap bmp = app.iconBitmap;
686 final int w = bmp.getWidth();
687 final int h = bmp.getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800688
Daniel Sandler388f6792010-03-02 14:08:08 -0500689 // We don't really have an accurate location to use. This will do.
690 int screenX = mMotionDownRawX - (w / 2);
691 int screenY = mMotionDownRawY - h;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800692
Daniel Sandler388f6792010-03-02 14:08:08 -0500693 mDragController.startDrag(bmp, screenX, screenY,
694 0, 0, w, h, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800695
Daniel Sandler388f6792010-03-02 14:08:08 -0500696 mLauncher.closeAllApps(true);
697 }
698 return true;
699 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800700
Daniel Sandler388f6792010-03-02 14:08:08 -0500701 @Override
702 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
703 if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
704 if (!isVisible()) {
705 return false;
706 }
707 String text = null;
708 int index;
709 int count = mAllAppsList.size() + 1; // +1 is home
710 int pos = -1;
711 switch (mLastSelection) {
712 case SELECTION_ICONS:
Jason Sams14f67ed2010-05-11 14:02:43 -0700713 index = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500714 if (index >= 0) {
715 ApplicationInfo info = mAllAppsList.get(index);
716 if (info.title != null) {
717 text = info.title.toString();
718 pos = index;
719 }
720 }
721 break;
722 case SELECTION_HOME:
723 text = getContext().getString(R.string.all_apps_home_button_label);
724 pos = count;
725 break;
726 }
727 if (text != null) {
728 event.setEnabled(true);
729 event.getText().add(text);
730 //event.setContentDescription(text);
731 event.setItemCount(count);
732 event.setCurrentItemIndex(pos);
733 }
734 }
735 return false;
736 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800737
Patrick Dubroya669d792010-11-23 14:40:33 -0800738 @Override
Daniel Sandler388f6792010-03-02 14:08:08 -0500739 public void setDragController(DragController dragger) {
740 mDragController = dragger;
741 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800742
Patrick Dubroya669d792010-11-23 14:40:33 -0800743 @Override
744 public void onDragViewVisible() {
745 }
746
747 @Override
Daniel Sandler388f6792010-03-02 14:08:08 -0500748 public void onDropCompleted(View target, boolean success) {
749 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800750
Daniel Sandler388f6792010-03-02 14:08:08 -0500751 /**
752 * Zoom to the specifed level.
753 *
754 * @param zoom [0..1] 0 is hidden, 1 is open
755 */
756 public void zoom(float zoom, boolean animate) {
757 cancelLongPress();
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700758 sNextZoom = zoom;
759 sAnimateNextZoom = animate;
Daniel Sandler388f6792010-03-02 14:08:08 -0500760 // if we do setZoom while we don't have a surface, we won't
761 // get the callbacks that actually set mZoom.
Joe Onorato2cc62e82010-03-17 20:23:53 -0700762 if (sRollo == null || !mHaveSurface) {
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700763 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500764 mZoom = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500765 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700766 sRollo.setZoom(zoom, animate);
Daniel Sandler388f6792010-03-02 14:08:08 -0500767 }
768 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800769
Joe Onorato878f0862010-03-22 12:22:22 -0400770 /**
771 * If sRollo is null, then we're not visible. This is also used to guard against
772 * sRollo being null.
773 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500774 public boolean isVisible() {
Joe Onorato878f0862010-03-22 12:22:22 -0400775 return sRollo != null && mZoom > 0.001f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500776 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800777
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700778 public boolean isAnimating() {
779 return isVisible() && mZoom <= 0.999f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500780 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800781
Daniel Sandler388f6792010-03-02 14:08:08 -0500782 public void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700783 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500784 // We've been removed from the window. Don't bother with all this.
785 return;
786 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800787
Daniel Sandler707b0f72010-04-15 16:41:31 -0400788 if (list != null) {
789 Collections.sort(list, LauncherModel.APP_NAME_COMPARATOR);
790 }
791
Romain Guy13c2e7b2010-03-10 19:45:00 -0800792 boolean reload = false;
793 if (mAllAppsList == null) {
794 reload = true;
795 } else if (list.size() != mAllAppsList.size()) {
796 reload = true;
797 } else {
798 final int count = list.size();
799 for (int i = 0; i < count; i++) {
800 if (list.get(i) != mAllAppsList.get(i)) {
801 reload = true;
802 break;
803 }
804 }
805 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800806
Daniel Sandler388f6792010-03-02 14:08:08 -0500807 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700808 if (sRollo != null && reload) {
809 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500810 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700811
Romain Guyc16fea72010-03-12 17:17:56 -0800812 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700813 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
Romain Guyc16fea72010-03-12 17:17:56 -0800814 mRestoreFocusIndex = -1;
815 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700816
Daniel Sandler388f6792010-03-02 14:08:08 -0500817 mLocks &= ~LOCK_ICONS_PENDING;
818 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800819
Daniel Sandler388f6792010-03-02 14:08:08 -0500820 public void addApps(ArrayList<ApplicationInfo> list) {
821 if (mAllAppsList == null) {
822 // Not done loading yet. We'll find out about it later.
823 return;
824 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700825 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500826 // We've been removed from the window. Don't bother with all this.
827 return;
828 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800829
Daniel Sandler388f6792010-03-02 14:08:08 -0500830 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700831 if (sRollo != null) {
832 sRollo.pause();
Jason Sams14f67ed2010-05-11 14:02:43 -0700833 sRollo.reallocAppsList(sRollo.mScript.get_gIconCount() + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500834 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800835
Daniel Sandler388f6792010-03-02 14:08:08 -0500836 for (int i=0; i<N; i++) {
837 final ApplicationInfo item = list.get(i);
838 int index = Collections.binarySearch(mAllAppsList, item,
839 LauncherModel.APP_NAME_COMPARATOR);
840 if (index < 0) {
841 index = -(index+1);
842 }
843 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700844 if (sRollo != null) {
845 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500846 }
847 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800848
Joe Onorato2cc62e82010-03-17 20:23:53 -0700849 if (sRollo != null) {
850 sRollo.saveAppsList();
851 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500852 }
853 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800854
Daniel Sandler388f6792010-03-02 14:08:08 -0500855 public void removeApps(ArrayList<ApplicationInfo> list) {
856 if (mAllAppsList == null) {
857 // Not done loading yet. We'll find out about it later.
858 return;
859 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800860
Joe Onorato2cc62e82010-03-17 20:23:53 -0700861 if (sRollo != null) {
862 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800863 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500864 final int N = list.size();
865 for (int i=0; i<N; i++) {
866 final ApplicationInfo item = list.get(i);
867 int index = findAppByComponent(mAllAppsList, item);
868 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500869 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700870 if (sRollo != null) {
871 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500872 }
873 } else {
874 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
875 // Try to recover. This should keep us from crashing for now.
876 }
877 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800878
Joe Onorato2cc62e82010-03-17 20:23:53 -0700879 if (sRollo != null) {
880 sRollo.saveAppsList();
881 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500882 }
883 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800884
Joe Onorato64e6be72010-03-05 15:05:52 -0500885 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500886 // Just remove and add, because they may need to be re-sorted.
887 removeApps(list);
888 addApps(list);
889 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800890
Daniel Sandler388f6792010-03-02 14:08:08 -0500891 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
892 ComponentName component = item.intent.getComponent();
893 final int N = list.size();
894 for (int i=0; i<N; i++) {
895 ApplicationInfo x = list.get(i);
896 if (x.intent.getComponent().equals(component)) {
897 return i;
898 }
899 }
900 return -1;
901 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800902
Daniel Sandler388f6792010-03-02 14:08:08 -0500903 class AAMessage extends RenderScript.RSMessage {
904 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700905 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500906 mVelocity = ((float)mData[1]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700907
908 boolean lastVisible = isVisible();
Daniel Sandler388f6792010-03-02 14:08:08 -0500909 mZoom = ((float)mData[2]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700910
911 final boolean visible = isVisible();
912 if (visible != lastVisible) {
913 post(new Runnable() {
914 public void run() {
915 if (visible) {
916 showSurface();
917 } else {
918 hideSurface();
919 }
920 }
921 });
922 }
923
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700924 sZoomDirty = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500925 }
926 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800927
Romain Guy13c2e7b2010-03-10 19:45:00 -0800928 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500929 // Allocations ======
930 private int mWidth;
931 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800932
Daniel Sandler388f6792010-03-02 14:08:08 -0500933 private Resources mRes;
Stephen Hinesb2d69862010-09-16 17:21:50 -0700934 ScriptC_allapps mScript;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800935
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700936 private Mesh mMesh;
Daniel Sandler388f6792010-03-02 14:08:08 -0500937 private ProgramVertex.MatrixAllocation mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800938
Jason Sams14f67ed2010-05-11 14:02:43 -0700939 private ScriptField_VpConsts mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800940
Daniel Sandler388f6792010-03-02 14:08:08 -0500941 private Allocation mHomeButtonNormal;
942 private Allocation mHomeButtonFocused;
943 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800944
Daniel Sandler388f6792010-03-02 14:08:08 -0500945 private Allocation[] mIcons;
946 private int[] mIconIds;
947 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800948
Daniel Sandler388f6792010-03-02 14:08:08 -0500949 private Allocation[] mLabels;
950 private int[] mLabelIds;
951 private Allocation mAllocLabelIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800952
Daniel Sandler388f6792010-03-02 14:08:08 -0500953 private Bitmap mSelectionBitmap;
954 private Canvas mSelectionCanvas;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800955
Jason Sams14f67ed2010-05-11 14:02:43 -0700956 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800957
Romain Guy13c2e7b2010-03-10 19:45:00 -0800958 AllApps3D mAllApps;
959 boolean mInitialize;
960
Daniel Sandler388f6792010-03-02 14:08:08 -0500961 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -0800962 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -0800963 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -0500964 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800965
966 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400967 if (sRS != null) {
968 sRS.contextBindRootScript(null);
969 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800970 }
971
972 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400973 if (sRS != null) {
974 sRS.contextBindRootScript(mScript);
975 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800976 }
977
Romain Guy13c2e7b2010-03-10 19:45:00 -0800978 public RolloRS(AllApps3D allApps) {
979 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -0500980 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800981
Daniel Sandler388f6792010-03-02 14:08:08 -0500982 public void init(Resources res, int width, int height) {
983 mRes = res;
984 mWidth = width;
985 mHeight = height;
Stephen Hinesb2d69862010-09-16 17:21:50 -0700986 mScript = new ScriptC_allapps(sRS, mRes, R.raw.allapps, true);
Jason Sams14f67ed2010-05-11 14:02:43 -0700987
Daniel Sandler388f6792010-03-02 14:08:08 -0500988 initProgramVertex();
989 initProgramFragment();
990 initProgramStore();
991 initGl();
992 initData();
Jason Sams14f67ed2010-05-11 14:02:43 -0700993
994 mScript.bind_gIconIDs(mAllocIconIds);
995 mScript.bind_gLabelIDs(mAllocLabelIds);
Jason Sams14f67ed2010-05-11 14:02:43 -0700996 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -0500997 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800998
Daniel Sandler388f6792010-03-02 14:08:08 -0500999 public void initMesh() {
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001000 Mesh.TriangleMeshBuilder tm = new Mesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001001
Daniel Sandler388f6792010-03-02 14:08:08 -05001002 for (int ct=0; ct < 16; ct++) {
1003 float pos = (1.f / (16.f - 1)) * ct;
1004 tm.addVertex(0.0f, pos);
1005 tm.addVertex(1.0f, pos);
1006 }
1007 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1008 tm.addTriangle(ct, ct+1, ct+2);
1009 tm.addTriangle(ct+1, ct+3, ct+2);
1010 }
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001011 mMesh = tm.create(true);
Jason Sams14f67ed2010-05-11 14:02:43 -07001012 mScript.set_gSMCell(mMesh);
Daniel Sandler388f6792010-03-02 14:08:08 -05001013 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001014
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001015 Matrix4f getProjectionMatrix(int w, int h) {
1016 // range -1,1 in the narrow axis at z = 0.
1017 Matrix4f m1 = new Matrix4f();
1018 Matrix4f m2 = new Matrix4f();
1019
1020 if(w > h) {
1021 float aspect = ((float)w) / h;
1022 m1.loadFrustum(-aspect,aspect, -1,1, 1,100);
1023 } else {
1024 float aspect = ((float)h) / w;
1025 m1.loadFrustum(-1,1, -aspect,aspect, 1,100);
1026 }
1027
1028 m2.loadRotate(180, 0, 1, 0);
1029 m1.loadMultiply(m1, m2);
1030
1031 m2.loadScale(-2, 2, 1);
1032 m1.loadMultiply(m1, m2);
1033
1034 m2.loadTranslate(0, 0, 2);
1035 m1.loadMultiply(m1, m2);
1036 return m1;
1037 }
1038
Daniel Sandler388f6792010-03-02 14:08:08 -05001039 void resize(int w, int h) {
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001040 Matrix4f proj = getProjectionMatrix(w, h);
1041 mPVA.loadProjection(proj);
1042
1043 if (mUniformAlloc != null) {
1044 ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
1045 i.Proj = proj;
1046 i.ScaleOffset.x = (2.f / 480.f);
1047 i.ScaleOffset.y = 0;
1048 i.ScaleOffset.z = -((float)w / 2) - 0.25f;
1049 i.ScaleOffset.w = -380.25f;
1050 i.BendPos.x = 120.f;
1051 i.BendPos.y = 680.f;
1052 if (w > h) {
1053 i.ScaleOffset.z = 40.f;
1054 i.ScaleOffset.w = h - 40.f;
1055 i.BendPos.y = 1.f;
1056 }
1057 mUniformAlloc.set(i, 0, true);
1058 }
1059
Daniel Sandler388f6792010-03-02 14:08:08 -05001060 mWidth = w;
1061 mHeight = h;
1062 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001063
Daniel Sandler388f6792010-03-02 14:08:08 -05001064 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001065 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001066 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001067
Joe Onorato2cc62e82010-03-17 20:23:53 -07001068 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001069 pvb.setTextureMatrixEnable(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001070 ProgramVertex pv = pvb.create();
1071 pv.bindAllocation(mPVA);
1072 sRS.contextBindProgramVertex(pv);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001073
Jason Sams14f67ed2010-05-11 14:02:43 -07001074 mUniformAlloc = new ScriptField_VpConsts(sRS, 1);
1075 mScript.bind_vpConstants(mUniformAlloc);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001076
Daniel Sandler388f6792010-03-02 14:08:08 -05001077 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001078 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001079 String t = "varying vec4 varColor;\n" +
Alex Sakhartchouk2f3b0b62010-10-06 09:32:12 -07001080 "varying vec2 varTex0;\n" +
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001081 "void main() {\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001082 // Animation
1083 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001084
Romain Guy060b5c82010-03-04 10:07:38 -08001085 " float bendY1 = UNI_BendPos.x;\n" +
1086 " float bendY2 = UNI_BendPos.y;\n" +
1087 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1088 " float bendDistance = bendY1 * 0.4;\n" +
1089 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001090
Romain Guy060b5c82010-03-04 10:07:38 -08001091 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1092 " float aDy = cos(bendAngle);\n" +
1093 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001094
Romain Guy060b5c82010-03-04 10:07:38 -08001095 " float scale = (2.0 / 480.0);\n" +
1096 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1097 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1098 " float y = 0.0;\n" +
1099 " float z = 0.0;\n" +
1100 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001101
Romain Guy060b5c82010-03-04 10:07:38 -08001102 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1103 " y += cv * aDy;\n" +
1104 " z += -cv * aDz;\n" +
1105 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1106 " lum += cv / bendDistance * distanceDimLevel;\n" +
1107 " y += cv * cos(cv * bendStep);\n" +
1108 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001109
Romain Guy060b5c82010-03-04 10:07:38 -08001110 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1111 " y += cv * aDy;\n" +
1112 " z += cv * aDz;\n" +
1113 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1114 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1115 " y += cv * cos(cv * bendStep);\n" +
1116 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001117
Romain Guy060b5c82010-03-04 10:07:38 -08001118 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001119
Romain Guy060b5c82010-03-04 10:07:38 -08001120 " vec4 pos;\n" +
1121 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1122 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1123 " pos.z = z * UNI_ScaleOffset.x;\n" +
1124 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001125
Romain Guy060b5c82010-03-04 10:07:38 -08001126 " pos.x *= 1.0 + ani * 4.0;\n" +
1127 " pos.y *= 1.0 + ani * 4.0;\n" +
1128 " pos.z -= ani * 1.5;\n" +
1129 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001130
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001131 " gl_Position = UNI_Proj * pos;\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001132 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1133 " varTex0.xy = ATTRIB_position;\n" +
1134 " varTex0.y = 1.0 - varTex0.y;\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001135 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001136 sb.setShader(t);
1137 sb.addConstant(mUniformAlloc.getType());
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001138 sb.addInput(mMesh.getVertexAllocation(0).getType().getElement());
Jason Sams60a55bb2010-06-18 15:11:19 -07001139 ProgramVertex pvc = sb.create();
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001140 pvc.bindConstants(mUniformAlloc.getAllocation(), 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001141
Jason Sams60a55bb2010-06-18 15:11:19 -07001142 mScript.set_gPVCurve(pvc);
Daniel Sandler388f6792010-03-02 14:08:08 -05001143 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001144
Daniel Sandler388f6792010-03-02 14:08:08 -05001145 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001146 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001147 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1148 sb.setMag(Sampler.Value.NEAREST);
1149 sb.setWrapS(Sampler.Value.CLAMP);
1150 sb.setWrapT(Sampler.Value.CLAMP);
1151 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001152
Daniel Sandler388f6792010-03-02 14:08:08 -05001153 sb.setMin(Sampler.Value.NEAREST);
1154 sb.setMag(Sampler.Value.NEAREST);
1155 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001156
Joe Onorato2cc62e82010-03-17 20:23:53 -07001157 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001158 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1159 ProgramFragment.Builder.Format.RGBA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001160 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001161 ProgramFragment pfTexMip = bf.create();
1162 pfTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001163
Jason Sams070ada82010-08-04 17:53:07 -07001164 bf.setVaryingColor(false);
Jason Sams60a55bb2010-06-18 15:11:19 -07001165 ProgramFragment pfTexNearest = bf.create();
1166 pfTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001167
Daniel Sandler388f6792010-03-02 14:08:08 -05001168 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1169 ProgramFragment.Builder.Format.ALPHA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001170 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001171 ProgramFragment pfTexMipAlpha = bf.create();
1172 pfTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001173
Jason Sams60a55bb2010-06-18 15:11:19 -07001174 mScript.set_gPFTexNearest(pfTexNearest);
1175 mScript.set_gPFTexMip(pfTexMip);
1176 mScript.set_gPFTexMipAlpha(pfTexMipAlpha);
Daniel Sandler388f6792010-03-02 14:08:08 -05001177 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001178
Daniel Sandler388f6792010-03-02 14:08:08 -05001179 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001180 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001181 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1182 bs.setColorMask(true,true,true,false);
1183 bs.setDitherEnable(true);
1184 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1185 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Jason Sams14f67ed2010-05-11 14:02:43 -07001186 mScript.set_gPS(bs.create());
Daniel Sandler388f6792010-03-02 14:08:08 -05001187 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001188
Daniel Sandler388f6792010-03-02 14:08:08 -05001189 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001190 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001191
Daniel Sandler388f6792010-03-02 14:08:08 -05001192 private void initData() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001193 mScript.set_COLUMNS_PER_PAGE_PORTRAIT(Defines.COLUMNS_PER_PAGE_PORTRAIT);
1194 mScript.set_ROWS_PER_PAGE_PORTRAIT(Defines.ROWS_PER_PAGE_PORTRAIT);
1195 mScript.set_COLUMNS_PER_PAGE_LANDSCAPE(Defines.COLUMNS_PER_PAGE_LANDSCAPE);
1196 mScript.set_ROWS_PER_PAGE_LANDSCAPE(Defines.ROWS_PER_PAGE_LANDSCAPE);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001197
Joe Onorato2cc62e82010-03-17 20:23:53 -07001198 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1199 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001200 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001201 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1202 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001203 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001204 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1205 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001206 mHomeButtonPressed.uploadToTexture(0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001207
Jason Sams14f67ed2010-05-11 14:02:43 -07001208 mScript.set_gHomeButton(mHomeButtonNormal);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001209
Daniel Sandler388f6792010-03-02 14:08:08 -05001210 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1211 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1212 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001213
Daniel Sandler388f6792010-03-02 14:08:08 -05001214 setApps(null);
1215 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001216
Daniel Sandler388f6792010-03-02 14:08:08 -05001217 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001218 if (sZoomDirty) {
1219 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001220 }
1221 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001222
Romain Guy060b5c82010-03-04 10:07:38 -08001223 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001224 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001225 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001226 final int count = list != null ? list.size() : 0;
1227 int allocCount = count;
1228 if (allocCount < 1) {
1229 allocCount = 1;
1230 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001231
Daniel Sandler388f6792010-03-02 14:08:08 -05001232 mIcons = new Allocation[count];
1233 mIconIds = new int[allocCount];
Jason Sams98994c42010-06-01 15:54:10 -07001234 mAllocIconIds = Allocation.createSized(sRS, Element.I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001235
Daniel Sandler388f6792010-03-02 14:08:08 -05001236 mLabels = new Allocation[count];
1237 mLabelIds = new int[allocCount];
Jason Sams98994c42010-06-01 15:54:10 -07001238 mAllocLabelIds = Allocation.createSized(sRS, Element.I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001239
Jason Sams14f67ed2010-05-11 14:02:43 -07001240 mScript.set_gIconCount(count);
1241 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001242 createAppIconAllocations(i, list.get(i));
1243 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001244 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001245 uploadAppIcon(i, list.get(i));
1246 }
1247 saveAppsList();
Jason Sams14f67ed2010-05-11 14:02:43 -07001248 android.util.Log.e("rs", "setApps");
Joe Onorato2cc62e82010-03-17 20:23:53 -07001249 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001250 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001251
Daniel Sandler388f6792010-03-02 14:08:08 -05001252 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001253 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001254 sRollo.clearSelectedIcon();
1255 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001256 }
Jason Sams60a55bb2010-06-18 15:11:19 -07001257 sRollo.mScript.invoke_setZoom(zoom, animate ? 1 : 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001258 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001259
Daniel Sandler388f6792010-03-02 14:08:08 -05001260 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001261 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1262 Element.RGBA_8888(sRS), false);
1263 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1264 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001265 mIconIds[index] = mIcons[index].getID();
1266 mLabelIds[index] = mLabels[index].getID();
1267 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001268
Daniel Sandler388f6792010-03-02 14:08:08 -05001269 private void uploadAppIcon(int index, ApplicationInfo item) {
1270 if (mIconIds[index] != mIcons[index].getID()) {
1271 throw new IllegalStateException("uploadAppIcon index=" + index
1272 + " mIcons[index].getID=" + mIcons[index].getID()
1273 + " mIconsIds[index]=" + mIconIds[index]
1274 + " item=" + item);
1275 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001276 mIcons[index].uploadToTexture(true, 0);
1277 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001278 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001279
Daniel Sandler388f6792010-03-02 14:08:08 -05001280 /**
1281 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1282 * fill in the values and call saveAppsList().
1283 */
1284 private void reallocAppsList(int count) {
1285 Allocation[] icons = new Allocation[count];
1286 int[] iconIds = new int[count];
Jason Sams98994c42010-06-01 15:54:10 -07001287 mAllocIconIds = Allocation.createSized(sRS, Element.I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001288
Daniel Sandler388f6792010-03-02 14:08:08 -05001289 Allocation[] labels = new Allocation[count];
1290 int[] labelIds = new int[count];
Jason Sams98994c42010-06-01 15:54:10 -07001291 mAllocLabelIds = Allocation.createSized(sRS, Element.I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001292
Jason Sams14f67ed2010-05-11 14:02:43 -07001293 final int oldCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001294
Daniel Sandler388f6792010-03-02 14:08:08 -05001295 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1296 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1297 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1298 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001299
Daniel Sandler388f6792010-03-02 14:08:08 -05001300 mIcons = icons;
1301 mIconIds = iconIds;
1302 mLabels = labels;
1303 mLabelIds = labelIds;
1304 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001305
Daniel Sandler388f6792010-03-02 14:08:08 -05001306 /**
1307 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1308 */
1309 private void addApp(int index, ApplicationInfo item) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001310 final int count = mScript.get_gIconCount() - index;
Daniel Sandler388f6792010-03-02 14:08:08 -05001311 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001312
Daniel Sandler388f6792010-03-02 14:08:08 -05001313 System.arraycopy(mIcons, index, mIcons, dest, count);
1314 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1315 System.arraycopy(mLabels, index, mLabels, dest, count);
1316 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001317
Daniel Sandler388f6792010-03-02 14:08:08 -05001318 createAppIconAllocations(index, item);
1319 uploadAppIcon(index, item);
Jason Sams14f67ed2010-05-11 14:02:43 -07001320
1321 mScript.set_gIconCount(mScript.get_gIconCount() + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001322 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001323
Daniel Sandler388f6792010-03-02 14:08:08 -05001324 /**
1325 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1326 */
1327 private void removeApp(int index) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001328 final int count = mScript.get_gIconCount() - index - 1;
Daniel Sandler388f6792010-03-02 14:08:08 -05001329 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001330
Daniel Sandler388f6792010-03-02 14:08:08 -05001331 System.arraycopy(mIcons, src, mIcons, index, count);
1332 System.arraycopy(mIconIds, src, mIconIds, index, count);
1333 System.arraycopy(mLabels, src, mLabels, index, count);
1334 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001335
Jason Sams14f67ed2010-05-11 14:02:43 -07001336 mScript.set_gIconCount(mScript.get_gIconCount() - 1);
1337 final int last = mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001338
Daniel Sandler388f6792010-03-02 14:08:08 -05001339 mIcons[last] = null;
1340 mIconIds[last] = 0;
1341 mLabels[last] = null;
1342 mLabelIds[last] = 0;
1343 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001344
Daniel Sandler388f6792010-03-02 14:08:08 -05001345 /**
1346 * Send the apps list structures to RS.
1347 */
1348 private void saveAppsList() {
1349 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1350 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001351 mAllocIconIds.data(mIconIds);
1352 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001353
Jason Sams14f67ed2010-05-11 14:02:43 -07001354 mScript.bind_gIconIDs(mAllocIconIds);
1355 mScript.bind_gLabelIDs(mAllocLabelIds);
Daniel Sandler388f6792010-03-02 14:08:08 -05001356 }
1357 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001358
Jason Sams60a55bb2010-06-18 15:11:19 -07001359 void fling(float pos, float v) {
1360 mScript.invoke_fling(pos, v);
Daniel Sandler388f6792010-03-02 14:08:08 -05001361 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001362
Jason Sams60a55bb2010-06-18 15:11:19 -07001363 void move(float pos) {
1364 mScript.invoke_move(pos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001365 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001366
Daniel Sandler388f6792010-03-02 14:08:08 -05001367 void moveTo(float row) {
Jason Sams60a55bb2010-06-18 15:11:19 -07001368 mScript.invoke_moveTo(row);
Daniel Sandler388f6792010-03-02 14:08:08 -05001369 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001370
Daniel Sandler388f6792010-03-02 14:08:08 -05001371 /**
1372 * You need to call save() on mState on your own after calling this.
1373 *
1374 * @return the index of the icon that was selected.
1375 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001376 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001377 if (mAllApps != null) {
1378 final int index = mAllApps.chooseTappedIcon(x, y);
1379 selectIcon(index, pressed);
1380 return index;
1381 } else {
1382 return -1;
1383 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001384 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001385
Daniel Sandler388f6792010-03-02 14:08:08 -05001386 /**
1387 * Select the icon at the given index.
1388 *
1389 * @param index The index.
1390 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1391 */
1392 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001393 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1394 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001395 if (mAllApps != null) {
1396 mAllApps.mRestoreFocusIndex = index;
1397 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001398 mScript.set_gSelectedIconIndex(-1);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001399 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1400 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001401 }
1402 } else {
1403 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001404 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001405 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001406
Jason Sams14f67ed2010-05-11 14:02:43 -07001407 int prev = mScript.get_gSelectedIconIndex();
1408 mScript.set_gSelectedIconIndex(index);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001409
Romain Guy13c2e7b2010-03-10 19:45:00 -08001410 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001411 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001412
Daniel Sandler388f6792010-03-02 14:08:08 -05001413 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1414 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1415 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001416
Jason Sams60a55bb2010-06-18 15:11:19 -07001417 Allocation si = Allocation.createFromBitmap(sRS, selectionBitmap,
Joe Onorato2cc62e82010-03-17 20:23:53 -07001418 Element.RGBA_8888(sRS), false);
Jason Sams60a55bb2010-06-18 15:11:19 -07001419 si.uploadToTexture(0);
1420 mScript.set_gSelectedIconTexture(si);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001421
Daniel Sandler388f6792010-03-02 14:08:08 -05001422 if (prev != index) {
1423 if (info.title != null && info.title.length() > 0) {
1424 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001425 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001426 }
1427 }
1428 }
1429 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001430
Daniel Sandler388f6792010-03-02 14:08:08 -05001431 /**
1432 * You need to call save() on mState on your own after calling this.
1433 */
1434 void clearSelectedIcon() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001435 mScript.set_gSelectedIconIndex(-1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001436 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001437
Daniel Sandler388f6792010-03-02 14:08:08 -05001438 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001439 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001440 switch (mode) {
1441 case SELECTED_NONE:
Jason Sams14f67ed2010-05-11 14:02:43 -07001442 mScript.set_gHomeButton(mHomeButtonNormal);
Daniel Sandler388f6792010-03-02 14:08:08 -05001443 break;
1444 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001445 mAllApps.mLastSelection = SELECTION_HOME;
Jason Sams14f67ed2010-05-11 14:02:43 -07001446 mScript.set_gHomeButton(mHomeButtonFocused);
Daniel Sandler388f6792010-03-02 14:08:08 -05001447 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001448 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001449 }
1450 break;
1451 case SELECTED_PRESSED:
Jason Sams14f67ed2010-05-11 14:02:43 -07001452 mScript.set_gHomeButton(mHomeButtonPressed);
Daniel Sandler388f6792010-03-02 14:08:08 -05001453 break;
1454 }
1455 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001456
Daniel Sandler388f6792010-03-02 14:08:08 -05001457 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001458 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1459 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1460 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001461 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001462 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001463 }
1464 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001465 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001466 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001467 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001468 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001469 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001470 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001471 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Jason Sams14f67ed2010-05-11 14:02:43 -07001472 //Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1473 //Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1474 //Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1475 //Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1476 //Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1477 //Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1478 //Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1479 //Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1480 //Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001481 }
1482 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001483
Daniel Sandler388f6792010-03-02 14:08:08 -05001484 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001485 Log.d(TAG, "sRS=" + sRS);
1486 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001487 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001488 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1489 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001490 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1491 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1492 Log.d(TAG, "mLastSelection=" + mLastSelection);
1493 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1494 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1495 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1496 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001497 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1498 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001499 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001500 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001501 Log.d(TAG, "mVelocity=" + mVelocity);
1502 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001503 if (sRollo != null) {
1504 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001505 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001506 if (sRS != null) {
1507 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001508 }
1509 }
1510}