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