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