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; |
| 23 | |
| 24 | import android.renderscript.RSSurfaceView; |
| 25 | import android.renderscript.RenderScript; |
| 26 | |
| 27 | import android.renderscript.RenderScript; |
| 28 | import android.renderscript.ProgramVertex; |
| 29 | import android.renderscript.Element; |
| 30 | import android.renderscript.Allocation; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 31 | import android.renderscript.Type; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 32 | import android.renderscript.Script; |
| 33 | import android.renderscript.ScriptC; |
| 34 | import android.renderscript.ProgramFragment; |
| 35 | import android.renderscript.ProgramStore; |
| 36 | import android.renderscript.Sampler; |
| 37 | |
| 38 | import android.content.Context; |
| 39 | import android.content.res.Resources; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 40 | import android.database.DataSetObserver; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 41 | import android.graphics.Bitmap; |
| 42 | import android.graphics.BitmapFactory; |
| 43 | import android.graphics.Canvas; |
| 44 | import android.graphics.Paint; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 45 | import android.graphics.drawable.BitmapDrawable; |
| 46 | import android.graphics.drawable.Drawable; |
| 47 | import android.os.Handler; |
| 48 | import android.os.Message; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 49 | import android.os.SystemClock; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 50 | import android.util.AttributeSet; |
| 51 | import android.util.Log; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 52 | import android.view.KeyEvent; |
| 53 | import android.view.MotionEvent; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 54 | import android.view.Surface; |
| 55 | import android.view.SurfaceHolder; |
| 56 | import android.view.SurfaceView; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 57 | import android.view.View; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 58 | import android.view.VelocityTracker; |
| 59 | import android.view.ViewConfiguration; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 60 | import android.graphics.PixelFormat; |
| 61 | |
| 62 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 63 | public class AllAppsView extends RSSurfaceView |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 64 | implements View.OnClickListener, View.OnLongClickListener, DragSource { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 65 | private static final String TAG = "Launcher.AllAppsView"; |
| 66 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 67 | /** Bit for mLocks for when there are icons being loaded. */ |
| 68 | private static final int LOCK_ICONS_PENDING = 1; |
| 69 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 70 | private Launcher mLauncher; |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 71 | private DragController mDragController; |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 72 | |
| 73 | /** When this is 0, modifications are allowed, when it's not, they're not. |
| 74 | * TODO: What about scrolling? */ |
| 75 | private int mLocks = LOCK_ICONS_PENDING; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 76 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 77 | private RenderScript mRS; |
| 78 | private RolloRS mRollo; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 79 | private ArrayList<ApplicationInfo> mAllAppsList; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 80 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 81 | private ViewConfiguration mConfig; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 82 | private int mPageCount; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 83 | private boolean mStartedScrolling; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 84 | private VelocityTracker mVelocity; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 85 | private int mLastMotionX; |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 86 | private int mMotionDownRawX; |
| 87 | private int mMotionDownRawY; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 88 | private int mScrollHandleTop; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 89 | private long mTouchTime; |
Joe Onorato | 360d035 | 2009-09-28 14:37:53 -0400 | [diff] [blame] | 90 | private boolean mZoomSwipeInProgress; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 91 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 92 | static class Defines { |
| 93 | private static float farSize(float sizeAt0) { |
| 94 | return sizeAt0 * (Defines.RADIUS - Defines.CAMERA_Z) / -Defines.CAMERA_Z; |
| 95 | } |
| 96 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 97 | public static final int ALLOC_PARAMS = 0; |
| 98 | public static final int ALLOC_STATE = 1; |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 99 | public static final int ALLOC_READBACK = 2; |
| 100 | public static final int ALLOC_ICON_IDS = 3; |
| 101 | public static final int ALLOC_LABEL_IDS = 4; |
| 102 | public static final int ALLOC_X_BORDERS = 5; |
| 103 | public static final int ALLOC_Y_BORDERS = 6; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 104 | |
| 105 | public static final int COLUMNS_PER_PAGE = 4; |
| 106 | public static final int ROWS_PER_PAGE = 4; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 107 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 108 | public static final float RADIUS = 4.0f; |
| 109 | |
| 110 | public static final int SCREEN_WIDTH_PX = 480; |
| 111 | public static final int SCREEN_HEIGHT_PX = 854; |
| 112 | |
| 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; |
| 121 | public static final float FAR_ICON_SIZE |
| 122 | = farSize(2 * ICON_WIDTH_PX / (float)SCREEN_WIDTH_PX); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 123 | } |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 124 | |
| 125 | public AllAppsView(Context context, AttributeSet attrs) { |
| 126 | super(context, attrs); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 127 | setFocusable(true); |
| 128 | getHolder().setFormat(PixelFormat.TRANSLUCENT); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 129 | mConfig = ViewConfiguration.get(context); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 130 | setOnClickListener(this); |
| 131 | setOnLongClickListener(this); |
Dianne Hackborn | e52a1b5 | 2009-09-30 22:36:20 -0700 | [diff] [blame^] | 132 | setZOrderOnTop(true); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 133 | getHolder().setFormat(PixelFormat.TRANSLUCENT); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 136 | public AllAppsView(Context context, AttributeSet attrs, int defStyle) { |
| 137 | this(context, attrs); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 140 | public void setLauncher(Launcher launcher) { |
| 141 | mLauncher = launcher; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 144 | @Override |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 145 | public void surfaceDestroyed(SurfaceHolder holder) { |
| 146 | super.surfaceDestroyed(holder); |
| 147 | |
| 148 | destroyRenderScript(); |
| 149 | mRS = null; |
| 150 | mRollo = null; |
| 151 | } |
| 152 | |
| 153 | @Override |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 154 | public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { |
| 155 | super.surfaceChanged(holder, format, w, h); |
| 156 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 157 | long startTime = SystemClock.uptimeMillis(); |
| 158 | |
Jason Sams | 05de32a | 2009-09-27 14:01:40 -0700 | [diff] [blame] | 159 | mRS = createRenderScript(true); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 160 | mRollo = new RolloRS(); |
| 161 | mRollo.init(getResources(), w, h); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 162 | if (mAllAppsList != null) { |
| 163 | mRollo.setApps(mAllAppsList); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 164 | Log.d(TAG, "surfaceChanged... calling mRollo.setApps"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 165 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 166 | |
| 167 | Resources res = getContext().getResources(); |
| 168 | int barHeight = (int)res.getDimension(R.dimen.button_bar_height); |
| 169 | mScrollHandleTop = h - barHeight; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 170 | |
| 171 | long endTime = SystemClock.uptimeMillis(); |
| 172 | Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms"); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public boolean onKeyDown(int keyCode, KeyEvent event) |
| 177 | { |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 178 | // this method doesn't work when 'extends View' include 'extends ScrollView'. |
| 179 | return super.onKeyDown(keyCode, event); |
| 180 | } |
| 181 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 182 | @Override |
| 183 | public boolean onTouchEvent(MotionEvent ev) |
| 184 | { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 185 | if (!isVisible()) { |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 186 | return true; |
Joe Onorato | e3406a2 | 2009-09-03 14:36:25 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 189 | if (mLocks != 0) { |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 190 | return true; |
| 191 | } |
| 192 | |
| 193 | super.onTouchEvent(ev); |
| 194 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 195 | int x = (int)ev.getX(); |
| 196 | int deltaX; |
| 197 | switch (ev.getAction()) { |
| 198 | case MotionEvent.ACTION_DOWN: |
| 199 | mMotionDownRawX = (int)ev.getRawX(); |
| 200 | mMotionDownRawY = (int)ev.getRawY(); |
| 201 | mLastMotionX = x; |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 202 | mRollo.mReadback.read(); |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 203 | |
| 204 | mRollo.mState.newPositionX = ev.getRawX() / Defines.SCREEN_WIDTH_PX; |
| 205 | mRollo.mState.newTouchDown = 1; |
| 206 | |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 207 | if (!mRollo.checkClickOK()) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 208 | mRollo.clearSelectedIcon(); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 209 | } else { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 210 | mRollo.selectIcon(x, (int)ev.getY(), mRollo.mReadback.posX); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 211 | } |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 212 | mRollo.mState.save(); |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 213 | mRollo.mInvokeMove.execute(); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 214 | mVelocity = VelocityTracker.obtain(); |
| 215 | mVelocity.addMovement(ev); |
| 216 | mStartedScrolling = false; |
| 217 | break; |
| 218 | case MotionEvent.ACTION_MOVE: |
| 219 | case MotionEvent.ACTION_OUTSIDE: |
| 220 | int slop = Math.abs(x - mLastMotionX); |
| 221 | if (!mStartedScrolling && slop < mConfig.getScaledTouchSlop()) { |
| 222 | // don't update mLastMotionX so slop is right and when we do start scrolling |
| 223 | // below, we get the right delta. |
| 224 | } else { |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 225 | |
| 226 | mRollo.mState.newPositionX = ev.getRawX() / Defines.SCREEN_WIDTH_PX; |
| 227 | mRollo.mState.newTouchDown = 1; |
| 228 | mRollo.mInvokeMove.execute(); |
| 229 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 230 | mStartedScrolling = true; |
| 231 | mRollo.clearSelectedIcon(); |
| 232 | deltaX = x - mLastMotionX; |
| 233 | mVelocity.addMovement(ev); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 234 | mRollo.mState.save(); |
| 235 | mLastMotionX = x; |
| 236 | } |
| 237 | break; |
| 238 | case MotionEvent.ACTION_UP: |
| 239 | case MotionEvent.ACTION_CANCEL: |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 240 | mRollo.mState.newTouchDown = 0; |
| 241 | mRollo.mState.newPositionX = ev.getRawX() / Defines.SCREEN_WIDTH_PX; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 242 | |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 243 | if (!mZoomSwipeInProgress) { |
Joe Onorato | 360d035 | 2009-09-28 14:37:53 -0400 | [diff] [blame] | 244 | mVelocity.computeCurrentVelocity(1000 /* px/sec */, |
| 245 | mConfig.getScaledMaximumFlingVelocity()); |
| 246 | mRollo.mState.flingVelocityX = mVelocity.getXVelocity() / Defines.SCREEN_WIDTH_PX; |
| 247 | mRollo.clearSelectedIcon(); |
| 248 | mRollo.mState.save(); |
| 249 | mRollo.mInvokeFling.execute(); |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 250 | } else { |
| 251 | mRollo.mState.save(); |
| 252 | mRollo.mInvokeMove.execute(); |
Joe Onorato | 360d035 | 2009-09-28 14:37:53 -0400 | [diff] [blame] | 253 | } |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 254 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 255 | mLastMotionX = -10000; |
| 256 | mVelocity.recycle(); |
| 257 | mVelocity = null; |
| 258 | break; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 259 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 260 | |
| 261 | return true; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 264 | public void onClick(View v) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 265 | if (mLocks != 0 || !isVisible()) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 266 | return; |
| 267 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 268 | int index = mRollo.mState.selectedIconIndex; |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 269 | if (mRollo.checkClickOK() && index >= 0 && index < mAllAppsList.size()) { |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 270 | ApplicationInfo app = mAllAppsList.get(index); |
| 271 | mLauncher.startActivitySafely(app.intent); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | public boolean onLongClick(View v) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 276 | if (mLocks != 0 || !isVisible()) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 277 | return true; |
| 278 | } |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 279 | int index = mRollo.mState.selectedIconIndex; |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 280 | Log.d(TAG, "long click! velocity=" + mRollo.mReadback.velocity + " index=" + index); |
| 281 | if (mRollo.checkClickOK() && index >= 0 && index < mAllAppsList.size()) { |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 282 | ApplicationInfo app = mAllAppsList.get(index); |
| 283 | |
| 284 | // We don't really have an accurate location to use. This will do. |
| 285 | int screenX = mMotionDownRawX - (Defines.ICON_WIDTH_PX / 2); |
| 286 | int screenY = mMotionDownRawY - Defines.ICON_HEIGHT_PX; |
| 287 | |
| 288 | int left = (Defines.ICON_TEXTURE_WIDTH_PX - Defines.ICON_WIDTH_PX) / 2; |
| 289 | int top = (Defines.ICON_TEXTURE_HEIGHT_PX - Defines.ICON_HEIGHT_PX) / 2; |
| 290 | mDragController.startDrag(app.iconBitmap, screenX, screenY, |
| 291 | left, top, Defines.ICON_WIDTH_PX, Defines.ICON_HEIGHT_PX, |
| 292 | this, app, DragController.DRAG_ACTION_COPY); |
Joe Onorato | e3406a2 | 2009-09-03 14:36:25 -0700 | [diff] [blame] | 293 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 294 | mLauncher.closeAllApps(true); |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 295 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 296 | return true; |
| 297 | } |
| 298 | |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 299 | public void setDragController(DragController dragger) { |
| 300 | mDragController = dragger; |
| 301 | } |
| 302 | |
| 303 | public void onDropCompleted(View target, boolean success) { |
| 304 | } |
| 305 | |
Joe Onorato | 360d035 | 2009-09-28 14:37:53 -0400 | [diff] [blame] | 306 | public void setZoomSwipeInProgress(boolean swiping, boolean touchStillDown) { |
| 307 | mZoomSwipeInProgress = swiping; |
| 308 | if (!touchStillDown) { |
| 309 | mRollo.mState.newTouchDown = 0; |
| 310 | mRollo.mState.save(); |
| 311 | mRollo.mInvokeTouchUp.execute(); |
| 312 | } |
| 313 | } |
| 314 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 315 | public void setZoomTarget(float amount) { |
| 316 | zoom(amount, true); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 319 | public void setZoom(float amount) { |
| 320 | zoom(amount, false); |
| 321 | } |
| 322 | |
| 323 | private void zoom(float amount, boolean animate) { |
| 324 | if (mRollo == null) { |
| 325 | return; |
| 326 | } |
| 327 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 328 | cancelLongPress(); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 329 | mRollo.clearSelectedIcon(); |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 330 | if (amount > 0.001f) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 331 | mRollo.mState.zoomTarget = amount; |
| 332 | if (!animate) { |
| 333 | // set in readback, so we're correct even before the next frame |
| 334 | mRollo.mReadback.zoom = mRollo.mState.zoom = amount; |
| 335 | mRollo.mReadback.save(); |
| 336 | } |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 337 | } else { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 338 | mRollo.mState.zoomTarget = 0; |
| 339 | if (!animate) { |
| 340 | mRollo.mReadback.zoom = mRollo.mState.zoom = 0; |
| 341 | mRollo.mReadback.save(); |
| 342 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 343 | } |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 344 | mRollo.mState.save(); |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 345 | if (!animate) { |
| 346 | mRollo.mInvokeSetZoom.execute(); |
| 347 | } else { |
| 348 | mRollo.mInvokeSetZoomTarget.execute(); |
| 349 | } |
Joe Onorato | 8e099e2 | 2009-09-25 17:30:47 -0700 | [diff] [blame] | 350 | mReadZoom.removeMessages(1); |
| 351 | mReadZoom.sendEmptyMessageDelayed(1, 1000); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 352 | } |
| 353 | |
Joe Onorato | 8e099e2 | 2009-09-25 17:30:47 -0700 | [diff] [blame] | 354 | Handler mReadZoom = new Handler() { |
| 355 | public void handleMessage(Message msg) { |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 356 | if(mRollo != null && mRollo.mReadback != null) { |
| 357 | // FIXME: These checks may indicate other problems. |
| 358 | mRollo.mReadback.read(); |
| 359 | } |
Joe Onorato | 8e099e2 | 2009-09-25 17:30:47 -0700 | [diff] [blame] | 360 | } |
| 361 | }; |
| 362 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 363 | public boolean isVisible() { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 364 | if (mRollo == null) { |
| 365 | return false; |
| 366 | } |
Joe Onorato | 8e099e2 | 2009-09-25 17:30:47 -0700 | [diff] [blame] | 367 | //mRollo.mReadback.read(); |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 368 | return mRollo.mReadback.zoom > 0.001f; |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 369 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 370 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 371 | @Override |
| 372 | public boolean onTrackballEvent(MotionEvent ev) |
| 373 | { |
| 374 | float x = ev.getX(); |
| 375 | float y = ev.getY(); |
| 376 | //Float tx = new Float(x); |
| 377 | //Float ty = new Float(y); |
| 378 | //Log.e("rs", "tbe " + tx.toString() + ", " + ty.toString()); |
| 379 | |
| 380 | |
| 381 | return true; |
| 382 | } |
| 383 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 384 | public void setApps(ArrayList<ApplicationInfo> list) { |
| 385 | mAllAppsList = list; |
| 386 | if (mRollo != null) { |
| 387 | mRollo.setApps(list); |
| 388 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 389 | mPageCount = countPages(list.size()); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 390 | Log.d(TAG, "setApps mRollo=" + mRollo + " list=" + list); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 391 | mLocks &= ~LOCK_ICONS_PENDING; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | private void invokeIcon(int index) { |
| 395 | Log.d(TAG, "launch it!!!! index=" + index); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | private static int countPages(int iconCount) { |
| 399 | int iconsPerPage = Defines.COLUMNS_PER_PAGE * Defines.ROWS_PER_PAGE; |
| 400 | int pages = iconCount / iconsPerPage; |
| 401 | if (pages*iconsPerPage != iconCount) { |
| 402 | pages++; |
| 403 | } |
| 404 | return pages; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 405 | } |
| 406 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 407 | public class RolloRS { |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 408 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 409 | // Allocations ====== |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 410 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 411 | private int mWidth; |
| 412 | private int mHeight; |
| 413 | |
| 414 | private Resources mRes; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 415 | private Script mScript; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 416 | |
| 417 | private Script.Invokable mInvokeMove; |
| 418 | private Script.Invokable mInvokeFling; |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 419 | private Script.Invokable mInvokeSetZoomTarget; |
| 420 | private Script.Invokable mInvokeSetZoom; |
Joe Onorato | 360d035 | 2009-09-28 14:37:53 -0400 | [diff] [blame] | 421 | private Script.Invokable mInvokeTouchUp; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 422 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 423 | private ProgramStore mPSIcons; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 424 | private ProgramStore mPSText; |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 425 | private ProgramFragment mPFColor; |
| 426 | private ProgramFragment mPFTexLinear; |
| 427 | private ProgramFragment mPFTexNearest; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 428 | private ProgramVertex mPV; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 429 | private ProgramVertex mPVOrtho; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 430 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 431 | private Allocation mScrollHandle; |
| 432 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 433 | private Allocation[] mIcons; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 434 | private int[] mIconIds; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 435 | private Allocation mAllocIconID; |
| 436 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 437 | private Allocation[] mLabels; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 438 | private int[] mLabelIds; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 439 | private Allocation mAllocLabelID; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 440 | private Allocation mSelectedIcon; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 441 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 442 | private int[] mTouchYBorders; |
| 443 | private Allocation mAllocTouchYBorders; |
| 444 | private int[] mTouchXBorders; |
| 445 | private Allocation mAllocTouchXBorders; |
| 446 | |
| 447 | private Bitmap mSelectionBitmap; |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 448 | private Canvas mSelectionCanvas; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 449 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 450 | Params mParams; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 451 | State mState; |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 452 | Readback mReadback; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 453 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 454 | class BaseAlloc { |
| 455 | Allocation mAlloc; |
| 456 | Type mType; |
| 457 | |
| 458 | void save() { |
| 459 | mAlloc.data(this); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 460 | } |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 463 | private boolean checkClickOK() { |
| 464 | //android.util.Log.e("rs", "check click " + Float.toString(mReadback.velocity) + ", " + Float.toString(mReadback.posX)); |
| 465 | return (Math.abs(mReadback.velocity) < 0.1f) && |
| 466 | (Math.abs(mReadback.posX - Math.round(mReadback.posX)) < 0.1f); |
| 467 | } |
| 468 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 469 | class Params extends BaseAlloc { |
| 470 | Params() { |
| 471 | mType = Type.createFromClass(mRS, Params.class, 1, "ParamsClass"); |
| 472 | mAlloc = Allocation.createTyped(mRS, mType); |
| 473 | save(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 474 | } |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 475 | public int bubbleWidth; |
| 476 | public int bubbleHeight; |
| 477 | public int bubbleBitmapWidth; |
| 478 | public int bubbleBitmapHeight; |
| 479 | public int scrollHandleId; |
| 480 | public int scrollHandleTextureWidth; |
| 481 | public int scrollHandleTextureHeight; |
| 482 | } |
| 483 | |
| 484 | class State extends BaseAlloc { |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 485 | public float newPositionX; |
| 486 | public int newTouchDown; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 487 | public float flingVelocityX; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 488 | public int iconCount; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 489 | public int selectedIconIndex = -1; |
| 490 | public int selectedIconTexture; |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 491 | public float zoomTarget; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 492 | public float zoom; |
| 493 | |
| 494 | State() { |
| 495 | mType = Type.createFromClass(mRS, State.class, 1, "StateClass"); |
| 496 | mAlloc = Allocation.createTyped(mRS, mType); |
| 497 | save(); |
| 498 | } |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 501 | class Readback extends BaseAlloc { |
| 502 | public float posX; |
| 503 | public float velocity; |
| 504 | public float zoom; |
| 505 | |
| 506 | Readback() { |
| 507 | mType = Type.createFromClass(mRS, Readback.class, 1, "ReadbackClass"); |
| 508 | mAlloc = Allocation.createTyped(mRS, mType); |
| 509 | save(); |
| 510 | } |
| 511 | |
| 512 | void read() { |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 513 | if(mAlloc != null) { |
| 514 | mAlloc.read(this); |
| 515 | } |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 519 | public RolloRS() { |
| 520 | } |
| 521 | |
| 522 | public void init(Resources res, int width, int height) { |
| 523 | mRes = res; |
| 524 | mWidth = width; |
| 525 | mHeight = height; |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 526 | initProgramVertex(); |
| 527 | initProgramFragment(); |
| 528 | initProgramStore(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 529 | initGl(); |
| 530 | initData(); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 531 | initTouchState(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 532 | initRs(); |
| 533 | } |
| 534 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 535 | private void initProgramVertex() { |
| 536 | ProgramVertex.MatrixAllocation pva = new ProgramVertex.MatrixAllocation(mRS); |
| 537 | pva.setupProjectionNormalized(mWidth, mHeight); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 538 | |
| 539 | ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null); |
| 540 | mPV = pvb.create(); |
| 541 | mPV.setName("PV"); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 542 | mPV.bindAllocation(pva); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 543 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 544 | pva = new ProgramVertex.MatrixAllocation(mRS); |
| 545 | pva.setupOrthoWindow(mWidth, mHeight); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 546 | pvb.setTextureMatrixEnable(true); |
| 547 | mPVOrtho = pvb.create(); |
| 548 | mPVOrtho.setName("PVOrtho"); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 549 | mPVOrtho.bindAllocation(pva); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 550 | |
| 551 | mRS.contextBindProgramVertex(mPV); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 552 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 553 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 554 | private void initProgramFragment() { |
| 555 | Sampler.Builder sb = new Sampler.Builder(mRS); |
| 556 | sb.setMin(Sampler.Value.LINEAR); |
| 557 | sb.setMag(Sampler.Value.LINEAR); |
| 558 | sb.setWrapS(Sampler.Value.CLAMP); |
| 559 | sb.setWrapT(Sampler.Value.CLAMP); |
| 560 | Sampler linear = sb.create(); |
| 561 | |
| 562 | sb.setMin(Sampler.Value.NEAREST); |
| 563 | sb.setMag(Sampler.Value.NEAREST); |
| 564 | Sampler nearest = sb.create(); |
| 565 | |
| 566 | ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null); |
| 567 | mPFColor = bf.create(); |
| 568 | mPFColor.setName("PFColor"); |
| 569 | |
| 570 | bf.setTexEnable(true, 0); |
| 571 | bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0); |
| 572 | mPFTexLinear = bf.create(); |
| 573 | mPFTexLinear.setName("PFTexLinear"); |
| 574 | mPFTexLinear.bindSampler(linear, 0); |
| 575 | |
| 576 | mPFTexNearest = bf.create(); |
| 577 | mPFTexNearest.setName("PFTexNearest"); |
| 578 | mPFTexNearest.bindSampler(nearest, 0); |
| 579 | } |
| 580 | |
| 581 | private void initProgramStore() { |
| 582 | ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null); |
| 583 | bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); |
| 584 | bs.setDitherEnable(true); |
| 585 | bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, |
| 586 | ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA); |
| 587 | mPSIcons = bs.create(); |
| 588 | mPSIcons.setName("PSIcons"); |
| 589 | |
| 590 | //bs.setDitherEnable(false); |
| 591 | //mPSText = bs.create(); |
| 592 | //mPSText.setName("PSText"); |
| 593 | } |
| 594 | |
| 595 | private void initGl() { |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 596 | mTouchXBorders = new int[Defines.COLUMNS_PER_PAGE+1]; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 597 | mAllocTouchXBorders = Allocation.createSized(mRS, Element.USER_I32(mRS), |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 598 | mTouchXBorders.length); |
| 599 | mAllocTouchXBorders.data(mTouchXBorders); |
| 600 | |
| 601 | mTouchYBorders = new int[Defines.ROWS_PER_PAGE+1]; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 602 | mAllocTouchYBorders = Allocation.createSized(mRS, Element.USER_I32(mRS), |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 603 | mTouchYBorders.length); |
| 604 | mAllocTouchYBorders.data(mTouchYBorders); |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 605 | } |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 606 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 607 | private void initData() { |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 608 | mParams = new Params(); |
| 609 | mState = new State(); |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 610 | mReadback = new Readback(); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 611 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 612 | final Utilities.BubbleText bubble = new Utilities.BubbleText(getContext()); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 613 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 614 | mParams.bubbleWidth = bubble.getBubbleWidth(); |
| 615 | mParams.bubbleHeight = bubble.getMaxBubbleHeight(); |
| 616 | mParams.bubbleBitmapWidth = bubble.getBitmapWidth(); |
| 617 | mParams.bubbleBitmapHeight = bubble.getBitmapHeight(); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 618 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 619 | mScrollHandle = Allocation.createFromBitmapResource(mRS, mRes, |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 620 | R.drawable.all_apps_button_pow2, Element.RGBA_8888(mRS), false); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 621 | mScrollHandle.uploadToTexture(0); |
| 622 | mParams.scrollHandleId = mScrollHandle.getID(); |
| 623 | Log.d(TAG, "mParams.scrollHandleId=" + mParams.scrollHandleId); |
| 624 | mParams.scrollHandleTextureWidth = 128; |
| 625 | mParams.scrollHandleTextureHeight = 128; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 626 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 627 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 628 | mParams.save(); |
| 629 | mState.save(); |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 630 | mReadback.save(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 631 | |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 632 | mSelectionBitmap = Bitmap.createBitmap(Defines.ICON_TEXTURE_WIDTH_PX, |
| 633 | Defines.ICON_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888); |
| 634 | mSelectionCanvas = new Canvas(mSelectionBitmap); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 635 | |
| 636 | Log.d(TAG, "initData calling mRollo.setApps"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 637 | setApps(null); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 638 | } |
| 639 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 640 | private void initRs() { |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 641 | ScriptC.Builder sb = new ScriptC.Builder(mRS); |
| 642 | sb.setScript(mRes, R.raw.rollo); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 643 | sb.setRoot(true); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 644 | sb.addDefines(Defines.class); |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 645 | sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS); |
| 646 | sb.setType(mState.mType, "state", Defines.ALLOC_STATE); |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 647 | sb.setType(mReadback.mType, "readback", Defines.ALLOC_READBACK); |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 648 | mInvokeMove = sb.addInvokable("move"); |
| 649 | mInvokeFling = sb.addInvokable("fling"); |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 650 | mInvokeSetZoomTarget = sb.addInvokable("setZoomTarget"); |
| 651 | mInvokeSetZoom = sb.addInvokable("setZoom"); |
Joe Onorato | 360d035 | 2009-09-28 14:37:53 -0400 | [diff] [blame] | 652 | mInvokeTouchUp = sb.addInvokable("touchUp"); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 653 | mScript = sb.create(); |
| 654 | mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 655 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 656 | mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS); |
| 657 | mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE); |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 658 | mScript.bindAllocation(mReadback.mAlloc, Defines.ALLOC_READBACK); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 659 | mScript.bindAllocation(mAllocIconID, Defines.ALLOC_ICON_IDS); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 660 | mScript.bindAllocation(mAllocLabelID, Defines.ALLOC_LABEL_IDS); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 661 | mScript.bindAllocation(mAllocTouchXBorders, Defines.ALLOC_X_BORDERS); |
| 662 | mScript.bindAllocation(mAllocTouchYBorders, Defines.ALLOC_Y_BORDERS); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 663 | |
| 664 | mRS.contextBindRootScript(mScript); |
| 665 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 666 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 667 | private void setApps(ArrayList<ApplicationInfo> list) { |
| 668 | final int count = list != null ? list.size() : 0; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 669 | int allocCount = count; |
| 670 | if(allocCount < 1) { |
| 671 | allocCount = 1; |
| 672 | } |
| 673 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 674 | mIcons = new Allocation[count]; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 675 | mIconIds = new int[allocCount]; |
| 676 | mAllocIconID = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 677 | |
| 678 | mLabels = new Allocation[count]; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 679 | mLabelIds = new int[allocCount]; |
| 680 | mAllocLabelID = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 681 | |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 682 | Element ie8888 = Element.RGBA_8888(mRS); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 683 | |
| 684 | Utilities.BubbleText bubble = new Utilities.BubbleText(getContext()); |
| 685 | |
| 686 | for (int i=0; i<count; i++) { |
| 687 | final ApplicationInfo item = list.get(i); |
| 688 | |
| 689 | mIcons[i] = Allocation.createFromBitmap(mRS, item.iconBitmap, |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 690 | Element.RGBA_8888(mRS), false); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 691 | mLabels[i] = Allocation.createFromBitmap(mRS, item.titleBitmap, |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 692 | Element.RGBA_8888(mRS), false); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 693 | |
| 694 | mIcons[i].uploadToTexture(0); |
| 695 | mLabels[i].uploadToTexture(0); |
| 696 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 697 | mIconIds[i] = mIcons[i].getID(); |
| 698 | mLabelIds[i] = mLabels[i].getID(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 699 | } |
| 700 | |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 701 | mAllocIconID.data(mIconIds); |
| 702 | mAllocLabelID.data(mLabelIds); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 703 | |
| 704 | mState.iconCount = count; |
| 705 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 706 | if (mScript != null) { // wtf |
| 707 | mScript.bindAllocation(mAllocIconID, Defines.ALLOC_ICON_IDS); |
| 708 | mScript.bindAllocation(mAllocLabelID, Defines.ALLOC_LABEL_IDS); |
| 709 | } |
| 710 | |
| 711 | mState.save(); |
| 712 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 713 | |
| 714 | void initTouchState() { |
| 715 | int width = getWidth(); |
| 716 | int height = getHeight(); |
| 717 | |
| 718 | int iconsSize; |
| 719 | if (width < height) { |
| 720 | iconsSize = width; |
| 721 | } else { |
| 722 | iconsSize = height; |
| 723 | } |
| 724 | int cellHeight = iconsSize / Defines.ROWS_PER_PAGE; |
| 725 | int cellWidth = iconsSize / Defines.COLUMNS_PER_PAGE; |
| 726 | |
Joe Onorato | 56848b0 | 2009-09-25 13:59:59 -0700 | [diff] [blame] | 727 | int centerY = (height / 2) - (int)(cellHeight * 0.2f); |
| 728 | mTouchYBorders[0] = centerY - (int)(2.8f * cellHeight); |
| 729 | mTouchYBorders[1] = centerY - (int)(1.25f * cellHeight); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 730 | mTouchYBorders[2] = centerY; |
Joe Onorato | 56848b0 | 2009-09-25 13:59:59 -0700 | [diff] [blame] | 731 | mTouchYBorders[3] = centerY + (int)(1.25f * cellHeight);; |
| 732 | mTouchYBorders[4] = centerY + (int)(2.6f * cellHeight); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 733 | |
| 734 | mAllocTouchYBorders.data(mTouchYBorders); |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 735 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 736 | int centerX = (width / 2); |
| 737 | mTouchXBorders[0] = centerX - (2 * cellWidth); |
Joe Onorato | 56848b0 | 2009-09-25 13:59:59 -0700 | [diff] [blame] | 738 | mTouchXBorders[1] = centerX - (int)(0.85f * cellWidth); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 739 | mTouchXBorders[2] = centerX; |
Joe Onorato | 56848b0 | 2009-09-25 13:59:59 -0700 | [diff] [blame] | 740 | mTouchXBorders[3] = centerX + (int)(0.85f * cellWidth); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 741 | mTouchXBorders[4] = centerX + (2 * cellWidth); |
| 742 | |
| 743 | mAllocTouchXBorders.data(mTouchXBorders); |
| 744 | } |
| 745 | |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 746 | int chooseTappedIcon(int x, int y, float page) { |
| 747 | int currentPage = (int)page; |
| 748 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 749 | int col = -1; |
| 750 | int row = -1; |
| 751 | |
| 752 | for (int i=0; i<Defines.COLUMNS_PER_PAGE; i++) { |
| 753 | if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) { |
| 754 | col = i; |
| 755 | break; |
| 756 | } |
| 757 | } |
| 758 | for (int i=0; i<Defines.ROWS_PER_PAGE; i++) { |
| 759 | if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) { |
| 760 | row = i; |
| 761 | break; |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | if (row < 0 || col < 0) { |
| 766 | return -1; |
| 767 | } |
| 768 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 769 | return (currentPage * Defines.ROWS_PER_PAGE * Defines.COLUMNS_PER_PAGE) |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 770 | + (row * Defines.ROWS_PER_PAGE) + col; |
| 771 | } |
| 772 | |
| 773 | /** |
| 774 | * You need to call save() on mState on your own after calling this. |
| 775 | */ |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 776 | void selectIcon(int x, int y, float pos) { |
| 777 | int index = chooseTappedIcon(x, y, pos); |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 778 | selectIcon(index); |
| 779 | } |
| 780 | |
| 781 | void selectIcon(int index) { |
| 782 | Log.d(TAG, "selectIcon index=" + index); |
| 783 | int iconCount = mAllAppsList.size(); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 784 | if (index < 0 || index >= iconCount) { |
| 785 | mState.selectedIconIndex = -1; |
| 786 | return; |
| 787 | } else { |
| 788 | mState.selectedIconIndex = index; |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 789 | |
| 790 | Bitmap selectionBitmap = mSelectionBitmap; |
| 791 | |
| 792 | Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas, |
| 793 | selectionBitmap.getWidth(), selectionBitmap.getHeight(), |
| 794 | mAllAppsList.get(index).iconBitmap); |
| 795 | |
| 796 | mSelectedIcon = Allocation.createFromBitmap(mRS, selectionBitmap, |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 797 | Element.RGBA_8888(mRS), false); |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 798 | mSelectedIcon.uploadToTexture(0); |
| 799 | mState.selectedIconTexture = mSelectedIcon.getID(); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 800 | } |
| 801 | } |
| 802 | |
| 803 | /** |
| 804 | * You need to call save() on mState on your own after calling this. |
| 805 | */ |
| 806 | void clearSelectedIcon() { |
Joe Onorato | 2ca51dc | 2009-09-16 11:44:14 -0400 | [diff] [blame] | 807 | mState.selectedIconIndex = -1; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 808 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 809 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | |