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