blob: 35e4cfc52c6953f42f33da38dd3fa9bfd9a0fe65 [file] [log] [blame]
Daniel Sandler388f6792010-03-02 14:08:08 -05001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher2;
18
19import android.content.ComponentName;
20import android.content.Context;
21import android.content.res.Resources;
22import android.graphics.Bitmap;
23import android.graphics.Canvas;
24import android.graphics.PixelFormat;
25import android.graphics.Rect;
Daniel Sandler388f6792010-03-02 14:08:08 -050026import android.renderscript.Allocation;
Daniel Sandler388f6792010-03-02 14:08:08 -050027import android.renderscript.Element;
28import android.renderscript.ProgramFragment;
29import android.renderscript.ProgramStore;
30import android.renderscript.ProgramVertex;
31import android.renderscript.RSSurfaceView;
32import android.renderscript.RenderScriptGL;
33import android.renderscript.RenderScript;
34import android.renderscript.Sampler;
35import android.renderscript.Script;
36import android.renderscript.ScriptC;
37import android.renderscript.SimpleMesh;
38import android.renderscript.Type;
39import android.util.AttributeSet;
Romain Guy060b5c82010-03-04 10:07:38 -080040import android.util.DisplayMetrics;
Daniel Sandler388f6792010-03-02 14:08:08 -050041import android.util.Log;
42import android.view.KeyEvent;
43import android.view.MotionEvent;
44import android.view.SoundEffectConstants;
45import android.view.SurfaceHolder;
46import android.view.VelocityTracker;
47import android.view.View;
48import android.view.ViewConfiguration;
49import android.view.accessibility.AccessibilityEvent;
50
51import java.util.ArrayList;
52import java.util.Arrays;
53import java.util.Collections;
Daniel Sandler388f6792010-03-02 14:08:08 -050054
Romain Guyedcce092010-03-04 13:03:17 -080055import com.android.launcher.R;
56
Daniel Sandler388f6792010-03-02 14:08:08 -050057public class AllApps3D extends RSSurfaceView
58 implements AllAppsView, View.OnClickListener, View.OnLongClickListener, DragSource {
59 private static final String TAG = "Launcher.AllApps3D";
60
61 /** Bit for mLocks for when there are icons being loaded. */
62 private static final int LOCK_ICONS_PENDING = 1;
63
64 private static final int TRACKING_NONE = 0;
65 private static final int TRACKING_FLING = 1;
66 private static final int TRACKING_HOME = 2;
67
68 private static final int SELECTED_NONE = 0;
69 private static final int SELECTED_FOCUSED = 1;
70 private static final int SELECTED_PRESSED = 2;
71
72 private static final int SELECTION_NONE = 0;
73 private static final int SELECTION_ICONS = 1;
74 private static final int SELECTION_HOME = 2;
75
76 private Launcher mLauncher;
77 private DragController mDragController;
78
79 /** When this is 0, modifications are allowed, when it's not, they're not.
80 * TODO: What about scrolling? */
81 private int mLocks = LOCK_ICONS_PENDING;
82
83 private int mSlop;
84 private int mMaxFlingVelocity;
85
86 private Defines mDefines = new Defines();
Daniel Sandler388f6792010-03-02 14:08:08 -050087 private ArrayList<ApplicationInfo> mAllAppsList;
88
Joe Onorato2cc62e82010-03-17 20:23:53 -070089 private static RenderScriptGL sRS;
90 private static RolloRS sRollo;
Jason Samsdd8cd8b2010-03-11 12:38:48 -080091
Daniel Sandler388f6792010-03-02 14:08:08 -050092 /**
93 * True when we are using arrow keys or trackball to drive navigation
94 */
95 private boolean mArrowNavigation = false;
96 private boolean mStartedScrolling;
97
98 /**
99 * Used to keep track of the selection when AllAppsView loses window focus.
100 * One of the SELECTION_ constants.
101 */
102 private int mLastSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800103
Daniel Sandler388f6792010-03-02 14:08:08 -0500104 /**
105 * Used to keep track of the selection when AllAppsView loses window focus
106 */
107 private int mLastSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800108
Daniel Sandler388f6792010-03-02 14:08:08 -0500109 private VelocityTracker mVelocityTracker;
110 private int mTouchTracking;
111 private int mMotionDownRawX;
112 private int mMotionDownRawY;
113 private int mDownIconIndex = -1;
114 private int mCurrentIconIndex = -1;
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700115 private int[] mTouchYBorders;
116 private int[] mTouchXBorders;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800117
Daniel Sandler388f6792010-03-02 14:08:08 -0500118 private boolean mShouldGainFocus;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800119
Daniel Sandler388f6792010-03-02 14:08:08 -0500120 private boolean mHaveSurface = false;
121 private boolean mZoomDirty = false;
122 private boolean mAnimateNextZoom;
123 private float mNextZoom;
124 private float mZoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500125 private float mVelocity;
126 private AAMessage mMessageProc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800127
Romain Guy060b5c82010-03-04 10:07:38 -0800128 private int mColumnsPerPage;
129 private int mRowsPerPage;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800130 private boolean mSurrendered;
131
Romain Guyc16fea72010-03-12 17:17:56 -0800132 private int mRestoreFocusIndex = -1;
133
Romain Guy060b5c82010-03-04 10:07:38 -0800134 @SuppressWarnings({"UnusedDeclaration"})
Daniel Sandler388f6792010-03-02 14:08:08 -0500135 static class Defines {
136 public static final int ALLOC_PARAMS = 0;
137 public static final int ALLOC_STATE = 1;
138 public static final int ALLOC_ICON_IDS = 3;
139 public static final int ALLOC_LABEL_IDS = 4;
140 public static final int ALLOC_VP_CONSTANTS = 5;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800141
Romain Guy060b5c82010-03-04 10:07:38 -0800142 public static final int COLUMNS_PER_PAGE_PORTRAIT = 4;
143 public static final int ROWS_PER_PAGE_PORTRAIT = 4;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800144
Romain Guy060b5c82010-03-04 10:07:38 -0800145 public static final int COLUMNS_PER_PAGE_LANDSCAPE = 6;
146 public static final int ROWS_PER_PAGE_LANDSCAPE = 3;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800147
Daniel Sandler388f6792010-03-02 14:08:08 -0500148 public static final int ICON_WIDTH_PX = 64;
149 public static final int ICON_TEXTURE_WIDTH_PX = 74;
150 public static final int SELECTION_TEXTURE_WIDTH_PX = 74 + 20;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800151
Daniel Sandler388f6792010-03-02 14:08:08 -0500152 public static final int ICON_HEIGHT_PX = 64;
153 public static final int ICON_TEXTURE_HEIGHT_PX = 74;
154 public static final int SELECTION_TEXTURE_HEIGHT_PX = 74 + 20;
155 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800156
Daniel Sandler388f6792010-03-02 14:08:08 -0500157 public AllApps3D(Context context, AttributeSet attrs) {
158 super(context, attrs);
159 setFocusable(true);
160 setSoundEffectsEnabled(false);
161 getHolder().setFormat(PixelFormat.TRANSLUCENT);
162 final ViewConfiguration config = ViewConfiguration.get(context);
163 mSlop = config.getScaledTouchSlop();
164 mMaxFlingVelocity = config.getScaledMaximumFlingVelocity();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800165
Daniel Sandler388f6792010-03-02 14:08:08 -0500166 setOnClickListener(this);
167 setOnLongClickListener(this);
168 setZOrderOnTop(true);
169 getHolder().setFormat(PixelFormat.TRANSLUCENT);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800170
Joe Onorato2cc62e82010-03-17 20:23:53 -0700171 if (sRS == null) {
172 sRS = createRenderScript(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800173 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700174 createRenderScript(sRS);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800175 }
176
Romain Guy060b5c82010-03-04 10:07:38 -0800177 final DisplayMetrics metrics = getResources().getDisplayMetrics();
178 final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
179 mColumnsPerPage = isPortrait ? Defines.COLUMNS_PER_PAGE_PORTRAIT :
180 Defines.COLUMNS_PER_PAGE_LANDSCAPE;
181 mRowsPerPage = isPortrait ? Defines.ROWS_PER_PAGE_PORTRAIT :
182 Defines.ROWS_PER_PAGE_LANDSCAPE;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800183
Joe Onorato2cc62e82010-03-17 20:23:53 -0700184 if (sRollo != null) {
185 sRollo.mAllApps = this;
186 sRollo.mRes = getResources();
187 sRollo.mInitialize = true;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800188 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500189 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800190
Romain Guy060b5c82010-03-04 10:07:38 -0800191 @SuppressWarnings({"UnusedDeclaration"})
192 public AllApps3D(Context context, AttributeSet attrs, int defStyle) {
193 this(context, attrs);
194 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800195
Romain Guy13c2e7b2010-03-10 19:45:00 -0800196 public void surrender() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400197 if (sRS != null) {
198 sRS.contextSetSurface(0, 0, null);
199 sRS.mMessageCallback = null;
200 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800201 mSurrendered = true;
202 }
203
Daniel Sandler388f6792010-03-02 14:08:08 -0500204 /**
205 * Note that this implementation prohibits this view from ever being reattached.
206 */
207 @Override
208 protected void onDetachedFromWindow() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700209 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800210 if (!mSurrendered) {
Joe Onorato96da4012010-03-17 20:03:24 -0700211 Log.i(TAG, "onDetachedFromWindow");
Romain Guy13c2e7b2010-03-10 19:45:00 -0800212 destroyRenderScript();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700213 sRS = null;
214 sRollo = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800215 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500216 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800217
Daniel Sandler388f6792010-03-02 14:08:08 -0500218 /**
219 * If you have an attached click listener, View always plays the click sound!?!?
220 * Deal with sound effects by hand.
221 */
222 public void reallyPlaySoundEffect(int sound) {
223 boolean old = isSoundEffectsEnabled();
224 setSoundEffectsEnabled(true);
225 playSoundEffect(sound);
226 setSoundEffectsEnabled(old);
227 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800228
Daniel Sandler388f6792010-03-02 14:08:08 -0500229 public void setLauncher(Launcher launcher) {
230 mLauncher = launcher;
231 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800232
Daniel Sandler388f6792010-03-02 14:08:08 -0500233 @Override
234 public void surfaceDestroyed(SurfaceHolder holder) {
235 super.surfaceDestroyed(holder);
236 // Without this, we leak mMessageCallback which leaks the context.
Romain Guy13c2e7b2010-03-10 19:45:00 -0800237 if (!mSurrendered) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700238 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800239 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500240 // We may lose any callbacks that are pending, so make sure that we re-sync that
241 // on the next surfaceChanged.
242 mZoomDirty = true;
243 mHaveSurface = false;
244 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800245
Daniel Sandler388f6792010-03-02 14:08:08 -0500246 @Override
247 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
248 //long startTime = SystemClock.uptimeMillis();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800249
Daniel Sandler388f6792010-03-02 14:08:08 -0500250 super.surfaceChanged(holder, format, w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800251
Romain Guy13c2e7b2010-03-10 19:45:00 -0800252 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800253
Daniel Sandler388f6792010-03-02 14:08:08 -0500254 mHaveSurface = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800255
Joe Onorato2cc62e82010-03-17 20:23:53 -0700256 if (sRollo == null) {
257 sRollo = new RolloRS(this);
258 sRollo.init(getResources(), w, h);
Daniel Sandler388f6792010-03-02 14:08:08 -0500259 if (mAllAppsList != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700260 sRollo.setApps(mAllAppsList);
Daniel Sandler388f6792010-03-02 14:08:08 -0500261 }
262 if (mShouldGainFocus) {
263 gainFocus();
264 mShouldGainFocus = false;
265 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700266 } else if (sRollo.mInitialize) {
267 sRollo.initGl();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700268 sRollo.mInitialize = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500269 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800270
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700271 initTouchState(w, h);
272
Joe Onorato2cc62e82010-03-17 20:23:53 -0700273 sRollo.dirtyCheck();
274 sRollo.resize(w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800275
Joe Onorato2cc62e82010-03-17 20:23:53 -0700276 if (sRS != null) {
277 sRS.mMessageCallback = mMessageProc = new AAMessage();
Daniel Sandler388f6792010-03-02 14:08:08 -0500278 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800279
Joe Onorato2cc62e82010-03-17 20:23:53 -0700280 if (sRollo.mUniformAlloc != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500281 float tf[] = new float[] {72.f, 72.f,
282 120.f, 120.f, 0.f, 0.f,
283 120.f, 680.f,
284 (2.f / 480.f), 0, -((float)w / 2) - 0.25f, -380.25f};
285 if (w > h) {
286 tf[6] = 40.f;
287 tf[7] = h - 40.f;
288 tf[9] = 1.f;
289 tf[10] = -((float)w / 2) - 0.25f;
290 tf[11] = -((float)h / 2) - 0.25f;
291 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800292
Joe Onorato2cc62e82010-03-17 20:23:53 -0700293 sRollo.mUniformAlloc.data(tf);
Daniel Sandler388f6792010-03-02 14:08:08 -0500294 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800295
Daniel Sandler388f6792010-03-02 14:08:08 -0500296 //long endTime = SystemClock.uptimeMillis();
297 //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
298 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800299
Daniel Sandler388f6792010-03-02 14:08:08 -0500300 @Override
301 public void onWindowFocusChanged(boolean hasWindowFocus) {
302 super.onWindowFocusChanged(hasWindowFocus);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800303
304 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800305
Daniel Sandler388f6792010-03-02 14:08:08 -0500306 if (mArrowNavigation) {
307 if (!hasWindowFocus) {
308 // Clear selection when we lose window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700309 mLastSelectedIcon = sRollo.mState.selectedIconIndex;
310 sRollo.setHomeSelected(SELECTED_NONE);
311 sRollo.clearSelectedIcon();
312 sRollo.mState.save();
Romain Guy060b5c82010-03-04 10:07:38 -0800313 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700314 if (sRollo.mState.iconCount > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500315 if (mLastSelection == SELECTION_ICONS) {
316 int selection = mLastSelectedIcon;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700317 final int firstIcon = Math.round(sRollo.mScrollPos) * mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500318 if (selection < 0 || // No selection
319 selection < firstIcon || // off the top of the screen
Joe Onorato2cc62e82010-03-17 20:23:53 -0700320 selection >= sRollo.mState.iconCount || // past last icon
Daniel Sandler388f6792010-03-02 14:08:08 -0500321 selection >= firstIcon + // past last icon on screen
Romain Guy060b5c82010-03-04 10:07:38 -0800322 (mColumnsPerPage * mRowsPerPage)) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500323 selection = firstIcon;
324 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800325
Daniel Sandler388f6792010-03-02 14:08:08 -0500326 // Select the first icon when we gain window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700327 sRollo.selectIcon(selection, SELECTED_FOCUSED);
328 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500329 } else if (mLastSelection == SELECTION_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700330 sRollo.setHomeSelected(SELECTED_FOCUSED);
331 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500332 }
333 }
334 }
335 }
336 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800337
Daniel Sandler388f6792010-03-02 14:08:08 -0500338 @Override
339 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
340 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800341
Romain Guy13c2e7b2010-03-10 19:45:00 -0800342 if (!isVisible() || mSurrendered) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500343 return;
344 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800345
Daniel Sandler388f6792010-03-02 14:08:08 -0500346 if (gainFocus) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700347 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500348 gainFocus();
349 } else {
350 mShouldGainFocus = true;
351 }
352 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700353 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500354 if (mArrowNavigation) {
355 // Clear selection when we lose focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700356 sRollo.clearSelectedIcon();
357 sRollo.setHomeSelected(SELECTED_NONE);
358 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500359 mArrowNavigation = false;
360 }
361 } else {
362 mShouldGainFocus = false;
363 }
364 }
365 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800366
Daniel Sandler388f6792010-03-02 14:08:08 -0500367 private void gainFocus() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700368 if (!mArrowNavigation && sRollo.mState.iconCount > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500369 // Select the first icon when we gain keyboard focus
370 mArrowNavigation = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700371 sRollo.selectIcon(Math.round(sRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED);
372 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500373 }
374 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800375
Daniel Sandler388f6792010-03-02 14:08:08 -0500376 @Override
377 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800378
Daniel Sandler388f6792010-03-02 14:08:08 -0500379 boolean handled = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800380
Daniel Sandler388f6792010-03-02 14:08:08 -0500381 if (!isVisible()) {
382 return false;
383 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700384 final int iconCount = sRollo.mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800385
Daniel Sandler388f6792010-03-02 14:08:08 -0500386 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
387 if (mArrowNavigation) {
388 if (mLastSelection == SELECTION_HOME) {
389 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
390 mLauncher.closeAllApps(true);
391 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700392 int whichApp = sRollo.mState.selectedIconIndex;
Daniel Sandler388f6792010-03-02 14:08:08 -0500393 if (whichApp >= 0) {
394 ApplicationInfo app = mAllAppsList.get(whichApp);
Joe Onoratof984e852010-03-25 09:47:45 -0700395 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500396 handled = true;
397 }
398 }
399 }
400 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800401
Daniel Sandler388f6792010-03-02 14:08:08 -0500402 if (iconCount > 0) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800403 final boolean isPortrait = getWidth() < getHeight();
404
Daniel Sandler388f6792010-03-02 14:08:08 -0500405 mArrowNavigation = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800406
Joe Onorato2cc62e82010-03-17 20:23:53 -0700407 int currentSelection = sRollo.mState.selectedIconIndex;
408 int currentTopRow = Math.round(sRollo.mScrollPos);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800409
Romain Guy060b5c82010-03-04 10:07:38 -0800410 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1
411 final int currentPageCol = currentSelection % mColumnsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800412
Romain Guy060b5c82010-03-04 10:07:38 -0800413 // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1
Romain Guy6a42cf32010-03-12 16:03:52 -0800414 final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage))
Romain Guy060b5c82010-03-04 10:07:38 -0800415 / mRowsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800416
Daniel Sandler388f6792010-03-02 14:08:08 -0500417 int newSelection = currentSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800418
Daniel Sandler388f6792010-03-02 14:08:08 -0500419 switch (keyCode) {
420 case KeyEvent.KEYCODE_DPAD_UP:
421 if (mLastSelection == SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800422 if (isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700423 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guy6a42cf32010-03-12 16:03:52 -0800424 int lastRowCount = iconCount % mColumnsPerPage;
425 if (lastRowCount == 0) {
426 lastRowCount = mColumnsPerPage;
427 }
428 newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2);
429 if (newSelection >= iconCount) {
430 newSelection = iconCount-1;
431 }
432 int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
433 if (target < 0) {
434 target = 0;
435 }
436 if (currentTopRow != target) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700437 sRollo.moveTo(target);
Romain Guy6a42cf32010-03-12 16:03:52 -0800438 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500439 }
440 } else {
441 if (currentPageRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800442 newSelection = currentSelection - mColumnsPerPage;
Romain Guy6a42cf32010-03-12 16:03:52 -0800443 if (currentTopRow > newSelection / mColumnsPerPage) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700444 sRollo.moveTo(newSelection / mColumnsPerPage);
Romain Guy6a42cf32010-03-12 16:03:52 -0800445 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500446 } else if (currentTopRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800447 newSelection = currentSelection - mColumnsPerPage;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700448 sRollo.moveTo(newSelection / mColumnsPerPage);
Daniel Sandler388f6792010-03-02 14:08:08 -0500449 } else if (currentPageRow != 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800450 newSelection = currentTopRow * mRowsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500451 }
452 }
453 handled = true;
454 break;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800455
Daniel Sandler388f6792010-03-02 14:08:08 -0500456 case KeyEvent.KEYCODE_DPAD_DOWN: {
Romain Guy060b5c82010-03-04 10:07:38 -0800457 final int rowCount = iconCount / mColumnsPerPage
458 + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
459 final int currentRow = currentSelection / mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500460 if (mLastSelection != SELECTION_HOME) {
461 if (currentRow < rowCount-1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700462 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500463 if (currentSelection < 0) {
464 newSelection = 0;
465 } else {
Romain Guy060b5c82010-03-04 10:07:38 -0800466 newSelection = currentSelection + mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500467 }
468 if (newSelection >= iconCount) {
469 // Go from D to G in this arrangement:
470 // A B C D
471 // E F G
472 newSelection = iconCount - 1;
473 }
Romain Guy060b5c82010-03-04 10:07:38 -0800474 if (currentPageRow >= mRowsPerPage - 1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700475 sRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -0500476 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800477 } else if (isPortrait) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500478 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700479 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500480 }
481 }
482 handled = true;
483 break;
484 }
485 case KeyEvent.KEYCODE_DPAD_LEFT:
486 if (mLastSelection != SELECTION_HOME) {
487 if (currentPageCol > 0) {
488 newSelection = currentSelection - 1;
489 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800490 } else if (!isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700491 newSelection = ((int) (sRollo.mScrollPos) * mColumnsPerPage) +
Romain Guy6a42cf32010-03-12 16:03:52 -0800492 (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700493 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500494 }
495 handled = true;
496 break;
497 case KeyEvent.KEYCODE_DPAD_RIGHT:
498 if (mLastSelection != SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800499 if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 ||
500 currentSelection == iconCount - 1)) {
501 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700502 sRollo.setHomeSelected(SELECTED_FOCUSED);
Romain Guy6a42cf32010-03-12 16:03:52 -0800503 } else if ((currentPageCol < mColumnsPerPage - 1) &&
Daniel Sandler388f6792010-03-02 14:08:08 -0500504 (currentSelection < iconCount - 1)) {
505 newSelection = currentSelection + 1;
506 }
507 }
508 handled = true;
509 break;
510 }
511 if (newSelection != currentSelection) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700512 sRollo.selectIcon(newSelection, SELECTED_FOCUSED);
513 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500514 }
515 }
516 return handled;
517 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800518
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700519 void initTouchState(int width, int height) {
520 boolean isPortrait = width < height;
521
522 int[] viewPos = new int[2];
523 getLocationOnScreen(viewPos);
524
525 mTouchXBorders = new int[mColumnsPerPage + 1];
526 mTouchYBorders = new int[mRowsPerPage + 1];
527
528 // TODO: Put this in a config file/define
529 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE_PORTRAIT;
530 if (!isPortrait) cellHeight -= 12;
531 int centerY = (int) (height * (isPortrait ? 0.5f : 0.47f));
532 if (!isPortrait) centerY += cellHeight / 2;
533 int half = (int) Math.floor((mRowsPerPage + 1) / 2);
534 int end = mTouchYBorders.length - (half + 1);
535
536 for (int i = -half; i <= end; i++) {
537 mTouchYBorders[i + half] = centerY + (i * cellHeight) - viewPos[1];
538 }
539
540 int x = 0;
541 // TODO: Put this in a config file/define
542 int columnWidth = 120;
543 for (int i = 0; i < mColumnsPerPage + 1; i++) {
544 mTouchXBorders[i] = x - viewPos[0];
545 x += columnWidth;
546 }
547 }
548
549 int chooseTappedIcon(int x, int y) {
550 float pos = sRollo != null ? sRollo.mScrollPos : 0;
551
552 int oldY = y;
553
554 // Adjust for scroll position if not zero.
555 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
556
557 int col = -1;
558 int row = -1;
559 final int columnsCount = mColumnsPerPage;
560 for (int i=0; i< columnsCount; i++) {
561 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
562 col = i;
563 break;
564 }
565 }
566 final int rowsCount = mRowsPerPage;
567 for (int i=0; i< rowsCount; i++) {
568 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
569 row = i;
570 break;
571 }
572 }
573
574 if (row < 0 || col < 0) {
575 return -1;
576 }
577
578 int index = (((int) pos) * columnsCount) + (row * columnsCount) + col;
579
580 if (index >= mAllAppsList.size()) {
581 return -1;
582 } else {
583 return index;
584 }
585 }
586
Daniel Sandler388f6792010-03-02 14:08:08 -0500587 @Override
588 public boolean onTouchEvent(MotionEvent ev)
589 {
590 mArrowNavigation = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800591
Daniel Sandler388f6792010-03-02 14:08:08 -0500592 if (!isVisible()) {
593 return true;
594 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800595
Daniel Sandler388f6792010-03-02 14:08:08 -0500596 if (mLocks != 0) {
597 return true;
598 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800599
Daniel Sandler388f6792010-03-02 14:08:08 -0500600 super.onTouchEvent(ev);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800601
Daniel Sandler388f6792010-03-02 14:08:08 -0500602 int x = (int)ev.getX();
603 int y = (int)ev.getY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800604
Romain Guyce115852010-03-04 12:15:37 -0800605 final boolean isPortrait = getWidth() < getHeight();
Daniel Sandler388f6792010-03-02 14:08:08 -0500606 int action = ev.getAction();
607 switch (action) {
608 case MotionEvent.ACTION_DOWN:
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700609 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
610 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500611 mTouchTracking = TRACKING_HOME;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700612 sRollo.setHomeSelected(SELECTED_PRESSED);
613 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500614 mCurrentIconIndex = -1;
615 } else {
616 mTouchTracking = TRACKING_FLING;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800617
Daniel Sandler388f6792010-03-02 14:08:08 -0500618 mMotionDownRawX = (int)ev.getRawX();
619 mMotionDownRawY = (int)ev.getRawY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800620
Joe Onorato2cc62e82010-03-17 20:23:53 -0700621 sRollo.mState.newPositionX = ev.getRawY() / getHeight();
622 sRollo.mState.newTouchDown = 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800623
Joe Onorato2cc62e82010-03-17 20:23:53 -0700624 if (!sRollo.checkClickOK()) {
625 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500626 } else {
627 mDownIconIndex = mCurrentIconIndex
Joe Onorato2cc62e82010-03-17 20:23:53 -0700628 = sRollo.selectIcon(x, y, SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500629 if (mDownIconIndex < 0) {
630 // if nothing was selected, no long press.
631 cancelLongPress();
632 }
633 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700634 sRollo.mState.save();
635 sRollo.move();
Daniel Sandler388f6792010-03-02 14:08:08 -0500636 mVelocityTracker = VelocityTracker.obtain();
637 mVelocityTracker.addMovement(ev);
638 mStartedScrolling = false;
639 }
640 break;
641 case MotionEvent.ACTION_MOVE:
642 case MotionEvent.ACTION_OUTSIDE:
643 if (mTouchTracking == TRACKING_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700644 sRollo.setHomeSelected((isPortrait &&
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700645 y > mTouchYBorders[mTouchYBorders.length-1]) || (!isPortrait
646 && x > mTouchXBorders[mTouchXBorders.length-1])
Daniel Sandler388f6792010-03-02 14:08:08 -0500647 ? SELECTED_PRESSED : SELECTED_NONE);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700648 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500649 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500650 int rawY = (int)ev.getRawY();
651 int slop;
652 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800653
Daniel Sandler388f6792010-03-02 14:08:08 -0500654 if (!mStartedScrolling && slop < mSlop) {
655 // don't update anything so when we do start scrolling
656 // below, we get the right delta.
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700657 mCurrentIconIndex = chooseTappedIcon(x, y);
Daniel Sandler388f6792010-03-02 14:08:08 -0500658 if (mDownIconIndex != mCurrentIconIndex) {
659 // If a different icon is selected, don't allow it to be picked up.
660 // This handles off-axis dragging.
661 cancelLongPress();
662 mCurrentIconIndex = -1;
663 }
664 } else {
665 if (!mStartedScrolling) {
666 cancelLongPress();
667 mCurrentIconIndex = -1;
668 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700669 sRollo.mState.newPositionX = ev.getRawY() / getHeight();
670 sRollo.mState.newTouchDown = 1;
671 sRollo.move();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800672
Daniel Sandler388f6792010-03-02 14:08:08 -0500673 mStartedScrolling = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700674 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500675 mVelocityTracker.addMovement(ev);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700676 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500677 }
678 }
679 break;
680 case MotionEvent.ACTION_UP:
681 case MotionEvent.ACTION_CANCEL:
682 if (mTouchTracking == TRACKING_HOME) {
683 if (action == MotionEvent.ACTION_UP) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700684 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
685 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500686 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
687 mLauncher.closeAllApps(true);
688 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700689 sRollo.setHomeSelected(SELECTED_NONE);
690 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500691 }
692 mCurrentIconIndex = -1;
693 } else if (mTouchTracking == TRACKING_FLING) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700694 sRollo.mState.newTouchDown = 0;
695 sRollo.mState.newPositionX = ev.getRawY() / getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800696
Daniel Sandler388f6792010-03-02 14:08:08 -0500697 mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700698 sRollo.mState.flingVelocity = mVelocityTracker.getYVelocity() / getHeight();
699 sRollo.clearSelectedIcon();
700 sRollo.mState.save();
701 sRollo.fling();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800702
Daniel Sandler388f6792010-03-02 14:08:08 -0500703 if (mVelocityTracker != null) {
704 mVelocityTracker.recycle();
705 mVelocityTracker = null;
706 }
707 }
708 mTouchTracking = TRACKING_NONE;
709 break;
710 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800711
Daniel Sandler388f6792010-03-02 14:08:08 -0500712 return true;
713 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800714
Daniel Sandler388f6792010-03-02 14:08:08 -0500715 public void onClick(View v) {
716 if (mLocks != 0 || !isVisible()) {
717 return;
718 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700719 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500720 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
721 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
722 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onoratof984e852010-03-25 09:47:45 -0700723 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500724 }
725 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800726
Daniel Sandler388f6792010-03-02 14:08:08 -0500727 public boolean onLongClick(View v) {
728 if (mLocks != 0 || !isVisible()) {
729 return true;
730 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700731 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500732 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
733 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800734
Daniel Sandler388f6792010-03-02 14:08:08 -0500735 Bitmap bmp = app.iconBitmap;
736 final int w = bmp.getWidth();
737 final int h = bmp.getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800738
Daniel Sandler388f6792010-03-02 14:08:08 -0500739 // We don't really have an accurate location to use. This will do.
740 int screenX = mMotionDownRawX - (w / 2);
741 int screenY = mMotionDownRawY - h;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800742
Daniel Sandler388f6792010-03-02 14:08:08 -0500743 mDragController.startDrag(bmp, screenX, screenY,
744 0, 0, w, h, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800745
Daniel Sandler388f6792010-03-02 14:08:08 -0500746 mLauncher.closeAllApps(true);
747 }
748 return true;
749 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800750
Daniel Sandler388f6792010-03-02 14:08:08 -0500751 @Override
752 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
753 if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
754 if (!isVisible()) {
755 return false;
756 }
757 String text = null;
758 int index;
759 int count = mAllAppsList.size() + 1; // +1 is home
760 int pos = -1;
761 switch (mLastSelection) {
762 case SELECTION_ICONS:
Joe Onorato2cc62e82010-03-17 20:23:53 -0700763 index = sRollo.mState.selectedIconIndex;
Daniel Sandler388f6792010-03-02 14:08:08 -0500764 if (index >= 0) {
765 ApplicationInfo info = mAllAppsList.get(index);
766 if (info.title != null) {
767 text = info.title.toString();
768 pos = index;
769 }
770 }
771 break;
772 case SELECTION_HOME:
773 text = getContext().getString(R.string.all_apps_home_button_label);
774 pos = count;
775 break;
776 }
777 if (text != null) {
778 event.setEnabled(true);
779 event.getText().add(text);
780 //event.setContentDescription(text);
781 event.setItemCount(count);
782 event.setCurrentItemIndex(pos);
783 }
784 }
785 return false;
786 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800787
Daniel Sandler388f6792010-03-02 14:08:08 -0500788 public void setDragController(DragController dragger) {
789 mDragController = dragger;
790 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800791
Daniel Sandler388f6792010-03-02 14:08:08 -0500792 public void onDropCompleted(View target, boolean success) {
793 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800794
Daniel Sandler388f6792010-03-02 14:08:08 -0500795 /**
796 * Zoom to the specifed level.
797 *
798 * @param zoom [0..1] 0 is hidden, 1 is open
799 */
800 public void zoom(float zoom, boolean animate) {
801 cancelLongPress();
802 mNextZoom = zoom;
803 mAnimateNextZoom = animate;
804 // if we do setZoom while we don't have a surface, we won't
805 // get the callbacks that actually set mZoom.
Joe Onorato2cc62e82010-03-17 20:23:53 -0700806 if (sRollo == null || !mHaveSurface) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500807 mZoomDirty = true;
808 mZoom = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500809 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700810 sRollo.setZoom(zoom, animate);
Daniel Sandler388f6792010-03-02 14:08:08 -0500811 }
812 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800813
Joe Onorato878f0862010-03-22 12:22:22 -0400814 /**
815 * If sRollo is null, then we're not visible. This is also used to guard against
816 * sRollo being null.
817 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500818 public boolean isVisible() {
Joe Onorato878f0862010-03-22 12:22:22 -0400819 return sRollo != null && mZoom > 0.001f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500820 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800821
Daniel Sandler388f6792010-03-02 14:08:08 -0500822 public boolean isOpaque() {
823 return mZoom > 0.999f;
824 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800825
Daniel Sandler388f6792010-03-02 14:08:08 -0500826 public void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700827 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500828 // We've been removed from the window. Don't bother with all this.
829 return;
830 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800831
832 boolean reload = false;
833 if (mAllAppsList == null) {
834 reload = true;
835 } else if (list.size() != mAllAppsList.size()) {
836 reload = true;
837 } else {
838 final int count = list.size();
839 for (int i = 0; i < count; i++) {
840 if (list.get(i) != mAllAppsList.get(i)) {
841 reload = true;
842 break;
843 }
844 }
845 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800846
Daniel Sandler388f6792010-03-02 14:08:08 -0500847 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700848 if (sRollo != null && reload) {
849 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500850 }
Romain Guyc16fea72010-03-12 17:17:56 -0800851
852 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700853 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
854 sRollo.mState.save();
Romain Guyc16fea72010-03-12 17:17:56 -0800855 mRestoreFocusIndex = -1;
856 }
857
Daniel Sandler388f6792010-03-02 14:08:08 -0500858 mLocks &= ~LOCK_ICONS_PENDING;
859 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800860
Daniel Sandler388f6792010-03-02 14:08:08 -0500861 public void addApps(ArrayList<ApplicationInfo> list) {
862 if (mAllAppsList == null) {
863 // Not done loading yet. We'll find out about it later.
864 return;
865 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700866 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500867 // We've been removed from the window. Don't bother with all this.
868 return;
869 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800870
Daniel Sandler388f6792010-03-02 14:08:08 -0500871 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700872 if (sRollo != null) {
873 sRollo.pause();
874 sRollo.reallocAppsList(sRollo.mState.iconCount + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500875 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800876
Daniel Sandler388f6792010-03-02 14:08:08 -0500877 for (int i=0; i<N; i++) {
878 final ApplicationInfo item = list.get(i);
879 int index = Collections.binarySearch(mAllAppsList, item,
880 LauncherModel.APP_NAME_COMPARATOR);
881 if (index < 0) {
882 index = -(index+1);
883 }
884 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700885 if (sRollo != null) {
886 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500887 }
888 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800889
Joe Onorato2cc62e82010-03-17 20:23:53 -0700890 if (sRollo != null) {
891 sRollo.saveAppsList();
892 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500893 }
894 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800895
Daniel Sandler388f6792010-03-02 14:08:08 -0500896 public void removeApps(ArrayList<ApplicationInfo> list) {
897 if (mAllAppsList == null) {
898 // Not done loading yet. We'll find out about it later.
899 return;
900 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800901
Joe Onorato2cc62e82010-03-17 20:23:53 -0700902 if (sRollo != null) {
903 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800904 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500905 final int N = list.size();
906 for (int i=0; i<N; i++) {
907 final ApplicationInfo item = list.get(i);
908 int index = findAppByComponent(mAllAppsList, item);
909 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500910 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700911 if (sRollo != null) {
912 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500913 }
914 } else {
915 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
916 // Try to recover. This should keep us from crashing for now.
917 }
918 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800919
Joe Onorato2cc62e82010-03-17 20:23:53 -0700920 if (sRollo != null) {
921 sRollo.saveAppsList();
922 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500923 }
924 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800925
Joe Onorato64e6be72010-03-05 15:05:52 -0500926 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500927 // Just remove and add, because they may need to be re-sorted.
928 removeApps(list);
929 addApps(list);
930 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800931
Daniel Sandler388f6792010-03-02 14:08:08 -0500932 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
933 ComponentName component = item.intent.getComponent();
934 final int N = list.size();
935 for (int i=0; i<N; i++) {
936 ApplicationInfo x = list.get(i);
937 if (x.intent.getComponent().equals(component)) {
938 return i;
939 }
940 }
941 return -1;
942 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800943
Romain Guy060b5c82010-03-04 10:07:38 -0800944 /*
Daniel Sandler388f6792010-03-02 14:08:08 -0500945 private static int countPages(int iconCount) {
Romain Guy060b5c82010-03-04 10:07:38 -0800946 int iconsPerPage = getColumnsCount() * Defines.ROWS_PER_PAGE_PORTRAIT;
Daniel Sandler388f6792010-03-02 14:08:08 -0500947 int pages = iconCount / iconsPerPage;
948 if (pages*iconsPerPage != iconCount) {
949 pages++;
950 }
951 return pages;
952 }
Romain Guy060b5c82010-03-04 10:07:38 -0800953 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500954
955 class AAMessage extends RenderScript.RSMessage {
956 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700957 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500958 mVelocity = ((float)mData[1]) / (1 << 16);
959 mZoom = ((float)mData[2]) / (1 << 16);
960 mZoomDirty = false;
961 }
962 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800963
Romain Guy13c2e7b2010-03-10 19:45:00 -0800964 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500965 // Allocations ======
966 private int mWidth;
967 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800968
Daniel Sandler388f6792010-03-02 14:08:08 -0500969 private Resources mRes;
970 private Script mScript;
971 private Script.Invokable mInvokeMove;
972 private Script.Invokable mInvokeMoveTo;
973 private Script.Invokable mInvokeFling;
974 private Script.Invokable mInvokeResetWAR;
975 private Script.Invokable mInvokeSetZoom;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800976
Daniel Sandler388f6792010-03-02 14:08:08 -0500977 private ProgramStore mPSIcons;
978 private ProgramFragment mPFTexMip;
979 private ProgramFragment mPFTexMipAlpha;
980 private ProgramFragment mPFTexNearest;
981 private ProgramVertex mPV;
982 private ProgramVertex mPVCurve;
983 private SimpleMesh mMesh;
984 private ProgramVertex.MatrixAllocation mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800985
Daniel Sandler388f6792010-03-02 14:08:08 -0500986 private Allocation mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800987
Daniel Sandler388f6792010-03-02 14:08:08 -0500988 private Allocation mHomeButtonNormal;
989 private Allocation mHomeButtonFocused;
990 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800991
Daniel Sandler388f6792010-03-02 14:08:08 -0500992 private Allocation[] mIcons;
993 private int[] mIconIds;
994 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800995
Daniel Sandler388f6792010-03-02 14:08:08 -0500996 private Allocation[] mLabels;
997 private int[] mLabelIds;
998 private Allocation mAllocLabelIds;
999 private Allocation mSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001000
Daniel Sandler388f6792010-03-02 14:08:08 -05001001 private Bitmap mSelectionBitmap;
1002 private Canvas mSelectionCanvas;
Romain Guy6a42cf32010-03-12 16:03:52 -08001003
1004 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001005
Daniel Sandler388f6792010-03-02 14:08:08 -05001006 Params mParams;
1007 State mState;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001008
Romain Guy13c2e7b2010-03-10 19:45:00 -08001009 AllApps3D mAllApps;
1010 boolean mInitialize;
1011
Daniel Sandler388f6792010-03-02 14:08:08 -05001012 class BaseAlloc {
1013 Allocation mAlloc;
1014 Type mType;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001015
Daniel Sandler388f6792010-03-02 14:08:08 -05001016 void save() {
1017 mAlloc.data(this);
1018 }
1019 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001020
Daniel Sandler388f6792010-03-02 14:08:08 -05001021 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001022 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -08001023 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -05001024 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001025
1026 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001027 if (sRS != null) {
1028 sRS.contextBindRootScript(null);
1029 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001030 }
1031
1032 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001033 if (sRS != null) {
1034 sRS.contextBindRootScript(mScript);
1035 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001036 }
1037
Daniel Sandler388f6792010-03-02 14:08:08 -05001038 class Params extends BaseAlloc {
1039 Params() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001040 mType = Type.createFromClass(sRS, Params.class, 1, "ParamsClass");
1041 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001042 save();
1043 }
1044 public int bubbleWidth;
1045 public int bubbleHeight;
1046 public int bubbleBitmapWidth;
1047 public int bubbleBitmapHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001048
Daniel Sandler388f6792010-03-02 14:08:08 -05001049 public int homeButtonWidth;
1050 public int homeButtonHeight;
1051 public int homeButtonTextureWidth;
1052 public int homeButtonTextureHeight;
1053 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001054
Daniel Sandler388f6792010-03-02 14:08:08 -05001055 class State extends BaseAlloc {
1056 public float newPositionX;
1057 public int newTouchDown;
1058 public float flingVelocity;
1059 public int iconCount;
1060 public int selectedIconIndex = -1;
1061 public int selectedIconTexture;
1062 public float zoomTarget;
1063 public int homeButtonId;
1064 public float targetPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001065
Daniel Sandler388f6792010-03-02 14:08:08 -05001066 State() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001067 mType = Type.createFromClass(sRS, State.class, 1, "StateClass");
1068 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001069 save();
1070 }
1071 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001072
Romain Guy13c2e7b2010-03-10 19:45:00 -08001073 public RolloRS(AllApps3D allApps) {
1074 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -05001075 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001076
Daniel Sandler388f6792010-03-02 14:08:08 -05001077 public void init(Resources res, int width, int height) {
1078 mRes = res;
1079 mWidth = width;
1080 mHeight = height;
1081 initProgramVertex();
1082 initProgramFragment();
1083 initProgramStore();
1084 initGl();
1085 initData();
Daniel Sandler388f6792010-03-02 14:08:08 -05001086 initRs();
1087 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001088
Daniel Sandler388f6792010-03-02 14:08:08 -05001089 public void initMesh() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001090 SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001091
Daniel Sandler388f6792010-03-02 14:08:08 -05001092 for (int ct=0; ct < 16; ct++) {
1093 float pos = (1.f / (16.f - 1)) * ct;
1094 tm.addVertex(0.0f, pos);
1095 tm.addVertex(1.0f, pos);
1096 }
1097 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1098 tm.addTriangle(ct, ct+1, ct+2);
1099 tm.addTriangle(ct+1, ct+3, ct+2);
1100 }
1101 mMesh = tm.create();
1102 mMesh.setName("SMCell");
1103 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001104
Daniel Sandler388f6792010-03-02 14:08:08 -05001105 void resize(int w, int h) {
1106 mPVA.setupProjectionNormalized(w, h);
1107 mWidth = w;
1108 mHeight = h;
1109 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001110
Daniel Sandler388f6792010-03-02 14:08:08 -05001111 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001112 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001113 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001114
Joe Onorato2cc62e82010-03-17 20:23:53 -07001115 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001116 pvb.setTextureMatrixEnable(true);
1117 mPV = pvb.create();
1118 mPV.setName("PV");
1119 mPV.bindAllocation(mPVA);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001120
Joe Onorato2cc62e82010-03-17 20:23:53 -07001121 Element.Builder eb = new Element.Builder(sRS);
1122 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "ImgSize");
1123 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "Position");
1124 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "BendPos");
1125 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "ScaleOffset");
Daniel Sandler388f6792010-03-02 14:08:08 -05001126 Element e = eb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001127
Joe Onorato2cc62e82010-03-17 20:23:53 -07001128 mUniformAlloc = Allocation.createSized(sRS, e, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001129
Daniel Sandler388f6792010-03-02 14:08:08 -05001130 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001131 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Romain Guy060b5c82010-03-04 10:07:38 -08001132 String t = "void main() {\n" +
1133 // Animation
1134 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001135
Romain Guy060b5c82010-03-04 10:07:38 -08001136 " float bendY1 = UNI_BendPos.x;\n" +
1137 " float bendY2 = UNI_BendPos.y;\n" +
1138 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1139 " float bendDistance = bendY1 * 0.4;\n" +
1140 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001141
Romain Guy060b5c82010-03-04 10:07:38 -08001142 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1143 " float aDy = cos(bendAngle);\n" +
1144 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001145
Romain Guy060b5c82010-03-04 10:07:38 -08001146 " float scale = (2.0 / 480.0);\n" +
1147 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1148 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1149 " float y = 0.0;\n" +
1150 " float z = 0.0;\n" +
1151 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001152
Romain Guy060b5c82010-03-04 10:07:38 -08001153 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1154 " y += cv * aDy;\n" +
1155 " z += -cv * aDz;\n" +
1156 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1157 " lum += cv / bendDistance * distanceDimLevel;\n" +
1158 " y += cv * cos(cv * bendStep);\n" +
1159 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001160
Romain Guy060b5c82010-03-04 10:07:38 -08001161 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1162 " y += cv * aDy;\n" +
1163 " z += cv * aDz;\n" +
1164 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1165 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1166 " y += cv * cos(cv * bendStep);\n" +
1167 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001168
Romain Guy060b5c82010-03-04 10:07:38 -08001169 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001170
Romain Guy060b5c82010-03-04 10:07:38 -08001171 " vec4 pos;\n" +
1172 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1173 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1174 " pos.z = z * UNI_ScaleOffset.x;\n" +
1175 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001176
Romain Guy060b5c82010-03-04 10:07:38 -08001177 " pos.x *= 1.0 + ani * 4.0;\n" +
1178 " pos.y *= 1.0 + ani * 4.0;\n" +
1179 " pos.z -= ani * 1.5;\n" +
1180 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001181
Romain Guy060b5c82010-03-04 10:07:38 -08001182 " gl_Position = UNI_MVP * pos;\n" +
1183 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1184 " varTex0.xy = ATTRIB_position;\n" +
1185 " varTex0.y = 1.0 - varTex0.y;\n" +
1186 " varTex0.zw = vec2(0.0, 0.0);\n" +
1187 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001188 sb.setShader(t);
1189 sb.addConstant(mUniformAlloc.getType());
1190 sb.addInput(mMesh.getVertexType(0).getElement());
1191 mPVCurve = sb.create();
1192 mPVCurve.setName("PVCurve");
1193 mPVCurve.bindAllocation(mPVA);
1194 mPVCurve.bindConstants(mUniformAlloc, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001195
Joe Onorato2cc62e82010-03-17 20:23:53 -07001196 sRS.contextBindProgramVertex(mPV);
Daniel Sandler388f6792010-03-02 14:08:08 -05001197 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001198
Daniel Sandler388f6792010-03-02 14:08:08 -05001199 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001200 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001201 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1202 sb.setMag(Sampler.Value.NEAREST);
1203 sb.setWrapS(Sampler.Value.CLAMP);
1204 sb.setWrapT(Sampler.Value.CLAMP);
1205 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001206
Daniel Sandler388f6792010-03-02 14:08:08 -05001207 sb.setMin(Sampler.Value.NEAREST);
1208 sb.setMag(Sampler.Value.NEAREST);
1209 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001210
Joe Onorato2cc62e82010-03-17 20:23:53 -07001211 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001212 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1213 ProgramFragment.Builder.Format.RGBA, 0);
1214 mPFTexMip = bf.create();
1215 mPFTexMip.setName("PFTexMip");
1216 mPFTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001217
Daniel Sandler388f6792010-03-02 14:08:08 -05001218 mPFTexNearest = bf.create();
1219 mPFTexNearest.setName("PFTexNearest");
1220 mPFTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001221
Daniel Sandler388f6792010-03-02 14:08:08 -05001222 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1223 ProgramFragment.Builder.Format.ALPHA, 0);
1224 mPFTexMipAlpha = bf.create();
1225 mPFTexMipAlpha.setName("PFTexMipAlpha");
1226 mPFTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001227
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 initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001231 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001232 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1233 bs.setColorMask(true,true,true,false);
1234 bs.setDitherEnable(true);
1235 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1236 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
1237 mPSIcons = bs.create();
1238 mPSIcons.setName("PSIcons");
1239 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001240
Daniel Sandler388f6792010-03-02 14:08:08 -05001241 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001242 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001243
Daniel Sandler388f6792010-03-02 14:08:08 -05001244 private void initData() {
1245 mParams = new Params();
1246 mState = new State();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001247
Romain Guy13c2e7b2010-03-10 19:45:00 -08001248 final Utilities.BubbleText bubble = new Utilities.BubbleText(mAllApps.getContext());
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001249
Daniel Sandler388f6792010-03-02 14:08:08 -05001250 mParams.bubbleWidth = bubble.getBubbleWidth();
1251 mParams.bubbleHeight = bubble.getMaxBubbleHeight();
1252 mParams.bubbleBitmapWidth = bubble.getBitmapWidth();
1253 mParams.bubbleBitmapHeight = bubble.getBitmapHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001254
Joe Onorato2cc62e82010-03-17 20:23:53 -07001255 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1256 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001257 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001258 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1259 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001260 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001261 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1262 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001263 mHomeButtonPressed.uploadToTexture(0);
1264 mParams.homeButtonWidth = 76;
1265 mParams.homeButtonHeight = 68;
1266 mParams.homeButtonTextureWidth = 128;
1267 mParams.homeButtonTextureHeight = 128;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001268
Daniel Sandler388f6792010-03-02 14:08:08 -05001269 mState.homeButtonId = mHomeButtonNormal.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001270
Daniel Sandler388f6792010-03-02 14:08:08 -05001271 mParams.save();
1272 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001273
Daniel Sandler388f6792010-03-02 14:08:08 -05001274 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1275 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1276 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001277
Daniel Sandler388f6792010-03-02 14:08:08 -05001278 setApps(null);
1279 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001280
Daniel Sandler388f6792010-03-02 14:08:08 -05001281 private void initRs() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001282 ScriptC.Builder sb = new ScriptC.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001283 sb.setScript(mRes, R.raw.allapps);
1284 sb.setRoot(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001285 sb.addDefines(mAllApps.mDefines);
Daniel Sandler388f6792010-03-02 14:08:08 -05001286 sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS);
1287 sb.setType(mState.mType, "state", Defines.ALLOC_STATE);
1288 sb.setType(mUniformAlloc.getType(), "vpConstants", Defines.ALLOC_VP_CONSTANTS);
1289 mInvokeMove = sb.addInvokable("move");
1290 mInvokeFling = sb.addInvokable("fling");
1291 mInvokeMoveTo = sb.addInvokable("moveTo");
1292 mInvokeResetWAR = sb.addInvokable("resetHWWar");
1293 mInvokeSetZoom = sb.addInvokable("setZoom");
1294 mScript = sb.create();
1295 mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1296 mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
1297 mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
1298 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1299 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
1300 mScript.bindAllocation(mUniformAlloc, Defines.ALLOC_VP_CONSTANTS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001301
Joe Onorato2cc62e82010-03-17 20:23:53 -07001302 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -05001303 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001304
Daniel Sandler388f6792010-03-02 14:08:08 -05001305 void dirtyCheck() {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001306 if (mAllApps.mZoomDirty) {
1307 setZoom(mAllApps.mNextZoom, mAllApps.mAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001308 }
1309 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001310
Romain Guy060b5c82010-03-04 10:07:38 -08001311 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001312 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001313 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001314 final int count = list != null ? list.size() : 0;
1315 int allocCount = count;
1316 if (allocCount < 1) {
1317 allocCount = 1;
1318 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001319
Daniel Sandler388f6792010-03-02 14:08:08 -05001320 mIcons = new Allocation[count];
1321 mIconIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001322 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001323
Daniel Sandler388f6792010-03-02 14:08:08 -05001324 mLabels = new Allocation[count];
1325 mLabelIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001326 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001327
Daniel Sandler388f6792010-03-02 14:08:08 -05001328 mState.iconCount = count;
1329 for (int i=0; i < mState.iconCount; i++) {
1330 createAppIconAllocations(i, list.get(i));
1331 }
1332 for (int i=0; i < mState.iconCount; i++) {
1333 uploadAppIcon(i, list.get(i));
1334 }
1335 saveAppsList();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001336 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001337 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001338
Daniel Sandler388f6792010-03-02 14:08:08 -05001339 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001340 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001341 sRollo.clearSelectedIcon();
1342 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001343 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001344 if (zoom > 0.001f) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001345 sRollo.mState.zoomTarget = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -05001346 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001347 sRollo.mState.zoomTarget = 0;
Daniel Sandler388f6792010-03-02 14:08:08 -05001348 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001349 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -05001350 if (!animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001351 sRollo.mInvokeSetZoom.execute();
Daniel Sandler388f6792010-03-02 14:08:08 -05001352 }
1353 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001354
Daniel Sandler388f6792010-03-02 14:08:08 -05001355 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001356 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1357 Element.RGBA_8888(sRS), false);
1358 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1359 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001360 mIconIds[index] = mIcons[index].getID();
1361 mLabelIds[index] = mLabels[index].getID();
1362 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001363
Daniel Sandler388f6792010-03-02 14:08:08 -05001364 private void uploadAppIcon(int index, ApplicationInfo item) {
1365 if (mIconIds[index] != mIcons[index].getID()) {
1366 throw new IllegalStateException("uploadAppIcon index=" + index
1367 + " mIcons[index].getID=" + mIcons[index].getID()
1368 + " mIconsIds[index]=" + mIconIds[index]
1369 + " item=" + item);
1370 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001371 mIcons[index].uploadToTexture(true, 0);
1372 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001373 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001374
Daniel Sandler388f6792010-03-02 14:08:08 -05001375 /**
1376 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1377 * fill in the values and call saveAppsList().
1378 */
1379 private void reallocAppsList(int count) {
1380 Allocation[] icons = new Allocation[count];
1381 int[] iconIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001382 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001383
Daniel Sandler388f6792010-03-02 14:08:08 -05001384 Allocation[] labels = new Allocation[count];
1385 int[] labelIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001386 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001387
Joe Onorato2cc62e82010-03-17 20:23:53 -07001388 final int oldCount = sRollo.mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001389
Daniel Sandler388f6792010-03-02 14:08:08 -05001390 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1391 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1392 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1393 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001394
Daniel Sandler388f6792010-03-02 14:08:08 -05001395 mIcons = icons;
1396 mIconIds = iconIds;
1397 mLabels = labels;
1398 mLabelIds = labelIds;
1399 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001400
Daniel Sandler388f6792010-03-02 14:08:08 -05001401 /**
1402 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1403 */
1404 private void addApp(int index, ApplicationInfo item) {
1405 final int count = mState.iconCount - index;
1406 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001407
Daniel Sandler388f6792010-03-02 14:08:08 -05001408 System.arraycopy(mIcons, index, mIcons, dest, count);
1409 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1410 System.arraycopy(mLabels, index, mLabels, dest, count);
1411 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001412
Daniel Sandler388f6792010-03-02 14:08:08 -05001413 createAppIconAllocations(index, item);
1414 uploadAppIcon(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001415 sRollo.mState.iconCount++;
Daniel Sandler388f6792010-03-02 14:08:08 -05001416 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001417
Daniel Sandler388f6792010-03-02 14:08:08 -05001418 /**
1419 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1420 */
1421 private void removeApp(int index) {
1422 final int count = mState.iconCount - index - 1;
1423 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001424
Daniel Sandler388f6792010-03-02 14:08:08 -05001425 System.arraycopy(mIcons, src, mIcons, index, count);
1426 System.arraycopy(mIconIds, src, mIconIds, index, count);
1427 System.arraycopy(mLabels, src, mLabels, index, count);
1428 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001429
Joe Onorato2cc62e82010-03-17 20:23:53 -07001430 sRollo.mState.iconCount--;
Daniel Sandler388f6792010-03-02 14:08:08 -05001431 final int last = mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001432
Daniel Sandler388f6792010-03-02 14:08:08 -05001433 mIcons[last] = null;
1434 mIconIds[last] = 0;
1435 mLabels[last] = null;
1436 mLabelIds[last] = 0;
1437 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001438
Daniel Sandler388f6792010-03-02 14:08:08 -05001439 /**
1440 * Send the apps list structures to RS.
1441 */
1442 private void saveAppsList() {
1443 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1444 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001445 mAllocIconIds.data(mIconIds);
1446 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001447
Daniel Sandler388f6792010-03-02 14:08:08 -05001448 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1449 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001450
Daniel Sandler388f6792010-03-02 14:08:08 -05001451 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001452
Daniel Sandler388f6792010-03-02 14:08:08 -05001453 // Note: mScript may be null if we haven't initialized it yet.
1454 // In that case, this is a no-op.
1455 if (mInvokeResetWAR != null) {
1456 mInvokeResetWAR.execute();
1457 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001458 }
1459 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001460
Daniel Sandler388f6792010-03-02 14:08:08 -05001461 void fling() {
1462 mInvokeFling.execute();
1463 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001464
Daniel Sandler388f6792010-03-02 14:08:08 -05001465 void move() {
1466 mInvokeMove.execute();
1467 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001468
Daniel Sandler388f6792010-03-02 14:08:08 -05001469 void moveTo(float row) {
1470 mState.targetPos = row;
1471 mState.save();
1472 mInvokeMoveTo.execute();
1473 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001474
Daniel Sandler388f6792010-03-02 14:08:08 -05001475 /**
1476 * You need to call save() on mState on your own after calling this.
1477 *
1478 * @return the index of the icon that was selected.
1479 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001480 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001481 if (mAllApps != null) {
1482 final int index = mAllApps.chooseTappedIcon(x, y);
1483 selectIcon(index, pressed);
1484 return index;
1485 } else {
1486 return -1;
1487 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001488 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001489
Daniel Sandler388f6792010-03-02 14:08:08 -05001490 /**
1491 * Select the icon at the given index.
1492 *
1493 * @param index The index.
1494 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1495 */
1496 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001497 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1498 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001499 if (mAllApps != null) {
1500 mAllApps.mRestoreFocusIndex = index;
1501 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001502 mState.selectedIconIndex = -1;
Romain Guy13c2e7b2010-03-10 19:45:00 -08001503 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1504 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001505 }
1506 } else {
1507 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001508 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001509 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001510
Daniel Sandler388f6792010-03-02 14:08:08 -05001511 int prev = mState.selectedIconIndex;
1512 mState.selectedIconIndex = index;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001513
Romain Guy13c2e7b2010-03-10 19:45:00 -08001514 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001515 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001516
Daniel Sandler388f6792010-03-02 14:08:08 -05001517 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1518 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1519 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001520
Joe Onorato2cc62e82010-03-17 20:23:53 -07001521 mSelectedIcon = Allocation.createFromBitmap(sRS, selectionBitmap,
1522 Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001523 mSelectedIcon.uploadToTexture(0);
1524 mState.selectedIconTexture = mSelectedIcon.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001525
Daniel Sandler388f6792010-03-02 14:08:08 -05001526 if (prev != index) {
1527 if (info.title != null && info.title.length() > 0) {
1528 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001529 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001530 }
1531 }
1532 }
1533 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001534
Daniel Sandler388f6792010-03-02 14:08:08 -05001535 /**
1536 * You need to call save() on mState on your own after calling this.
1537 */
1538 void clearSelectedIcon() {
1539 mState.selectedIconIndex = -1;
1540 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001541
Daniel Sandler388f6792010-03-02 14:08:08 -05001542 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001543 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001544 switch (mode) {
1545 case SELECTED_NONE:
1546 mState.homeButtonId = mHomeButtonNormal.getID();
1547 break;
1548 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001549 mAllApps.mLastSelection = SELECTION_HOME;
Daniel Sandler388f6792010-03-02 14:08:08 -05001550 mState.homeButtonId = mHomeButtonFocused.getID();
1551 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001552 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001553 }
1554 break;
1555 case SELECTED_PRESSED:
1556 mState.homeButtonId = mHomeButtonPressed.getID();
1557 break;
1558 }
1559 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001560
Daniel Sandler388f6792010-03-02 14:08:08 -05001561 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001562 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1563 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1564 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001565 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001566 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001567 }
1568 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001569 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001570 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001571 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001572 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001573 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001574 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001575 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Joe Onorato2cc62e82010-03-17 20:23:53 -07001576 Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1577 Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1578 Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1579 Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1580 Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1581 Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1582 Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1583 Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1584 Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
1585 Log.d(TAG, "sRollo.mParams.bubbleWidth=" + mParams.bubbleWidth);
1586 Log.d(TAG, "sRollo.mParams.bubbleHeight=" + mParams.bubbleHeight);
1587 Log.d(TAG, "sRollo.mParams.bubbleBitmapWidth=" + mParams.bubbleBitmapWidth);
1588 Log.d(TAG, "sRollo.mParams.bubbleBitmapHeight=" + mParams.bubbleBitmapHeight);
1589 Log.d(TAG, "sRollo.mParams.homeButtonWidth=" + mParams.homeButtonWidth);
1590 Log.d(TAG, "sRollo.mParams.homeButtonHeight=" + mParams.homeButtonHeight);
1591 Log.d(TAG, "sRollo.mParams.homeButtonTextureWidth=" + mParams.homeButtonTextureWidth);
1592 Log.d(TAG, "sRollo.mParams.homeButtonTextureHeight=" + mParams.homeButtonTextureHeight);
Daniel Sandler388f6792010-03-02 14:08:08 -05001593 }
1594 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001595
Daniel Sandler388f6792010-03-02 14:08:08 -05001596 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001597 Log.d(TAG, "sRS=" + sRS);
1598 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001599 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001600 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1601 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001602 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1603 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1604 Log.d(TAG, "mLastSelection=" + mLastSelection);
1605 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1606 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1607 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1608 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
1609 Log.d(TAG, "mZoomDirty=" + mZoomDirty);
1610 Log.d(TAG, "mAnimateNextZoom=" + mAnimateNextZoom);
1611 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001612 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001613 Log.d(TAG, "mVelocity=" + mVelocity);
1614 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001615 if (sRollo != null) {
1616 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001617 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001618 if (sRS != null) {
1619 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001620 }
1621 }
1622}
1623
1624