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