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