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