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