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