blob: d06624d2507cfb233935ff8b6c22ebad848f9c44 [file] [log] [blame]
Daniel Sandler388f6792010-03-02 14:08:08 -05001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher2;
18
Winson Chungaafa03c2010-06-11 17:34:16 -070019import java.util.ArrayList;
20import java.util.Arrays;
21import java.util.Collections;
22
Daniel Sandler388f6792010-03-02 14:08:08 -050023import android.content.ComponentName;
24import android.content.Context;
25import android.content.res.Resources;
26import android.graphics.Bitmap;
27import android.graphics.Canvas;
28import android.graphics.PixelFormat;
29import android.graphics.Rect;
Daniel Sandler388f6792010-03-02 14:08:08 -050030import android.renderscript.Allocation;
Daniel Sandler388f6792010-03-02 14:08:08 -050031import android.renderscript.Element;
32import android.renderscript.ProgramFragment;
33import android.renderscript.ProgramStore;
34import android.renderscript.ProgramVertex;
35import android.renderscript.RSSurfaceView;
Daniel Sandler388f6792010-03-02 14:08:08 -050036import android.renderscript.RenderScript;
Winson Chungaafa03c2010-06-11 17:34:16 -070037import android.renderscript.RenderScriptGL;
Daniel Sandler388f6792010-03-02 14:08:08 -050038import android.renderscript.Sampler;
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -070039import android.renderscript.Mesh;
Daniel Sandler388f6792010-03-02 14:08:08 -050040import android.renderscript.Type;
41import android.util.AttributeSet;
Romain Guy060b5c82010-03-04 10:07:38 -080042import android.util.DisplayMetrics;
Daniel Sandler388f6792010-03-02 14:08:08 -050043import android.util.Log;
44import android.view.KeyEvent;
45import android.view.MotionEvent;
46import android.view.SoundEffectConstants;
47import android.view.SurfaceHolder;
48import android.view.VelocityTracker;
49import android.view.View;
50import android.view.ViewConfiguration;
51import android.view.accessibility.AccessibilityEvent;
52
Romain Guyedcce092010-03-04 13:03:17 -080053import com.android.launcher.R;
54
Daniel Sandler388f6792010-03-02 14:08:08 -050055public class AllApps3D extends RSSurfaceView
56 implements AllAppsView, View.OnClickListener, View.OnLongClickListener, DragSource {
57 private static final String TAG = "Launcher.AllApps3D";
58
59 /** Bit for mLocks for when there are icons being loaded. */
60 private static final int LOCK_ICONS_PENDING = 1;
61
62 private static final int TRACKING_NONE = 0;
63 private static final int TRACKING_FLING = 1;
64 private static final int TRACKING_HOME = 2;
65
66 private static final int SELECTED_NONE = 0;
67 private static final int SELECTED_FOCUSED = 1;
68 private static final int SELECTED_PRESSED = 2;
69
70 private static final int SELECTION_NONE = 0;
71 private static final int SELECTION_ICONS = 1;
72 private static final int SELECTION_HOME = 2;
73
74 private Launcher mLauncher;
75 private DragController mDragController;
76
77 /** When this is 0, modifications are allowed, when it's not, they're not.
78 * TODO: What about scrolling? */
79 private int mLocks = LOCK_ICONS_PENDING;
80
81 private int mSlop;
82 private int mMaxFlingVelocity;
83
84 private Defines mDefines = new Defines();
Daniel Sandler388f6792010-03-02 14:08:08 -050085 private ArrayList<ApplicationInfo> mAllAppsList;
86
Joe Onorato2cc62e82010-03-17 20:23:53 -070087 private static RenderScriptGL sRS;
88 private static RolloRS sRollo;
Jason Samsdd8cd8b2010-03-11 12:38:48 -080089
Joe Onoratoeffc4a82010-04-15 11:48:13 -070090 private static boolean sZoomDirty = false;
91 private static boolean sAnimateNextZoom;
92 private static float sNextZoom;
93
Daniel Sandler388f6792010-03-02 14:08:08 -050094 /**
95 * True when we are using arrow keys or trackball to drive navigation
96 */
97 private boolean mArrowNavigation = false;
98 private boolean mStartedScrolling;
99
100 /**
101 * Used to keep track of the selection when AllAppsView loses window focus.
102 * One of the SELECTION_ constants.
103 */
104 private int mLastSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800105
Daniel Sandler388f6792010-03-02 14:08:08 -0500106 /**
107 * Used to keep track of the selection when AllAppsView loses window focus
108 */
109 private int mLastSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800110
Daniel Sandler388f6792010-03-02 14:08:08 -0500111 private VelocityTracker mVelocityTracker;
112 private int mTouchTracking;
113 private int mMotionDownRawX;
114 private int mMotionDownRawY;
115 private int mDownIconIndex = -1;
116 private int mCurrentIconIndex = -1;
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700117 private int[] mTouchYBorders;
118 private int[] mTouchXBorders;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800119
Daniel Sandler388f6792010-03-02 14:08:08 -0500120 private boolean mShouldGainFocus;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800121
Daniel Sandler388f6792010-03-02 14:08:08 -0500122 private boolean mHaveSurface = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500123 private float mZoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500124 private float mVelocity;
125 private AAMessage mMessageProc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800126
Romain Guy060b5c82010-03-04 10:07:38 -0800127 private int mColumnsPerPage;
128 private int mRowsPerPage;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800129 private boolean mSurrendered;
130
Romain Guyc16fea72010-03-12 17:17:56 -0800131 private int mRestoreFocusIndex = -1;
Jason Sams14f67ed2010-05-11 14:02:43 -0700132
Romain Guy060b5c82010-03-04 10:07:38 -0800133 @SuppressWarnings({"UnusedDeclaration"})
Daniel Sandler388f6792010-03-02 14:08:08 -0500134 static class Defines {
Romain Guy060b5c82010-03-04 10:07:38 -0800135 public static final int COLUMNS_PER_PAGE_PORTRAIT = 4;
136 public static final int ROWS_PER_PAGE_PORTRAIT = 4;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800137
Romain Guy060b5c82010-03-04 10:07:38 -0800138 public static final int COLUMNS_PER_PAGE_LANDSCAPE = 6;
139 public static final int ROWS_PER_PAGE_LANDSCAPE = 3;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800140
Daniel Sandler388f6792010-03-02 14:08:08 -0500141 public static final int SELECTION_TEXTURE_WIDTH_PX = 74 + 20;
Daniel Sandler388f6792010-03-02 14:08:08 -0500142 public static final int SELECTION_TEXTURE_HEIGHT_PX = 74 + 20;
143 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800144
Daniel Sandler388f6792010-03-02 14:08:08 -0500145 public AllApps3D(Context context, AttributeSet attrs) {
146 super(context, attrs);
147 setFocusable(true);
148 setSoundEffectsEnabled(false);
Daniel Sandler388f6792010-03-02 14:08:08 -0500149 final ViewConfiguration config = ViewConfiguration.get(context);
150 mSlop = config.getScaledTouchSlop();
151 mMaxFlingVelocity = config.getScaledMaximumFlingVelocity();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800152
Daniel Sandler388f6792010-03-02 14:08:08 -0500153 setOnClickListener(this);
154 setOnLongClickListener(this);
155 setZOrderOnTop(true);
156 getHolder().setFormat(PixelFormat.TRANSLUCENT);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800157
Joe Onorato2cc62e82010-03-17 20:23:53 -0700158 if (sRS == null) {
159 sRS = createRenderScript(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800160 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700161 createRenderScript(sRS);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800162 }
163
Romain Guy060b5c82010-03-04 10:07:38 -0800164 final DisplayMetrics metrics = getResources().getDisplayMetrics();
165 final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
166 mColumnsPerPage = isPortrait ? Defines.COLUMNS_PER_PAGE_PORTRAIT :
167 Defines.COLUMNS_PER_PAGE_LANDSCAPE;
168 mRowsPerPage = isPortrait ? Defines.ROWS_PER_PAGE_PORTRAIT :
169 Defines.ROWS_PER_PAGE_LANDSCAPE;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800170
Joe Onorato2cc62e82010-03-17 20:23:53 -0700171 if (sRollo != null) {
172 sRollo.mAllApps = this;
173 sRollo.mRes = getResources();
174 sRollo.mInitialize = true;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800175 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500176 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800177
Romain Guy060b5c82010-03-04 10:07:38 -0800178 @SuppressWarnings({"UnusedDeclaration"})
179 public AllApps3D(Context context, AttributeSet attrs, int defStyle) {
180 this(context, attrs);
181 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800182
Romain Guy13c2e7b2010-03-10 19:45:00 -0800183 public void surrender() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400184 if (sRS != null) {
185 sRS.contextSetSurface(0, 0, null);
186 sRS.mMessageCallback = null;
187 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800188 mSurrendered = true;
189 }
190
Daniel Sandler388f6792010-03-02 14:08:08 -0500191 /**
192 * Note that this implementation prohibits this view from ever being reattached.
193 */
194 @Override
195 protected void onDetachedFromWindow() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700196 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800197 if (!mSurrendered) {
Joe Onorato96da4012010-03-17 20:03:24 -0700198 Log.i(TAG, "onDetachedFromWindow");
Romain Guy13c2e7b2010-03-10 19:45:00 -0800199 destroyRenderScript();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700200 sRS = null;
201 sRollo = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800202 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500203 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800204
Daniel Sandler388f6792010-03-02 14:08:08 -0500205 /**
206 * If you have an attached click listener, View always plays the click sound!?!?
207 * Deal with sound effects by hand.
208 */
209 public void reallyPlaySoundEffect(int sound) {
210 boolean old = isSoundEffectsEnabled();
211 setSoundEffectsEnabled(true);
212 playSoundEffect(sound);
213 setSoundEffectsEnabled(old);
214 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800215
Daniel Sandler388f6792010-03-02 14:08:08 -0500216 public void setLauncher(Launcher launcher) {
217 mLauncher = launcher;
218 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800219
Daniel Sandler388f6792010-03-02 14:08:08 -0500220 @Override
221 public void surfaceDestroyed(SurfaceHolder holder) {
222 super.surfaceDestroyed(holder);
223 // Without this, we leak mMessageCallback which leaks the context.
Romain Guy13c2e7b2010-03-10 19:45:00 -0800224 if (!mSurrendered) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700225 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800226 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500227 // We may lose any callbacks that are pending, so make sure that we re-sync that
228 // on the next surfaceChanged.
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700229 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500230 mHaveSurface = false;
231 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800232
Daniel Sandler388f6792010-03-02 14:08:08 -0500233 @Override
234 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
235 //long startTime = SystemClock.uptimeMillis();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800236
Daniel Sandler388f6792010-03-02 14:08:08 -0500237 super.surfaceChanged(holder, format, w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800238
Romain Guy13c2e7b2010-03-10 19:45:00 -0800239 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800240
Daniel Sandler388f6792010-03-02 14:08:08 -0500241 mHaveSurface = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800242
Joe Onorato2cc62e82010-03-17 20:23:53 -0700243 if (sRollo == null) {
244 sRollo = new RolloRS(this);
245 sRollo.init(getResources(), w, h);
Daniel Sandler388f6792010-03-02 14:08:08 -0500246 if (mAllAppsList != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700247 sRollo.setApps(mAllAppsList);
Daniel Sandler388f6792010-03-02 14:08:08 -0500248 }
249 if (mShouldGainFocus) {
250 gainFocus();
251 mShouldGainFocus = false;
252 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700253 } else if (sRollo.mInitialize) {
254 sRollo.initGl();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700255 sRollo.mInitialize = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500256 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800257
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700258 initTouchState(w, h);
259
Joe Onorato2cc62e82010-03-17 20:23:53 -0700260 sRollo.dirtyCheck();
261 sRollo.resize(w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800262
Jason Sams14f67ed2010-05-11 14:02:43 -0700263 Log.d(TAG, "sc " + sRS);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700264 if (sRS != null) {
265 sRS.mMessageCallback = mMessageProc = new AAMessage();
Daniel Sandler388f6792010-03-02 14:08:08 -0500266 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800267
Joe Onorato2cc62e82010-03-17 20:23:53 -0700268 if (sRollo.mUniformAlloc != null) {
Jason Sams60a55bb2010-06-18 15:11:19 -0700269 ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
270 i.ScaleOffset.x = (2.f / 480.f);
271 i.ScaleOffset.y = 0;
272 i.ScaleOffset.z = -((float)w / 2) - 0.25f;
273 i.ScaleOffset.w = -380.25f;
274 i.BendPos.x = 120.f;
275 i.BendPos.y = 680.f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500276 if (w > h) {
Jason Sams60a55bb2010-06-18 15:11:19 -0700277 i.ScaleOffset.z = 40.f;
278 i.ScaleOffset.w = h - 40.f;
279 i.BendPos.y = 1.f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500280 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700281 sRollo.mUniformAlloc.set(i, 0, true);
Daniel Sandler388f6792010-03-02 14:08:08 -0500282 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800283
Daniel Sandler388f6792010-03-02 14:08:08 -0500284 //long endTime = SystemClock.uptimeMillis();
285 //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
286 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800287
Daniel Sandler388f6792010-03-02 14:08:08 -0500288 @Override
289 public void onWindowFocusChanged(boolean hasWindowFocus) {
290 super.onWindowFocusChanged(hasWindowFocus);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800291
292 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800293
Daniel Sandler388f6792010-03-02 14:08:08 -0500294 if (mArrowNavigation) {
295 if (!hasWindowFocus) {
296 // Clear selection when we lose window focus
Jason Sams14f67ed2010-05-11 14:02:43 -0700297 mLastSelectedIcon = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700298 sRollo.setHomeSelected(SELECTED_NONE);
299 sRollo.clearSelectedIcon();
Romain Guy060b5c82010-03-04 10:07:38 -0800300 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700301 if (sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500302 if (mLastSelection == SELECTION_ICONS) {
303 int selection = mLastSelectedIcon;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700304 final int firstIcon = Math.round(sRollo.mScrollPos) * mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500305 if (selection < 0 || // No selection
306 selection < firstIcon || // off the top of the screen
Jason Sams14f67ed2010-05-11 14:02:43 -0700307 selection >= sRollo.mScript.get_gIconCount() || // past last icon
Daniel Sandler388f6792010-03-02 14:08:08 -0500308 selection >= firstIcon + // past last icon on screen
Romain Guy060b5c82010-03-04 10:07:38 -0800309 (mColumnsPerPage * mRowsPerPage)) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500310 selection = firstIcon;
311 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800312
Daniel Sandler388f6792010-03-02 14:08:08 -0500313 // Select the first icon when we gain window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700314 sRollo.selectIcon(selection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500315 } else if (mLastSelection == SELECTION_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700316 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500317 }
318 }
319 }
320 }
321 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800322
Daniel Sandler388f6792010-03-02 14:08:08 -0500323 @Override
324 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
325 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800326
Romain Guy13c2e7b2010-03-10 19:45:00 -0800327 if (!isVisible() || mSurrendered) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500328 return;
329 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800330
Daniel Sandler388f6792010-03-02 14:08:08 -0500331 if (gainFocus) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700332 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500333 gainFocus();
334 } else {
335 mShouldGainFocus = true;
336 }
337 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700338 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500339 if (mArrowNavigation) {
340 // Clear selection when we lose focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700341 sRollo.clearSelectedIcon();
342 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500343 mArrowNavigation = false;
344 }
345 } else {
346 mShouldGainFocus = false;
347 }
348 }
349 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800350
Daniel Sandler388f6792010-03-02 14:08:08 -0500351 private void gainFocus() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700352 if (!mArrowNavigation && sRollo.mScript.get_gIconCount() > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500353 // Select the first icon when we gain keyboard focus
354 mArrowNavigation = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700355 sRollo.selectIcon(Math.round(sRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500356 }
357 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800358
Daniel Sandler388f6792010-03-02 14:08:08 -0500359 @Override
360 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800361
Daniel Sandler388f6792010-03-02 14:08:08 -0500362 boolean handled = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800363
Daniel Sandler388f6792010-03-02 14:08:08 -0500364 if (!isVisible()) {
365 return false;
366 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700367 final int iconCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800368
Daniel Sandler388f6792010-03-02 14:08:08 -0500369 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
370 if (mArrowNavigation) {
371 if (mLastSelection == SELECTION_HOME) {
372 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
373 mLauncher.closeAllApps(true);
374 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700375 int whichApp = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500376 if (whichApp >= 0) {
377 ApplicationInfo app = mAllAppsList.get(whichApp);
Joe Onoratof984e852010-03-25 09:47:45 -0700378 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500379 handled = true;
380 }
381 }
382 }
383 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800384
Daniel Sandler388f6792010-03-02 14:08:08 -0500385 if (iconCount > 0) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800386 final boolean isPortrait = getWidth() < getHeight();
Jason Sams14f67ed2010-05-11 14:02:43 -0700387
Daniel Sandler388f6792010-03-02 14:08:08 -0500388 mArrowNavigation = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800389
Jason Sams14f67ed2010-05-11 14:02:43 -0700390 int currentSelection = sRollo.mScript.get_gSelectedIconIndex();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700391 int currentTopRow = Math.round(sRollo.mScrollPos);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800392
Romain Guy060b5c82010-03-04 10:07:38 -0800393 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1
394 final int currentPageCol = currentSelection % mColumnsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800395
Romain Guy060b5c82010-03-04 10:07:38 -0800396 // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1
Romain Guy6a42cf32010-03-12 16:03:52 -0800397 final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage))
Romain Guy060b5c82010-03-04 10:07:38 -0800398 / mRowsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800399
Daniel Sandler388f6792010-03-02 14:08:08 -0500400 int newSelection = currentSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800401
Daniel Sandler388f6792010-03-02 14:08:08 -0500402 switch (keyCode) {
403 case KeyEvent.KEYCODE_DPAD_UP:
404 if (mLastSelection == SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800405 if (isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700406 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guy6a42cf32010-03-12 16:03:52 -0800407 int lastRowCount = iconCount % mColumnsPerPage;
408 if (lastRowCount == 0) {
409 lastRowCount = mColumnsPerPage;
410 }
411 newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2);
412 if (newSelection >= iconCount) {
413 newSelection = iconCount-1;
414 }
415 int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
416 if (target < 0) {
417 target = 0;
418 }
419 if (currentTopRow != target) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700420 sRollo.moveTo(target);
Romain Guy6a42cf32010-03-12 16:03:52 -0800421 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500422 }
423 } else {
424 if (currentPageRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800425 newSelection = currentSelection - mColumnsPerPage;
Romain Guy6a42cf32010-03-12 16:03:52 -0800426 if (currentTopRow > newSelection / mColumnsPerPage) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700427 sRollo.moveTo(newSelection / mColumnsPerPage);
Romain Guy6a42cf32010-03-12 16:03:52 -0800428 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500429 } else if (currentTopRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800430 newSelection = currentSelection - mColumnsPerPage;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700431 sRollo.moveTo(newSelection / mColumnsPerPage);
Daniel Sandler388f6792010-03-02 14:08:08 -0500432 } else if (currentPageRow != 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800433 newSelection = currentTopRow * mRowsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500434 }
435 }
436 handled = true;
437 break;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800438
Daniel Sandler388f6792010-03-02 14:08:08 -0500439 case KeyEvent.KEYCODE_DPAD_DOWN: {
Romain Guy060b5c82010-03-04 10:07:38 -0800440 final int rowCount = iconCount / mColumnsPerPage
441 + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
442 final int currentRow = currentSelection / mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500443 if (mLastSelection != SELECTION_HOME) {
444 if (currentRow < rowCount-1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700445 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500446 if (currentSelection < 0) {
447 newSelection = 0;
448 } else {
Romain Guy060b5c82010-03-04 10:07:38 -0800449 newSelection = currentSelection + mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500450 }
451 if (newSelection >= iconCount) {
452 // Go from D to G in this arrangement:
453 // A B C D
454 // E F G
455 newSelection = iconCount - 1;
456 }
Romain Guy060b5c82010-03-04 10:07:38 -0800457 if (currentPageRow >= mRowsPerPage - 1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700458 sRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -0500459 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800460 } else if (isPortrait) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500461 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700462 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500463 }
464 }
465 handled = true;
466 break;
467 }
468 case KeyEvent.KEYCODE_DPAD_LEFT:
469 if (mLastSelection != SELECTION_HOME) {
470 if (currentPageCol > 0) {
471 newSelection = currentSelection - 1;
472 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800473 } else if (!isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700474 newSelection = ((int) (sRollo.mScrollPos) * mColumnsPerPage) +
Romain Guy6a42cf32010-03-12 16:03:52 -0800475 (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700476 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500477 }
478 handled = true;
479 break;
480 case KeyEvent.KEYCODE_DPAD_RIGHT:
481 if (mLastSelection != SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800482 if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 ||
483 currentSelection == iconCount - 1)) {
484 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700485 sRollo.setHomeSelected(SELECTED_FOCUSED);
Romain Guy6a42cf32010-03-12 16:03:52 -0800486 } else if ((currentPageCol < mColumnsPerPage - 1) &&
Daniel Sandler388f6792010-03-02 14:08:08 -0500487 (currentSelection < iconCount - 1)) {
488 newSelection = currentSelection + 1;
489 }
490 }
491 handled = true;
492 break;
493 }
494 if (newSelection != currentSelection) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700495 sRollo.selectIcon(newSelection, SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500496 }
497 }
498 return handled;
499 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800500
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700501 void initTouchState(int width, int height) {
502 boolean isPortrait = width < height;
503
504 int[] viewPos = new int[2];
505 getLocationOnScreen(viewPos);
506
507 mTouchXBorders = new int[mColumnsPerPage + 1];
508 mTouchYBorders = new int[mRowsPerPage + 1];
509
510 // TODO: Put this in a config file/define
511 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE_PORTRAIT;
512 if (!isPortrait) cellHeight -= 12;
513 int centerY = (int) (height * (isPortrait ? 0.5f : 0.47f));
514 if (!isPortrait) centerY += cellHeight / 2;
515 int half = (int) Math.floor((mRowsPerPage + 1) / 2);
516 int end = mTouchYBorders.length - (half + 1);
517
518 for (int i = -half; i <= end; i++) {
519 mTouchYBorders[i + half] = centerY + (i * cellHeight) - viewPos[1];
520 }
521
522 int x = 0;
523 // TODO: Put this in a config file/define
524 int columnWidth = 120;
525 for (int i = 0; i < mColumnsPerPage + 1; i++) {
526 mTouchXBorders[i] = x - viewPos[0];
527 x += columnWidth;
528 }
529 }
530
531 int chooseTappedIcon(int x, int y) {
532 float pos = sRollo != null ? sRollo.mScrollPos : 0;
533
534 int oldY = y;
535
536 // Adjust for scroll position if not zero.
537 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
538
539 int col = -1;
540 int row = -1;
541 final int columnsCount = mColumnsPerPage;
542 for (int i=0; i< columnsCount; i++) {
543 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
544 col = i;
545 break;
546 }
547 }
548 final int rowsCount = mRowsPerPage;
549 for (int i=0; i< rowsCount; i++) {
550 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
551 row = i;
552 break;
553 }
554 }
555
556 if (row < 0 || col < 0) {
557 return -1;
558 }
559
560 int index = (((int) pos) * columnsCount) + (row * columnsCount) + col;
561
562 if (index >= mAllAppsList.size()) {
563 return -1;
564 } else {
565 return index;
566 }
567 }
568
Daniel Sandler388f6792010-03-02 14:08:08 -0500569 @Override
570 public boolean onTouchEvent(MotionEvent ev)
571 {
572 mArrowNavigation = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800573
Daniel Sandler388f6792010-03-02 14:08:08 -0500574 if (!isVisible()) {
575 return true;
576 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800577
Daniel Sandler388f6792010-03-02 14:08:08 -0500578 if (mLocks != 0) {
579 return true;
580 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800581
Daniel Sandler388f6792010-03-02 14:08:08 -0500582 super.onTouchEvent(ev);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800583
Daniel Sandler388f6792010-03-02 14:08:08 -0500584 int x = (int)ev.getX();
585 int y = (int)ev.getY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800586
Romain Guyce115852010-03-04 12:15:37 -0800587 final boolean isPortrait = getWidth() < getHeight();
Daniel Sandler388f6792010-03-02 14:08:08 -0500588 int action = ev.getAction();
589 switch (action) {
590 case MotionEvent.ACTION_DOWN:
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700591 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
592 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500593 mTouchTracking = TRACKING_HOME;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700594 sRollo.setHomeSelected(SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500595 mCurrentIconIndex = -1;
596 } else {
597 mTouchTracking = TRACKING_FLING;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800598
Daniel Sandler388f6792010-03-02 14:08:08 -0500599 mMotionDownRawX = (int)ev.getRawX();
600 mMotionDownRawY = (int)ev.getRawY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800601
Joe Onorato2cc62e82010-03-17 20:23:53 -0700602 if (!sRollo.checkClickOK()) {
603 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500604 } else {
605 mDownIconIndex = mCurrentIconIndex
Joe Onorato2cc62e82010-03-17 20:23:53 -0700606 = sRollo.selectIcon(x, y, SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500607 if (mDownIconIndex < 0) {
608 // if nothing was selected, no long press.
609 cancelLongPress();
610 }
611 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700612 sRollo.move(ev.getRawY() / getHeight());
Daniel Sandler388f6792010-03-02 14:08:08 -0500613 mVelocityTracker = VelocityTracker.obtain();
614 mVelocityTracker.addMovement(ev);
615 mStartedScrolling = false;
616 }
617 break;
618 case MotionEvent.ACTION_MOVE:
619 case MotionEvent.ACTION_OUTSIDE:
620 if (mTouchTracking == TRACKING_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700621 sRollo.setHomeSelected((isPortrait &&
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700622 y > mTouchYBorders[mTouchYBorders.length-1]) || (!isPortrait
623 && x > mTouchXBorders[mTouchXBorders.length-1])
Daniel Sandler388f6792010-03-02 14:08:08 -0500624 ? SELECTED_PRESSED : SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500625 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500626 int rawY = (int)ev.getRawY();
627 int slop;
628 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800629
Daniel Sandler388f6792010-03-02 14:08:08 -0500630 if (!mStartedScrolling && slop < mSlop) {
631 // don't update anything so when we do start scrolling
632 // below, we get the right delta.
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700633 mCurrentIconIndex = chooseTappedIcon(x, y);
Daniel Sandler388f6792010-03-02 14:08:08 -0500634 if (mDownIconIndex != mCurrentIconIndex) {
635 // If a different icon is selected, don't allow it to be picked up.
636 // This handles off-axis dragging.
637 cancelLongPress();
638 mCurrentIconIndex = -1;
639 }
640 } else {
641 if (!mStartedScrolling) {
642 cancelLongPress();
643 mCurrentIconIndex = -1;
644 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700645 sRollo.move(ev.getRawY() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800646
Daniel Sandler388f6792010-03-02 14:08:08 -0500647 mStartedScrolling = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700648 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500649 mVelocityTracker.addMovement(ev);
Daniel Sandler388f6792010-03-02 14:08:08 -0500650 }
651 }
652 break;
653 case MotionEvent.ACTION_UP:
654 case MotionEvent.ACTION_CANCEL:
655 if (mTouchTracking == TRACKING_HOME) {
656 if (action == MotionEvent.ACTION_UP) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700657 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
658 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500659 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
660 mLauncher.closeAllApps(true);
661 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700662 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500663 }
664 mCurrentIconIndex = -1;
665 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500666 mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700667 sRollo.clearSelectedIcon();
Jason Sams60a55bb2010-06-18 15:11:19 -0700668 sRollo.fling(ev.getRawY() / getHeight(),
669 mVelocityTracker.getYVelocity() / getHeight());
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800670
Daniel Sandler388f6792010-03-02 14:08:08 -0500671 if (mVelocityTracker != null) {
672 mVelocityTracker.recycle();
673 mVelocityTracker = null;
674 }
675 }
676 mTouchTracking = TRACKING_NONE;
677 break;
678 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800679
Daniel Sandler388f6792010-03-02 14:08:08 -0500680 return true;
681 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800682
Daniel Sandler388f6792010-03-02 14:08:08 -0500683 public void onClick(View v) {
684 if (mLocks != 0 || !isVisible()) {
685 return;
686 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700687 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500688 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
689 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
690 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onoratof984e852010-03-25 09:47:45 -0700691 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500692 }
693 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800694
Daniel Sandler388f6792010-03-02 14:08:08 -0500695 public boolean onLongClick(View v) {
Joe Onorato6b4adbc2010-09-01 12:13:25 -0700696 // We don't accept long click events in these cases
697 // - If the workspace isn't ready to accept a drop
698 // - If we're not done loading (because we might be confused about which item
699 // to pick up
700 // - If we're not visible
701 if (!isVisible() || mLauncher.isWorkspaceLocked() || mLocks != 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500702 return true;
703 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700704 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500705 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
706 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800707
Daniel Sandler388f6792010-03-02 14:08:08 -0500708 Bitmap bmp = app.iconBitmap;
709 final int w = bmp.getWidth();
710 final int h = bmp.getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800711
Daniel Sandler388f6792010-03-02 14:08:08 -0500712 // We don't really have an accurate location to use. This will do.
713 int screenX = mMotionDownRawX - (w / 2);
714 int screenY = mMotionDownRawY - h;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800715
Daniel Sandler388f6792010-03-02 14:08:08 -0500716 mDragController.startDrag(bmp, screenX, screenY,
717 0, 0, w, h, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800718
Daniel Sandler388f6792010-03-02 14:08:08 -0500719 mLauncher.closeAllApps(true);
720 }
721 return true;
722 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800723
Daniel Sandler388f6792010-03-02 14:08:08 -0500724 @Override
725 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
726 if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
727 if (!isVisible()) {
728 return false;
729 }
730 String text = null;
731 int index;
732 int count = mAllAppsList.size() + 1; // +1 is home
733 int pos = -1;
734 switch (mLastSelection) {
735 case SELECTION_ICONS:
Jason Sams14f67ed2010-05-11 14:02:43 -0700736 index = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500737 if (index >= 0) {
738 ApplicationInfo info = mAllAppsList.get(index);
739 if (info.title != null) {
740 text = info.title.toString();
741 pos = index;
742 }
743 }
744 break;
745 case SELECTION_HOME:
746 text = getContext().getString(R.string.all_apps_home_button_label);
747 pos = count;
748 break;
749 }
750 if (text != null) {
751 event.setEnabled(true);
752 event.getText().add(text);
753 //event.setContentDescription(text);
754 event.setItemCount(count);
755 event.setCurrentItemIndex(pos);
756 }
757 }
758 return false;
759 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800760
Daniel Sandler388f6792010-03-02 14:08:08 -0500761 public void setDragController(DragController dragger) {
762 mDragController = dragger;
763 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800764
Daniel Sandler388f6792010-03-02 14:08:08 -0500765 public void onDropCompleted(View target, boolean success) {
766 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800767
Daniel Sandler388f6792010-03-02 14:08:08 -0500768 /**
769 * Zoom to the specifed level.
770 *
771 * @param zoom [0..1] 0 is hidden, 1 is open
772 */
773 public void zoom(float zoom, boolean animate) {
774 cancelLongPress();
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700775 sNextZoom = zoom;
776 sAnimateNextZoom = animate;
Daniel Sandler388f6792010-03-02 14:08:08 -0500777 // if we do setZoom while we don't have a surface, we won't
778 // get the callbacks that actually set mZoom.
Joe Onorato2cc62e82010-03-17 20:23:53 -0700779 if (sRollo == null || !mHaveSurface) {
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700780 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500781 mZoom = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500782 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700783 sRollo.setZoom(zoom, animate);
Daniel Sandler388f6792010-03-02 14:08:08 -0500784 }
785 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800786
Joe Onorato878f0862010-03-22 12:22:22 -0400787 /**
788 * If sRollo is null, then we're not visible. This is also used to guard against
789 * sRollo being null.
790 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500791 public boolean isVisible() {
Joe Onorato878f0862010-03-22 12:22:22 -0400792 return sRollo != null && mZoom > 0.001f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500793 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800794
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700795 public boolean isAnimating() {
796 return isVisible() && mZoom <= 0.999f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500797 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800798
Daniel Sandler388f6792010-03-02 14:08:08 -0500799 public void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700800 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500801 // We've been removed from the window. Don't bother with all this.
802 return;
803 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800804
Daniel Sandler707b0f72010-04-15 16:41:31 -0400805 if (list != null) {
806 Collections.sort(list, LauncherModel.APP_NAME_COMPARATOR);
807 }
808
Romain Guy13c2e7b2010-03-10 19:45:00 -0800809 boolean reload = false;
810 if (mAllAppsList == null) {
811 reload = true;
812 } else if (list.size() != mAllAppsList.size()) {
813 reload = true;
814 } else {
815 final int count = list.size();
816 for (int i = 0; i < count; i++) {
817 if (list.get(i) != mAllAppsList.get(i)) {
818 reload = true;
819 break;
820 }
821 }
822 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800823
Daniel Sandler388f6792010-03-02 14:08:08 -0500824 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700825 if (sRollo != null && reload) {
826 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500827 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700828
Romain Guyc16fea72010-03-12 17:17:56 -0800829 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700830 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
Romain Guyc16fea72010-03-12 17:17:56 -0800831 mRestoreFocusIndex = -1;
832 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700833
Daniel Sandler388f6792010-03-02 14:08:08 -0500834 mLocks &= ~LOCK_ICONS_PENDING;
835 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800836
Daniel Sandler388f6792010-03-02 14:08:08 -0500837 public void addApps(ArrayList<ApplicationInfo> list) {
838 if (mAllAppsList == null) {
839 // Not done loading yet. We'll find out about it later.
840 return;
841 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700842 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500843 // We've been removed from the window. Don't bother with all this.
844 return;
845 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800846
Daniel Sandler388f6792010-03-02 14:08:08 -0500847 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700848 if (sRollo != null) {
849 sRollo.pause();
Jason Sams14f67ed2010-05-11 14:02:43 -0700850 sRollo.reallocAppsList(sRollo.mScript.get_gIconCount() + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500851 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800852
Daniel Sandler388f6792010-03-02 14:08:08 -0500853 for (int i=0; i<N; i++) {
854 final ApplicationInfo item = list.get(i);
855 int index = Collections.binarySearch(mAllAppsList, item,
856 LauncherModel.APP_NAME_COMPARATOR);
857 if (index < 0) {
858 index = -(index+1);
859 }
860 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700861 if (sRollo != null) {
862 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500863 }
864 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800865
Joe Onorato2cc62e82010-03-17 20:23:53 -0700866 if (sRollo != null) {
867 sRollo.saveAppsList();
868 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500869 }
870 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800871
Daniel Sandler388f6792010-03-02 14:08:08 -0500872 public void removeApps(ArrayList<ApplicationInfo> list) {
873 if (mAllAppsList == null) {
874 // Not done loading yet. We'll find out about it later.
875 return;
876 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800877
Joe Onorato2cc62e82010-03-17 20:23:53 -0700878 if (sRollo != null) {
879 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800880 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500881 final int N = list.size();
882 for (int i=0; i<N; i++) {
883 final ApplicationInfo item = list.get(i);
884 int index = findAppByComponent(mAllAppsList, item);
885 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500886 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700887 if (sRollo != null) {
888 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500889 }
890 } else {
891 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
892 // Try to recover. This should keep us from crashing for now.
893 }
894 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800895
Joe Onorato2cc62e82010-03-17 20:23:53 -0700896 if (sRollo != null) {
897 sRollo.saveAppsList();
898 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500899 }
900 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800901
Joe Onorato64e6be72010-03-05 15:05:52 -0500902 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500903 // Just remove and add, because they may need to be re-sorted.
904 removeApps(list);
905 addApps(list);
906 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800907
Daniel Sandler388f6792010-03-02 14:08:08 -0500908 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
909 ComponentName component = item.intent.getComponent();
910 final int N = list.size();
911 for (int i=0; i<N; i++) {
912 ApplicationInfo x = list.get(i);
913 if (x.intent.getComponent().equals(component)) {
914 return i;
915 }
916 }
917 return -1;
918 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800919
Daniel Sandler388f6792010-03-02 14:08:08 -0500920 class AAMessage extends RenderScript.RSMessage {
921 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700922 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500923 mVelocity = ((float)mData[1]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700924
925 boolean lastVisible = isVisible();
Daniel Sandler388f6792010-03-02 14:08:08 -0500926 mZoom = ((float)mData[2]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700927
928 final boolean visible = isVisible();
929 if (visible != lastVisible) {
930 post(new Runnable() {
931 public void run() {
932 if (visible) {
933 showSurface();
934 } else {
935 hideSurface();
936 }
937 }
938 });
939 }
940
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700941 sZoomDirty = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500942 }
943 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800944
Romain Guy13c2e7b2010-03-10 19:45:00 -0800945 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500946 // Allocations ======
947 private int mWidth;
948 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800949
Daniel Sandler388f6792010-03-02 14:08:08 -0500950 private Resources mRes;
Jason Sams1aa4ff02010-06-15 14:59:57 -0700951 ScriptC_Allapps mScript;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800952
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700953 private Mesh mMesh;
Daniel Sandler388f6792010-03-02 14:08:08 -0500954 private ProgramVertex.MatrixAllocation mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800955
Jason Sams14f67ed2010-05-11 14:02:43 -0700956 private ScriptField_VpConsts mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800957
Daniel Sandler388f6792010-03-02 14:08:08 -0500958 private Allocation mHomeButtonNormal;
959 private Allocation mHomeButtonFocused;
960 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800961
Daniel Sandler388f6792010-03-02 14:08:08 -0500962 private Allocation[] mIcons;
963 private int[] mIconIds;
964 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800965
Daniel Sandler388f6792010-03-02 14:08:08 -0500966 private Allocation[] mLabels;
967 private int[] mLabelIds;
968 private Allocation mAllocLabelIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800969
Daniel Sandler388f6792010-03-02 14:08:08 -0500970 private Bitmap mSelectionBitmap;
971 private Canvas mSelectionCanvas;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800972
Jason Sams14f67ed2010-05-11 14:02:43 -0700973 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800974
Romain Guy13c2e7b2010-03-10 19:45:00 -0800975 AllApps3D mAllApps;
976 boolean mInitialize;
977
Daniel Sandler388f6792010-03-02 14:08:08 -0500978 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -0800979 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -0800980 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -0500981 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800982
983 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400984 if (sRS != null) {
985 sRS.contextBindRootScript(null);
986 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800987 }
988
989 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400990 if (sRS != null) {
991 sRS.contextBindRootScript(mScript);
992 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800993 }
994
Romain Guy13c2e7b2010-03-10 19:45:00 -0800995 public RolloRS(AllApps3D allApps) {
996 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -0500997 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800998
Daniel Sandler388f6792010-03-02 14:08:08 -0500999 public void init(Resources res, int width, int height) {
1000 mRes = res;
1001 mWidth = width;
1002 mHeight = height;
Shih-wei Liaoafb81d42010-07-19 16:20:03 -07001003 mScript = new ScriptC_Allapps(sRS, mRes, R.raw.allapps, true);
Jason Sams14f67ed2010-05-11 14:02:43 -07001004
Daniel Sandler388f6792010-03-02 14:08:08 -05001005 initProgramVertex();
1006 initProgramFragment();
1007 initProgramStore();
1008 initGl();
1009 initData();
Jason Sams14f67ed2010-05-11 14:02:43 -07001010
1011 mScript.bind_gIconIDs(mAllocIconIds);
1012 mScript.bind_gLabelIDs(mAllocLabelIds);
Jason Sams14f67ed2010-05-11 14:02:43 -07001013 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -05001014 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001015
Daniel Sandler388f6792010-03-02 14:08:08 -05001016 public void initMesh() {
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001017 Mesh.TriangleMeshBuilder tm = new Mesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001018
Daniel Sandler388f6792010-03-02 14:08:08 -05001019 for (int ct=0; ct < 16; ct++) {
1020 float pos = (1.f / (16.f - 1)) * ct;
1021 tm.addVertex(0.0f, pos);
1022 tm.addVertex(1.0f, pos);
1023 }
1024 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1025 tm.addTriangle(ct, ct+1, ct+2);
1026 tm.addTriangle(ct+1, ct+3, ct+2);
1027 }
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001028 mMesh = tm.create(true);
Jason Sams14f67ed2010-05-11 14:02:43 -07001029 mScript.set_gSMCell(mMesh);
Daniel Sandler388f6792010-03-02 14:08:08 -05001030 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001031
Daniel Sandler388f6792010-03-02 14:08:08 -05001032 void resize(int w, int h) {
1033 mPVA.setupProjectionNormalized(w, h);
1034 mWidth = w;
1035 mHeight = h;
1036 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001037
Daniel Sandler388f6792010-03-02 14:08:08 -05001038 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001039 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001040 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001041
Joe Onorato2cc62e82010-03-17 20:23:53 -07001042 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001043 pvb.setTextureMatrixEnable(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001044 ProgramVertex pv = pvb.create();
1045 pv.bindAllocation(mPVA);
1046 sRS.contextBindProgramVertex(pv);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001047
Jason Sams14f67ed2010-05-11 14:02:43 -07001048 mUniformAlloc = new ScriptField_VpConsts(sRS, 1);
1049 mScript.bind_vpConstants(mUniformAlloc);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001050
Daniel Sandler388f6792010-03-02 14:08:08 -05001051 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001052 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Romain Guy060b5c82010-03-04 10:07:38 -08001053 String t = "void main() {\n" +
1054 // Animation
1055 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001056
Romain Guy060b5c82010-03-04 10:07:38 -08001057 " float bendY1 = UNI_BendPos.x;\n" +
1058 " float bendY2 = UNI_BendPos.y;\n" +
1059 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1060 " float bendDistance = bendY1 * 0.4;\n" +
1061 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001062
Romain Guy060b5c82010-03-04 10:07:38 -08001063 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1064 " float aDy = cos(bendAngle);\n" +
1065 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001066
Romain Guy060b5c82010-03-04 10:07:38 -08001067 " float scale = (2.0 / 480.0);\n" +
1068 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1069 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1070 " float y = 0.0;\n" +
1071 " float z = 0.0;\n" +
1072 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001073
Romain Guy060b5c82010-03-04 10:07:38 -08001074 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1075 " y += cv * aDy;\n" +
1076 " z += -cv * aDz;\n" +
1077 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1078 " lum += cv / bendDistance * distanceDimLevel;\n" +
1079 " y += cv * cos(cv * bendStep);\n" +
1080 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001081
Romain Guy060b5c82010-03-04 10:07:38 -08001082 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1083 " y += cv * aDy;\n" +
1084 " z += cv * aDz;\n" +
1085 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1086 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1087 " y += cv * cos(cv * bendStep);\n" +
1088 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001089
Romain Guy060b5c82010-03-04 10:07:38 -08001090 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001091
Romain Guy060b5c82010-03-04 10:07:38 -08001092 " vec4 pos;\n" +
1093 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1094 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1095 " pos.z = z * UNI_ScaleOffset.x;\n" +
1096 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001097
Romain Guy060b5c82010-03-04 10:07:38 -08001098 " pos.x *= 1.0 + ani * 4.0;\n" +
1099 " pos.y *= 1.0 + ani * 4.0;\n" +
1100 " pos.z -= ani * 1.5;\n" +
1101 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001102
Romain Guy060b5c82010-03-04 10:07:38 -08001103 " gl_Position = UNI_MVP * pos;\n" +
1104 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1105 " varTex0.xy = ATTRIB_position;\n" +
1106 " varTex0.y = 1.0 - varTex0.y;\n" +
1107 " varTex0.zw = vec2(0.0, 0.0);\n" +
1108 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001109 sb.setShader(t);
1110 sb.addConstant(mUniformAlloc.getType());
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001111 sb.addInput(mMesh.getVertexAllocation(0).getType().getElement());
Jason Sams60a55bb2010-06-18 15:11:19 -07001112 ProgramVertex pvc = sb.create();
1113 pvc.bindAllocation(mPVA);
1114 pvc.bindConstants(mUniformAlloc.getAllocation(), 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001115
Jason Sams60a55bb2010-06-18 15:11:19 -07001116 mScript.set_gPVCurve(pvc);
Daniel Sandler388f6792010-03-02 14:08:08 -05001117 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001118
Daniel Sandler388f6792010-03-02 14:08:08 -05001119 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001120 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001121 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1122 sb.setMag(Sampler.Value.NEAREST);
1123 sb.setWrapS(Sampler.Value.CLAMP);
1124 sb.setWrapT(Sampler.Value.CLAMP);
1125 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001126
Daniel Sandler388f6792010-03-02 14:08:08 -05001127 sb.setMin(Sampler.Value.NEAREST);
1128 sb.setMag(Sampler.Value.NEAREST);
1129 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001130
Joe Onorato2cc62e82010-03-17 20:23:53 -07001131 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001132 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1133 ProgramFragment.Builder.Format.RGBA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001134 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001135 ProgramFragment pfTexMip = bf.create();
1136 pfTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001137
Jason Sams070ada82010-08-04 17:53:07 -07001138 bf.setVaryingColor(false);
Jason Sams60a55bb2010-06-18 15:11:19 -07001139 ProgramFragment pfTexNearest = bf.create();
1140 pfTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001141
Daniel Sandler388f6792010-03-02 14:08:08 -05001142 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1143 ProgramFragment.Builder.Format.ALPHA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001144 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001145 ProgramFragment pfTexMipAlpha = bf.create();
1146 pfTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001147
Jason Sams60a55bb2010-06-18 15:11:19 -07001148 mScript.set_gPFTexNearest(pfTexNearest);
1149 mScript.set_gPFTexMip(pfTexMip);
1150 mScript.set_gPFTexMipAlpha(pfTexMipAlpha);
Daniel Sandler388f6792010-03-02 14:08:08 -05001151 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001152
Daniel Sandler388f6792010-03-02 14:08:08 -05001153 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001154 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001155 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1156 bs.setColorMask(true,true,true,false);
1157 bs.setDitherEnable(true);
1158 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1159 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Jason Sams14f67ed2010-05-11 14:02:43 -07001160 mScript.set_gPS(bs.create());
Daniel Sandler388f6792010-03-02 14:08:08 -05001161 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001162
Daniel Sandler388f6792010-03-02 14:08:08 -05001163 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001164 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001165
Daniel Sandler388f6792010-03-02 14:08:08 -05001166 private void initData() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001167 mScript.set_COLUMNS_PER_PAGE_PORTRAIT(Defines.COLUMNS_PER_PAGE_PORTRAIT);
1168 mScript.set_ROWS_PER_PAGE_PORTRAIT(Defines.ROWS_PER_PAGE_PORTRAIT);
1169 mScript.set_COLUMNS_PER_PAGE_LANDSCAPE(Defines.COLUMNS_PER_PAGE_LANDSCAPE);
1170 mScript.set_ROWS_PER_PAGE_LANDSCAPE(Defines.ROWS_PER_PAGE_LANDSCAPE);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001171
Joe Onorato2cc62e82010-03-17 20:23:53 -07001172 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1173 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001174 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001175 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1176 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001177 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001178 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1179 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001180 mHomeButtonPressed.uploadToTexture(0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001181
Jason Sams14f67ed2010-05-11 14:02:43 -07001182 mScript.set_gHomeButton(mHomeButtonNormal);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001183
Daniel Sandler388f6792010-03-02 14:08:08 -05001184 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1185 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1186 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001187
Daniel Sandler388f6792010-03-02 14:08:08 -05001188 setApps(null);
1189 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001190
Daniel Sandler388f6792010-03-02 14:08:08 -05001191 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001192 if (sZoomDirty) {
1193 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001194 }
1195 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001196
Romain Guy060b5c82010-03-04 10:07:38 -08001197 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001198 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001199 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001200 final int count = list != null ? list.size() : 0;
1201 int allocCount = count;
1202 if (allocCount < 1) {
1203 allocCount = 1;
1204 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001205
Daniel Sandler388f6792010-03-02 14:08:08 -05001206 mIcons = new Allocation[count];
1207 mIconIds = new int[allocCount];
Jason Sams98994c42010-06-01 15:54:10 -07001208 mAllocIconIds = Allocation.createSized(sRS, Element.I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001209
Daniel Sandler388f6792010-03-02 14:08:08 -05001210 mLabels = new Allocation[count];
1211 mLabelIds = new int[allocCount];
Jason Sams98994c42010-06-01 15:54:10 -07001212 mAllocLabelIds = Allocation.createSized(sRS, Element.I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001213
Jason Sams14f67ed2010-05-11 14:02:43 -07001214 mScript.set_gIconCount(count);
1215 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001216 createAppIconAllocations(i, list.get(i));
1217 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001218 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001219 uploadAppIcon(i, list.get(i));
1220 }
1221 saveAppsList();
Jason Sams14f67ed2010-05-11 14:02:43 -07001222 android.util.Log.e("rs", "setApps");
Joe Onorato2cc62e82010-03-17 20:23:53 -07001223 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001224 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001225
Daniel Sandler388f6792010-03-02 14:08:08 -05001226 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001227 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001228 sRollo.clearSelectedIcon();
1229 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001230 }
Jason Sams60a55bb2010-06-18 15:11:19 -07001231 sRollo.mScript.invoke_setZoom(zoom, animate ? 1 : 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001232 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001233
Daniel Sandler388f6792010-03-02 14:08:08 -05001234 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001235 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1236 Element.RGBA_8888(sRS), false);
1237 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1238 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001239 mIconIds[index] = mIcons[index].getID();
1240 mLabelIds[index] = mLabels[index].getID();
1241 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001242
Daniel Sandler388f6792010-03-02 14:08:08 -05001243 private void uploadAppIcon(int index, ApplicationInfo item) {
1244 if (mIconIds[index] != mIcons[index].getID()) {
1245 throw new IllegalStateException("uploadAppIcon index=" + index
1246 + " mIcons[index].getID=" + mIcons[index].getID()
1247 + " mIconsIds[index]=" + mIconIds[index]
1248 + " item=" + item);
1249 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001250 mIcons[index].uploadToTexture(true, 0);
1251 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001252 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001253
Daniel Sandler388f6792010-03-02 14:08:08 -05001254 /**
1255 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1256 * fill in the values and call saveAppsList().
1257 */
1258 private void reallocAppsList(int count) {
1259 Allocation[] icons = new Allocation[count];
1260 int[] iconIds = new int[count];
Jason Sams98994c42010-06-01 15:54:10 -07001261 mAllocIconIds = Allocation.createSized(sRS, Element.I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001262
Daniel Sandler388f6792010-03-02 14:08:08 -05001263 Allocation[] labels = new Allocation[count];
1264 int[] labelIds = new int[count];
Jason Sams98994c42010-06-01 15:54:10 -07001265 mAllocLabelIds = Allocation.createSized(sRS, Element.I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001266
Jason Sams14f67ed2010-05-11 14:02:43 -07001267 final int oldCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001268
Daniel Sandler388f6792010-03-02 14:08:08 -05001269 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1270 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1271 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1272 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001273
Daniel Sandler388f6792010-03-02 14:08:08 -05001274 mIcons = icons;
1275 mIconIds = iconIds;
1276 mLabels = labels;
1277 mLabelIds = labelIds;
1278 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001279
Daniel Sandler388f6792010-03-02 14:08:08 -05001280 /**
1281 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1282 */
1283 private void addApp(int index, ApplicationInfo item) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001284 final int count = mScript.get_gIconCount() - index;
Daniel Sandler388f6792010-03-02 14:08:08 -05001285 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001286
Daniel Sandler388f6792010-03-02 14:08:08 -05001287 System.arraycopy(mIcons, index, mIcons, dest, count);
1288 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1289 System.arraycopy(mLabels, index, mLabels, dest, count);
1290 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001291
Daniel Sandler388f6792010-03-02 14:08:08 -05001292 createAppIconAllocations(index, item);
1293 uploadAppIcon(index, item);
Jason Sams14f67ed2010-05-11 14:02:43 -07001294
1295 mScript.set_gIconCount(mScript.get_gIconCount() + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001296 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001297
Daniel Sandler388f6792010-03-02 14:08:08 -05001298 /**
1299 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1300 */
1301 private void removeApp(int index) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001302 final int count = mScript.get_gIconCount() - index - 1;
Daniel Sandler388f6792010-03-02 14:08:08 -05001303 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001304
Daniel Sandler388f6792010-03-02 14:08:08 -05001305 System.arraycopy(mIcons, src, mIcons, index, count);
1306 System.arraycopy(mIconIds, src, mIconIds, index, count);
1307 System.arraycopy(mLabels, src, mLabels, index, count);
1308 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001309
Jason Sams14f67ed2010-05-11 14:02:43 -07001310 mScript.set_gIconCount(mScript.get_gIconCount() - 1);
1311 final int last = mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001312
Daniel Sandler388f6792010-03-02 14:08:08 -05001313 mIcons[last] = null;
1314 mIconIds[last] = 0;
1315 mLabels[last] = null;
1316 mLabelIds[last] = 0;
1317 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001318
Daniel Sandler388f6792010-03-02 14:08:08 -05001319 /**
1320 * Send the apps list structures to RS.
1321 */
1322 private void saveAppsList() {
1323 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1324 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001325 mAllocIconIds.data(mIconIds);
1326 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001327
Jason Sams14f67ed2010-05-11 14:02:43 -07001328 mScript.bind_gIconIDs(mAllocIconIds);
1329 mScript.bind_gLabelIDs(mAllocLabelIds);
Daniel Sandler388f6792010-03-02 14:08:08 -05001330 }
1331 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001332
Jason Sams60a55bb2010-06-18 15:11:19 -07001333 void fling(float pos, float v) {
1334 mScript.invoke_fling(pos, v);
Daniel Sandler388f6792010-03-02 14:08:08 -05001335 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001336
Jason Sams60a55bb2010-06-18 15:11:19 -07001337 void move(float pos) {
1338 mScript.invoke_move(pos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001339 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001340
Daniel Sandler388f6792010-03-02 14:08:08 -05001341 void moveTo(float row) {
Jason Sams60a55bb2010-06-18 15:11:19 -07001342 mScript.invoke_moveTo(row);
Daniel Sandler388f6792010-03-02 14:08:08 -05001343 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001344
Daniel Sandler388f6792010-03-02 14:08:08 -05001345 /**
1346 * You need to call save() on mState on your own after calling this.
1347 *
1348 * @return the index of the icon that was selected.
1349 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001350 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001351 if (mAllApps != null) {
1352 final int index = mAllApps.chooseTappedIcon(x, y);
1353 selectIcon(index, pressed);
1354 return index;
1355 } else {
1356 return -1;
1357 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001358 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001359
Daniel Sandler388f6792010-03-02 14:08:08 -05001360 /**
1361 * Select the icon at the given index.
1362 *
1363 * @param index The index.
1364 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1365 */
1366 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001367 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1368 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001369 if (mAllApps != null) {
1370 mAllApps.mRestoreFocusIndex = index;
1371 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001372 mScript.set_gSelectedIconIndex(-1);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001373 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1374 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001375 }
1376 } else {
1377 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001378 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001379 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001380
Jason Sams14f67ed2010-05-11 14:02:43 -07001381 int prev = mScript.get_gSelectedIconIndex();
1382 mScript.set_gSelectedIconIndex(index);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001383
Romain Guy13c2e7b2010-03-10 19:45:00 -08001384 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001385 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001386
Daniel Sandler388f6792010-03-02 14:08:08 -05001387 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1388 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1389 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001390
Jason Sams60a55bb2010-06-18 15:11:19 -07001391 Allocation si = Allocation.createFromBitmap(sRS, selectionBitmap,
Joe Onorato2cc62e82010-03-17 20:23:53 -07001392 Element.RGBA_8888(sRS), false);
Jason Sams60a55bb2010-06-18 15:11:19 -07001393 si.uploadToTexture(0);
1394 mScript.set_gSelectedIconTexture(si);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001395
Daniel Sandler388f6792010-03-02 14:08:08 -05001396 if (prev != index) {
1397 if (info.title != null && info.title.length() > 0) {
1398 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001399 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001400 }
1401 }
1402 }
1403 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001404
Daniel Sandler388f6792010-03-02 14:08:08 -05001405 /**
1406 * You need to call save() on mState on your own after calling this.
1407 */
1408 void clearSelectedIcon() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001409 mScript.set_gSelectedIconIndex(-1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001410 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001411
Daniel Sandler388f6792010-03-02 14:08:08 -05001412 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001413 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001414 switch (mode) {
1415 case SELECTED_NONE:
Jason Sams14f67ed2010-05-11 14:02:43 -07001416 mScript.set_gHomeButton(mHomeButtonNormal);
Daniel Sandler388f6792010-03-02 14:08:08 -05001417 break;
1418 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001419 mAllApps.mLastSelection = SELECTION_HOME;
Jason Sams14f67ed2010-05-11 14:02:43 -07001420 mScript.set_gHomeButton(mHomeButtonFocused);
Daniel Sandler388f6792010-03-02 14:08:08 -05001421 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001422 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001423 }
1424 break;
1425 case SELECTED_PRESSED:
Jason Sams14f67ed2010-05-11 14:02:43 -07001426 mScript.set_gHomeButton(mHomeButtonPressed);
Daniel Sandler388f6792010-03-02 14:08:08 -05001427 break;
1428 }
1429 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001430
Daniel Sandler388f6792010-03-02 14:08:08 -05001431 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001432 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1433 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1434 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001435 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001436 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001437 }
1438 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001439 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001440 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001441 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001442 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001443 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001444 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001445 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Jason Sams14f67ed2010-05-11 14:02:43 -07001446 //Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1447 //Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1448 //Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1449 //Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1450 //Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1451 //Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1452 //Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1453 //Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1454 //Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001455 }
1456 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001457
Daniel Sandler388f6792010-03-02 14:08:08 -05001458 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001459 Log.d(TAG, "sRS=" + sRS);
1460 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001461 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001462 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1463 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001464 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1465 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1466 Log.d(TAG, "mLastSelection=" + mLastSelection);
1467 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1468 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1469 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1470 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001471 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1472 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001473 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001474 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001475 Log.d(TAG, "mVelocity=" + mVelocity);
1476 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001477 if (sRollo != null) {
1478 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001479 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001480 if (sRS != null) {
1481 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001482 }
1483 }
1484}