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