blob: e975fa11d50a96844f884ec6d73d414293695c6a [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) {
696 if (mLocks != 0 || !isVisible()) {
697 return true;
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 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800702
Daniel Sandler388f6792010-03-02 14:08:08 -0500703 Bitmap bmp = app.iconBitmap;
704 final int w = bmp.getWidth();
705 final int h = bmp.getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800706
Daniel Sandler388f6792010-03-02 14:08:08 -0500707 // We don't really have an accurate location to use. This will do.
708 int screenX = mMotionDownRawX - (w / 2);
709 int screenY = mMotionDownRawY - h;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800710
Daniel Sandler388f6792010-03-02 14:08:08 -0500711 mDragController.startDrag(bmp, screenX, screenY,
712 0, 0, w, h, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800713
Daniel Sandler388f6792010-03-02 14:08:08 -0500714 mLauncher.closeAllApps(true);
715 }
716 return true;
717 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800718
Daniel Sandler388f6792010-03-02 14:08:08 -0500719 @Override
720 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
721 if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
722 if (!isVisible()) {
723 return false;
724 }
725 String text = null;
726 int index;
727 int count = mAllAppsList.size() + 1; // +1 is home
728 int pos = -1;
729 switch (mLastSelection) {
730 case SELECTION_ICONS:
Jason Sams14f67ed2010-05-11 14:02:43 -0700731 index = sRollo.mScript.get_gSelectedIconIndex();
Daniel Sandler388f6792010-03-02 14:08:08 -0500732 if (index >= 0) {
733 ApplicationInfo info = mAllAppsList.get(index);
734 if (info.title != null) {
735 text = info.title.toString();
736 pos = index;
737 }
738 }
739 break;
740 case SELECTION_HOME:
741 text = getContext().getString(R.string.all_apps_home_button_label);
742 pos = count;
743 break;
744 }
745 if (text != null) {
746 event.setEnabled(true);
747 event.getText().add(text);
748 //event.setContentDescription(text);
749 event.setItemCount(count);
750 event.setCurrentItemIndex(pos);
751 }
752 }
753 return false;
754 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800755
Daniel Sandler388f6792010-03-02 14:08:08 -0500756 public void setDragController(DragController dragger) {
757 mDragController = dragger;
758 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800759
Daniel Sandler388f6792010-03-02 14:08:08 -0500760 public void onDropCompleted(View target, boolean success) {
761 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800762
Daniel Sandler388f6792010-03-02 14:08:08 -0500763 /**
764 * Zoom to the specifed level.
765 *
766 * @param zoom [0..1] 0 is hidden, 1 is open
767 */
768 public void zoom(float zoom, boolean animate) {
769 cancelLongPress();
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700770 sNextZoom = zoom;
771 sAnimateNextZoom = animate;
Daniel Sandler388f6792010-03-02 14:08:08 -0500772 // if we do setZoom while we don't have a surface, we won't
773 // get the callbacks that actually set mZoom.
Joe Onorato2cc62e82010-03-17 20:23:53 -0700774 if (sRollo == null || !mHaveSurface) {
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700775 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500776 mZoom = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500777 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700778 sRollo.setZoom(zoom, animate);
Daniel Sandler388f6792010-03-02 14:08:08 -0500779 }
780 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800781
Joe Onorato878f0862010-03-22 12:22:22 -0400782 /**
783 * If sRollo is null, then we're not visible. This is also used to guard against
784 * sRollo being null.
785 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500786 public boolean isVisible() {
Joe Onorato878f0862010-03-22 12:22:22 -0400787 return sRollo != null && mZoom > 0.001f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500788 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800789
Patrick Dubroyff5f0402010-07-26 15:23:26 -0700790 public boolean isAnimating() {
791 return isVisible() && mZoom <= 0.999f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500792 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800793
Daniel Sandler388f6792010-03-02 14:08:08 -0500794 public void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700795 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500796 // We've been removed from the window. Don't bother with all this.
797 return;
798 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800799
Daniel Sandler707b0f72010-04-15 16:41:31 -0400800 if (list != null) {
801 Collections.sort(list, LauncherModel.APP_NAME_COMPARATOR);
802 }
803
Romain Guy13c2e7b2010-03-10 19:45:00 -0800804 boolean reload = false;
805 if (mAllAppsList == null) {
806 reload = true;
807 } else if (list.size() != mAllAppsList.size()) {
808 reload = true;
809 } else {
810 final int count = list.size();
811 for (int i = 0; i < count; i++) {
812 if (list.get(i) != mAllAppsList.get(i)) {
813 reload = true;
814 break;
815 }
816 }
817 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800818
Daniel Sandler388f6792010-03-02 14:08:08 -0500819 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700820 if (sRollo != null && reload) {
821 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500822 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700823
Romain Guyc16fea72010-03-12 17:17:56 -0800824 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700825 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
Romain Guyc16fea72010-03-12 17:17:56 -0800826 mRestoreFocusIndex = -1;
827 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700828
Daniel Sandler388f6792010-03-02 14:08:08 -0500829 mLocks &= ~LOCK_ICONS_PENDING;
830 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800831
Daniel Sandler388f6792010-03-02 14:08:08 -0500832 public void addApps(ArrayList<ApplicationInfo> list) {
833 if (mAllAppsList == null) {
834 // Not done loading yet. We'll find out about it later.
835 return;
836 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700837 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500838 // We've been removed from the window. Don't bother with all this.
839 return;
840 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800841
Daniel Sandler388f6792010-03-02 14:08:08 -0500842 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700843 if (sRollo != null) {
844 sRollo.pause();
Jason Sams14f67ed2010-05-11 14:02:43 -0700845 sRollo.reallocAppsList(sRollo.mScript.get_gIconCount() + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500846 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800847
Daniel Sandler388f6792010-03-02 14:08:08 -0500848 for (int i=0; i<N; i++) {
849 final ApplicationInfo item = list.get(i);
850 int index = Collections.binarySearch(mAllAppsList, item,
851 LauncherModel.APP_NAME_COMPARATOR);
852 if (index < 0) {
853 index = -(index+1);
854 }
855 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700856 if (sRollo != null) {
857 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500858 }
859 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800860
Joe Onorato2cc62e82010-03-17 20:23:53 -0700861 if (sRollo != null) {
862 sRollo.saveAppsList();
863 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500864 }
865 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800866
Daniel Sandler388f6792010-03-02 14:08:08 -0500867 public void removeApps(ArrayList<ApplicationInfo> list) {
868 if (mAllAppsList == null) {
869 // Not done loading yet. We'll find out about it later.
870 return;
871 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800872
Joe Onorato2cc62e82010-03-17 20:23:53 -0700873 if (sRollo != null) {
874 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800875 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500876 final int N = list.size();
877 for (int i=0; i<N; i++) {
878 final ApplicationInfo item = list.get(i);
879 int index = findAppByComponent(mAllAppsList, item);
880 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500881 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700882 if (sRollo != null) {
883 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500884 }
885 } else {
886 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
887 // Try to recover. This should keep us from crashing for now.
888 }
889 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800890
Joe Onorato2cc62e82010-03-17 20:23:53 -0700891 if (sRollo != null) {
892 sRollo.saveAppsList();
893 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500894 }
895 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800896
Joe Onorato64e6be72010-03-05 15:05:52 -0500897 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500898 // Just remove and add, because they may need to be re-sorted.
899 removeApps(list);
900 addApps(list);
901 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800902
Daniel Sandler388f6792010-03-02 14:08:08 -0500903 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
904 ComponentName component = item.intent.getComponent();
905 final int N = list.size();
906 for (int i=0; i<N; i++) {
907 ApplicationInfo x = list.get(i);
908 if (x.intent.getComponent().equals(component)) {
909 return i;
910 }
911 }
912 return -1;
913 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800914
Daniel Sandler388f6792010-03-02 14:08:08 -0500915 class AAMessage extends RenderScript.RSMessage {
916 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700917 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500918 mVelocity = ((float)mData[1]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700919
920 boolean lastVisible = isVisible();
Daniel Sandler388f6792010-03-02 14:08:08 -0500921 mZoom = ((float)mData[2]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700922
923 final boolean visible = isVisible();
924 if (visible != lastVisible) {
925 post(new Runnable() {
926 public void run() {
927 if (visible) {
928 showSurface();
929 } else {
930 hideSurface();
931 }
932 }
933 });
934 }
935
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700936 sZoomDirty = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500937 }
938 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800939
Romain Guy13c2e7b2010-03-10 19:45:00 -0800940 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500941 // Allocations ======
942 private int mWidth;
943 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800944
Daniel Sandler388f6792010-03-02 14:08:08 -0500945 private Resources mRes;
Jason Sams1aa4ff02010-06-15 14:59:57 -0700946 ScriptC_Allapps mScript;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800947
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700948 private Mesh mMesh;
Daniel Sandler388f6792010-03-02 14:08:08 -0500949 private ProgramVertex.MatrixAllocation mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800950
Jason Sams14f67ed2010-05-11 14:02:43 -0700951 private ScriptField_VpConsts mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800952
Daniel Sandler388f6792010-03-02 14:08:08 -0500953 private Allocation mHomeButtonNormal;
954 private Allocation mHomeButtonFocused;
955 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800956
Daniel Sandler388f6792010-03-02 14:08:08 -0500957 private Allocation[] mIcons;
958 private int[] mIconIds;
959 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800960
Daniel Sandler388f6792010-03-02 14:08:08 -0500961 private Allocation[] mLabels;
962 private int[] mLabelIds;
963 private Allocation mAllocLabelIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800964
Daniel Sandler388f6792010-03-02 14:08:08 -0500965 private Bitmap mSelectionBitmap;
966 private Canvas mSelectionCanvas;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800967
Jason Sams14f67ed2010-05-11 14:02:43 -0700968 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800969
Romain Guy13c2e7b2010-03-10 19:45:00 -0800970 AllApps3D mAllApps;
971 boolean mInitialize;
972
Daniel Sandler388f6792010-03-02 14:08:08 -0500973 class BaseAlloc {
974 Allocation mAlloc;
975 Type mType;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800976
Daniel Sandler388f6792010-03-02 14:08:08 -0500977 void save() {
978 mAlloc.data(this);
979 }
980 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800981
Daniel Sandler388f6792010-03-02 14:08:08 -0500982 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -0800983 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -0800984 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -0500985 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800986
987 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400988 if (sRS != null) {
989 sRS.contextBindRootScript(null);
990 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800991 }
992
993 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400994 if (sRS != null) {
995 sRS.contextBindRootScript(mScript);
996 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800997 }
998
Romain Guy13c2e7b2010-03-10 19:45:00 -0800999 public RolloRS(AllApps3D allApps) {
1000 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -05001001 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001002
Daniel Sandler388f6792010-03-02 14:08:08 -05001003 public void init(Resources res, int width, int height) {
1004 mRes = res;
1005 mWidth = width;
1006 mHeight = height;
Shih-wei Liaoafb81d42010-07-19 16:20:03 -07001007 mScript = new ScriptC_Allapps(sRS, mRes, R.raw.allapps, true);
Jason Sams14f67ed2010-05-11 14:02:43 -07001008
Daniel Sandler388f6792010-03-02 14:08:08 -05001009 initProgramVertex();
1010 initProgramFragment();
1011 initProgramStore();
1012 initGl();
1013 initData();
Jason Sams14f67ed2010-05-11 14:02:43 -07001014
1015 mScript.bind_gIconIDs(mAllocIconIds);
1016 mScript.bind_gLabelIDs(mAllocLabelIds);
Jason Sams14f67ed2010-05-11 14:02:43 -07001017 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -05001018 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001019
Daniel Sandler388f6792010-03-02 14:08:08 -05001020 public void initMesh() {
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001021 Mesh.TriangleMeshBuilder tm = new Mesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001022
Daniel Sandler388f6792010-03-02 14:08:08 -05001023 for (int ct=0; ct < 16; ct++) {
1024 float pos = (1.f / (16.f - 1)) * ct;
1025 tm.addVertex(0.0f, pos);
1026 tm.addVertex(1.0f, pos);
1027 }
1028 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1029 tm.addTriangle(ct, ct+1, ct+2);
1030 tm.addTriangle(ct+1, ct+3, ct+2);
1031 }
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001032 mMesh = tm.create(true);
Jason Sams14f67ed2010-05-11 14:02:43 -07001033 mScript.set_gSMCell(mMesh);
Daniel Sandler388f6792010-03-02 14:08:08 -05001034 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001035
Daniel Sandler388f6792010-03-02 14:08:08 -05001036 void resize(int w, int h) {
1037 mPVA.setupProjectionNormalized(w, h);
1038 mWidth = w;
1039 mHeight = h;
1040 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001041
Daniel Sandler388f6792010-03-02 14:08:08 -05001042 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001043 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001044 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001045
Joe Onorato2cc62e82010-03-17 20:23:53 -07001046 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001047 pvb.setTextureMatrixEnable(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001048 ProgramVertex pv = pvb.create();
1049 pv.bindAllocation(mPVA);
1050 sRS.contextBindProgramVertex(pv);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001051
Jason Sams14f67ed2010-05-11 14:02:43 -07001052 mUniformAlloc = new ScriptField_VpConsts(sRS, 1);
1053 mScript.bind_vpConstants(mUniformAlloc);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001054
Daniel Sandler388f6792010-03-02 14:08:08 -05001055 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001056 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Romain Guy060b5c82010-03-04 10:07:38 -08001057 String t = "void main() {\n" +
1058 // Animation
1059 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001060
Romain Guy060b5c82010-03-04 10:07:38 -08001061 " float bendY1 = UNI_BendPos.x;\n" +
1062 " float bendY2 = UNI_BendPos.y;\n" +
1063 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1064 " float bendDistance = bendY1 * 0.4;\n" +
1065 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001066
Romain Guy060b5c82010-03-04 10:07:38 -08001067 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1068 " float aDy = cos(bendAngle);\n" +
1069 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001070
Romain Guy060b5c82010-03-04 10:07:38 -08001071 " float scale = (2.0 / 480.0);\n" +
1072 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1073 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1074 " float y = 0.0;\n" +
1075 " float z = 0.0;\n" +
1076 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001077
Romain Guy060b5c82010-03-04 10:07:38 -08001078 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1079 " y += cv * aDy;\n" +
1080 " z += -cv * aDz;\n" +
1081 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1082 " lum += cv / bendDistance * distanceDimLevel;\n" +
1083 " y += cv * cos(cv * bendStep);\n" +
1084 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001085
Romain Guy060b5c82010-03-04 10:07:38 -08001086 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1087 " y += cv * aDy;\n" +
1088 " z += cv * aDz;\n" +
1089 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1090 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1091 " y += cv * cos(cv * bendStep);\n" +
1092 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001093
Romain Guy060b5c82010-03-04 10:07:38 -08001094 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001095
Romain Guy060b5c82010-03-04 10:07:38 -08001096 " vec4 pos;\n" +
1097 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1098 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1099 " pos.z = z * UNI_ScaleOffset.x;\n" +
1100 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001101
Romain Guy060b5c82010-03-04 10:07:38 -08001102 " pos.x *= 1.0 + ani * 4.0;\n" +
1103 " pos.y *= 1.0 + ani * 4.0;\n" +
1104 " pos.z -= ani * 1.5;\n" +
1105 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001106
Romain Guy060b5c82010-03-04 10:07:38 -08001107 " gl_Position = UNI_MVP * pos;\n" +
1108 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1109 " varTex0.xy = ATTRIB_position;\n" +
1110 " varTex0.y = 1.0 - varTex0.y;\n" +
1111 " varTex0.zw = vec2(0.0, 0.0);\n" +
1112 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001113 sb.setShader(t);
1114 sb.addConstant(mUniformAlloc.getType());
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -07001115 sb.addInput(mMesh.getVertexAllocation(0).getType().getElement());
Jason Sams60a55bb2010-06-18 15:11:19 -07001116 ProgramVertex pvc = sb.create();
1117 pvc.bindAllocation(mPVA);
1118 pvc.bindConstants(mUniformAlloc.getAllocation(), 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001119
Jason Sams60a55bb2010-06-18 15:11:19 -07001120 mScript.set_gPVCurve(pvc);
Daniel Sandler388f6792010-03-02 14:08:08 -05001121 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001122
Daniel Sandler388f6792010-03-02 14:08:08 -05001123 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001124 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001125 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1126 sb.setMag(Sampler.Value.NEAREST);
1127 sb.setWrapS(Sampler.Value.CLAMP);
1128 sb.setWrapT(Sampler.Value.CLAMP);
1129 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001130
Daniel Sandler388f6792010-03-02 14:08:08 -05001131 sb.setMin(Sampler.Value.NEAREST);
1132 sb.setMag(Sampler.Value.NEAREST);
1133 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001134
Joe Onorato2cc62e82010-03-17 20:23:53 -07001135 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001136 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1137 ProgramFragment.Builder.Format.RGBA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001138 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001139 ProgramFragment pfTexMip = bf.create();
1140 pfTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001141
Jason Sams070ada82010-08-04 17:53:07 -07001142 bf.setVaryingColor(false);
Jason Sams60a55bb2010-06-18 15:11:19 -07001143 ProgramFragment pfTexNearest = bf.create();
1144 pfTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001145
Daniel Sandler388f6792010-03-02 14:08:08 -05001146 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1147 ProgramFragment.Builder.Format.ALPHA, 0);
Jason Sams070ada82010-08-04 17:53:07 -07001148 bf.setVaryingColor(true);
Jason Sams60a55bb2010-06-18 15:11:19 -07001149 ProgramFragment pfTexMipAlpha = bf.create();
1150 pfTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001151
Jason Sams60a55bb2010-06-18 15:11:19 -07001152 mScript.set_gPFTexNearest(pfTexNearest);
1153 mScript.set_gPFTexMip(pfTexMip);
1154 mScript.set_gPFTexMipAlpha(pfTexMipAlpha);
Daniel Sandler388f6792010-03-02 14:08:08 -05001155 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001156
Daniel Sandler388f6792010-03-02 14:08:08 -05001157 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001158 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001159 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1160 bs.setColorMask(true,true,true,false);
1161 bs.setDitherEnable(true);
1162 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1163 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Jason Sams14f67ed2010-05-11 14:02:43 -07001164 mScript.set_gPS(bs.create());
Daniel Sandler388f6792010-03-02 14:08:08 -05001165 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001166
Daniel Sandler388f6792010-03-02 14:08:08 -05001167 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001168 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001169
Daniel Sandler388f6792010-03-02 14:08:08 -05001170 private void initData() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001171 mScript.set_COLUMNS_PER_PAGE_PORTRAIT(Defines.COLUMNS_PER_PAGE_PORTRAIT);
1172 mScript.set_ROWS_PER_PAGE_PORTRAIT(Defines.ROWS_PER_PAGE_PORTRAIT);
1173 mScript.set_COLUMNS_PER_PAGE_LANDSCAPE(Defines.COLUMNS_PER_PAGE_LANDSCAPE);
1174 mScript.set_ROWS_PER_PAGE_LANDSCAPE(Defines.ROWS_PER_PAGE_LANDSCAPE);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001175
Joe Onorato2cc62e82010-03-17 20:23:53 -07001176 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1177 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001178 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001179 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1180 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001181 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001182 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1183 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001184 mHomeButtonPressed.uploadToTexture(0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001185
Jason Sams14f67ed2010-05-11 14:02:43 -07001186 mScript.set_gHomeButton(mHomeButtonNormal);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001187
Daniel Sandler388f6792010-03-02 14:08:08 -05001188 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1189 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1190 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001191
Daniel Sandler388f6792010-03-02 14:08:08 -05001192 setApps(null);
1193 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001194
Daniel Sandler388f6792010-03-02 14:08:08 -05001195 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001196 if (sZoomDirty) {
1197 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001198 }
1199 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001200
Romain Guy060b5c82010-03-04 10:07:38 -08001201 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001202 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001203 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001204 final int count = list != null ? list.size() : 0;
1205 int allocCount = count;
1206 if (allocCount < 1) {
1207 allocCount = 1;
1208 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001209
Daniel Sandler388f6792010-03-02 14:08:08 -05001210 mIcons = new Allocation[count];
1211 mIconIds = new int[allocCount];
Jason Sams98994c42010-06-01 15:54:10 -07001212 mAllocIconIds = Allocation.createSized(sRS, Element.I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001213
Daniel Sandler388f6792010-03-02 14:08:08 -05001214 mLabels = new Allocation[count];
1215 mLabelIds = new int[allocCount];
Jason Sams98994c42010-06-01 15:54:10 -07001216 mAllocLabelIds = Allocation.createSized(sRS, Element.I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001217
Jason Sams14f67ed2010-05-11 14:02:43 -07001218 mScript.set_gIconCount(count);
1219 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001220 createAppIconAllocations(i, list.get(i));
1221 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001222 for (int i=0; i < count; i++) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001223 uploadAppIcon(i, list.get(i));
1224 }
1225 saveAppsList();
Jason Sams14f67ed2010-05-11 14:02:43 -07001226 android.util.Log.e("rs", "setApps");
Joe Onorato2cc62e82010-03-17 20:23:53 -07001227 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001228 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001229
Daniel Sandler388f6792010-03-02 14:08:08 -05001230 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001231 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001232 sRollo.clearSelectedIcon();
1233 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001234 }
Jason Sams60a55bb2010-06-18 15:11:19 -07001235 sRollo.mScript.invoke_setZoom(zoom, animate ? 1 : 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001236 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001237
Daniel Sandler388f6792010-03-02 14:08:08 -05001238 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001239 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1240 Element.RGBA_8888(sRS), false);
1241 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1242 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001243 mIconIds[index] = mIcons[index].getID();
1244 mLabelIds[index] = mLabels[index].getID();
1245 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001246
Daniel Sandler388f6792010-03-02 14:08:08 -05001247 private void uploadAppIcon(int index, ApplicationInfo item) {
1248 if (mIconIds[index] != mIcons[index].getID()) {
1249 throw new IllegalStateException("uploadAppIcon index=" + index
1250 + " mIcons[index].getID=" + mIcons[index].getID()
1251 + " mIconsIds[index]=" + mIconIds[index]
1252 + " item=" + item);
1253 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001254 mIcons[index].uploadToTexture(true, 0);
1255 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001256 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001257
Daniel Sandler388f6792010-03-02 14:08:08 -05001258 /**
1259 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1260 * fill in the values and call saveAppsList().
1261 */
1262 private void reallocAppsList(int count) {
1263 Allocation[] icons = new Allocation[count];
1264 int[] iconIds = new int[count];
Jason Sams98994c42010-06-01 15:54:10 -07001265 mAllocIconIds = Allocation.createSized(sRS, Element.I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001266
Daniel Sandler388f6792010-03-02 14:08:08 -05001267 Allocation[] labels = new Allocation[count];
1268 int[] labelIds = new int[count];
Jason Sams98994c42010-06-01 15:54:10 -07001269 mAllocLabelIds = Allocation.createSized(sRS, Element.I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001270
Jason Sams14f67ed2010-05-11 14:02:43 -07001271 final int oldCount = sRollo.mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001272
Daniel Sandler388f6792010-03-02 14:08:08 -05001273 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1274 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1275 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1276 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001277
Daniel Sandler388f6792010-03-02 14:08:08 -05001278 mIcons = icons;
1279 mIconIds = iconIds;
1280 mLabels = labels;
1281 mLabelIds = labelIds;
1282 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001283
Daniel Sandler388f6792010-03-02 14:08:08 -05001284 /**
1285 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1286 */
1287 private void addApp(int index, ApplicationInfo item) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001288 final int count = mScript.get_gIconCount() - index;
Daniel Sandler388f6792010-03-02 14:08:08 -05001289 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001290
Daniel Sandler388f6792010-03-02 14:08:08 -05001291 System.arraycopy(mIcons, index, mIcons, dest, count);
1292 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1293 System.arraycopy(mLabels, index, mLabels, dest, count);
1294 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001295
Daniel Sandler388f6792010-03-02 14:08:08 -05001296 createAppIconAllocations(index, item);
1297 uploadAppIcon(index, item);
Jason Sams14f67ed2010-05-11 14:02:43 -07001298
1299 mScript.set_gIconCount(mScript.get_gIconCount() + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001300 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001301
Daniel Sandler388f6792010-03-02 14:08:08 -05001302 /**
1303 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1304 */
1305 private void removeApp(int index) {
Jason Sams14f67ed2010-05-11 14:02:43 -07001306 final int count = mScript.get_gIconCount() - index - 1;
Daniel Sandler388f6792010-03-02 14:08:08 -05001307 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001308
Daniel Sandler388f6792010-03-02 14:08:08 -05001309 System.arraycopy(mIcons, src, mIcons, index, count);
1310 System.arraycopy(mIconIds, src, mIconIds, index, count);
1311 System.arraycopy(mLabels, src, mLabels, index, count);
1312 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001313
Jason Sams14f67ed2010-05-11 14:02:43 -07001314 mScript.set_gIconCount(mScript.get_gIconCount() - 1);
1315 final int last = mScript.get_gIconCount();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001316
Daniel Sandler388f6792010-03-02 14:08:08 -05001317 mIcons[last] = null;
1318 mIconIds[last] = 0;
1319 mLabels[last] = null;
1320 mLabelIds[last] = 0;
1321 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001322
Daniel Sandler388f6792010-03-02 14:08:08 -05001323 /**
1324 * Send the apps list structures to RS.
1325 */
1326 private void saveAppsList() {
1327 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1328 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001329 mAllocIconIds.data(mIconIds);
1330 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001331
Jason Sams14f67ed2010-05-11 14:02:43 -07001332 mScript.bind_gIconIDs(mAllocIconIds);
1333 mScript.bind_gLabelIDs(mAllocLabelIds);
Daniel Sandler388f6792010-03-02 14:08:08 -05001334 }
1335 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001336
Jason Sams60a55bb2010-06-18 15:11:19 -07001337 void fling(float pos, float v) {
1338 mScript.invoke_fling(pos, v);
Daniel Sandler388f6792010-03-02 14:08:08 -05001339 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001340
Jason Sams60a55bb2010-06-18 15:11:19 -07001341 void move(float pos) {
1342 mScript.invoke_move(pos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001343 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001344
Daniel Sandler388f6792010-03-02 14:08:08 -05001345 void moveTo(float row) {
Jason Sams60a55bb2010-06-18 15:11:19 -07001346 mScript.invoke_moveTo(row);
Daniel Sandler388f6792010-03-02 14:08:08 -05001347 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001348
Daniel Sandler388f6792010-03-02 14:08:08 -05001349 /**
1350 * You need to call save() on mState on your own after calling this.
1351 *
1352 * @return the index of the icon that was selected.
1353 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001354 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001355 if (mAllApps != null) {
1356 final int index = mAllApps.chooseTappedIcon(x, y);
1357 selectIcon(index, pressed);
1358 return index;
1359 } else {
1360 return -1;
1361 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001362 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001363
Daniel Sandler388f6792010-03-02 14:08:08 -05001364 /**
1365 * Select the icon at the given index.
1366 *
1367 * @param index The index.
1368 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1369 */
1370 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001371 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1372 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001373 if (mAllApps != null) {
1374 mAllApps.mRestoreFocusIndex = index;
1375 }
Jason Sams14f67ed2010-05-11 14:02:43 -07001376 mScript.set_gSelectedIconIndex(-1);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001377 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1378 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001379 }
1380 } else {
1381 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001382 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001383 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001384
Jason Sams14f67ed2010-05-11 14:02:43 -07001385 int prev = mScript.get_gSelectedIconIndex();
1386 mScript.set_gSelectedIconIndex(index);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001387
Romain Guy13c2e7b2010-03-10 19:45:00 -08001388 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001389 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001390
Daniel Sandler388f6792010-03-02 14:08:08 -05001391 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1392 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1393 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001394
Jason Sams60a55bb2010-06-18 15:11:19 -07001395 Allocation si = Allocation.createFromBitmap(sRS, selectionBitmap,
Joe Onorato2cc62e82010-03-17 20:23:53 -07001396 Element.RGBA_8888(sRS), false);
Jason Sams60a55bb2010-06-18 15:11:19 -07001397 si.uploadToTexture(0);
1398 mScript.set_gSelectedIconTexture(si);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001399
Daniel Sandler388f6792010-03-02 14:08:08 -05001400 if (prev != index) {
1401 if (info.title != null && info.title.length() > 0) {
1402 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001403 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001404 }
1405 }
1406 }
1407 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001408
Daniel Sandler388f6792010-03-02 14:08:08 -05001409 /**
1410 * You need to call save() on mState on your own after calling this.
1411 */
1412 void clearSelectedIcon() {
Jason Sams14f67ed2010-05-11 14:02:43 -07001413 mScript.set_gSelectedIconIndex(-1);
Daniel Sandler388f6792010-03-02 14:08:08 -05001414 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001415
Daniel Sandler388f6792010-03-02 14:08:08 -05001416 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001417 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001418 switch (mode) {
1419 case SELECTED_NONE:
Jason Sams14f67ed2010-05-11 14:02:43 -07001420 mScript.set_gHomeButton(mHomeButtonNormal);
Daniel Sandler388f6792010-03-02 14:08:08 -05001421 break;
1422 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001423 mAllApps.mLastSelection = SELECTION_HOME;
Jason Sams14f67ed2010-05-11 14:02:43 -07001424 mScript.set_gHomeButton(mHomeButtonFocused);
Daniel Sandler388f6792010-03-02 14:08:08 -05001425 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001426 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001427 }
1428 break;
1429 case SELECTED_PRESSED:
Jason Sams14f67ed2010-05-11 14:02:43 -07001430 mScript.set_gHomeButton(mHomeButtonPressed);
Daniel Sandler388f6792010-03-02 14:08:08 -05001431 break;
1432 }
1433 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001434
Daniel Sandler388f6792010-03-02 14:08:08 -05001435 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001436 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1437 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1438 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001439 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001440 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001441 }
1442 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001443 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001444 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001445 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001446 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001447 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001448 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001449 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Jason Sams14f67ed2010-05-11 14:02:43 -07001450 //Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1451 //Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1452 //Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1453 //Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1454 //Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1455 //Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1456 //Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1457 //Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1458 //Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001459 }
1460 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001461
Daniel Sandler388f6792010-03-02 14:08:08 -05001462 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001463 Log.d(TAG, "sRS=" + sRS);
1464 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001465 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001466 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1467 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001468 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1469 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1470 Log.d(TAG, "mLastSelection=" + mLastSelection);
1471 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1472 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1473 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1474 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001475 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1476 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001477 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001478 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001479 Log.d(TAG, "mVelocity=" + mVelocity);
1480 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001481 if (sRollo != null) {
1482 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001483 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001484 if (sRS != null) {
1485 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001486 }
1487 }
1488}