blob: 64c8c4c53c8d224bee9fc605f0f80c030ecab25e [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
Daniel Sandlerdca66122010-04-13 16:23:58 -040076 private static final int BATCH_SIZE = 0; // give us all the apps at once
77
Daniel Sandler388f6792010-03-02 14:08:08 -050078 private Launcher mLauncher;
79 private DragController mDragController;
80
81 /** When this is 0, modifications are allowed, when it's not, they're not.
82 * TODO: What about scrolling? */
83 private int mLocks = LOCK_ICONS_PENDING;
84
85 private int mSlop;
86 private int mMaxFlingVelocity;
87
88 private Defines mDefines = new Defines();
Daniel Sandler388f6792010-03-02 14:08:08 -050089 private ArrayList<ApplicationInfo> mAllAppsList;
90
Joe Onorato2cc62e82010-03-17 20:23:53 -070091 private static RenderScriptGL sRS;
92 private static RolloRS sRollo;
Jason Samsdd8cd8b2010-03-11 12:38:48 -080093
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;
123 private boolean mZoomDirty = false;
124 private boolean mAnimateNextZoom;
125 private float mNextZoom;
126 private float mZoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500127 private float mVelocity;
128 private AAMessage mMessageProc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800129
Romain Guy060b5c82010-03-04 10:07:38 -0800130 private int mColumnsPerPage;
131 private int mRowsPerPage;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800132 private boolean mSurrendered;
133
Romain Guyc16fea72010-03-12 17:17:56 -0800134 private int mRestoreFocusIndex = -1;
135
Romain Guy060b5c82010-03-04 10:07:38 -0800136 @SuppressWarnings({"UnusedDeclaration"})
Daniel Sandler388f6792010-03-02 14:08:08 -0500137 static class Defines {
138 public static final int ALLOC_PARAMS = 0;
139 public static final int ALLOC_STATE = 1;
140 public static final int ALLOC_ICON_IDS = 3;
141 public static final int ALLOC_LABEL_IDS = 4;
142 public static final int ALLOC_VP_CONSTANTS = 5;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800143
Romain Guy060b5c82010-03-04 10:07:38 -0800144 public static final int COLUMNS_PER_PAGE_PORTRAIT = 4;
145 public static final int ROWS_PER_PAGE_PORTRAIT = 4;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800146
Romain Guy060b5c82010-03-04 10:07:38 -0800147 public static final int COLUMNS_PER_PAGE_LANDSCAPE = 6;
148 public static final int ROWS_PER_PAGE_LANDSCAPE = 3;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800149
Daniel Sandler388f6792010-03-02 14:08:08 -0500150 public static final int ICON_WIDTH_PX = 64;
151 public static final int ICON_TEXTURE_WIDTH_PX = 74;
152 public static final int SELECTION_TEXTURE_WIDTH_PX = 74 + 20;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800153
Daniel Sandler388f6792010-03-02 14:08:08 -0500154 public static final int ICON_HEIGHT_PX = 64;
155 public static final int ICON_TEXTURE_HEIGHT_PX = 74;
156 public static final int SELECTION_TEXTURE_HEIGHT_PX = 74 + 20;
157 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800158
Daniel Sandler388f6792010-03-02 14:08:08 -0500159 public AllApps3D(Context context, AttributeSet attrs) {
160 super(context, attrs);
161 setFocusable(true);
162 setSoundEffectsEnabled(false);
163 getHolder().setFormat(PixelFormat.TRANSLUCENT);
164 final ViewConfiguration config = ViewConfiguration.get(context);
165 mSlop = config.getScaledTouchSlop();
166 mMaxFlingVelocity = config.getScaledMaximumFlingVelocity();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800167
Daniel Sandler388f6792010-03-02 14:08:08 -0500168 setOnClickListener(this);
169 setOnLongClickListener(this);
170 setZOrderOnTop(true);
171 getHolder().setFormat(PixelFormat.TRANSLUCENT);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800172
Joe Onorato2cc62e82010-03-17 20:23:53 -0700173 if (sRS == null) {
174 sRS = createRenderScript(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800175 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700176 createRenderScript(sRS);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800177 }
178
Romain Guy060b5c82010-03-04 10:07:38 -0800179 final DisplayMetrics metrics = getResources().getDisplayMetrics();
180 final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
181 mColumnsPerPage = isPortrait ? Defines.COLUMNS_PER_PAGE_PORTRAIT :
182 Defines.COLUMNS_PER_PAGE_LANDSCAPE;
183 mRowsPerPage = isPortrait ? Defines.ROWS_PER_PAGE_PORTRAIT :
184 Defines.ROWS_PER_PAGE_LANDSCAPE;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800185
Joe Onorato2cc62e82010-03-17 20:23:53 -0700186 if (sRollo != null) {
187 sRollo.mAllApps = this;
188 sRollo.mRes = getResources();
189 sRollo.mInitialize = true;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800190 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500191 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800192
Romain Guy060b5c82010-03-04 10:07:38 -0800193 @SuppressWarnings({"UnusedDeclaration"})
194 public AllApps3D(Context context, AttributeSet attrs, int defStyle) {
195 this(context, attrs);
196 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800197
Romain Guy13c2e7b2010-03-10 19:45:00 -0800198 public void surrender() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400199 if (sRS != null) {
200 sRS.contextSetSurface(0, 0, null);
201 sRS.mMessageCallback = null;
202 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800203 mSurrendered = true;
204 }
205
Daniel Sandler388f6792010-03-02 14:08:08 -0500206 /**
207 * Note that this implementation prohibits this view from ever being reattached.
208 */
209 @Override
210 protected void onDetachedFromWindow() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700211 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800212 if (!mSurrendered) {
Joe Onorato96da4012010-03-17 20:03:24 -0700213 Log.i(TAG, "onDetachedFromWindow");
Romain Guy13c2e7b2010-03-10 19:45:00 -0800214 destroyRenderScript();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700215 sRS = null;
216 sRollo = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800217 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500218 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800219
Daniel Sandler388f6792010-03-02 14:08:08 -0500220 /**
221 * If you have an attached click listener, View always plays the click sound!?!?
222 * Deal with sound effects by hand.
223 */
224 public void reallyPlaySoundEffect(int sound) {
225 boolean old = isSoundEffectsEnabled();
226 setSoundEffectsEnabled(true);
227 playSoundEffect(sound);
228 setSoundEffectsEnabled(old);
229 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800230
Daniel Sandler388f6792010-03-02 14:08:08 -0500231 public void setLauncher(Launcher launcher) {
232 mLauncher = launcher;
233 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800234
Daniel Sandler388f6792010-03-02 14:08:08 -0500235 @Override
236 public void surfaceDestroyed(SurfaceHolder holder) {
237 super.surfaceDestroyed(holder);
238 // Without this, we leak mMessageCallback which leaks the context.
Romain Guy13c2e7b2010-03-10 19:45:00 -0800239 if (!mSurrendered) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700240 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800241 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500242 // We may lose any callbacks that are pending, so make sure that we re-sync that
243 // on the next surfaceChanged.
244 mZoomDirty = true;
245 mHaveSurface = false;
246 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800247
Daniel Sandler388f6792010-03-02 14:08:08 -0500248 @Override
249 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
250 //long startTime = SystemClock.uptimeMillis();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800251
Daniel Sandler388f6792010-03-02 14:08:08 -0500252 super.surfaceChanged(holder, format, w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800253
Romain Guy13c2e7b2010-03-10 19:45:00 -0800254 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800255
Daniel Sandler388f6792010-03-02 14:08:08 -0500256 mHaveSurface = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800257
Joe Onorato2cc62e82010-03-17 20:23:53 -0700258 if (sRollo == null) {
259 sRollo = new RolloRS(this);
260 sRollo.init(getResources(), w, h);
Daniel Sandler388f6792010-03-02 14:08:08 -0500261 if (mAllAppsList != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700262 sRollo.setApps(mAllAppsList);
Daniel Sandler388f6792010-03-02 14:08:08 -0500263 }
264 if (mShouldGainFocus) {
265 gainFocus();
266 mShouldGainFocus = false;
267 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700268 } else if (sRollo.mInitialize) {
269 sRollo.initGl();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700270 sRollo.mInitialize = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500271 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800272
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700273 initTouchState(w, h);
274
Joe Onorato2cc62e82010-03-17 20:23:53 -0700275 sRollo.dirtyCheck();
276 sRollo.resize(w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800277
Joe Onorato2cc62e82010-03-17 20:23:53 -0700278 if (sRS != null) {
279 sRS.mMessageCallback = mMessageProc = new AAMessage();
Daniel Sandler388f6792010-03-02 14:08:08 -0500280 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800281
Joe Onorato2cc62e82010-03-17 20:23:53 -0700282 if (sRollo.mUniformAlloc != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500283 float tf[] = new float[] {72.f, 72.f,
284 120.f, 120.f, 0.f, 0.f,
285 120.f, 680.f,
286 (2.f / 480.f), 0, -((float)w / 2) - 0.25f, -380.25f};
287 if (w > h) {
288 tf[6] = 40.f;
289 tf[7] = h - 40.f;
290 tf[9] = 1.f;
291 tf[10] = -((float)w / 2) - 0.25f;
292 tf[11] = -((float)h / 2) - 0.25f;
293 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800294
Joe Onorato2cc62e82010-03-17 20:23:53 -0700295 sRollo.mUniformAlloc.data(tf);
Daniel Sandler388f6792010-03-02 14:08:08 -0500296 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800297
Daniel Sandler388f6792010-03-02 14:08:08 -0500298 //long endTime = SystemClock.uptimeMillis();
299 //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
300 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800301
Daniel Sandler388f6792010-03-02 14:08:08 -0500302 @Override
303 public void onWindowFocusChanged(boolean hasWindowFocus) {
304 super.onWindowFocusChanged(hasWindowFocus);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800305
306 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800307
Daniel Sandler388f6792010-03-02 14:08:08 -0500308 if (mArrowNavigation) {
309 if (!hasWindowFocus) {
310 // Clear selection when we lose window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700311 mLastSelectedIcon = sRollo.mState.selectedIconIndex;
312 sRollo.setHomeSelected(SELECTED_NONE);
313 sRollo.clearSelectedIcon();
314 sRollo.mState.save();
Romain Guy060b5c82010-03-04 10:07:38 -0800315 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700316 if (sRollo.mState.iconCount > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500317 if (mLastSelection == SELECTION_ICONS) {
318 int selection = mLastSelectedIcon;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700319 final int firstIcon = Math.round(sRollo.mScrollPos) * mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500320 if (selection < 0 || // No selection
321 selection < firstIcon || // off the top of the screen
Joe Onorato2cc62e82010-03-17 20:23:53 -0700322 selection >= sRollo.mState.iconCount || // past last icon
Daniel Sandler388f6792010-03-02 14:08:08 -0500323 selection >= firstIcon + // past last icon on screen
Romain Guy060b5c82010-03-04 10:07:38 -0800324 (mColumnsPerPage * mRowsPerPage)) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500325 selection = firstIcon;
326 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800327
Daniel Sandler388f6792010-03-02 14:08:08 -0500328 // Select the first icon when we gain window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700329 sRollo.selectIcon(selection, SELECTED_FOCUSED);
330 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500331 } else if (mLastSelection == SELECTION_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700332 sRollo.setHomeSelected(SELECTED_FOCUSED);
333 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500334 }
335 }
336 }
337 }
338 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800339
Daniel Sandler388f6792010-03-02 14:08:08 -0500340 @Override
341 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
342 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800343
Romain Guy13c2e7b2010-03-10 19:45:00 -0800344 if (!isVisible() || mSurrendered) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500345 return;
346 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800347
Daniel Sandler388f6792010-03-02 14:08:08 -0500348 if (gainFocus) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700349 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500350 gainFocus();
351 } else {
352 mShouldGainFocus = true;
353 }
354 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700355 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500356 if (mArrowNavigation) {
357 // Clear selection when we lose focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700358 sRollo.clearSelectedIcon();
359 sRollo.setHomeSelected(SELECTED_NONE);
360 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500361 mArrowNavigation = false;
362 }
363 } else {
364 mShouldGainFocus = false;
365 }
366 }
367 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800368
Daniel Sandler388f6792010-03-02 14:08:08 -0500369 private void gainFocus() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700370 if (!mArrowNavigation && sRollo.mState.iconCount > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500371 // Select the first icon when we gain keyboard focus
372 mArrowNavigation = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700373 sRollo.selectIcon(Math.round(sRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED);
374 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500375 }
376 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800377
Daniel Sandler388f6792010-03-02 14:08:08 -0500378 @Override
379 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800380
Daniel Sandler388f6792010-03-02 14:08:08 -0500381 boolean handled = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800382
Daniel Sandler388f6792010-03-02 14:08:08 -0500383 if (!isVisible()) {
384 return false;
385 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700386 final int iconCount = sRollo.mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800387
Daniel Sandler388f6792010-03-02 14:08:08 -0500388 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
389 if (mArrowNavigation) {
390 if (mLastSelection == SELECTION_HOME) {
391 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
392 mLauncher.closeAllApps(true);
393 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700394 int whichApp = sRollo.mState.selectedIconIndex;
Daniel Sandler388f6792010-03-02 14:08:08 -0500395 if (whichApp >= 0) {
396 ApplicationInfo app = mAllAppsList.get(whichApp);
Joe Onoratof984e852010-03-25 09:47:45 -0700397 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500398 handled = true;
399 }
400 }
401 }
402 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800403
Daniel Sandler388f6792010-03-02 14:08:08 -0500404 if (iconCount > 0) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800405 final boolean isPortrait = getWidth() < getHeight();
406
Daniel Sandler388f6792010-03-02 14:08:08 -0500407 mArrowNavigation = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800408
Joe Onorato2cc62e82010-03-17 20:23:53 -0700409 int currentSelection = sRollo.mState.selectedIconIndex;
410 int currentTopRow = Math.round(sRollo.mScrollPos);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800411
Romain Guy060b5c82010-03-04 10:07:38 -0800412 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1
413 final int currentPageCol = currentSelection % mColumnsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800414
Romain Guy060b5c82010-03-04 10:07:38 -0800415 // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1
Romain Guy6a42cf32010-03-12 16:03:52 -0800416 final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage))
Romain Guy060b5c82010-03-04 10:07:38 -0800417 / mRowsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800418
Daniel Sandler388f6792010-03-02 14:08:08 -0500419 int newSelection = currentSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800420
Daniel Sandler388f6792010-03-02 14:08:08 -0500421 switch (keyCode) {
422 case KeyEvent.KEYCODE_DPAD_UP:
423 if (mLastSelection == SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800424 if (isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700425 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guy6a42cf32010-03-12 16:03:52 -0800426 int lastRowCount = iconCount % mColumnsPerPage;
427 if (lastRowCount == 0) {
428 lastRowCount = mColumnsPerPage;
429 }
430 newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2);
431 if (newSelection >= iconCount) {
432 newSelection = iconCount-1;
433 }
434 int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
435 if (target < 0) {
436 target = 0;
437 }
438 if (currentTopRow != target) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700439 sRollo.moveTo(target);
Romain Guy6a42cf32010-03-12 16:03:52 -0800440 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500441 }
442 } else {
443 if (currentPageRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800444 newSelection = currentSelection - mColumnsPerPage;
Romain Guy6a42cf32010-03-12 16:03:52 -0800445 if (currentTopRow > newSelection / mColumnsPerPage) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700446 sRollo.moveTo(newSelection / mColumnsPerPage);
Romain Guy6a42cf32010-03-12 16:03:52 -0800447 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500448 } else if (currentTopRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800449 newSelection = currentSelection - mColumnsPerPage;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700450 sRollo.moveTo(newSelection / mColumnsPerPage);
Daniel Sandler388f6792010-03-02 14:08:08 -0500451 } else if (currentPageRow != 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800452 newSelection = currentTopRow * mRowsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500453 }
454 }
455 handled = true;
456 break;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800457
Daniel Sandler388f6792010-03-02 14:08:08 -0500458 case KeyEvent.KEYCODE_DPAD_DOWN: {
Romain Guy060b5c82010-03-04 10:07:38 -0800459 final int rowCount = iconCount / mColumnsPerPage
460 + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
461 final int currentRow = currentSelection / mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500462 if (mLastSelection != SELECTION_HOME) {
463 if (currentRow < rowCount-1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700464 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500465 if (currentSelection < 0) {
466 newSelection = 0;
467 } else {
Romain Guy060b5c82010-03-04 10:07:38 -0800468 newSelection = currentSelection + mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500469 }
470 if (newSelection >= iconCount) {
471 // Go from D to G in this arrangement:
472 // A B C D
473 // E F G
474 newSelection = iconCount - 1;
475 }
Romain Guy060b5c82010-03-04 10:07:38 -0800476 if (currentPageRow >= mRowsPerPage - 1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700477 sRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -0500478 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800479 } else if (isPortrait) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500480 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700481 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500482 }
483 }
484 handled = true;
485 break;
486 }
487 case KeyEvent.KEYCODE_DPAD_LEFT:
488 if (mLastSelection != SELECTION_HOME) {
489 if (currentPageCol > 0) {
490 newSelection = currentSelection - 1;
491 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800492 } else if (!isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700493 newSelection = ((int) (sRollo.mScrollPos) * mColumnsPerPage) +
Romain Guy6a42cf32010-03-12 16:03:52 -0800494 (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700495 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500496 }
497 handled = true;
498 break;
499 case KeyEvent.KEYCODE_DPAD_RIGHT:
500 if (mLastSelection != SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800501 if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 ||
502 currentSelection == iconCount - 1)) {
503 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700504 sRollo.setHomeSelected(SELECTED_FOCUSED);
Romain Guy6a42cf32010-03-12 16:03:52 -0800505 } else if ((currentPageCol < mColumnsPerPage - 1) &&
Daniel Sandler388f6792010-03-02 14:08:08 -0500506 (currentSelection < iconCount - 1)) {
507 newSelection = currentSelection + 1;
508 }
509 }
510 handled = true;
511 break;
512 }
513 if (newSelection != currentSelection) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700514 sRollo.selectIcon(newSelection, SELECTED_FOCUSED);
515 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500516 }
517 }
518 return handled;
519 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800520
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700521 void initTouchState(int width, int height) {
522 boolean isPortrait = width < height;
523
524 int[] viewPos = new int[2];
525 getLocationOnScreen(viewPos);
526
527 mTouchXBorders = new int[mColumnsPerPage + 1];
528 mTouchYBorders = new int[mRowsPerPage + 1];
529
530 // TODO: Put this in a config file/define
531 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE_PORTRAIT;
532 if (!isPortrait) cellHeight -= 12;
533 int centerY = (int) (height * (isPortrait ? 0.5f : 0.47f));
534 if (!isPortrait) centerY += cellHeight / 2;
535 int half = (int) Math.floor((mRowsPerPage + 1) / 2);
536 int end = mTouchYBorders.length - (half + 1);
537
538 for (int i = -half; i <= end; i++) {
539 mTouchYBorders[i + half] = centerY + (i * cellHeight) - viewPos[1];
540 }
541
542 int x = 0;
543 // TODO: Put this in a config file/define
544 int columnWidth = 120;
545 for (int i = 0; i < mColumnsPerPage + 1; i++) {
546 mTouchXBorders[i] = x - viewPos[0];
547 x += columnWidth;
548 }
549 }
550
551 int chooseTappedIcon(int x, int y) {
552 float pos = sRollo != null ? sRollo.mScrollPos : 0;
553
554 int oldY = y;
555
556 // Adjust for scroll position if not zero.
557 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
558
559 int col = -1;
560 int row = -1;
561 final int columnsCount = mColumnsPerPage;
562 for (int i=0; i< columnsCount; i++) {
563 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
564 col = i;
565 break;
566 }
567 }
568 final int rowsCount = mRowsPerPage;
569 for (int i=0; i< rowsCount; i++) {
570 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
571 row = i;
572 break;
573 }
574 }
575
576 if (row < 0 || col < 0) {
577 return -1;
578 }
579
580 int index = (((int) pos) * columnsCount) + (row * columnsCount) + col;
581
582 if (index >= mAllAppsList.size()) {
583 return -1;
584 } else {
585 return index;
586 }
587 }
588
Daniel Sandler388f6792010-03-02 14:08:08 -0500589 @Override
590 public boolean onTouchEvent(MotionEvent ev)
591 {
592 mArrowNavigation = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800593
Daniel Sandler388f6792010-03-02 14:08:08 -0500594 if (!isVisible()) {
595 return true;
596 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800597
Daniel Sandler388f6792010-03-02 14:08:08 -0500598 if (mLocks != 0) {
599 return true;
600 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800601
Daniel Sandler388f6792010-03-02 14:08:08 -0500602 super.onTouchEvent(ev);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800603
Daniel Sandler388f6792010-03-02 14:08:08 -0500604 int x = (int)ev.getX();
605 int y = (int)ev.getY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800606
Romain Guyce115852010-03-04 12:15:37 -0800607 final boolean isPortrait = getWidth() < getHeight();
Daniel Sandler388f6792010-03-02 14:08:08 -0500608 int action = ev.getAction();
609 switch (action) {
610 case MotionEvent.ACTION_DOWN:
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700611 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
612 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500613 mTouchTracking = TRACKING_HOME;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700614 sRollo.setHomeSelected(SELECTED_PRESSED);
615 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500616 mCurrentIconIndex = -1;
617 } else {
618 mTouchTracking = TRACKING_FLING;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800619
Daniel Sandler388f6792010-03-02 14:08:08 -0500620 mMotionDownRawX = (int)ev.getRawX();
621 mMotionDownRawY = (int)ev.getRawY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800622
Joe Onorato2cc62e82010-03-17 20:23:53 -0700623 sRollo.mState.newPositionX = ev.getRawY() / getHeight();
624 sRollo.mState.newTouchDown = 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800625
Joe Onorato2cc62e82010-03-17 20:23:53 -0700626 if (!sRollo.checkClickOK()) {
627 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500628 } else {
629 mDownIconIndex = mCurrentIconIndex
Joe Onorato2cc62e82010-03-17 20:23:53 -0700630 = sRollo.selectIcon(x, y, SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500631 if (mDownIconIndex < 0) {
632 // if nothing was selected, no long press.
633 cancelLongPress();
634 }
635 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700636 sRollo.mState.save();
637 sRollo.move();
Daniel Sandler388f6792010-03-02 14:08:08 -0500638 mVelocityTracker = VelocityTracker.obtain();
639 mVelocityTracker.addMovement(ev);
640 mStartedScrolling = false;
641 }
642 break;
643 case MotionEvent.ACTION_MOVE:
644 case MotionEvent.ACTION_OUTSIDE:
645 if (mTouchTracking == TRACKING_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700646 sRollo.setHomeSelected((isPortrait &&
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700647 y > mTouchYBorders[mTouchYBorders.length-1]) || (!isPortrait
648 && x > mTouchXBorders[mTouchXBorders.length-1])
Daniel Sandler388f6792010-03-02 14:08:08 -0500649 ? SELECTED_PRESSED : SELECTED_NONE);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700650 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500651 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500652 int rawY = (int)ev.getRawY();
653 int slop;
654 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800655
Daniel Sandler388f6792010-03-02 14:08:08 -0500656 if (!mStartedScrolling && slop < mSlop) {
657 // don't update anything so when we do start scrolling
658 // below, we get the right delta.
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700659 mCurrentIconIndex = chooseTappedIcon(x, y);
Daniel Sandler388f6792010-03-02 14:08:08 -0500660 if (mDownIconIndex != mCurrentIconIndex) {
661 // If a different icon is selected, don't allow it to be picked up.
662 // This handles off-axis dragging.
663 cancelLongPress();
664 mCurrentIconIndex = -1;
665 }
666 } else {
667 if (!mStartedScrolling) {
668 cancelLongPress();
669 mCurrentIconIndex = -1;
670 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700671 sRollo.mState.newPositionX = ev.getRawY() / getHeight();
672 sRollo.mState.newTouchDown = 1;
673 sRollo.move();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800674
Daniel Sandler388f6792010-03-02 14:08:08 -0500675 mStartedScrolling = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700676 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500677 mVelocityTracker.addMovement(ev);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700678 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500679 }
680 }
681 break;
682 case MotionEvent.ACTION_UP:
683 case MotionEvent.ACTION_CANCEL:
684 if (mTouchTracking == TRACKING_HOME) {
685 if (action == MotionEvent.ACTION_UP) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700686 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
687 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500688 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
689 mLauncher.closeAllApps(true);
690 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700691 sRollo.setHomeSelected(SELECTED_NONE);
692 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500693 }
694 mCurrentIconIndex = -1;
695 } else if (mTouchTracking == TRACKING_FLING) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700696 sRollo.mState.newTouchDown = 0;
697 sRollo.mState.newPositionX = ev.getRawY() / getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800698
Daniel Sandler388f6792010-03-02 14:08:08 -0500699 mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700700 sRollo.mState.flingVelocity = mVelocityTracker.getYVelocity() / getHeight();
701 sRollo.clearSelectedIcon();
702 sRollo.mState.save();
703 sRollo.fling();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800704
Daniel Sandler388f6792010-03-02 14:08:08 -0500705 if (mVelocityTracker != null) {
706 mVelocityTracker.recycle();
707 mVelocityTracker = null;
708 }
709 }
710 mTouchTracking = TRACKING_NONE;
711 break;
712 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800713
Daniel Sandler388f6792010-03-02 14:08:08 -0500714 return true;
715 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800716
Daniel Sandler388f6792010-03-02 14:08:08 -0500717 public void onClick(View v) {
718 if (mLocks != 0 || !isVisible()) {
719 return;
720 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700721 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500722 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
723 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
724 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onoratof984e852010-03-25 09:47:45 -0700725 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500726 }
727 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800728
Daniel Sandler388f6792010-03-02 14:08:08 -0500729 public boolean onLongClick(View v) {
730 if (mLocks != 0 || !isVisible()) {
731 return true;
732 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700733 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500734 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
735 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800736
Daniel Sandler388f6792010-03-02 14:08:08 -0500737 Bitmap bmp = app.iconBitmap;
738 final int w = bmp.getWidth();
739 final int h = bmp.getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800740
Daniel Sandler388f6792010-03-02 14:08:08 -0500741 // We don't really have an accurate location to use. This will do.
742 int screenX = mMotionDownRawX - (w / 2);
743 int screenY = mMotionDownRawY - h;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800744
Daniel Sandler388f6792010-03-02 14:08:08 -0500745 mDragController.startDrag(bmp, screenX, screenY,
746 0, 0, w, h, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800747
Daniel Sandler388f6792010-03-02 14:08:08 -0500748 mLauncher.closeAllApps(true);
749 }
750 return true;
751 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800752
Daniel Sandler388f6792010-03-02 14:08:08 -0500753 @Override
754 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
755 if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
756 if (!isVisible()) {
757 return false;
758 }
759 String text = null;
760 int index;
761 int count = mAllAppsList.size() + 1; // +1 is home
762 int pos = -1;
763 switch (mLastSelection) {
764 case SELECTION_ICONS:
Joe Onorato2cc62e82010-03-17 20:23:53 -0700765 index = sRollo.mState.selectedIconIndex;
Daniel Sandler388f6792010-03-02 14:08:08 -0500766 if (index >= 0) {
767 ApplicationInfo info = mAllAppsList.get(index);
768 if (info.title != null) {
769 text = info.title.toString();
770 pos = index;
771 }
772 }
773 break;
774 case SELECTION_HOME:
775 text = getContext().getString(R.string.all_apps_home_button_label);
776 pos = count;
777 break;
778 }
779 if (text != null) {
780 event.setEnabled(true);
781 event.getText().add(text);
782 //event.setContentDescription(text);
783 event.setItemCount(count);
784 event.setCurrentItemIndex(pos);
785 }
786 }
787 return false;
788 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800789
Daniel Sandler388f6792010-03-02 14:08:08 -0500790 public void setDragController(DragController dragger) {
791 mDragController = dragger;
792 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800793
Daniel Sandler388f6792010-03-02 14:08:08 -0500794 public void onDropCompleted(View target, boolean success) {
795 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800796
Daniel Sandler388f6792010-03-02 14:08:08 -0500797 /**
798 * Zoom to the specifed level.
799 *
800 * @param zoom [0..1] 0 is hidden, 1 is open
801 */
802 public void zoom(float zoom, boolean animate) {
803 cancelLongPress();
804 mNextZoom = zoom;
805 mAnimateNextZoom = animate;
806 // if we do setZoom while we don't have a surface, we won't
807 // get the callbacks that actually set mZoom.
Joe Onorato2cc62e82010-03-17 20:23:53 -0700808 if (sRollo == null || !mHaveSurface) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500809 mZoomDirty = true;
810 mZoom = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500811 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700812 sRollo.setZoom(zoom, animate);
Daniel Sandler388f6792010-03-02 14:08:08 -0500813 }
814 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800815
Joe Onorato878f0862010-03-22 12:22:22 -0400816 /**
817 * If sRollo is null, then we're not visible. This is also used to guard against
818 * sRollo being null.
819 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500820 public boolean isVisible() {
Joe Onorato878f0862010-03-22 12:22:22 -0400821 return sRollo != null && mZoom > 0.001f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500822 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800823
Daniel Sandler388f6792010-03-02 14:08:08 -0500824 public boolean isOpaque() {
825 return mZoom > 0.999f;
826 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800827
Daniel Sandler388f6792010-03-02 14:08:08 -0500828 public void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700829 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500830 // We've been removed from the window. Don't bother with all this.
831 return;
832 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800833
834 boolean reload = false;
835 if (mAllAppsList == null) {
836 reload = true;
837 } else if (list.size() != mAllAppsList.size()) {
838 reload = true;
839 } else {
840 final int count = list.size();
841 for (int i = 0; i < count; i++) {
842 if (list.get(i) != mAllAppsList.get(i)) {
843 reload = true;
844 break;
845 }
846 }
847 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800848
Daniel Sandler388f6792010-03-02 14:08:08 -0500849 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700850 if (sRollo != null && reload) {
851 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500852 }
Romain Guyc16fea72010-03-12 17:17:56 -0800853
854 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700855 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
856 sRollo.mState.save();
Romain Guyc16fea72010-03-12 17:17:56 -0800857 mRestoreFocusIndex = -1;
858 }
859
Daniel Sandler388f6792010-03-02 14:08:08 -0500860 mLocks &= ~LOCK_ICONS_PENDING;
861 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800862
Daniel Sandler388f6792010-03-02 14:08:08 -0500863 public void addApps(ArrayList<ApplicationInfo> list) {
864 if (mAllAppsList == null) {
865 // Not done loading yet. We'll find out about it later.
866 return;
867 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700868 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500869 // We've been removed from the window. Don't bother with all this.
870 return;
871 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800872
Daniel Sandler388f6792010-03-02 14:08:08 -0500873 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700874 if (sRollo != null) {
875 sRollo.pause();
876 sRollo.reallocAppsList(sRollo.mState.iconCount + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500877 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800878
Daniel Sandler388f6792010-03-02 14:08:08 -0500879 for (int i=0; i<N; i++) {
880 final ApplicationInfo item = list.get(i);
881 int index = Collections.binarySearch(mAllAppsList, item,
882 LauncherModel.APP_NAME_COMPARATOR);
883 if (index < 0) {
884 index = -(index+1);
885 }
886 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700887 if (sRollo != null) {
888 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500889 }
890 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800891
Joe Onorato2cc62e82010-03-17 20:23:53 -0700892 if (sRollo != null) {
893 sRollo.saveAppsList();
894 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500895 }
896 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800897
Daniel Sandler388f6792010-03-02 14:08:08 -0500898 public void removeApps(ArrayList<ApplicationInfo> list) {
899 if (mAllAppsList == null) {
900 // Not done loading yet. We'll find out about it later.
901 return;
902 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800903
Joe Onorato2cc62e82010-03-17 20:23:53 -0700904 if (sRollo != null) {
905 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800906 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500907 final int N = list.size();
908 for (int i=0; i<N; i++) {
909 final ApplicationInfo item = list.get(i);
910 int index = findAppByComponent(mAllAppsList, item);
911 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500912 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700913 if (sRollo != null) {
914 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500915 }
916 } else {
917 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
918 // Try to recover. This should keep us from crashing for now.
919 }
920 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800921
Joe Onorato2cc62e82010-03-17 20:23:53 -0700922 if (sRollo != null) {
923 sRollo.saveAppsList();
924 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500925 }
926 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800927
Joe Onorato64e6be72010-03-05 15:05:52 -0500928 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500929 // Just remove and add, because they may need to be re-sorted.
930 removeApps(list);
931 addApps(list);
932 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800933
Daniel Sandler388f6792010-03-02 14:08:08 -0500934 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
935 ComponentName component = item.intent.getComponent();
936 final int N = list.size();
937 for (int i=0; i<N; i++) {
938 ApplicationInfo x = list.get(i);
939 if (x.intent.getComponent().equals(component)) {
940 return i;
941 }
942 }
943 return -1;
944 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800945
Romain Guy060b5c82010-03-04 10:07:38 -0800946 /*
Daniel Sandler388f6792010-03-02 14:08:08 -0500947 private static int countPages(int iconCount) {
Romain Guy060b5c82010-03-04 10:07:38 -0800948 int iconsPerPage = getColumnsCount() * Defines.ROWS_PER_PAGE_PORTRAIT;
Daniel Sandler388f6792010-03-02 14:08:08 -0500949 int pages = iconCount / iconsPerPage;
950 if (pages*iconsPerPage != iconCount) {
951 pages++;
952 }
953 return pages;
954 }
Romain Guy060b5c82010-03-04 10:07:38 -0800955 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500956
957 class AAMessage extends RenderScript.RSMessage {
958 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700959 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500960 mVelocity = ((float)mData[1]) / (1 << 16);
961 mZoom = ((float)mData[2]) / (1 << 16);
962 mZoomDirty = false;
963 }
964 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800965
Romain Guy13c2e7b2010-03-10 19:45:00 -0800966 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500967 // Allocations ======
968 private int mWidth;
969 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800970
Daniel Sandler388f6792010-03-02 14:08:08 -0500971 private Resources mRes;
972 private Script mScript;
973 private Script.Invokable mInvokeMove;
974 private Script.Invokable mInvokeMoveTo;
975 private Script.Invokable mInvokeFling;
976 private Script.Invokable mInvokeResetWAR;
977 private Script.Invokable mInvokeSetZoom;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800978
Daniel Sandler388f6792010-03-02 14:08:08 -0500979 private ProgramStore mPSIcons;
980 private ProgramFragment mPFTexMip;
981 private ProgramFragment mPFTexMipAlpha;
982 private ProgramFragment mPFTexNearest;
983 private ProgramVertex mPV;
984 private ProgramVertex mPVCurve;
985 private SimpleMesh mMesh;
986 private ProgramVertex.MatrixAllocation mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800987
Daniel Sandler388f6792010-03-02 14:08:08 -0500988 private Allocation mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800989
Daniel Sandler388f6792010-03-02 14:08:08 -0500990 private Allocation mHomeButtonNormal;
991 private Allocation mHomeButtonFocused;
992 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800993
Daniel Sandler388f6792010-03-02 14:08:08 -0500994 private Allocation[] mIcons;
995 private int[] mIconIds;
996 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800997
Daniel Sandler388f6792010-03-02 14:08:08 -0500998 private Allocation[] mLabels;
999 private int[] mLabelIds;
1000 private Allocation mAllocLabelIds;
1001 private Allocation mSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001002
Daniel Sandler388f6792010-03-02 14:08:08 -05001003 private Bitmap mSelectionBitmap;
1004 private Canvas mSelectionCanvas;
Romain Guy6a42cf32010-03-12 16:03:52 -08001005
1006 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001007
Daniel Sandler388f6792010-03-02 14:08:08 -05001008 Params mParams;
1009 State mState;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001010
Romain Guy13c2e7b2010-03-10 19:45:00 -08001011 AllApps3D mAllApps;
1012 boolean mInitialize;
1013
Daniel Sandler388f6792010-03-02 14:08:08 -05001014 class BaseAlloc {
1015 Allocation mAlloc;
1016 Type mType;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001017
Daniel Sandler388f6792010-03-02 14:08:08 -05001018 void save() {
1019 mAlloc.data(this);
1020 }
1021 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001022
Daniel Sandler388f6792010-03-02 14:08:08 -05001023 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001024 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -08001025 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -05001026 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001027
1028 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001029 if (sRS != null) {
1030 sRS.contextBindRootScript(null);
1031 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001032 }
1033
1034 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001035 if (sRS != null) {
1036 sRS.contextBindRootScript(mScript);
1037 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001038 }
1039
Daniel Sandler388f6792010-03-02 14:08:08 -05001040 class Params extends BaseAlloc {
1041 Params() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001042 mType = Type.createFromClass(sRS, Params.class, 1, "ParamsClass");
1043 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001044 save();
1045 }
1046 public int bubbleWidth;
1047 public int bubbleHeight;
1048 public int bubbleBitmapWidth;
1049 public int bubbleBitmapHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001050
Daniel Sandler388f6792010-03-02 14:08:08 -05001051 public int homeButtonWidth;
1052 public int homeButtonHeight;
1053 public int homeButtonTextureWidth;
1054 public int homeButtonTextureHeight;
1055 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001056
Daniel Sandler388f6792010-03-02 14:08:08 -05001057 class State extends BaseAlloc {
1058 public float newPositionX;
1059 public int newTouchDown;
1060 public float flingVelocity;
1061 public int iconCount;
1062 public int selectedIconIndex = -1;
1063 public int selectedIconTexture;
1064 public float zoomTarget;
1065 public int homeButtonId;
1066 public float targetPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001067
Daniel Sandler388f6792010-03-02 14:08:08 -05001068 State() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001069 mType = Type.createFromClass(sRS, State.class, 1, "StateClass");
1070 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001071 save();
1072 }
1073 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001074
Romain Guy13c2e7b2010-03-10 19:45:00 -08001075 public RolloRS(AllApps3D allApps) {
1076 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -05001077 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001078
Daniel Sandler388f6792010-03-02 14:08:08 -05001079 public void init(Resources res, int width, int height) {
1080 mRes = res;
1081 mWidth = width;
1082 mHeight = height;
1083 initProgramVertex();
1084 initProgramFragment();
1085 initProgramStore();
1086 initGl();
1087 initData();
Daniel Sandler388f6792010-03-02 14:08:08 -05001088 initRs();
1089 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001090
Daniel Sandler388f6792010-03-02 14:08:08 -05001091 public void initMesh() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001092 SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001093
Daniel Sandler388f6792010-03-02 14:08:08 -05001094 for (int ct=0; ct < 16; ct++) {
1095 float pos = (1.f / (16.f - 1)) * ct;
1096 tm.addVertex(0.0f, pos);
1097 tm.addVertex(1.0f, pos);
1098 }
1099 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1100 tm.addTriangle(ct, ct+1, ct+2);
1101 tm.addTriangle(ct+1, ct+3, ct+2);
1102 }
1103 mMesh = tm.create();
1104 mMesh.setName("SMCell");
1105 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001106
Daniel Sandler388f6792010-03-02 14:08:08 -05001107 void resize(int w, int h) {
1108 mPVA.setupProjectionNormalized(w, h);
1109 mWidth = w;
1110 mHeight = h;
1111 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001112
Daniel Sandler388f6792010-03-02 14:08:08 -05001113 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001114 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001115 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001116
Joe Onorato2cc62e82010-03-17 20:23:53 -07001117 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001118 pvb.setTextureMatrixEnable(true);
1119 mPV = pvb.create();
1120 mPV.setName("PV");
1121 mPV.bindAllocation(mPVA);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001122
Joe Onorato2cc62e82010-03-17 20:23:53 -07001123 Element.Builder eb = new Element.Builder(sRS);
1124 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "ImgSize");
1125 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "Position");
1126 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "BendPos");
1127 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "ScaleOffset");
Daniel Sandler388f6792010-03-02 14:08:08 -05001128 Element e = eb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001129
Joe Onorato2cc62e82010-03-17 20:23:53 -07001130 mUniformAlloc = Allocation.createSized(sRS, e, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001131
Daniel Sandler388f6792010-03-02 14:08:08 -05001132 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001133 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Romain Guy060b5c82010-03-04 10:07:38 -08001134 String t = "void main() {\n" +
1135 // Animation
1136 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001137
Romain Guy060b5c82010-03-04 10:07:38 -08001138 " float bendY1 = UNI_BendPos.x;\n" +
1139 " float bendY2 = UNI_BendPos.y;\n" +
1140 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1141 " float bendDistance = bendY1 * 0.4;\n" +
1142 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001143
Romain Guy060b5c82010-03-04 10:07:38 -08001144 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1145 " float aDy = cos(bendAngle);\n" +
1146 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001147
Romain Guy060b5c82010-03-04 10:07:38 -08001148 " float scale = (2.0 / 480.0);\n" +
1149 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1150 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1151 " float y = 0.0;\n" +
1152 " float z = 0.0;\n" +
1153 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001154
Romain Guy060b5c82010-03-04 10:07:38 -08001155 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1156 " y += cv * aDy;\n" +
1157 " z += -cv * aDz;\n" +
1158 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1159 " lum += cv / bendDistance * distanceDimLevel;\n" +
1160 " y += cv * cos(cv * bendStep);\n" +
1161 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001162
Romain Guy060b5c82010-03-04 10:07:38 -08001163 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1164 " y += cv * aDy;\n" +
1165 " z += cv * aDz;\n" +
1166 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1167 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1168 " y += cv * cos(cv * bendStep);\n" +
1169 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001170
Romain Guy060b5c82010-03-04 10:07:38 -08001171 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001172
Romain Guy060b5c82010-03-04 10:07:38 -08001173 " vec4 pos;\n" +
1174 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1175 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1176 " pos.z = z * UNI_ScaleOffset.x;\n" +
1177 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001178
Romain Guy060b5c82010-03-04 10:07:38 -08001179 " pos.x *= 1.0 + ani * 4.0;\n" +
1180 " pos.y *= 1.0 + ani * 4.0;\n" +
1181 " pos.z -= ani * 1.5;\n" +
1182 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001183
Romain Guy060b5c82010-03-04 10:07:38 -08001184 " gl_Position = UNI_MVP * pos;\n" +
1185 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1186 " varTex0.xy = ATTRIB_position;\n" +
1187 " varTex0.y = 1.0 - varTex0.y;\n" +
1188 " varTex0.zw = vec2(0.0, 0.0);\n" +
1189 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001190 sb.setShader(t);
1191 sb.addConstant(mUniformAlloc.getType());
1192 sb.addInput(mMesh.getVertexType(0).getElement());
1193 mPVCurve = sb.create();
1194 mPVCurve.setName("PVCurve");
1195 mPVCurve.bindAllocation(mPVA);
1196 mPVCurve.bindConstants(mUniformAlloc, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001197
Joe Onorato2cc62e82010-03-17 20:23:53 -07001198 sRS.contextBindProgramVertex(mPV);
Daniel Sandler388f6792010-03-02 14:08:08 -05001199 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001200
Daniel Sandler388f6792010-03-02 14:08:08 -05001201 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001202 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001203 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1204 sb.setMag(Sampler.Value.NEAREST);
1205 sb.setWrapS(Sampler.Value.CLAMP);
1206 sb.setWrapT(Sampler.Value.CLAMP);
1207 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001208
Daniel Sandler388f6792010-03-02 14:08:08 -05001209 sb.setMin(Sampler.Value.NEAREST);
1210 sb.setMag(Sampler.Value.NEAREST);
1211 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001212
Joe Onorato2cc62e82010-03-17 20:23:53 -07001213 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001214 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1215 ProgramFragment.Builder.Format.RGBA, 0);
1216 mPFTexMip = bf.create();
1217 mPFTexMip.setName("PFTexMip");
1218 mPFTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001219
Daniel Sandler388f6792010-03-02 14:08:08 -05001220 mPFTexNearest = bf.create();
1221 mPFTexNearest.setName("PFTexNearest");
1222 mPFTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001223
Daniel Sandler388f6792010-03-02 14:08:08 -05001224 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1225 ProgramFragment.Builder.Format.ALPHA, 0);
1226 mPFTexMipAlpha = bf.create();
1227 mPFTexMipAlpha.setName("PFTexMipAlpha");
1228 mPFTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001229
Daniel Sandler388f6792010-03-02 14:08:08 -05001230 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001231
Daniel Sandler388f6792010-03-02 14:08:08 -05001232 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001233 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001234 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1235 bs.setColorMask(true,true,true,false);
1236 bs.setDitherEnable(true);
1237 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1238 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
1239 mPSIcons = bs.create();
1240 mPSIcons.setName("PSIcons");
1241 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001242
Daniel Sandler388f6792010-03-02 14:08:08 -05001243 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001244 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001245
Daniel Sandler388f6792010-03-02 14:08:08 -05001246 private void initData() {
1247 mParams = new Params();
1248 mState = new State();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001249
Romain Guy13c2e7b2010-03-10 19:45:00 -08001250 final Utilities.BubbleText bubble = new Utilities.BubbleText(mAllApps.getContext());
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001251
Daniel Sandler388f6792010-03-02 14:08:08 -05001252 mParams.bubbleWidth = bubble.getBubbleWidth();
1253 mParams.bubbleHeight = bubble.getMaxBubbleHeight();
1254 mParams.bubbleBitmapWidth = bubble.getBitmapWidth();
1255 mParams.bubbleBitmapHeight = bubble.getBitmapHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001256
Joe Onorato2cc62e82010-03-17 20:23:53 -07001257 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1258 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001259 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001260 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1261 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001262 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001263 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1264 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001265 mHomeButtonPressed.uploadToTexture(0);
1266 mParams.homeButtonWidth = 76;
1267 mParams.homeButtonHeight = 68;
1268 mParams.homeButtonTextureWidth = 128;
1269 mParams.homeButtonTextureHeight = 128;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001270
Daniel Sandler388f6792010-03-02 14:08:08 -05001271 mState.homeButtonId = mHomeButtonNormal.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001272
Daniel Sandler388f6792010-03-02 14:08:08 -05001273 mParams.save();
1274 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001275
Daniel Sandler388f6792010-03-02 14:08:08 -05001276 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1277 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1278 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001279
Daniel Sandler388f6792010-03-02 14:08:08 -05001280 setApps(null);
1281 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001282
Daniel Sandler388f6792010-03-02 14:08:08 -05001283 private void initRs() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001284 ScriptC.Builder sb = new ScriptC.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001285 sb.setScript(mRes, R.raw.allapps);
1286 sb.setRoot(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001287 sb.addDefines(mAllApps.mDefines);
Daniel Sandler388f6792010-03-02 14:08:08 -05001288 sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS);
1289 sb.setType(mState.mType, "state", Defines.ALLOC_STATE);
1290 sb.setType(mUniformAlloc.getType(), "vpConstants", Defines.ALLOC_VP_CONSTANTS);
1291 mInvokeMove = sb.addInvokable("move");
1292 mInvokeFling = sb.addInvokable("fling");
1293 mInvokeMoveTo = sb.addInvokable("moveTo");
1294 mInvokeResetWAR = sb.addInvokable("resetHWWar");
1295 mInvokeSetZoom = sb.addInvokable("setZoom");
1296 mScript = sb.create();
1297 mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1298 mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
1299 mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
1300 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1301 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
1302 mScript.bindAllocation(mUniformAlloc, Defines.ALLOC_VP_CONSTANTS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001303
Joe Onorato2cc62e82010-03-17 20:23:53 -07001304 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -05001305 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001306
Daniel Sandler388f6792010-03-02 14:08:08 -05001307 void dirtyCheck() {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001308 if (mAllApps.mZoomDirty) {
1309 setZoom(mAllApps.mNextZoom, mAllApps.mAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001310 }
1311 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001312
Romain Guy060b5c82010-03-04 10:07:38 -08001313 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001314 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001315 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001316 final int count = list != null ? list.size() : 0;
1317 int allocCount = count;
1318 if (allocCount < 1) {
1319 allocCount = 1;
1320 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001321
Daniel Sandler388f6792010-03-02 14:08:08 -05001322 mIcons = new Allocation[count];
1323 mIconIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001324 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001325
Daniel Sandler388f6792010-03-02 14:08:08 -05001326 mLabels = new Allocation[count];
1327 mLabelIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001328 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001329
Daniel Sandler388f6792010-03-02 14:08:08 -05001330 mState.iconCount = count;
1331 for (int i=0; i < mState.iconCount; i++) {
1332 createAppIconAllocations(i, list.get(i));
1333 }
1334 for (int i=0; i < mState.iconCount; i++) {
1335 uploadAppIcon(i, list.get(i));
1336 }
1337 saveAppsList();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001338 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001339 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001340
Daniel Sandler388f6792010-03-02 14:08:08 -05001341 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001342 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001343 sRollo.clearSelectedIcon();
1344 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001345 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001346 if (zoom > 0.001f) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001347 sRollo.mState.zoomTarget = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -05001348 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001349 sRollo.mState.zoomTarget = 0;
Daniel Sandler388f6792010-03-02 14:08:08 -05001350 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001351 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -05001352 if (!animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001353 sRollo.mInvokeSetZoom.execute();
Daniel Sandler388f6792010-03-02 14:08:08 -05001354 }
1355 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001356
Daniel Sandler388f6792010-03-02 14:08:08 -05001357 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001358 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1359 Element.RGBA_8888(sRS), false);
1360 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1361 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001362 mIconIds[index] = mIcons[index].getID();
1363 mLabelIds[index] = mLabels[index].getID();
1364 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001365
Daniel Sandler388f6792010-03-02 14:08:08 -05001366 private void uploadAppIcon(int index, ApplicationInfo item) {
1367 if (mIconIds[index] != mIcons[index].getID()) {
1368 throw new IllegalStateException("uploadAppIcon index=" + index
1369 + " mIcons[index].getID=" + mIcons[index].getID()
1370 + " mIconsIds[index]=" + mIconIds[index]
1371 + " item=" + item);
1372 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001373 mIcons[index].uploadToTexture(true, 0);
1374 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001375 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001376
Daniel Sandler388f6792010-03-02 14:08:08 -05001377 /**
1378 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1379 * fill in the values and call saveAppsList().
1380 */
1381 private void reallocAppsList(int count) {
1382 Allocation[] icons = new Allocation[count];
1383 int[] iconIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001384 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001385
Daniel Sandler388f6792010-03-02 14:08:08 -05001386 Allocation[] labels = new Allocation[count];
1387 int[] labelIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001388 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001389
Joe Onorato2cc62e82010-03-17 20:23:53 -07001390 final int oldCount = sRollo.mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001391
Daniel Sandler388f6792010-03-02 14:08:08 -05001392 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1393 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1394 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1395 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001396
Daniel Sandler388f6792010-03-02 14:08:08 -05001397 mIcons = icons;
1398 mIconIds = iconIds;
1399 mLabels = labels;
1400 mLabelIds = labelIds;
1401 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001402
Daniel Sandler388f6792010-03-02 14:08:08 -05001403 /**
1404 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1405 */
1406 private void addApp(int index, ApplicationInfo item) {
1407 final int count = mState.iconCount - index;
1408 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001409
Daniel Sandler388f6792010-03-02 14:08:08 -05001410 System.arraycopy(mIcons, index, mIcons, dest, count);
1411 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1412 System.arraycopy(mLabels, index, mLabels, dest, count);
1413 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001414
Daniel Sandler388f6792010-03-02 14:08:08 -05001415 createAppIconAllocations(index, item);
1416 uploadAppIcon(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001417 sRollo.mState.iconCount++;
Daniel Sandler388f6792010-03-02 14:08:08 -05001418 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001419
Daniel Sandler388f6792010-03-02 14:08:08 -05001420 /**
1421 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1422 */
1423 private void removeApp(int index) {
1424 final int count = mState.iconCount - index - 1;
1425 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001426
Daniel Sandler388f6792010-03-02 14:08:08 -05001427 System.arraycopy(mIcons, src, mIcons, index, count);
1428 System.arraycopy(mIconIds, src, mIconIds, index, count);
1429 System.arraycopy(mLabels, src, mLabels, index, count);
1430 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001431
Joe Onorato2cc62e82010-03-17 20:23:53 -07001432 sRollo.mState.iconCount--;
Daniel Sandler388f6792010-03-02 14:08:08 -05001433 final int last = mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001434
Daniel Sandler388f6792010-03-02 14:08:08 -05001435 mIcons[last] = null;
1436 mIconIds[last] = 0;
1437 mLabels[last] = null;
1438 mLabelIds[last] = 0;
1439 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001440
Daniel Sandler388f6792010-03-02 14:08:08 -05001441 /**
1442 * Send the apps list structures to RS.
1443 */
1444 private void saveAppsList() {
1445 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1446 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001447 mAllocIconIds.data(mIconIds);
1448 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001449
Daniel Sandler388f6792010-03-02 14:08:08 -05001450 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1451 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001452
Daniel Sandler388f6792010-03-02 14:08:08 -05001453 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001454
Daniel Sandler388f6792010-03-02 14:08:08 -05001455 // Note: mScript may be null if we haven't initialized it yet.
1456 // In that case, this is a no-op.
1457 if (mInvokeResetWAR != null) {
1458 mInvokeResetWAR.execute();
1459 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001460 }
1461 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001462
Daniel Sandler388f6792010-03-02 14:08:08 -05001463 void fling() {
1464 mInvokeFling.execute();
1465 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001466
Daniel Sandler388f6792010-03-02 14:08:08 -05001467 void move() {
1468 mInvokeMove.execute();
1469 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001470
Daniel Sandler388f6792010-03-02 14:08:08 -05001471 void moveTo(float row) {
1472 mState.targetPos = row;
1473 mState.save();
1474 mInvokeMoveTo.execute();
1475 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001476
Daniel Sandler388f6792010-03-02 14:08:08 -05001477 /**
1478 * You need to call save() on mState on your own after calling this.
1479 *
1480 * @return the index of the icon that was selected.
1481 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001482 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001483 if (mAllApps != null) {
1484 final int index = mAllApps.chooseTappedIcon(x, y);
1485 selectIcon(index, pressed);
1486 return index;
1487 } else {
1488 return -1;
1489 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001490 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001491
Daniel Sandler388f6792010-03-02 14:08:08 -05001492 /**
1493 * Select the icon at the given index.
1494 *
1495 * @param index The index.
1496 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1497 */
1498 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001499 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1500 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001501 if (mAllApps != null) {
1502 mAllApps.mRestoreFocusIndex = index;
1503 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001504 mState.selectedIconIndex = -1;
Romain Guy13c2e7b2010-03-10 19:45:00 -08001505 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1506 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001507 }
1508 } else {
1509 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001510 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001511 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001512
Daniel Sandler388f6792010-03-02 14:08:08 -05001513 int prev = mState.selectedIconIndex;
1514 mState.selectedIconIndex = index;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001515
Romain Guy13c2e7b2010-03-10 19:45:00 -08001516 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001517 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001518
Daniel Sandler388f6792010-03-02 14:08:08 -05001519 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1520 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1521 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001522
Joe Onorato2cc62e82010-03-17 20:23:53 -07001523 mSelectedIcon = Allocation.createFromBitmap(sRS, selectionBitmap,
1524 Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001525 mSelectedIcon.uploadToTexture(0);
1526 mState.selectedIconTexture = mSelectedIcon.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001527
Daniel Sandler388f6792010-03-02 14:08:08 -05001528 if (prev != index) {
1529 if (info.title != null && info.title.length() > 0) {
1530 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001531 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001532 }
1533 }
1534 }
1535 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001536
Daniel Sandler388f6792010-03-02 14:08:08 -05001537 /**
1538 * You need to call save() on mState on your own after calling this.
1539 */
1540 void clearSelectedIcon() {
1541 mState.selectedIconIndex = -1;
1542 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001543
Daniel Sandler388f6792010-03-02 14:08:08 -05001544 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001545 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001546 switch (mode) {
1547 case SELECTED_NONE:
1548 mState.homeButtonId = mHomeButtonNormal.getID();
1549 break;
1550 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001551 mAllApps.mLastSelection = SELECTION_HOME;
Daniel Sandler388f6792010-03-02 14:08:08 -05001552 mState.homeButtonId = mHomeButtonFocused.getID();
1553 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001554 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001555 }
1556 break;
1557 case SELECTED_PRESSED:
1558 mState.homeButtonId = mHomeButtonPressed.getID();
1559 break;
1560 }
1561 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001562
Daniel Sandler388f6792010-03-02 14:08:08 -05001563 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001564 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1565 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1566 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001567 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001568 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001569 }
1570 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001571 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001572 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001573 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001574 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001575 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001576 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001577 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Joe Onorato2cc62e82010-03-17 20:23:53 -07001578 Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1579 Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1580 Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1581 Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1582 Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1583 Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1584 Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1585 Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1586 Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
1587 Log.d(TAG, "sRollo.mParams.bubbleWidth=" + mParams.bubbleWidth);
1588 Log.d(TAG, "sRollo.mParams.bubbleHeight=" + mParams.bubbleHeight);
1589 Log.d(TAG, "sRollo.mParams.bubbleBitmapWidth=" + mParams.bubbleBitmapWidth);
1590 Log.d(TAG, "sRollo.mParams.bubbleBitmapHeight=" + mParams.bubbleBitmapHeight);
1591 Log.d(TAG, "sRollo.mParams.homeButtonWidth=" + mParams.homeButtonWidth);
1592 Log.d(TAG, "sRollo.mParams.homeButtonHeight=" + mParams.homeButtonHeight);
1593 Log.d(TAG, "sRollo.mParams.homeButtonTextureWidth=" + mParams.homeButtonTextureWidth);
1594 Log.d(TAG, "sRollo.mParams.homeButtonTextureHeight=" + mParams.homeButtonTextureHeight);
Daniel Sandler388f6792010-03-02 14:08:08 -05001595 }
1596 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001597
Daniel Sandlerdca66122010-04-13 16:23:58 -04001598 public int getAppBatchSize() {
1599 return BATCH_SIZE;
1600 }
1601
Daniel Sandler388f6792010-03-02 14:08:08 -05001602 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001603 Log.d(TAG, "sRS=" + sRS);
1604 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001605 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001606 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1607 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001608 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1609 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1610 Log.d(TAG, "mLastSelection=" + mLastSelection);
1611 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1612 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1613 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1614 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
1615 Log.d(TAG, "mZoomDirty=" + mZoomDirty);
1616 Log.d(TAG, "mAnimateNextZoom=" + mAnimateNextZoom);
1617 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001618 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001619 Log.d(TAG, "mVelocity=" + mVelocity);
1620 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001621 if (sRollo != null) {
1622 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001623 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001624 if (sRS != null) {
1625 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001626 }
1627 }
1628}
1629
1630