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