blob: b56a9c9fa89cde95de9338729840ea8bc63f833a [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
Daniel Sandler388f6792010-03-02 14:08:08 -0500738 public void setDragController(DragController dragger) {
739 mDragController = dragger;
740 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800741
Daniel Sandler388f6792010-03-02 14:08:08 -0500742 public void onDropCompleted(View target, boolean success) {
743 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800744
Daniel Sandler388f6792010-03-02 14:08:08 -0500745 /**
746 * Zoom to the specifed level.
747 *
748 * @param zoom [0..1] 0 is hidden, 1 is open
749 */
750 public void zoom(float zoom, boolean animate) {
751 cancelLongPress();
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700752 sNextZoom = zoom;
753 sAnimateNextZoom = animate;
Daniel Sandler388f6792010-03-02 14:08:08 -0500754 // if we do setZoom while we don't have a surface, we won't
755 // get the callbacks that actually set mZoom.
Joe Onorato2cc62e82010-03-17 20:23:53 -0700756 if (sRollo == null || !mHaveSurface) {
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700757 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500758 mZoom = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500759 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700760 sRollo.setZoom(zoom, animate);
Daniel Sandler388f6792010-03-02 14:08:08 -0500761 }
762 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800763
Joe Onorato878f0862010-03-22 12:22:22 -0400764 /**
765 * If sRollo is null, then we're not visible. This is also used to guard against
766 * sRollo being null.
767 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500768 public boolean isVisible() {
Joe Onorato878f0862010-03-22 12:22:22 -0400769 return sRollo != null && mZoom > 0.001f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500770 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800771
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700772 public boolean isAnimating() {
773 return isVisible() && mZoom <= 0.999f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500774 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800775
Daniel Sandler388f6792010-03-02 14:08:08 -0500776 public void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700777 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500778 // We've been removed from the window. Don't bother with all this.
779 return;
780 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800781
Daniel Sandler707b0f72010-04-15 16:41:31 -0400782 if (list != null) {
783 Collections.sort(list, LauncherModel.APP_NAME_COMPARATOR);
784 }
785
Romain Guy13c2e7b2010-03-10 19:45:00 -0800786 boolean reload = false;
787 if (mAllAppsList == null) {
788 reload = true;
789 } else if (list.size() != mAllAppsList.size()) {
790 reload = true;
791 } else {
792 final int count = list.size();
793 for (int i = 0; i < count; i++) {
794 if (list.get(i) != mAllAppsList.get(i)) {
795 reload = true;
796 break;
797 }
798 }
799 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800800
Daniel Sandler388f6792010-03-02 14:08:08 -0500801 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700802 if (sRollo != null && reload) {
803 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500804 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700805
Romain Guyc16fea72010-03-12 17:17:56 -0800806 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700807 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
Romain Guyc16fea72010-03-12 17:17:56 -0800808 mRestoreFocusIndex = -1;
809 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700810
Daniel Sandler388f6792010-03-02 14:08:08 -0500811 mLocks &= ~LOCK_ICONS_PENDING;
812 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800813
Daniel Sandler388f6792010-03-02 14:08:08 -0500814 public void addApps(ArrayList<ApplicationInfo> list) {
815 if (mAllAppsList == null) {
816 // Not done loading yet. We'll find out about it later.
817 return;
818 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700819 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500820 // We've been removed from the window. Don't bother with all this.
821 return;
822 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800823
Daniel Sandler388f6792010-03-02 14:08:08 -0500824 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700825 if (sRollo != null) {
826 sRollo.pause();
Jason Sams14f67ed2010-05-11 14:02:43 -0700827 sRollo.reallocAppsList(sRollo.mScript.get_gIconCount() + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500828 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800829
Daniel Sandler388f6792010-03-02 14:08:08 -0500830 for (int i=0; i<N; i++) {
831 final ApplicationInfo item = list.get(i);
832 int index = Collections.binarySearch(mAllAppsList, item,
833 LauncherModel.APP_NAME_COMPARATOR);
834 if (index < 0) {
835 index = -(index+1);
836 }
837 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700838 if (sRollo != null) {
839 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500840 }
841 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800842
Joe Onorato2cc62e82010-03-17 20:23:53 -0700843 if (sRollo != null) {
844 sRollo.saveAppsList();
845 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500846 }
847 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800848
Daniel Sandler388f6792010-03-02 14:08:08 -0500849 public void removeApps(ArrayList<ApplicationInfo> list) {
850 if (mAllAppsList == null) {
851 // Not done loading yet. We'll find out about it later.
852 return;
853 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800854
Joe Onorato2cc62e82010-03-17 20:23:53 -0700855 if (sRollo != null) {
856 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800857 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500858 final int N = list.size();
859 for (int i=0; i<N; i++) {
860 final ApplicationInfo item = list.get(i);
861 int index = findAppByComponent(mAllAppsList, item);
862 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500863 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700864 if (sRollo != null) {
865 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500866 }
867 } else {
868 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
869 // Try to recover. This should keep us from crashing for now.
870 }
871 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800872
Joe Onorato2cc62e82010-03-17 20:23:53 -0700873 if (sRollo != null) {
874 sRollo.saveAppsList();
875 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500876 }
877 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800878
Joe Onorato64e6be72010-03-05 15:05:52 -0500879 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500880 // Just remove and add, because they may need to be re-sorted.
881 removeApps(list);
882 addApps(list);
883 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800884
Daniel Sandler388f6792010-03-02 14:08:08 -0500885 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
886 ComponentName component = item.intent.getComponent();
887 final int N = list.size();
888 for (int i=0; i<N; i++) {
889 ApplicationInfo x = list.get(i);
890 if (x.intent.getComponent().equals(component)) {
891 return i;
892 }
893 }
894 return -1;
895 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800896
Daniel Sandler388f6792010-03-02 14:08:08 -0500897 class AAMessage extends RenderScript.RSMessage {
898 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700899 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500900 mVelocity = ((float)mData[1]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700901
902 boolean lastVisible = isVisible();
Daniel Sandler388f6792010-03-02 14:08:08 -0500903 mZoom = ((float)mData[2]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700904
905 final boolean visible = isVisible();
906 if (visible != lastVisible) {
907 post(new Runnable() {
908 public void run() {
909 if (visible) {
910 showSurface();
911 } else {
912 hideSurface();
913 }
914 }
915 });
916 }
917
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700918 sZoomDirty = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500919 }
920 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800921
Romain Guy13c2e7b2010-03-10 19:45:00 -0800922 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500923 // Allocations ======
924 private int mWidth;
925 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800926
Daniel Sandler388f6792010-03-02 14:08:08 -0500927 private Resources mRes;
Stephen Hinesb2d69862010-09-16 17:21:50 -0700928 ScriptC_allapps mScript;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800929
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700930 private Mesh mMesh;
Daniel Sandler388f6792010-03-02 14:08:08 -0500931 private ProgramVertex.MatrixAllocation mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800932
Jason Sams14f67ed2010-05-11 14:02:43 -0700933 private ScriptField_VpConsts mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800934
Daniel Sandler388f6792010-03-02 14:08:08 -0500935 private Allocation mHomeButtonNormal;
936 private Allocation mHomeButtonFocused;
937 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800938
Daniel Sandler388f6792010-03-02 14:08:08 -0500939 private Allocation[] mIcons;
940 private int[] mIconIds;
941 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800942
Daniel Sandler388f6792010-03-02 14:08:08 -0500943 private Allocation[] mLabels;
944 private int[] mLabelIds;
945 private Allocation mAllocLabelIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800946
Daniel Sandler388f6792010-03-02 14:08:08 -0500947 private Bitmap mSelectionBitmap;
948 private Canvas mSelectionCanvas;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800949
Jason Sams14f67ed2010-05-11 14:02:43 -0700950 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800951
Romain Guy13c2e7b2010-03-10 19:45:00 -0800952 AllApps3D mAllApps;
953 boolean mInitialize;
954
Daniel Sandler388f6792010-03-02 14:08:08 -0500955 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -0800956 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -0800957 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -0500958 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800959
960 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400961 if (sRS != null) {
962 sRS.contextBindRootScript(null);
963 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800964 }
965
966 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400967 if (sRS != null) {
968 sRS.contextBindRootScript(mScript);
969 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800970 }
971
Romain Guy13c2e7b2010-03-10 19:45:00 -0800972 public RolloRS(AllApps3D allApps) {
973 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -0500974 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800975
Daniel Sandler388f6792010-03-02 14:08:08 -0500976 public void init(Resources res, int width, int height) {
977 mRes = res;
978 mWidth = width;
979 mHeight = height;
Stephen Hinesb2d69862010-09-16 17:21:50 -0700980 mScript = new ScriptC_allapps(sRS, mRes, R.raw.allapps, true);
Jason Sams14f67ed2010-05-11 14:02:43 -0700981
Daniel Sandler388f6792010-03-02 14:08:08 -0500982 initProgramVertex();
983 initProgramFragment();
984 initProgramStore();
985 initGl();
986 initData();
Jason Sams14f67ed2010-05-11 14:02:43 -0700987
988 mScript.bind_gIconIDs(mAllocIconIds);
989 mScript.bind_gLabelIDs(mAllocLabelIds);
Jason Sams14f67ed2010-05-11 14:02:43 -0700990 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -0500991 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800992
Daniel Sandler388f6792010-03-02 14:08:08 -0500993 public void initMesh() {
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700994 Mesh.TriangleMeshBuilder tm = new Mesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800995
Daniel Sandler388f6792010-03-02 14:08:08 -0500996 for (int ct=0; ct < 16; ct++) {
997 float pos = (1.f / (16.f - 1)) * ct;
998 tm.addVertex(0.0f, pos);
999 tm.addVertex(1.0f, pos);
1000 }
1001 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1002 tm.addTriangle(ct, ct+1, ct+2);
1003 tm.addTriangle(ct+1, ct+3, ct+2);
1004 }
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001005 mMesh = tm.create(true);
Jason Sams14f67ed2010-05-11 14:02:43 -07001006 mScript.set_gSMCell(mMesh);
Daniel Sandler388f6792010-03-02 14:08:08 -05001007 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001008
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001009 Matrix4f getProjectionMatrix(int w, int h) {
1010 // range -1,1 in the narrow axis at z = 0.
1011 Matrix4f m1 = new Matrix4f();
1012 Matrix4f m2 = new Matrix4f();
1013
1014 if(w > h) {
1015 float aspect = ((float)w) / h;
1016 m1.loadFrustum(-aspect,aspect, -1,1, 1,100);
1017 } else {
1018 float aspect = ((float)h) / w;
1019 m1.loadFrustum(-1,1, -aspect,aspect, 1,100);
1020 }
1021
1022 m2.loadRotate(180, 0, 1, 0);
1023 m1.loadMultiply(m1, m2);
1024
1025 m2.loadScale(-2, 2, 1);
1026 m1.loadMultiply(m1, m2);
1027
1028 m2.loadTranslate(0, 0, 2);
1029 m1.loadMultiply(m1, m2);
1030 return m1;
1031 }
1032
Daniel Sandler388f6792010-03-02 14:08:08 -05001033 void resize(int w, int h) {
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001034 Matrix4f proj = getProjectionMatrix(w, h);
1035 mPVA.loadProjection(proj);
1036
1037 if (mUniformAlloc != null) {
1038 ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
1039 i.Proj = proj;
1040 i.ScaleOffset.x = (2.f / 480.f);
1041 i.ScaleOffset.y = 0;
1042 i.ScaleOffset.z = -((float)w / 2) - 0.25f;
1043 i.ScaleOffset.w = -380.25f;
1044 i.BendPos.x = 120.f;
1045 i.BendPos.y = 680.f;
1046 if (w > h) {
1047 i.ScaleOffset.z = 40.f;
1048 i.ScaleOffset.w = h - 40.f;
1049 i.BendPos.y = 1.f;
1050 }
1051 mUniformAlloc.set(i, 0, true);
1052 }
1053
Daniel Sandler388f6792010-03-02 14:08:08 -05001054 mWidth = w;
1055 mHeight = h;
1056 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001057
Daniel Sandler388f6792010-03-02 14:08:08 -05001058 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001059 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001060 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001061
Joe Onorato2cc62e82010-03-17 20:23:53 -07001062 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001063 pvb.setTextureMatrixEnable(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001064 ProgramVertex pv = pvb.create();
1065 pv.bindAllocation(mPVA);
1066 sRS.contextBindProgramVertex(pv);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001067
Jason Sams14f67ed2010-05-11 14:02:43 -07001068 mUniformAlloc = new ScriptField_VpConsts(sRS, 1);
1069 mScript.bind_vpConstants(mUniformAlloc);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001070
Daniel Sandler388f6792010-03-02 14:08:08 -05001071 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001072 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001073 String t = "varying vec4 varColor;\n" +
Alex Sakhartchouk2f3b0b62010-10-06 09:32:12 -07001074 "varying vec2 varTex0;\n" +
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001075 "void main() {\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001076 // Animation
1077 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001078
Romain Guy060b5c82010-03-04 10:07:38 -08001079 " float bendY1 = UNI_BendPos.x;\n" +
1080 " float bendY2 = UNI_BendPos.y;\n" +
1081 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1082 " float bendDistance = bendY1 * 0.4;\n" +
1083 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001084
Romain Guy060b5c82010-03-04 10:07:38 -08001085 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1086 " float aDy = cos(bendAngle);\n" +
1087 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001088
Romain Guy060b5c82010-03-04 10:07:38 -08001089 " float scale = (2.0 / 480.0);\n" +
1090 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1091 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1092 " float y = 0.0;\n" +
1093 " float z = 0.0;\n" +
1094 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001095
Romain Guy060b5c82010-03-04 10:07:38 -08001096 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1097 " y += cv * aDy;\n" +
1098 " z += -cv * aDz;\n" +
1099 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1100 " lum += cv / bendDistance * distanceDimLevel;\n" +
1101 " y += cv * cos(cv * bendStep);\n" +
1102 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001103
Romain Guy060b5c82010-03-04 10:07:38 -08001104 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1105 " y += cv * aDy;\n" +
1106 " z += cv * aDz;\n" +
1107 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1108 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1109 " y += cv * cos(cv * bendStep);\n" +
1110 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001111
Romain Guy060b5c82010-03-04 10:07:38 -08001112 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001113
Romain Guy060b5c82010-03-04 10:07:38 -08001114 " vec4 pos;\n" +
1115 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1116 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1117 " pos.z = z * UNI_ScaleOffset.x;\n" +
1118 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001119
Romain Guy060b5c82010-03-04 10:07:38 -08001120 " pos.x *= 1.0 + ani * 4.0;\n" +
1121 " pos.y *= 1.0 + ani * 4.0;\n" +
1122 " pos.z -= ani * 1.5;\n" +
1123 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001124
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001125 " gl_Position = UNI_Proj * pos;\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001126 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1127 " varTex0.xy = ATTRIB_position;\n" +
1128 " varTex0.y = 1.0 - varTex0.y;\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001129 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001130 sb.setShader(t);
1131 sb.addConstant(mUniformAlloc.getType());
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001132 sb.addInput(mMesh.getVertexAllocation(0).getType().getElement());
Jason Sams60a55bb2010-06-18 15:11:19 -07001133 ProgramVertex pvc = sb.create();
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001134 pvc.bindConstants(mUniformAlloc.getAllocation(), 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001135
Jason Sams60a55bb2010-06-18 15:11:19 -07001136 mScript.set_gPVCurve(pvc);
Daniel Sandler388f6792010-03-02 14:08:08 -05001137 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001138
Daniel Sandler388f6792010-03-02 14:08:08 -05001139 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001140 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001141 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1142 sb.setMag(Sampler.Value.NEAREST);
1143 sb.setWrapS(Sampler.Value.CLAMP);
1144 sb.setWrapT(Sampler.Value.CLAMP);
1145 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001146
Daniel Sandler388f6792010-03-02 14:08:08 -05001147 sb.setMin(Sampler.Value.NEAREST);
1148 sb.setMag(Sampler.Value.NEAREST);
1149 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001150
Joe Onorato2cc62e82010-03-17 20:23:53 -07001151 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001152 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1153 ProgramFragment.Builder.Format.RGBA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001154 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001155 ProgramFragment pfTexMip = bf.create();
1156 pfTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001157
Jason Sams070ada82010-08-04 17:53:07 -07001158 bf.setVaryingColor(false);
Jason Sams60a55bb2010-06-18 15:11:19 -07001159 ProgramFragment pfTexNearest = bf.create();
1160 pfTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001161
Daniel Sandler388f6792010-03-02 14:08:08 -05001162 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1163 ProgramFragment.Builder.Format.ALPHA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001164 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001165 ProgramFragment pfTexMipAlpha = bf.create();
1166 pfTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001167
Jason Sams60a55bb2010-06-18 15:11:19 -07001168 mScript.set_gPFTexNearest(pfTexNearest);
1169 mScript.set_gPFTexMip(pfTexMip);
1170 mScript.set_gPFTexMipAlpha(pfTexMipAlpha);
Daniel Sandler388f6792010-03-02 14:08:08 -05001171 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001172
Daniel Sandler388f6792010-03-02 14:08:08 -05001173 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001174 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001175 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1176 bs.setColorMask(true,true,true,false);
1177 bs.setDitherEnable(true);
1178 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1179 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Jason Sams14f67ed2010-05-11 14:02:43 -07001180 mScript.set_gPS(bs.create());
Daniel Sandler388f6792010-03-02 14:08:08 -05001181 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001182
Daniel Sandler388f6792010-03-02 14:08:08 -05001183 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001184 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001185
Daniel Sandler388f6792010-03-02 14:08:08 -05001186 private void initData() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001187 mScript.set_COLUMNS_PER_PAGE_PORTRAIT(Defines.COLUMNS_PER_PAGE_PORTRAIT);
1188 mScript.set_ROWS_PER_PAGE_PORTRAIT(Defines.ROWS_PER_PAGE_PORTRAIT);
1189 mScript.set_COLUMNS_PER_PAGE_LANDSCAPE(Defines.COLUMNS_PER_PAGE_LANDSCAPE);
1190 mScript.set_ROWS_PER_PAGE_LANDSCAPE(Defines.ROWS_PER_PAGE_LANDSCAPE);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001191
Joe Onorato2cc62e82010-03-17 20:23:53 -07001192 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1193 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001194 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001195 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1196 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001197 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001198 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1199 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001200 mHomeButtonPressed.uploadToTexture(0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001201
Jason Sams14f67ed2010-05-11 14:02:43 -07001202 mScript.set_gHomeButton(mHomeButtonNormal);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001203
Daniel Sandler388f6792010-03-02 14:08:08 -05001204 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1205 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1206 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001207
Daniel Sandler388f6792010-03-02 14:08:08 -05001208 setApps(null);
1209 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001210
Daniel Sandler388f6792010-03-02 14:08:08 -05001211 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001212 if (sZoomDirty) {
1213 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001214 }
1215 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001216
Romain Guy060b5c82010-03-04 10:07:38 -08001217 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001218 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001219 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001220 final int count = list != null ? list.size() : 0;
1221 int allocCount = count;
1222 if (allocCount < 1) {
1223 allocCount = 1;
1224 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001225
Daniel Sandler388f6792010-03-02 14:08:08 -05001226 mIcons = new Allocation[count];
1227 mIconIds = new int[allocCount];
Jason Sams98994c42010-06-01 15:54:10 -07001228 mAllocIconIds = Allocation.createSized(sRS, Element.I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001229
Daniel Sandler388f6792010-03-02 14:08:08 -05001230 mLabels = new Allocation[count];
1231 mLabelIds = new int[allocCount];
Jason Sams98994c42010-06-01 15:54:10 -07001232 mAllocLabelIds = Allocation.createSized(sRS, Element.I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001233
Jason Sams14f67ed2010-05-11 14:02:43 -07001234 mScript.set_gIconCount(count);
1235 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001236 createAppIconAllocations(i, list.get(i));
1237 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001238 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001239 uploadAppIcon(i, list.get(i));
1240 }
1241 saveAppsList();
Jason Sams14f67ed2010-05-11 14:02:43 -07001242 android.util.Log.e("rs", "setApps");
Joe Onorato2cc62e82010-03-17 20:23:53 -07001243 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001244 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001245
Daniel Sandler388f6792010-03-02 14:08:08 -05001246 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001247 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001248 sRollo.clearSelectedIcon();
1249 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001250 }
Jason Sams60a55bb2010-06-18 15:11:19 -07001251 sRollo.mScript.invoke_setZoom(zoom, animate ? 1 : 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001252 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001253
Daniel Sandler388f6792010-03-02 14:08:08 -05001254 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001255 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1256 Element.RGBA_8888(sRS), false);
1257 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1258 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001259 mIconIds[index] = mIcons[index].getID();
1260 mLabelIds[index] = mLabels[index].getID();
1261 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001262
Daniel Sandler388f6792010-03-02 14:08:08 -05001263 private void uploadAppIcon(int index, ApplicationInfo item) {
1264 if (mIconIds[index] != mIcons[index].getID()) {
1265 throw new IllegalStateException("uploadAppIcon index=" + index
1266 + " mIcons[index].getID=" + mIcons[index].getID()
1267 + " mIconsIds[index]=" + mIconIds[index]
1268 + " item=" + item);
1269 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001270 mIcons[index].uploadToTexture(true, 0);
1271 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001272 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001273
Daniel Sandler388f6792010-03-02 14:08:08 -05001274 /**
1275 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1276 * fill in the values and call saveAppsList().
1277 */
1278 private void reallocAppsList(int count) {
1279 Allocation[] icons = new Allocation[count];
1280 int[] iconIds = new int[count];
Jason Sams98994c42010-06-01 15:54:10 -07001281 mAllocIconIds = Allocation.createSized(sRS, Element.I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001282
Daniel Sandler388f6792010-03-02 14:08:08 -05001283 Allocation[] labels = new Allocation[count];
1284 int[] labelIds = new int[count];
Jason Sams98994c42010-06-01 15:54:10 -07001285 mAllocLabelIds = Allocation.createSized(sRS, Element.I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001286
Jason Sams14f67ed2010-05-11 14:02:43 -07001287 final int oldCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001288
Daniel Sandler388f6792010-03-02 14:08:08 -05001289 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1290 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1291 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1292 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001293
Daniel Sandler388f6792010-03-02 14:08:08 -05001294 mIcons = icons;
1295 mIconIds = iconIds;
1296 mLabels = labels;
1297 mLabelIds = labelIds;
1298 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001299
Daniel Sandler388f6792010-03-02 14:08:08 -05001300 /**
1301 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1302 */
1303 private void addApp(int index, ApplicationInfo item) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001304 final int count = mScript.get_gIconCount() - index;
Daniel Sandler388f6792010-03-02 14:08:08 -05001305 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001306
Daniel Sandler388f6792010-03-02 14:08:08 -05001307 System.arraycopy(mIcons, index, mIcons, dest, count);
1308 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1309 System.arraycopy(mLabels, index, mLabels, dest, count);
1310 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001311
Daniel Sandler388f6792010-03-02 14:08:08 -05001312 createAppIconAllocations(index, item);
1313 uploadAppIcon(index, item);
Jason Sams14f67ed2010-05-11 14:02:43 -07001314
1315 mScript.set_gIconCount(mScript.get_gIconCount() + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001316 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001317
Daniel Sandler388f6792010-03-02 14:08:08 -05001318 /**
1319 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1320 */
1321 private void removeApp(int index) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001322 final int count = mScript.get_gIconCount() - index - 1;
Daniel Sandler388f6792010-03-02 14:08:08 -05001323 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001324
Daniel Sandler388f6792010-03-02 14:08:08 -05001325 System.arraycopy(mIcons, src, mIcons, index, count);
1326 System.arraycopy(mIconIds, src, mIconIds, index, count);
1327 System.arraycopy(mLabels, src, mLabels, index, count);
1328 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001329
Jason Sams14f67ed2010-05-11 14:02:43 -07001330 mScript.set_gIconCount(mScript.get_gIconCount() - 1);
1331 final int last = mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001332
Daniel Sandler388f6792010-03-02 14:08:08 -05001333 mIcons[last] = null;
1334 mIconIds[last] = 0;
1335 mLabels[last] = null;
1336 mLabelIds[last] = 0;
1337 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001338
Daniel Sandler388f6792010-03-02 14:08:08 -05001339 /**
1340 * Send the apps list structures to RS.
1341 */
1342 private void saveAppsList() {
1343 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1344 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001345 mAllocIconIds.data(mIconIds);
1346 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001347
Jason Sams14f67ed2010-05-11 14:02:43 -07001348 mScript.bind_gIconIDs(mAllocIconIds);
1349 mScript.bind_gLabelIDs(mAllocLabelIds);
Daniel Sandler388f6792010-03-02 14:08:08 -05001350 }
1351 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001352
Jason Sams60a55bb2010-06-18 15:11:19 -07001353 void fling(float pos, float v) {
1354 mScript.invoke_fling(pos, v);
Daniel Sandler388f6792010-03-02 14:08:08 -05001355 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001356
Jason Sams60a55bb2010-06-18 15:11:19 -07001357 void move(float pos) {
1358 mScript.invoke_move(pos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001359 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001360
Daniel Sandler388f6792010-03-02 14:08:08 -05001361 void moveTo(float row) {
Jason Sams60a55bb2010-06-18 15:11:19 -07001362 mScript.invoke_moveTo(row);
Daniel Sandler388f6792010-03-02 14:08:08 -05001363 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001364
Daniel Sandler388f6792010-03-02 14:08:08 -05001365 /**
1366 * You need to call save() on mState on your own after calling this.
1367 *
1368 * @return the index of the icon that was selected.
1369 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001370 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001371 if (mAllApps != null) {
1372 final int index = mAllApps.chooseTappedIcon(x, y);
1373 selectIcon(index, pressed);
1374 return index;
1375 } else {
1376 return -1;
1377 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001378 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001379
Daniel Sandler388f6792010-03-02 14:08:08 -05001380 /**
1381 * Select the icon at the given index.
1382 *
1383 * @param index The index.
1384 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1385 */
1386 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001387 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1388 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001389 if (mAllApps != null) {
1390 mAllApps.mRestoreFocusIndex = index;
1391 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001392 mScript.set_gSelectedIconIndex(-1);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001393 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1394 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001395 }
1396 } else {
1397 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001398 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001399 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001400
Jason Sams14f67ed2010-05-11 14:02:43 -07001401 int prev = mScript.get_gSelectedIconIndex();
1402 mScript.set_gSelectedIconIndex(index);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001403
Romain Guy13c2e7b2010-03-10 19:45:00 -08001404 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001405 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001406
Daniel Sandler388f6792010-03-02 14:08:08 -05001407 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1408 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1409 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001410
Jason Sams60a55bb2010-06-18 15:11:19 -07001411 Allocation si = Allocation.createFromBitmap(sRS, selectionBitmap,
Joe Onorato2cc62e82010-03-17 20:23:53 -07001412 Element.RGBA_8888(sRS), false);
Jason Sams60a55bb2010-06-18 15:11:19 -07001413 si.uploadToTexture(0);
1414 mScript.set_gSelectedIconTexture(si);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001415
Daniel Sandler388f6792010-03-02 14:08:08 -05001416 if (prev != index) {
1417 if (info.title != null && info.title.length() > 0) {
1418 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001419 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001420 }
1421 }
1422 }
1423 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001424
Daniel Sandler388f6792010-03-02 14:08:08 -05001425 /**
1426 * You need to call save() on mState on your own after calling this.
1427 */
1428 void clearSelectedIcon() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001429 mScript.set_gSelectedIconIndex(-1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001430 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001431
Daniel Sandler388f6792010-03-02 14:08:08 -05001432 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001433 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001434 switch (mode) {
1435 case SELECTED_NONE:
Jason Sams14f67ed2010-05-11 14:02:43 -07001436 mScript.set_gHomeButton(mHomeButtonNormal);
Daniel Sandler388f6792010-03-02 14:08:08 -05001437 break;
1438 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001439 mAllApps.mLastSelection = SELECTION_HOME;
Jason Sams14f67ed2010-05-11 14:02:43 -07001440 mScript.set_gHomeButton(mHomeButtonFocused);
Daniel Sandler388f6792010-03-02 14:08:08 -05001441 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001442 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001443 }
1444 break;
1445 case SELECTED_PRESSED:
Jason Sams14f67ed2010-05-11 14:02:43 -07001446 mScript.set_gHomeButton(mHomeButtonPressed);
Daniel Sandler388f6792010-03-02 14:08:08 -05001447 break;
1448 }
1449 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001450
Daniel Sandler388f6792010-03-02 14:08:08 -05001451 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001452 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1453 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1454 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001455 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001456 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001457 }
1458 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001459 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001460 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001461 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001462 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001463 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001464 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001465 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Jason Sams14f67ed2010-05-11 14:02:43 -07001466 //Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1467 //Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1468 //Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1469 //Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1470 //Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1471 //Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1472 //Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1473 //Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1474 //Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001475 }
1476 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001477
Daniel Sandler388f6792010-03-02 14:08:08 -05001478 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001479 Log.d(TAG, "sRS=" + sRS);
1480 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001481 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001482 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1483 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001484 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1485 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1486 Log.d(TAG, "mLastSelection=" + mLastSelection);
1487 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1488 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1489 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1490 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001491 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1492 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001493 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001494 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001495 Log.d(TAG, "mVelocity=" + mVelocity);
1496 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001497 if (sRollo != null) {
1498 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001499 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001500 if (sRS != null) {
1501 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001502 }
1503 }
1504}