blob: 14c42bd2147c386ba61292ae9fc7bc06cee5c89b [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) {
149 sRS = createRenderScript(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800150 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700151 createRenderScript(sRS);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800152 }
153
Romain Guy060b5c82010-03-04 10:07:38 -0800154 final DisplayMetrics metrics = getResources().getDisplayMetrics();
155 final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
156 mColumnsPerPage = isPortrait ? Defines.COLUMNS_PER_PAGE_PORTRAIT :
157 Defines.COLUMNS_PER_PAGE_LANDSCAPE;
158 mRowsPerPage = isPortrait ? Defines.ROWS_PER_PAGE_PORTRAIT :
159 Defines.ROWS_PER_PAGE_LANDSCAPE;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800160
Joe Onorato2cc62e82010-03-17 20:23:53 -0700161 if (sRollo != null) {
162 sRollo.mAllApps = this;
163 sRollo.mRes = getResources();
164 sRollo.mInitialize = true;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800165 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500166 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800167
Romain Guy060b5c82010-03-04 10:07:38 -0800168 @SuppressWarnings({"UnusedDeclaration"})
169 public AllApps3D(Context context, AttributeSet attrs, int defStyle) {
170 this(context, attrs);
171 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800172
Romain Guy13c2e7b2010-03-10 19:45:00 -0800173 public void surrender() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400174 if (sRS != null) {
175 sRS.contextSetSurface(0, 0, null);
176 sRS.mMessageCallback = null;
177 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800178 mSurrendered = true;
179 }
180
Daniel Sandler388f6792010-03-02 14:08:08 -0500181 /**
182 * Note that this implementation prohibits this view from ever being reattached.
183 */
184 @Override
185 protected void onDetachedFromWindow() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700186 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800187 if (!mSurrendered) {
Joe Onorato96da4012010-03-17 20:03:24 -0700188 Log.i(TAG, "onDetachedFromWindow");
Romain Guy13c2e7b2010-03-10 19:45:00 -0800189 destroyRenderScript();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700190 sRS = null;
191 sRollo = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800192 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500193 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800194
Daniel Sandler388f6792010-03-02 14:08:08 -0500195 /**
196 * If you have an attached click listener, View always plays the click sound!?!?
197 * Deal with sound effects by hand.
198 */
199 public void reallyPlaySoundEffect(int sound) {
200 boolean old = isSoundEffectsEnabled();
201 setSoundEffectsEnabled(true);
202 playSoundEffect(sound);
203 setSoundEffectsEnabled(old);
204 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800205
Daniel Sandler388f6792010-03-02 14:08:08 -0500206 public void setLauncher(Launcher launcher) {
207 mLauncher = launcher;
208 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800209
Daniel Sandler388f6792010-03-02 14:08:08 -0500210 @Override
211 public void surfaceDestroyed(SurfaceHolder holder) {
212 super.surfaceDestroyed(holder);
213 // Without this, we leak mMessageCallback which leaks the context.
Romain Guy13c2e7b2010-03-10 19:45:00 -0800214 if (!mSurrendered) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700215 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800216 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500217 // We may lose any callbacks that are pending, so make sure that we re-sync that
218 // on the next surfaceChanged.
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700219 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500220 mHaveSurface = false;
221 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800222
Daniel Sandler388f6792010-03-02 14:08:08 -0500223 @Override
224 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
225 //long startTime = SystemClock.uptimeMillis();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800226
Daniel Sandler388f6792010-03-02 14:08:08 -0500227 super.surfaceChanged(holder, format, w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800228
Romain Guy13c2e7b2010-03-10 19:45:00 -0800229 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800230
Daniel Sandler388f6792010-03-02 14:08:08 -0500231 mHaveSurface = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800232
Joe Onorato2cc62e82010-03-17 20:23:53 -0700233 if (sRollo == null) {
234 sRollo = new RolloRS(this);
235 sRollo.init(getResources(), w, h);
Daniel Sandler388f6792010-03-02 14:08:08 -0500236 if (mAllAppsList != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700237 sRollo.setApps(mAllAppsList);
Daniel Sandler388f6792010-03-02 14:08:08 -0500238 }
239 if (mShouldGainFocus) {
240 gainFocus();
241 mShouldGainFocus = false;
242 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700243 } else if (sRollo.mInitialize) {
244 sRollo.initGl();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700245 sRollo.mInitialize = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500246 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800247
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700248 initTouchState(w, h);
249
Joe Onorato2cc62e82010-03-17 20:23:53 -0700250 sRollo.dirtyCheck();
251 sRollo.resize(w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800252
Jason Sams14f67ed2010-05-11 14:02:43 -0700253 Log.d(TAG, "sc " + sRS);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700254 if (sRS != null) {
255 sRS.mMessageCallback = mMessageProc = new AAMessage();
Daniel Sandler388f6792010-03-02 14:08:08 -0500256 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800257
Daniel Sandler388f6792010-03-02 14:08:08 -0500258 //long endTime = SystemClock.uptimeMillis();
259 //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
260 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800261
Daniel Sandler388f6792010-03-02 14:08:08 -0500262 @Override
263 public void onWindowFocusChanged(boolean hasWindowFocus) {
264 super.onWindowFocusChanged(hasWindowFocus);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800265
266 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800267
Daniel Sandler388f6792010-03-02 14:08:08 -0500268 if (mArrowNavigation) {
269 if (!hasWindowFocus) {
270 // Clear selection when we lose window focus
Jason Sams14f67ed2010-05-11 14:02:43 -0700271 mLastSelectedIcon = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700272 sRollo.setHomeSelected(SELECTED_NONE);
273 sRollo.clearSelectedIcon();
Romain Guy060b5c82010-03-04 10:07:38 -0800274 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700275 if (sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500276 if (mLastSelection == SELECTION_ICONS) {
277 int selection = mLastSelectedIcon;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700278 final int firstIcon = Math.round(sRollo.mScrollPos) * mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500279 if (selection < 0 || // No selection
280 selection < firstIcon || // off the top of the screen
Jason Sams14f67ed2010-05-11 14:02:43 -0700281 selection >= sRollo.mScript.get_gIconCount() || // past last icon
Daniel Sandler388f6792010-03-02 14:08:08 -0500282 selection >= firstIcon + // past last icon on screen
Romain Guy060b5c82010-03-04 10:07:38 -0800283 (mColumnsPerPage * mRowsPerPage)) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500284 selection = firstIcon;
285 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800286
Daniel Sandler388f6792010-03-02 14:08:08 -0500287 // Select the first icon when we gain window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700288 sRollo.selectIcon(selection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500289 } else if (mLastSelection == SELECTION_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700290 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500291 }
292 }
293 }
294 }
295 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800296
Daniel Sandler388f6792010-03-02 14:08:08 -0500297 @Override
298 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
299 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800300
Romain Guy13c2e7b2010-03-10 19:45:00 -0800301 if (!isVisible() || mSurrendered) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500302 return;
303 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800304
Daniel Sandler388f6792010-03-02 14:08:08 -0500305 if (gainFocus) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700306 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500307 gainFocus();
308 } else {
309 mShouldGainFocus = true;
310 }
311 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700312 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500313 if (mArrowNavigation) {
314 // Clear selection when we lose focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700315 sRollo.clearSelectedIcon();
316 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500317 mArrowNavigation = false;
318 }
319 } else {
320 mShouldGainFocus = false;
321 }
322 }
323 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800324
Daniel Sandler388f6792010-03-02 14:08:08 -0500325 private void gainFocus() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700326 if (!mArrowNavigation && sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500327 // Select the first icon when we gain keyboard focus
328 mArrowNavigation = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700329 sRollo.selectIcon(Math.round(sRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500330 }
331 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800332
Daniel Sandler388f6792010-03-02 14:08:08 -0500333 @Override
334 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800335
Daniel Sandler388f6792010-03-02 14:08:08 -0500336 boolean handled = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800337
Daniel Sandler388f6792010-03-02 14:08:08 -0500338 if (!isVisible()) {
339 return false;
340 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700341 final int iconCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800342
Daniel Sandler388f6792010-03-02 14:08:08 -0500343 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
344 if (mArrowNavigation) {
345 if (mLastSelection == SELECTION_HOME) {
346 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
347 mLauncher.closeAllApps(true);
348 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700349 int whichApp = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500350 if (whichApp >= 0) {
351 ApplicationInfo app = mAllAppsList.get(whichApp);
Joe Onoratof984e852010-03-25 09:47:45 -0700352 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500353 handled = true;
354 }
355 }
356 }
357 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800358
Daniel Sandler388f6792010-03-02 14:08:08 -0500359 if (iconCount > 0) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800360 final boolean isPortrait = getWidth() < getHeight();
Jason Sams14f67ed2010-05-11 14:02:43 -0700361
Daniel Sandler388f6792010-03-02 14:08:08 -0500362 mArrowNavigation = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800363
Jason Sams14f67ed2010-05-11 14:02:43 -0700364 int currentSelection = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700365 int currentTopRow = Math.round(sRollo.mScrollPos);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800366
Romain Guy060b5c82010-03-04 10:07:38 -0800367 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1
368 final int currentPageCol = currentSelection % mColumnsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800369
Romain Guy060b5c82010-03-04 10:07:38 -0800370 // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1
Romain Guy6a42cf32010-03-12 16:03:52 -0800371 final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage))
Romain Guy060b5c82010-03-04 10:07:38 -0800372 / mRowsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800373
Daniel Sandler388f6792010-03-02 14:08:08 -0500374 int newSelection = currentSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800375
Daniel Sandler388f6792010-03-02 14:08:08 -0500376 switch (keyCode) {
377 case KeyEvent.KEYCODE_DPAD_UP:
378 if (mLastSelection == SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800379 if (isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700380 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guy6a42cf32010-03-12 16:03:52 -0800381 int lastRowCount = iconCount % mColumnsPerPage;
382 if (lastRowCount == 0) {
383 lastRowCount = mColumnsPerPage;
384 }
385 newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2);
386 if (newSelection >= iconCount) {
387 newSelection = iconCount-1;
388 }
389 int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
390 if (target < 0) {
391 target = 0;
392 }
393 if (currentTopRow != target) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700394 sRollo.moveTo(target);
Romain Guy6a42cf32010-03-12 16:03:52 -0800395 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500396 }
397 } else {
398 if (currentPageRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800399 newSelection = currentSelection - mColumnsPerPage;
Romain Guy6a42cf32010-03-12 16:03:52 -0800400 if (currentTopRow > newSelection / mColumnsPerPage) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700401 sRollo.moveTo(newSelection / mColumnsPerPage);
Romain Guy6a42cf32010-03-12 16:03:52 -0800402 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500403 } else if (currentTopRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800404 newSelection = currentSelection - mColumnsPerPage;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700405 sRollo.moveTo(newSelection / mColumnsPerPage);
Daniel Sandler388f6792010-03-02 14:08:08 -0500406 } else if (currentPageRow != 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800407 newSelection = currentTopRow * mRowsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500408 }
409 }
410 handled = true;
411 break;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800412
Daniel Sandler388f6792010-03-02 14:08:08 -0500413 case KeyEvent.KEYCODE_DPAD_DOWN: {
Romain Guy060b5c82010-03-04 10:07:38 -0800414 final int rowCount = iconCount / mColumnsPerPage
415 + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
416 final int currentRow = currentSelection / mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500417 if (mLastSelection != SELECTION_HOME) {
418 if (currentRow < rowCount-1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700419 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500420 if (currentSelection < 0) {
421 newSelection = 0;
422 } else {
Romain Guy060b5c82010-03-04 10:07:38 -0800423 newSelection = currentSelection + mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500424 }
425 if (newSelection >= iconCount) {
426 // Go from D to G in this arrangement:
427 // A B C D
428 // E F G
429 newSelection = iconCount - 1;
430 }
Romain Guy060b5c82010-03-04 10:07:38 -0800431 if (currentPageRow >= mRowsPerPage - 1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700432 sRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -0500433 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800434 } else if (isPortrait) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500435 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700436 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500437 }
438 }
439 handled = true;
440 break;
441 }
442 case KeyEvent.KEYCODE_DPAD_LEFT:
443 if (mLastSelection != SELECTION_HOME) {
444 if (currentPageCol > 0) {
445 newSelection = currentSelection - 1;
446 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800447 } else if (!isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700448 newSelection = ((int) (sRollo.mScrollPos) * mColumnsPerPage) +
Romain Guy6a42cf32010-03-12 16:03:52 -0800449 (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700450 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500451 }
452 handled = true;
453 break;
454 case KeyEvent.KEYCODE_DPAD_RIGHT:
455 if (mLastSelection != SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800456 if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 ||
457 currentSelection == iconCount - 1)) {
458 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700459 sRollo.setHomeSelected(SELECTED_FOCUSED);
Romain Guy6a42cf32010-03-12 16:03:52 -0800460 } else if ((currentPageCol < mColumnsPerPage - 1) &&
Daniel Sandler388f6792010-03-02 14:08:08 -0500461 (currentSelection < iconCount - 1)) {
462 newSelection = currentSelection + 1;
463 }
464 }
465 handled = true;
466 break;
467 }
468 if (newSelection != currentSelection) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700469 sRollo.selectIcon(newSelection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500470 }
471 }
472 return handled;
473 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800474
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700475 void initTouchState(int width, int height) {
476 boolean isPortrait = width < height;
477
478 int[] viewPos = new int[2];
479 getLocationOnScreen(viewPos);
480
481 mTouchXBorders = new int[mColumnsPerPage + 1];
482 mTouchYBorders = new int[mRowsPerPage + 1];
483
484 // TODO: Put this in a config file/define
485 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE_PORTRAIT;
486 if (!isPortrait) cellHeight -= 12;
487 int centerY = (int) (height * (isPortrait ? 0.5f : 0.47f));
488 if (!isPortrait) centerY += cellHeight / 2;
489 int half = (int) Math.floor((mRowsPerPage + 1) / 2);
490 int end = mTouchYBorders.length - (half + 1);
491
492 for (int i = -half; i <= end; i++) {
493 mTouchYBorders[i + half] = centerY + (i * cellHeight) - viewPos[1];
494 }
495
496 int x = 0;
497 // TODO: Put this in a config file/define
498 int columnWidth = 120;
499 for (int i = 0; i < mColumnsPerPage + 1; i++) {
500 mTouchXBorders[i] = x - viewPos[0];
501 x += columnWidth;
502 }
503 }
504
505 int chooseTappedIcon(int x, int y) {
506 float pos = sRollo != null ? sRollo.mScrollPos : 0;
507
508 int oldY = y;
509
510 // Adjust for scroll position if not zero.
511 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
512
513 int col = -1;
514 int row = -1;
515 final int columnsCount = mColumnsPerPage;
516 for (int i=0; i< columnsCount; i++) {
517 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
518 col = i;
519 break;
520 }
521 }
522 final int rowsCount = mRowsPerPage;
523 for (int i=0; i< rowsCount; i++) {
524 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
525 row = i;
526 break;
527 }
528 }
529
530 if (row < 0 || col < 0) {
531 return -1;
532 }
533
534 int index = (((int) pos) * columnsCount) + (row * columnsCount) + col;
535
536 if (index >= mAllAppsList.size()) {
537 return -1;
538 } else {
539 return index;
540 }
541 }
542
Daniel Sandler388f6792010-03-02 14:08:08 -0500543 @Override
544 public boolean onTouchEvent(MotionEvent ev)
545 {
546 mArrowNavigation = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800547
Daniel Sandler388f6792010-03-02 14:08:08 -0500548 if (!isVisible()) {
549 return true;
550 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800551
Daniel Sandler388f6792010-03-02 14:08:08 -0500552 if (mLocks != 0) {
553 return true;
554 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800555
Daniel Sandler388f6792010-03-02 14:08:08 -0500556 super.onTouchEvent(ev);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800557
Daniel Sandler388f6792010-03-02 14:08:08 -0500558 int x = (int)ev.getX();
559 int y = (int)ev.getY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800560
Romain Guyce115852010-03-04 12:15:37 -0800561 final boolean isPortrait = getWidth() < getHeight();
Daniel Sandler388f6792010-03-02 14:08:08 -0500562 int action = ev.getAction();
563 switch (action) {
564 case MotionEvent.ACTION_DOWN:
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700565 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
566 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500567 mTouchTracking = TRACKING_HOME;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700568 sRollo.setHomeSelected(SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500569 mCurrentIconIndex = -1;
570 } else {
571 mTouchTracking = TRACKING_FLING;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800572
Daniel Sandler388f6792010-03-02 14:08:08 -0500573 mMotionDownRawX = (int)ev.getRawX();
574 mMotionDownRawY = (int)ev.getRawY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800575
Joe Onorato2cc62e82010-03-17 20:23:53 -0700576 if (!sRollo.checkClickOK()) {
577 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500578 } else {
579 mDownIconIndex = mCurrentIconIndex
Joe Onorato2cc62e82010-03-17 20:23:53 -0700580 = sRollo.selectIcon(x, y, SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500581 if (mDownIconIndex < 0) {
582 // if nothing was selected, no long press.
583 cancelLongPress();
584 }
585 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700586 sRollo.move(ev.getRawY() / getHeight());
Daniel Sandler388f6792010-03-02 14:08:08 -0500587 mVelocityTracker = VelocityTracker.obtain();
588 mVelocityTracker.addMovement(ev);
589 mStartedScrolling = false;
590 }
591 break;
592 case MotionEvent.ACTION_MOVE:
593 case MotionEvent.ACTION_OUTSIDE:
594 if (mTouchTracking == TRACKING_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700595 sRollo.setHomeSelected((isPortrait &&
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700596 y > mTouchYBorders[mTouchYBorders.length-1]) || (!isPortrait
597 && x > mTouchXBorders[mTouchXBorders.length-1])
Daniel Sandler388f6792010-03-02 14:08:08 -0500598 ? SELECTED_PRESSED : SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500599 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500600 int rawY = (int)ev.getRawY();
601 int slop;
602 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800603
Daniel Sandler388f6792010-03-02 14:08:08 -0500604 if (!mStartedScrolling && slop < mSlop) {
605 // don't update anything so when we do start scrolling
606 // below, we get the right delta.
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700607 mCurrentIconIndex = chooseTappedIcon(x, y);
Daniel Sandler388f6792010-03-02 14:08:08 -0500608 if (mDownIconIndex != mCurrentIconIndex) {
609 // If a different icon is selected, don't allow it to be picked up.
610 // This handles off-axis dragging.
611 cancelLongPress();
612 mCurrentIconIndex = -1;
613 }
614 } else {
615 if (!mStartedScrolling) {
616 cancelLongPress();
617 mCurrentIconIndex = -1;
618 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700619 sRollo.move(ev.getRawY() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800620
Daniel Sandler388f6792010-03-02 14:08:08 -0500621 mStartedScrolling = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700622 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500623 mVelocityTracker.addMovement(ev);
Daniel Sandler388f6792010-03-02 14:08:08 -0500624 }
625 }
626 break;
627 case MotionEvent.ACTION_UP:
628 case MotionEvent.ACTION_CANCEL:
629 if (mTouchTracking == TRACKING_HOME) {
630 if (action == MotionEvent.ACTION_UP) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700631 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
632 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500633 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
634 mLauncher.closeAllApps(true);
635 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700636 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500637 }
638 mCurrentIconIndex = -1;
639 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500640 mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700641 sRollo.clearSelectedIcon();
Jason Sams60a55bb2010-06-18 15:11:19 -0700642 sRollo.fling(ev.getRawY() / getHeight(),
643 mVelocityTracker.getYVelocity() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800644
Daniel Sandler388f6792010-03-02 14:08:08 -0500645 if (mVelocityTracker != null) {
646 mVelocityTracker.recycle();
647 mVelocityTracker = null;
648 }
649 }
650 mTouchTracking = TRACKING_NONE;
651 break;
652 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800653
Daniel Sandler388f6792010-03-02 14:08:08 -0500654 return true;
655 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800656
Daniel Sandler388f6792010-03-02 14:08:08 -0500657 public void onClick(View v) {
658 if (mLocks != 0 || !isVisible()) {
659 return;
660 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700661 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500662 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
663 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
664 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onoratof984e852010-03-25 09:47:45 -0700665 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500666 }
667 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800668
Daniel Sandler388f6792010-03-02 14:08:08 -0500669 public boolean onLongClick(View v) {
Joe Onorato6b4adbc2010-09-01 12:13:25 -0700670 // We don't accept long click events in these cases
671 // - If the workspace isn't ready to accept a drop
672 // - If we're not done loading (because we might be confused about which item
673 // to pick up
674 // - If we're not visible
675 if (!isVisible() || mLauncher.isWorkspaceLocked() || mLocks != 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500676 return true;
677 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700678 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500679 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
680 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800681
Daniel Sandler388f6792010-03-02 14:08:08 -0500682 Bitmap bmp = app.iconBitmap;
683 final int w = bmp.getWidth();
684 final int h = bmp.getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800685
Daniel Sandler388f6792010-03-02 14:08:08 -0500686 // We don't really have an accurate location to use. This will do.
687 int screenX = mMotionDownRawX - (w / 2);
688 int screenY = mMotionDownRawY - h;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800689
Daniel Sandler388f6792010-03-02 14:08:08 -0500690 mDragController.startDrag(bmp, screenX, screenY,
691 0, 0, w, h, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800692
Daniel Sandler388f6792010-03-02 14:08:08 -0500693 mLauncher.closeAllApps(true);
694 }
695 return true;
696 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800697
Daniel Sandler388f6792010-03-02 14:08:08 -0500698 @Override
699 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
700 if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
701 if (!isVisible()) {
702 return false;
703 }
704 String text = null;
705 int index;
706 int count = mAllAppsList.size() + 1; // +1 is home
707 int pos = -1;
708 switch (mLastSelection) {
709 case SELECTION_ICONS:
Jason Sams14f67ed2010-05-11 14:02:43 -0700710 index = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500711 if (index >= 0) {
712 ApplicationInfo info = mAllAppsList.get(index);
713 if (info.title != null) {
714 text = info.title.toString();
715 pos = index;
716 }
717 }
718 break;
719 case SELECTION_HOME:
720 text = getContext().getString(R.string.all_apps_home_button_label);
721 pos = count;
722 break;
723 }
724 if (text != null) {
725 event.setEnabled(true);
726 event.getText().add(text);
727 //event.setContentDescription(text);
728 event.setItemCount(count);
729 event.setCurrentItemIndex(pos);
730 }
731 }
732 return false;
733 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800734
Daniel Sandler388f6792010-03-02 14:08:08 -0500735 public void setDragController(DragController dragger) {
736 mDragController = dragger;
737 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800738
Daniel Sandler388f6792010-03-02 14:08:08 -0500739 public void onDropCompleted(View target, boolean success) {
740 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800741
Daniel Sandler388f6792010-03-02 14:08:08 -0500742 /**
743 * Zoom to the specifed level.
744 *
745 * @param zoom [0..1] 0 is hidden, 1 is open
746 */
747 public void zoom(float zoom, boolean animate) {
748 cancelLongPress();
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700749 sNextZoom = zoom;
750 sAnimateNextZoom = animate;
Daniel Sandler388f6792010-03-02 14:08:08 -0500751 // if we do setZoom while we don't have a surface, we won't
752 // get the callbacks that actually set mZoom.
Joe Onorato2cc62e82010-03-17 20:23:53 -0700753 if (sRollo == null || !mHaveSurface) {
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700754 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500755 mZoom = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500756 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700757 sRollo.setZoom(zoom, animate);
Daniel Sandler388f6792010-03-02 14:08:08 -0500758 }
759 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800760
Joe Onorato878f0862010-03-22 12:22:22 -0400761 /**
762 * If sRollo is null, then we're not visible. This is also used to guard against
763 * sRollo being null.
764 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500765 public boolean isVisible() {
Joe Onorato878f0862010-03-22 12:22:22 -0400766 return sRollo != null && mZoom > 0.001f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500767 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800768
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700769 public boolean isAnimating() {
770 return isVisible() && mZoom <= 0.999f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500771 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800772
Daniel Sandler388f6792010-03-02 14:08:08 -0500773 public void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700774 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500775 // We've been removed from the window. Don't bother with all this.
776 return;
777 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800778
Daniel Sandler707b0f72010-04-15 16:41:31 -0400779 if (list != null) {
780 Collections.sort(list, LauncherModel.APP_NAME_COMPARATOR);
781 }
782
Romain Guy13c2e7b2010-03-10 19:45:00 -0800783 boolean reload = false;
784 if (mAllAppsList == null) {
785 reload = true;
786 } else if (list.size() != mAllAppsList.size()) {
787 reload = true;
788 } else {
789 final int count = list.size();
790 for (int i = 0; i < count; i++) {
791 if (list.get(i) != mAllAppsList.get(i)) {
792 reload = true;
793 break;
794 }
795 }
796 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800797
Daniel Sandler388f6792010-03-02 14:08:08 -0500798 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700799 if (sRollo != null && reload) {
800 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500801 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700802
Romain Guyc16fea72010-03-12 17:17:56 -0800803 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700804 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
Romain Guyc16fea72010-03-12 17:17:56 -0800805 mRestoreFocusIndex = -1;
806 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700807
Daniel Sandler388f6792010-03-02 14:08:08 -0500808 mLocks &= ~LOCK_ICONS_PENDING;
809 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800810
Daniel Sandler388f6792010-03-02 14:08:08 -0500811 public void addApps(ArrayList<ApplicationInfo> list) {
812 if (mAllAppsList == null) {
813 // Not done loading yet. We'll find out about it later.
814 return;
815 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700816 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500817 // We've been removed from the window. Don't bother with all this.
818 return;
819 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800820
Daniel Sandler388f6792010-03-02 14:08:08 -0500821 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700822 if (sRollo != null) {
823 sRollo.pause();
Jason Sams14f67ed2010-05-11 14:02:43 -0700824 sRollo.reallocAppsList(sRollo.mScript.get_gIconCount() + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500825 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800826
Daniel Sandler388f6792010-03-02 14:08:08 -0500827 for (int i=0; i<N; i++) {
828 final ApplicationInfo item = list.get(i);
829 int index = Collections.binarySearch(mAllAppsList, item,
830 LauncherModel.APP_NAME_COMPARATOR);
831 if (index < 0) {
832 index = -(index+1);
833 }
834 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700835 if (sRollo != null) {
836 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500837 }
838 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800839
Joe Onorato2cc62e82010-03-17 20:23:53 -0700840 if (sRollo != null) {
841 sRollo.saveAppsList();
842 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500843 }
844 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800845
Daniel Sandler388f6792010-03-02 14:08:08 -0500846 public void removeApps(ArrayList<ApplicationInfo> list) {
847 if (mAllAppsList == null) {
848 // Not done loading yet. We'll find out about it later.
849 return;
850 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800851
Joe Onorato2cc62e82010-03-17 20:23:53 -0700852 if (sRollo != null) {
853 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800854 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500855 final int N = list.size();
856 for (int i=0; i<N; i++) {
857 final ApplicationInfo item = list.get(i);
858 int index = findAppByComponent(mAllAppsList, item);
859 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500860 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700861 if (sRollo != null) {
862 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500863 }
864 } else {
865 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
866 // Try to recover. This should keep us from crashing for now.
867 }
868 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800869
Joe Onorato2cc62e82010-03-17 20:23:53 -0700870 if (sRollo != null) {
871 sRollo.saveAppsList();
872 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500873 }
874 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800875
Joe Onorato64e6be72010-03-05 15:05:52 -0500876 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500877 // Just remove and add, because they may need to be re-sorted.
878 removeApps(list);
879 addApps(list);
880 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800881
Daniel Sandler388f6792010-03-02 14:08:08 -0500882 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
883 ComponentName component = item.intent.getComponent();
884 final int N = list.size();
885 for (int i=0; i<N; i++) {
886 ApplicationInfo x = list.get(i);
887 if (x.intent.getComponent().equals(component)) {
888 return i;
889 }
890 }
891 return -1;
892 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800893
Daniel Sandler388f6792010-03-02 14:08:08 -0500894 class AAMessage extends RenderScript.RSMessage {
895 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700896 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500897 mVelocity = ((float)mData[1]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700898
899 boolean lastVisible = isVisible();
Daniel Sandler388f6792010-03-02 14:08:08 -0500900 mZoom = ((float)mData[2]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700901
902 final boolean visible = isVisible();
903 if (visible != lastVisible) {
904 post(new Runnable() {
905 public void run() {
906 if (visible) {
907 showSurface();
908 } else {
909 hideSurface();
910 }
911 }
912 });
913 }
914
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700915 sZoomDirty = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500916 }
917 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800918
Romain Guy13c2e7b2010-03-10 19:45:00 -0800919 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500920 // Allocations ======
921 private int mWidth;
922 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800923
Daniel Sandler388f6792010-03-02 14:08:08 -0500924 private Resources mRes;
Jason Sams1aa4ff02010-06-15 14:59:57 -0700925 ScriptC_Allapps mScript;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800926
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700927 private Mesh mMesh;
Daniel Sandler388f6792010-03-02 14:08:08 -0500928 private ProgramVertex.MatrixAllocation mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800929
Jason Sams14f67ed2010-05-11 14:02:43 -0700930 private ScriptField_VpConsts mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800931
Daniel Sandler388f6792010-03-02 14:08:08 -0500932 private Allocation mHomeButtonNormal;
933 private Allocation mHomeButtonFocused;
934 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800935
Daniel Sandler388f6792010-03-02 14:08:08 -0500936 private Allocation[] mIcons;
937 private int[] mIconIds;
938 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800939
Daniel Sandler388f6792010-03-02 14:08:08 -0500940 private Allocation[] mLabels;
941 private int[] mLabelIds;
942 private Allocation mAllocLabelIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800943
Daniel Sandler388f6792010-03-02 14:08:08 -0500944 private Bitmap mSelectionBitmap;
945 private Canvas mSelectionCanvas;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800946
Jason Sams14f67ed2010-05-11 14:02:43 -0700947 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800948
Romain Guy13c2e7b2010-03-10 19:45:00 -0800949 AllApps3D mAllApps;
950 boolean mInitialize;
951
Daniel Sandler388f6792010-03-02 14:08:08 -0500952 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -0800953 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -0800954 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -0500955 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800956
957 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400958 if (sRS != null) {
959 sRS.contextBindRootScript(null);
960 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800961 }
962
963 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400964 if (sRS != null) {
965 sRS.contextBindRootScript(mScript);
966 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800967 }
968
Romain Guy13c2e7b2010-03-10 19:45:00 -0800969 public RolloRS(AllApps3D allApps) {
970 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -0500971 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800972
Daniel Sandler388f6792010-03-02 14:08:08 -0500973 public void init(Resources res, int width, int height) {
974 mRes = res;
975 mWidth = width;
976 mHeight = height;
Shih-wei Liaoafb81d42010-07-19 16:20:03 -0700977 mScript = new ScriptC_Allapps(sRS, mRes, R.raw.allapps, true);
Jason Sams14f67ed2010-05-11 14:02:43 -0700978
Daniel Sandler388f6792010-03-02 14:08:08 -0500979 initProgramVertex();
980 initProgramFragment();
981 initProgramStore();
982 initGl();
983 initData();
Jason Sams14f67ed2010-05-11 14:02:43 -0700984
985 mScript.bind_gIconIDs(mAllocIconIds);
986 mScript.bind_gLabelIDs(mAllocLabelIds);
Jason Sams14f67ed2010-05-11 14:02:43 -0700987 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -0500988 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800989
Daniel Sandler388f6792010-03-02 14:08:08 -0500990 public void initMesh() {
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700991 Mesh.TriangleMeshBuilder tm = new Mesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800992
Daniel Sandler388f6792010-03-02 14:08:08 -0500993 for (int ct=0; ct < 16; ct++) {
994 float pos = (1.f / (16.f - 1)) * ct;
995 tm.addVertex(0.0f, pos);
996 tm.addVertex(1.0f, pos);
997 }
998 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
999 tm.addTriangle(ct, ct+1, ct+2);
1000 tm.addTriangle(ct+1, ct+3, ct+2);
1001 }
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001002 mMesh = tm.create(true);
Jason Sams14f67ed2010-05-11 14:02:43 -07001003 mScript.set_gSMCell(mMesh);
Daniel Sandler388f6792010-03-02 14:08:08 -05001004 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001005
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001006 Matrix4f getProjectionMatrix(int w, int h) {
1007 // range -1,1 in the narrow axis at z = 0.
1008 Matrix4f m1 = new Matrix4f();
1009 Matrix4f m2 = new Matrix4f();
1010
1011 if(w > h) {
1012 float aspect = ((float)w) / h;
1013 m1.loadFrustum(-aspect,aspect, -1,1, 1,100);
1014 } else {
1015 float aspect = ((float)h) / w;
1016 m1.loadFrustum(-1,1, -aspect,aspect, 1,100);
1017 }
1018
1019 m2.loadRotate(180, 0, 1, 0);
1020 m1.loadMultiply(m1, m2);
1021
1022 m2.loadScale(-2, 2, 1);
1023 m1.loadMultiply(m1, m2);
1024
1025 m2.loadTranslate(0, 0, 2);
1026 m1.loadMultiply(m1, m2);
1027 return m1;
1028 }
1029
Daniel Sandler388f6792010-03-02 14:08:08 -05001030 void resize(int w, int h) {
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001031 Matrix4f proj = getProjectionMatrix(w, h);
1032 mPVA.loadProjection(proj);
1033
1034 if (mUniformAlloc != null) {
1035 ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
1036 i.Proj = proj;
1037 i.ScaleOffset.x = (2.f / 480.f);
1038 i.ScaleOffset.y = 0;
1039 i.ScaleOffset.z = -((float)w / 2) - 0.25f;
1040 i.ScaleOffset.w = -380.25f;
1041 i.BendPos.x = 120.f;
1042 i.BendPos.y = 680.f;
1043 if (w > h) {
1044 i.ScaleOffset.z = 40.f;
1045 i.ScaleOffset.w = h - 40.f;
1046 i.BendPos.y = 1.f;
1047 }
1048 mUniformAlloc.set(i, 0, true);
1049 }
1050
Daniel Sandler388f6792010-03-02 14:08:08 -05001051 mWidth = w;
1052 mHeight = h;
1053 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001054
Daniel Sandler388f6792010-03-02 14:08:08 -05001055 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001056 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001057 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001058
Joe Onorato2cc62e82010-03-17 20:23:53 -07001059 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001060 pvb.setTextureMatrixEnable(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001061 ProgramVertex pv = pvb.create();
1062 pv.bindAllocation(mPVA);
1063 sRS.contextBindProgramVertex(pv);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001064
Jason Sams14f67ed2010-05-11 14:02:43 -07001065 mUniformAlloc = new ScriptField_VpConsts(sRS, 1);
1066 mScript.bind_vpConstants(mUniformAlloc);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001067
Daniel Sandler388f6792010-03-02 14:08:08 -05001068 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001069 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001070 String t = "varying vec4 varColor;\n" +
1071 "varying vec4 varTex0;\n" +
1072 "void main() {\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001073 // Animation
1074 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001075
Romain Guy060b5c82010-03-04 10:07:38 -08001076 " float bendY1 = UNI_BendPos.x;\n" +
1077 " float bendY2 = UNI_BendPos.y;\n" +
1078 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1079 " float bendDistance = bendY1 * 0.4;\n" +
1080 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001081
Romain Guy060b5c82010-03-04 10:07:38 -08001082 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1083 " float aDy = cos(bendAngle);\n" +
1084 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001085
Romain Guy060b5c82010-03-04 10:07:38 -08001086 " float scale = (2.0 / 480.0);\n" +
1087 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1088 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1089 " float y = 0.0;\n" +
1090 " float z = 0.0;\n" +
1091 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001092
Romain Guy060b5c82010-03-04 10:07:38 -08001093 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1094 " y += cv * aDy;\n" +
1095 " z += -cv * aDz;\n" +
1096 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1097 " lum += cv / bendDistance * distanceDimLevel;\n" +
1098 " y += cv * cos(cv * bendStep);\n" +
1099 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001100
Romain Guy060b5c82010-03-04 10:07:38 -08001101 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1102 " y += cv * aDy;\n" +
1103 " z += cv * aDz;\n" +
1104 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1105 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1106 " y += cv * cos(cv * bendStep);\n" +
1107 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001108
Romain Guy060b5c82010-03-04 10:07:38 -08001109 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001110
Romain Guy060b5c82010-03-04 10:07:38 -08001111 " vec4 pos;\n" +
1112 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1113 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1114 " pos.z = z * UNI_ScaleOffset.x;\n" +
1115 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001116
Romain Guy060b5c82010-03-04 10:07:38 -08001117 " pos.x *= 1.0 + ani * 4.0;\n" +
1118 " pos.y *= 1.0 + ani * 4.0;\n" +
1119 " pos.z -= ani * 1.5;\n" +
1120 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001121
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001122 " gl_Position = UNI_Proj * pos;\n" +
Romain Guy060b5c82010-03-04 10:07:38 -08001123 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1124 " varTex0.xy = ATTRIB_position;\n" +
1125 " varTex0.y = 1.0 - varTex0.y;\n" +
1126 " varTex0.zw = vec2(0.0, 0.0);\n" +
1127 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001128 sb.setShader(t);
1129 sb.addConstant(mUniformAlloc.getType());
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001130 sb.addInput(mMesh.getVertexAllocation(0).getType().getElement());
Jason Sams60a55bb2010-06-18 15:11:19 -07001131 ProgramVertex pvc = sb.create();
Alex Sakhartchouk95252b42010-09-13 20:44:01 -07001132 pvc.bindConstants(mUniformAlloc.getAllocation(), 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001133
Jason Sams60a55bb2010-06-18 15:11:19 -07001134 mScript.set_gPVCurve(pvc);
Daniel Sandler388f6792010-03-02 14:08:08 -05001135 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001136
Daniel Sandler388f6792010-03-02 14:08:08 -05001137 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001138 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001139 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1140 sb.setMag(Sampler.Value.NEAREST);
1141 sb.setWrapS(Sampler.Value.CLAMP);
1142 sb.setWrapT(Sampler.Value.CLAMP);
1143 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001144
Daniel Sandler388f6792010-03-02 14:08:08 -05001145 sb.setMin(Sampler.Value.NEAREST);
1146 sb.setMag(Sampler.Value.NEAREST);
1147 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001148
Joe Onorato2cc62e82010-03-17 20:23:53 -07001149 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001150 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1151 ProgramFragment.Builder.Format.RGBA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001152 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001153 ProgramFragment pfTexMip = bf.create();
1154 pfTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001155
Jason Sams070ada82010-08-04 17:53:07 -07001156 bf.setVaryingColor(false);
Jason Sams60a55bb2010-06-18 15:11:19 -07001157 ProgramFragment pfTexNearest = bf.create();
1158 pfTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001159
Daniel Sandler388f6792010-03-02 14:08:08 -05001160 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1161 ProgramFragment.Builder.Format.ALPHA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001162 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001163 ProgramFragment pfTexMipAlpha = bf.create();
1164 pfTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001165
Jason Sams60a55bb2010-06-18 15:11:19 -07001166 mScript.set_gPFTexNearest(pfTexNearest);
1167 mScript.set_gPFTexMip(pfTexMip);
1168 mScript.set_gPFTexMipAlpha(pfTexMipAlpha);
Daniel Sandler388f6792010-03-02 14:08:08 -05001169 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001170
Daniel Sandler388f6792010-03-02 14:08:08 -05001171 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001172 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001173 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1174 bs.setColorMask(true,true,true,false);
1175 bs.setDitherEnable(true);
1176 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1177 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Jason Sams14f67ed2010-05-11 14:02:43 -07001178 mScript.set_gPS(bs.create());
Daniel Sandler388f6792010-03-02 14:08:08 -05001179 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001180
Daniel Sandler388f6792010-03-02 14:08:08 -05001181 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001182 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001183
Daniel Sandler388f6792010-03-02 14:08:08 -05001184 private void initData() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001185 mScript.set_COLUMNS_PER_PAGE_PORTRAIT(Defines.COLUMNS_PER_PAGE_PORTRAIT);
1186 mScript.set_ROWS_PER_PAGE_PORTRAIT(Defines.ROWS_PER_PAGE_PORTRAIT);
1187 mScript.set_COLUMNS_PER_PAGE_LANDSCAPE(Defines.COLUMNS_PER_PAGE_LANDSCAPE);
1188 mScript.set_ROWS_PER_PAGE_LANDSCAPE(Defines.ROWS_PER_PAGE_LANDSCAPE);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001189
Joe Onorato2cc62e82010-03-17 20:23:53 -07001190 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1191 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001192 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001193 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1194 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001195 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001196 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1197 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001198 mHomeButtonPressed.uploadToTexture(0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001199
Jason Sams14f67ed2010-05-11 14:02:43 -07001200 mScript.set_gHomeButton(mHomeButtonNormal);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001201
Daniel Sandler388f6792010-03-02 14:08:08 -05001202 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1203 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1204 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001205
Daniel Sandler388f6792010-03-02 14:08:08 -05001206 setApps(null);
1207 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001208
Daniel Sandler388f6792010-03-02 14:08:08 -05001209 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001210 if (sZoomDirty) {
1211 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001212 }
1213 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001214
Romain Guy060b5c82010-03-04 10:07:38 -08001215 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001216 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001217 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001218 final int count = list != null ? list.size() : 0;
1219 int allocCount = count;
1220 if (allocCount < 1) {
1221 allocCount = 1;
1222 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001223
Daniel Sandler388f6792010-03-02 14:08:08 -05001224 mIcons = new Allocation[count];
1225 mIconIds = new int[allocCount];
Jason Sams98994c42010-06-01 15:54:10 -07001226 mAllocIconIds = Allocation.createSized(sRS, Element.I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001227
Daniel Sandler388f6792010-03-02 14:08:08 -05001228 mLabels = new Allocation[count];
1229 mLabelIds = new int[allocCount];
Jason Sams98994c42010-06-01 15:54:10 -07001230 mAllocLabelIds = Allocation.createSized(sRS, Element.I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001231
Jason Sams14f67ed2010-05-11 14:02:43 -07001232 mScript.set_gIconCount(count);
1233 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001234 createAppIconAllocations(i, list.get(i));
1235 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001236 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001237 uploadAppIcon(i, list.get(i));
1238 }
1239 saveAppsList();
Jason Sams14f67ed2010-05-11 14:02:43 -07001240 android.util.Log.e("rs", "setApps");
Joe Onorato2cc62e82010-03-17 20:23:53 -07001241 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001242 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001243
Daniel Sandler388f6792010-03-02 14:08:08 -05001244 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001245 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001246 sRollo.clearSelectedIcon();
1247 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001248 }
Jason Sams60a55bb2010-06-18 15:11:19 -07001249 sRollo.mScript.invoke_setZoom(zoom, animate ? 1 : 0);
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 createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001253 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1254 Element.RGBA_8888(sRS), false);
1255 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1256 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001257 mIconIds[index] = mIcons[index].getID();
1258 mLabelIds[index] = mLabels[index].getID();
1259 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001260
Daniel Sandler388f6792010-03-02 14:08:08 -05001261 private void uploadAppIcon(int index, ApplicationInfo item) {
1262 if (mIconIds[index] != mIcons[index].getID()) {
1263 throw new IllegalStateException("uploadAppIcon index=" + index
1264 + " mIcons[index].getID=" + mIcons[index].getID()
1265 + " mIconsIds[index]=" + mIconIds[index]
1266 + " item=" + item);
1267 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001268 mIcons[index].uploadToTexture(true, 0);
1269 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001270 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001271
Daniel Sandler388f6792010-03-02 14:08:08 -05001272 /**
1273 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1274 * fill in the values and call saveAppsList().
1275 */
1276 private void reallocAppsList(int count) {
1277 Allocation[] icons = new Allocation[count];
1278 int[] iconIds = new int[count];
Jason Sams98994c42010-06-01 15:54:10 -07001279 mAllocIconIds = Allocation.createSized(sRS, Element.I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001280
Daniel Sandler388f6792010-03-02 14:08:08 -05001281 Allocation[] labels = new Allocation[count];
1282 int[] labelIds = new int[count];
Jason Sams98994c42010-06-01 15:54:10 -07001283 mAllocLabelIds = Allocation.createSized(sRS, Element.I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001284
Jason Sams14f67ed2010-05-11 14:02:43 -07001285 final int oldCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001286
Daniel Sandler388f6792010-03-02 14:08:08 -05001287 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1288 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1289 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1290 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001291
Daniel Sandler388f6792010-03-02 14:08:08 -05001292 mIcons = icons;
1293 mIconIds = iconIds;
1294 mLabels = labels;
1295 mLabelIds = labelIds;
1296 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001297
Daniel Sandler388f6792010-03-02 14:08:08 -05001298 /**
1299 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1300 */
1301 private void addApp(int index, ApplicationInfo item) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001302 final int count = mScript.get_gIconCount() - index;
Daniel Sandler388f6792010-03-02 14:08:08 -05001303 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001304
Daniel Sandler388f6792010-03-02 14:08:08 -05001305 System.arraycopy(mIcons, index, mIcons, dest, count);
1306 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1307 System.arraycopy(mLabels, index, mLabels, dest, count);
1308 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001309
Daniel Sandler388f6792010-03-02 14:08:08 -05001310 createAppIconAllocations(index, item);
1311 uploadAppIcon(index, item);
Jason Sams14f67ed2010-05-11 14:02:43 -07001312
1313 mScript.set_gIconCount(mScript.get_gIconCount() + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001314 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001315
Daniel Sandler388f6792010-03-02 14:08:08 -05001316 /**
1317 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1318 */
1319 private void removeApp(int index) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001320 final int count = mScript.get_gIconCount() - index - 1;
Daniel Sandler388f6792010-03-02 14:08:08 -05001321 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001322
Daniel Sandler388f6792010-03-02 14:08:08 -05001323 System.arraycopy(mIcons, src, mIcons, index, count);
1324 System.arraycopy(mIconIds, src, mIconIds, index, count);
1325 System.arraycopy(mLabels, src, mLabels, index, count);
1326 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001327
Jason Sams14f67ed2010-05-11 14:02:43 -07001328 mScript.set_gIconCount(mScript.get_gIconCount() - 1);
1329 final int last = mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001330
Daniel Sandler388f6792010-03-02 14:08:08 -05001331 mIcons[last] = null;
1332 mIconIds[last] = 0;
1333 mLabels[last] = null;
1334 mLabelIds[last] = 0;
1335 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001336
Daniel Sandler388f6792010-03-02 14:08:08 -05001337 /**
1338 * Send the apps list structures to RS.
1339 */
1340 private void saveAppsList() {
1341 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1342 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001343 mAllocIconIds.data(mIconIds);
1344 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001345
Jason Sams14f67ed2010-05-11 14:02:43 -07001346 mScript.bind_gIconIDs(mAllocIconIds);
1347 mScript.bind_gLabelIDs(mAllocLabelIds);
Daniel Sandler388f6792010-03-02 14:08:08 -05001348 }
1349 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001350
Jason Sams60a55bb2010-06-18 15:11:19 -07001351 void fling(float pos, float v) {
1352 mScript.invoke_fling(pos, v);
Daniel Sandler388f6792010-03-02 14:08:08 -05001353 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001354
Jason Sams60a55bb2010-06-18 15:11:19 -07001355 void move(float pos) {
1356 mScript.invoke_move(pos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001357 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001358
Daniel Sandler388f6792010-03-02 14:08:08 -05001359 void moveTo(float row) {
Jason Sams60a55bb2010-06-18 15:11:19 -07001360 mScript.invoke_moveTo(row);
Daniel Sandler388f6792010-03-02 14:08:08 -05001361 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001362
Daniel Sandler388f6792010-03-02 14:08:08 -05001363 /**
1364 * You need to call save() on mState on your own after calling this.
1365 *
1366 * @return the index of the icon that was selected.
1367 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001368 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001369 if (mAllApps != null) {
1370 final int index = mAllApps.chooseTappedIcon(x, y);
1371 selectIcon(index, pressed);
1372 return index;
1373 } else {
1374 return -1;
1375 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001376 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001377
Daniel Sandler388f6792010-03-02 14:08:08 -05001378 /**
1379 * Select the icon at the given index.
1380 *
1381 * @param index The index.
1382 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1383 */
1384 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001385 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1386 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001387 if (mAllApps != null) {
1388 mAllApps.mRestoreFocusIndex = index;
1389 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001390 mScript.set_gSelectedIconIndex(-1);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001391 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1392 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001393 }
1394 } else {
1395 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001396 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001397 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001398
Jason Sams14f67ed2010-05-11 14:02:43 -07001399 int prev = mScript.get_gSelectedIconIndex();
1400 mScript.set_gSelectedIconIndex(index);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001401
Romain Guy13c2e7b2010-03-10 19:45:00 -08001402 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001403 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001404
Daniel Sandler388f6792010-03-02 14:08:08 -05001405 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1406 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1407 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001408
Jason Sams60a55bb2010-06-18 15:11:19 -07001409 Allocation si = Allocation.createFromBitmap(sRS, selectionBitmap,
Joe Onorato2cc62e82010-03-17 20:23:53 -07001410 Element.RGBA_8888(sRS), false);
Jason Sams60a55bb2010-06-18 15:11:19 -07001411 si.uploadToTexture(0);
1412 mScript.set_gSelectedIconTexture(si);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001413
Daniel Sandler388f6792010-03-02 14:08:08 -05001414 if (prev != index) {
1415 if (info.title != null && info.title.length() > 0) {
1416 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001417 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001418 }
1419 }
1420 }
1421 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001422
Daniel Sandler388f6792010-03-02 14:08:08 -05001423 /**
1424 * You need to call save() on mState on your own after calling this.
1425 */
1426 void clearSelectedIcon() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001427 mScript.set_gSelectedIconIndex(-1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001428 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001429
Daniel Sandler388f6792010-03-02 14:08:08 -05001430 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001431 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001432 switch (mode) {
1433 case SELECTED_NONE:
Jason Sams14f67ed2010-05-11 14:02:43 -07001434 mScript.set_gHomeButton(mHomeButtonNormal);
Daniel Sandler388f6792010-03-02 14:08:08 -05001435 break;
1436 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001437 mAllApps.mLastSelection = SELECTION_HOME;
Jason Sams14f67ed2010-05-11 14:02:43 -07001438 mScript.set_gHomeButton(mHomeButtonFocused);
Daniel Sandler388f6792010-03-02 14:08:08 -05001439 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001440 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001441 }
1442 break;
1443 case SELECTED_PRESSED:
Jason Sams14f67ed2010-05-11 14:02:43 -07001444 mScript.set_gHomeButton(mHomeButtonPressed);
Daniel Sandler388f6792010-03-02 14:08:08 -05001445 break;
1446 }
1447 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001448
Daniel Sandler388f6792010-03-02 14:08:08 -05001449 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001450 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1451 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1452 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001453 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001454 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001455 }
1456 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001457 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001458 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001459 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001460 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001461 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001462 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001463 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Jason Sams14f67ed2010-05-11 14:02:43 -07001464 //Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1465 //Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1466 //Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1467 //Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1468 //Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1469 //Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1470 //Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1471 //Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1472 //Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001473 }
1474 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001475
Daniel Sandler388f6792010-03-02 14:08:08 -05001476 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001477 Log.d(TAG, "sRS=" + sRS);
1478 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001479 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001480 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1481 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001482 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1483 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1484 Log.d(TAG, "mLastSelection=" + mLastSelection);
1485 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1486 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1487 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1488 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001489 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1490 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001491 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001492 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001493 Log.d(TAG, "mVelocity=" + mVelocity);
1494 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001495 if (sRollo != null) {
1496 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001497 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001498 if (sRS != null) {
1499 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001500 }
1501 }
1502}