blob: b8aa8eccf10a39eb1b96f72f99928f8b4270efcc [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);
Romain Guy8783a052010-06-07 17:08:34 -0700964
965 boolean lastVisible = isVisible();
Daniel Sandler388f6792010-03-02 14:08:08 -0500966 mZoom = ((float)mData[2]) / (1 << 16);
Romain Guy8783a052010-06-07 17:08:34 -0700967
968 final boolean visible = isVisible();
969 if (visible != lastVisible) {
970 post(new Runnable() {
971 public void run() {
972 if (visible) {
973 showSurface();
974 } else {
975 hideSurface();
976 }
977 }
978 });
979 }
980
Joe Onoratoeffc4a82010-04-15 11:48:13 -0700981 sZoomDirty = false;
Daniel Sandler388f6792010-03-02 14:08:08 -0500982 }
983 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800984
Romain Guy13c2e7b2010-03-10 19:45:00 -0800985 public static class RolloRS {
Daniel Sandler388f6792010-03-02 14:08:08 -0500986 // Allocations ======
987 private int mWidth;
988 private int mHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800989
Daniel Sandler388f6792010-03-02 14:08:08 -0500990 private Resources mRes;
991 private Script mScript;
992 private Script.Invokable mInvokeMove;
993 private Script.Invokable mInvokeMoveTo;
994 private Script.Invokable mInvokeFling;
995 private Script.Invokable mInvokeResetWAR;
996 private Script.Invokable mInvokeSetZoom;
Jason Samsdd8cd8b2010-03-11 12:38:48 -0800997
Daniel Sandler388f6792010-03-02 14:08:08 -0500998 private ProgramStore mPSIcons;
999 private ProgramFragment mPFTexMip;
1000 private ProgramFragment mPFTexMipAlpha;
1001 private ProgramFragment mPFTexNearest;
1002 private ProgramVertex mPV;
1003 private ProgramVertex mPVCurve;
1004 private SimpleMesh mMesh;
1005 private ProgramVertex.MatrixAllocation mPVA;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001006
Daniel Sandler388f6792010-03-02 14:08:08 -05001007 private Allocation mUniformAlloc;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001008
Daniel Sandler388f6792010-03-02 14:08:08 -05001009 private Allocation mHomeButtonNormal;
1010 private Allocation mHomeButtonFocused;
1011 private Allocation mHomeButtonPressed;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001012
Daniel Sandler388f6792010-03-02 14:08:08 -05001013 private Allocation[] mIcons;
1014 private int[] mIconIds;
1015 private Allocation mAllocIconIds;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001016
Daniel Sandler388f6792010-03-02 14:08:08 -05001017 private Allocation[] mLabels;
1018 private int[] mLabelIds;
1019 private Allocation mAllocLabelIds;
1020 private Allocation mSelectedIcon;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001021
Daniel Sandler388f6792010-03-02 14:08:08 -05001022 private Bitmap mSelectionBitmap;
1023 private Canvas mSelectionCanvas;
Romain Guy6a42cf32010-03-12 16:03:52 -08001024
1025 private float mScrollPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001026
Daniel Sandler388f6792010-03-02 14:08:08 -05001027 Params mParams;
1028 State mState;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001029
Romain Guy13c2e7b2010-03-10 19:45:00 -08001030 AllApps3D mAllApps;
1031 boolean mInitialize;
1032
Daniel Sandler388f6792010-03-02 14:08:08 -05001033 class BaseAlloc {
1034 Allocation mAlloc;
1035 Type mType;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001036
Daniel Sandler388f6792010-03-02 14:08:08 -05001037 void save() {
1038 mAlloc.data(this);
1039 }
1040 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001041
Daniel Sandler388f6792010-03-02 14:08:08 -05001042 private boolean checkClickOK() {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001043 return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
Romain Guy6a42cf32010-03-12 16:03:52 -08001044 (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
Daniel Sandler388f6792010-03-02 14:08:08 -05001045 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001046
1047 void pause() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001048 if (sRS != null) {
1049 sRS.contextBindRootScript(null);
1050 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001051 }
1052
1053 void resume() {
Joe Onoratoc5210eb2010-03-23 11:26:28 -04001054 if (sRS != null) {
1055 sRS.contextBindRootScript(mScript);
1056 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001057 }
1058
Daniel Sandler388f6792010-03-02 14:08:08 -05001059 class Params extends BaseAlloc {
1060 Params() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001061 mType = Type.createFromClass(sRS, Params.class, 1, "ParamsClass");
1062 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001063 save();
1064 }
1065 public int bubbleWidth;
1066 public int bubbleHeight;
1067 public int bubbleBitmapWidth;
1068 public int bubbleBitmapHeight;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001069
Daniel Sandler388f6792010-03-02 14:08:08 -05001070 public int homeButtonWidth;
1071 public int homeButtonHeight;
1072 public int homeButtonTextureWidth;
1073 public int homeButtonTextureHeight;
1074 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001075
Daniel Sandler388f6792010-03-02 14:08:08 -05001076 class State extends BaseAlloc {
1077 public float newPositionX;
1078 public int newTouchDown;
1079 public float flingVelocity;
1080 public int iconCount;
1081 public int selectedIconIndex = -1;
1082 public int selectedIconTexture;
1083 public float zoomTarget;
1084 public int homeButtonId;
1085 public float targetPos;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001086
Daniel Sandler388f6792010-03-02 14:08:08 -05001087 State() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001088 mType = Type.createFromClass(sRS, State.class, 1, "StateClass");
1089 mAlloc = Allocation.createTyped(sRS, mType);
Daniel Sandler388f6792010-03-02 14:08:08 -05001090 save();
1091 }
1092 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001093
Romain Guy13c2e7b2010-03-10 19:45:00 -08001094 public RolloRS(AllApps3D allApps) {
1095 mAllApps = allApps;
Daniel Sandler388f6792010-03-02 14:08:08 -05001096 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001097
Daniel Sandler388f6792010-03-02 14:08:08 -05001098 public void init(Resources res, int width, int height) {
1099 mRes = res;
1100 mWidth = width;
1101 mHeight = height;
1102 initProgramVertex();
1103 initProgramFragment();
1104 initProgramStore();
1105 initGl();
1106 initData();
Daniel Sandler388f6792010-03-02 14:08:08 -05001107 initRs();
1108 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001109
Daniel Sandler388f6792010-03-02 14:08:08 -05001110 public void initMesh() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001111 SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(sRS, 2, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001112
Daniel Sandler388f6792010-03-02 14:08:08 -05001113 for (int ct=0; ct < 16; ct++) {
1114 float pos = (1.f / (16.f - 1)) * ct;
1115 tm.addVertex(0.0f, pos);
1116 tm.addVertex(1.0f, pos);
1117 }
1118 for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
1119 tm.addTriangle(ct, ct+1, ct+2);
1120 tm.addTriangle(ct+1, ct+3, ct+2);
1121 }
1122 mMesh = tm.create();
1123 mMesh.setName("SMCell");
1124 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001125
Daniel Sandler388f6792010-03-02 14:08:08 -05001126 void resize(int w, int h) {
1127 mPVA.setupProjectionNormalized(w, h);
1128 mWidth = w;
1129 mHeight = h;
1130 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001131
Daniel Sandler388f6792010-03-02 14:08:08 -05001132 private void initProgramVertex() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001133 mPVA = new ProgramVertex.MatrixAllocation(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001134 resize(mWidth, mHeight);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001135
Joe Onorato2cc62e82010-03-17 20:23:53 -07001136 ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001137 pvb.setTextureMatrixEnable(true);
1138 mPV = pvb.create();
1139 mPV.setName("PV");
1140 mPV.bindAllocation(mPVA);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001141
Joe Onorato2cc62e82010-03-17 20:23:53 -07001142 Element.Builder eb = new Element.Builder(sRS);
1143 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "ImgSize");
1144 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "Position");
1145 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 2), "BendPos");
1146 eb.add(Element.createVector(sRS, Element.DataType.FLOAT_32, 4), "ScaleOffset");
Daniel Sandler388f6792010-03-02 14:08:08 -05001147 Element e = eb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001148
Joe Onorato2cc62e82010-03-17 20:23:53 -07001149 mUniformAlloc = Allocation.createSized(sRS, e, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001150
Daniel Sandler388f6792010-03-02 14:08:08 -05001151 initMesh();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001152 ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
Romain Guy060b5c82010-03-04 10:07:38 -08001153 String t = "void main() {\n" +
1154 // Animation
1155 " float ani = UNI_Position.z;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001156
Romain Guy060b5c82010-03-04 10:07:38 -08001157 " float bendY1 = UNI_BendPos.x;\n" +
1158 " float bendY2 = UNI_BendPos.y;\n" +
1159 " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
1160 " float bendDistance = bendY1 * 0.4;\n" +
1161 " float distanceDimLevel = 0.6;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001162
Romain Guy060b5c82010-03-04 10:07:38 -08001163 " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
1164 " float aDy = cos(bendAngle);\n" +
1165 " float aDz = sin(bendAngle);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001166
Romain Guy060b5c82010-03-04 10:07:38 -08001167 " float scale = (2.0 / 480.0);\n" +
1168 " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
1169 " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
1170 " float y = 0.0;\n" +
1171 " float z = 0.0;\n" +
1172 " float lum = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001173
Romain Guy060b5c82010-03-04 10:07:38 -08001174 " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
1175 " y += cv * aDy;\n" +
1176 " z += -cv * aDz;\n" +
1177 " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
1178 " lum += cv / bendDistance * distanceDimLevel;\n" +
1179 " y += cv * cos(cv * bendStep);\n" +
1180 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001181
Romain Guy060b5c82010-03-04 10:07:38 -08001182 " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
1183 " y += cv * aDy;\n" +
1184 " z += cv * aDz;\n" +
1185 " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
1186 " lum -= cv / bendDistance * distanceDimLevel;\n" +
1187 " y += cv * cos(cv * bendStep);\n" +
1188 " z += cv * sin(cv * bendStep);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001189
Romain Guy060b5c82010-03-04 10:07:38 -08001190 " y += clamp(ys, bendY1, bendY2);\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001191
Romain Guy060b5c82010-03-04 10:07:38 -08001192 " vec4 pos;\n" +
1193 " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
1194 " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
1195 " pos.z = z * UNI_ScaleOffset.x;\n" +
1196 " pos.w = 1.0;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001197
Romain Guy060b5c82010-03-04 10:07:38 -08001198 " pos.x *= 1.0 + ani * 4.0;\n" +
1199 " pos.y *= 1.0 + ani * 4.0;\n" +
1200 " pos.z -= ani * 1.5;\n" +
1201 " lum *= 1.0 - ani;\n" +
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001202
Romain Guy060b5c82010-03-04 10:07:38 -08001203 " gl_Position = UNI_MVP * pos;\n" +
1204 " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
1205 " varTex0.xy = ATTRIB_position;\n" +
1206 " varTex0.y = 1.0 - varTex0.y;\n" +
1207 " varTex0.zw = vec2(0.0, 0.0);\n" +
1208 "}\n";
Daniel Sandler388f6792010-03-02 14:08:08 -05001209 sb.setShader(t);
1210 sb.addConstant(mUniformAlloc.getType());
1211 sb.addInput(mMesh.getVertexType(0).getElement());
1212 mPVCurve = sb.create();
1213 mPVCurve.setName("PVCurve");
1214 mPVCurve.bindAllocation(mPVA);
1215 mPVCurve.bindConstants(mUniformAlloc, 1);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001216
Joe Onorato2cc62e82010-03-17 20:23:53 -07001217 sRS.contextBindProgramVertex(mPV);
Daniel Sandler388f6792010-03-02 14:08:08 -05001218 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001219
Daniel Sandler388f6792010-03-02 14:08:08 -05001220 private void initProgramFragment() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001221 Sampler.Builder sb = new Sampler.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001222 sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
1223 sb.setMag(Sampler.Value.NEAREST);
1224 sb.setWrapS(Sampler.Value.CLAMP);
1225 sb.setWrapT(Sampler.Value.CLAMP);
1226 Sampler linear = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001227
Daniel Sandler388f6792010-03-02 14:08:08 -05001228 sb.setMin(Sampler.Value.NEAREST);
1229 sb.setMag(Sampler.Value.NEAREST);
1230 Sampler nearest = sb.create();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001231
Joe Onorato2cc62e82010-03-17 20:23:53 -07001232 ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001233 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1234 ProgramFragment.Builder.Format.RGBA, 0);
1235 mPFTexMip = bf.create();
1236 mPFTexMip.setName("PFTexMip");
1237 mPFTexMip.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001238
Daniel Sandler388f6792010-03-02 14:08:08 -05001239 mPFTexNearest = bf.create();
1240 mPFTexNearest.setName("PFTexNearest");
1241 mPFTexNearest.bindSampler(nearest, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001242
Daniel Sandler388f6792010-03-02 14:08:08 -05001243 bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
1244 ProgramFragment.Builder.Format.ALPHA, 0);
1245 mPFTexMipAlpha = bf.create();
1246 mPFTexMipAlpha.setName("PFTexMipAlpha");
1247 mPFTexMipAlpha.bindSampler(linear, 0);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001248
Daniel Sandler388f6792010-03-02 14:08:08 -05001249 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001250
Daniel Sandler388f6792010-03-02 14:08:08 -05001251 private void initProgramStore() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001252 ProgramStore.Builder bs = new ProgramStore.Builder(sRS, null, null);
Daniel Sandler388f6792010-03-02 14:08:08 -05001253 bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
1254 bs.setColorMask(true,true,true,false);
1255 bs.setDitherEnable(true);
1256 bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
1257 ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
1258 mPSIcons = bs.create();
1259 mPSIcons.setName("PSIcons");
1260 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001261
Daniel Sandler388f6792010-03-02 14:08:08 -05001262 private void initGl() {
Daniel Sandler388f6792010-03-02 14:08:08 -05001263 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001264
Daniel Sandler388f6792010-03-02 14:08:08 -05001265 private void initData() {
1266 mParams = new Params();
1267 mState = new State();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001268
Romain Guy13c2e7b2010-03-10 19:45:00 -08001269 final Utilities.BubbleText bubble = new Utilities.BubbleText(mAllApps.getContext());
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001270
Daniel Sandler388f6792010-03-02 14:08:08 -05001271 mParams.bubbleWidth = bubble.getBubbleWidth();
1272 mParams.bubbleHeight = bubble.getMaxBubbleHeight();
1273 mParams.bubbleBitmapWidth = bubble.getBitmapWidth();
1274 mParams.bubbleBitmapHeight = bubble.getBitmapHeight();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001275
Joe Onorato2cc62e82010-03-17 20:23:53 -07001276 mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
1277 R.drawable.home_button_normal, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001278 mHomeButtonNormal.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001279 mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
1280 R.drawable.home_button_focused, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001281 mHomeButtonFocused.uploadToTexture(0);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001282 mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
1283 R.drawable.home_button_pressed, Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001284 mHomeButtonPressed.uploadToTexture(0);
1285 mParams.homeButtonWidth = 76;
1286 mParams.homeButtonHeight = 68;
1287 mParams.homeButtonTextureWidth = 128;
1288 mParams.homeButtonTextureHeight = 128;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001289
Daniel Sandler388f6792010-03-02 14:08:08 -05001290 mState.homeButtonId = mHomeButtonNormal.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001291
Daniel Sandler388f6792010-03-02 14:08:08 -05001292 mParams.save();
1293 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001294
Daniel Sandler388f6792010-03-02 14:08:08 -05001295 mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
1296 Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
1297 mSelectionCanvas = new Canvas(mSelectionBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001298
Daniel Sandler388f6792010-03-02 14:08:08 -05001299 setApps(null);
1300 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001301
Daniel Sandler388f6792010-03-02 14:08:08 -05001302 private void initRs() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001303 ScriptC.Builder sb = new ScriptC.Builder(sRS);
Daniel Sandler388f6792010-03-02 14:08:08 -05001304 sb.setScript(mRes, R.raw.allapps);
1305 sb.setRoot(true);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001306 sb.addDefines(mAllApps.mDefines);
Daniel Sandler388f6792010-03-02 14:08:08 -05001307 sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS);
1308 sb.setType(mState.mType, "state", Defines.ALLOC_STATE);
1309 sb.setType(mUniformAlloc.getType(), "vpConstants", Defines.ALLOC_VP_CONSTANTS);
1310 mInvokeMove = sb.addInvokable("move");
1311 mInvokeFling = sb.addInvokable("fling");
1312 mInvokeMoveTo = sb.addInvokable("moveTo");
1313 mInvokeResetWAR = sb.addInvokable("resetHWWar");
1314 mInvokeSetZoom = sb.addInvokable("setZoom");
1315 mScript = sb.create();
1316 mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1317 mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
1318 mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
1319 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1320 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
1321 mScript.bindAllocation(mUniformAlloc, Defines.ALLOC_VP_CONSTANTS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001322
Joe Onorato2cc62e82010-03-17 20:23:53 -07001323 sRS.contextBindRootScript(mScript);
Daniel Sandler388f6792010-03-02 14:08:08 -05001324 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001325
Daniel Sandler388f6792010-03-02 14:08:08 -05001326 void dirtyCheck() {
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001327 if (sZoomDirty) {
1328 setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001329 }
1330 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001331
Romain Guy060b5c82010-03-04 10:07:38 -08001332 @SuppressWarnings({"ConstantConditions"})
Daniel Sandler388f6792010-03-02 14:08:08 -05001333 private void setApps(ArrayList<ApplicationInfo> list) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001334 sRollo.pause();
Daniel Sandler388f6792010-03-02 14:08:08 -05001335 final int count = list != null ? list.size() : 0;
1336 int allocCount = count;
1337 if (allocCount < 1) {
1338 allocCount = 1;
1339 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001340
Daniel Sandler388f6792010-03-02 14:08:08 -05001341 mIcons = new Allocation[count];
1342 mIconIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001343 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001344
Daniel Sandler388f6792010-03-02 14:08:08 -05001345 mLabels = new Allocation[count];
1346 mLabelIds = new int[allocCount];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001347 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), allocCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001348
Daniel Sandler388f6792010-03-02 14:08:08 -05001349 mState.iconCount = count;
1350 for (int i=0; i < mState.iconCount; i++) {
1351 createAppIconAllocations(i, list.get(i));
1352 }
1353 for (int i=0; i < mState.iconCount; i++) {
1354 uploadAppIcon(i, list.get(i));
1355 }
1356 saveAppsList();
Joe Onorato2cc62e82010-03-17 20:23:53 -07001357 sRollo.resume();
Daniel Sandler388f6792010-03-02 14:08:08 -05001358 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001359
Daniel Sandler388f6792010-03-02 14:08:08 -05001360 private void setZoom(float zoom, boolean animate) {
Romain Guyc16fea72010-03-12 17:17:56 -08001361 if (animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001362 sRollo.clearSelectedIcon();
1363 sRollo.setHomeSelected(SELECTED_NONE);
Romain Guyc16fea72010-03-12 17:17:56 -08001364 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001365 if (zoom > 0.001f) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001366 sRollo.mState.zoomTarget = zoom;
Daniel Sandler388f6792010-03-02 14:08:08 -05001367 } else {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001368 sRollo.mState.zoomTarget = 0;
Daniel Sandler388f6792010-03-02 14:08:08 -05001369 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001370 sRollo.mState.save();
Daniel Sandler388f6792010-03-02 14:08:08 -05001371 if (!animate) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001372 sRollo.mInvokeSetZoom.execute();
Daniel Sandler388f6792010-03-02 14:08:08 -05001373 }
1374 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001375
Daniel Sandler388f6792010-03-02 14:08:08 -05001376 private void createAppIconAllocations(int index, ApplicationInfo item) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001377 mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
1378 Element.RGBA_8888(sRS), false);
1379 mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
1380 Element.A_8(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001381 mIconIds[index] = mIcons[index].getID();
1382 mLabelIds[index] = mLabels[index].getID();
1383 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001384
Daniel Sandler388f6792010-03-02 14:08:08 -05001385 private void uploadAppIcon(int index, ApplicationInfo item) {
1386 if (mIconIds[index] != mIcons[index].getID()) {
1387 throw new IllegalStateException("uploadAppIcon index=" + index
1388 + " mIcons[index].getID=" + mIcons[index].getID()
1389 + " mIconsIds[index]=" + mIconIds[index]
1390 + " item=" + item);
1391 }
Jason Samsd1e2e1d2010-03-05 13:24:31 -08001392 mIcons[index].uploadToTexture(true, 0);
1393 mLabels[index].uploadToTexture(true, 0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001394 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001395
Daniel Sandler388f6792010-03-02 14:08:08 -05001396 /**
1397 * Puts the empty spaces at the end. Updates mState.iconCount. You must
1398 * fill in the values and call saveAppsList().
1399 */
1400 private void reallocAppsList(int count) {
1401 Allocation[] icons = new Allocation[count];
1402 int[] iconIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001403 mAllocIconIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001404
Daniel Sandler388f6792010-03-02 14:08:08 -05001405 Allocation[] labels = new Allocation[count];
1406 int[] labelIds = new int[count];
Joe Onorato2cc62e82010-03-17 20:23:53 -07001407 mAllocLabelIds = Allocation.createSized(sRS, Element.USER_I32(sRS), count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001408
Joe Onorato2cc62e82010-03-17 20:23:53 -07001409 final int oldCount = sRollo.mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001410
Daniel Sandler388f6792010-03-02 14:08:08 -05001411 System.arraycopy(mIcons, 0, icons, 0, oldCount);
1412 System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
1413 System.arraycopy(mLabels, 0, labels, 0, oldCount);
1414 System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001415
Daniel Sandler388f6792010-03-02 14:08:08 -05001416 mIcons = icons;
1417 mIconIds = iconIds;
1418 mLabels = labels;
1419 mLabelIds = labelIds;
1420 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001421
Daniel Sandler388f6792010-03-02 14:08:08 -05001422 /**
1423 * Handle the allocations for the new app. Make sure you call saveAppsList when done.
1424 */
1425 private void addApp(int index, ApplicationInfo item) {
1426 final int count = mState.iconCount - index;
1427 final int dest = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001428
Daniel Sandler388f6792010-03-02 14:08:08 -05001429 System.arraycopy(mIcons, index, mIcons, dest, count);
1430 System.arraycopy(mIconIds, index, mIconIds, dest, count);
1431 System.arraycopy(mLabels, index, mLabels, dest, count);
1432 System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001433
Daniel Sandler388f6792010-03-02 14:08:08 -05001434 createAppIconAllocations(index, item);
1435 uploadAppIcon(index, item);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001436 sRollo.mState.iconCount++;
Daniel Sandler388f6792010-03-02 14:08:08 -05001437 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001438
Daniel Sandler388f6792010-03-02 14:08:08 -05001439 /**
1440 * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
1441 */
1442 private void removeApp(int index) {
1443 final int count = mState.iconCount - index - 1;
1444 final int src = index + 1;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001445
Daniel Sandler388f6792010-03-02 14:08:08 -05001446 System.arraycopy(mIcons, src, mIcons, index, count);
1447 System.arraycopy(mIconIds, src, mIconIds, index, count);
1448 System.arraycopy(mLabels, src, mLabels, index, count);
1449 System.arraycopy(mLabelIds, src, mLabelIds, index, count);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001450
Joe Onorato2cc62e82010-03-17 20:23:53 -07001451 sRollo.mState.iconCount--;
Daniel Sandler388f6792010-03-02 14:08:08 -05001452 final int last = mState.iconCount;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001453
Daniel Sandler388f6792010-03-02 14:08:08 -05001454 mIcons[last] = null;
1455 mIconIds[last] = 0;
1456 mLabels[last] = null;
1457 mLabelIds[last] = 0;
1458 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001459
Daniel Sandler388f6792010-03-02 14:08:08 -05001460 /**
1461 * Send the apps list structures to RS.
1462 */
1463 private void saveAppsList() {
1464 // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
1465 if (mScript != null && mAllocIconIds != null) {
Daniel Sandler388f6792010-03-02 14:08:08 -05001466 mAllocIconIds.data(mIconIds);
1467 mAllocLabelIds.data(mLabelIds);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001468
Daniel Sandler388f6792010-03-02 14:08:08 -05001469 mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
1470 mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001471
Daniel Sandler388f6792010-03-02 14:08:08 -05001472 mState.save();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001473
Daniel Sandler388f6792010-03-02 14:08:08 -05001474 // Note: mScript may be null if we haven't initialized it yet.
1475 // In that case, this is a no-op.
1476 if (mInvokeResetWAR != null) {
1477 mInvokeResetWAR.execute();
1478 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001479 }
1480 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001481
Daniel Sandler388f6792010-03-02 14:08:08 -05001482 void fling() {
1483 mInvokeFling.execute();
1484 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001485
Daniel Sandler388f6792010-03-02 14:08:08 -05001486 void move() {
1487 mInvokeMove.execute();
1488 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001489
Daniel Sandler388f6792010-03-02 14:08:08 -05001490 void moveTo(float row) {
1491 mState.targetPos = row;
1492 mState.save();
1493 mInvokeMoveTo.execute();
1494 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001495
Daniel Sandler388f6792010-03-02 14:08:08 -05001496 /**
1497 * You need to call save() on mState on your own after calling this.
1498 *
1499 * @return the index of the icon that was selected.
1500 */
Romain Guy6a42cf32010-03-12 16:03:52 -08001501 int selectIcon(int x, int y, int pressed) {
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001502 if (mAllApps != null) {
1503 final int index = mAllApps.chooseTappedIcon(x, y);
1504 selectIcon(index, pressed);
1505 return index;
1506 } else {
1507 return -1;
1508 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001509 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001510
Daniel Sandler388f6792010-03-02 14:08:08 -05001511 /**
1512 * Select the icon at the given index.
1513 *
1514 * @param index The index.
1515 * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
1516 */
1517 void selectIcon(int index, int pressed) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001518 final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
1519 if (appsList == null || index < 0 || index >= appsList.size()) {
Romain Guyc16fea72010-03-12 17:17:56 -08001520 if (mAllApps != null) {
1521 mAllApps.mRestoreFocusIndex = index;
1522 }
Daniel Sandler388f6792010-03-02 14:08:08 -05001523 mState.selectedIconIndex = -1;
Romain Guy13c2e7b2010-03-10 19:45:00 -08001524 if (mAllApps.mLastSelection == SELECTION_ICONS) {
1525 mAllApps.mLastSelection = SELECTION_NONE;
Daniel Sandler388f6792010-03-02 14:08:08 -05001526 }
1527 } else {
1528 if (pressed == SELECTED_FOCUSED) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001529 mAllApps.mLastSelection = SELECTION_ICONS;
Daniel Sandler388f6792010-03-02 14:08:08 -05001530 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001531
Daniel Sandler388f6792010-03-02 14:08:08 -05001532 int prev = mState.selectedIconIndex;
1533 mState.selectedIconIndex = index;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001534
Romain Guy13c2e7b2010-03-10 19:45:00 -08001535 ApplicationInfo info = appsList.get(index);
Daniel Sandler388f6792010-03-02 14:08:08 -05001536 Bitmap selectionBitmap = mSelectionBitmap;
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001537
Daniel Sandler388f6792010-03-02 14:08:08 -05001538 Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
1539 selectionBitmap.getWidth(), selectionBitmap.getHeight(),
1540 pressed == SELECTED_PRESSED, info.iconBitmap);
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001541
Joe Onorato2cc62e82010-03-17 20:23:53 -07001542 mSelectedIcon = Allocation.createFromBitmap(sRS, selectionBitmap,
1543 Element.RGBA_8888(sRS), false);
Daniel Sandler388f6792010-03-02 14:08:08 -05001544 mSelectedIcon.uploadToTexture(0);
1545 mState.selectedIconTexture = mSelectedIcon.getID();
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001546
Daniel Sandler388f6792010-03-02 14:08:08 -05001547 if (prev != index) {
1548 if (info.title != null && info.title.length() > 0) {
1549 //setContentDescription(info.title);
Romain Guy13c2e7b2010-03-10 19:45:00 -08001550 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001551 }
1552 }
1553 }
1554 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001555
Daniel Sandler388f6792010-03-02 14:08:08 -05001556 /**
1557 * You need to call save() on mState on your own after calling this.
1558 */
1559 void clearSelectedIcon() {
1560 mState.selectedIconIndex = -1;
1561 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001562
Daniel Sandler388f6792010-03-02 14:08:08 -05001563 void setHomeSelected(int mode) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001564 final int prev = mAllApps.mLastSelection;
Daniel Sandler388f6792010-03-02 14:08:08 -05001565 switch (mode) {
1566 case SELECTED_NONE:
1567 mState.homeButtonId = mHomeButtonNormal.getID();
1568 break;
1569 case SELECTED_FOCUSED:
Romain Guy13c2e7b2010-03-10 19:45:00 -08001570 mAllApps.mLastSelection = SELECTION_HOME;
Daniel Sandler388f6792010-03-02 14:08:08 -05001571 mState.homeButtonId = mHomeButtonFocused.getID();
1572 if (prev != SELECTION_HOME) {
Romain Guy13c2e7b2010-03-10 19:45:00 -08001573 mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Daniel Sandler388f6792010-03-02 14:08:08 -05001574 }
1575 break;
1576 case SELECTED_PRESSED:
1577 mState.homeButtonId = mHomeButtonPressed.getID();
1578 break;
1579 }
1580 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001581
Daniel Sandler388f6792010-03-02 14:08:08 -05001582 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001583 Log.d(TAG, "sRollo.mWidth=" + mWidth);
1584 Log.d(TAG, "sRollo.mHeight=" + mHeight);
1585 Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
Daniel Sandler388f6792010-03-02 14:08:08 -05001586 if (mIcons != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001587 Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001588 }
1589 if (mIconIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001590 Log.d(TAG, "sRollo.mIconIds.length=" + mIconIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001591 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001592 Log.d(TAG, "sRollo.mIconIds=" + Arrays.toString(mIconIds));
Daniel Sandler388f6792010-03-02 14:08:08 -05001593 if (mLabelIds != null) {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001594 Log.d(TAG, "sRollo.mLabelIds.length=" + mLabelIds.length);
Daniel Sandler388f6792010-03-02 14:08:08 -05001595 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001596 Log.d(TAG, "sRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Joe Onorato2cc62e82010-03-17 20:23:53 -07001597 Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
1598 Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
1599 Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
1600 Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
1601 Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
1602 Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
1603 Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
1604 Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
1605 Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
1606 Log.d(TAG, "sRollo.mParams.bubbleWidth=" + mParams.bubbleWidth);
1607 Log.d(TAG, "sRollo.mParams.bubbleHeight=" + mParams.bubbleHeight);
1608 Log.d(TAG, "sRollo.mParams.bubbleBitmapWidth=" + mParams.bubbleBitmapWidth);
1609 Log.d(TAG, "sRollo.mParams.bubbleBitmapHeight=" + mParams.bubbleBitmapHeight);
1610 Log.d(TAG, "sRollo.mParams.homeButtonWidth=" + mParams.homeButtonWidth);
1611 Log.d(TAG, "sRollo.mParams.homeButtonHeight=" + mParams.homeButtonHeight);
1612 Log.d(TAG, "sRollo.mParams.homeButtonTextureWidth=" + mParams.homeButtonTextureWidth);
1613 Log.d(TAG, "sRollo.mParams.homeButtonTextureHeight=" + mParams.homeButtonTextureHeight);
Daniel Sandler388f6792010-03-02 14:08:08 -05001614 }
1615 }
Jason Samsdd8cd8b2010-03-11 12:38:48 -08001616
Daniel Sandler388f6792010-03-02 14:08:08 -05001617 public void dumpState() {
Joe Onorato2cc62e82010-03-17 20:23:53 -07001618 Log.d(TAG, "sRS=" + sRS);
1619 Log.d(TAG, "sRollo=" + sRollo);
Daniel Sandler388f6792010-03-02 14:08:08 -05001620 ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
Joe Onoratocfc4c7b2010-03-18 15:15:10 -07001621 Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
1622 Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Daniel Sandler388f6792010-03-02 14:08:08 -05001623 Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
1624 Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
1625 Log.d(TAG, "mLastSelection=" + mLastSelection);
1626 Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
1627 Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
1628 Log.d(TAG, "mTouchTracking=" + mTouchTracking);
1629 Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
Joe Onoratoeffc4a82010-04-15 11:48:13 -07001630 Log.d(TAG, "sZoomDirty=" + sZoomDirty);
1631 Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
Daniel Sandler388f6792010-03-02 14:08:08 -05001632 Log.d(TAG, "mZoom=" + mZoom);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001633 Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
Daniel Sandler388f6792010-03-02 14:08:08 -05001634 Log.d(TAG, "mVelocity=" + mVelocity);
1635 Log.d(TAG, "mMessageProc=" + mMessageProc);
Joe Onorato2cc62e82010-03-17 20:23:53 -07001636 if (sRollo != null) {
1637 sRollo.dumpState();
Daniel Sandler388f6792010-03-02 14:08:08 -05001638 }
Joe Onorato2cc62e82010-03-17 20:23:53 -07001639 if (sRS != null) {
1640 sRS.contextDump(0);
Daniel Sandler388f6792010-03-02 14:08:08 -05001641 }
1642 }
1643}
1644
1645