blob: 376b1fea0eaa604b8e8f12171493d38b36986250 [file] [log] [blame]
Daniel Sandler388f6792010-03-02 14:08:08 -05001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher2;
18
19import android.content.ComponentName;
20import android.content.Context;
21import android.content.res.Resources;
22import android.graphics.Bitmap;
23import android.graphics.Canvas;
24import android.graphics.PixelFormat;
25import android.graphics.Rect;
Daniel Sandler388f6792010-03-02 14:08:08 -050026import android.renderscript.Allocation;
Daniel Sandler388f6792010-03-02 14:08:08 -050027import android.renderscript.Element;
28import android.renderscript.ProgramFragment;
29import android.renderscript.ProgramStore;
30import android.renderscript.ProgramVertex;
31import android.renderscript.RSSurfaceView;
32import android.renderscript.RenderScriptGL;
33import android.renderscript.RenderScript;
34import android.renderscript.Sampler;
35import android.renderscript.Script;
36import android.renderscript.ScriptC;
37import android.renderscript.SimpleMesh;
38import android.renderscript.Type;
39import android.util.AttributeSet;
Romain Guy060b5c82010-03-04 10:07:38 -080040import android.util.DisplayMetrics;
Daniel Sandler388f6792010-03-02 14:08:08 -050041import android.util.Log;
42import android.view.KeyEvent;
43import android.view.MotionEvent;
44import android.view.SoundEffectConstants;
45import android.view.SurfaceHolder;
46import android.view.VelocityTracker;
47import android.view.View;
48import android.view.ViewConfiguration;
49import android.view.accessibility.AccessibilityEvent;
50
51import java.util.ArrayList;
52import java.util.Arrays;
53import java.util.Collections;
Daniel Sandler388f6792010-03-02 14:08:08 -050054
Romain Guyedcce092010-03-04 13:03:17 -080055import com.android.launcher.R;
56
Daniel Sandler388f6792010-03-02 14:08:08 -050057public class AllApps3D extends RSSurfaceView
58 implements AllAppsView, View.OnClickListener, View.OnLongClickListener, DragSource {
59 private static final String TAG = "Launcher.AllApps3D";
60
61 /** Bit for mLocks for when there are icons being loaded. */
62 private static final int LOCK_ICONS_PENDING = 1;
63
64 private static final int TRACKING_NONE = 0;
65 private static final int TRACKING_FLING = 1;
66 private static final int TRACKING_HOME = 2;
67
68 private static final int SELECTED_NONE = 0;
69 private static final int SELECTED_FOCUSED = 1;
70 private static final int SELECTED_PRESSED = 2;
71
72 private static final int SELECTION_NONE = 0;
73 private static final int SELECTION_ICONS = 1;
74 private static final int SELECTION_HOME = 2;
75
76 private Launcher mLauncher;
77 private DragController mDragController;
78
79 /** When this is 0, modifications are allowed, when it's not, they're not.
80 * TODO: What about scrolling? */
81 private int mLocks = LOCK_ICONS_PENDING;
82
83 private int mSlop;
84 private int mMaxFlingVelocity;
85
86 private Defines mDefines = new Defines();
Daniel Sandler388f6792010-03-02 14:08:08 -050087 private ArrayList<ApplicationInfo> mAllAppsList;
88
Joe Onorato2cc62e82010-03-17 20:23:53 -070089 private static RenderScriptGL sRS;
90 private static RolloRS sRollo;
Jason Samsdd8cd8b2010-03-11 12:38:48 -080091
Joe Onoratoeffc4a82010-04-15 11:48:13 -070092 private static boolean sZoomDirty = false;
93 private static boolean sAnimateNextZoom;
94 private static float sNextZoom;
95
Daniel Sandler388f6792010-03-02 14:08:08 -050096 /**
97 * True when we are using arrow keys or trackball to drive navigation
98 */
99 private boolean mArrowNavigation = false;
100 private boolean mStartedScrolling;
101
102 /**
103 * Used to keep track of the selection when AllAppsView loses window focus.
104 * One of the SELECTION_ constants.
105 */
106 private int mLastSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800107
Daniel Sandler388f6792010-03-02 14:08:08 -0500108 /**
109 * Used to keep track of the selection when AllAppsView loses window focus
110 */
111 private int mLastSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800112
Daniel Sandler388f6792010-03-02 14:08:08 -0500113 private VelocityTracker mVelocityTracker;
114 private int mTouchTracking;
115 private int mMotionDownRawX;
116 private int mMotionDownRawY;
117 private int mDownIconIndex = -1;
118 private int mCurrentIconIndex = -1;
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700119 private int[] mTouchYBorders;
120 private int[] mTouchXBorders;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800121
Daniel Sandler388f6792010-03-02 14:08:08 -0500122 private boolean mShouldGainFocus;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800123
Daniel Sandler388f6792010-03-02 14:08:08 -0500124 private boolean mHaveSurface = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500125 private float mZoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500126 private float mVelocity;
127 private AAMessage mMessageProc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800128
Romain Guy060b5c82010-03-04 10:07:38 -0800129 private int mColumnsPerPage;
130 private int mRowsPerPage;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800131 private boolean mSurrendered;
132
Romain Guyc16fea72010-03-12 17:17:56 -0800133 private int mRestoreFocusIndex = -1;
134
Romain Guy060b5c82010-03-04 10:07:38 -0800135 @SuppressWarnings({"UnusedDeclaration"})
Daniel Sandler388f6792010-03-02 14:08:08 -0500136 static class Defines {
137 public static final int ALLOC_PARAMS = 0;
138 public static final int ALLOC_STATE = 1;
139 public static final int ALLOC_ICON_IDS = 3;
140 public static final int ALLOC_LABEL_IDS = 4;
141 public static final int ALLOC_VP_CONSTANTS = 5;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800142
Romain Guy060b5c82010-03-04 10:07:38 -0800143 public static final int COLUMNS_PER_PAGE_PORTRAIT = 4;
144 public static final int ROWS_PER_PAGE_PORTRAIT = 4;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800145
Romain Guy060b5c82010-03-04 10:07:38 -0800146 public static final int COLUMNS_PER_PAGE_LANDSCAPE = 6;
147 public static final int ROWS_PER_PAGE_LANDSCAPE = 3;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800148
Daniel Sandler388f6792010-03-02 14:08:08 -0500149 public static final int ICON_WIDTH_PX = 64;
150 public static final int ICON_TEXTURE_WIDTH_PX = 74;
151 public static final int SELECTION_TEXTURE_WIDTH_PX = 74 + 20;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800152
Daniel Sandler388f6792010-03-02 14:08:08 -0500153 public static final int ICON_HEIGHT_PX = 64;
154 public static final int ICON_TEXTURE_HEIGHT_PX = 74;
155 public static final int SELECTION_TEXTURE_HEIGHT_PX = 74 + 20;
156 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800157
Daniel Sandler388f6792010-03-02 14:08:08 -0500158 public AllApps3D(Context context, AttributeSet attrs) {
159 super(context, attrs);
160 setFocusable(true);
161 setSoundEffectsEnabled(false);
162 getHolder().setFormat(PixelFormat.TRANSLUCENT);
163 final ViewConfiguration config = ViewConfiguration.get(context);
164 mSlop = config.getScaledTouchSlop();
165 mMaxFlingVelocity = config.getScaledMaximumFlingVelocity();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800166
Daniel Sandler388f6792010-03-02 14:08:08 -0500167 setOnClickListener(this);
168 setOnLongClickListener(this);
169 setZOrderOnTop(true);
170 getHolder().setFormat(PixelFormat.TRANSLUCENT);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800171
Joe Onorato2cc62e82010-03-17 20:23:53 -0700172 if (sRS == null) {
173 sRS = createRenderScript(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800174 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700175 createRenderScript(sRS);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800176 }
177
Romain Guy060b5c82010-03-04 10:07:38 -0800178 final DisplayMetrics metrics = getResources().getDisplayMetrics();
179 final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
180 mColumnsPerPage = isPortrait ? Defines.COLUMNS_PER_PAGE_PORTRAIT :
181 Defines.COLUMNS_PER_PAGE_LANDSCAPE;
182 mRowsPerPage = isPortrait ? Defines.ROWS_PER_PAGE_PORTRAIT :
183 Defines.ROWS_PER_PAGE_LANDSCAPE;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800184
Joe Onorato2cc62e82010-03-17 20:23:53 -0700185 if (sRollo != null) {
186 sRollo.mAllApps = this;
187 sRollo.mRes = getResources();
188 sRollo.mInitialize = true;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800189 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500190 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800191
Romain Guy060b5c82010-03-04 10:07:38 -0800192 @SuppressWarnings({"UnusedDeclaration"})
193 public AllApps3D(Context context, AttributeSet attrs, int defStyle) {
194 this(context, attrs);
195 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800196
Romain Guy13c2e7b2010-03-10 19:45:00 -0800197 public void surrender() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -0400198 if (sRS != null) {
199 sRS.contextSetSurface(0, 0, null);
200 sRS.mMessageCallback = null;
201 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800202 mSurrendered = true;
203 }
204
Daniel Sandler388f6792010-03-02 14:08:08 -0500205 /**
206 * Note that this implementation prohibits this view from ever being reattached.
207 */
208 @Override
209 protected void onDetachedFromWindow() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700210 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800211 if (!mSurrendered) {
Joe Onorato96da4012010-03-17 20:03:24 -0700212 Log.i(TAG, "onDetachedFromWindow");
Romain Guy13c2e7b2010-03-10 19:45:00 -0800213 destroyRenderScript();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700214 sRS = null;
215 sRollo = null;
thigobr1f43a312010-10-22 18:13:26 -0200216 super.onDetachedFromWindow();
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.
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700244 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500245 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();
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700804 sNextZoom = zoom;
805 sAnimateNextZoom = animate;
Daniel Sandler388f6792010-03-02 14:08:08 -0500806 // 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) {
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700809 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500810 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
Daniel Sandler707b0f72010-04-15 16:41:31 -0400834 if (list != null) {
835 Collections.sort(list, LauncherModel.APP_NAME_COMPARATOR);
836 }
837
Romain Guy13c2e7b2010-03-10 19:45:00 -0800838 boolean reload = false;
839 if (mAllAppsList == null) {
840 reload = true;
841 } else if (list.size() != mAllAppsList.size()) {
842 reload = true;
843 } else {
844 final int count = list.size();
845 for (int i = 0; i < count; i++) {
846 if (list.get(i) != mAllAppsList.get(i)) {
847 reload = true;
848 break;
849 }
850 }
851 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800852
Daniel Sandler388f6792010-03-02 14:08:08 -0500853 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700854 if (sRollo != null && reload) {
855 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500856 }
Romain Guyc16fea72010-03-12 17:17:56 -0800857
858 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700859 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
860 sRollo.mState.save();
Romain Guyc16fea72010-03-12 17:17:56 -0800861 mRestoreFocusIndex = -1;
862 }
863
Daniel Sandler388f6792010-03-02 14:08:08 -0500864 mLocks &= ~LOCK_ICONS_PENDING;
865 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800866
Daniel Sandler388f6792010-03-02 14:08:08 -0500867 public void addApps(ArrayList<ApplicationInfo> list) {
868 if (mAllAppsList == null) {
869 // Not done loading yet. We'll find out about it later.
870 return;
871 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700872 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500873 // We've been removed from the window. Don't bother with all this.
874 return;
875 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800876
Daniel Sandler388f6792010-03-02 14:08:08 -0500877 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700878 if (sRollo != null) {
879 sRollo.pause();
880 sRollo.reallocAppsList(sRollo.mState.iconCount + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500881 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800882
Daniel Sandler388f6792010-03-02 14:08:08 -0500883 for (int i=0; i<N; i++) {
884 final ApplicationInfo item = list.get(i);
885 int index = Collections.binarySearch(mAllAppsList, item,
886 LauncherModel.APP_NAME_COMPARATOR);
887 if (index < 0) {
888 index = -(index+1);
889 }
890 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700891 if (sRollo != null) {
892 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500893 }
894 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800895
Joe Onorato2cc62e82010-03-17 20:23:53 -0700896 if (sRollo != null) {
897 sRollo.saveAppsList();
898 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500899 }
900 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800901
Daniel Sandler388f6792010-03-02 14:08:08 -0500902 public void removeApps(ArrayList<ApplicationInfo> list) {
903 if (mAllAppsList == null) {
904 // Not done loading yet. We'll find out about it later.
905 return;
906 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800907
Joe Onorato2cc62e82010-03-17 20:23:53 -0700908 if (sRollo != null) {
909 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800910 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500911 final int N = list.size();
912 for (int i=0; i<N; i++) {
913 final ApplicationInfo item = list.get(i);
914 int index = findAppByComponent(mAllAppsList, item);
915 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500916 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700917 if (sRollo != null) {
918 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500919 }
920 } else {
921 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
922 // Try to recover. This should keep us from crashing for now.
923 }
924 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800925
Joe Onorato2cc62e82010-03-17 20:23:53 -0700926 if (sRollo != null) {
927 sRollo.saveAppsList();
928 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500929 }
930 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800931
Joe Onorato64e6be72010-03-05 15:05:52 -0500932 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500933 // Just remove and add, because they may need to be re-sorted.
934 removeApps(list);
935 addApps(list);
936 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800937
Daniel Sandler388f6792010-03-02 14:08:08 -0500938 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
939 ComponentName component = item.intent.getComponent();
940 final int N = list.size();
941 for (int i=0; i<N; i++) {
942 ApplicationInfo x = list.get(i);
943 if (x.intent.getComponent().equals(component)) {
944 return i;
945 }
946 }
947 return -1;
948 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800949
Romain Guy060b5c82010-03-04 10:07:38 -0800950 /*
Daniel Sandler388f6792010-03-02 14:08:08 -0500951 private static int countPages(int iconCount) {
Romain Guy060b5c82010-03-04 10:07:38 -0800952 int iconsPerPage = getColumnsCount() * Defines.ROWS_PER_PAGE_PORTRAIT;
Daniel Sandler388f6792010-03-02 14:08:08 -0500953 int pages = iconCount / iconsPerPage;
954 if (pages*iconsPerPage != iconCount) {
955 pages++;
956 }
957 return pages;
958 }
Romain Guy060b5c82010-03-04 10:07:38 -0800959 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500960
961 class AAMessage extends RenderScript.RSMessage {
962 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700963 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500964 mVelocity = ((float)mData[1]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700965
966 boolean lastVisible = isVisible();
Daniel Sandler388f6792010-03-02 14:08:08 -0500967 mZoom = ((float)mData[2]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700968
969 final boolean visible = isVisible();
970 if (visible != lastVisible) {
971 post(new Runnable() {
972 public void run() {
973 if (visible) {
974 showSurface();
975 } else {
976 hideSurface();
977 }
978 }
979 });
980 }
981
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700982 sZoomDirty = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500983 }
984 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800985
Romain Guy13c2e7b2010-03-10 19:45:00 -0800986 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500987 // Allocations ======
988 private int mWidth;
989 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800990
Daniel Sandler388f6792010-03-02 14:08:08 -0500991 private Resources mRes;
992 private Script mScript;
993 private Script.Invokable mInvokeMove;
994 private Script.Invokable mInvokeMoveTo;
995 private Script.Invokable mInvokeFling;
996 private Script.Invokable mInvokeResetWAR;
997 private Script.Invokable mInvokeSetZoom;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800998
Daniel Sandler388f6792010-03-02 14:08:08 -0500999 private ProgramStore mPSIcons;
1000 private ProgramFragment mPFTexMip;
1001 private ProgramFragment mPFTexMipAlpha;
1002 private ProgramFragment mPFTexNearest;
1003 private ProgramVertex mPV;
1004 private ProgramVertex mPVCurve;
1005 private SimpleMesh mMesh;
1006 private ProgramVertex.MatrixAllocation mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001007
Daniel Sandler388f6792010-03-02 14:08:08 -05001008 private Allocation mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001009
Daniel Sandler388f6792010-03-02 14:08:08 -05001010 private Allocation mHomeButtonNormal;
1011 private Allocation mHomeButtonFocused;
1012 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001013
Daniel Sandler388f6792010-03-02 14:08:08 -05001014 private Allocation[] mIcons;
1015 private int[] mIconIds;
1016 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001017
Daniel Sandler388f6792010-03-02 14:08:08 -05001018 private Allocation[] mLabels;
1019 private int[] mLabelIds;
1020 private Allocation mAllocLabelIds;
1021 private Allocation mSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001022
Daniel Sandler388f6792010-03-02 14:08:08 -05001023 private Bitmap mSelectionBitmap;
1024 private Canvas mSelectionCanvas;
Romain Guy6a42cf32010-03-12 16:03:52 -08001025
1026 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001027
Daniel Sandler388f6792010-03-02 14:08:08 -05001028 Params mParams;
1029 State mState;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001030
Romain Guy13c2e7b2010-03-10 19:45:00 -08001031 AllApps3D mAllApps;
1032 boolean mInitialize;
1033
Daniel Sandler388f6792010-03-02 14:08:08 -05001034 class BaseAlloc {
1035 Allocation mAlloc;
1036 Type mType;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001037
Daniel Sandler388f6792010-03-02 14:08:08 -05001038 void save() {
1039 mAlloc.data(this);
1040 }
1041 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001042
Daniel Sandler388f6792010-03-02 14:08:08 -05001043 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001044 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -08001045 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -05001046 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001047
1048 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001049 if (sRS != null) {
1050 sRS.contextBindRootScript(null);
1051 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001052 }
1053
1054 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001055 if (sRS != null) {
1056 sRS.contextBindRootScript(mScript);
1057 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001058 }
1059
Daniel Sandler388f6792010-03-02 14:08:08 -05001060 class Params extends BaseAlloc {
1061 Params() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001062 mType = Type.createFromClass(sRS, Params.class, 1, "ParamsClass");
1063 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001064 save();
1065 }
1066 public int bubbleWidth;
1067 public int bubbleHeight;
1068 public int bubbleBitmapWidth;
1069 public int bubbleBitmapHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001070
Daniel Sandler388f6792010-03-02 14:08:08 -05001071 public int homeButtonWidth;
1072 public int homeButtonHeight;
1073 public int homeButtonTextureWidth;
1074 public int homeButtonTextureHeight;
1075 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001076
Daniel Sandler388f6792010-03-02 14:08:08 -05001077 class State extends BaseAlloc {
1078 public float newPositionX;
1079 public int newTouchDown;
1080 public float flingVelocity;
1081 public int iconCount;
1082 public int selectedIconIndex = -1;
1083 public int selectedIconTexture;
1084 public float zoomTarget;
1085 public int homeButtonId;
1086 public float targetPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001087
Daniel Sandler388f6792010-03-02 14:08:08 -05001088 State() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001089 mType = Type.createFromClass(sRS, State.class, 1, "StateClass");
1090 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001091 save();
1092 }
1093 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001094
Romain Guy13c2e7b2010-03-10 19:45:00 -08001095 public RolloRS(AllApps3D allApps) {
1096 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -05001097 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001098
Daniel Sandler388f6792010-03-02 14:08:08 -05001099 public void init(Resources res, int width, int height) {
1100 mRes = res;
1101 mWidth = width;
1102 mHeight = height;
1103 initProgramVertex();
1104 initProgramFragment();
1105 initProgramStore();
1106 initGl();
1107 initData();
Daniel Sandler388f6792010-03-02 14:08:08 -05001108 initRs();
1109 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001110
Daniel Sandler388f6792010-03-02 14:08:08 -05001111 public void initMesh() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001112 SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001113
Daniel Sandler388f6792010-03-02 14:08:08 -05001114 for (int ct=0; ct < 16; ct++) {
1115 float pos = (1.f / (16.f - 1)) * ct;
1116 tm.addVertex(0.0f, pos);
1117 tm.addVertex(1.0f, pos);
1118 }
1119 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1120 tm.addTriangle(ct, ct+1, ct+2);
1121 tm.addTriangle(ct+1, ct+3, ct+2);
1122 }
1123 mMesh = tm.create();
1124 mMesh.setName("SMCell");
1125 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001126
Daniel Sandler388f6792010-03-02 14:08:08 -05001127 void resize(int w, int h) {
1128 mPVA.setupProjectionNormalized(w, h);
1129 mWidth = w;
1130 mHeight = h;
1131 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001132
Daniel Sandler388f6792010-03-02 14:08:08 -05001133 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001134 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001135 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001136
Joe Onorato2cc62e82010-03-17 20:23:53 -07001137 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001138 pvb.setTextureMatrixEnable(true);
1139 mPV = pvb.create();
1140 mPV.setName("PV");
1141 mPV.bindAllocation(mPVA);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001142
Joe Onorato2cc62e82010-03-17 20:23:53 -07001143 Element.Builder eb = new Element.Builder(sRS);
1144 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "ImgSize");
1145 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "Position");
1146 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "BendPos");
1147 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "ScaleOffset");
Daniel Sandler388f6792010-03-02 14:08:08 -05001148 Element e = eb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001149
Joe Onorato2cc62e82010-03-17 20:23:53 -07001150 mUniformAlloc = Allocation.createSized(sRS, e, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001151
Daniel Sandler388f6792010-03-02 14:08:08 -05001152 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001153 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Romain Guy060b5c82010-03-04 10:07:38 -08001154 String t = "void main() {\n" +
1155 // Animation
1156 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001157
Romain Guy060b5c82010-03-04 10:07:38 -08001158 " float bendY1 = UNI_BendPos.x;\n" +
1159 " float bendY2 = UNI_BendPos.y;\n" +
1160 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1161 " float bendDistance = bendY1 * 0.4;\n" +
1162 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001163
Romain Guy060b5c82010-03-04 10:07:38 -08001164 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1165 " float aDy = cos(bendAngle);\n" +
1166 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001167
Romain Guy060b5c82010-03-04 10:07:38 -08001168 " float scale = (2.0 / 480.0);\n" +
1169 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1170 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1171 " float y = 0.0;\n" +
1172 " float z = 0.0;\n" +
1173 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001174
Romain Guy060b5c82010-03-04 10:07:38 -08001175 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1176 " y += cv * aDy;\n" +
1177 " z += -cv * aDz;\n" +
1178 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1179 " lum += cv / bendDistance * distanceDimLevel;\n" +
1180 " y += cv * cos(cv * bendStep);\n" +
1181 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001182
Romain Guy060b5c82010-03-04 10:07:38 -08001183 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1184 " y += cv * aDy;\n" +
1185 " z += cv * aDz;\n" +
1186 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1187 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1188 " y += cv * cos(cv * bendStep);\n" +
1189 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001190
Romain Guy060b5c82010-03-04 10:07:38 -08001191 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001192
Romain Guy060b5c82010-03-04 10:07:38 -08001193 " vec4 pos;\n" +
1194 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1195 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1196 " pos.z = z * UNI_ScaleOffset.x;\n" +
1197 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001198
Romain Guy060b5c82010-03-04 10:07:38 -08001199 " pos.x *= 1.0 + ani * 4.0;\n" +
1200 " pos.y *= 1.0 + ani * 4.0;\n" +
1201 " pos.z -= ani * 1.5;\n" +
1202 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001203
Romain Guy060b5c82010-03-04 10:07:38 -08001204 " gl_Position = UNI_MVP * pos;\n" +
1205 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1206 " varTex0.xy = ATTRIB_position;\n" +
1207 " varTex0.y = 1.0 - varTex0.y;\n" +
1208 " varTex0.zw = vec2(0.0, 0.0);\n" +
1209 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001210 sb.setShader(t);
1211 sb.addConstant(mUniformAlloc.getType());
1212 sb.addInput(mMesh.getVertexType(0).getElement());
1213 mPVCurve = sb.create();
1214 mPVCurve.setName("PVCurve");
1215 mPVCurve.bindAllocation(mPVA);
1216 mPVCurve.bindConstants(mUniformAlloc, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001217
Joe Onorato2cc62e82010-03-17 20:23:53 -07001218 sRS.contextBindProgramVertex(mPV);
Daniel Sandler388f6792010-03-02 14:08:08 -05001219 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001220
Daniel Sandler388f6792010-03-02 14:08:08 -05001221 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001222 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001223 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1224 sb.setMag(Sampler.Value.NEAREST);
1225 sb.setWrapS(Sampler.Value.CLAMP);
1226 sb.setWrapT(Sampler.Value.CLAMP);
1227 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001228
Daniel Sandler388f6792010-03-02 14:08:08 -05001229 sb.setMin(Sampler.Value.NEAREST);
1230 sb.setMag(Sampler.Value.NEAREST);
1231 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001232
Joe Onorato2cc62e82010-03-17 20:23:53 -07001233 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001234 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1235 ProgramFragment.Builder.Format.RGBA, 0);
1236 mPFTexMip = bf.create();
1237 mPFTexMip.setName("PFTexMip");
1238 mPFTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001239
Daniel Sandler388f6792010-03-02 14:08:08 -05001240 mPFTexNearest = bf.create();
1241 mPFTexNearest.setName("PFTexNearest");
1242 mPFTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001243
Daniel Sandler388f6792010-03-02 14:08:08 -05001244 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1245 ProgramFragment.Builder.Format.ALPHA, 0);
1246 mPFTexMipAlpha = bf.create();
1247 mPFTexMipAlpha.setName("PFTexMipAlpha");
1248 mPFTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001249
Daniel Sandler388f6792010-03-02 14:08:08 -05001250 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001251
Daniel Sandler388f6792010-03-02 14:08:08 -05001252 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001253 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001254 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1255 bs.setColorMask(true,true,true,false);
1256 bs.setDitherEnable(true);
1257 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1258 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
1259 mPSIcons = bs.create();
1260 mPSIcons.setName("PSIcons");
1261 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001262
Daniel Sandler388f6792010-03-02 14:08:08 -05001263 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001264 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001265
Daniel Sandler388f6792010-03-02 14:08:08 -05001266 private void initData() {
1267 mParams = new Params();
1268 mState = new State();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001269
Romain Guy13c2e7b2010-03-10 19:45:00 -08001270 final Utilities.BubbleText bubble = new Utilities.BubbleText(mAllApps.getContext());
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001271
Daniel Sandler388f6792010-03-02 14:08:08 -05001272 mParams.bubbleWidth = bubble.getBubbleWidth();
1273 mParams.bubbleHeight = bubble.getMaxBubbleHeight();
1274 mParams.bubbleBitmapWidth = bubble.getBitmapWidth();
1275 mParams.bubbleBitmapHeight = bubble.getBitmapHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001276
Joe Onorato2cc62e82010-03-17 20:23:53 -07001277 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1278 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001279 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001280 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1281 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001282 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001283 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1284 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001285 mHomeButtonPressed.uploadToTexture(0);
1286 mParams.homeButtonWidth = 76;
1287 mParams.homeButtonHeight = 68;
1288 mParams.homeButtonTextureWidth = 128;
1289 mParams.homeButtonTextureHeight = 128;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001290
Daniel Sandler388f6792010-03-02 14:08:08 -05001291 mState.homeButtonId = mHomeButtonNormal.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001292
Daniel Sandler388f6792010-03-02 14:08:08 -05001293 mParams.save();
1294 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001295
Daniel Sandler388f6792010-03-02 14:08:08 -05001296 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1297 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1298 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001299
Daniel Sandler388f6792010-03-02 14:08:08 -05001300 setApps(null);
1301 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001302
Daniel Sandler388f6792010-03-02 14:08:08 -05001303 private void initRs() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001304 ScriptC.Builder sb = new ScriptC.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001305 sb.setScript(mRes, R.raw.allapps);
1306 sb.setRoot(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001307 sb.addDefines(mAllApps.mDefines);
Daniel Sandler388f6792010-03-02 14:08:08 -05001308 sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS);
1309 sb.setType(mState.mType, "state", Defines.ALLOC_STATE);
1310 sb.setType(mUniformAlloc.getType(), "vpConstants", Defines.ALLOC_VP_CONSTANTS);
1311 mInvokeMove = sb.addInvokable("move");
1312 mInvokeFling = sb.addInvokable("fling");
1313 mInvokeMoveTo = sb.addInvokable("moveTo");
1314 mInvokeResetWAR = sb.addInvokable("resetHWWar");
1315 mInvokeSetZoom = sb.addInvokable("setZoom");
1316 mScript = sb.create();
1317 mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1318 mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
1319 mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
1320 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1321 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
1322 mScript.bindAllocation(mUniformAlloc, Defines.ALLOC_VP_CONSTANTS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001323
Joe Onorato2cc62e82010-03-17 20:23:53 -07001324 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -05001325 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001326
Daniel Sandler388f6792010-03-02 14:08:08 -05001327 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001328 if (sZoomDirty) {
1329 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001330 }
1331 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001332
Romain Guy060b5c82010-03-04 10:07:38 -08001333 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001334 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001335 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001336 final int count = list != null ? list.size() : 0;
1337 int allocCount = count;
1338 if (allocCount < 1) {
1339 allocCount = 1;
1340 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001341
Daniel Sandler388f6792010-03-02 14:08:08 -05001342 mIcons = new Allocation[count];
1343 mIconIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001344 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001345
Daniel Sandler388f6792010-03-02 14:08:08 -05001346 mLabels = new Allocation[count];
1347 mLabelIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001348 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001349
Daniel Sandler388f6792010-03-02 14:08:08 -05001350 mState.iconCount = count;
1351 for (int i=0; i < mState.iconCount; i++) {
1352 createAppIconAllocations(i, list.get(i));
1353 }
1354 for (int i=0; i < mState.iconCount; i++) {
1355 uploadAppIcon(i, list.get(i));
1356 }
1357 saveAppsList();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001358 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001359 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001360
Daniel Sandler388f6792010-03-02 14:08:08 -05001361 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001362 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001363 sRollo.clearSelectedIcon();
1364 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001365 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001366 if (zoom > 0.001f) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001367 sRollo.mState.zoomTarget = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -05001368 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001369 sRollo.mState.zoomTarget = 0;
Daniel Sandler388f6792010-03-02 14:08:08 -05001370 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001371 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -05001372 if (!animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001373 sRollo.mInvokeSetZoom.execute();
Daniel Sandler388f6792010-03-02 14:08:08 -05001374 }
1375 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001376
Daniel Sandler388f6792010-03-02 14:08:08 -05001377 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001378 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1379 Element.RGBA_8888(sRS), false);
1380 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1381 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001382 mIconIds[index] = mIcons[index].getID();
1383 mLabelIds[index] = mLabels[index].getID();
1384 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001385
Daniel Sandler388f6792010-03-02 14:08:08 -05001386 private void uploadAppIcon(int index, ApplicationInfo item) {
1387 if (mIconIds[index] != mIcons[index].getID()) {
1388 throw new IllegalStateException("uploadAppIcon index=" + index
1389 + " mIcons[index].getID=" + mIcons[index].getID()
1390 + " mIconsIds[index]=" + mIconIds[index]
1391 + " item=" + item);
1392 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001393 mIcons[index].uploadToTexture(true, 0);
1394 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001395 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001396
Daniel Sandler388f6792010-03-02 14:08:08 -05001397 /**
1398 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1399 * fill in the values and call saveAppsList().
1400 */
1401 private void reallocAppsList(int count) {
1402 Allocation[] icons = new Allocation[count];
1403 int[] iconIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001404 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001405
Daniel Sandler388f6792010-03-02 14:08:08 -05001406 Allocation[] labels = new Allocation[count];
1407 int[] labelIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001408 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001409
Joe Onorato2cc62e82010-03-17 20:23:53 -07001410 final int oldCount = sRollo.mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001411
Daniel Sandler388f6792010-03-02 14:08:08 -05001412 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1413 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1414 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1415 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001416
Daniel Sandler388f6792010-03-02 14:08:08 -05001417 mIcons = icons;
1418 mIconIds = iconIds;
1419 mLabels = labels;
1420 mLabelIds = labelIds;
1421 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001422
Daniel Sandler388f6792010-03-02 14:08:08 -05001423 /**
1424 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1425 */
1426 private void addApp(int index, ApplicationInfo item) {
1427 final int count = mState.iconCount - index;
1428 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001429
Daniel Sandler388f6792010-03-02 14:08:08 -05001430 System.arraycopy(mIcons, index, mIcons, dest, count);
1431 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1432 System.arraycopy(mLabels, index, mLabels, dest, count);
1433 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001434
Daniel Sandler388f6792010-03-02 14:08:08 -05001435 createAppIconAllocations(index, item);
1436 uploadAppIcon(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001437 sRollo.mState.iconCount++;
Daniel Sandler388f6792010-03-02 14:08:08 -05001438 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001439
Daniel Sandler388f6792010-03-02 14:08:08 -05001440 /**
1441 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1442 */
1443 private void removeApp(int index) {
1444 final int count = mState.iconCount - index - 1;
1445 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001446
Daniel Sandler388f6792010-03-02 14:08:08 -05001447 System.arraycopy(mIcons, src, mIcons, index, count);
1448 System.arraycopy(mIconIds, src, mIconIds, index, count);
1449 System.arraycopy(mLabels, src, mLabels, index, count);
1450 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001451
Joe Onorato2cc62e82010-03-17 20:23:53 -07001452 sRollo.mState.iconCount--;
Daniel Sandler388f6792010-03-02 14:08:08 -05001453 final int last = mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001454
Daniel Sandler388f6792010-03-02 14:08:08 -05001455 mIcons[last] = null;
1456 mIconIds[last] = 0;
1457 mLabels[last] = null;
1458 mLabelIds[last] = 0;
1459 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001460
Daniel Sandler388f6792010-03-02 14:08:08 -05001461 /**
1462 * Send the apps list structures to RS.
1463 */
1464 private void saveAppsList() {
1465 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1466 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001467 mAllocIconIds.data(mIconIds);
1468 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001469
Daniel Sandler388f6792010-03-02 14:08:08 -05001470 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1471 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001472
Daniel Sandler388f6792010-03-02 14:08:08 -05001473 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001474
Daniel Sandler388f6792010-03-02 14:08:08 -05001475 // Note: mScript may be null if we haven't initialized it yet.
1476 // In that case, this is a no-op.
1477 if (mInvokeResetWAR != null) {
1478 mInvokeResetWAR.execute();
1479 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001480 }
1481 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001482
Daniel Sandler388f6792010-03-02 14:08:08 -05001483 void fling() {
1484 mInvokeFling.execute();
1485 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001486
Daniel Sandler388f6792010-03-02 14:08:08 -05001487 void move() {
1488 mInvokeMove.execute();
1489 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001490
Daniel Sandler388f6792010-03-02 14:08:08 -05001491 void moveTo(float row) {
1492 mState.targetPos = row;
1493 mState.save();
1494 mInvokeMoveTo.execute();
1495 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001496
Daniel Sandler388f6792010-03-02 14:08:08 -05001497 /**
1498 * You need to call save() on mState on your own after calling this.
1499 *
1500 * @return the index of the icon that was selected.
1501 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001502 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001503 if (mAllApps != null) {
1504 final int index = mAllApps.chooseTappedIcon(x, y);
1505 selectIcon(index, pressed);
1506 return index;
1507 } else {
1508 return -1;
1509 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001510 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001511
Daniel Sandler388f6792010-03-02 14:08:08 -05001512 /**
1513 * Select the icon at the given index.
1514 *
1515 * @param index The index.
1516 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1517 */
1518 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001519 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1520 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001521 if (mAllApps != null) {
1522 mAllApps.mRestoreFocusIndex = index;
1523 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001524 mState.selectedIconIndex = -1;
Romain Guy13c2e7b2010-03-10 19:45:00 -08001525 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1526 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001527 }
1528 } else {
1529 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001530 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001531 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001532
Daniel Sandler388f6792010-03-02 14:08:08 -05001533 int prev = mState.selectedIconIndex;
1534 mState.selectedIconIndex = index;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001535
Romain Guy13c2e7b2010-03-10 19:45:00 -08001536 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001537 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001538
Daniel Sandler388f6792010-03-02 14:08:08 -05001539 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1540 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1541 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001542
Joe Onorato2cc62e82010-03-17 20:23:53 -07001543 mSelectedIcon = Allocation.createFromBitmap(sRS, selectionBitmap,
1544 Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001545 mSelectedIcon.uploadToTexture(0);
1546 mState.selectedIconTexture = mSelectedIcon.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001547
Daniel Sandler388f6792010-03-02 14:08:08 -05001548 if (prev != index) {
1549 if (info.title != null && info.title.length() > 0) {
1550 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001551 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001552 }
1553 }
1554 }
1555 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001556
Daniel Sandler388f6792010-03-02 14:08:08 -05001557 /**
1558 * You need to call save() on mState on your own after calling this.
1559 */
1560 void clearSelectedIcon() {
1561 mState.selectedIconIndex = -1;
1562 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001563
Daniel Sandler388f6792010-03-02 14:08:08 -05001564 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001565 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001566 switch (mode) {
1567 case SELECTED_NONE:
1568 mState.homeButtonId = mHomeButtonNormal.getID();
1569 break;
1570 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001571 mAllApps.mLastSelection = SELECTION_HOME;
Daniel Sandler388f6792010-03-02 14:08:08 -05001572 mState.homeButtonId = mHomeButtonFocused.getID();
1573 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001574 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001575 }
1576 break;
1577 case SELECTED_PRESSED:
1578 mState.homeButtonId = mHomeButtonPressed.getID();
1579 break;
1580 }
1581 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001582
Daniel Sandler388f6792010-03-02 14:08:08 -05001583 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001584 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1585 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1586 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001587 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001588 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001589 }
1590 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001591 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001592 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001593 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001594 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001595 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001596 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001597 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Joe Onorato2cc62e82010-03-17 20:23:53 -07001598 Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1599 Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1600 Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1601 Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1602 Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1603 Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1604 Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1605 Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1606 Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
1607 Log.d(TAG, "sRollo.mParams.bubbleWidth=" + mParams.bubbleWidth);
1608 Log.d(TAG, "sRollo.mParams.bubbleHeight=" + mParams.bubbleHeight);
1609 Log.d(TAG, "sRollo.mParams.bubbleBitmapWidth=" + mParams.bubbleBitmapWidth);
1610 Log.d(TAG, "sRollo.mParams.bubbleBitmapHeight=" + mParams.bubbleBitmapHeight);
1611 Log.d(TAG, "sRollo.mParams.homeButtonWidth=" + mParams.homeButtonWidth);
1612 Log.d(TAG, "sRollo.mParams.homeButtonHeight=" + mParams.homeButtonHeight);
1613 Log.d(TAG, "sRollo.mParams.homeButtonTextureWidth=" + mParams.homeButtonTextureWidth);
1614 Log.d(TAG, "sRollo.mParams.homeButtonTextureHeight=" + mParams.homeButtonTextureHeight);
Daniel Sandler388f6792010-03-02 14:08:08 -05001615 }
1616 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001617
Daniel Sandler388f6792010-03-02 14:08:08 -05001618 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001619 Log.d(TAG, "sRS=" + sRS);
1620 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001621 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001622 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1623 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001624 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1625 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1626 Log.d(TAG, "mLastSelection=" + mLastSelection);
1627 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1628 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1629 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1630 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001631 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1632 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001633 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001634 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001635 Log.d(TAG, "mVelocity=" + mVelocity);
1636 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001637 if (sRollo != null) {
1638 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001639 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001640 if (sRS != null) {
1641 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001642 }
1643 }
1644}
1645
1646