blob: 36e19ceee6c4c952748e36e24ca976897a82f59b [file] [log] [blame]
Daniel Sandler388f6792010-03-02 14:08:08 -05001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher2;
18
19import android.content.ComponentName;
20import android.content.Context;
21import android.content.res.Resources;
22import android.graphics.Bitmap;
23import android.graphics.Canvas;
24import android.graphics.PixelFormat;
25import android.graphics.Rect;
Daniel Sandler388f6792010-03-02 14:08:08 -050026import android.renderscript.Allocation;
Daniel Sandler388f6792010-03-02 14:08:08 -050027import android.renderscript.Element;
28import android.renderscript.ProgramFragment;
29import android.renderscript.ProgramStore;
30import android.renderscript.ProgramVertex;
31import android.renderscript.RSSurfaceView;
32import android.renderscript.RenderScriptGL;
33import android.renderscript.RenderScript;
34import android.renderscript.Sampler;
35import android.renderscript.Script;
36import android.renderscript.ScriptC;
37import android.renderscript.SimpleMesh;
38import android.renderscript.Type;
39import android.util.AttributeSet;
Romain Guy060b5c82010-03-04 10:07:38 -080040import android.util.DisplayMetrics;
Daniel Sandler388f6792010-03-02 14:08:08 -050041import android.util.Log;
42import android.view.KeyEvent;
43import android.view.MotionEvent;
44import android.view.SoundEffectConstants;
45import android.view.SurfaceHolder;
46import android.view.VelocityTracker;
47import android.view.View;
48import android.view.ViewConfiguration;
49import android.view.accessibility.AccessibilityEvent;
50
51import java.util.ArrayList;
52import java.util.Arrays;
53import java.util.Collections;
Daniel Sandler388f6792010-03-02 14:08:08 -050054
Romain Guyedcce092010-03-04 13:03:17 -080055import com.android.launcher.R;
56
Daniel Sandler388f6792010-03-02 14:08:08 -050057public class AllApps3D extends RSSurfaceView
58 implements AllAppsView, View.OnClickListener, View.OnLongClickListener, DragSource {
59 private static final String TAG = "Launcher.AllApps3D";
60
61 /** Bit for mLocks for when there are icons being loaded. */
62 private static final int LOCK_ICONS_PENDING = 1;
63
64 private static final int TRACKING_NONE = 0;
65 private static final int TRACKING_FLING = 1;
66 private static final int TRACKING_HOME = 2;
67
68 private static final int SELECTED_NONE = 0;
69 private static final int SELECTED_FOCUSED = 1;
70 private static final int SELECTED_PRESSED = 2;
71
72 private static final int SELECTION_NONE = 0;
73 private static final int SELECTION_ICONS = 1;
74 private static final int SELECTION_HOME = 2;
75
76 private Launcher mLauncher;
77 private DragController mDragController;
78
79 /** When this is 0, modifications are allowed, when it's not, they're not.
80 * TODO: What about scrolling? */
81 private int mLocks = LOCK_ICONS_PENDING;
82
83 private int mSlop;
84 private int mMaxFlingVelocity;
85
86 private Defines mDefines = new Defines();
Daniel Sandler388f6792010-03-02 14:08:08 -050087 private ArrayList<ApplicationInfo> mAllAppsList;
88
Joe Onorato2cc62e82010-03-17 20:23:53 -070089 private static RenderScriptGL sRS;
90 private static RolloRS sRollo;
Jason Samsdd8cd8b2010-03-11 12:38:48 -080091
Joe Onoratoeffc4a82010-04-15 11:48:13 -070092 private static boolean sZoomDirty = false;
93 private static boolean sAnimateNextZoom;
94 private static float sNextZoom;
95
Daniel Sandler388f6792010-03-02 14:08:08 -050096 /**
97 * True when we are using arrow keys or trackball to drive navigation
98 */
99 private boolean mArrowNavigation = false;
100 private boolean mStartedScrolling;
101
102 /**
103 * Used to keep track of the selection when AllAppsView loses window focus.
104 * One of the SELECTION_ constants.
105 */
106 private int mLastSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800107
Daniel Sandler388f6792010-03-02 14:08:08 -0500108 /**
109 * Used to keep track of the selection when AllAppsView loses window focus
110 */
111 private int mLastSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800112
Daniel Sandler388f6792010-03-02 14:08:08 -0500113 private VelocityTracker mVelocityTracker;
114 private int mTouchTracking;
115 private int mMotionDownRawX;
116 private int mMotionDownRawY;
117 private int mDownIconIndex = -1;
118 private int mCurrentIconIndex = -1;
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700119 private int[] mTouchYBorders;
120 private int[] mTouchXBorders;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800121
Daniel Sandler388f6792010-03-02 14:08:08 -0500122 private boolean mShouldGainFocus;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800123
Daniel Sandler388f6792010-03-02 14:08:08 -0500124 private boolean mHaveSurface = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500125 private float mZoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500126 private float mVelocity;
127 private AAMessage mMessageProc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800128
Romain Guy060b5c82010-03-04 10:07:38 -0800129 private int mColumnsPerPage;
130 private int mRowsPerPage;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800131 private boolean mSurrendered;
132
Romain Guyc16fea72010-03-12 17:17:56 -0800133 private int mRestoreFocusIndex = -1;
Jason Sams14f67ed2010-05-11 14:02:43 -0700134
Romain Guy060b5c82010-03-04 10:07:38 -0800135 @SuppressWarnings({"UnusedDeclaration"})
Daniel Sandler388f6792010-03-02 14:08:08 -0500136 static class Defines {
Romain Guy060b5c82010-03-04 10:07:38 -0800137 public static final int COLUMNS_PER_PAGE_PORTRAIT = 4;
138 public static final int ROWS_PER_PAGE_PORTRAIT = 4;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800139
Romain Guy060b5c82010-03-04 10:07:38 -0800140 public static final int COLUMNS_PER_PAGE_LANDSCAPE = 6;
141 public static final int ROWS_PER_PAGE_LANDSCAPE = 3;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800142
Daniel Sandler388f6792010-03-02 14:08:08 -0500143 public static final int SELECTION_TEXTURE_WIDTH_PX = 74 + 20;
Daniel Sandler388f6792010-03-02 14:08:08 -0500144 public static final int SELECTION_TEXTURE_HEIGHT_PX = 74 + 20;
145 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800146
Daniel Sandler388f6792010-03-02 14:08:08 -0500147 public AllApps3D(Context context, AttributeSet attrs) {
148 super(context, attrs);
149 setFocusable(true);
150 setSoundEffectsEnabled(false);
151 getHolder().setFormat(PixelFormat.TRANSLUCENT);
152 final ViewConfiguration config = ViewConfiguration.get(context);
153 mSlop = config.getScaledTouchSlop();
154 mMaxFlingVelocity = config.getScaledMaximumFlingVelocity();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800155
Daniel Sandler388f6792010-03-02 14:08:08 -0500156 setOnClickListener(this);
157 setOnLongClickListener(this);
158 setZOrderOnTop(true);
159 getHolder().setFormat(PixelFormat.TRANSLUCENT);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800160
Joe Onorato2cc62e82010-03-17 20:23:53 -0700161 if (sRS == null) {
162 sRS = createRenderScript(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800163 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700164 createRenderScript(sRS);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800165 }
166
Romain Guy060b5c82010-03-04 10:07:38 -0800167 final DisplayMetrics metrics = getResources().getDisplayMetrics();
168 final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
169 mColumnsPerPage = isPortrait ? Defines.COLUMNS_PER_PAGE_PORTRAIT :
170 Defines.COLUMNS_PER_PAGE_LANDSCAPE;
171 mRowsPerPage = isPortrait ? Defines.ROWS_PER_PAGE_PORTRAIT :
172 Defines.ROWS_PER_PAGE_LANDSCAPE;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800173
Joe Onorato2cc62e82010-03-17 20:23:53 -0700174 if (sRollo != null) {
175 sRollo.mAllApps = this;
176 sRollo.mRes = getResources();
177 sRollo.mInitialize = true;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800178 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500179 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800180
Romain Guy060b5c82010-03-04 10:07:38 -0800181 @SuppressWarnings({"UnusedDeclaration"})
182 public AllApps3D(Context context, AttributeSet attrs, int defStyle) {
183 this(context, attrs);
184 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800185
Romain Guy13c2e7b2010-03-10 19:45:00 -0800186 public void surrender() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400187 if (sRS != null) {
188 sRS.contextSetSurface(0, 0, null);
189 sRS.mMessageCallback = null;
190 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800191 mSurrendered = true;
192 }
193
Daniel Sandler388f6792010-03-02 14:08:08 -0500194 /**
195 * Note that this implementation prohibits this view from ever being reattached.
196 */
197 @Override
198 protected void onDetachedFromWindow() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700199 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800200 if (!mSurrendered) {
Joe Onorato96da4012010-03-17 20:03:24 -0700201 Log.i(TAG, "onDetachedFromWindow");
Romain Guy13c2e7b2010-03-10 19:45:00 -0800202 destroyRenderScript();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700203 sRS = null;
204 sRollo = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800205 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500206 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800207
Daniel Sandler388f6792010-03-02 14:08:08 -0500208 /**
209 * If you have an attached click listener, View always plays the click sound!?!?
210 * Deal with sound effects by hand.
211 */
212 public void reallyPlaySoundEffect(int sound) {
213 boolean old = isSoundEffectsEnabled();
214 setSoundEffectsEnabled(true);
215 playSoundEffect(sound);
216 setSoundEffectsEnabled(old);
217 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800218
Daniel Sandler388f6792010-03-02 14:08:08 -0500219 public void setLauncher(Launcher launcher) {
220 mLauncher = launcher;
221 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800222
Daniel Sandler388f6792010-03-02 14:08:08 -0500223 @Override
224 public void surfaceDestroyed(SurfaceHolder holder) {
225 super.surfaceDestroyed(holder);
226 // Without this, we leak mMessageCallback which leaks the context.
Romain Guy13c2e7b2010-03-10 19:45:00 -0800227 if (!mSurrendered) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700228 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800229 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500230 // We may lose any callbacks that are pending, so make sure that we re-sync that
231 // on the next surfaceChanged.
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700232 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500233 mHaveSurface = false;
234 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800235
Daniel Sandler388f6792010-03-02 14:08:08 -0500236 @Override
237 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
238 //long startTime = SystemClock.uptimeMillis();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800239
Daniel Sandler388f6792010-03-02 14:08:08 -0500240 super.surfaceChanged(holder, format, w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800241
Romain Guy13c2e7b2010-03-10 19:45:00 -0800242 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800243
Daniel Sandler388f6792010-03-02 14:08:08 -0500244 mHaveSurface = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800245
Joe Onorato2cc62e82010-03-17 20:23:53 -0700246 if (sRollo == null) {
247 sRollo = new RolloRS(this);
248 sRollo.init(getResources(), w, h);
Daniel Sandler388f6792010-03-02 14:08:08 -0500249 if (mAllAppsList != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700250 sRollo.setApps(mAllAppsList);
Daniel Sandler388f6792010-03-02 14:08:08 -0500251 }
252 if (mShouldGainFocus) {
253 gainFocus();
254 mShouldGainFocus = false;
255 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700256 } else if (sRollo.mInitialize) {
257 sRollo.initGl();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700258 sRollo.mInitialize = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500259 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800260
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700261 initTouchState(w, h);
262
Joe Onorato2cc62e82010-03-17 20:23:53 -0700263 sRollo.dirtyCheck();
264 sRollo.resize(w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800265
Jason Sams14f67ed2010-05-11 14:02:43 -0700266 Log.d(TAG, "sc " + sRS);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700267 if (sRS != null) {
268 sRS.mMessageCallback = mMessageProc = new AAMessage();
Daniel Sandler388f6792010-03-02 14:08:08 -0500269 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800270
Joe Onorato2cc62e82010-03-17 20:23:53 -0700271 if (sRollo.mUniformAlloc != null) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700272 float tf[] = new float[] {120.f, 120.f, 0.f, 0.f,
273 (2.f / 480.f), 0, -((float)w / 2) - 0.25f, -380.25f,
Daniel Sandler388f6792010-03-02 14:08:08 -0500274 120.f, 680.f,
Jason Sams14f67ed2010-05-11 14:02:43 -0700275 72.f, 72.f,};
Daniel Sandler388f6792010-03-02 14:08:08 -0500276 if (w > h) {
277 tf[6] = 40.f;
278 tf[7] = h - 40.f;
279 tf[9] = 1.f;
280 tf[10] = -((float)w / 2) - 0.25f;
281 tf[11] = -((float)h / 2) - 0.25f;
282 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800283
Jason Sams14f67ed2010-05-11 14:02:43 -0700284 sRollo.mUniformAlloc.getAllocation().data(tf);
Daniel Sandler388f6792010-03-02 14:08:08 -0500285 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800286
Daniel Sandler388f6792010-03-02 14:08:08 -0500287 //long endTime = SystemClock.uptimeMillis();
288 //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
289 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800290
Daniel Sandler388f6792010-03-02 14:08:08 -0500291 @Override
292 public void onWindowFocusChanged(boolean hasWindowFocus) {
293 super.onWindowFocusChanged(hasWindowFocus);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800294
295 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800296
Daniel Sandler388f6792010-03-02 14:08:08 -0500297 if (mArrowNavigation) {
298 if (!hasWindowFocus) {
299 // Clear selection when we lose window focus
Jason Sams14f67ed2010-05-11 14:02:43 -0700300 mLastSelectedIcon = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700301 sRollo.setHomeSelected(SELECTED_NONE);
302 sRollo.clearSelectedIcon();
Romain Guy060b5c82010-03-04 10:07:38 -0800303 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700304 if (sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500305 if (mLastSelection == SELECTION_ICONS) {
306 int selection = mLastSelectedIcon;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700307 final int firstIcon = Math.round(sRollo.mScrollPos) * mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500308 if (selection < 0 || // No selection
309 selection < firstIcon || // off the top of the screen
Jason Sams14f67ed2010-05-11 14:02:43 -0700310 selection >= sRollo.mScript.get_gIconCount() || // past last icon
Daniel Sandler388f6792010-03-02 14:08:08 -0500311 selection >= firstIcon + // past last icon on screen
Romain Guy060b5c82010-03-04 10:07:38 -0800312 (mColumnsPerPage * mRowsPerPage)) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500313 selection = firstIcon;
314 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800315
Daniel Sandler388f6792010-03-02 14:08:08 -0500316 // Select the first icon when we gain window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700317 sRollo.selectIcon(selection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500318 } else if (mLastSelection == SELECTION_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700319 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500320 }
321 }
322 }
323 }
324 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800325
Daniel Sandler388f6792010-03-02 14:08:08 -0500326 @Override
327 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
328 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800329
Romain Guy13c2e7b2010-03-10 19:45:00 -0800330 if (!isVisible() || mSurrendered) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500331 return;
332 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800333
Daniel Sandler388f6792010-03-02 14:08:08 -0500334 if (gainFocus) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700335 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500336 gainFocus();
337 } else {
338 mShouldGainFocus = true;
339 }
340 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700341 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500342 if (mArrowNavigation) {
343 // Clear selection when we lose focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700344 sRollo.clearSelectedIcon();
345 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500346 mArrowNavigation = false;
347 }
348 } else {
349 mShouldGainFocus = false;
350 }
351 }
352 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800353
Daniel Sandler388f6792010-03-02 14:08:08 -0500354 private void gainFocus() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700355 if (!mArrowNavigation && sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500356 // Select the first icon when we gain keyboard focus
357 mArrowNavigation = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700358 sRollo.selectIcon(Math.round(sRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500359 }
360 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800361
Daniel Sandler388f6792010-03-02 14:08:08 -0500362 @Override
363 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800364
Daniel Sandler388f6792010-03-02 14:08:08 -0500365 boolean handled = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800366
Daniel Sandler388f6792010-03-02 14:08:08 -0500367 if (!isVisible()) {
368 return false;
369 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700370 final int iconCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800371
Daniel Sandler388f6792010-03-02 14:08:08 -0500372 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
373 if (mArrowNavigation) {
374 if (mLastSelection == SELECTION_HOME) {
375 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
376 mLauncher.closeAllApps(true);
377 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700378 int whichApp = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500379 if (whichApp >= 0) {
380 ApplicationInfo app = mAllAppsList.get(whichApp);
Joe Onoratof984e852010-03-25 09:47:45 -0700381 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500382 handled = true;
383 }
384 }
385 }
386 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800387
Daniel Sandler388f6792010-03-02 14:08:08 -0500388 if (iconCount > 0) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800389 final boolean isPortrait = getWidth() < getHeight();
Jason Sams14f67ed2010-05-11 14:02:43 -0700390
Daniel Sandler388f6792010-03-02 14:08:08 -0500391 mArrowNavigation = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800392
Jason Sams14f67ed2010-05-11 14:02:43 -0700393 int currentSelection = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700394 int currentTopRow = Math.round(sRollo.mScrollPos);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800395
Romain Guy060b5c82010-03-04 10:07:38 -0800396 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1
397 final int currentPageCol = currentSelection % mColumnsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800398
Romain Guy060b5c82010-03-04 10:07:38 -0800399 // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1
Romain Guy6a42cf32010-03-12 16:03:52 -0800400 final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage))
Romain Guy060b5c82010-03-04 10:07:38 -0800401 / mRowsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800402
Daniel Sandler388f6792010-03-02 14:08:08 -0500403 int newSelection = currentSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800404
Daniel Sandler388f6792010-03-02 14:08:08 -0500405 switch (keyCode) {
406 case KeyEvent.KEYCODE_DPAD_UP:
407 if (mLastSelection == SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800408 if (isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700409 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guy6a42cf32010-03-12 16:03:52 -0800410 int lastRowCount = iconCount % mColumnsPerPage;
411 if (lastRowCount == 0) {
412 lastRowCount = mColumnsPerPage;
413 }
414 newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2);
415 if (newSelection >= iconCount) {
416 newSelection = iconCount-1;
417 }
418 int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
419 if (target < 0) {
420 target = 0;
421 }
422 if (currentTopRow != target) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700423 sRollo.moveTo(target);
Romain Guy6a42cf32010-03-12 16:03:52 -0800424 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500425 }
426 } else {
427 if (currentPageRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800428 newSelection = currentSelection - mColumnsPerPage;
Romain Guy6a42cf32010-03-12 16:03:52 -0800429 if (currentTopRow > newSelection / mColumnsPerPage) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700430 sRollo.moveTo(newSelection / mColumnsPerPage);
Romain Guy6a42cf32010-03-12 16:03:52 -0800431 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500432 } else if (currentTopRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800433 newSelection = currentSelection - mColumnsPerPage;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700434 sRollo.moveTo(newSelection / mColumnsPerPage);
Daniel Sandler388f6792010-03-02 14:08:08 -0500435 } else if (currentPageRow != 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800436 newSelection = currentTopRow * mRowsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500437 }
438 }
439 handled = true;
440 break;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800441
Daniel Sandler388f6792010-03-02 14:08:08 -0500442 case KeyEvent.KEYCODE_DPAD_DOWN: {
Romain Guy060b5c82010-03-04 10:07:38 -0800443 final int rowCount = iconCount / mColumnsPerPage
444 + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
445 final int currentRow = currentSelection / mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500446 if (mLastSelection != SELECTION_HOME) {
447 if (currentRow < rowCount-1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700448 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500449 if (currentSelection < 0) {
450 newSelection = 0;
451 } else {
Romain Guy060b5c82010-03-04 10:07:38 -0800452 newSelection = currentSelection + mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500453 }
454 if (newSelection >= iconCount) {
455 // Go from D to G in this arrangement:
456 // A B C D
457 // E F G
458 newSelection = iconCount - 1;
459 }
Romain Guy060b5c82010-03-04 10:07:38 -0800460 if (currentPageRow >= mRowsPerPage - 1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700461 sRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -0500462 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800463 } else if (isPortrait) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500464 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700465 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500466 }
467 }
468 handled = true;
469 break;
470 }
471 case KeyEvent.KEYCODE_DPAD_LEFT:
472 if (mLastSelection != SELECTION_HOME) {
473 if (currentPageCol > 0) {
474 newSelection = currentSelection - 1;
475 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800476 } else if (!isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700477 newSelection = ((int) (sRollo.mScrollPos) * mColumnsPerPage) +
Romain Guy6a42cf32010-03-12 16:03:52 -0800478 (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700479 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500480 }
481 handled = true;
482 break;
483 case KeyEvent.KEYCODE_DPAD_RIGHT:
484 if (mLastSelection != SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800485 if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 ||
486 currentSelection == iconCount - 1)) {
487 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700488 sRollo.setHomeSelected(SELECTED_FOCUSED);
Romain Guy6a42cf32010-03-12 16:03:52 -0800489 } else if ((currentPageCol < mColumnsPerPage - 1) &&
Daniel Sandler388f6792010-03-02 14:08:08 -0500490 (currentSelection < iconCount - 1)) {
491 newSelection = currentSelection + 1;
492 }
493 }
494 handled = true;
495 break;
496 }
497 if (newSelection != currentSelection) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700498 sRollo.selectIcon(newSelection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500499 }
500 }
501 return handled;
502 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800503
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700504 void initTouchState(int width, int height) {
505 boolean isPortrait = width < height;
506
507 int[] viewPos = new int[2];
508 getLocationOnScreen(viewPos);
509
510 mTouchXBorders = new int[mColumnsPerPage + 1];
511 mTouchYBorders = new int[mRowsPerPage + 1];
512
513 // TODO: Put this in a config file/define
514 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE_PORTRAIT;
515 if (!isPortrait) cellHeight -= 12;
516 int centerY = (int) (height * (isPortrait ? 0.5f : 0.47f));
517 if (!isPortrait) centerY += cellHeight / 2;
518 int half = (int) Math.floor((mRowsPerPage + 1) / 2);
519 int end = mTouchYBorders.length - (half + 1);
520
521 for (int i = -half; i <= end; i++) {
522 mTouchYBorders[i + half] = centerY + (i * cellHeight) - viewPos[1];
523 }
524
525 int x = 0;
526 // TODO: Put this in a config file/define
527 int columnWidth = 120;
528 for (int i = 0; i < mColumnsPerPage + 1; i++) {
529 mTouchXBorders[i] = x - viewPos[0];
530 x += columnWidth;
531 }
532 }
533
534 int chooseTappedIcon(int x, int y) {
535 float pos = sRollo != null ? sRollo.mScrollPos : 0;
536
537 int oldY = y;
538
539 // Adjust for scroll position if not zero.
540 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
541
542 int col = -1;
543 int row = -1;
544 final int columnsCount = mColumnsPerPage;
545 for (int i=0; i< columnsCount; i++) {
546 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
547 col = i;
548 break;
549 }
550 }
551 final int rowsCount = mRowsPerPage;
552 for (int i=0; i< rowsCount; i++) {
553 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
554 row = i;
555 break;
556 }
557 }
558
559 if (row < 0 || col < 0) {
560 return -1;
561 }
562
563 int index = (((int) pos) * columnsCount) + (row * columnsCount) + col;
564
565 if (index >= mAllAppsList.size()) {
566 return -1;
567 } else {
568 return index;
569 }
570 }
571
Daniel Sandler388f6792010-03-02 14:08:08 -0500572 @Override
573 public boolean onTouchEvent(MotionEvent ev)
574 {
575 mArrowNavigation = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800576
Daniel Sandler388f6792010-03-02 14:08:08 -0500577 if (!isVisible()) {
578 return true;
579 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800580
Daniel Sandler388f6792010-03-02 14:08:08 -0500581 if (mLocks != 0) {
582 return true;
583 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800584
Daniel Sandler388f6792010-03-02 14:08:08 -0500585 super.onTouchEvent(ev);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800586
Daniel Sandler388f6792010-03-02 14:08:08 -0500587 int x = (int)ev.getX();
588 int y = (int)ev.getY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800589
Romain Guyce115852010-03-04 12:15:37 -0800590 final boolean isPortrait = getWidth() < getHeight();
Daniel Sandler388f6792010-03-02 14:08:08 -0500591 int action = ev.getAction();
592 switch (action) {
593 case MotionEvent.ACTION_DOWN:
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700594 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
595 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500596 mTouchTracking = TRACKING_HOME;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700597 sRollo.setHomeSelected(SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500598 mCurrentIconIndex = -1;
599 } else {
600 mTouchTracking = TRACKING_FLING;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800601
Daniel Sandler388f6792010-03-02 14:08:08 -0500602 mMotionDownRawX = (int)ev.getRawX();
603 mMotionDownRawY = (int)ev.getRawY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800604
Jason Sams14f67ed2010-05-11 14:02:43 -0700605 sRollo.mScript.set_gNewPositionX(ev.getRawY() / getHeight());
606 sRollo.mScript.set_gNewTouchDown(1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800607
Joe Onorato2cc62e82010-03-17 20:23:53 -0700608 if (!sRollo.checkClickOK()) {
609 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500610 } else {
611 mDownIconIndex = mCurrentIconIndex
Joe Onorato2cc62e82010-03-17 20:23:53 -0700612 = sRollo.selectIcon(x, y, SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500613 if (mDownIconIndex < 0) {
614 // if nothing was selected, no long press.
615 cancelLongPress();
616 }
617 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700618 sRollo.move();
Daniel Sandler388f6792010-03-02 14:08:08 -0500619 mVelocityTracker = VelocityTracker.obtain();
620 mVelocityTracker.addMovement(ev);
621 mStartedScrolling = false;
622 }
623 break;
624 case MotionEvent.ACTION_MOVE:
625 case MotionEvent.ACTION_OUTSIDE:
626 if (mTouchTracking == TRACKING_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700627 sRollo.setHomeSelected((isPortrait &&
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700628 y > mTouchYBorders[mTouchYBorders.length-1]) || (!isPortrait
629 && x > mTouchXBorders[mTouchXBorders.length-1])
Daniel Sandler388f6792010-03-02 14:08:08 -0500630 ? SELECTED_PRESSED : SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500631 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500632 int rawY = (int)ev.getRawY();
633 int slop;
634 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800635
Daniel Sandler388f6792010-03-02 14:08:08 -0500636 if (!mStartedScrolling && slop < mSlop) {
637 // don't update anything so when we do start scrolling
638 // below, we get the right delta.
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700639 mCurrentIconIndex = chooseTappedIcon(x, y);
Daniel Sandler388f6792010-03-02 14:08:08 -0500640 if (mDownIconIndex != mCurrentIconIndex) {
641 // If a different icon is selected, don't allow it to be picked up.
642 // This handles off-axis dragging.
643 cancelLongPress();
644 mCurrentIconIndex = -1;
645 }
646 } else {
647 if (!mStartedScrolling) {
648 cancelLongPress();
649 mCurrentIconIndex = -1;
650 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700651 sRollo.mScript.set_gNewPositionX(ev.getRawY() / getHeight());
652 sRollo.mScript.set_gNewTouchDown(1);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700653 sRollo.move();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800654
Daniel Sandler388f6792010-03-02 14:08:08 -0500655 mStartedScrolling = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700656 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500657 mVelocityTracker.addMovement(ev);
Daniel Sandler388f6792010-03-02 14:08:08 -0500658 }
659 }
660 break;
661 case MotionEvent.ACTION_UP:
662 case MotionEvent.ACTION_CANCEL:
663 if (mTouchTracking == TRACKING_HOME) {
664 if (action == MotionEvent.ACTION_UP) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700665 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
666 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500667 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
668 mLauncher.closeAllApps(true);
669 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700670 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500671 }
672 mCurrentIconIndex = -1;
673 } else if (mTouchTracking == TRACKING_FLING) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700674 sRollo.mScript.set_gNewTouchDown(0);
675 sRollo.mScript.set_gNewPositionX(ev.getRawY() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800676
Daniel Sandler388f6792010-03-02 14:08:08 -0500677 mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Jason Sams14f67ed2010-05-11 14:02:43 -0700678 sRollo.mScript.set_gFlingVelocity(mVelocityTracker.getYVelocity() / getHeight());
Joe Onorato2cc62e82010-03-17 20:23:53 -0700679 sRollo.clearSelectedIcon();
Jason Sams14f67ed2010-05-11 14:02:43 -0700680 sRollo.move();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700681 sRollo.fling();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800682
Daniel Sandler388f6792010-03-02 14:08:08 -0500683 if (mVelocityTracker != null) {
684 mVelocityTracker.recycle();
685 mVelocityTracker = null;
686 }
687 }
688 mTouchTracking = TRACKING_NONE;
689 break;
690 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800691
Daniel Sandler388f6792010-03-02 14:08:08 -0500692 return true;
693 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800694
Daniel Sandler388f6792010-03-02 14:08:08 -0500695 public void onClick(View v) {
696 if (mLocks != 0 || !isVisible()) {
697 return;
698 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700699 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500700 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
701 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
702 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onoratof984e852010-03-25 09:47:45 -0700703 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500704 }
705 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800706
Daniel Sandler388f6792010-03-02 14:08:08 -0500707 public boolean onLongClick(View v) {
708 if (mLocks != 0 || !isVisible()) {
709 return true;
710 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700711 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500712 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
713 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800714
Daniel Sandler388f6792010-03-02 14:08:08 -0500715 Bitmap bmp = app.iconBitmap;
716 final int w = bmp.getWidth();
717 final int h = bmp.getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800718
Daniel Sandler388f6792010-03-02 14:08:08 -0500719 // We don't really have an accurate location to use. This will do.
720 int screenX = mMotionDownRawX - (w / 2);
721 int screenY = mMotionDownRawY - h;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800722
Daniel Sandler388f6792010-03-02 14:08:08 -0500723 mDragController.startDrag(bmp, screenX, screenY,
724 0, 0, w, h, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800725
Daniel Sandler388f6792010-03-02 14:08:08 -0500726 mLauncher.closeAllApps(true);
727 }
728 return true;
729 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800730
Daniel Sandler388f6792010-03-02 14:08:08 -0500731 @Override
732 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
733 if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
734 if (!isVisible()) {
735 return false;
736 }
737 String text = null;
738 int index;
739 int count = mAllAppsList.size() + 1; // +1 is home
740 int pos = -1;
741 switch (mLastSelection) {
742 case SELECTION_ICONS:
Jason Sams14f67ed2010-05-11 14:02:43 -0700743 index = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500744 if (index >= 0) {
745 ApplicationInfo info = mAllAppsList.get(index);
746 if (info.title != null) {
747 text = info.title.toString();
748 pos = index;
749 }
750 }
751 break;
752 case SELECTION_HOME:
753 text = getContext().getString(R.string.all_apps_home_button_label);
754 pos = count;
755 break;
756 }
757 if (text != null) {
758 event.setEnabled(true);
759 event.getText().add(text);
760 //event.setContentDescription(text);
761 event.setItemCount(count);
762 event.setCurrentItemIndex(pos);
763 }
764 }
765 return false;
766 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800767
Daniel Sandler388f6792010-03-02 14:08:08 -0500768 public void setDragController(DragController dragger) {
769 mDragController = dragger;
770 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800771
Daniel Sandler388f6792010-03-02 14:08:08 -0500772 public void onDropCompleted(View target, boolean success) {
773 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800774
Daniel Sandler388f6792010-03-02 14:08:08 -0500775 /**
776 * Zoom to the specifed level.
777 *
778 * @param zoom [0..1] 0 is hidden, 1 is open
779 */
780 public void zoom(float zoom, boolean animate) {
781 cancelLongPress();
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700782 sNextZoom = zoom;
783 sAnimateNextZoom = animate;
Daniel Sandler388f6792010-03-02 14:08:08 -0500784 // if we do setZoom while we don't have a surface, we won't
785 // get the callbacks that actually set mZoom.
Joe Onorato2cc62e82010-03-17 20:23:53 -0700786 if (sRollo == null || !mHaveSurface) {
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700787 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500788 mZoom = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500789 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700790 sRollo.setZoom(zoom, animate);
Daniel Sandler388f6792010-03-02 14:08:08 -0500791 }
792 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800793
Joe Onorato878f0862010-03-22 12:22:22 -0400794 /**
795 * If sRollo is null, then we're not visible. This is also used to guard against
796 * sRollo being null.
797 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500798 public boolean isVisible() {
Joe Onorato878f0862010-03-22 12:22:22 -0400799 return sRollo != null && mZoom > 0.001f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500800 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800801
Daniel Sandler388f6792010-03-02 14:08:08 -0500802 public boolean isOpaque() {
803 return mZoom > 0.999f;
804 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800805
Daniel Sandler388f6792010-03-02 14:08:08 -0500806 public void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700807 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500808 // We've been removed from the window. Don't bother with all this.
809 return;
810 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800811
Daniel Sandler707b0f72010-04-15 16:41:31 -0400812 if (list != null) {
813 Collections.sort(list, LauncherModel.APP_NAME_COMPARATOR);
814 }
815
Romain Guy13c2e7b2010-03-10 19:45:00 -0800816 boolean reload = false;
817 if (mAllAppsList == null) {
818 reload = true;
819 } else if (list.size() != mAllAppsList.size()) {
820 reload = true;
821 } else {
822 final int count = list.size();
823 for (int i = 0; i < count; i++) {
824 if (list.get(i) != mAllAppsList.get(i)) {
825 reload = true;
826 break;
827 }
828 }
829 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800830
Daniel Sandler388f6792010-03-02 14:08:08 -0500831 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700832 if (sRollo != null && reload) {
833 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500834 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700835
Romain Guyc16fea72010-03-12 17:17:56 -0800836 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700837 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
Romain Guyc16fea72010-03-12 17:17:56 -0800838 mRestoreFocusIndex = -1;
839 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700840
Daniel Sandler388f6792010-03-02 14:08:08 -0500841 mLocks &= ~LOCK_ICONS_PENDING;
842 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800843
Daniel Sandler388f6792010-03-02 14:08:08 -0500844 public void addApps(ArrayList<ApplicationInfo> list) {
845 if (mAllAppsList == null) {
846 // Not done loading yet. We'll find out about it later.
847 return;
848 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700849 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500850 // We've been removed from the window. Don't bother with all this.
851 return;
852 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800853
Daniel Sandler388f6792010-03-02 14:08:08 -0500854 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700855 if (sRollo != null) {
856 sRollo.pause();
Jason Sams14f67ed2010-05-11 14:02:43 -0700857 sRollo.reallocAppsList(sRollo.mScript.get_gIconCount() + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500858 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800859
Daniel Sandler388f6792010-03-02 14:08:08 -0500860 for (int i=0; i<N; i++) {
861 final ApplicationInfo item = list.get(i);
862 int index = Collections.binarySearch(mAllAppsList, item,
863 LauncherModel.APP_NAME_COMPARATOR);
864 if (index < 0) {
865 index = -(index+1);
866 }
867 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700868 if (sRollo != null) {
869 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500870 }
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
Daniel Sandler388f6792010-03-02 14:08:08 -0500879 public void removeApps(ArrayList<ApplicationInfo> list) {
880 if (mAllAppsList == null) {
881 // Not done loading yet. We'll find out about it later.
882 return;
883 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800884
Joe Onorato2cc62e82010-03-17 20:23:53 -0700885 if (sRollo != null) {
886 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800887 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500888 final int N = list.size();
889 for (int i=0; i<N; i++) {
890 final ApplicationInfo item = list.get(i);
891 int index = findAppByComponent(mAllAppsList, item);
892 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500893 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700894 if (sRollo != null) {
895 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500896 }
897 } else {
898 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
899 // Try to recover. This should keep us from crashing for now.
900 }
901 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800902
Joe Onorato2cc62e82010-03-17 20:23:53 -0700903 if (sRollo != null) {
904 sRollo.saveAppsList();
905 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500906 }
907 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800908
Joe Onorato64e6be72010-03-05 15:05:52 -0500909 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500910 // Just remove and add, because they may need to be re-sorted.
911 removeApps(list);
912 addApps(list);
913 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800914
Daniel Sandler388f6792010-03-02 14:08:08 -0500915 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
916 ComponentName component = item.intent.getComponent();
917 final int N = list.size();
918 for (int i=0; i<N; i++) {
919 ApplicationInfo x = list.get(i);
920 if (x.intent.getComponent().equals(component)) {
921 return i;
922 }
923 }
924 return -1;
925 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800926
Romain Guy060b5c82010-03-04 10:07:38 -0800927 /*
Daniel Sandler388f6792010-03-02 14:08:08 -0500928 private static int countPages(int iconCount) {
Romain Guy060b5c82010-03-04 10:07:38 -0800929 int iconsPerPage = getColumnsCount() * Defines.ROWS_PER_PAGE_PORTRAIT;
Daniel Sandler388f6792010-03-02 14:08:08 -0500930 int pages = iconCount / iconsPerPage;
931 if (pages*iconsPerPage != iconCount) {
932 pages++;
933 }
934 return pages;
935 }
Romain Guy060b5c82010-03-04 10:07:38 -0800936 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500937
938 class AAMessage extends RenderScript.RSMessage {
939 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700940 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500941 mVelocity = ((float)mData[1]) / (1 << 16);
942 mZoom = ((float)mData[2]) / (1 << 16);
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700943 sZoomDirty = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500944 }
945 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800946
Romain Guy13c2e7b2010-03-10 19:45:00 -0800947 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500948 // Allocations ======
949 private int mWidth;
950 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800951
Daniel Sandler388f6792010-03-02 14:08:08 -0500952 private Resources mRes;
Jason Sams14f67ed2010-05-11 14:02:43 -0700953 ScriptC_allapps mScript;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800954
Jason Sams14f67ed2010-05-11 14:02:43 -0700955 //private ProgramStore mPSIcons;
Daniel Sandler388f6792010-03-02 14:08:08 -0500956 private ProgramFragment mPFTexMip;
957 private ProgramFragment mPFTexMipAlpha;
958 private ProgramFragment mPFTexNearest;
959 private ProgramVertex mPV;
960 private ProgramVertex mPVCurve;
961 private SimpleMesh mMesh;
962 private ProgramVertex.MatrixAllocation mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800963
Jason Sams14f67ed2010-05-11 14:02:43 -0700964 private ScriptField_VpConsts mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800965
Daniel Sandler388f6792010-03-02 14:08:08 -0500966 private Allocation mHomeButtonNormal;
967 private Allocation mHomeButtonFocused;
968 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800969
Daniel Sandler388f6792010-03-02 14:08:08 -0500970 private Allocation[] mIcons;
971 private int[] mIconIds;
972 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800973
Daniel Sandler388f6792010-03-02 14:08:08 -0500974 private Allocation[] mLabels;
975 private int[] mLabelIds;
976 private Allocation mAllocLabelIds;
977 private Allocation mSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800978
Daniel Sandler388f6792010-03-02 14:08:08 -0500979 private Bitmap mSelectionBitmap;
980 private Canvas mSelectionCanvas;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800981
Jason Sams14f67ed2010-05-11 14:02:43 -0700982 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800983
Romain Guy13c2e7b2010-03-10 19:45:00 -0800984 AllApps3D mAllApps;
985 boolean mInitialize;
986
Daniel Sandler388f6792010-03-02 14:08:08 -0500987 class BaseAlloc {
988 Allocation mAlloc;
989 Type mType;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800990
Daniel Sandler388f6792010-03-02 14:08:08 -0500991 void save() {
992 mAlloc.data(this);
993 }
994 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800995
Daniel Sandler388f6792010-03-02 14:08:08 -0500996 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -0800997 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -0800998 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -0500999 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001000
1001 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001002 if (sRS != null) {
1003 sRS.contextBindRootScript(null);
1004 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001005 }
1006
1007 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001008 if (sRS != null) {
1009 sRS.contextBindRootScript(mScript);
1010 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001011 }
1012
Romain Guy13c2e7b2010-03-10 19:45:00 -08001013 public RolloRS(AllApps3D allApps) {
1014 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -05001015 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001016
Daniel Sandler388f6792010-03-02 14:08:08 -05001017 public void init(Resources res, int width, int height) {
1018 mRes = res;
1019 mWidth = width;
1020 mHeight = height;
Jason Sams14f67ed2010-05-11 14:02:43 -07001021 mScript = new ScriptC_allapps(sRS, mRes, R.raw.allapps_bc, true);
Jason Sams14f67ed2010-05-11 14:02:43 -07001022
Daniel Sandler388f6792010-03-02 14:08:08 -05001023 initProgramVertex();
1024 initProgramFragment();
1025 initProgramStore();
1026 initGl();
1027 initData();
Jason Sams14f67ed2010-05-11 14:02:43 -07001028
1029 mScript.bind_gIconIDs(mAllocIconIds);
1030 mScript.bind_gLabelIDs(mAllocLabelIds);
Jason Sams14f67ed2010-05-11 14:02:43 -07001031 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -05001032 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001033
Daniel Sandler388f6792010-03-02 14:08:08 -05001034 public void initMesh() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001035 SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001036
Daniel Sandler388f6792010-03-02 14:08:08 -05001037 for (int ct=0; ct < 16; ct++) {
1038 float pos = (1.f / (16.f - 1)) * ct;
1039 tm.addVertex(0.0f, pos);
1040 tm.addVertex(1.0f, pos);
1041 }
1042 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1043 tm.addTriangle(ct, ct+1, ct+2);
1044 tm.addTriangle(ct+1, ct+3, ct+2);
1045 }
1046 mMesh = tm.create();
Jason Sams14f67ed2010-05-11 14:02:43 -07001047 mScript.set_gSMCell(mMesh);
Daniel Sandler388f6792010-03-02 14:08:08 -05001048 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001049
Daniel Sandler388f6792010-03-02 14:08:08 -05001050 void resize(int w, int h) {
1051 mPVA.setupProjectionNormalized(w, h);
1052 mWidth = w;
1053 mHeight = h;
1054 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001055
Daniel Sandler388f6792010-03-02 14:08:08 -05001056 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001057 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001058 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001059
Joe Onorato2cc62e82010-03-17 20:23:53 -07001060 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001061 pvb.setTextureMatrixEnable(true);
1062 mPV = pvb.create();
Daniel Sandler388f6792010-03-02 14:08:08 -05001063 mPV.bindAllocation(mPVA);
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);
Romain Guy060b5c82010-03-04 10:07:38 -08001070 String t = "void main() {\n" +
1071 // Animation
1072 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001073
Romain Guy060b5c82010-03-04 10:07:38 -08001074 " float bendY1 = UNI_BendPos.x;\n" +
1075 " float bendY2 = UNI_BendPos.y;\n" +
1076 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1077 " float bendDistance = bendY1 * 0.4;\n" +
1078 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001079
Romain Guy060b5c82010-03-04 10:07:38 -08001080 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1081 " float aDy = cos(bendAngle);\n" +
1082 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001083
Romain Guy060b5c82010-03-04 10:07:38 -08001084 " float scale = (2.0 / 480.0);\n" +
1085 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1086 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1087 " float y = 0.0;\n" +
1088 " float z = 0.0;\n" +
1089 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001090
Romain Guy060b5c82010-03-04 10:07:38 -08001091 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1092 " y += cv * aDy;\n" +
1093 " z += -cv * aDz;\n" +
1094 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1095 " lum += cv / bendDistance * distanceDimLevel;\n" +
1096 " y += cv * cos(cv * bendStep);\n" +
1097 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001098
Romain Guy060b5c82010-03-04 10:07:38 -08001099 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1100 " y += cv * aDy;\n" +
1101 " z += cv * aDz;\n" +
1102 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1103 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1104 " y += cv * cos(cv * bendStep);\n" +
1105 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001106
Romain Guy060b5c82010-03-04 10:07:38 -08001107 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001108
Romain Guy060b5c82010-03-04 10:07:38 -08001109 " vec4 pos;\n" +
1110 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1111 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1112 " pos.z = z * UNI_ScaleOffset.x;\n" +
1113 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001114
Romain Guy060b5c82010-03-04 10:07:38 -08001115 " pos.x *= 1.0 + ani * 4.0;\n" +
1116 " pos.y *= 1.0 + ani * 4.0;\n" +
1117 " pos.z -= ani * 1.5;\n" +
1118 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001119
Romain Guy060b5c82010-03-04 10:07:38 -08001120 " gl_Position = UNI_MVP * pos;\n" +
1121 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1122 " varTex0.xy = ATTRIB_position;\n" +
1123 " varTex0.y = 1.0 - varTex0.y;\n" +
1124 " varTex0.zw = vec2(0.0, 0.0);\n" +
1125 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001126 sb.setShader(t);
1127 sb.addConstant(mUniformAlloc.getType());
1128 sb.addInput(mMesh.getVertexType(0).getElement());
1129 mPVCurve = sb.create();
Daniel Sandler388f6792010-03-02 14:08:08 -05001130 mPVCurve.bindAllocation(mPVA);
Jason Sams14f67ed2010-05-11 14:02:43 -07001131 mPVCurve.bindConstants(mUniformAlloc.getAllocation(), 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001132
Joe Onorato2cc62e82010-03-17 20:23:53 -07001133 sRS.contextBindProgramVertex(mPV);
Jason Sams14f67ed2010-05-11 14:02:43 -07001134 mScript.set_gPVCurve(mPVCurve);
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);
1152 mPFTexMip = bf.create();
Daniel Sandler388f6792010-03-02 14:08:08 -05001153 mPFTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001154
Daniel Sandler388f6792010-03-02 14:08:08 -05001155 mPFTexNearest = bf.create();
Daniel Sandler388f6792010-03-02 14:08:08 -05001156 mPFTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001157
Daniel Sandler388f6792010-03-02 14:08:08 -05001158 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1159 ProgramFragment.Builder.Format.ALPHA, 0);
1160 mPFTexMipAlpha = bf.create();
Daniel Sandler388f6792010-03-02 14:08:08 -05001161 mPFTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001162
Jason Sams14f67ed2010-05-11 14:02:43 -07001163 mScript.set_gPFTexNearest(mPFTexNearest);
1164 mScript.set_gPFTexMip(mPFTexMip);
1165 mScript.set_gPFTexMipAlpha(mPFTexMipAlpha);
Daniel Sandler388f6792010-03-02 14:08:08 -05001166 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001167
Daniel Sandler388f6792010-03-02 14:08:08 -05001168 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001169 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001170 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1171 bs.setColorMask(true,true,true,false);
1172 bs.setDitherEnable(true);
1173 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1174 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Jason Sams14f67ed2010-05-11 14:02:43 -07001175 mScript.set_gPS(bs.create());
Daniel Sandler388f6792010-03-02 14:08:08 -05001176 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001177
Daniel Sandler388f6792010-03-02 14:08:08 -05001178 private void initGl() {
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 initData() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001182 mScript.set_COLUMNS_PER_PAGE_PORTRAIT(Defines.COLUMNS_PER_PAGE_PORTRAIT);
1183 mScript.set_ROWS_PER_PAGE_PORTRAIT(Defines.ROWS_PER_PAGE_PORTRAIT);
1184 mScript.set_COLUMNS_PER_PAGE_LANDSCAPE(Defines.COLUMNS_PER_PAGE_LANDSCAPE);
1185 mScript.set_ROWS_PER_PAGE_LANDSCAPE(Defines.ROWS_PER_PAGE_LANDSCAPE);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001186
Joe Onorato2cc62e82010-03-17 20:23:53 -07001187 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1188 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001189 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001190 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1191 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001192 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001193 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1194 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001195 mHomeButtonPressed.uploadToTexture(0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001196
Jason Sams14f67ed2010-05-11 14:02:43 -07001197 mScript.set_gHomeButton(mHomeButtonNormal);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001198
Daniel Sandler388f6792010-03-02 14:08:08 -05001199 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1200 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1201 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001202
Daniel Sandler388f6792010-03-02 14:08:08 -05001203 setApps(null);
1204 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001205
Daniel Sandler388f6792010-03-02 14:08:08 -05001206 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001207 if (sZoomDirty) {
1208 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001209 }
1210 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001211
Romain Guy060b5c82010-03-04 10:07:38 -08001212 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001213 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001214 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001215 final int count = list != null ? list.size() : 0;
1216 int allocCount = count;
1217 if (allocCount < 1) {
1218 allocCount = 1;
1219 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001220
Daniel Sandler388f6792010-03-02 14:08:08 -05001221 mIcons = new Allocation[count];
1222 mIconIds = new int[allocCount];
Jason Sams98994c42010-06-01 15:54:10 -07001223 mAllocIconIds = Allocation.createSized(sRS, Element.I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001224
Daniel Sandler388f6792010-03-02 14:08:08 -05001225 mLabels = new Allocation[count];
1226 mLabelIds = new int[allocCount];
Jason Sams98994c42010-06-01 15:54:10 -07001227 mAllocLabelIds = Allocation.createSized(sRS, Element.I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001228
Jason Sams14f67ed2010-05-11 14:02:43 -07001229 mScript.set_gIconCount(count);
1230 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001231 createAppIconAllocations(i, list.get(i));
1232 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001233 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001234 uploadAppIcon(i, list.get(i));
1235 }
1236 saveAppsList();
Jason Sams14f67ed2010-05-11 14:02:43 -07001237 android.util.Log.e("rs", "setApps");
Joe Onorato2cc62e82010-03-17 20:23:53 -07001238 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001239 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001240
Daniel Sandler388f6792010-03-02 14:08:08 -05001241 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001242 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001243 sRollo.clearSelectedIcon();
1244 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001245 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001246 if (zoom > 0.001f) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001247 sRollo.mScript.set_gZoomTarget(zoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001248 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -07001249 sRollo.mScript.set_gZoomTarget(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001250 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001251 if (!animate) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001252 sRollo.mScript.invokable_SetZoom();
Daniel Sandler388f6792010-03-02 14:08:08 -05001253 }
1254 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001255
Daniel Sandler388f6792010-03-02 14:08:08 -05001256 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001257 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1258 Element.RGBA_8888(sRS), false);
1259 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1260 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001261 mIconIds[index] = mIcons[index].getID();
1262 mLabelIds[index] = mLabels[index].getID();
1263 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001264
Daniel Sandler388f6792010-03-02 14:08:08 -05001265 private void uploadAppIcon(int index, ApplicationInfo item) {
1266 if (mIconIds[index] != mIcons[index].getID()) {
1267 throw new IllegalStateException("uploadAppIcon index=" + index
1268 + " mIcons[index].getID=" + mIcons[index].getID()
1269 + " mIconsIds[index]=" + mIconIds[index]
1270 + " item=" + item);
1271 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001272 mIcons[index].uploadToTexture(true, 0);
1273 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001274 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001275
Daniel Sandler388f6792010-03-02 14:08:08 -05001276 /**
1277 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1278 * fill in the values and call saveAppsList().
1279 */
1280 private void reallocAppsList(int count) {
1281 Allocation[] icons = new Allocation[count];
1282 int[] iconIds = new int[count];
Jason Sams98994c42010-06-01 15:54:10 -07001283 mAllocIconIds = Allocation.createSized(sRS, Element.I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001284
Daniel Sandler388f6792010-03-02 14:08:08 -05001285 Allocation[] labels = new Allocation[count];
1286 int[] labelIds = new int[count];
Jason Sams98994c42010-06-01 15:54:10 -07001287 mAllocLabelIds = Allocation.createSized(sRS, Element.I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001288
Jason Sams14f67ed2010-05-11 14:02:43 -07001289 final int oldCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001290
Daniel Sandler388f6792010-03-02 14:08:08 -05001291 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1292 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1293 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1294 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001295
Daniel Sandler388f6792010-03-02 14:08:08 -05001296 mIcons = icons;
1297 mIconIds = iconIds;
1298 mLabels = labels;
1299 mLabelIds = labelIds;
1300 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001301
Daniel Sandler388f6792010-03-02 14:08:08 -05001302 /**
1303 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1304 */
1305 private void addApp(int index, ApplicationInfo item) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001306 final int count = mScript.get_gIconCount() - index;
Daniel Sandler388f6792010-03-02 14:08:08 -05001307 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001308
Daniel Sandler388f6792010-03-02 14:08:08 -05001309 System.arraycopy(mIcons, index, mIcons, dest, count);
1310 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1311 System.arraycopy(mLabels, index, mLabels, dest, count);
1312 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001313
Daniel Sandler388f6792010-03-02 14:08:08 -05001314 createAppIconAllocations(index, item);
1315 uploadAppIcon(index, item);
Jason Sams14f67ed2010-05-11 14:02:43 -07001316
1317 mScript.set_gIconCount(mScript.get_gIconCount() + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001318 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001319
Daniel Sandler388f6792010-03-02 14:08:08 -05001320 /**
1321 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1322 */
1323 private void removeApp(int index) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001324 final int count = mScript.get_gIconCount() - index - 1;
Daniel Sandler388f6792010-03-02 14:08:08 -05001325 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001326
Daniel Sandler388f6792010-03-02 14:08:08 -05001327 System.arraycopy(mIcons, src, mIcons, index, count);
1328 System.arraycopy(mIconIds, src, mIconIds, index, count);
1329 System.arraycopy(mLabels, src, mLabels, index, count);
1330 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001331
Jason Sams14f67ed2010-05-11 14:02:43 -07001332 mScript.set_gIconCount(mScript.get_gIconCount() - 1);
1333 final int last = mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001334
Daniel Sandler388f6792010-03-02 14:08:08 -05001335 mIcons[last] = null;
1336 mIconIds[last] = 0;
1337 mLabels[last] = null;
1338 mLabelIds[last] = 0;
1339 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001340
Daniel Sandler388f6792010-03-02 14:08:08 -05001341 /**
1342 * Send the apps list structures to RS.
1343 */
1344 private void saveAppsList() {
1345 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1346 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001347 mAllocIconIds.data(mIconIds);
1348 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001349
Jason Sams14f67ed2010-05-11 14:02:43 -07001350 mScript.bind_gIconIDs(mAllocIconIds);
1351 mScript.bind_gLabelIDs(mAllocLabelIds);
Daniel Sandler388f6792010-03-02 14:08:08 -05001352 }
1353 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001354
Daniel Sandler388f6792010-03-02 14:08:08 -05001355 void fling() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001356 mScript.invokable_Fling();
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 move() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001360 mScript.invokable_Move();
Daniel Sandler388f6792010-03-02 14:08:08 -05001361 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001362
Daniel Sandler388f6792010-03-02 14:08:08 -05001363 void moveTo(float row) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001364 mScript.set_gTargetPos(row);
1365 mScript.invokable_MoveTo();
Daniel Sandler388f6792010-03-02 14:08:08 -05001366 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001367
Daniel Sandler388f6792010-03-02 14:08:08 -05001368 /**
1369 * You need to call save() on mState on your own after calling this.
1370 *
1371 * @return the index of the icon that was selected.
1372 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001373 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001374 if (mAllApps != null) {
1375 final int index = mAllApps.chooseTappedIcon(x, y);
1376 selectIcon(index, pressed);
1377 return index;
1378 } else {
1379 return -1;
1380 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001381 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001382
Daniel Sandler388f6792010-03-02 14:08:08 -05001383 /**
1384 * Select the icon at the given index.
1385 *
1386 * @param index The index.
1387 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1388 */
1389 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001390 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1391 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001392 if (mAllApps != null) {
1393 mAllApps.mRestoreFocusIndex = index;
1394 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001395 mScript.set_gSelectedIconIndex(-1);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001396 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1397 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001398 }
1399 } else {
1400 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001401 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001402 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001403
Jason Sams14f67ed2010-05-11 14:02:43 -07001404 int prev = mScript.get_gSelectedIconIndex();
1405 mScript.set_gSelectedIconIndex(index);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001406
Romain Guy13c2e7b2010-03-10 19:45:00 -08001407 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001408 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001409
Daniel Sandler388f6792010-03-02 14:08:08 -05001410 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1411 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1412 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001413
Joe Onorato2cc62e82010-03-17 20:23:53 -07001414 mSelectedIcon = Allocation.createFromBitmap(sRS, selectionBitmap,
1415 Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001416 mSelectedIcon.uploadToTexture(0);
Jason Sams14f67ed2010-05-11 14:02:43 -07001417 mScript.set_gSelectedIconTexture(mSelectedIcon);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001418
Daniel Sandler388f6792010-03-02 14:08:08 -05001419 if (prev != index) {
1420 if (info.title != null && info.title.length() > 0) {
1421 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001422 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001423 }
1424 }
1425 }
1426 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001427
Daniel Sandler388f6792010-03-02 14:08:08 -05001428 /**
1429 * You need to call save() on mState on your own after calling this.
1430 */
1431 void clearSelectedIcon() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001432 mScript.set_gSelectedIconIndex(-1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001433 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001434
Daniel Sandler388f6792010-03-02 14:08:08 -05001435 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001436 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001437 switch (mode) {
1438 case SELECTED_NONE:
Jason Sams14f67ed2010-05-11 14:02:43 -07001439 mScript.set_gHomeButton(mHomeButtonNormal);
Daniel Sandler388f6792010-03-02 14:08:08 -05001440 break;
1441 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001442 mAllApps.mLastSelection = SELECTION_HOME;
Jason Sams14f67ed2010-05-11 14:02:43 -07001443 mScript.set_gHomeButton(mHomeButtonFocused);
Daniel Sandler388f6792010-03-02 14:08:08 -05001444 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001445 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001446 }
1447 break;
1448 case SELECTED_PRESSED:
Jason Sams14f67ed2010-05-11 14:02:43 -07001449 mScript.set_gHomeButton(mHomeButtonPressed);
Daniel Sandler388f6792010-03-02 14:08:08 -05001450 break;
1451 }
1452 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001453
Daniel Sandler388f6792010-03-02 14:08:08 -05001454 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001455 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1456 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1457 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001458 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001459 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001460 }
1461 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001462 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001463 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001464 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001465 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001466 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001467 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001468 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Jason Sams14f67ed2010-05-11 14:02:43 -07001469 //Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1470 //Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1471 //Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1472 //Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1473 //Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1474 //Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1475 //Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1476 //Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1477 //Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001478 }
1479 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001480
Daniel Sandler388f6792010-03-02 14:08:08 -05001481 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001482 Log.d(TAG, "sRS=" + sRS);
1483 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001484 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001485 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1486 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001487 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1488 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1489 Log.d(TAG, "mLastSelection=" + mLastSelection);
1490 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1491 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1492 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1493 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001494 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1495 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001496 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001497 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001498 Log.d(TAG, "mVelocity=" + mVelocity);
1499 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001500 if (sRollo != null) {
1501 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001502 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001503 if (sRS != null) {
1504 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001505 }
1506 }
1507}
1508
1509