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