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