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