blob: 8896ec0ef598c8ac3bccc828199c04c6c696cf02 [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);
Daniel Sandler388f6792010-03-02 14:08:08 -0500151 final ViewConfiguration config = ViewConfiguration.get(context);
152 mSlop = config.getScaledTouchSlop();
153 mMaxFlingVelocity = config.getScaledMaximumFlingVelocity();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800154
Daniel Sandler388f6792010-03-02 14:08:08 -0500155 setOnClickListener(this);
156 setOnLongClickListener(this);
157 setZOrderOnTop(true);
158 getHolder().setFormat(PixelFormat.TRANSLUCENT);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800159
Joe Onorato2cc62e82010-03-17 20:23:53 -0700160 if (sRS == null) {
161 sRS = createRenderScript(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800162 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700163 createRenderScript(sRS);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800164 }
165
Romain Guy060b5c82010-03-04 10:07:38 -0800166 final DisplayMetrics metrics = getResources().getDisplayMetrics();
167 final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
168 mColumnsPerPage = isPortrait ? Defines.COLUMNS_PER_PAGE_PORTRAIT :
169 Defines.COLUMNS_PER_PAGE_LANDSCAPE;
170 mRowsPerPage = isPortrait ? Defines.ROWS_PER_PAGE_PORTRAIT :
171 Defines.ROWS_PER_PAGE_LANDSCAPE;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800172
Joe Onorato2cc62e82010-03-17 20:23:53 -0700173 if (sRollo != null) {
174 sRollo.mAllApps = this;
175 sRollo.mRes = getResources();
176 sRollo.mInitialize = true;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800177 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500178 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800179
Romain Guy060b5c82010-03-04 10:07:38 -0800180 @SuppressWarnings({"UnusedDeclaration"})
181 public AllApps3D(Context context, AttributeSet attrs, int defStyle) {
182 this(context, attrs);
183 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800184
Romain Guy13c2e7b2010-03-10 19:45:00 -0800185 public void surrender() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400186 if (sRS != null) {
187 sRS.contextSetSurface(0, 0, null);
188 sRS.mMessageCallback = null;
189 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800190 mSurrendered = true;
191 }
192
Daniel Sandler388f6792010-03-02 14:08:08 -0500193 /**
194 * Note that this implementation prohibits this view from ever being reattached.
195 */
196 @Override
197 protected void onDetachedFromWindow() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700198 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800199 if (!mSurrendered) {
Joe Onorato96da4012010-03-17 20:03:24 -0700200 Log.i(TAG, "onDetachedFromWindow");
Romain Guy13c2e7b2010-03-10 19:45:00 -0800201 destroyRenderScript();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700202 sRS = null;
203 sRollo = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800204 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500205 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800206
Daniel Sandler388f6792010-03-02 14:08:08 -0500207 /**
208 * If you have an attached click listener, View always plays the click sound!?!?
209 * Deal with sound effects by hand.
210 */
211 public void reallyPlaySoundEffect(int sound) {
212 boolean old = isSoundEffectsEnabled();
213 setSoundEffectsEnabled(true);
214 playSoundEffect(sound);
215 setSoundEffectsEnabled(old);
216 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800217
Daniel Sandler388f6792010-03-02 14:08:08 -0500218 public void setLauncher(Launcher launcher) {
219 mLauncher = launcher;
220 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800221
Daniel Sandler388f6792010-03-02 14:08:08 -0500222 @Override
223 public void surfaceDestroyed(SurfaceHolder holder) {
224 super.surfaceDestroyed(holder);
225 // Without this, we leak mMessageCallback which leaks the context.
Romain Guy13c2e7b2010-03-10 19:45:00 -0800226 if (!mSurrendered) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700227 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800228 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500229 // We may lose any callbacks that are pending, so make sure that we re-sync that
230 // on the next surfaceChanged.
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700231 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500232 mHaveSurface = false;
233 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800234
Daniel Sandler388f6792010-03-02 14:08:08 -0500235 @Override
236 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
237 //long startTime = SystemClock.uptimeMillis();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800238
Daniel Sandler388f6792010-03-02 14:08:08 -0500239 super.surfaceChanged(holder, format, w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800240
Romain Guy13c2e7b2010-03-10 19:45:00 -0800241 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800242
Daniel Sandler388f6792010-03-02 14:08:08 -0500243 mHaveSurface = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800244
Joe Onorato2cc62e82010-03-17 20:23:53 -0700245 if (sRollo == null) {
246 sRollo = new RolloRS(this);
247 sRollo.init(getResources(), w, h);
Daniel Sandler388f6792010-03-02 14:08:08 -0500248 if (mAllAppsList != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700249 sRollo.setApps(mAllAppsList);
Daniel Sandler388f6792010-03-02 14:08:08 -0500250 }
251 if (mShouldGainFocus) {
252 gainFocus();
253 mShouldGainFocus = false;
254 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700255 } else if (sRollo.mInitialize) {
256 sRollo.initGl();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700257 sRollo.mInitialize = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500258 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800259
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700260 initTouchState(w, h);
261
Joe Onorato2cc62e82010-03-17 20:23:53 -0700262 sRollo.dirtyCheck();
263 sRollo.resize(w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800264
Jason Sams14f67ed2010-05-11 14:02:43 -0700265 Log.d(TAG, "sc " + sRS);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700266 if (sRS != null) {
267 sRS.mMessageCallback = mMessageProc = new AAMessage();
Daniel Sandler388f6792010-03-02 14:08:08 -0500268 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800269
Joe Onorato2cc62e82010-03-17 20:23:53 -0700270 if (sRollo.mUniformAlloc != null) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700271 float tf[] = new float[] {120.f, 120.f, 0.f, 0.f,
272 (2.f / 480.f), 0, -((float)w / 2) - 0.25f, -380.25f,
Daniel Sandler388f6792010-03-02 14:08:08 -0500273 120.f, 680.f,
Jason Sams14f67ed2010-05-11 14:02:43 -0700274 72.f, 72.f,};
Daniel Sandler388f6792010-03-02 14:08:08 -0500275 if (w > h) {
276 tf[6] = 40.f;
277 tf[7] = h - 40.f;
278 tf[9] = 1.f;
279 tf[10] = -((float)w / 2) - 0.25f;
280 tf[11] = -((float)h / 2) - 0.25f;
281 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800282
Jason Sams14f67ed2010-05-11 14:02:43 -0700283 sRollo.mUniformAlloc.getAllocation().data(tf);
Daniel Sandler388f6792010-03-02 14:08:08 -0500284 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800285
Daniel Sandler388f6792010-03-02 14:08:08 -0500286 //long endTime = SystemClock.uptimeMillis();
287 //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
288 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800289
Daniel Sandler388f6792010-03-02 14:08:08 -0500290 @Override
291 public void onWindowFocusChanged(boolean hasWindowFocus) {
292 super.onWindowFocusChanged(hasWindowFocus);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800293
294 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800295
Daniel Sandler388f6792010-03-02 14:08:08 -0500296 if (mArrowNavigation) {
297 if (!hasWindowFocus) {
298 // Clear selection when we lose window focus
Jason Sams14f67ed2010-05-11 14:02:43 -0700299 mLastSelectedIcon = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700300 sRollo.setHomeSelected(SELECTED_NONE);
301 sRollo.clearSelectedIcon();
Romain Guy060b5c82010-03-04 10:07:38 -0800302 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700303 if (sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500304 if (mLastSelection == SELECTION_ICONS) {
305 int selection = mLastSelectedIcon;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700306 final int firstIcon = Math.round(sRollo.mScrollPos) * mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500307 if (selection < 0 || // No selection
308 selection < firstIcon || // off the top of the screen
Jason Sams14f67ed2010-05-11 14:02:43 -0700309 selection >= sRollo.mScript.get_gIconCount() || // past last icon
Daniel Sandler388f6792010-03-02 14:08:08 -0500310 selection >= firstIcon + // past last icon on screen
Romain Guy060b5c82010-03-04 10:07:38 -0800311 (mColumnsPerPage * mRowsPerPage)) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500312 selection = firstIcon;
313 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800314
Daniel Sandler388f6792010-03-02 14:08:08 -0500315 // Select the first icon when we gain window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700316 sRollo.selectIcon(selection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500317 } else if (mLastSelection == SELECTION_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700318 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500319 }
320 }
321 }
322 }
323 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800324
Daniel Sandler388f6792010-03-02 14:08:08 -0500325 @Override
326 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
327 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800328
Romain Guy13c2e7b2010-03-10 19:45:00 -0800329 if (!isVisible() || mSurrendered) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500330 return;
331 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800332
Daniel Sandler388f6792010-03-02 14:08:08 -0500333 if (gainFocus) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700334 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500335 gainFocus();
336 } else {
337 mShouldGainFocus = true;
338 }
339 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700340 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500341 if (mArrowNavigation) {
342 // Clear selection when we lose focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700343 sRollo.clearSelectedIcon();
344 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500345 mArrowNavigation = false;
346 }
347 } else {
348 mShouldGainFocus = false;
349 }
350 }
351 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800352
Daniel Sandler388f6792010-03-02 14:08:08 -0500353 private void gainFocus() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700354 if (!mArrowNavigation && sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500355 // Select the first icon when we gain keyboard focus
356 mArrowNavigation = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700357 sRollo.selectIcon(Math.round(sRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500358 }
359 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800360
Daniel Sandler388f6792010-03-02 14:08:08 -0500361 @Override
362 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800363
Daniel Sandler388f6792010-03-02 14:08:08 -0500364 boolean handled = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800365
Daniel Sandler388f6792010-03-02 14:08:08 -0500366 if (!isVisible()) {
367 return false;
368 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700369 final int iconCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800370
Daniel Sandler388f6792010-03-02 14:08:08 -0500371 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
372 if (mArrowNavigation) {
373 if (mLastSelection == SELECTION_HOME) {
374 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
375 mLauncher.closeAllApps(true);
376 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700377 int whichApp = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500378 if (whichApp >= 0) {
379 ApplicationInfo app = mAllAppsList.get(whichApp);
Joe Onoratof984e852010-03-25 09:47:45 -0700380 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500381 handled = true;
382 }
383 }
384 }
385 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800386
Daniel Sandler388f6792010-03-02 14:08:08 -0500387 if (iconCount > 0) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800388 final boolean isPortrait = getWidth() < getHeight();
Jason Sams14f67ed2010-05-11 14:02:43 -0700389
Daniel Sandler388f6792010-03-02 14:08:08 -0500390 mArrowNavigation = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800391
Jason Sams14f67ed2010-05-11 14:02:43 -0700392 int currentSelection = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700393 int currentTopRow = Math.round(sRollo.mScrollPos);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800394
Romain Guy060b5c82010-03-04 10:07:38 -0800395 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1
396 final int currentPageCol = currentSelection % mColumnsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800397
Romain Guy060b5c82010-03-04 10:07:38 -0800398 // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1
Romain Guy6a42cf32010-03-12 16:03:52 -0800399 final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage))
Romain Guy060b5c82010-03-04 10:07:38 -0800400 / mRowsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800401
Daniel Sandler388f6792010-03-02 14:08:08 -0500402 int newSelection = currentSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800403
Daniel Sandler388f6792010-03-02 14:08:08 -0500404 switch (keyCode) {
405 case KeyEvent.KEYCODE_DPAD_UP:
406 if (mLastSelection == SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800407 if (isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700408 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guy6a42cf32010-03-12 16:03:52 -0800409 int lastRowCount = iconCount % mColumnsPerPage;
410 if (lastRowCount == 0) {
411 lastRowCount = mColumnsPerPage;
412 }
413 newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2);
414 if (newSelection >= iconCount) {
415 newSelection = iconCount-1;
416 }
417 int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
418 if (target < 0) {
419 target = 0;
420 }
421 if (currentTopRow != target) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700422 sRollo.moveTo(target);
Romain Guy6a42cf32010-03-12 16:03:52 -0800423 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500424 }
425 } else {
426 if (currentPageRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800427 newSelection = currentSelection - mColumnsPerPage;
Romain Guy6a42cf32010-03-12 16:03:52 -0800428 if (currentTopRow > newSelection / mColumnsPerPage) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700429 sRollo.moveTo(newSelection / mColumnsPerPage);
Romain Guy6a42cf32010-03-12 16:03:52 -0800430 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500431 } else if (currentTopRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800432 newSelection = currentSelection - mColumnsPerPage;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700433 sRollo.moveTo(newSelection / mColumnsPerPage);
Daniel Sandler388f6792010-03-02 14:08:08 -0500434 } else if (currentPageRow != 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800435 newSelection = currentTopRow * mRowsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500436 }
437 }
438 handled = true;
439 break;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800440
Daniel Sandler388f6792010-03-02 14:08:08 -0500441 case KeyEvent.KEYCODE_DPAD_DOWN: {
Romain Guy060b5c82010-03-04 10:07:38 -0800442 final int rowCount = iconCount / mColumnsPerPage
443 + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
444 final int currentRow = currentSelection / mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500445 if (mLastSelection != SELECTION_HOME) {
446 if (currentRow < rowCount-1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700447 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500448 if (currentSelection < 0) {
449 newSelection = 0;
450 } else {
Romain Guy060b5c82010-03-04 10:07:38 -0800451 newSelection = currentSelection + mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500452 }
453 if (newSelection >= iconCount) {
454 // Go from D to G in this arrangement:
455 // A B C D
456 // E F G
457 newSelection = iconCount - 1;
458 }
Romain Guy060b5c82010-03-04 10:07:38 -0800459 if (currentPageRow >= mRowsPerPage - 1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700460 sRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -0500461 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800462 } else if (isPortrait) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500463 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700464 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500465 }
466 }
467 handled = true;
468 break;
469 }
470 case KeyEvent.KEYCODE_DPAD_LEFT:
471 if (mLastSelection != SELECTION_HOME) {
472 if (currentPageCol > 0) {
473 newSelection = currentSelection - 1;
474 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800475 } else if (!isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700476 newSelection = ((int) (sRollo.mScrollPos) * mColumnsPerPage) +
Romain Guy6a42cf32010-03-12 16:03:52 -0800477 (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700478 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500479 }
480 handled = true;
481 break;
482 case KeyEvent.KEYCODE_DPAD_RIGHT:
483 if (mLastSelection != SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800484 if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 ||
485 currentSelection == iconCount - 1)) {
486 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700487 sRollo.setHomeSelected(SELECTED_FOCUSED);
Romain Guy6a42cf32010-03-12 16:03:52 -0800488 } else if ((currentPageCol < mColumnsPerPage - 1) &&
Daniel Sandler388f6792010-03-02 14:08:08 -0500489 (currentSelection < iconCount - 1)) {
490 newSelection = currentSelection + 1;
491 }
492 }
493 handled = true;
494 break;
495 }
496 if (newSelection != currentSelection) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700497 sRollo.selectIcon(newSelection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500498 }
499 }
500 return handled;
501 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800502
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700503 void initTouchState(int width, int height) {
504 boolean isPortrait = width < height;
505
506 int[] viewPos = new int[2];
507 getLocationOnScreen(viewPos);
508
509 mTouchXBorders = new int[mColumnsPerPage + 1];
510 mTouchYBorders = new int[mRowsPerPage + 1];
511
512 // TODO: Put this in a config file/define
513 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE_PORTRAIT;
514 if (!isPortrait) cellHeight -= 12;
515 int centerY = (int) (height * (isPortrait ? 0.5f : 0.47f));
516 if (!isPortrait) centerY += cellHeight / 2;
517 int half = (int) Math.floor((mRowsPerPage + 1) / 2);
518 int end = mTouchYBorders.length - (half + 1);
519
520 for (int i = -half; i <= end; i++) {
521 mTouchYBorders[i + half] = centerY + (i * cellHeight) - viewPos[1];
522 }
523
524 int x = 0;
525 // TODO: Put this in a config file/define
526 int columnWidth = 120;
527 for (int i = 0; i < mColumnsPerPage + 1; i++) {
528 mTouchXBorders[i] = x - viewPos[0];
529 x += columnWidth;
530 }
531 }
532
533 int chooseTappedIcon(int x, int y) {
534 float pos = sRollo != null ? sRollo.mScrollPos : 0;
535
536 int oldY = y;
537
538 // Adjust for scroll position if not zero.
539 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
540
541 int col = -1;
542 int row = -1;
543 final int columnsCount = mColumnsPerPage;
544 for (int i=0; i< columnsCount; i++) {
545 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
546 col = i;
547 break;
548 }
549 }
550 final int rowsCount = mRowsPerPage;
551 for (int i=0; i< rowsCount; i++) {
552 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
553 row = i;
554 break;
555 }
556 }
557
558 if (row < 0 || col < 0) {
559 return -1;
560 }
561
562 int index = (((int) pos) * columnsCount) + (row * columnsCount) + col;
563
564 if (index >= mAllAppsList.size()) {
565 return -1;
566 } else {
567 return index;
568 }
569 }
570
Daniel Sandler388f6792010-03-02 14:08:08 -0500571 @Override
572 public boolean onTouchEvent(MotionEvent ev)
573 {
574 mArrowNavigation = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800575
Daniel Sandler388f6792010-03-02 14:08:08 -0500576 if (!isVisible()) {
577 return true;
578 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800579
Daniel Sandler388f6792010-03-02 14:08:08 -0500580 if (mLocks != 0) {
581 return true;
582 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800583
Daniel Sandler388f6792010-03-02 14:08:08 -0500584 super.onTouchEvent(ev);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800585
Daniel Sandler388f6792010-03-02 14:08:08 -0500586 int x = (int)ev.getX();
587 int y = (int)ev.getY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800588
Romain Guyce115852010-03-04 12:15:37 -0800589 final boolean isPortrait = getWidth() < getHeight();
Daniel Sandler388f6792010-03-02 14:08:08 -0500590 int action = ev.getAction();
591 switch (action) {
592 case MotionEvent.ACTION_DOWN:
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700593 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
594 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500595 mTouchTracking = TRACKING_HOME;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700596 sRollo.setHomeSelected(SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500597 mCurrentIconIndex = -1;
598 } else {
599 mTouchTracking = TRACKING_FLING;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800600
Daniel Sandler388f6792010-03-02 14:08:08 -0500601 mMotionDownRawX = (int)ev.getRawX();
602 mMotionDownRawY = (int)ev.getRawY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800603
Jason Sams14f67ed2010-05-11 14:02:43 -0700604 sRollo.mScript.set_gNewPositionX(ev.getRawY() / getHeight());
605 sRollo.mScript.set_gNewTouchDown(1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800606
Joe Onorato2cc62e82010-03-17 20:23:53 -0700607 if (!sRollo.checkClickOK()) {
608 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500609 } else {
610 mDownIconIndex = mCurrentIconIndex
Joe Onorato2cc62e82010-03-17 20:23:53 -0700611 = sRollo.selectIcon(x, y, SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500612 if (mDownIconIndex < 0) {
613 // if nothing was selected, no long press.
614 cancelLongPress();
615 }
616 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700617 sRollo.move();
Daniel Sandler388f6792010-03-02 14:08:08 -0500618 mVelocityTracker = VelocityTracker.obtain();
619 mVelocityTracker.addMovement(ev);
620 mStartedScrolling = false;
621 }
622 break;
623 case MotionEvent.ACTION_MOVE:
624 case MotionEvent.ACTION_OUTSIDE:
625 if (mTouchTracking == TRACKING_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700626 sRollo.setHomeSelected((isPortrait &&
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700627 y > mTouchYBorders[mTouchYBorders.length-1]) || (!isPortrait
628 && x > mTouchXBorders[mTouchXBorders.length-1])
Daniel Sandler388f6792010-03-02 14:08:08 -0500629 ? SELECTED_PRESSED : SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500630 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500631 int rawY = (int)ev.getRawY();
632 int slop;
633 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800634
Daniel Sandler388f6792010-03-02 14:08:08 -0500635 if (!mStartedScrolling && slop < mSlop) {
636 // don't update anything so when we do start scrolling
637 // below, we get the right delta.
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700638 mCurrentIconIndex = chooseTappedIcon(x, y);
Daniel Sandler388f6792010-03-02 14:08:08 -0500639 if (mDownIconIndex != mCurrentIconIndex) {
640 // If a different icon is selected, don't allow it to be picked up.
641 // This handles off-axis dragging.
642 cancelLongPress();
643 mCurrentIconIndex = -1;
644 }
645 } else {
646 if (!mStartedScrolling) {
647 cancelLongPress();
648 mCurrentIconIndex = -1;
649 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700650 sRollo.mScript.set_gNewPositionX(ev.getRawY() / getHeight());
651 sRollo.mScript.set_gNewTouchDown(1);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700652 sRollo.move();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800653
Daniel Sandler388f6792010-03-02 14:08:08 -0500654 mStartedScrolling = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700655 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500656 mVelocityTracker.addMovement(ev);
Daniel Sandler388f6792010-03-02 14:08:08 -0500657 }
658 }
659 break;
660 case MotionEvent.ACTION_UP:
661 case MotionEvent.ACTION_CANCEL:
662 if (mTouchTracking == TRACKING_HOME) {
663 if (action == MotionEvent.ACTION_UP) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700664 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
665 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500666 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
667 mLauncher.closeAllApps(true);
668 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700669 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500670 }
671 mCurrentIconIndex = -1;
672 } else if (mTouchTracking == TRACKING_FLING) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700673 sRollo.mScript.set_gNewTouchDown(0);
674 sRollo.mScript.set_gNewPositionX(ev.getRawY() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800675
Daniel Sandler388f6792010-03-02 14:08:08 -0500676 mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Jason Sams14f67ed2010-05-11 14:02:43 -0700677 sRollo.mScript.set_gFlingVelocity(mVelocityTracker.getYVelocity() / getHeight());
Joe Onorato2cc62e82010-03-17 20:23:53 -0700678 sRollo.clearSelectedIcon();
Jason Sams14f67ed2010-05-11 14:02:43 -0700679 sRollo.move();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700680 sRollo.fling();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800681
Daniel Sandler388f6792010-03-02 14:08:08 -0500682 if (mVelocityTracker != null) {
683 mVelocityTracker.recycle();
684 mVelocityTracker = null;
685 }
686 }
687 mTouchTracking = TRACKING_NONE;
688 break;
689 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800690
Daniel Sandler388f6792010-03-02 14:08:08 -0500691 return true;
692 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800693
Daniel Sandler388f6792010-03-02 14:08:08 -0500694 public void onClick(View v) {
695 if (mLocks != 0 || !isVisible()) {
696 return;
697 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700698 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500699 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
700 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
701 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onoratof984e852010-03-25 09:47:45 -0700702 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500703 }
704 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800705
Daniel Sandler388f6792010-03-02 14:08:08 -0500706 public boolean onLongClick(View v) {
707 if (mLocks != 0 || !isVisible()) {
708 return true;
709 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700710 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500711 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
712 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800713
Daniel Sandler388f6792010-03-02 14:08:08 -0500714 Bitmap bmp = app.iconBitmap;
715 final int w = bmp.getWidth();
716 final int h = bmp.getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800717
Daniel Sandler388f6792010-03-02 14:08:08 -0500718 // We don't really have an accurate location to use. This will do.
719 int screenX = mMotionDownRawX - (w / 2);
720 int screenY = mMotionDownRawY - h;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800721
Daniel Sandler388f6792010-03-02 14:08:08 -0500722 mDragController.startDrag(bmp, screenX, screenY,
723 0, 0, w, h, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800724
Daniel Sandler388f6792010-03-02 14:08:08 -0500725 mLauncher.closeAllApps(true);
726 }
727 return true;
728 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800729
Daniel Sandler388f6792010-03-02 14:08:08 -0500730 @Override
731 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
732 if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
733 if (!isVisible()) {
734 return false;
735 }
736 String text = null;
737 int index;
738 int count = mAllAppsList.size() + 1; // +1 is home
739 int pos = -1;
740 switch (mLastSelection) {
741 case SELECTION_ICONS:
Jason Sams14f67ed2010-05-11 14:02:43 -0700742 index = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500743 if (index >= 0) {
744 ApplicationInfo info = mAllAppsList.get(index);
745 if (info.title != null) {
746 text = info.title.toString();
747 pos = index;
748 }
749 }
750 break;
751 case SELECTION_HOME:
752 text = getContext().getString(R.string.all_apps_home_button_label);
753 pos = count;
754 break;
755 }
756 if (text != null) {
757 event.setEnabled(true);
758 event.getText().add(text);
759 //event.setContentDescription(text);
760 event.setItemCount(count);
761 event.setCurrentItemIndex(pos);
762 }
763 }
764 return false;
765 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800766
Daniel Sandler388f6792010-03-02 14:08:08 -0500767 public void setDragController(DragController dragger) {
768 mDragController = dragger;
769 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800770
Daniel Sandler388f6792010-03-02 14:08:08 -0500771 public void onDropCompleted(View target, boolean success) {
772 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800773
Daniel Sandler388f6792010-03-02 14:08:08 -0500774 /**
775 * Zoom to the specifed level.
776 *
777 * @param zoom [0..1] 0 is hidden, 1 is open
778 */
779 public void zoom(float zoom, boolean animate) {
780 cancelLongPress();
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700781 sNextZoom = zoom;
782 sAnimateNextZoom = animate;
Daniel Sandler388f6792010-03-02 14:08:08 -0500783 // if we do setZoom while we don't have a surface, we won't
784 // get the callbacks that actually set mZoom.
Joe Onorato2cc62e82010-03-17 20:23:53 -0700785 if (sRollo == null || !mHaveSurface) {
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700786 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500787 mZoom = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500788 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700789 sRollo.setZoom(zoom, animate);
Daniel Sandler388f6792010-03-02 14:08:08 -0500790 }
791 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800792
Joe Onorato878f0862010-03-22 12:22:22 -0400793 /**
794 * If sRollo is null, then we're not visible. This is also used to guard against
795 * sRollo being null.
796 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500797 public boolean isVisible() {
Joe Onorato878f0862010-03-22 12:22:22 -0400798 return sRollo != null && mZoom > 0.001f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500799 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800800
Daniel Sandler388f6792010-03-02 14:08:08 -0500801 public boolean isOpaque() {
802 return mZoom > 0.999f;
803 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800804
Daniel Sandler388f6792010-03-02 14:08:08 -0500805 public void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700806 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500807 // We've been removed from the window. Don't bother with all this.
808 return;
809 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800810
Daniel Sandler707b0f72010-04-15 16:41:31 -0400811 if (list != null) {
812 Collections.sort(list, LauncherModel.APP_NAME_COMPARATOR);
813 }
814
Romain Guy13c2e7b2010-03-10 19:45:00 -0800815 boolean reload = false;
816 if (mAllAppsList == null) {
817 reload = true;
818 } else if (list.size() != mAllAppsList.size()) {
819 reload = true;
820 } else {
821 final int count = list.size();
822 for (int i = 0; i < count; i++) {
823 if (list.get(i) != mAllAppsList.get(i)) {
824 reload = true;
825 break;
826 }
827 }
828 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800829
Daniel Sandler388f6792010-03-02 14:08:08 -0500830 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700831 if (sRollo != null && reload) {
832 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500833 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700834
Romain Guyc16fea72010-03-12 17:17:56 -0800835 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700836 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
Romain Guyc16fea72010-03-12 17:17:56 -0800837 mRestoreFocusIndex = -1;
838 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700839
Daniel Sandler388f6792010-03-02 14:08:08 -0500840 mLocks &= ~LOCK_ICONS_PENDING;
841 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800842
Daniel Sandler388f6792010-03-02 14:08:08 -0500843 public void addApps(ArrayList<ApplicationInfo> list) {
844 if (mAllAppsList == null) {
845 // Not done loading yet. We'll find out about it later.
846 return;
847 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700848 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500849 // We've been removed from the window. Don't bother with all this.
850 return;
851 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800852
Daniel Sandler388f6792010-03-02 14:08:08 -0500853 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700854 if (sRollo != null) {
855 sRollo.pause();
Jason Sams14f67ed2010-05-11 14:02:43 -0700856 sRollo.reallocAppsList(sRollo.mScript.get_gIconCount() + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500857 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800858
Daniel Sandler388f6792010-03-02 14:08:08 -0500859 for (int i=0; i<N; i++) {
860 final ApplicationInfo item = list.get(i);
861 int index = Collections.binarySearch(mAllAppsList, item,
862 LauncherModel.APP_NAME_COMPARATOR);
863 if (index < 0) {
864 index = -(index+1);
865 }
866 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700867 if (sRollo != null) {
868 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500869 }
870 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800871
Joe Onorato2cc62e82010-03-17 20:23:53 -0700872 if (sRollo != null) {
873 sRollo.saveAppsList();
874 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500875 }
876 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800877
Daniel Sandler388f6792010-03-02 14:08:08 -0500878 public void removeApps(ArrayList<ApplicationInfo> list) {
879 if (mAllAppsList == null) {
880 // Not done loading yet. We'll find out about it later.
881 return;
882 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800883
Joe Onorato2cc62e82010-03-17 20:23:53 -0700884 if (sRollo != null) {
885 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800886 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500887 final int N = list.size();
888 for (int i=0; i<N; i++) {
889 final ApplicationInfo item = list.get(i);
890 int index = findAppByComponent(mAllAppsList, item);
891 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500892 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700893 if (sRollo != null) {
894 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500895 }
896 } else {
897 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
898 // Try to recover. This should keep us from crashing for now.
899 }
900 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800901
Joe Onorato2cc62e82010-03-17 20:23:53 -0700902 if (sRollo != null) {
903 sRollo.saveAppsList();
904 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500905 }
906 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800907
Joe Onorato64e6be72010-03-05 15:05:52 -0500908 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500909 // Just remove and add, because they may need to be re-sorted.
910 removeApps(list);
911 addApps(list);
912 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800913
Daniel Sandler388f6792010-03-02 14:08:08 -0500914 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
915 ComponentName component = item.intent.getComponent();
916 final int N = list.size();
917 for (int i=0; i<N; i++) {
918 ApplicationInfo x = list.get(i);
919 if (x.intent.getComponent().equals(component)) {
920 return i;
921 }
922 }
923 return -1;
924 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800925
Romain Guy060b5c82010-03-04 10:07:38 -0800926 /*
Daniel Sandler388f6792010-03-02 14:08:08 -0500927 private static int countPages(int iconCount) {
Romain Guy060b5c82010-03-04 10:07:38 -0800928 int iconsPerPage = getColumnsCount() * Defines.ROWS_PER_PAGE_PORTRAIT;
Daniel Sandler388f6792010-03-02 14:08:08 -0500929 int pages = iconCount / iconsPerPage;
930 if (pages*iconsPerPage != iconCount) {
931 pages++;
932 }
933 return pages;
934 }
Romain Guy060b5c82010-03-04 10:07:38 -0800935 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500936
937 class AAMessage extends RenderScript.RSMessage {
938 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700939 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500940 mVelocity = ((float)mData[1]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700941
942 boolean lastVisible = isVisible();
Daniel Sandler388f6792010-03-02 14:08:08 -0500943 mZoom = ((float)mData[2]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700944
945 final boolean visible = isVisible();
946 if (visible != lastVisible) {
947 post(new Runnable() {
948 public void run() {
949 if (visible) {
950 showSurface();
951 } else {
952 hideSurface();
953 }
954 }
955 });
956 }
957
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700958 sZoomDirty = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500959 }
960 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800961
Romain Guy13c2e7b2010-03-10 19:45:00 -0800962 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500963 // Allocations ======
964 private int mWidth;
965 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800966
Daniel Sandler388f6792010-03-02 14:08:08 -0500967 private Resources mRes;
Jason Sams1aa4ff02010-06-15 14:59:57 -0700968 ScriptC_Allapps mScript;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800969
Jason Sams14f67ed2010-05-11 14:02:43 -0700970 //private ProgramStore mPSIcons;
Daniel Sandler388f6792010-03-02 14:08:08 -0500971 private ProgramFragment mPFTexMip;
972 private ProgramFragment mPFTexMipAlpha;
973 private ProgramFragment mPFTexNearest;
974 private ProgramVertex mPV;
975 private ProgramVertex mPVCurve;
976 private SimpleMesh mMesh;
977 private ProgramVertex.MatrixAllocation mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800978
Jason Sams14f67ed2010-05-11 14:02:43 -0700979 private ScriptField_VpConsts mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800980
Daniel Sandler388f6792010-03-02 14:08:08 -0500981 private Allocation mHomeButtonNormal;
982 private Allocation mHomeButtonFocused;
983 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800984
Daniel Sandler388f6792010-03-02 14:08:08 -0500985 private Allocation[] mIcons;
986 private int[] mIconIds;
987 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800988
Daniel Sandler388f6792010-03-02 14:08:08 -0500989 private Allocation[] mLabels;
990 private int[] mLabelIds;
991 private Allocation mAllocLabelIds;
992 private Allocation mSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800993
Daniel Sandler388f6792010-03-02 14:08:08 -0500994 private Bitmap mSelectionBitmap;
995 private Canvas mSelectionCanvas;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800996
Jason Sams14f67ed2010-05-11 14:02:43 -0700997 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800998
Romain Guy13c2e7b2010-03-10 19:45:00 -0800999 AllApps3D mAllApps;
1000 boolean mInitialize;
1001
Daniel Sandler388f6792010-03-02 14:08:08 -05001002 class BaseAlloc {
1003 Allocation mAlloc;
1004 Type mType;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001005
Daniel Sandler388f6792010-03-02 14:08:08 -05001006 void save() {
1007 mAlloc.data(this);
1008 }
1009 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001010
Daniel Sandler388f6792010-03-02 14:08:08 -05001011 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001012 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -08001013 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -05001014 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001015
1016 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001017 if (sRS != null) {
1018 sRS.contextBindRootScript(null);
1019 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001020 }
1021
1022 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001023 if (sRS != null) {
1024 sRS.contextBindRootScript(mScript);
1025 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001026 }
1027
Romain Guy13c2e7b2010-03-10 19:45:00 -08001028 public RolloRS(AllApps3D allApps) {
1029 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -05001030 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001031
Daniel Sandler388f6792010-03-02 14:08:08 -05001032 public void init(Resources res, int width, int height) {
1033 mRes = res;
1034 mWidth = width;
1035 mHeight = height;
Jason Sams1aa4ff02010-06-15 14:59:57 -07001036 mScript = new ScriptC_Allapps(sRS, mRes, R.raw.allapps_bc, true);
Jason Sams14f67ed2010-05-11 14:02:43 -07001037
Daniel Sandler388f6792010-03-02 14:08:08 -05001038 initProgramVertex();
1039 initProgramFragment();
1040 initProgramStore();
1041 initGl();
1042 initData();
Jason Sams14f67ed2010-05-11 14:02:43 -07001043
1044 mScript.bind_gIconIDs(mAllocIconIds);
1045 mScript.bind_gLabelIDs(mAllocLabelIds);
Jason Sams14f67ed2010-05-11 14:02:43 -07001046 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -05001047 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001048
Daniel Sandler388f6792010-03-02 14:08:08 -05001049 public void initMesh() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001050 SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001051
Daniel Sandler388f6792010-03-02 14:08:08 -05001052 for (int ct=0; ct < 16; ct++) {
1053 float pos = (1.f / (16.f - 1)) * ct;
1054 tm.addVertex(0.0f, pos);
1055 tm.addVertex(1.0f, pos);
1056 }
1057 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1058 tm.addTriangle(ct, ct+1, ct+2);
1059 tm.addTriangle(ct+1, ct+3, ct+2);
1060 }
1061 mMesh = tm.create();
Jason Sams14f67ed2010-05-11 14:02:43 -07001062 mScript.set_gSMCell(mMesh);
Daniel Sandler388f6792010-03-02 14:08:08 -05001063 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001064
Daniel Sandler388f6792010-03-02 14:08:08 -05001065 void resize(int w, int h) {
1066 mPVA.setupProjectionNormalized(w, h);
1067 mWidth = w;
1068 mHeight = h;
1069 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001070
Daniel Sandler388f6792010-03-02 14:08:08 -05001071 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001072 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001073 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001074
Joe Onorato2cc62e82010-03-17 20:23:53 -07001075 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001076 pvb.setTextureMatrixEnable(true);
1077 mPV = pvb.create();
Daniel Sandler388f6792010-03-02 14:08:08 -05001078 mPV.bindAllocation(mPVA);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001079
Jason Sams14f67ed2010-05-11 14:02:43 -07001080 mUniformAlloc = new ScriptField_VpConsts(sRS, 1);
1081 mScript.bind_vpConstants(mUniformAlloc);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001082
Daniel Sandler388f6792010-03-02 14:08:08 -05001083 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001084 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Romain Guy060b5c82010-03-04 10:07:38 -08001085 String t = "void main() {\n" +
1086 // Animation
1087 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001088
Romain Guy060b5c82010-03-04 10:07:38 -08001089 " float bendY1 = UNI_BendPos.x;\n" +
1090 " float bendY2 = UNI_BendPos.y;\n" +
1091 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1092 " float bendDistance = bendY1 * 0.4;\n" +
1093 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001094
Romain Guy060b5c82010-03-04 10:07:38 -08001095 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1096 " float aDy = cos(bendAngle);\n" +
1097 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001098
Romain Guy060b5c82010-03-04 10:07:38 -08001099 " float scale = (2.0 / 480.0);\n" +
1100 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1101 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1102 " float y = 0.0;\n" +
1103 " float z = 0.0;\n" +
1104 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001105
Romain Guy060b5c82010-03-04 10:07:38 -08001106 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1107 " y += cv * aDy;\n" +
1108 " z += -cv * aDz;\n" +
1109 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1110 " lum += cv / bendDistance * distanceDimLevel;\n" +
1111 " y += cv * cos(cv * bendStep);\n" +
1112 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001113
Romain Guy060b5c82010-03-04 10:07:38 -08001114 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1115 " y += cv * aDy;\n" +
1116 " z += cv * aDz;\n" +
1117 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1118 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1119 " y += cv * cos(cv * bendStep);\n" +
1120 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001121
Romain Guy060b5c82010-03-04 10:07:38 -08001122 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001123
Romain Guy060b5c82010-03-04 10:07:38 -08001124 " vec4 pos;\n" +
1125 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1126 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1127 " pos.z = z * UNI_ScaleOffset.x;\n" +
1128 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001129
Romain Guy060b5c82010-03-04 10:07:38 -08001130 " pos.x *= 1.0 + ani * 4.0;\n" +
1131 " pos.y *= 1.0 + ani * 4.0;\n" +
1132 " pos.z -= ani * 1.5;\n" +
1133 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001134
Romain Guy060b5c82010-03-04 10:07:38 -08001135 " gl_Position = UNI_MVP * pos;\n" +
1136 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1137 " varTex0.xy = ATTRIB_position;\n" +
1138 " varTex0.y = 1.0 - varTex0.y;\n" +
1139 " varTex0.zw = vec2(0.0, 0.0);\n" +
1140 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001141 sb.setShader(t);
1142 sb.addConstant(mUniformAlloc.getType());
1143 sb.addInput(mMesh.getVertexType(0).getElement());
1144 mPVCurve = sb.create();
Daniel Sandler388f6792010-03-02 14:08:08 -05001145 mPVCurve.bindAllocation(mPVA);
Jason Sams14f67ed2010-05-11 14:02:43 -07001146 mPVCurve.bindConstants(mUniformAlloc.getAllocation(), 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001147
Joe Onorato2cc62e82010-03-17 20:23:53 -07001148 sRS.contextBindProgramVertex(mPV);
Jason Sams14f67ed2010-05-11 14:02:43 -07001149 mScript.set_gPVCurve(mPVCurve);
Daniel Sandler388f6792010-03-02 14:08:08 -05001150 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001151
Daniel Sandler388f6792010-03-02 14:08:08 -05001152 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001153 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001154 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1155 sb.setMag(Sampler.Value.NEAREST);
1156 sb.setWrapS(Sampler.Value.CLAMP);
1157 sb.setWrapT(Sampler.Value.CLAMP);
1158 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001159
Daniel Sandler388f6792010-03-02 14:08:08 -05001160 sb.setMin(Sampler.Value.NEAREST);
1161 sb.setMag(Sampler.Value.NEAREST);
1162 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001163
Joe Onorato2cc62e82010-03-17 20:23:53 -07001164 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001165 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1166 ProgramFragment.Builder.Format.RGBA, 0);
1167 mPFTexMip = bf.create();
Daniel Sandler388f6792010-03-02 14:08:08 -05001168 mPFTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001169
Daniel Sandler388f6792010-03-02 14:08:08 -05001170 mPFTexNearest = bf.create();
Daniel Sandler388f6792010-03-02 14:08:08 -05001171 mPFTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001172
Daniel Sandler388f6792010-03-02 14:08:08 -05001173 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1174 ProgramFragment.Builder.Format.ALPHA, 0);
1175 mPFTexMipAlpha = bf.create();
Daniel Sandler388f6792010-03-02 14:08:08 -05001176 mPFTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001177
Jason Sams14f67ed2010-05-11 14:02:43 -07001178 mScript.set_gPFTexNearest(mPFTexNearest);
1179 mScript.set_gPFTexMip(mPFTexMip);
1180 mScript.set_gPFTexMipAlpha(mPFTexMipAlpha);
Daniel Sandler388f6792010-03-02 14:08:08 -05001181 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001182
Daniel Sandler388f6792010-03-02 14:08:08 -05001183 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001184 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001185 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1186 bs.setColorMask(true,true,true,false);
1187 bs.setDitherEnable(true);
1188 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1189 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Jason Sams14f67ed2010-05-11 14:02:43 -07001190 mScript.set_gPS(bs.create());
Daniel Sandler388f6792010-03-02 14:08:08 -05001191 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001192
Daniel Sandler388f6792010-03-02 14:08:08 -05001193 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001194 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001195
Daniel Sandler388f6792010-03-02 14:08:08 -05001196 private void initData() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001197 mScript.set_COLUMNS_PER_PAGE_PORTRAIT(Defines.COLUMNS_PER_PAGE_PORTRAIT);
1198 mScript.set_ROWS_PER_PAGE_PORTRAIT(Defines.ROWS_PER_PAGE_PORTRAIT);
1199 mScript.set_COLUMNS_PER_PAGE_LANDSCAPE(Defines.COLUMNS_PER_PAGE_LANDSCAPE);
1200 mScript.set_ROWS_PER_PAGE_LANDSCAPE(Defines.ROWS_PER_PAGE_LANDSCAPE);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001201
Joe Onorato2cc62e82010-03-17 20:23:53 -07001202 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1203 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001204 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001205 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1206 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001207 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001208 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1209 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001210 mHomeButtonPressed.uploadToTexture(0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001211
Jason Sams14f67ed2010-05-11 14:02:43 -07001212 mScript.set_gHomeButton(mHomeButtonNormal);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001213
Daniel Sandler388f6792010-03-02 14:08:08 -05001214 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1215 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1216 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001217
Daniel Sandler388f6792010-03-02 14:08:08 -05001218 setApps(null);
1219 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001220
Daniel Sandler388f6792010-03-02 14:08:08 -05001221 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001222 if (sZoomDirty) {
1223 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001224 }
1225 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001226
Romain Guy060b5c82010-03-04 10:07:38 -08001227 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001228 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001229 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001230 final int count = list != null ? list.size() : 0;
1231 int allocCount = count;
1232 if (allocCount < 1) {
1233 allocCount = 1;
1234 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001235
Daniel Sandler388f6792010-03-02 14:08:08 -05001236 mIcons = new Allocation[count];
1237 mIconIds = new int[allocCount];
Jason Sams98994c42010-06-01 15:54:10 -07001238 mAllocIconIds = Allocation.createSized(sRS, Element.I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001239
Daniel Sandler388f6792010-03-02 14:08:08 -05001240 mLabels = new Allocation[count];
1241 mLabelIds = new int[allocCount];
Jason Sams98994c42010-06-01 15:54:10 -07001242 mAllocLabelIds = Allocation.createSized(sRS, Element.I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001243
Jason Sams14f67ed2010-05-11 14:02:43 -07001244 mScript.set_gIconCount(count);
1245 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001246 createAppIconAllocations(i, list.get(i));
1247 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001248 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001249 uploadAppIcon(i, list.get(i));
1250 }
1251 saveAppsList();
Jason Sams14f67ed2010-05-11 14:02:43 -07001252 android.util.Log.e("rs", "setApps");
Joe Onorato2cc62e82010-03-17 20:23:53 -07001253 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001254 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001255
Daniel Sandler388f6792010-03-02 14:08:08 -05001256 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001257 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001258 sRollo.clearSelectedIcon();
1259 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001260 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001261 if (zoom > 0.001f) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001262 sRollo.mScript.set_gZoomTarget(zoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001263 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -07001264 sRollo.mScript.set_gZoomTarget(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001265 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001266 if (!animate) {
Jason Sams1aa4ff02010-06-15 14:59:57 -07001267 sRollo.mScript.invoke_setZoom();
Daniel Sandler388f6792010-03-02 14:08:08 -05001268 }
1269 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001270
Daniel Sandler388f6792010-03-02 14:08:08 -05001271 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001272 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1273 Element.RGBA_8888(sRS), false);
1274 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1275 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001276 mIconIds[index] = mIcons[index].getID();
1277 mLabelIds[index] = mLabels[index].getID();
1278 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001279
Daniel Sandler388f6792010-03-02 14:08:08 -05001280 private void uploadAppIcon(int index, ApplicationInfo item) {
1281 if (mIconIds[index] != mIcons[index].getID()) {
1282 throw new IllegalStateException("uploadAppIcon index=" + index
1283 + " mIcons[index].getID=" + mIcons[index].getID()
1284 + " mIconsIds[index]=" + mIconIds[index]
1285 + " item=" + item);
1286 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001287 mIcons[index].uploadToTexture(true, 0);
1288 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001289 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001290
Daniel Sandler388f6792010-03-02 14:08:08 -05001291 /**
1292 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1293 * fill in the values and call saveAppsList().
1294 */
1295 private void reallocAppsList(int count) {
1296 Allocation[] icons = new Allocation[count];
1297 int[] iconIds = new int[count];
Jason Sams98994c42010-06-01 15:54:10 -07001298 mAllocIconIds = Allocation.createSized(sRS, Element.I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001299
Daniel Sandler388f6792010-03-02 14:08:08 -05001300 Allocation[] labels = new Allocation[count];
1301 int[] labelIds = new int[count];
Jason Sams98994c42010-06-01 15:54:10 -07001302 mAllocLabelIds = Allocation.createSized(sRS, Element.I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001303
Jason Sams14f67ed2010-05-11 14:02:43 -07001304 final int oldCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001305
Daniel Sandler388f6792010-03-02 14:08:08 -05001306 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1307 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1308 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1309 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001310
Daniel Sandler388f6792010-03-02 14:08:08 -05001311 mIcons = icons;
1312 mIconIds = iconIds;
1313 mLabels = labels;
1314 mLabelIds = labelIds;
1315 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001316
Daniel Sandler388f6792010-03-02 14:08:08 -05001317 /**
1318 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1319 */
1320 private void addApp(int index, ApplicationInfo item) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001321 final int count = mScript.get_gIconCount() - index;
Daniel Sandler388f6792010-03-02 14:08:08 -05001322 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001323
Daniel Sandler388f6792010-03-02 14:08:08 -05001324 System.arraycopy(mIcons, index, mIcons, dest, count);
1325 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1326 System.arraycopy(mLabels, index, mLabels, dest, count);
1327 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001328
Daniel Sandler388f6792010-03-02 14:08:08 -05001329 createAppIconAllocations(index, item);
1330 uploadAppIcon(index, item);
Jason Sams14f67ed2010-05-11 14:02:43 -07001331
1332 mScript.set_gIconCount(mScript.get_gIconCount() + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001333 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001334
Daniel Sandler388f6792010-03-02 14:08:08 -05001335 /**
1336 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1337 */
1338 private void removeApp(int index) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001339 final int count = mScript.get_gIconCount() - index - 1;
Daniel Sandler388f6792010-03-02 14:08:08 -05001340 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001341
Daniel Sandler388f6792010-03-02 14:08:08 -05001342 System.arraycopy(mIcons, src, mIcons, index, count);
1343 System.arraycopy(mIconIds, src, mIconIds, index, count);
1344 System.arraycopy(mLabels, src, mLabels, index, count);
1345 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001346
Jason Sams14f67ed2010-05-11 14:02:43 -07001347 mScript.set_gIconCount(mScript.get_gIconCount() - 1);
1348 final int last = mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001349
Daniel Sandler388f6792010-03-02 14:08:08 -05001350 mIcons[last] = null;
1351 mIconIds[last] = 0;
1352 mLabels[last] = null;
1353 mLabelIds[last] = 0;
1354 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001355
Daniel Sandler388f6792010-03-02 14:08:08 -05001356 /**
1357 * Send the apps list structures to RS.
1358 */
1359 private void saveAppsList() {
1360 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1361 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001362 mAllocIconIds.data(mIconIds);
1363 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001364
Jason Sams14f67ed2010-05-11 14:02:43 -07001365 mScript.bind_gIconIDs(mAllocIconIds);
1366 mScript.bind_gLabelIDs(mAllocLabelIds);
Daniel Sandler388f6792010-03-02 14:08:08 -05001367 }
1368 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001369
Daniel Sandler388f6792010-03-02 14:08:08 -05001370 void fling() {
Jason Sams1aa4ff02010-06-15 14:59:57 -07001371 mScript.invoke_fling();
Daniel Sandler388f6792010-03-02 14:08:08 -05001372 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001373
Daniel Sandler388f6792010-03-02 14:08:08 -05001374 void move() {
Jason Sams1aa4ff02010-06-15 14:59:57 -07001375 mScript.invoke_move();
Daniel Sandler388f6792010-03-02 14:08:08 -05001376 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001377
Daniel Sandler388f6792010-03-02 14:08:08 -05001378 void moveTo(float row) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001379 mScript.set_gTargetPos(row);
Jason Sams1aa4ff02010-06-15 14:59:57 -07001380 mScript.invoke_moveTo();
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 * You need to call save() on mState on your own after calling this.
1385 *
1386 * @return the index of the icon that was selected.
1387 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001388 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001389 if (mAllApps != null) {
1390 final int index = mAllApps.chooseTappedIcon(x, y);
1391 selectIcon(index, pressed);
1392 return index;
1393 } else {
1394 return -1;
1395 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001396 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001397
Daniel Sandler388f6792010-03-02 14:08:08 -05001398 /**
1399 * Select the icon at the given index.
1400 *
1401 * @param index The index.
1402 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1403 */
1404 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001405 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1406 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001407 if (mAllApps != null) {
1408 mAllApps.mRestoreFocusIndex = index;
1409 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001410 mScript.set_gSelectedIconIndex(-1);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001411 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1412 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001413 }
1414 } else {
1415 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001416 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001417 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001418
Jason Sams14f67ed2010-05-11 14:02:43 -07001419 int prev = mScript.get_gSelectedIconIndex();
1420 mScript.set_gSelectedIconIndex(index);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001421
Romain Guy13c2e7b2010-03-10 19:45:00 -08001422 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001423 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001424
Daniel Sandler388f6792010-03-02 14:08:08 -05001425 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1426 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1427 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001428
Joe Onorato2cc62e82010-03-17 20:23:53 -07001429 mSelectedIcon = Allocation.createFromBitmap(sRS, selectionBitmap,
1430 Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001431 mSelectedIcon.uploadToTexture(0);
Jason Sams14f67ed2010-05-11 14:02:43 -07001432 mScript.set_gSelectedIconTexture(mSelectedIcon);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001433
Daniel Sandler388f6792010-03-02 14:08:08 -05001434 if (prev != index) {
1435 if (info.title != null && info.title.length() > 0) {
1436 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001437 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001438 }
1439 }
1440 }
1441 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001442
Daniel Sandler388f6792010-03-02 14:08:08 -05001443 /**
1444 * You need to call save() on mState on your own after calling this.
1445 */
1446 void clearSelectedIcon() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001447 mScript.set_gSelectedIconIndex(-1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001448 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001449
Daniel Sandler388f6792010-03-02 14:08:08 -05001450 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001451 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001452 switch (mode) {
1453 case SELECTED_NONE:
Jason Sams14f67ed2010-05-11 14:02:43 -07001454 mScript.set_gHomeButton(mHomeButtonNormal);
Daniel Sandler388f6792010-03-02 14:08:08 -05001455 break;
1456 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001457 mAllApps.mLastSelection = SELECTION_HOME;
Jason Sams14f67ed2010-05-11 14:02:43 -07001458 mScript.set_gHomeButton(mHomeButtonFocused);
Daniel Sandler388f6792010-03-02 14:08:08 -05001459 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001460 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001461 }
1462 break;
1463 case SELECTED_PRESSED:
Jason Sams14f67ed2010-05-11 14:02:43 -07001464 mScript.set_gHomeButton(mHomeButtonPressed);
Daniel Sandler388f6792010-03-02 14:08:08 -05001465 break;
1466 }
1467 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001468
Daniel Sandler388f6792010-03-02 14:08:08 -05001469 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001470 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1471 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1472 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001473 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001474 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001475 }
1476 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001477 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001478 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001479 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001480 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001481 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001482 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001483 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Jason Sams14f67ed2010-05-11 14:02:43 -07001484 //Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1485 //Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1486 //Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1487 //Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1488 //Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1489 //Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1490 //Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1491 //Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1492 //Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001493 }
1494 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001495
Daniel Sandler388f6792010-03-02 14:08:08 -05001496 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001497 Log.d(TAG, "sRS=" + sRS);
1498 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001499 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001500 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1501 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001502 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1503 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1504 Log.d(TAG, "mLastSelection=" + mLastSelection);
1505 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1506 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1507 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1508 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001509 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1510 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001511 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001512 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001513 Log.d(TAG, "mVelocity=" + mVelocity);
1514 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001515 if (sRollo != null) {
1516 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001517 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001518 if (sRS != null) {
1519 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001520 }
1521 }
1522}
1523
1524