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