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