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