Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.launcher2; |
| 18 | |
Joe Onorato | cb9f798 | 2009-10-31 16:32:02 -0400 | [diff] [blame] | 19 | import android.content.ComponentName; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.res.Resources; |
| 22 | import android.graphics.Bitmap; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 23 | import android.graphics.Canvas; |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 24 | import android.graphics.PixelFormat; |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 25 | import android.graphics.Rect; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 26 | import android.os.SystemClock; |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 27 | import android.renderscript.Allocation; |
| 28 | import android.renderscript.Dimension; |
| 29 | import android.renderscript.Element; |
| 30 | import android.renderscript.ProgramFragment; |
| 31 | import android.renderscript.ProgramStore; |
| 32 | import android.renderscript.ProgramVertex; |
| 33 | import android.renderscript.RSSurfaceView; |
| 34 | import android.renderscript.RenderScript; |
| 35 | import android.renderscript.Sampler; |
| 36 | import android.renderscript.Script; |
| 37 | import android.renderscript.ScriptC; |
| 38 | import android.renderscript.SimpleMesh; |
| 39 | import android.renderscript.Type; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 40 | import android.util.AttributeSet; |
| 41 | import android.util.Log; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 42 | import android.view.KeyEvent; |
| 43 | import android.view.MotionEvent; |
Joe Onorato | b39e51a | 2009-10-28 15:47:49 -0400 | [diff] [blame] | 44 | import android.view.SoundEffectConstants; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 45 | import android.view.SurfaceHolder; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 46 | import android.view.VelocityTracker; |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 47 | import android.view.View; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 48 | import android.view.ViewConfiguration; |
Joe Onorato | 52a653f | 2009-11-11 14:52:11 -0800 | [diff] [blame] | 49 | import android.view.accessibility.AccessibilityEvent; |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 50 | |
| 51 | import java.util.ArrayList; |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 52 | import java.util.Arrays; |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 53 | import java.util.Collections; |
| 54 | import java.util.Comparator; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 55 | |
| 56 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 57 | public class AllAppsView extends RSSurfaceView |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 58 | implements View.OnClickListener, View.OnLongClickListener, DragSource { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 59 | private static final String TAG = "Launcher.AllAppsView"; |
| 60 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 61 | /** Bit for mLocks for when there are icons being loaded. */ |
| 62 | private static final int LOCK_ICONS_PENDING = 1; |
| 63 | |
Joe Onorato | 68ffd10 | 2009-10-15 17:59:43 -0700 | [diff] [blame] | 64 | private static final int TRACKING_NONE = 0; |
| 65 | private static final int TRACKING_FLING = 1; |
| 66 | private static final int TRACKING_HOME = 2; |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 67 | |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 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 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 76 | private Launcher mLauncher; |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 77 | private DragController mDragController; |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 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; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 82 | |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 83 | private int mSlop; |
Joe Onorato | f7b0e01 | 2009-10-01 14:09:15 -0700 | [diff] [blame] | 84 | private int mMaxFlingVelocity; |
| 85 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 86 | private Defines mDefines = new Defines(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 87 | private RenderScript mRS; |
| 88 | private RolloRS mRollo; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 89 | private ArrayList<ApplicationInfo> mAllAppsList; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 90 | |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 91 | /** |
| 92 | * True when we are using arrow keys or trackball to drive navigation |
| 93 | */ |
| 94 | private boolean mArrowNavigation = false; |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 95 | private boolean mStartedScrolling; |
| 96 | |
| 97 | /** |
| 98 | * Used to keep track of the selection when AllAppsView loses window focus. |
| 99 | * One of the SELECTION_ constants. |
| 100 | */ |
| 101 | private int mLastSelection; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 102 | |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 103 | /** |
| 104 | * Used to keep track of the selection when AllAppsView loses window focus |
| 105 | */ |
| 106 | private int mLastSelectedIcon; |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 107 | |
Joe Onorato | 68ba5ca | 2009-11-12 14:23:43 -0800 | [diff] [blame] | 108 | private VelocityTracker mVelocityTracker; |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 109 | private int mTouchTracking; |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 110 | private int mMotionDownRawX; |
| 111 | private int mMotionDownRawY; |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 112 | private int mDownIconIndex = -1; |
| 113 | private int mCurrentIconIndex = -1; |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 114 | |
Mike Cleron | b64b67a | 2009-11-08 14:56:25 -0800 | [diff] [blame] | 115 | private boolean mShouldGainFocus; |
| 116 | |
Joe Onorato | 6374c51 | 2010-01-06 20:42:25 -0800 | [diff] [blame^] | 117 | private boolean mHaveSurface = false; |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 118 | private boolean mZoomDirty = false; |
Joe Onorato | 68ba5ca | 2009-11-12 14:23:43 -0800 | [diff] [blame] | 119 | private boolean mAnimateNextZoom; |
Joe Onorato | 6374c51 | 2010-01-06 20:42:25 -0800 | [diff] [blame^] | 120 | private float mNextZoom; |
Joe Onorato | 68ba5ca | 2009-11-12 14:23:43 -0800 | [diff] [blame] | 121 | private float mZoom; |
| 122 | private float mPosX; |
| 123 | private float mVelocity; |
| 124 | private AAMessage mMessageProc; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 125 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 126 | static class Defines { |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 127 | public static final int ALLOC_PARAMS = 0; |
| 128 | public static final int ALLOC_STATE = 1; |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 129 | public static final int ALLOC_ICON_IDS = 3; |
| 130 | public static final int ALLOC_LABEL_IDS = 4; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 131 | |
| 132 | public static final int COLUMNS_PER_PAGE = 4; |
| 133 | public static final int ROWS_PER_PAGE = 4; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 134 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 135 | public static final int ICON_WIDTH_PX = 64; |
| 136 | public static final int ICON_TEXTURE_WIDTH_PX = 128; |
| 137 | |
| 138 | public static final int ICON_HEIGHT_PX = 64; |
| 139 | public static final int ICON_TEXTURE_HEIGHT_PX = 128; |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 140 | |
| 141 | public int SCREEN_WIDTH_PX; |
| 142 | public int SCREEN_HEIGHT_PX; |
| 143 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 144 | public void recompute(int w, int h) { |
| 145 | SCREEN_WIDTH_PX = 480; |
| 146 | SCREEN_HEIGHT_PX = 800; |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 147 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 148 | } |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 149 | |
| 150 | public AllAppsView(Context context, AttributeSet attrs) { |
| 151 | super(context, attrs); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 152 | setFocusable(true); |
Joe Onorato | b39e51a | 2009-10-28 15:47:49 -0400 | [diff] [blame] | 153 | setSoundEffectsEnabled(false); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 154 | getHolder().setFormat(PixelFormat.TRANSLUCENT); |
Joe Onorato | f7b0e01 | 2009-10-01 14:09:15 -0700 | [diff] [blame] | 155 | final ViewConfiguration config = ViewConfiguration.get(context); |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 156 | mSlop = config.getScaledTouchSlop(); |
Joe Onorato | f7b0e01 | 2009-10-01 14:09:15 -0700 | [diff] [blame] | 157 | mMaxFlingVelocity = config.getScaledMaximumFlingVelocity(); |
| 158 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 159 | setOnClickListener(this); |
| 160 | setOnLongClickListener(this); |
Dianne Hackborn | e52a1b5 | 2009-09-30 22:36:20 -0700 | [diff] [blame] | 161 | setZOrderOnTop(true); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 162 | getHolder().setFormat(PixelFormat.TRANSLUCENT); |
Jason Sams | e26d9fc | 2009-11-12 14:00:43 -0800 | [diff] [blame] | 163 | |
| 164 | mRS = createRenderScript(true); |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | protected void onDetachedFromWindow() { |
| 169 | destroyRenderScript(); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Joe Onorato | b39e51a | 2009-10-28 15:47:49 -0400 | [diff] [blame] | 172 | /** |
| 173 | * If you have an attached click listener, View always plays the click sound!?!? |
| 174 | * Deal with sound effects by hand. |
| 175 | */ |
| 176 | public void reallyPlaySoundEffect(int sound) { |
| 177 | boolean old = isSoundEffectsEnabled(); |
| 178 | setSoundEffectsEnabled(true); |
| 179 | playSoundEffect(sound); |
| 180 | setSoundEffectsEnabled(old); |
| 181 | } |
| 182 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 183 | public AllAppsView(Context context, AttributeSet attrs, int defStyle) { |
| 184 | this(context, attrs); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 187 | public void setLauncher(Launcher launcher) { |
| 188 | mLauncher = launcher; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 191 | @Override |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 192 | public void surfaceDestroyed(SurfaceHolder holder) { |
| 193 | super.surfaceDestroyed(holder); |
Joe Onorato | fab7440 | 2009-11-11 16:05:23 -0800 | [diff] [blame] | 194 | // Without this, we leak mMessageCallback which leaks the context. |
| 195 | mRS.mMessageCallback = null; |
Joe Onorato | 6374c51 | 2010-01-06 20:42:25 -0800 | [diff] [blame^] | 196 | // We may lose any callbacks that are pending, so make sure that we re-sync that |
| 197 | // on the next surfaceChanged. |
| 198 | mZoomDirty = true; |
| 199 | mHaveSurface = false; |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | @Override |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 203 | public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 204 | //long startTime = SystemClock.uptimeMillis(); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 205 | |
Joe Onorato | 080d9b6 | 2009-11-02 12:01:11 -0500 | [diff] [blame] | 206 | super.surfaceChanged(holder, format, w, h); |
| 207 | |
Joe Onorato | 6374c51 | 2010-01-06 20:42:25 -0800 | [diff] [blame^] | 208 | mHaveSurface = true; |
| 209 | |
Jason Sams | e26d9fc | 2009-11-12 14:00:43 -0800 | [diff] [blame] | 210 | if (mRollo == null) { |
Jason Sams | 9039667 | 2009-11-03 13:59:34 -0800 | [diff] [blame] | 211 | mRollo = new RolloRS(); |
| 212 | mRollo.init(getResources(), w, h); |
| 213 | if (mAllAppsList != null) { |
| 214 | mRollo.setApps(mAllAppsList); |
Jason Sams | 9039667 | 2009-11-03 13:59:34 -0800 | [diff] [blame] | 215 | } |
Mike Cleron | b64b67a | 2009-11-08 14:56:25 -0800 | [diff] [blame] | 216 | if (mShouldGainFocus) { |
| 217 | gainFocus(); |
| 218 | mShouldGainFocus = false; |
| 219 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 220 | } |
Jason Sams | e26d9fc | 2009-11-12 14:00:43 -0800 | [diff] [blame] | 221 | mRollo.dirtyCheck(); |
Jason Sams | 5612e43 | 2009-11-16 14:18:07 -0800 | [diff] [blame] | 222 | mRollo.resize(w, h); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 223 | |
Joe Onorato | cb75f36 | 2009-11-12 13:04:07 -0800 | [diff] [blame] | 224 | mRS.mMessageCallback = mMessageProc = new AAMessage(); |
| 225 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 226 | Resources res = getContext().getResources(); |
| 227 | int barHeight = (int)res.getDimension(R.dimen.button_bar_height); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 228 | |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 229 | //long endTime = SystemClock.uptimeMillis(); |
| 230 | //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms"); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 231 | } |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 232 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 233 | @Override |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 234 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 235 | super.onWindowFocusChanged(hasWindowFocus); |
| 236 | if (mArrowNavigation) { |
| 237 | if (!hasWindowFocus) { |
| 238 | // Clear selection when we lose window focus |
| 239 | mLastSelectedIcon = mRollo.mState.selectedIconIndex; |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 240 | mRollo.setHomeSelected(SELECTED_NONE); |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 241 | mRollo.clearSelectedIcon(); |
| 242 | mRollo.mState.save(); |
| 243 | } else if (hasWindowFocus) { |
| 244 | if (mRollo.mState.iconCount > 0) { |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 245 | if (mLastSelection == SELECTION_ICONS) { |
| 246 | int selection = mLastSelectedIcon; |
Joe Onorato | 68ba5ca | 2009-11-12 14:23:43 -0800 | [diff] [blame] | 247 | final int firstIcon = Math.round(mPosX) * |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 248 | Defines.COLUMNS_PER_PAGE; |
| 249 | if (selection < 0 || // No selection |
| 250 | selection < firstIcon || // off the top of the screen |
| 251 | selection >= mRollo.mState.iconCount || // past last icon |
| 252 | selection >= firstIcon + // past last icon on screen |
| 253 | (Defines.COLUMNS_PER_PAGE * Defines.ROWS_PER_PAGE)) { |
| 254 | selection = firstIcon; |
| 255 | } |
| 256 | |
| 257 | // Select the first icon when we gain window focus |
| 258 | mRollo.selectIcon(selection, SELECTED_FOCUSED); |
| 259 | mRollo.mState.save(); |
| 260 | } else if (mLastSelection == SELECTION_HOME) { |
| 261 | mRollo.setHomeSelected(SELECTED_FOCUSED); |
| 262 | mRollo.mState.save(); |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 263 | } |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | @Override |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 270 | protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { |
| 271 | super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); |
Joe Onorato | 859b3a7 | 2009-10-28 15:17:01 -0400 | [diff] [blame] | 272 | |
| 273 | if (!isVisible()) { |
| 274 | return; |
| 275 | } |
| 276 | |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 277 | if (gainFocus) { |
Jason Sams | 510ee04 | 2009-12-15 14:23:37 -0800 | [diff] [blame] | 278 | if (mRollo != null) { |
Mike Cleron | b64b67a | 2009-11-08 14:56:25 -0800 | [diff] [blame] | 279 | gainFocus(); |
| 280 | } else { |
| 281 | mShouldGainFocus = true; |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 282 | } |
| 283 | } else { |
Joe Onorato | 8eea391 | 2009-12-09 13:01:06 -0800 | [diff] [blame] | 284 | if (mRollo != null) { |
Mike Cleron | b64b67a | 2009-11-08 14:56:25 -0800 | [diff] [blame] | 285 | if (mArrowNavigation) { |
| 286 | // Clear selection when we lose focus |
| 287 | mRollo.clearSelectedIcon(); |
| 288 | mRollo.setHomeSelected(SELECTED_NONE); |
| 289 | mRollo.mState.save(); |
| 290 | mArrowNavigation = false; |
| 291 | } |
| 292 | } else { |
| 293 | mShouldGainFocus = false; |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
Mike Cleron | b64b67a | 2009-11-08 14:56:25 -0800 | [diff] [blame] | 298 | private void gainFocus() { |
| 299 | if (!mArrowNavigation && mRollo.mState.iconCount > 0) { |
| 300 | // Select the first icon when we gain keyboard focus |
| 301 | mArrowNavigation = true; |
Joe Onorato | 68ba5ca | 2009-11-12 14:23:43 -0800 | [diff] [blame] | 302 | mRollo.selectIcon(Math.round(mPosX) * Defines.COLUMNS_PER_PAGE, |
Mike Cleron | b64b67a | 2009-11-08 14:56:25 -0800 | [diff] [blame] | 303 | SELECTED_FOCUSED); |
| 304 | mRollo.mState.save(); |
| 305 | } |
| 306 | } |
| 307 | |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 308 | @Override |
| 309 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 310 | |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 311 | boolean handled = false; |
Jason Sams | e26d9fc | 2009-11-12 14:00:43 -0800 | [diff] [blame] | 312 | |
Joe Onorato | 859b3a7 | 2009-10-28 15:17:01 -0400 | [diff] [blame] | 313 | if (!isVisible()) { |
| 314 | return false; |
| 315 | } |
Joe Onorato | a13f574 | 2009-11-02 17:15:19 -0500 | [diff] [blame] | 316 | final int iconCount = mRollo.mState.iconCount; |
| 317 | |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 318 | if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) { |
| 319 | if (mArrowNavigation) { |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 320 | if (mLastSelection == SELECTION_HOME) { |
| 321 | reallyPlaySoundEffect(SoundEffectConstants.CLICK); |
| 322 | mLauncher.closeAllApps(true); |
| 323 | } else { |
| 324 | int whichApp = mRollo.mState.selectedIconIndex; |
| 325 | if (whichApp >= 0) { |
| 326 | ApplicationInfo app = mAllAppsList.get(whichApp); |
| 327 | mLauncher.startActivitySafely(app.intent); |
| 328 | handled = true; |
| 329 | } |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | } |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 333 | |
Joe Onorato | 478730f | 2009-11-16 18:54:43 -0800 | [diff] [blame] | 334 | if (iconCount > 0) { |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 335 | mArrowNavigation = true; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 336 | |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 337 | int currentSelection = mRollo.mState.selectedIconIndex; |
Joe Onorato | 68ba5ca | 2009-11-12 14:23:43 -0800 | [diff] [blame] | 338 | int currentTopRow = Math.round(mPosX); |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 339 | |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 340 | // The column of the current selection, in the range 0..COLUMNS_PER_PAGE-1 |
Joe Onorato | a13f574 | 2009-11-02 17:15:19 -0500 | [diff] [blame] | 341 | final int currentPageCol = currentSelection % Defines.COLUMNS_PER_PAGE; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 342 | |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 343 | // The row of the current selection, in the range 0..ROWS_PER_PAGE-1 |
Joe Onorato | a13f574 | 2009-11-02 17:15:19 -0500 | [diff] [blame] | 344 | final int currentPageRow = (currentSelection - (currentTopRow*Defines.COLUMNS_PER_PAGE)) |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 345 | / Defines.ROWS_PER_PAGE; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 346 | |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 347 | int newSelection = currentSelection; |
| 348 | |
| 349 | switch (keyCode) { |
| 350 | case KeyEvent.KEYCODE_DPAD_UP: |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 351 | if (mLastSelection == SELECTION_HOME) { |
| 352 | mRollo.setHomeSelected(SELECTED_NONE); |
| 353 | int lastRowCount = iconCount % Defines.COLUMNS_PER_PAGE; |
| 354 | if (lastRowCount == 0) { |
| 355 | lastRowCount = Defines.COLUMNS_PER_PAGE; |
| 356 | } |
| 357 | newSelection = iconCount - lastRowCount + (Defines.COLUMNS_PER_PAGE / 2); |
| 358 | if (newSelection >= iconCount) { |
| 359 | newSelection = iconCount-1; |
| 360 | } |
| 361 | int target = (newSelection / Defines.COLUMNS_PER_PAGE) |
| 362 | - (Defines.ROWS_PER_PAGE - 1); |
| 363 | if (target < 0) { |
| 364 | target = 0; |
| 365 | } |
| 366 | if (currentTopRow != target) { |
| 367 | mRollo.moveTo(target); |
| 368 | } |
| 369 | } else { |
| 370 | if (currentPageRow > 0) { |
| 371 | newSelection = currentSelection - Defines.COLUMNS_PER_PAGE; |
| 372 | } else if (currentTopRow > 0) { |
| 373 | newSelection = currentSelection - Defines.COLUMNS_PER_PAGE; |
| 374 | mRollo.moveTo(newSelection / Defines.COLUMNS_PER_PAGE); |
Joe Onorato | af5b4cb | 2009-12-08 17:51:22 -0800 | [diff] [blame] | 375 | } else if (currentPageRow != 0) { |
| 376 | newSelection = currentTopRow * Defines.ROWS_PER_PAGE; |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 377 | } |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 378 | } |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 379 | handled = true; |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 380 | break; |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 381 | |
Joe Onorato | a13f574 | 2009-11-02 17:15:19 -0500 | [diff] [blame] | 382 | case KeyEvent.KEYCODE_DPAD_DOWN: { |
| 383 | final int rowCount = iconCount / Defines.COLUMNS_PER_PAGE |
| 384 | + (iconCount % Defines.COLUMNS_PER_PAGE == 0 ? 0 : 1); |
| 385 | final int currentRow = currentSelection / Defines.COLUMNS_PER_PAGE; |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 386 | if (mLastSelection != SELECTION_HOME) { |
| 387 | if (currentRow < rowCount-1) { |
| 388 | mRollo.setHomeSelected(SELECTED_NONE); |
Joe Onorato | 478730f | 2009-11-16 18:54:43 -0800 | [diff] [blame] | 389 | if (currentSelection < 0) { |
| 390 | newSelection = 0; |
| 391 | } else { |
| 392 | newSelection = currentSelection + Defines.COLUMNS_PER_PAGE; |
| 393 | } |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 394 | if (newSelection >= iconCount) { |
| 395 | // Go from D to G in this arrangement: |
| 396 | // A B C D |
| 397 | // E F G |
| 398 | newSelection = iconCount - 1; |
| 399 | } |
| 400 | if (currentPageRow >= Defines.ROWS_PER_PAGE - 1) { |
| 401 | mRollo.moveTo((newSelection / Defines.COLUMNS_PER_PAGE) - |
| 402 | Defines.ROWS_PER_PAGE + 1); |
| 403 | } |
| 404 | } else { |
| 405 | newSelection = -1; |
| 406 | mRollo.setHomeSelected(SELECTED_FOCUSED); |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 407 | } |
| 408 | } |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 409 | handled = true; |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 410 | break; |
Joe Onorato | a13f574 | 2009-11-02 17:15:19 -0500 | [diff] [blame] | 411 | } |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 412 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 413 | if (currentPageCol > 0) { |
| 414 | newSelection = currentSelection - 1; |
| 415 | } |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 416 | handled = true; |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 417 | break; |
| 418 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 419 | if ((currentPageCol < Defines.COLUMNS_PER_PAGE - 1) && |
Joe Onorato | a13f574 | 2009-11-02 17:15:19 -0500 | [diff] [blame] | 420 | (currentSelection < iconCount - 1)) { |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 421 | newSelection = currentSelection + 1; |
| 422 | } |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 423 | handled = true; |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 424 | break; |
| 425 | } |
| 426 | if (newSelection != currentSelection) { |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 427 | mRollo.selectIcon(newSelection, SELECTED_FOCUSED); |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 428 | mRollo.mState.save(); |
| 429 | } |
| 430 | } |
Mike Cleron | 4a5c1e1 | 2009-11-03 10:17:05 -0800 | [diff] [blame] | 431 | return handled; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 434 | @Override |
| 435 | public boolean onTouchEvent(MotionEvent ev) |
| 436 | { |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 437 | mArrowNavigation = false; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 438 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 439 | if (!isVisible()) { |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 440 | return true; |
Joe Onorato | e3406a2 | 2009-09-03 14:36:25 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 443 | if (mLocks != 0) { |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 444 | return true; |
| 445 | } |
| 446 | |
| 447 | super.onTouchEvent(ev); |
| 448 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 449 | int x = (int)ev.getX(); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 450 | int y = (int)ev.getY(); |
| 451 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 452 | int action = ev.getAction(); |
| 453 | switch (action) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 454 | case MotionEvent.ACTION_DOWN: |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 455 | if (y > mRollo.mTouchYBorders[mRollo.mTouchYBorders.length-1]) { |
| 456 | mTouchTracking = TRACKING_HOME; |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 457 | mRollo.setHomeSelected(SELECTED_PRESSED); |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 458 | mRollo.mState.save(); |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 459 | mCurrentIconIndex = -1; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 460 | } else { |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 461 | mTouchTracking = TRACKING_FLING; |
| 462 | |
| 463 | mMotionDownRawX = (int)ev.getRawX(); |
| 464 | mMotionDownRawY = (int)ev.getRawY(); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 465 | |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 466 | mRollo.mState.newPositionX = ev.getRawY() / getHeight(); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 467 | mRollo.mState.newTouchDown = 1; |
| 468 | |
| 469 | if (!mRollo.checkClickOK()) { |
| 470 | mRollo.clearSelectedIcon(); |
| 471 | } else { |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 472 | mDownIconIndex = mCurrentIconIndex |
Joe Onorato | 68ba5ca | 2009-11-12 14:23:43 -0800 | [diff] [blame] | 473 | = mRollo.selectIcon(x, y, mPosX, SELECTED_PRESSED); |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 474 | if (mDownIconIndex < 0) { |
| 475 | // if nothing was selected, no long press. |
| 476 | cancelLongPress(); |
| 477 | } |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 478 | } |
| 479 | mRollo.mState.save(); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 480 | mRollo.move(); |
Joe Onorato | 68ba5ca | 2009-11-12 14:23:43 -0800 | [diff] [blame] | 481 | mVelocityTracker = VelocityTracker.obtain(); |
| 482 | mVelocityTracker.addMovement(ev); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 483 | mStartedScrolling = false; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 484 | } |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 485 | break; |
| 486 | case MotionEvent.ACTION_MOVE: |
| 487 | case MotionEvent.ACTION_OUTSIDE: |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 488 | if (mTouchTracking == TRACKING_HOME) { |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 489 | mRollo.setHomeSelected(y > mRollo.mTouchYBorders[mRollo.mTouchYBorders.length-1] |
| 490 | ? SELECTED_PRESSED : SELECTED_NONE); |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 491 | mRollo.mState.save(); |
Joe Onorato | 68ffd10 | 2009-10-15 17:59:43 -0700 | [diff] [blame] | 492 | } else if (mTouchTracking == TRACKING_FLING) { |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 493 | int rawX = (int)ev.getRawX(); |
| 494 | int rawY = (int)ev.getRawY(); |
| 495 | int slop; |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 496 | slop = Math.abs(rawY - mMotionDownRawY); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 497 | |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 498 | if (!mStartedScrolling && slop < mSlop) { |
| 499 | // don't update anything so when we do start scrolling |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 500 | // below, we get the right delta. |
Joe Onorato | 68ba5ca | 2009-11-12 14:23:43 -0800 | [diff] [blame] | 501 | mCurrentIconIndex = mRollo.chooseTappedIcon(x, y, mPosX); |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 502 | if (mDownIconIndex != mCurrentIconIndex) { |
| 503 | // If a different icon is selected, don't allow it to be picked up. |
| 504 | // This handles off-axis dragging. |
| 505 | cancelLongPress(); |
| 506 | mCurrentIconIndex = -1; |
| 507 | } |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 508 | } else { |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 509 | if (!mStartedScrolling) { |
| 510 | cancelLongPress(); |
| 511 | mCurrentIconIndex = -1; |
| 512 | } |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 513 | mRollo.mState.newPositionX = ev.getRawY() / getHeight(); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 514 | mRollo.mState.newTouchDown = 1; |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 515 | mRollo.move(); |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 516 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 517 | mStartedScrolling = true; |
| 518 | mRollo.clearSelectedIcon(); |
Joe Onorato | 68ba5ca | 2009-11-12 14:23:43 -0800 | [diff] [blame] | 519 | mVelocityTracker.addMovement(ev); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 520 | mRollo.mState.save(); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 521 | } |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 522 | } |
| 523 | break; |
| 524 | case MotionEvent.ACTION_UP: |
| 525 | case MotionEvent.ACTION_CANCEL: |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 526 | if (mTouchTracking == TRACKING_HOME) { |
| 527 | if (action == MotionEvent.ACTION_UP) { |
| 528 | if (y > mRollo.mTouchYBorders[mRollo.mTouchYBorders.length-1]) { |
Joe Onorato | b39e51a | 2009-10-28 15:47:49 -0400 | [diff] [blame] | 529 | reallyPlaySoundEffect(SoundEffectConstants.CLICK); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 530 | mLauncher.closeAllApps(true); |
| 531 | } |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 532 | mRollo.setHomeSelected(SELECTED_NONE); |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 533 | mRollo.mState.save(); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 534 | } |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 535 | mCurrentIconIndex = -1; |
Joe Onorato | 68ffd10 | 2009-10-15 17:59:43 -0700 | [diff] [blame] | 536 | } else if (mTouchTracking == TRACKING_FLING) { |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 537 | mRollo.mState.newTouchDown = 0; |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 538 | mRollo.mState.newPositionX = ev.getRawY() / getHeight(); |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 539 | |
Joe Onorato | 68ba5ca | 2009-11-12 14:23:43 -0800 | [diff] [blame] | 540 | mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity); |
| 541 | mRollo.mState.flingVelocity = mVelocityTracker.getYVelocity() / getHeight(); |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 542 | mRollo.clearSelectedIcon(); |
| 543 | mRollo.mState.save(); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 544 | mRollo.fling(); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 545 | |
Joe Onorato | 68ba5ca | 2009-11-12 14:23:43 -0800 | [diff] [blame] | 546 | if (mVelocityTracker != null) { |
| 547 | mVelocityTracker.recycle(); |
| 548 | mVelocityTracker = null; |
Joe Onorato | 539ed9d | 2009-10-02 10:22:14 -0700 | [diff] [blame] | 549 | } |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 550 | } |
Joe Onorato | 68ffd10 | 2009-10-15 17:59:43 -0700 | [diff] [blame] | 551 | mTouchTracking = TRACKING_NONE; |
| 552 | break; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 553 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 554 | |
| 555 | return true; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 558 | public void onClick(View v) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 559 | if (mLocks != 0 || !isVisible()) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 560 | return; |
| 561 | } |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 562 | if (mRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex |
| 563 | && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) { |
Joe Onorato | b39e51a | 2009-10-28 15:47:49 -0400 | [diff] [blame] | 564 | reallyPlaySoundEffect(SoundEffectConstants.CLICK); |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 565 | ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 566 | mLauncher.startActivitySafely(app.intent); |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | public boolean onLongClick(View v) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 571 | if (mLocks != 0 || !isVisible()) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 572 | return true; |
| 573 | } |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 574 | if (mRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex |
| 575 | && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) { |
| 576 | ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex); |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 577 | |
| 578 | // We don't really have an accurate location to use. This will do. |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 579 | int screenX = mMotionDownRawX - (mDefines.ICON_WIDTH_PX / 2); |
| 580 | int screenY = mMotionDownRawY - mDefines.ICON_HEIGHT_PX; |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 581 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 582 | int left = (mDefines.ICON_TEXTURE_WIDTH_PX - mDefines.ICON_WIDTH_PX) / 2; |
| 583 | int top = (mDefines.ICON_TEXTURE_HEIGHT_PX - mDefines.ICON_HEIGHT_PX) / 2; |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 584 | mDragController.startDrag(app.iconBitmap, screenX, screenY, |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 585 | left, top, mDefines.ICON_WIDTH_PX, mDefines.ICON_HEIGHT_PX, |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 586 | this, app, DragController.DRAG_ACTION_COPY); |
Joe Onorato | e3406a2 | 2009-09-03 14:36:25 -0700 | [diff] [blame] | 587 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 588 | mLauncher.closeAllApps(true); |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 589 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 590 | return true; |
| 591 | } |
| 592 | |
Joe Onorato | 52a653f | 2009-11-11 14:52:11 -0800 | [diff] [blame] | 593 | @Override |
| 594 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 595 | if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) { |
| 596 | if (!isVisible()) { |
| 597 | return false; |
| 598 | } |
| 599 | String text = null; |
| 600 | int index; |
| 601 | int count = mAllAppsList.size() + 1; // +1 is home |
| 602 | int pos = -1; |
| 603 | switch (mLastSelection) { |
| 604 | case SELECTION_ICONS: |
| 605 | index = mRollo.mState.selectedIconIndex; |
| 606 | if (index >= 0) { |
| 607 | ApplicationInfo info = mAllAppsList.get(index); |
| 608 | if (info.title != null) { |
| 609 | text = info.title.toString(); |
| 610 | pos = index; |
| 611 | } |
| 612 | } |
| 613 | break; |
| 614 | case SELECTION_HOME: |
| 615 | text = getContext().getString(R.string.all_apps_home_button_label); |
| 616 | pos = count; |
| 617 | break; |
| 618 | } |
| 619 | if (text != null) { |
Joe Onorato | 52a653f | 2009-11-11 14:52:11 -0800 | [diff] [blame] | 620 | event.setEnabled(true); |
| 621 | event.getText().add(text); |
| 622 | //event.setContentDescription(text); |
| 623 | event.setItemCount(count); |
| 624 | event.setCurrentItemIndex(pos); |
| 625 | } |
| 626 | } |
| 627 | return false; |
| 628 | } |
| 629 | |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 630 | public void setDragController(DragController dragger) { |
| 631 | mDragController = dragger; |
| 632 | } |
| 633 | |
| 634 | public void onDropCompleted(View target, boolean success) { |
| 635 | } |
| 636 | |
Joe Onorato | 4db5231 | 2009-10-06 11:17:43 -0700 | [diff] [blame] | 637 | /** |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 638 | * Zoom to the specifed level. |
Joe Onorato | 4db5231 | 2009-10-06 11:17:43 -0700 | [diff] [blame] | 639 | * |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 640 | * @param zoom [0..1] 0 is hidden, 1 is open |
Joe Onorato | 4db5231 | 2009-10-06 11:17:43 -0700 | [diff] [blame] | 641 | */ |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 642 | public void zoom(float zoom, boolean animate) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 643 | cancelLongPress(); |
Joe Onorato | 6374c51 | 2010-01-06 20:42:25 -0800 | [diff] [blame^] | 644 | mNextZoom = zoom; |
| 645 | mAnimateNextZoom = animate; |
| 646 | // if we do setZoom while we don't have a surface, we won't |
| 647 | // get the callbacks that actually set mZoom. |
| 648 | if (mRollo == null || !mHaveSurface) { |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 649 | mZoomDirty = true; |
Joe Onorato | 68ba5ca | 2009-11-12 14:23:43 -0800 | [diff] [blame] | 650 | mZoom = zoom; |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 651 | return; |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 652 | } else { |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 653 | mRollo.setZoom(zoom, animate); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 654 | } |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | public boolean isVisible() { |
Joe Onorato | 68ba5ca | 2009-11-12 14:23:43 -0800 | [diff] [blame] | 658 | return mZoom > 0.001f; |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | public boolean isOpaque() { |
Joe Onorato | 68ba5ca | 2009-11-12 14:23:43 -0800 | [diff] [blame] | 662 | return mZoom > 0.999f; |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 663 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 664 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 665 | public void setApps(ArrayList<ApplicationInfo> list) { |
| 666 | mAllAppsList = list; |
| 667 | if (mRollo != null) { |
Joe Onorato | 3ecbd81 | 2009-12-11 13:38:54 -0800 | [diff] [blame] | 668 | mRollo.setApps(list); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 669 | } |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 670 | mLocks &= ~LOCK_ICONS_PENDING; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 673 | public void addApps(ArrayList<ApplicationInfo> list) { |
Joe Onorato | 2d80476 | 2009-11-05 16:02:32 -0500 | [diff] [blame] | 674 | if (mAllAppsList == null) { |
| 675 | // Not done loading yet. We'll find out about it later. |
| 676 | return; |
| 677 | } |
| 678 | |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 679 | final int N = list.size(); |
Joe Onorato | 8eea391 | 2009-12-09 13:01:06 -0800 | [diff] [blame] | 680 | if (mRollo != null) { |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 681 | mRollo.reallocAppsList(mRollo.mState.iconCount + N); |
| 682 | } |
| 683 | |
| 684 | for (int i=0; i<N; i++) { |
| 685 | final ApplicationInfo item = list.get(i); |
Joe Onorato | b0c27f2 | 2009-12-01 16:19:38 -0800 | [diff] [blame] | 686 | int index = Collections.binarySearch(mAllAppsList, item, |
| 687 | LauncherModel.APP_NAME_COMPARATOR); |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 688 | if (index < 0) { |
| 689 | index = -(index+1); |
| 690 | } |
| 691 | mAllAppsList.add(index, item); |
Joe Onorato | 8eea391 | 2009-12-09 13:01:06 -0800 | [diff] [blame] | 692 | if (mRollo != null) { |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 693 | mRollo.addApp(index, item); |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | |
Joe Onorato | 8eea391 | 2009-12-09 13:01:06 -0800 | [diff] [blame] | 697 | if (mRollo != null) { |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 698 | mRollo.saveAppsList(); |
| 699 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 702 | public void removeApps(ArrayList<ApplicationInfo> list) { |
Joe Onorato | 2d80476 | 2009-11-05 16:02:32 -0500 | [diff] [blame] | 703 | if (mAllAppsList == null) { |
| 704 | // Not done loading yet. We'll find out about it later. |
| 705 | return; |
| 706 | } |
| 707 | |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 708 | final int N = list.size(); |
| 709 | for (int i=0; i<N; i++) { |
| 710 | final ApplicationInfo item = list.get(i); |
Joe Onorato | cb9f798 | 2009-10-31 16:32:02 -0400 | [diff] [blame] | 711 | int index = findAppByComponent(mAllAppsList, item); |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 712 | if (index >= 0) { |
Joe Onorato | a276fc5 | 2009-12-08 17:02:02 -0800 | [diff] [blame] | 713 | int ic = mRollo != null ? mRollo.mState.iconCount : 666; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 714 | mAllAppsList.remove(index); |
Joe Onorato | 8eea391 | 2009-12-09 13:01:06 -0800 | [diff] [blame] | 715 | if (mRollo != null) { |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 716 | mRollo.removeApp(index); |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 717 | } |
| 718 | } else { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 719 | Log.w(TAG, "couldn't find a match for item \"" + item + "\""); |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 720 | // Try to recover. This should keep us from crashing for now. |
| 721 | } |
| 722 | } |
| 723 | |
Joe Onorato | 8eea391 | 2009-12-09 13:01:06 -0800 | [diff] [blame] | 724 | if (mRollo != null) { |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 725 | mRollo.saveAppsList(); |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | public void updateApps(String packageName, ArrayList<ApplicationInfo> list) { |
| 730 | // Just remove and add, because they may need to be re-sorted. |
| 731 | removeApps(list); |
| 732 | addApps(list); |
| 733 | } |
| 734 | |
Joe Onorato | cb9f798 | 2009-10-31 16:32:02 -0400 | [diff] [blame] | 735 | private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) { |
| 736 | ComponentName component = item.intent.getComponent(); |
| 737 | final int N = list.size(); |
| 738 | for (int i=0; i<N; i++) { |
| 739 | ApplicationInfo x = list.get(i); |
| 740 | if (x.intent.getComponent().equals(component)) { |
| 741 | return i; |
| 742 | } |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 743 | } |
Joe Onorato | cb9f798 | 2009-10-31 16:32:02 -0400 | [diff] [blame] | 744 | return -1; |
| 745 | } |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 746 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 747 | private static int countPages(int iconCount) { |
| 748 | int iconsPerPage = Defines.COLUMNS_PER_PAGE * Defines.ROWS_PER_PAGE; |
| 749 | int pages = iconCount / iconsPerPage; |
| 750 | if (pages*iconsPerPage != iconCount) { |
| 751 | pages++; |
| 752 | } |
| 753 | return pages; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 754 | } |
| 755 | |
Joe Onorato | cb75f36 | 2009-11-12 13:04:07 -0800 | [diff] [blame] | 756 | class AAMessage extends RenderScript.RSMessage { |
| 757 | public void run() { |
| 758 | mPosX = ((float)mData[0]) / (1 << 16); |
| 759 | mVelocity = ((float)mData[1]) / (1 << 16); |
| 760 | mZoom = ((float)mData[2]) / (1 << 16); |
| 761 | mZoomDirty = false; |
| 762 | } |
Joe Onorato | cb75f36 | 2009-11-12 13:04:07 -0800 | [diff] [blame] | 763 | } |
| 764 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 765 | public class RolloRS { |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 766 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 767 | // Allocations ====== |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 768 | private int mWidth; |
| 769 | private int mHeight; |
| 770 | |
| 771 | private Resources mRes; |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 772 | private Script mScript; |
| 773 | private Script.Invokable mInvokeMove; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 774 | private Script.Invokable mInvokeMoveTo; |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 775 | private Script.Invokable mInvokeFling; |
| 776 | private Script.Invokable mInvokeResetWAR; |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 777 | private Script.Invokable mInvokeSetZoom; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 778 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 779 | private ProgramStore mPSIcons; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 780 | private ProgramStore mPSText; |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 781 | private ProgramFragment mPFColor; |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 782 | private ProgramFragment mPFTexMip; |
| 783 | private ProgramFragment mPFTexNearest; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 784 | private ProgramVertex mPV; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 785 | private ProgramVertex mPVOrtho; |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 786 | private SimpleMesh mMesh; |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 787 | private SimpleMesh mMesh2; |
Jason Sams | 5612e43 | 2009-11-16 14:18:07 -0800 | [diff] [blame] | 788 | private ProgramVertex.MatrixAllocation mPVA; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 789 | |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 790 | private Allocation mHomeButtonNormal; |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 791 | private Allocation mHomeButtonFocused; |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 792 | private Allocation mHomeButtonPressed; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 793 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 794 | private Allocation[] mIcons; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 795 | private int[] mIconIds; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 796 | private Allocation mAllocIconIds; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 797 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 798 | private Allocation[] mLabels; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 799 | private int[] mLabelIds; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 800 | private Allocation mAllocLabelIds; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 801 | private Allocation mSelectedIcon; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 802 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 803 | private int[] mTouchYBorders; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 804 | private int[] mTouchXBorders; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 805 | |
| 806 | private Bitmap mSelectionBitmap; |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 807 | private Canvas mSelectionCanvas; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 808 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 809 | Params mParams; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 810 | State mState; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 811 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 812 | class BaseAlloc { |
| 813 | Allocation mAlloc; |
| 814 | Type mType; |
| 815 | |
| 816 | void save() { |
| 817 | mAlloc.data(this); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 818 | } |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 819 | } |
| 820 | |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 821 | private boolean checkClickOK() { |
Joe Onorato | 68ba5ca | 2009-11-12 14:23:43 -0800 | [diff] [blame] | 822 | return (Math.abs(mVelocity) < 0.4f) && |
| 823 | (Math.abs(mPosX - Math.round(mPosX)) < 0.4f); |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 824 | } |
| 825 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 826 | class Params extends BaseAlloc { |
| 827 | Params() { |
| 828 | mType = Type.createFromClass(mRS, Params.class, 1, "ParamsClass"); |
| 829 | mAlloc = Allocation.createTyped(mRS, mType); |
| 830 | save(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 831 | } |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 832 | public int bubbleWidth; |
| 833 | public int bubbleHeight; |
| 834 | public int bubbleBitmapWidth; |
| 835 | public int bubbleBitmapHeight; |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 836 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 837 | public int homeButtonWidth; |
| 838 | public int homeButtonHeight; |
| 839 | public int homeButtonTextureWidth; |
| 840 | public int homeButtonTextureHeight; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | class State extends BaseAlloc { |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 844 | public float newPositionX; |
| 845 | public int newTouchDown; |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 846 | public float flingVelocity; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 847 | public int iconCount; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 848 | public int selectedIconIndex = -1; |
| 849 | public int selectedIconTexture; |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 850 | public float zoomTarget; |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 851 | public int homeButtonId; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 852 | public float targetPos; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 853 | |
| 854 | State() { |
| 855 | mType = Type.createFromClass(mRS, State.class, 1, "StateClass"); |
| 856 | mAlloc = Allocation.createTyped(mRS, mType); |
| 857 | save(); |
| 858 | } |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | public RolloRS() { |
| 862 | } |
| 863 | |
| 864 | public void init(Resources res, int width, int height) { |
| 865 | mRes = res; |
| 866 | mWidth = width; |
| 867 | mHeight = height; |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 868 | mDefines.recompute(width, height); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 869 | initProgramVertex(); |
| 870 | initProgramFragment(); |
| 871 | initProgramStore(); |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 872 | initMesh(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 873 | initGl(); |
| 874 | initData(); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 875 | initTouchState(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 876 | initRs(); |
| 877 | } |
| 878 | |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 879 | public void initMesh() { |
| 880 | SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(mRS, 3, |
| 881 | SimpleMesh.TriangleMeshBuilder.TEXTURE_0 | SimpleMesh.TriangleMeshBuilder.COLOR); |
| 882 | |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 883 | float y = 0; |
| 884 | float z = 0; |
| 885 | for (int ct=0; ct < 200; ct++) { |
| 886 | float angle = 0; |
| 887 | float maxAngle = 3.14f * 0.16f; |
| 888 | float l = 1.f; |
| 889 | |
| 890 | l = 1 - ((ct-5) * 0.10f); |
| 891 | if (ct > 7) { |
| 892 | angle = maxAngle * (ct - 7) * 0.2f; |
| 893 | angle = Math.min(angle, maxAngle); |
| 894 | } |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 895 | l = Math.max(0.4f, l); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 896 | l = Math.min(1.0f, l); |
| 897 | |
| 898 | y += 0.1f * Math.cos(angle); |
| 899 | z += 0.1f * Math.sin(angle); |
| 900 | |
| 901 | float t = 0.1f * ct; |
| 902 | float ds = 0.08f; |
| 903 | tm.setColor(l, l, l, 0.99f); |
| 904 | tm.setTexture(ds, t); |
| 905 | tm.addVertex(-0.5f, y, z); |
| 906 | tm.setTexture(1 - ds, t); |
| 907 | tm.addVertex(0.5f, y, z); |
| 908 | } |
| 909 | for (int ct=0; ct < (200 * 2 - 2); ct+= 2) { |
| 910 | tm.addTriangle(ct, ct+1, ct+2); |
| 911 | tm.addTriangle(ct+1, ct+3, ct+2); |
| 912 | } |
| 913 | mMesh2 = tm.create(); |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 914 | mMesh2.setName("SMMesh"); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Jason Sams | 5612e43 | 2009-11-16 14:18:07 -0800 | [diff] [blame] | 917 | void resize(int w, int h) { |
| 918 | mPVA.setupProjectionNormalized(w, h); |
| 919 | mWidth = w; |
| 920 | mHeight = h; |
| 921 | } |
| 922 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 923 | private void initProgramVertex() { |
Jason Sams | 5612e43 | 2009-11-16 14:18:07 -0800 | [diff] [blame] | 924 | mPVA = new ProgramVertex.MatrixAllocation(mRS); |
| 925 | resize(mWidth, mHeight); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 926 | |
| 927 | ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null); |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 928 | pvb.setTextureMatrixEnable(true); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 929 | mPV = pvb.create(); |
| 930 | mPV.setName("PV"); |
Jason Sams | 5612e43 | 2009-11-16 14:18:07 -0800 | [diff] [blame] | 931 | mPV.bindAllocation(mPVA); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 932 | |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 933 | //pva = new ProgramVertex.MatrixAllocation(mRS); |
| 934 | //pva.setupOrthoWindow(mWidth, mHeight); |
| 935 | //pvb.setTextureMatrixEnable(true); |
| 936 | //mPVOrtho = pvb.create(); |
| 937 | //mPVOrtho.setName("PVOrtho"); |
| 938 | //mPVOrtho.bindAllocation(pva); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 939 | |
| 940 | mRS.contextBindProgramVertex(mPV); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 941 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 942 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 943 | private void initProgramFragment() { |
| 944 | Sampler.Builder sb = new Sampler.Builder(mRS); |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 945 | sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 946 | sb.setMag(Sampler.Value.LINEAR); |
| 947 | sb.setWrapS(Sampler.Value.CLAMP); |
| 948 | sb.setWrapT(Sampler.Value.CLAMP); |
| 949 | Sampler linear = sb.create(); |
| 950 | |
| 951 | sb.setMin(Sampler.Value.NEAREST); |
| 952 | sb.setMag(Sampler.Value.NEAREST); |
| 953 | Sampler nearest = sb.create(); |
| 954 | |
Jason Sams | 72f1d31 | 2009-12-17 16:58:25 -0800 | [diff] [blame] | 955 | ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS); |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 956 | //mPFColor = bf.create(); |
| 957 | //mPFColor.setName("PFColor"); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 958 | |
Jason Sams | 72f1d31 | 2009-12-17 16:58:25 -0800 | [diff] [blame] | 959 | bf.setTexture(ProgramFragment.Builder.EnvMode.REPLACE, |
| 960 | ProgramFragment.Builder.Format.RGBA, 0); |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 961 | mPFTexMip = bf.create(); |
| 962 | mPFTexMip.setName("PFTexMip"); |
| 963 | mPFTexMip.bindSampler(linear, 0); |
| 964 | |
| 965 | mPFTexNearest = bf.create(); |
| 966 | mPFTexNearest.setName("PFTexNearest"); |
| 967 | mPFTexNearest.bindSampler(nearest, 0); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | private void initProgramStore() { |
| 971 | ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null); |
| 972 | bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 973 | bs.setColorMask(true,true,true,false); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 974 | bs.setDitherEnable(true); |
| 975 | bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, |
| 976 | ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA); |
| 977 | mPSIcons = bs.create(); |
| 978 | mPSIcons.setName("PSIcons"); |
| 979 | |
| 980 | //bs.setDitherEnable(false); |
| 981 | //mPSText = bs.create(); |
| 982 | //mPSText.setName("PSText"); |
| 983 | } |
| 984 | |
| 985 | private void initGl() { |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 986 | mTouchXBorders = new int[Defines.COLUMNS_PER_PAGE+1]; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 987 | mTouchYBorders = new int[Defines.ROWS_PER_PAGE+1]; |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 988 | } |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 989 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 990 | private void initData() { |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 991 | mParams = new Params(); |
| 992 | mState = new State(); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 993 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 994 | final Utilities.BubbleText bubble = new Utilities.BubbleText(getContext()); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 995 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 996 | mParams.bubbleWidth = bubble.getBubbleWidth(); |
| 997 | mParams.bubbleHeight = bubble.getMaxBubbleHeight(); |
| 998 | mParams.bubbleBitmapWidth = bubble.getBitmapWidth(); |
| 999 | mParams.bubbleBitmapHeight = bubble.getBitmapHeight(); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 1000 | |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 1001 | mHomeButtonNormal = Allocation.createFromBitmapResource(mRS, mRes, |
| 1002 | R.drawable.home_button_normal, Element.RGBA_8888(mRS), false); |
| 1003 | mHomeButtonNormal.uploadToTexture(0); |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 1004 | mHomeButtonFocused = Allocation.createFromBitmapResource(mRS, mRes, |
| 1005 | R.drawable.home_button_focused, Element.RGBA_8888(mRS), false); |
| 1006 | mHomeButtonFocused.uploadToTexture(0); |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 1007 | mHomeButtonPressed = Allocation.createFromBitmapResource(mRS, mRes, |
| 1008 | R.drawable.home_button_pressed, Element.RGBA_8888(mRS), false); |
| 1009 | mHomeButtonPressed.uploadToTexture(0); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 1010 | mParams.homeButtonWidth = 76; |
| 1011 | mParams.homeButtonHeight = 68; |
| 1012 | mParams.homeButtonTextureWidth = 128; |
| 1013 | mParams.homeButtonTextureHeight = 128; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 1014 | |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 1015 | mState.homeButtonId = mHomeButtonNormal.getID(); |
| 1016 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 1017 | mParams.save(); |
| 1018 | mState.save(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1019 | |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 1020 | mSelectionBitmap = Bitmap.createBitmap(Defines.ICON_TEXTURE_WIDTH_PX, |
| 1021 | Defines.ICON_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888); |
| 1022 | mSelectionCanvas = new Canvas(mSelectionBitmap); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1023 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1024 | setApps(null); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 1027 | private void initScript(int id) { |
| 1028 | } |
| 1029 | |
| 1030 | private void initRs() { |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 1031 | ScriptC.Builder sb = new ScriptC.Builder(mRS); |
Jason Sams | d15f3ef | 2010-01-06 14:58:06 -0800 | [diff] [blame] | 1032 | sb.setScript(mRes, R.raw.allapps); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 1033 | sb.setRoot(true); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 1034 | sb.addDefines(mDefines); |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 1035 | sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS); |
| 1036 | sb.setType(mState.mType, "state", Defines.ALLOC_STATE); |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 1037 | mInvokeMove = sb.addInvokable("move"); |
| 1038 | mInvokeFling = sb.addInvokable("fling"); |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 1039 | mInvokeMoveTo = sb.addInvokable("moveTo"); |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 1040 | mInvokeResetWAR = sb.addInvokable("resetHWWar"); |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1041 | mInvokeSetZoom = sb.addInvokable("setZoom"); |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 1042 | mScript = sb.create(); |
| 1043 | mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 1044 | mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS); |
| 1045 | mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE); |
| 1046 | mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS); |
| 1047 | mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 1048 | |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 1049 | mRS.contextBindRootScript(mScript); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 1050 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 1051 | |
Jason Sams | 20df7c7 | 2009-11-05 12:30:24 -0800 | [diff] [blame] | 1052 | void dirtyCheck() { |
Jason Sams | 510ee04 | 2009-12-15 14:23:37 -0800 | [diff] [blame] | 1053 | if (mZoomDirty) { |
Joe Onorato | 6374c51 | 2010-01-06 20:42:25 -0800 | [diff] [blame^] | 1054 | setZoom(mNextZoom, mAnimateNextZoom); |
Jason Sams | 20df7c7 | 2009-11-05 12:30:24 -0800 | [diff] [blame] | 1055 | } |
| 1056 | } |
| 1057 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1058 | private void setApps(ArrayList<ApplicationInfo> list) { |
| 1059 | final int count = list != null ? list.size() : 0; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 1060 | int allocCount = count; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1061 | if (allocCount < 1) { |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 1062 | allocCount = 1; |
| 1063 | } |
| 1064 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1065 | mIcons = new Allocation[count]; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 1066 | mIconIds = new int[allocCount]; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1067 | mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1068 | |
| 1069 | mLabels = new Allocation[count]; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 1070 | mLabelIds = new int[allocCount]; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1071 | mAllocLabelIds = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1072 | |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 1073 | Element ie8888 = Element.RGBA_8888(mRS); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1074 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1075 | mState.iconCount = count; |
Joe Onorato | 8eea391 | 2009-12-09 13:01:06 -0800 | [diff] [blame] | 1076 | for (int i=0; i < mState.iconCount; i++) { |
| 1077 | createAppIconAllocations(i, list.get(i)); |
Joe Onorato | 3ecbd81 | 2009-12-11 13:38:54 -0800 | [diff] [blame] | 1078 | } |
Jason Sams | 510ee04 | 2009-12-15 14:23:37 -0800 | [diff] [blame] | 1079 | for (int i=0; i < mState.iconCount; i++) { |
| 1080 | uploadAppIcon(i, list.get(i)); |
Joe Onorato | 8eea391 | 2009-12-09 13:01:06 -0800 | [diff] [blame] | 1081 | } |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1082 | saveAppsList(); |
| 1083 | } |
| 1084 | |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 1085 | private void setZoom(float zoom, boolean animate) { |
| 1086 | mRollo.clearSelectedIcon(); |
| 1087 | mRollo.setHomeSelected(SELECTED_NONE); |
| 1088 | if (zoom > 0.001f) { |
| 1089 | mRollo.mState.zoomTarget = zoom; |
| 1090 | } else { |
| 1091 | mRollo.mState.zoomTarget = 0; |
| 1092 | } |
| 1093 | mRollo.mState.save(); |
| 1094 | if (!animate) { |
| 1095 | mRollo.mInvokeSetZoom.execute(); |
| 1096 | } |
| 1097 | } |
| 1098 | |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 1099 | private void frameBitmapAllocMips(Allocation alloc, int w, int h) { |
| 1100 | int black[] = new int[w > h ? w : h]; |
| 1101 | Allocation.Adapter2D a = alloc.createAdapter2D(); |
| 1102 | int mip = 0; |
| 1103 | while (w > 1 || h > 1) { |
| 1104 | a.subData(0, 0, 1, h, black); |
| 1105 | a.subData(w-1, 0, 1, h, black); |
| 1106 | a.subData(0, 0, w, 1, black); |
| 1107 | a.subData(0, h-1, w, 1, black); |
| 1108 | mip++; |
| 1109 | w = (w + 1) >> 1; |
| 1110 | h = (h + 1) >> 1; |
| 1111 | a.setConstraint(Dimension.LOD, mip); |
| 1112 | } |
| 1113 | a.subData(0, 0, 1, 1, black); |
| 1114 | } |
| 1115 | |
Joe Onorato | 8eea391 | 2009-12-09 13:01:06 -0800 | [diff] [blame] | 1116 | private void createAppIconAllocations(int index, ApplicationInfo item) { |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1117 | mIcons[index] = Allocation.createFromBitmap(mRS, item.iconBitmap, |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 1118 | Element.RGBA_8888(mRS), true); |
Joe Onorato | 8eea391 | 2009-12-09 13:01:06 -0800 | [diff] [blame] | 1119 | frameBitmapAllocMips(mIcons[index], item.iconBitmap.getWidth(), |
| 1120 | item.iconBitmap.getHeight()); |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 1121 | |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1122 | mLabels[index] = Allocation.createFromBitmap(mRS, item.titleBitmap, |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 1123 | Element.RGBA_8888(mRS), true); |
Joe Onorato | 8eea391 | 2009-12-09 13:01:06 -0800 | [diff] [blame] | 1124 | frameBitmapAllocMips(mLabels[index], item.titleBitmap.getWidth(), |
| 1125 | item.titleBitmap.getHeight()); |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1126 | |
| 1127 | mIconIds[index] = mIcons[index].getID(); |
| 1128 | mLabelIds[index] = mLabels[index].getID(); |
| 1129 | } |
| 1130 | |
Joe Onorato | 8eea391 | 2009-12-09 13:01:06 -0800 | [diff] [blame] | 1131 | private void uploadAppIcon(int index, ApplicationInfo item) { |
| 1132 | if (mIconIds[index] != mIcons[index].getID()) { |
| 1133 | throw new IllegalStateException("uploadAppIcon index=" + index |
| 1134 | + " mIcons[index].getID=" + mIcons[index].getID() |
| 1135 | + " mIconsIds[index]=" + mIconIds[index] |
| 1136 | + " item=" + item); |
| 1137 | } |
| 1138 | mIcons[index].uploadToTexture(0); |
| 1139 | mLabels[index].uploadToTexture(0); |
| 1140 | } |
| 1141 | |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1142 | /** |
| 1143 | * Puts the empty spaces at the end. Updates mState.iconCount. You must |
| 1144 | * fill in the values and call saveAppsList(). |
| 1145 | */ |
| 1146 | private void reallocAppsList(int count) { |
| 1147 | Allocation[] icons = new Allocation[count]; |
| 1148 | int[] iconIds = new int[count]; |
| 1149 | mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), count); |
| 1150 | |
| 1151 | Allocation[] labels = new Allocation[count]; |
| 1152 | int[] labelIds = new int[count]; |
| 1153 | mAllocLabelIds = Allocation.createSized(mRS, Element.USER_I32(mRS), count); |
| 1154 | |
Joe Onorato | bf173f1 | 2009-12-08 13:29:38 -0800 | [diff] [blame] | 1155 | final int oldCount = mRollo.mState.iconCount; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1156 | |
| 1157 | System.arraycopy(mIcons, 0, icons, 0, oldCount); |
| 1158 | System.arraycopy(mIconIds, 0, iconIds, 0, oldCount); |
| 1159 | System.arraycopy(mLabels, 0, labels, 0, oldCount); |
| 1160 | System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount); |
| 1161 | |
| 1162 | mIcons = icons; |
| 1163 | mIconIds = iconIds; |
| 1164 | mLabels = labels; |
| 1165 | mLabelIds = labelIds; |
| 1166 | } |
| 1167 | |
| 1168 | /** |
| 1169 | * Handle the allocations for the new app. Make sure you call saveAppsList when done. |
| 1170 | */ |
| 1171 | private void addApp(int index, ApplicationInfo item) { |
| 1172 | final int count = mState.iconCount - index; |
| 1173 | final int dest = index + 1; |
| 1174 | |
| 1175 | System.arraycopy(mIcons, index, mIcons, dest, count); |
| 1176 | System.arraycopy(mIconIds, index, mIconIds, dest, count); |
| 1177 | System.arraycopy(mLabels, index, mLabels, dest, count); |
| 1178 | System.arraycopy(mLabelIds, index, mLabelIds, dest, count); |
| 1179 | |
Joe Onorato | 8eea391 | 2009-12-09 13:01:06 -0800 | [diff] [blame] | 1180 | createAppIconAllocations(index, item); |
Jason Sams | 510ee04 | 2009-12-15 14:23:37 -0800 | [diff] [blame] | 1181 | uploadAppIcon(index, item); |
Joe Onorato | 8eea391 | 2009-12-09 13:01:06 -0800 | [diff] [blame] | 1182 | mRollo.mState.iconCount++; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | /** |
| 1186 | * Handle the allocations for the removed app. Make sure you call saveAppsList when done. |
| 1187 | */ |
| 1188 | private void removeApp(int index) { |
| 1189 | final int count = mState.iconCount - index - 1; |
| 1190 | final int src = index + 1; |
| 1191 | |
| 1192 | System.arraycopy(mIcons, src, mIcons, index, count); |
| 1193 | System.arraycopy(mIconIds, src, mIconIds, index, count); |
| 1194 | System.arraycopy(mLabels, src, mLabels, index, count); |
| 1195 | System.arraycopy(mLabelIds, src, mLabelIds, index, count); |
| 1196 | |
Joe Onorato | a276fc5 | 2009-12-08 17:02:02 -0800 | [diff] [blame] | 1197 | mRollo.mState.iconCount--; |
Joe Onorato | 8eea391 | 2009-12-09 13:01:06 -0800 | [diff] [blame] | 1198 | final int last = mState.iconCount; |
Joe Onorato | a276fc5 | 2009-12-08 17:02:02 -0800 | [diff] [blame] | 1199 | |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1200 | mIcons[last] = null; |
| 1201 | mIconIds[last] = 0; |
| 1202 | mLabels[last] = null; |
| 1203 | mLabelIds[last] = 0; |
| 1204 | } |
| 1205 | |
| 1206 | /** |
| 1207 | * Send the apps list structures to RS. |
| 1208 | */ |
| 1209 | private void saveAppsList() { |
| 1210 | mRS.contextBindRootScript(null); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 1211 | |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1212 | mAllocIconIds.data(mIconIds); |
| 1213 | mAllocLabelIds.data(mLabelIds); |
| 1214 | |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 1215 | if (mScript != null) { // this happens when we init it |
| 1216 | mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS); |
| 1217 | mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | mState.save(); |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1221 | |
| 1222 | // Note: mScript may be null if we haven't initialized it yet. |
| 1223 | // In that case, this is a no-op. |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 1224 | if (mInvokeResetWAR != null) { |
| 1225 | mInvokeResetWAR.execute(); |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 1226 | } |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 1227 | mRS.contextBindRootScript(mScript); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1228 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1229 | |
| 1230 | void initTouchState() { |
| 1231 | int width = getWidth(); |
| 1232 | int height = getHeight(); |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 1233 | int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE; |
| 1234 | int cellWidth = width / Defines.COLUMNS_PER_PAGE; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1235 | |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 1236 | int centerY = (height / 2); |
| 1237 | mTouchYBorders[0] = centerY - (cellHeight * 2); |
| 1238 | mTouchYBorders[1] = centerY - cellHeight; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1239 | mTouchYBorders[2] = centerY; |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 1240 | mTouchYBorders[3] = centerY + cellHeight; |
| 1241 | mTouchYBorders[4] = centerY + (cellHeight * 2); |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 1242 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1243 | int centerX = (width / 2); |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 1244 | mTouchXBorders[0] = 0; |
| 1245 | mTouchXBorders[1] = centerX - (width / 4); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1246 | mTouchXBorders[2] = centerX; |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 1247 | mTouchXBorders[3] = centerX + (width / 4); |
| 1248 | mTouchXBorders[4] = width; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
Joe Onorato | 664457d | 2009-10-28 16:30:34 -0400 | [diff] [blame] | 1251 | void fling() { |
| 1252 | mInvokeFling.execute(); |
| 1253 | } |
| 1254 | |
| 1255 | void move() { |
| 1256 | mInvokeMove.execute(); |
| 1257 | } |
| 1258 | |
| 1259 | void moveTo(float row) { |
| 1260 | mState.targetPos = row; |
| 1261 | mState.save(); |
| 1262 | mInvokeMoveTo.execute(); |
| 1263 | } |
| 1264 | |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 1265 | int chooseTappedIcon(int x, int y, float pos) { |
| 1266 | // Adjust for scroll position if not zero. |
| 1267 | y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]); |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 1268 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1269 | int col = -1; |
| 1270 | int row = -1; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1271 | for (int i=0; i<Defines.COLUMNS_PER_PAGE; i++) { |
| 1272 | if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) { |
| 1273 | col = i; |
| 1274 | break; |
| 1275 | } |
| 1276 | } |
| 1277 | for (int i=0; i<Defines.ROWS_PER_PAGE; i++) { |
| 1278 | if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) { |
| 1279 | row = i; |
| 1280 | break; |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | if (row < 0 || col < 0) { |
| 1285 | return -1; |
| 1286 | } |
| 1287 | |
Joe Onorato | 664457d | 2009-10-28 16:30:34 -0400 | [diff] [blame] | 1288 | int index = (((int)pos) * Defines.COLUMNS_PER_PAGE) |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1289 | + (row * Defines.ROWS_PER_PAGE) + col; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1290 | |
Joe Onorato | 664457d | 2009-10-28 16:30:34 -0400 | [diff] [blame] | 1291 | if (index >= mState.iconCount) { |
| 1292 | return -1; |
| 1293 | } else { |
| 1294 | return index; |
| 1295 | } |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 1296 | } |
| 1297 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1298 | /** |
| 1299 | * You need to call save() on mState on your own after calling this. |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 1300 | * |
| 1301 | * @return the index of the icon that was selected. |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1302 | */ |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 1303 | int selectIcon(int x, int y, float pos, int pressed) { |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 1304 | final int index = chooseTappedIcon(x, y, pos); |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 1305 | selectIcon(index, pressed); |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 1306 | return index; |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 1307 | } |
| 1308 | |
Joe Onorato | c61cff9 | 2009-11-08 11:54:39 -0500 | [diff] [blame] | 1309 | /** |
| 1310 | * Select the icon at the given index. |
| 1311 | * |
| 1312 | * @param index The index. |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 1313 | * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED |
Joe Onorato | c61cff9 | 2009-11-08 11:54:39 -0500 | [diff] [blame] | 1314 | */ |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 1315 | void selectIcon(int index, int pressed) { |
Joe Onorato | 2d80476 | 2009-11-05 16:02:32 -0500 | [diff] [blame] | 1316 | if (mAllAppsList == null || index < 0 || index >= mAllAppsList.size()) { |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1317 | mState.selectedIconIndex = -1; |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 1318 | if (mLastSelection == SELECTION_ICONS) { |
| 1319 | mLastSelection = SELECTION_NONE; |
| 1320 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1321 | } else { |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 1322 | if (pressed == SELECTED_FOCUSED) { |
| 1323 | mLastSelection = SELECTION_ICONS; |
| 1324 | } |
| 1325 | |
Joe Onorato | 52a653f | 2009-11-11 14:52:11 -0800 | [diff] [blame] | 1326 | int prev = mState.selectedIconIndex; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1327 | mState.selectedIconIndex = index; |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 1328 | |
Joe Onorato | 52a653f | 2009-11-11 14:52:11 -0800 | [diff] [blame] | 1329 | ApplicationInfo info = mAllAppsList.get(index); |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 1330 | Bitmap selectionBitmap = mSelectionBitmap; |
| 1331 | |
| 1332 | Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas, |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 1333 | selectionBitmap.getWidth(), selectionBitmap.getHeight(), |
Joe Onorato | 52a653f | 2009-11-11 14:52:11 -0800 | [diff] [blame] | 1334 | pressed == SELECTED_PRESSED, info.iconBitmap); |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 1335 | |
| 1336 | mSelectedIcon = Allocation.createFromBitmap(mRS, selectionBitmap, |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 1337 | Element.RGBA_8888(mRS), false); |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 1338 | mSelectedIcon.uploadToTexture(0); |
| 1339 | mState.selectedIconTexture = mSelectedIcon.getID(); |
Joe Onorato | 52a653f | 2009-11-11 14:52:11 -0800 | [diff] [blame] | 1340 | |
| 1341 | if (prev != index) { |
| 1342 | if (info.title != null && info.title.length() > 0) { |
Joe Onorato | 52a653f | 2009-11-11 14:52:11 -0800 | [diff] [blame] | 1343 | //setContentDescription(info.title); |
| 1344 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); |
| 1345 | } |
| 1346 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | /** |
| 1351 | * You need to call save() on mState on your own after calling this. |
| 1352 | */ |
| 1353 | void clearSelectedIcon() { |
Joe Onorato | 2ca51dc | 2009-09-16 11:44:14 -0400 | [diff] [blame] | 1354 | mState.selectedIconIndex = -1; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1355 | } |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1356 | |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 1357 | void setHomeSelected(int mode) { |
Joe Onorato | 52a653f | 2009-11-11 14:52:11 -0800 | [diff] [blame] | 1358 | final int prev = mLastSelection; |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 1359 | switch (mode) { |
| 1360 | case SELECTED_NONE: |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 1361 | mState.homeButtonId = mHomeButtonNormal.getID(); |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 1362 | break; |
| 1363 | case SELECTED_FOCUSED: |
| 1364 | mLastSelection = SELECTION_HOME; |
| 1365 | mState.homeButtonId = mHomeButtonFocused.getID(); |
Joe Onorato | 52a653f | 2009-11-11 14:52:11 -0800 | [diff] [blame] | 1366 | if (prev != SELECTION_HOME) { |
Joe Onorato | 52a653f | 2009-11-11 14:52:11 -0800 | [diff] [blame] | 1367 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); |
| 1368 | } |
Joe Onorato | eb8325a | 2009-11-08 13:20:30 -0500 | [diff] [blame] | 1369 | break; |
| 1370 | case SELECTED_PRESSED: |
| 1371 | mState.homeButtonId = mHomeButtonPressed.getID(); |
| 1372 | break; |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 1373 | } |
| 1374 | } |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1375 | |
| 1376 | public void dumpState() { |
| 1377 | Log.d(TAG, "mRollo.mWidth=" + mWidth); |
| 1378 | Log.d(TAG, "mRollo.mHeight=" + mHeight); |
| 1379 | Log.d(TAG, "mRollo.mIcons=" + mIcons); |
| 1380 | if (mIcons != null) { |
| 1381 | Log.d(TAG, "mRollo.mIcons.length=" + mIcons.length); |
| 1382 | } |
| 1383 | if (mIconIds != null) { |
| 1384 | Log.d(TAG, "mRollo.mIconIds.length=" + mIconIds.length); |
| 1385 | } |
| 1386 | Log.d(TAG, "mRollo.mIconIds=" + Arrays.toString(mIconIds)); |
| 1387 | if (mLabelIds != null) { |
| 1388 | Log.d(TAG, "mRollo.mLabelIds.length=" + mLabelIds.length); |
| 1389 | } |
| 1390 | Log.d(TAG, "mRollo.mLabelIds=" + Arrays.toString(mLabelIds)); |
| 1391 | Log.d(TAG, "mRollo.mTouchXBorders=" + Arrays.toString(mTouchXBorders)); |
| 1392 | Log.d(TAG, "mRollo.mTouchYBorders=" + Arrays.toString(mTouchYBorders)); |
Joe Onorato | be38609 | 2009-11-17 17:32:16 -0800 | [diff] [blame] | 1393 | Log.d(TAG, "mRollo.mState.newPositionX=" + mState.newPositionX); |
| 1394 | Log.d(TAG, "mRollo.mState.newTouchDown=" + mState.newTouchDown); |
| 1395 | Log.d(TAG, "mRollo.mState.flingVelocity=" + mState.flingVelocity); |
| 1396 | Log.d(TAG, "mRollo.mState.iconCount=" + mState.iconCount); |
| 1397 | Log.d(TAG, "mRollo.mState.selectedIconIndex=" + mState.selectedIconIndex); |
| 1398 | Log.d(TAG, "mRollo.mState.selectedIconTexture=" + mState.selectedIconTexture); |
| 1399 | Log.d(TAG, "mRollo.mState.zoomTarget=" + mState.zoomTarget); |
| 1400 | Log.d(TAG, "mRollo.mState.homeButtonId=" + mState.homeButtonId); |
| 1401 | Log.d(TAG, "mRollo.mState.targetPos=" + mState.targetPos); |
| 1402 | Log.d(TAG, "mRollo.mParams.bubbleWidth=" + mParams.bubbleWidth); |
| 1403 | Log.d(TAG, "mRollo.mParams.bubbleHeight=" + mParams.bubbleHeight); |
| 1404 | Log.d(TAG, "mRollo.mParams.bubbleBitmapWidth=" + mParams.bubbleBitmapWidth); |
| 1405 | Log.d(TAG, "mRollo.mParams.bubbleBitmapHeight=" + mParams.bubbleBitmapHeight); |
| 1406 | Log.d(TAG, "mRollo.mParams.homeButtonWidth=" + mParams.homeButtonWidth); |
| 1407 | Log.d(TAG, "mRollo.mParams.homeButtonHeight=" + mParams.homeButtonHeight); |
| 1408 | Log.d(TAG, "mRollo.mParams.homeButtonTextureWidth=" + mParams.homeButtonTextureWidth); |
| 1409 | Log.d(TAG, "mRollo.mParams.homeButtonTextureHeight=" + mParams.homeButtonTextureHeight); |
| 1410 | } |
| 1411 | } |
| 1412 | |
| 1413 | public void dumpState() { |
| 1414 | Log.d(TAG, "mRS=" + mRS); |
| 1415 | Log.d(TAG, "mRollo=" + mRollo); |
| 1416 | ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList); |
| 1417 | Log.d(TAG, "mArrowNavigation=" + mArrowNavigation); |
| 1418 | Log.d(TAG, "mStartedScrolling=" + mStartedScrolling); |
| 1419 | Log.d(TAG, "mLastSelection=" + mLastSelection); |
| 1420 | Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon); |
| 1421 | Log.d(TAG, "mVelocityTracker=" + mVelocityTracker); |
| 1422 | Log.d(TAG, "mTouchTracking=" + mTouchTracking); |
| 1423 | Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus); |
| 1424 | Log.d(TAG, "mZoomDirty=" + mZoomDirty); |
| 1425 | Log.d(TAG, "mAnimateNextZoom=" + mAnimateNextZoom); |
| 1426 | Log.d(TAG, "mZoom=" + mZoom); |
| 1427 | Log.d(TAG, "mPosX=" + mPosX); |
| 1428 | Log.d(TAG, "mVelocity=" + mVelocity); |
| 1429 | Log.d(TAG, "mMessageProc=" + mMessageProc); |
| 1430 | if (mRollo != null) { |
| 1431 | mRollo.dumpState(); |
| 1432 | } |
| 1433 | if (mRS != null) { |
| 1434 | mRS.contextDump(0); |
| 1435 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1436 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | |