blob: 8644a43e60e2f3a013b383a153241bb84e745dd2 [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);
1022 mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1023
1024
Daniel Sandler388f6792010-03-02 14:08:08 -05001025 initProgramVertex();
1026 initProgramFragment();
1027 initProgramStore();
1028 initGl();
1029 initData();
Jason Sams14f67ed2010-05-11 14:02:43 -07001030
1031 mScript.bind_gIconIDs(mAllocIconIds);
1032 mScript.bind_gLabelIDs(mAllocLabelIds);
1033
1034 //mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
1035 //mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
1036
1037 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -05001038 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001039
Daniel Sandler388f6792010-03-02 14:08:08 -05001040 public void initMesh() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001041 SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001042
Daniel Sandler388f6792010-03-02 14:08:08 -05001043 for (int ct=0; ct < 16; ct++) {
1044 float pos = (1.f / (16.f - 1)) * ct;
1045 tm.addVertex(0.0f, pos);
1046 tm.addVertex(1.0f, pos);
1047 }
1048 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1049 tm.addTriangle(ct, ct+1, ct+2);
1050 tm.addTriangle(ct+1, ct+3, ct+2);
1051 }
1052 mMesh = tm.create();
Jason Sams14f67ed2010-05-11 14:02:43 -07001053 mScript.set_gSMCell(mMesh);
Daniel Sandler388f6792010-03-02 14:08:08 -05001054 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001055
Daniel Sandler388f6792010-03-02 14:08:08 -05001056 void resize(int w, int h) {
1057 mPVA.setupProjectionNormalized(w, h);
1058 mWidth = w;
1059 mHeight = h;
1060 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001061
Daniel Sandler388f6792010-03-02 14:08:08 -05001062 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001063 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001064 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001065
Joe Onorato2cc62e82010-03-17 20:23:53 -07001066 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001067 pvb.setTextureMatrixEnable(true);
1068 mPV = pvb.create();
Daniel Sandler388f6792010-03-02 14:08:08 -05001069 mPV.bindAllocation(mPVA);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001070
Jason Sams14f67ed2010-05-11 14:02:43 -07001071 mUniformAlloc = new ScriptField_VpConsts(sRS, 1);
1072 mScript.bind_vpConstants(mUniformAlloc);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001073
Daniel Sandler388f6792010-03-02 14:08:08 -05001074 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001075 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Romain Guy060b5c82010-03-04 10:07:38 -08001076 String t = "void main() {\n" +
1077 // Animation
1078 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001079
Romain Guy060b5c82010-03-04 10:07:38 -08001080 " float bendY1 = UNI_BendPos.x;\n" +
1081 " float bendY2 = UNI_BendPos.y;\n" +
1082 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1083 " float bendDistance = bendY1 * 0.4;\n" +
1084 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001085
Romain Guy060b5c82010-03-04 10:07:38 -08001086 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1087 " float aDy = cos(bendAngle);\n" +
1088 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001089
Romain Guy060b5c82010-03-04 10:07:38 -08001090 " float scale = (2.0 / 480.0);\n" +
1091 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1092 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1093 " float y = 0.0;\n" +
1094 " float z = 0.0;\n" +
1095 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001096
Romain Guy060b5c82010-03-04 10:07:38 -08001097 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1098 " y += cv * aDy;\n" +
1099 " z += -cv * aDz;\n" +
1100 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1101 " lum += cv / bendDistance * distanceDimLevel;\n" +
1102 " y += cv * cos(cv * bendStep);\n" +
1103 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001104
Romain Guy060b5c82010-03-04 10:07:38 -08001105 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1106 " y += cv * aDy;\n" +
1107 " z += cv * aDz;\n" +
1108 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1109 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1110 " y += cv * cos(cv * bendStep);\n" +
1111 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001112
Romain Guy060b5c82010-03-04 10:07:38 -08001113 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001114
Romain Guy060b5c82010-03-04 10:07:38 -08001115 " vec4 pos;\n" +
1116 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1117 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1118 " pos.z = z * UNI_ScaleOffset.x;\n" +
1119 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001120
Romain Guy060b5c82010-03-04 10:07:38 -08001121 " pos.x *= 1.0 + ani * 4.0;\n" +
1122 " pos.y *= 1.0 + ani * 4.0;\n" +
1123 " pos.z -= ani * 1.5;\n" +
1124 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001125
Romain Guy060b5c82010-03-04 10:07:38 -08001126 " gl_Position = UNI_MVP * pos;\n" +
1127 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1128 " varTex0.xy = ATTRIB_position;\n" +
1129 " varTex0.y = 1.0 - varTex0.y;\n" +
1130 " varTex0.zw = vec2(0.0, 0.0);\n" +
1131 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001132 sb.setShader(t);
1133 sb.addConstant(mUniformAlloc.getType());
1134 sb.addInput(mMesh.getVertexType(0).getElement());
1135 mPVCurve = sb.create();
Daniel Sandler388f6792010-03-02 14:08:08 -05001136 mPVCurve.bindAllocation(mPVA);
Jason Sams14f67ed2010-05-11 14:02:43 -07001137 mPVCurve.bindConstants(mUniformAlloc.getAllocation(), 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001138
Joe Onorato2cc62e82010-03-17 20:23:53 -07001139 sRS.contextBindProgramVertex(mPV);
Jason Sams14f67ed2010-05-11 14:02:43 -07001140 mScript.set_gPVCurve(mPVCurve);
Daniel Sandler388f6792010-03-02 14:08:08 -05001141 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001142
Daniel Sandler388f6792010-03-02 14:08:08 -05001143 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001144 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001145 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1146 sb.setMag(Sampler.Value.NEAREST);
1147 sb.setWrapS(Sampler.Value.CLAMP);
1148 sb.setWrapT(Sampler.Value.CLAMP);
1149 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001150
Daniel Sandler388f6792010-03-02 14:08:08 -05001151 sb.setMin(Sampler.Value.NEAREST);
1152 sb.setMag(Sampler.Value.NEAREST);
1153 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001154
Joe Onorato2cc62e82010-03-17 20:23:53 -07001155 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001156 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1157 ProgramFragment.Builder.Format.RGBA, 0);
1158 mPFTexMip = bf.create();
Daniel Sandler388f6792010-03-02 14:08:08 -05001159 mPFTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001160
Daniel Sandler388f6792010-03-02 14:08:08 -05001161 mPFTexNearest = bf.create();
Daniel Sandler388f6792010-03-02 14:08:08 -05001162 mPFTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001163
Daniel Sandler388f6792010-03-02 14:08:08 -05001164 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1165 ProgramFragment.Builder.Format.ALPHA, 0);
1166 mPFTexMipAlpha = bf.create();
Daniel Sandler388f6792010-03-02 14:08:08 -05001167 mPFTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001168
Jason Sams14f67ed2010-05-11 14:02:43 -07001169 mScript.set_gPFTexNearest(mPFTexNearest);
1170 mScript.set_gPFTexMip(mPFTexMip);
1171 mScript.set_gPFTexMipAlpha(mPFTexMipAlpha);
Daniel Sandler388f6792010-03-02 14:08:08 -05001172 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001173
Daniel Sandler388f6792010-03-02 14:08:08 -05001174 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001175 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001176 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1177 bs.setColorMask(true,true,true,false);
1178 bs.setDitherEnable(true);
1179 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1180 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Jason Sams14f67ed2010-05-11 14:02:43 -07001181 mScript.set_gPS(bs.create());
Daniel Sandler388f6792010-03-02 14:08:08 -05001182 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001183
Daniel Sandler388f6792010-03-02 14:08:08 -05001184 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001185 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001186
Daniel Sandler388f6792010-03-02 14:08:08 -05001187 private void initData() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001188 mScript.set_COLUMNS_PER_PAGE_PORTRAIT(Defines.COLUMNS_PER_PAGE_PORTRAIT);
1189 mScript.set_ROWS_PER_PAGE_PORTRAIT(Defines.ROWS_PER_PAGE_PORTRAIT);
1190 mScript.set_COLUMNS_PER_PAGE_LANDSCAPE(Defines.COLUMNS_PER_PAGE_LANDSCAPE);
1191 mScript.set_ROWS_PER_PAGE_LANDSCAPE(Defines.ROWS_PER_PAGE_LANDSCAPE);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001192
Jason Sams14f67ed2010-05-11 14:02:43 -07001193 //mScript.set_gNewPositionX(float v) {
1194 //mScript.set_gNewTouchDown(int v) {
1195 //mScript.set_gFlingVelocity(float v) {
1196 //mScript.set_gIconCount(int v) {
1197 //mScript.set_gSelectedIconIndex(int v) {
1198 //mScript.set_gSelectedIconTexture(int v) {
1199 //mScript.set_gZoomTarget(float v) {
1200 //mScript.set_gTargetPos(float v) {
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001201
Jason Sams14f67ed2010-05-11 14:02:43 -07001202
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001203
Joe Onorato2cc62e82010-03-17 20:23:53 -07001204 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1205 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001206 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001207 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1208 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001209 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001210 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1211 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001212 mHomeButtonPressed.uploadToTexture(0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001213
Jason Sams14f67ed2010-05-11 14:02:43 -07001214 mScript.set_gHomeButton(mHomeButtonNormal);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001215
Daniel Sandler388f6792010-03-02 14:08:08 -05001216 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1217 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1218 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001219
Daniel Sandler388f6792010-03-02 14:08:08 -05001220 setApps(null);
1221 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001222
Daniel Sandler388f6792010-03-02 14:08:08 -05001223 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001224 if (sZoomDirty) {
1225 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001226 }
1227 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001228
Romain Guy060b5c82010-03-04 10:07:38 -08001229 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001230 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001231 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001232 final int count = list != null ? list.size() : 0;
1233 int allocCount = count;
1234 if (allocCount < 1) {
1235 allocCount = 1;
1236 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001237
Daniel Sandler388f6792010-03-02 14:08:08 -05001238 mIcons = new Allocation[count];
1239 mIconIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001240 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001241
Daniel Sandler388f6792010-03-02 14:08:08 -05001242 mLabels = new Allocation[count];
1243 mLabelIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001244 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001245
Jason Sams14f67ed2010-05-11 14:02:43 -07001246 mScript.set_gIconCount(count);
1247 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001248 createAppIconAllocations(i, list.get(i));
1249 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001250 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001251 uploadAppIcon(i, list.get(i));
1252 }
1253 saveAppsList();
Jason Sams14f67ed2010-05-11 14:02:43 -07001254 android.util.Log.e("rs", "setApps");
Joe Onorato2cc62e82010-03-17 20:23:53 -07001255 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001256 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001257
Daniel Sandler388f6792010-03-02 14:08:08 -05001258 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001259 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001260 sRollo.clearSelectedIcon();
1261 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001262 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001263 if (zoom > 0.001f) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001264 sRollo.mScript.set_gZoomTarget(zoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001265 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -07001266 sRollo.mScript.set_gZoomTarget(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001267 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001268 if (!animate) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001269 sRollo.mScript.invokable_SetZoom();
Daniel Sandler388f6792010-03-02 14:08:08 -05001270 }
1271 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001272
Daniel Sandler388f6792010-03-02 14:08:08 -05001273 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001274 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1275 Element.RGBA_8888(sRS), false);
1276 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1277 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001278 mIconIds[index] = mIcons[index].getID();
1279 mLabelIds[index] = mLabels[index].getID();
1280 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001281
Daniel Sandler388f6792010-03-02 14:08:08 -05001282 private void uploadAppIcon(int index, ApplicationInfo item) {
1283 if (mIconIds[index] != mIcons[index].getID()) {
1284 throw new IllegalStateException("uploadAppIcon index=" + index
1285 + " mIcons[index].getID=" + mIcons[index].getID()
1286 + " mIconsIds[index]=" + mIconIds[index]
1287 + " item=" + item);
1288 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001289 mIcons[index].uploadToTexture(true, 0);
1290 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001291 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001292
Daniel Sandler388f6792010-03-02 14:08:08 -05001293 /**
1294 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1295 * fill in the values and call saveAppsList().
1296 */
1297 private void reallocAppsList(int count) {
1298 Allocation[] icons = new Allocation[count];
1299 int[] iconIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001300 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001301
Daniel Sandler388f6792010-03-02 14:08:08 -05001302 Allocation[] labels = new Allocation[count];
1303 int[] labelIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001304 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001305
Jason Sams14f67ed2010-05-11 14:02:43 -07001306 final int oldCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001307
Daniel Sandler388f6792010-03-02 14:08:08 -05001308 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1309 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1310 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1311 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001312
Daniel Sandler388f6792010-03-02 14:08:08 -05001313 mIcons = icons;
1314 mIconIds = iconIds;
1315 mLabels = labels;
1316 mLabelIds = labelIds;
1317 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001318
Daniel Sandler388f6792010-03-02 14:08:08 -05001319 /**
1320 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1321 */
1322 private void addApp(int index, ApplicationInfo item) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001323 final int count = mScript.get_gIconCount() - index;
Daniel Sandler388f6792010-03-02 14:08:08 -05001324 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001325
Daniel Sandler388f6792010-03-02 14:08:08 -05001326 System.arraycopy(mIcons, index, mIcons, dest, count);
1327 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1328 System.arraycopy(mLabels, index, mLabels, dest, count);
1329 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001330
Daniel Sandler388f6792010-03-02 14:08:08 -05001331 createAppIconAllocations(index, item);
1332 uploadAppIcon(index, item);
Jason Sams14f67ed2010-05-11 14:02:43 -07001333
1334 mScript.set_gIconCount(mScript.get_gIconCount() + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001335 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001336
Daniel Sandler388f6792010-03-02 14:08:08 -05001337 /**
1338 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1339 */
1340 private void removeApp(int index) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001341 final int count = mScript.get_gIconCount() - index - 1;
Daniel Sandler388f6792010-03-02 14:08:08 -05001342 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001343
Daniel Sandler388f6792010-03-02 14:08:08 -05001344 System.arraycopy(mIcons, src, mIcons, index, count);
1345 System.arraycopy(mIconIds, src, mIconIds, index, count);
1346 System.arraycopy(mLabels, src, mLabels, index, count);
1347 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001348
Jason Sams14f67ed2010-05-11 14:02:43 -07001349 mScript.set_gIconCount(mScript.get_gIconCount() - 1);
1350 final int last = mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001351
Daniel Sandler388f6792010-03-02 14:08:08 -05001352 mIcons[last] = null;
1353 mIconIds[last] = 0;
1354 mLabels[last] = null;
1355 mLabelIds[last] = 0;
1356 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001357
Daniel Sandler388f6792010-03-02 14:08:08 -05001358 /**
1359 * Send the apps list structures to RS.
1360 */
1361 private void saveAppsList() {
1362 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1363 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001364 mAllocIconIds.data(mIconIds);
1365 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001366
Jason Sams14f67ed2010-05-11 14:02:43 -07001367 mScript.bind_gIconIDs(mAllocIconIds);
1368 mScript.bind_gLabelIDs(mAllocLabelIds);
1369 mScript.invokable_ResetWAR();
Daniel Sandler388f6792010-03-02 14:08:08 -05001370 }
1371 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001372
Daniel Sandler388f6792010-03-02 14:08:08 -05001373 void fling() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001374 mScript.invokable_Fling();
Daniel Sandler388f6792010-03-02 14:08:08 -05001375 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001376
Daniel Sandler388f6792010-03-02 14:08:08 -05001377 void move() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001378 mScript.invokable_Move();
Daniel Sandler388f6792010-03-02 14:08:08 -05001379 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001380
Daniel Sandler388f6792010-03-02 14:08:08 -05001381 void moveTo(float row) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001382 mScript.set_gTargetPos(row);
1383 mScript.invokable_MoveTo();
Daniel Sandler388f6792010-03-02 14:08:08 -05001384 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001385
Daniel Sandler388f6792010-03-02 14:08:08 -05001386 /**
1387 * You need to call save() on mState on your own after calling this.
1388 *
1389 * @return the index of the icon that was selected.
1390 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001391 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001392 if (mAllApps != null) {
1393 final int index = mAllApps.chooseTappedIcon(x, y);
1394 selectIcon(index, pressed);
1395 return index;
1396 } else {
1397 return -1;
1398 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001399 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001400
Daniel Sandler388f6792010-03-02 14:08:08 -05001401 /**
1402 * Select the icon at the given index.
1403 *
1404 * @param index The index.
1405 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1406 */
1407 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001408 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1409 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001410 if (mAllApps != null) {
1411 mAllApps.mRestoreFocusIndex = index;
1412 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001413 mScript.set_gSelectedIconIndex(-1);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001414 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1415 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001416 }
1417 } else {
1418 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001419 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001420 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001421
Jason Sams14f67ed2010-05-11 14:02:43 -07001422 int prev = mScript.get_gSelectedIconIndex();
1423 mScript.set_gSelectedIconIndex(index);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001424
Romain Guy13c2e7b2010-03-10 19:45:00 -08001425 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001426 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001427
Daniel Sandler388f6792010-03-02 14:08:08 -05001428 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1429 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1430 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001431
Joe Onorato2cc62e82010-03-17 20:23:53 -07001432 mSelectedIcon = Allocation.createFromBitmap(sRS, selectionBitmap,
1433 Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001434 mSelectedIcon.uploadToTexture(0);
Jason Sams14f67ed2010-05-11 14:02:43 -07001435 mScript.set_gSelectedIconTexture(mSelectedIcon);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001436
Daniel Sandler388f6792010-03-02 14:08:08 -05001437 if (prev != index) {
1438 if (info.title != null && info.title.length() > 0) {
1439 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001440 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001441 }
1442 }
1443 }
1444 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001445
Daniel Sandler388f6792010-03-02 14:08:08 -05001446 /**
1447 * You need to call save() on mState on your own after calling this.
1448 */
1449 void clearSelectedIcon() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001450 mScript.set_gSelectedIconIndex(-1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001451 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001452
Daniel Sandler388f6792010-03-02 14:08:08 -05001453 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001454 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001455 switch (mode) {
1456 case SELECTED_NONE:
Jason Sams14f67ed2010-05-11 14:02:43 -07001457 mScript.set_gHomeButton(mHomeButtonNormal);
Daniel Sandler388f6792010-03-02 14:08:08 -05001458 break;
1459 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001460 mAllApps.mLastSelection = SELECTION_HOME;
Jason Sams14f67ed2010-05-11 14:02:43 -07001461 mScript.set_gHomeButton(mHomeButtonFocused);
Daniel Sandler388f6792010-03-02 14:08:08 -05001462 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001463 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001464 }
1465 break;
1466 case SELECTED_PRESSED:
Jason Sams14f67ed2010-05-11 14:02:43 -07001467 mScript.set_gHomeButton(mHomeButtonPressed);
Daniel Sandler388f6792010-03-02 14:08:08 -05001468 break;
1469 }
1470 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001471
Daniel Sandler388f6792010-03-02 14:08:08 -05001472 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001473 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1474 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1475 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001476 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001477 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001478 }
1479 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001480 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001481 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001482 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001483 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001484 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001485 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001486 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Jason Sams14f67ed2010-05-11 14:02:43 -07001487 //Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1488 //Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1489 //Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1490 //Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1491 //Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1492 //Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1493 //Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1494 //Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1495 //Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001496 }
1497 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001498
Daniel Sandler388f6792010-03-02 14:08:08 -05001499 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001500 Log.d(TAG, "sRS=" + sRS);
1501 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001502 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001503 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1504 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001505 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1506 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1507 Log.d(TAG, "mLastSelection=" + mLastSelection);
1508 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1509 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1510 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1511 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001512 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1513 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001514 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001515 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001516 Log.d(TAG, "mVelocity=" + mVelocity);
1517 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001518 if (sRollo != null) {
1519 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001520 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001521 if (sRS != null) {
1522 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001523 }
1524 }
1525}
1526
1527