blob: 9c3b3e4c72eafe7855edaafa363e20e5c5d53dd4 [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;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800216 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500217 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800218
Daniel Sandler388f6792010-03-02 14:08:08 -0500219 /**
220 * If you have an attached click listener, View always plays the click sound!?!?
221 * Deal with sound effects by hand.
222 */
223 public void reallyPlaySoundEffect(int sound) {
224 boolean old = isSoundEffectsEnabled();
225 setSoundEffectsEnabled(true);
226 playSoundEffect(sound);
227 setSoundEffectsEnabled(old);
228 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800229
Daniel Sandler388f6792010-03-02 14:08:08 -0500230 public void setLauncher(Launcher launcher) {
231 mLauncher = launcher;
232 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800233
Daniel Sandler388f6792010-03-02 14:08:08 -0500234 @Override
235 public void surfaceDestroyed(SurfaceHolder holder) {
236 super.surfaceDestroyed(holder);
237 // Without this, we leak mMessageCallback which leaks the context.
Romain Guy13c2e7b2010-03-10 19:45:00 -0800238 if (!mSurrendered) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700239 sRS.mMessageCallback = null;
Romain Guy13c2e7b2010-03-10 19:45:00 -0800240 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500241 // We may lose any callbacks that are pending, so make sure that we re-sync that
242 // on the next surfaceChanged.
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700243 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500244 mHaveSurface = false;
245 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800246
Daniel Sandler388f6792010-03-02 14:08:08 -0500247 @Override
248 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
249 //long startTime = SystemClock.uptimeMillis();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800250
Daniel Sandler388f6792010-03-02 14:08:08 -0500251 super.surfaceChanged(holder, format, w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800252
Romain Guy13c2e7b2010-03-10 19:45:00 -0800253 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800254
Daniel Sandler388f6792010-03-02 14:08:08 -0500255 mHaveSurface = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800256
Joe Onorato2cc62e82010-03-17 20:23:53 -0700257 if (sRollo == null) {
258 sRollo = new RolloRS(this);
259 sRollo.init(getResources(), w, h);
Daniel Sandler388f6792010-03-02 14:08:08 -0500260 if (mAllAppsList != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700261 sRollo.setApps(mAllAppsList);
Daniel Sandler388f6792010-03-02 14:08:08 -0500262 }
263 if (mShouldGainFocus) {
264 gainFocus();
265 mShouldGainFocus = false;
266 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700267 } else if (sRollo.mInitialize) {
268 sRollo.initGl();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700269 sRollo.mInitialize = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500270 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800271
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700272 initTouchState(w, h);
273
Joe Onorato2cc62e82010-03-17 20:23:53 -0700274 sRollo.dirtyCheck();
275 sRollo.resize(w, h);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800276
Joe Onorato2cc62e82010-03-17 20:23:53 -0700277 if (sRS != null) {
278 sRS.mMessageCallback = mMessageProc = new AAMessage();
Daniel Sandler388f6792010-03-02 14:08:08 -0500279 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800280
Joe Onorato2cc62e82010-03-17 20:23:53 -0700281 if (sRollo.mUniformAlloc != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500282 float tf[] = new float[] {72.f, 72.f,
283 120.f, 120.f, 0.f, 0.f,
284 120.f, 680.f,
285 (2.f / 480.f), 0, -((float)w / 2) - 0.25f, -380.25f};
286 if (w > h) {
287 tf[6] = 40.f;
288 tf[7] = h - 40.f;
289 tf[9] = 1.f;
290 tf[10] = -((float)w / 2) - 0.25f;
291 tf[11] = -((float)h / 2) - 0.25f;
292 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800293
Joe Onorato2cc62e82010-03-17 20:23:53 -0700294 sRollo.mUniformAlloc.data(tf);
Daniel Sandler388f6792010-03-02 14:08:08 -0500295 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800296
Daniel Sandler388f6792010-03-02 14:08:08 -0500297 //long endTime = SystemClock.uptimeMillis();
298 //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
299 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800300
Daniel Sandler388f6792010-03-02 14:08:08 -0500301 @Override
302 public void onWindowFocusChanged(boolean hasWindowFocus) {
303 super.onWindowFocusChanged(hasWindowFocus);
Romain Guy13c2e7b2010-03-10 19:45:00 -0800304
305 if (mSurrendered) return;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800306
Daniel Sandler388f6792010-03-02 14:08:08 -0500307 if (mArrowNavigation) {
308 if (!hasWindowFocus) {
309 // Clear selection when we lose window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700310 mLastSelectedIcon = sRollo.mState.selectedIconIndex;
311 sRollo.setHomeSelected(SELECTED_NONE);
312 sRollo.clearSelectedIcon();
313 sRollo.mState.save();
Romain Guy060b5c82010-03-04 10:07:38 -0800314 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700315 if (sRollo.mState.iconCount > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500316 if (mLastSelection == SELECTION_ICONS) {
317 int selection = mLastSelectedIcon;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700318 final int firstIcon = Math.round(sRollo.mScrollPos) * mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500319 if (selection < 0 || // No selection
320 selection < firstIcon || // off the top of the screen
Joe Onorato2cc62e82010-03-17 20:23:53 -0700321 selection >= sRollo.mState.iconCount || // past last icon
Daniel Sandler388f6792010-03-02 14:08:08 -0500322 selection >= firstIcon + // past last icon on screen
Romain Guy060b5c82010-03-04 10:07:38 -0800323 (mColumnsPerPage * mRowsPerPage)) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500324 selection = firstIcon;
325 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800326
Daniel Sandler388f6792010-03-02 14:08:08 -0500327 // Select the first icon when we gain window focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700328 sRollo.selectIcon(selection, SELECTED_FOCUSED);
329 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500330 } else if (mLastSelection == SELECTION_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700331 sRollo.setHomeSelected(SELECTED_FOCUSED);
332 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500333 }
334 }
335 }
336 }
337 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800338
Daniel Sandler388f6792010-03-02 14:08:08 -0500339 @Override
340 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
341 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800342
Romain Guy13c2e7b2010-03-10 19:45:00 -0800343 if (!isVisible() || mSurrendered) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500344 return;
345 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800346
Daniel Sandler388f6792010-03-02 14:08:08 -0500347 if (gainFocus) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700348 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500349 gainFocus();
350 } else {
351 mShouldGainFocus = true;
352 }
353 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700354 if (sRollo != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500355 if (mArrowNavigation) {
356 // Clear selection when we lose focus
Joe Onorato2cc62e82010-03-17 20:23:53 -0700357 sRollo.clearSelectedIcon();
358 sRollo.setHomeSelected(SELECTED_NONE);
359 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500360 mArrowNavigation = false;
361 }
362 } else {
363 mShouldGainFocus = false;
364 }
365 }
366 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800367
Daniel Sandler388f6792010-03-02 14:08:08 -0500368 private void gainFocus() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700369 if (!mArrowNavigation && sRollo.mState.iconCount > 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500370 // Select the first icon when we gain keyboard focus
371 mArrowNavigation = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700372 sRollo.selectIcon(Math.round(sRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED);
373 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500374 }
375 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800376
Daniel Sandler388f6792010-03-02 14:08:08 -0500377 @Override
378 public boolean onKeyDown(int keyCode, KeyEvent event) {
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800379
Daniel Sandler388f6792010-03-02 14:08:08 -0500380 boolean handled = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800381
Daniel Sandler388f6792010-03-02 14:08:08 -0500382 if (!isVisible()) {
383 return false;
384 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700385 final int iconCount = sRollo.mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800386
Daniel Sandler388f6792010-03-02 14:08:08 -0500387 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
388 if (mArrowNavigation) {
389 if (mLastSelection == SELECTION_HOME) {
390 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
391 mLauncher.closeAllApps(true);
392 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700393 int whichApp = sRollo.mState.selectedIconIndex;
Daniel Sandler388f6792010-03-02 14:08:08 -0500394 if (whichApp >= 0) {
395 ApplicationInfo app = mAllAppsList.get(whichApp);
Joe Onoratof984e852010-03-25 09:47:45 -0700396 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500397 handled = true;
398 }
399 }
400 }
401 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800402
Daniel Sandler388f6792010-03-02 14:08:08 -0500403 if (iconCount > 0) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800404 final boolean isPortrait = getWidth() < getHeight();
405
Daniel Sandler388f6792010-03-02 14:08:08 -0500406 mArrowNavigation = true;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800407
Joe Onorato2cc62e82010-03-17 20:23:53 -0700408 int currentSelection = sRollo.mState.selectedIconIndex;
409 int currentTopRow = Math.round(sRollo.mScrollPos);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800410
Romain Guy060b5c82010-03-04 10:07:38 -0800411 // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1
412 final int currentPageCol = currentSelection % mColumnsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800413
Romain Guy060b5c82010-03-04 10:07:38 -0800414 // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1
Romain Guy6a42cf32010-03-12 16:03:52 -0800415 final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage))
Romain Guy060b5c82010-03-04 10:07:38 -0800416 / mRowsPerPage;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800417
Daniel Sandler388f6792010-03-02 14:08:08 -0500418 int newSelection = currentSelection;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800419
Daniel Sandler388f6792010-03-02 14:08:08 -0500420 switch (keyCode) {
421 case KeyEvent.KEYCODE_DPAD_UP:
422 if (mLastSelection == SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800423 if (isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700424 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guy6a42cf32010-03-12 16:03:52 -0800425 int lastRowCount = iconCount % mColumnsPerPage;
426 if (lastRowCount == 0) {
427 lastRowCount = mColumnsPerPage;
428 }
429 newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2);
430 if (newSelection >= iconCount) {
431 newSelection = iconCount-1;
432 }
433 int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
434 if (target < 0) {
435 target = 0;
436 }
437 if (currentTopRow != target) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700438 sRollo.moveTo(target);
Romain Guy6a42cf32010-03-12 16:03:52 -0800439 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500440 }
441 } else {
442 if (currentPageRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800443 newSelection = currentSelection - mColumnsPerPage;
Romain Guy6a42cf32010-03-12 16:03:52 -0800444 if (currentTopRow > newSelection / mColumnsPerPage) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700445 sRollo.moveTo(newSelection / mColumnsPerPage);
Romain Guy6a42cf32010-03-12 16:03:52 -0800446 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500447 } else if (currentTopRow > 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800448 newSelection = currentSelection - mColumnsPerPage;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700449 sRollo.moveTo(newSelection / mColumnsPerPage);
Daniel Sandler388f6792010-03-02 14:08:08 -0500450 } else if (currentPageRow != 0) {
Romain Guy060b5c82010-03-04 10:07:38 -0800451 newSelection = currentTopRow * mRowsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500452 }
453 }
454 handled = true;
455 break;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800456
Daniel Sandler388f6792010-03-02 14:08:08 -0500457 case KeyEvent.KEYCODE_DPAD_DOWN: {
Romain Guy060b5c82010-03-04 10:07:38 -0800458 final int rowCount = iconCount / mColumnsPerPage
459 + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
460 final int currentRow = currentSelection / mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500461 if (mLastSelection != SELECTION_HOME) {
462 if (currentRow < rowCount-1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700463 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500464 if (currentSelection < 0) {
465 newSelection = 0;
466 } else {
Romain Guy060b5c82010-03-04 10:07:38 -0800467 newSelection = currentSelection + mColumnsPerPage;
Daniel Sandler388f6792010-03-02 14:08:08 -0500468 }
469 if (newSelection >= iconCount) {
470 // Go from D to G in this arrangement:
471 // A B C D
472 // E F G
473 newSelection = iconCount - 1;
474 }
Romain Guy060b5c82010-03-04 10:07:38 -0800475 if (currentPageRow >= mRowsPerPage - 1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700476 sRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
Daniel Sandler388f6792010-03-02 14:08:08 -0500477 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800478 } else if (isPortrait) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500479 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700480 sRollo.setHomeSelected(SELECTED_FOCUSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500481 }
482 }
483 handled = true;
484 break;
485 }
486 case KeyEvent.KEYCODE_DPAD_LEFT:
487 if (mLastSelection != SELECTION_HOME) {
488 if (currentPageCol > 0) {
489 newSelection = currentSelection - 1;
490 }
Romain Guy6a42cf32010-03-12 16:03:52 -0800491 } else if (!isPortrait) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700492 newSelection = ((int) (sRollo.mScrollPos) * mColumnsPerPage) +
Romain Guy6a42cf32010-03-12 16:03:52 -0800493 (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700494 sRollo.setHomeSelected(SELECTED_NONE);
Daniel Sandler388f6792010-03-02 14:08:08 -0500495 }
496 handled = true;
497 break;
498 case KeyEvent.KEYCODE_DPAD_RIGHT:
499 if (mLastSelection != SELECTION_HOME) {
Romain Guy6a42cf32010-03-12 16:03:52 -0800500 if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 ||
501 currentSelection == iconCount - 1)) {
502 newSelection = -1;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700503 sRollo.setHomeSelected(SELECTED_FOCUSED);
Romain Guy6a42cf32010-03-12 16:03:52 -0800504 } else if ((currentPageCol < mColumnsPerPage - 1) &&
Daniel Sandler388f6792010-03-02 14:08:08 -0500505 (currentSelection < iconCount - 1)) {
506 newSelection = currentSelection + 1;
507 }
508 }
509 handled = true;
510 break;
511 }
512 if (newSelection != currentSelection) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700513 sRollo.selectIcon(newSelection, SELECTED_FOCUSED);
514 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500515 }
516 }
517 return handled;
518 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800519
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700520 void initTouchState(int width, int height) {
521 boolean isPortrait = width < height;
522
523 int[] viewPos = new int[2];
524 getLocationOnScreen(viewPos);
525
526 mTouchXBorders = new int[mColumnsPerPage + 1];
527 mTouchYBorders = new int[mRowsPerPage + 1];
528
529 // TODO: Put this in a config file/define
530 int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE_PORTRAIT;
531 if (!isPortrait) cellHeight -= 12;
532 int centerY = (int) (height * (isPortrait ? 0.5f : 0.47f));
533 if (!isPortrait) centerY += cellHeight / 2;
534 int half = (int) Math.floor((mRowsPerPage + 1) / 2);
535 int end = mTouchYBorders.length - (half + 1);
536
537 for (int i = -half; i <= end; i++) {
538 mTouchYBorders[i + half] = centerY + (i * cellHeight) - viewPos[1];
539 }
540
541 int x = 0;
542 // TODO: Put this in a config file/define
543 int columnWidth = 120;
544 for (int i = 0; i < mColumnsPerPage + 1; i++) {
545 mTouchXBorders[i] = x - viewPos[0];
546 x += columnWidth;
547 }
548 }
549
550 int chooseTappedIcon(int x, int y) {
551 float pos = sRollo != null ? sRollo.mScrollPos : 0;
552
553 int oldY = y;
554
555 // Adjust for scroll position if not zero.
556 y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
557
558 int col = -1;
559 int row = -1;
560 final int columnsCount = mColumnsPerPage;
561 for (int i=0; i< columnsCount; i++) {
562 if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
563 col = i;
564 break;
565 }
566 }
567 final int rowsCount = mRowsPerPage;
568 for (int i=0; i< rowsCount; i++) {
569 if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
570 row = i;
571 break;
572 }
573 }
574
575 if (row < 0 || col < 0) {
576 return -1;
577 }
578
579 int index = (((int) pos) * columnsCount) + (row * columnsCount) + col;
580
581 if (index >= mAllAppsList.size()) {
582 return -1;
583 } else {
584 return index;
585 }
586 }
587
Daniel Sandler388f6792010-03-02 14:08:08 -0500588 @Override
589 public boolean onTouchEvent(MotionEvent ev)
590 {
591 mArrowNavigation = false;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800592
Daniel Sandler388f6792010-03-02 14:08:08 -0500593 if (!isVisible()) {
594 return true;
595 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800596
Daniel Sandler388f6792010-03-02 14:08:08 -0500597 if (mLocks != 0) {
598 return true;
599 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800600
Daniel Sandler388f6792010-03-02 14:08:08 -0500601 super.onTouchEvent(ev);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800602
Daniel Sandler388f6792010-03-02 14:08:08 -0500603 int x = (int)ev.getX();
604 int y = (int)ev.getY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800605
Romain Guyce115852010-03-04 12:15:37 -0800606 final boolean isPortrait = getWidth() < getHeight();
Daniel Sandler388f6792010-03-02 14:08:08 -0500607 int action = ev.getAction();
608 switch (action) {
609 case MotionEvent.ACTION_DOWN:
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700610 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
611 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500612 mTouchTracking = TRACKING_HOME;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700613 sRollo.setHomeSelected(SELECTED_PRESSED);
614 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500615 mCurrentIconIndex = -1;
616 } else {
617 mTouchTracking = TRACKING_FLING;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800618
Daniel Sandler388f6792010-03-02 14:08:08 -0500619 mMotionDownRawX = (int)ev.getRawX();
620 mMotionDownRawY = (int)ev.getRawY();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800621
Joe Onorato2cc62e82010-03-17 20:23:53 -0700622 sRollo.mState.newPositionX = ev.getRawY() / getHeight();
623 sRollo.mState.newTouchDown = 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800624
Joe Onorato2cc62e82010-03-17 20:23:53 -0700625 if (!sRollo.checkClickOK()) {
626 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500627 } else {
628 mDownIconIndex = mCurrentIconIndex
Joe Onorato2cc62e82010-03-17 20:23:53 -0700629 = sRollo.selectIcon(x, y, SELECTED_PRESSED);
Daniel Sandler388f6792010-03-02 14:08:08 -0500630 if (mDownIconIndex < 0) {
631 // if nothing was selected, no long press.
632 cancelLongPress();
633 }
634 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700635 sRollo.mState.save();
636 sRollo.move();
Daniel Sandler388f6792010-03-02 14:08:08 -0500637 mVelocityTracker = VelocityTracker.obtain();
638 mVelocityTracker.addMovement(ev);
639 mStartedScrolling = false;
640 }
641 break;
642 case MotionEvent.ACTION_MOVE:
643 case MotionEvent.ACTION_OUTSIDE:
644 if (mTouchTracking == TRACKING_HOME) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700645 sRollo.setHomeSelected((isPortrait &&
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700646 y > mTouchYBorders[mTouchYBorders.length-1]) || (!isPortrait
647 && x > mTouchXBorders[mTouchXBorders.length-1])
Daniel Sandler388f6792010-03-02 14:08:08 -0500648 ? SELECTED_PRESSED : SELECTED_NONE);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700649 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500650 } else if (mTouchTracking == TRACKING_FLING) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500651 int rawY = (int)ev.getRawY();
652 int slop;
653 slop = Math.abs(rawY - mMotionDownRawY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800654
Daniel Sandler388f6792010-03-02 14:08:08 -0500655 if (!mStartedScrolling && slop < mSlop) {
656 // don't update anything so when we do start scrolling
657 // below, we get the right delta.
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700658 mCurrentIconIndex = chooseTappedIcon(x, y);
Daniel Sandler388f6792010-03-02 14:08:08 -0500659 if (mDownIconIndex != mCurrentIconIndex) {
660 // If a different icon is selected, don't allow it to be picked up.
661 // This handles off-axis dragging.
662 cancelLongPress();
663 mCurrentIconIndex = -1;
664 }
665 } else {
666 if (!mStartedScrolling) {
667 cancelLongPress();
668 mCurrentIconIndex = -1;
669 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700670 sRollo.mState.newPositionX = ev.getRawY() / getHeight();
671 sRollo.mState.newTouchDown = 1;
672 sRollo.move();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800673
Daniel Sandler388f6792010-03-02 14:08:08 -0500674 mStartedScrolling = true;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700675 sRollo.clearSelectedIcon();
Daniel Sandler388f6792010-03-02 14:08:08 -0500676 mVelocityTracker.addMovement(ev);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700677 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500678 }
679 }
680 break;
681 case MotionEvent.ACTION_UP:
682 case MotionEvent.ACTION_CANCEL:
683 if (mTouchTracking == TRACKING_HOME) {
684 if (action == MotionEvent.ACTION_UP) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -0700685 if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
686 (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500687 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
688 mLauncher.closeAllApps(true);
689 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700690 sRollo.setHomeSelected(SELECTED_NONE);
691 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -0500692 }
693 mCurrentIconIndex = -1;
694 } else if (mTouchTracking == TRACKING_FLING) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700695 sRollo.mState.newTouchDown = 0;
696 sRollo.mState.newPositionX = ev.getRawY() / getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800697
Daniel Sandler388f6792010-03-02 14:08:08 -0500698 mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700699 sRollo.mState.flingVelocity = mVelocityTracker.getYVelocity() / getHeight();
700 sRollo.clearSelectedIcon();
701 sRollo.mState.save();
702 sRollo.fling();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800703
Daniel Sandler388f6792010-03-02 14:08:08 -0500704 if (mVelocityTracker != null) {
705 mVelocityTracker.recycle();
706 mVelocityTracker = null;
707 }
708 }
709 mTouchTracking = TRACKING_NONE;
710 break;
711 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800712
Daniel Sandler388f6792010-03-02 14:08:08 -0500713 return true;
714 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800715
Daniel Sandler388f6792010-03-02 14:08:08 -0500716 public void onClick(View v) {
717 if (mLocks != 0 || !isVisible()) {
718 return;
719 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700720 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500721 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
722 reallyPlaySoundEffect(SoundEffectConstants.CLICK);
723 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Joe Onoratof984e852010-03-25 09:47:45 -0700724 mLauncher.startActivitySafely(app.intent, app);
Daniel Sandler388f6792010-03-02 14:08:08 -0500725 }
726 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800727
Daniel Sandler388f6792010-03-02 14:08:08 -0500728 public boolean onLongClick(View v) {
729 if (mLocks != 0 || !isVisible()) {
730 return true;
731 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700732 if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
Daniel Sandler388f6792010-03-02 14:08:08 -0500733 && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
734 ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800735
Daniel Sandler388f6792010-03-02 14:08:08 -0500736 Bitmap bmp = app.iconBitmap;
737 final int w = bmp.getWidth();
738 final int h = bmp.getHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800739
Daniel Sandler388f6792010-03-02 14:08:08 -0500740 // We don't really have an accurate location to use. This will do.
741 int screenX = mMotionDownRawX - (w / 2);
742 int screenY = mMotionDownRawY - h;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800743
Daniel Sandler388f6792010-03-02 14:08:08 -0500744 mDragController.startDrag(bmp, screenX, screenY,
745 0, 0, w, h, this, app, DragController.DRAG_ACTION_COPY);
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800746
Daniel Sandler388f6792010-03-02 14:08:08 -0500747 mLauncher.closeAllApps(true);
748 }
749 return true;
750 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800751
Daniel Sandler388f6792010-03-02 14:08:08 -0500752 @Override
753 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
754 if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
755 if (!isVisible()) {
756 return false;
757 }
758 String text = null;
759 int index;
760 int count = mAllAppsList.size() + 1; // +1 is home
761 int pos = -1;
762 switch (mLastSelection) {
763 case SELECTION_ICONS:
Joe Onorato2cc62e82010-03-17 20:23:53 -0700764 index = sRollo.mState.selectedIconIndex;
Daniel Sandler388f6792010-03-02 14:08:08 -0500765 if (index >= 0) {
766 ApplicationInfo info = mAllAppsList.get(index);
767 if (info.title != null) {
768 text = info.title.toString();
769 pos = index;
770 }
771 }
772 break;
773 case SELECTION_HOME:
774 text = getContext().getString(R.string.all_apps_home_button_label);
775 pos = count;
776 break;
777 }
778 if (text != null) {
779 event.setEnabled(true);
780 event.getText().add(text);
781 //event.setContentDescription(text);
782 event.setItemCount(count);
783 event.setCurrentItemIndex(pos);
784 }
785 }
786 return false;
787 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800788
Daniel Sandler388f6792010-03-02 14:08:08 -0500789 public void setDragController(DragController dragger) {
790 mDragController = dragger;
791 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800792
Daniel Sandler388f6792010-03-02 14:08:08 -0500793 public void onDropCompleted(View target, boolean success) {
794 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800795
Daniel Sandler388f6792010-03-02 14:08:08 -0500796 /**
797 * Zoom to the specifed level.
798 *
799 * @param zoom [0..1] 0 is hidden, 1 is open
800 */
801 public void zoom(float zoom, boolean animate) {
802 cancelLongPress();
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700803 sNextZoom = zoom;
804 sAnimateNextZoom = animate;
Daniel Sandler388f6792010-03-02 14:08:08 -0500805 // if we do setZoom while we don't have a surface, we won't
806 // get the callbacks that actually set mZoom.
Joe Onorato2cc62e82010-03-17 20:23:53 -0700807 if (sRollo == null || !mHaveSurface) {
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700808 sZoomDirty = true;
Daniel Sandler388f6792010-03-02 14:08:08 -0500809 mZoom = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -0500810 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700811 sRollo.setZoom(zoom, animate);
Daniel Sandler388f6792010-03-02 14:08:08 -0500812 }
813 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800814
Joe Onorato878f0862010-03-22 12:22:22 -0400815 /**
816 * If sRollo is null, then we're not visible. This is also used to guard against
817 * sRollo being null.
818 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500819 public boolean isVisible() {
Joe Onorato878f0862010-03-22 12:22:22 -0400820 return sRollo != null && mZoom > 0.001f;
Daniel Sandler388f6792010-03-02 14:08:08 -0500821 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800822
Daniel Sandler388f6792010-03-02 14:08:08 -0500823 public boolean isOpaque() {
824 return mZoom > 0.999f;
825 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800826
Daniel Sandler388f6792010-03-02 14:08:08 -0500827 public void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700828 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500829 // We've been removed from the window. Don't bother with all this.
830 return;
831 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800832
Daniel Sandler707b0f72010-04-15 16:41:31 -0400833 if (list != null) {
834 Collections.sort(list, LauncherModel.APP_NAME_COMPARATOR);
835 }
836
Romain Guy13c2e7b2010-03-10 19:45:00 -0800837 boolean reload = false;
838 if (mAllAppsList == null) {
839 reload = true;
840 } else if (list.size() != mAllAppsList.size()) {
841 reload = true;
842 } else {
843 final int count = list.size();
844 for (int i = 0; i < count; i++) {
845 if (list.get(i) != mAllAppsList.get(i)) {
846 reload = true;
847 break;
848 }
849 }
850 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800851
Daniel Sandler388f6792010-03-02 14:08:08 -0500852 mAllAppsList = list;
Joe Onorato2cc62e82010-03-17 20:23:53 -0700853 if (sRollo != null && reload) {
854 sRollo.setApps(list);
Daniel Sandler388f6792010-03-02 14:08:08 -0500855 }
Romain Guyc16fea72010-03-12 17:17:56 -0800856
857 if (hasFocus() && mRestoreFocusIndex != -1) {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700858 sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
859 sRollo.mState.save();
Romain Guyc16fea72010-03-12 17:17:56 -0800860 mRestoreFocusIndex = -1;
861 }
862
Daniel Sandler388f6792010-03-02 14:08:08 -0500863 mLocks &= ~LOCK_ICONS_PENDING;
864 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800865
Daniel Sandler388f6792010-03-02 14:08:08 -0500866 public void addApps(ArrayList<ApplicationInfo> list) {
867 if (mAllAppsList == null) {
868 // Not done loading yet. We'll find out about it later.
869 return;
870 }
Joe Onorato2cc62e82010-03-17 20:23:53 -0700871 if (sRS == null) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500872 // We've been removed from the window. Don't bother with all this.
873 return;
874 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800875
Daniel Sandler388f6792010-03-02 14:08:08 -0500876 final int N = list.size();
Joe Onorato2cc62e82010-03-17 20:23:53 -0700877 if (sRollo != null) {
878 sRollo.pause();
879 sRollo.reallocAppsList(sRollo.mState.iconCount + N);
Daniel Sandler388f6792010-03-02 14:08:08 -0500880 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800881
Daniel Sandler388f6792010-03-02 14:08:08 -0500882 for (int i=0; i<N; i++) {
883 final ApplicationInfo item = list.get(i);
884 int index = Collections.binarySearch(mAllAppsList, item,
885 LauncherModel.APP_NAME_COMPARATOR);
886 if (index < 0) {
887 index = -(index+1);
888 }
889 mAllAppsList.add(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700890 if (sRollo != null) {
891 sRollo.addApp(index, item);
Daniel Sandler388f6792010-03-02 14:08:08 -0500892 }
893 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800894
Joe Onorato2cc62e82010-03-17 20:23:53 -0700895 if (sRollo != null) {
896 sRollo.saveAppsList();
897 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500898 }
899 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800900
Daniel Sandler388f6792010-03-02 14:08:08 -0500901 public void removeApps(ArrayList<ApplicationInfo> list) {
902 if (mAllAppsList == null) {
903 // Not done loading yet. We'll find out about it later.
904 return;
905 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800906
Joe Onorato2cc62e82010-03-17 20:23:53 -0700907 if (sRollo != null) {
908 sRollo.pause();
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800909 }
Daniel Sandler388f6792010-03-02 14:08:08 -0500910 final int N = list.size();
911 for (int i=0; i<N; i++) {
912 final ApplicationInfo item = list.get(i);
913 int index = findAppByComponent(mAllAppsList, item);
914 if (index >= 0) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500915 mAllAppsList.remove(index);
Joe Onorato2cc62e82010-03-17 20:23:53 -0700916 if (sRollo != null) {
917 sRollo.removeApp(index);
Daniel Sandler388f6792010-03-02 14:08:08 -0500918 }
919 } else {
920 Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
921 // Try to recover. This should keep us from crashing for now.
922 }
923 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800924
Joe Onorato2cc62e82010-03-17 20:23:53 -0700925 if (sRollo != null) {
926 sRollo.saveAppsList();
927 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -0500928 }
929 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800930
Joe Onorato64e6be72010-03-05 15:05:52 -0500931 public void updateApps(ArrayList<ApplicationInfo> list) {
Daniel Sandler388f6792010-03-02 14:08:08 -0500932 // Just remove and add, because they may need to be re-sorted.
933 removeApps(list);
934 addApps(list);
935 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800936
Daniel Sandler388f6792010-03-02 14:08:08 -0500937 private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
938 ComponentName component = item.intent.getComponent();
939 final int N = list.size();
940 for (int i=0; i<N; i++) {
941 ApplicationInfo x = list.get(i);
942 if (x.intent.getComponent().equals(component)) {
943 return i;
944 }
945 }
946 return -1;
947 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800948
Romain Guy060b5c82010-03-04 10:07:38 -0800949 /*
Daniel Sandler388f6792010-03-02 14:08:08 -0500950 private static int countPages(int iconCount) {
Romain Guy060b5c82010-03-04 10:07:38 -0800951 int iconsPerPage = getColumnsCount() * Defines.ROWS_PER_PAGE_PORTRAIT;
Daniel Sandler388f6792010-03-02 14:08:08 -0500952 int pages = iconCount / iconsPerPage;
953 if (pages*iconsPerPage != iconCount) {
954 pages++;
955 }
956 return pages;
957 }
Romain Guy060b5c82010-03-04 10:07:38 -0800958 */
Daniel Sandler388f6792010-03-02 14:08:08 -0500959
960 class AAMessage extends RenderScript.RSMessage {
961 public void run() {
Joe Onorato2cc62e82010-03-17 20:23:53 -0700962 sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
Daniel Sandler388f6792010-03-02 14:08:08 -0500963 mVelocity = ((float)mData[1]) / (1 << 16);
964 mZoom = ((float)mData[2]) / (1 << 16);
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700965 sZoomDirty = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500966 }
967 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800968
Romain Guy13c2e7b2010-03-10 19:45:00 -0800969 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500970 // Allocations ======
971 private int mWidth;
972 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800973
Daniel Sandler388f6792010-03-02 14:08:08 -0500974 private Resources mRes;
975 private Script mScript;
976 private Script.Invokable mInvokeMove;
977 private Script.Invokable mInvokeMoveTo;
978 private Script.Invokable mInvokeFling;
979 private Script.Invokable mInvokeResetWAR;
980 private Script.Invokable mInvokeSetZoom;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800981
Daniel Sandler388f6792010-03-02 14:08:08 -0500982 private ProgramStore mPSIcons;
983 private ProgramFragment mPFTexMip;
984 private ProgramFragment mPFTexMipAlpha;
985 private ProgramFragment mPFTexNearest;
986 private ProgramVertex mPV;
987 private ProgramVertex mPVCurve;
988 private SimpleMesh mMesh;
989 private ProgramVertex.MatrixAllocation mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800990
Daniel Sandler388f6792010-03-02 14:08:08 -0500991 private Allocation mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800992
Daniel Sandler388f6792010-03-02 14:08:08 -0500993 private Allocation mHomeButtonNormal;
994 private Allocation mHomeButtonFocused;
995 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800996
Daniel Sandler388f6792010-03-02 14:08:08 -0500997 private Allocation[] mIcons;
998 private int[] mIconIds;
999 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001000
Daniel Sandler388f6792010-03-02 14:08:08 -05001001 private Allocation[] mLabels;
1002 private int[] mLabelIds;
1003 private Allocation mAllocLabelIds;
1004 private Allocation mSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001005
Daniel Sandler388f6792010-03-02 14:08:08 -05001006 private Bitmap mSelectionBitmap;
1007 private Canvas mSelectionCanvas;
Romain Guy6a42cf32010-03-12 16:03:52 -08001008
1009 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001010
Daniel Sandler388f6792010-03-02 14:08:08 -05001011 Params mParams;
1012 State mState;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001013
Romain Guy13c2e7b2010-03-10 19:45:00 -08001014 AllApps3D mAllApps;
1015 boolean mInitialize;
1016
Daniel Sandler388f6792010-03-02 14:08:08 -05001017 class BaseAlloc {
1018 Allocation mAlloc;
1019 Type mType;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001020
Daniel Sandler388f6792010-03-02 14:08:08 -05001021 void save() {
1022 mAlloc.data(this);
1023 }
1024 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001025
Daniel Sandler388f6792010-03-02 14:08:08 -05001026 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001027 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -08001028 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -05001029 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001030
1031 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001032 if (sRS != null) {
1033 sRS.contextBindRootScript(null);
1034 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001035 }
1036
1037 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001038 if (sRS != null) {
1039 sRS.contextBindRootScript(mScript);
1040 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001041 }
1042
Daniel Sandler388f6792010-03-02 14:08:08 -05001043 class Params extends BaseAlloc {
1044 Params() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001045 mType = Type.createFromClass(sRS, Params.class, 1, "ParamsClass");
1046 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001047 save();
1048 }
1049 public int bubbleWidth;
1050 public int bubbleHeight;
1051 public int bubbleBitmapWidth;
1052 public int bubbleBitmapHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001053
Daniel Sandler388f6792010-03-02 14:08:08 -05001054 public int homeButtonWidth;
1055 public int homeButtonHeight;
1056 public int homeButtonTextureWidth;
1057 public int homeButtonTextureHeight;
1058 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001059
Daniel Sandler388f6792010-03-02 14:08:08 -05001060 class State extends BaseAlloc {
1061 public float newPositionX;
1062 public int newTouchDown;
1063 public float flingVelocity;
1064 public int iconCount;
1065 public int selectedIconIndex = -1;
1066 public int selectedIconTexture;
1067 public float zoomTarget;
1068 public int homeButtonId;
1069 public float targetPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001070
Daniel Sandler388f6792010-03-02 14:08:08 -05001071 State() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001072 mType = Type.createFromClass(sRS, State.class, 1, "StateClass");
1073 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001074 save();
1075 }
1076 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001077
Romain Guy13c2e7b2010-03-10 19:45:00 -08001078 public RolloRS(AllApps3D allApps) {
1079 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -05001080 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001081
Daniel Sandler388f6792010-03-02 14:08:08 -05001082 public void init(Resources res, int width, int height) {
1083 mRes = res;
1084 mWidth = width;
1085 mHeight = height;
1086 initProgramVertex();
1087 initProgramFragment();
1088 initProgramStore();
1089 initGl();
1090 initData();
Daniel Sandler388f6792010-03-02 14:08:08 -05001091 initRs();
1092 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001093
Daniel Sandler388f6792010-03-02 14:08:08 -05001094 public void initMesh() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001095 SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001096
Daniel Sandler388f6792010-03-02 14:08:08 -05001097 for (int ct=0; ct < 16; ct++) {
1098 float pos = (1.f / (16.f - 1)) * ct;
1099 tm.addVertex(0.0f, pos);
1100 tm.addVertex(1.0f, pos);
1101 }
1102 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1103 tm.addTriangle(ct, ct+1, ct+2);
1104 tm.addTriangle(ct+1, ct+3, ct+2);
1105 }
1106 mMesh = tm.create();
1107 mMesh.setName("SMCell");
1108 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001109
Daniel Sandler388f6792010-03-02 14:08:08 -05001110 void resize(int w, int h) {
1111 mPVA.setupProjectionNormalized(w, h);
1112 mWidth = w;
1113 mHeight = h;
1114 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001115
Daniel Sandler388f6792010-03-02 14:08:08 -05001116 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001117 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001118 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001119
Joe Onorato2cc62e82010-03-17 20:23:53 -07001120 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001121 pvb.setTextureMatrixEnable(true);
1122 mPV = pvb.create();
1123 mPV.setName("PV");
1124 mPV.bindAllocation(mPVA);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001125
Joe Onorato2cc62e82010-03-17 20:23:53 -07001126 Element.Builder eb = new Element.Builder(sRS);
1127 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "ImgSize");
1128 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "Position");
1129 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "BendPos");
1130 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "ScaleOffset");
Daniel Sandler388f6792010-03-02 14:08:08 -05001131 Element e = eb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001132
Joe Onorato2cc62e82010-03-17 20:23:53 -07001133 mUniformAlloc = Allocation.createSized(sRS, e, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001134
Daniel Sandler388f6792010-03-02 14:08:08 -05001135 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001136 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Romain Guy060b5c82010-03-04 10:07:38 -08001137 String t = "void main() {\n" +
1138 // Animation
1139 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001140
Romain Guy060b5c82010-03-04 10:07:38 -08001141 " float bendY1 = UNI_BendPos.x;\n" +
1142 " float bendY2 = UNI_BendPos.y;\n" +
1143 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1144 " float bendDistance = bendY1 * 0.4;\n" +
1145 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001146
Romain Guy060b5c82010-03-04 10:07:38 -08001147 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1148 " float aDy = cos(bendAngle);\n" +
1149 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001150
Romain Guy060b5c82010-03-04 10:07:38 -08001151 " float scale = (2.0 / 480.0);\n" +
1152 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1153 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1154 " float y = 0.0;\n" +
1155 " float z = 0.0;\n" +
1156 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001157
Romain Guy060b5c82010-03-04 10:07:38 -08001158 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1159 " y += cv * aDy;\n" +
1160 " z += -cv * aDz;\n" +
1161 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1162 " lum += cv / bendDistance * distanceDimLevel;\n" +
1163 " y += cv * cos(cv * bendStep);\n" +
1164 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001165
Romain Guy060b5c82010-03-04 10:07:38 -08001166 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1167 " y += cv * aDy;\n" +
1168 " z += cv * aDz;\n" +
1169 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1170 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1171 " y += cv * cos(cv * bendStep);\n" +
1172 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001173
Romain Guy060b5c82010-03-04 10:07:38 -08001174 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001175
Romain Guy060b5c82010-03-04 10:07:38 -08001176 " vec4 pos;\n" +
1177 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1178 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1179 " pos.z = z * UNI_ScaleOffset.x;\n" +
1180 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001181
Romain Guy060b5c82010-03-04 10:07:38 -08001182 " pos.x *= 1.0 + ani * 4.0;\n" +
1183 " pos.y *= 1.0 + ani * 4.0;\n" +
1184 " pos.z -= ani * 1.5;\n" +
1185 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001186
Romain Guy060b5c82010-03-04 10:07:38 -08001187 " gl_Position = UNI_MVP * pos;\n" +
1188 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1189 " varTex0.xy = ATTRIB_position;\n" +
1190 " varTex0.y = 1.0 - varTex0.y;\n" +
1191 " varTex0.zw = vec2(0.0, 0.0);\n" +
1192 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001193 sb.setShader(t);
1194 sb.addConstant(mUniformAlloc.getType());
1195 sb.addInput(mMesh.getVertexType(0).getElement());
1196 mPVCurve = sb.create();
1197 mPVCurve.setName("PVCurve");
1198 mPVCurve.bindAllocation(mPVA);
1199 mPVCurve.bindConstants(mUniformAlloc, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001200
Joe Onorato2cc62e82010-03-17 20:23:53 -07001201 sRS.contextBindProgramVertex(mPV);
Daniel Sandler388f6792010-03-02 14:08:08 -05001202 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001203
Daniel Sandler388f6792010-03-02 14:08:08 -05001204 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001205 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001206 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1207 sb.setMag(Sampler.Value.NEAREST);
1208 sb.setWrapS(Sampler.Value.CLAMP);
1209 sb.setWrapT(Sampler.Value.CLAMP);
1210 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001211
Daniel Sandler388f6792010-03-02 14:08:08 -05001212 sb.setMin(Sampler.Value.NEAREST);
1213 sb.setMag(Sampler.Value.NEAREST);
1214 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001215
Joe Onorato2cc62e82010-03-17 20:23:53 -07001216 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001217 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1218 ProgramFragment.Builder.Format.RGBA, 0);
1219 mPFTexMip = bf.create();
1220 mPFTexMip.setName("PFTexMip");
1221 mPFTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001222
Daniel Sandler388f6792010-03-02 14:08:08 -05001223 mPFTexNearest = bf.create();
1224 mPFTexNearest.setName("PFTexNearest");
1225 mPFTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001226
Daniel Sandler388f6792010-03-02 14:08:08 -05001227 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1228 ProgramFragment.Builder.Format.ALPHA, 0);
1229 mPFTexMipAlpha = bf.create();
1230 mPFTexMipAlpha.setName("PFTexMipAlpha");
1231 mPFTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001232
Daniel Sandler388f6792010-03-02 14:08:08 -05001233 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001234
Daniel Sandler388f6792010-03-02 14:08:08 -05001235 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001236 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001237 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1238 bs.setColorMask(true,true,true,false);
1239 bs.setDitherEnable(true);
1240 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1241 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
1242 mPSIcons = bs.create();
1243 mPSIcons.setName("PSIcons");
1244 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001245
Daniel Sandler388f6792010-03-02 14:08:08 -05001246 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001247 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001248
Daniel Sandler388f6792010-03-02 14:08:08 -05001249 private void initData() {
1250 mParams = new Params();
1251 mState = new State();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001252
Romain Guy13c2e7b2010-03-10 19:45:00 -08001253 final Utilities.BubbleText bubble = new Utilities.BubbleText(mAllApps.getContext());
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001254
Daniel Sandler388f6792010-03-02 14:08:08 -05001255 mParams.bubbleWidth = bubble.getBubbleWidth();
1256 mParams.bubbleHeight = bubble.getMaxBubbleHeight();
1257 mParams.bubbleBitmapWidth = bubble.getBitmapWidth();
1258 mParams.bubbleBitmapHeight = bubble.getBitmapHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001259
Joe Onorato2cc62e82010-03-17 20:23:53 -07001260 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1261 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001262 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001263 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1264 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001265 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001266 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1267 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001268 mHomeButtonPressed.uploadToTexture(0);
1269 mParams.homeButtonWidth = 76;
1270 mParams.homeButtonHeight = 68;
1271 mParams.homeButtonTextureWidth = 128;
1272 mParams.homeButtonTextureHeight = 128;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001273
Daniel Sandler388f6792010-03-02 14:08:08 -05001274 mState.homeButtonId = mHomeButtonNormal.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001275
Daniel Sandler388f6792010-03-02 14:08:08 -05001276 mParams.save();
1277 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001278
Daniel Sandler388f6792010-03-02 14:08:08 -05001279 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1280 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1281 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001282
Daniel Sandler388f6792010-03-02 14:08:08 -05001283 setApps(null);
1284 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001285
Daniel Sandler388f6792010-03-02 14:08:08 -05001286 private void initRs() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001287 ScriptC.Builder sb = new ScriptC.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001288 sb.setScript(mRes, R.raw.allapps);
1289 sb.setRoot(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001290 sb.addDefines(mAllApps.mDefines);
Daniel Sandler388f6792010-03-02 14:08:08 -05001291 sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS);
1292 sb.setType(mState.mType, "state", Defines.ALLOC_STATE);
1293 sb.setType(mUniformAlloc.getType(), "vpConstants", Defines.ALLOC_VP_CONSTANTS);
1294 mInvokeMove = sb.addInvokable("move");
1295 mInvokeFling = sb.addInvokable("fling");
1296 mInvokeMoveTo = sb.addInvokable("moveTo");
1297 mInvokeResetWAR = sb.addInvokable("resetHWWar");
1298 mInvokeSetZoom = sb.addInvokable("setZoom");
1299 mScript = sb.create();
1300 mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1301 mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
1302 mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
1303 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1304 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
1305 mScript.bindAllocation(mUniformAlloc, Defines.ALLOC_VP_CONSTANTS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001306
Joe Onorato2cc62e82010-03-17 20:23:53 -07001307 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -05001308 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001309
Daniel Sandler388f6792010-03-02 14:08:08 -05001310 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001311 if (sZoomDirty) {
1312 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001313 }
1314 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001315
Romain Guy060b5c82010-03-04 10:07:38 -08001316 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001317 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001318 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001319 final int count = list != null ? list.size() : 0;
1320 int allocCount = count;
1321 if (allocCount < 1) {
1322 allocCount = 1;
1323 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001324
Daniel Sandler388f6792010-03-02 14:08:08 -05001325 mIcons = new Allocation[count];
1326 mIconIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001327 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001328
Daniel Sandler388f6792010-03-02 14:08:08 -05001329 mLabels = new Allocation[count];
1330 mLabelIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001331 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001332
Daniel Sandler388f6792010-03-02 14:08:08 -05001333 mState.iconCount = count;
1334 for (int i=0; i < mState.iconCount; i++) {
1335 createAppIconAllocations(i, list.get(i));
1336 }
1337 for (int i=0; i < mState.iconCount; i++) {
1338 uploadAppIcon(i, list.get(i));
1339 }
1340 saveAppsList();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001341 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001342 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001343
Daniel Sandler388f6792010-03-02 14:08:08 -05001344 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001345 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001346 sRollo.clearSelectedIcon();
1347 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001348 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001349 if (zoom > 0.001f) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001350 sRollo.mState.zoomTarget = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -05001351 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001352 sRollo.mState.zoomTarget = 0;
Daniel Sandler388f6792010-03-02 14:08:08 -05001353 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001354 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -05001355 if (!animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001356 sRollo.mInvokeSetZoom.execute();
Daniel Sandler388f6792010-03-02 14:08:08 -05001357 }
1358 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001359
Daniel Sandler388f6792010-03-02 14:08:08 -05001360 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001361 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1362 Element.RGBA_8888(sRS), false);
1363 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1364 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001365 mIconIds[index] = mIcons[index].getID();
1366 mLabelIds[index] = mLabels[index].getID();
1367 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001368
Daniel Sandler388f6792010-03-02 14:08:08 -05001369 private void uploadAppIcon(int index, ApplicationInfo item) {
1370 if (mIconIds[index] != mIcons[index].getID()) {
1371 throw new IllegalStateException("uploadAppIcon index=" + index
1372 + " mIcons[index].getID=" + mIcons[index].getID()
1373 + " mIconsIds[index]=" + mIconIds[index]
1374 + " item=" + item);
1375 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001376 mIcons[index].uploadToTexture(true, 0);
1377 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001378 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001379
Daniel Sandler388f6792010-03-02 14:08:08 -05001380 /**
1381 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1382 * fill in the values and call saveAppsList().
1383 */
1384 private void reallocAppsList(int count) {
1385 Allocation[] icons = new Allocation[count];
1386 int[] iconIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001387 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001388
Daniel Sandler388f6792010-03-02 14:08:08 -05001389 Allocation[] labels = new Allocation[count];
1390 int[] labelIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001391 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001392
Joe Onorato2cc62e82010-03-17 20:23:53 -07001393 final int oldCount = sRollo.mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001394
Daniel Sandler388f6792010-03-02 14:08:08 -05001395 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1396 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1397 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1398 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001399
Daniel Sandler388f6792010-03-02 14:08:08 -05001400 mIcons = icons;
1401 mIconIds = iconIds;
1402 mLabels = labels;
1403 mLabelIds = labelIds;
1404 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001405
Daniel Sandler388f6792010-03-02 14:08:08 -05001406 /**
1407 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1408 */
1409 private void addApp(int index, ApplicationInfo item) {
1410 final int count = mState.iconCount - index;
1411 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001412
Daniel Sandler388f6792010-03-02 14:08:08 -05001413 System.arraycopy(mIcons, index, mIcons, dest, count);
1414 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1415 System.arraycopy(mLabels, index, mLabels, dest, count);
1416 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001417
Daniel Sandler388f6792010-03-02 14:08:08 -05001418 createAppIconAllocations(index, item);
1419 uploadAppIcon(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001420 sRollo.mState.iconCount++;
Daniel Sandler388f6792010-03-02 14:08:08 -05001421 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001422
Daniel Sandler388f6792010-03-02 14:08:08 -05001423 /**
1424 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1425 */
1426 private void removeApp(int index) {
1427 final int count = mState.iconCount - index - 1;
1428 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001429
Daniel Sandler388f6792010-03-02 14:08:08 -05001430 System.arraycopy(mIcons, src, mIcons, index, count);
1431 System.arraycopy(mIconIds, src, mIconIds, index, count);
1432 System.arraycopy(mLabels, src, mLabels, index, count);
1433 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001434
Joe Onorato2cc62e82010-03-17 20:23:53 -07001435 sRollo.mState.iconCount--;
Daniel Sandler388f6792010-03-02 14:08:08 -05001436 final int last = mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001437
Daniel Sandler388f6792010-03-02 14:08:08 -05001438 mIcons[last] = null;
1439 mIconIds[last] = 0;
1440 mLabels[last] = null;
1441 mLabelIds[last] = 0;
1442 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001443
Daniel Sandler388f6792010-03-02 14:08:08 -05001444 /**
1445 * Send the apps list structures to RS.
1446 */
1447 private void saveAppsList() {
1448 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1449 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001450 mAllocIconIds.data(mIconIds);
1451 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001452
Daniel Sandler388f6792010-03-02 14:08:08 -05001453 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1454 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001455
Daniel Sandler388f6792010-03-02 14:08:08 -05001456 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001457
Daniel Sandler388f6792010-03-02 14:08:08 -05001458 // Note: mScript may be null if we haven't initialized it yet.
1459 // In that case, this is a no-op.
1460 if (mInvokeResetWAR != null) {
1461 mInvokeResetWAR.execute();
1462 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001463 }
1464 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001465
Daniel Sandler388f6792010-03-02 14:08:08 -05001466 void fling() {
1467 mInvokeFling.execute();
1468 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001469
Daniel Sandler388f6792010-03-02 14:08:08 -05001470 void move() {
1471 mInvokeMove.execute();
1472 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001473
Daniel Sandler388f6792010-03-02 14:08:08 -05001474 void moveTo(float row) {
1475 mState.targetPos = row;
1476 mState.save();
1477 mInvokeMoveTo.execute();
1478 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001479
Daniel Sandler388f6792010-03-02 14:08:08 -05001480 /**
1481 * You need to call save() on mState on your own after calling this.
1482 *
1483 * @return the index of the icon that was selected.
1484 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001485 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001486 if (mAllApps != null) {
1487 final int index = mAllApps.chooseTappedIcon(x, y);
1488 selectIcon(index, pressed);
1489 return index;
1490 } else {
1491 return -1;
1492 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001493 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001494
Daniel Sandler388f6792010-03-02 14:08:08 -05001495 /**
1496 * Select the icon at the given index.
1497 *
1498 * @param index The index.
1499 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1500 */
1501 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001502 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1503 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001504 if (mAllApps != null) {
1505 mAllApps.mRestoreFocusIndex = index;
1506 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001507 mState.selectedIconIndex = -1;
Romain Guy13c2e7b2010-03-10 19:45:00 -08001508 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1509 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001510 }
1511 } else {
1512 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001513 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001514 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001515
Daniel Sandler388f6792010-03-02 14:08:08 -05001516 int prev = mState.selectedIconIndex;
1517 mState.selectedIconIndex = index;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001518
Romain Guy13c2e7b2010-03-10 19:45:00 -08001519 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001520 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001521
Daniel Sandler388f6792010-03-02 14:08:08 -05001522 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1523 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1524 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001525
Joe Onorato2cc62e82010-03-17 20:23:53 -07001526 mSelectedIcon = Allocation.createFromBitmap(sRS, selectionBitmap,
1527 Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001528 mSelectedIcon.uploadToTexture(0);
1529 mState.selectedIconTexture = mSelectedIcon.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001530
Daniel Sandler388f6792010-03-02 14:08:08 -05001531 if (prev != index) {
1532 if (info.title != null && info.title.length() > 0) {
1533 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001534 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001535 }
1536 }
1537 }
1538 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001539
Daniel Sandler388f6792010-03-02 14:08:08 -05001540 /**
1541 * You need to call save() on mState on your own after calling this.
1542 */
1543 void clearSelectedIcon() {
1544 mState.selectedIconIndex = -1;
1545 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001546
Daniel Sandler388f6792010-03-02 14:08:08 -05001547 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001548 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001549 switch (mode) {
1550 case SELECTED_NONE:
1551 mState.homeButtonId = mHomeButtonNormal.getID();
1552 break;
1553 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001554 mAllApps.mLastSelection = SELECTION_HOME;
Daniel Sandler388f6792010-03-02 14:08:08 -05001555 mState.homeButtonId = mHomeButtonFocused.getID();
1556 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001557 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001558 }
1559 break;
1560 case SELECTED_PRESSED:
1561 mState.homeButtonId = mHomeButtonPressed.getID();
1562 break;
1563 }
1564 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001565
Daniel Sandler388f6792010-03-02 14:08:08 -05001566 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001567 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1568 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1569 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001570 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001571 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001572 }
1573 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001574 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001575 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001576 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001577 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001578 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001579 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001580 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Joe Onorato2cc62e82010-03-17 20:23:53 -07001581 Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1582 Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1583 Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1584 Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1585 Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1586 Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1587 Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1588 Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1589 Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
1590 Log.d(TAG, "sRollo.mParams.bubbleWidth=" + mParams.bubbleWidth);
1591 Log.d(TAG, "sRollo.mParams.bubbleHeight=" + mParams.bubbleHeight);
1592 Log.d(TAG, "sRollo.mParams.bubbleBitmapWidth=" + mParams.bubbleBitmapWidth);
1593 Log.d(TAG, "sRollo.mParams.bubbleBitmapHeight=" + mParams.bubbleBitmapHeight);
1594 Log.d(TAG, "sRollo.mParams.homeButtonWidth=" + mParams.homeButtonWidth);
1595 Log.d(TAG, "sRollo.mParams.homeButtonHeight=" + mParams.homeButtonHeight);
1596 Log.d(TAG, "sRollo.mParams.homeButtonTextureWidth=" + mParams.homeButtonTextureWidth);
1597 Log.d(TAG, "sRollo.mParams.homeButtonTextureHeight=" + mParams.homeButtonTextureHeight);
Daniel Sandler388f6792010-03-02 14:08:08 -05001598 }
1599 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001600
Daniel Sandler388f6792010-03-02 14:08:08 -05001601 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001602 Log.d(TAG, "sRS=" + sRS);
1603 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001604 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001605 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1606 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001607 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1608 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1609 Log.d(TAG, "mLastSelection=" + mLastSelection);
1610 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1611 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1612 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1613 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001614 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1615 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001616 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001617 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001618 Log.d(TAG, "mVelocity=" + mVelocity);
1619 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001620 if (sRollo != null) {
1621 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001622 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001623 if (sRS != null) {
1624 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001625 }
1626 }
1627}
1628
1629