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 | b8898d5 | 2009-09-14 22:30:18 -0700 | [diff] [blame] | 132 | setOnTop(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 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 207 | if (mRollo.mReadback.velocity != 0) { |
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: |
Joe Onorato | 360d035 | 2009-09-28 14:37:53 -0400 | [diff] [blame] | 240 | if (!mZoomSwipeInProgress) { |
| 241 | mRollo.mState.newPositionX = ev.getRawX() / Defines.SCREEN_WIDTH_PX; |
| 242 | mRollo.mState.newTouchDown = 0; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 243 | |
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(); |
| 250 | } |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 251 | mLastMotionX = -10000; |
| 252 | mVelocity.recycle(); |
| 253 | mVelocity = null; |
| 254 | break; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 255 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 256 | |
| 257 | return true; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 260 | public void onClick(View v) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 261 | if (mLocks != 0 || !isVisible()) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 262 | return; |
| 263 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 264 | int index = mRollo.mState.selectedIconIndex; |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame^] | 265 | if (mRollo.mReadback.velocity < 1 && index >= 0 && index < mAllAppsList.size()) { |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 266 | ApplicationInfo app = mAllAppsList.get(index); |
| 267 | mLauncher.startActivitySafely(app.intent); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | public boolean onLongClick(View v) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 272 | if (mLocks != 0 || !isVisible()) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 273 | return true; |
| 274 | } |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 275 | int index = mRollo.mState.selectedIconIndex; |
| 276 | Log.d(TAG, "long click! velocity=" + mRollo.mState.flingVelocityX + " index=" + index); |
| 277 | if (mRollo.mState.flingVelocityX == 0 && index >= 0 && index < mAllAppsList.size()) { |
| 278 | ApplicationInfo app = mAllAppsList.get(index); |
| 279 | |
| 280 | // We don't really have an accurate location to use. This will do. |
| 281 | int screenX = mMotionDownRawX - (Defines.ICON_WIDTH_PX / 2); |
| 282 | int screenY = mMotionDownRawY - Defines.ICON_HEIGHT_PX; |
| 283 | |
| 284 | int left = (Defines.ICON_TEXTURE_WIDTH_PX - Defines.ICON_WIDTH_PX) / 2; |
| 285 | int top = (Defines.ICON_TEXTURE_HEIGHT_PX - Defines.ICON_HEIGHT_PX) / 2; |
| 286 | mDragController.startDrag(app.iconBitmap, screenX, screenY, |
| 287 | left, top, Defines.ICON_WIDTH_PX, Defines.ICON_HEIGHT_PX, |
| 288 | this, app, DragController.DRAG_ACTION_COPY); |
Joe Onorato | e3406a2 | 2009-09-03 14:36:25 -0700 | [diff] [blame] | 289 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 290 | mLauncher.closeAllApps(true); |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 291 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 292 | return true; |
| 293 | } |
| 294 | |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 295 | public void setDragController(DragController dragger) { |
| 296 | mDragController = dragger; |
| 297 | } |
| 298 | |
| 299 | public void onDropCompleted(View target, boolean success) { |
| 300 | } |
| 301 | |
Joe Onorato | 360d035 | 2009-09-28 14:37:53 -0400 | [diff] [blame] | 302 | public void setZoomSwipeInProgress(boolean swiping, boolean touchStillDown) { |
| 303 | mZoomSwipeInProgress = swiping; |
| 304 | if (!touchStillDown) { |
| 305 | mRollo.mState.newTouchDown = 0; |
| 306 | mRollo.mState.save(); |
| 307 | mRollo.mInvokeTouchUp.execute(); |
| 308 | } |
| 309 | } |
| 310 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 311 | public void setZoomTarget(float amount) { |
| 312 | zoom(amount, true); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 315 | public void setZoom(float amount) { |
| 316 | zoom(amount, false); |
| 317 | } |
| 318 | |
| 319 | private void zoom(float amount, boolean animate) { |
| 320 | if (mRollo == null) { |
| 321 | return; |
| 322 | } |
| 323 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 324 | cancelLongPress(); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 325 | mRollo.clearSelectedIcon(); |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 326 | if (amount > 0.001f) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 327 | mRollo.mState.zoomTarget = amount; |
| 328 | if (!animate) { |
| 329 | // set in readback, so we're correct even before the next frame |
| 330 | mRollo.mReadback.zoom = mRollo.mState.zoom = amount; |
| 331 | mRollo.mReadback.save(); |
| 332 | } |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 333 | } else { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 334 | mRollo.mState.zoomTarget = 0; |
| 335 | if (!animate) { |
| 336 | mRollo.mReadback.zoom = mRollo.mState.zoom = 0; |
| 337 | mRollo.mReadback.save(); |
| 338 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 339 | } |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 340 | mRollo.mState.save(); |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 341 | if (!animate) { |
| 342 | mRollo.mInvokeSetZoom.execute(); |
| 343 | } else { |
| 344 | mRollo.mInvokeSetZoomTarget.execute(); |
| 345 | } |
Joe Onorato | 8e099e2 | 2009-09-25 17:30:47 -0700 | [diff] [blame] | 346 | mReadZoom.removeMessages(1); |
| 347 | mReadZoom.sendEmptyMessageDelayed(1, 1000); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 348 | } |
| 349 | |
Joe Onorato | 8e099e2 | 2009-09-25 17:30:47 -0700 | [diff] [blame] | 350 | Handler mReadZoom = new Handler() { |
| 351 | public void handleMessage(Message msg) { |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 352 | if(mRollo != null && mRollo.mReadback != null) { |
| 353 | // FIXME: These checks may indicate other problems. |
| 354 | mRollo.mReadback.read(); |
| 355 | } |
Joe Onorato | 8e099e2 | 2009-09-25 17:30:47 -0700 | [diff] [blame] | 356 | } |
| 357 | }; |
| 358 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 359 | public boolean isVisible() { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 360 | if (mRollo == null) { |
| 361 | return false; |
| 362 | } |
Joe Onorato | 8e099e2 | 2009-09-25 17:30:47 -0700 | [diff] [blame] | 363 | //mRollo.mReadback.read(); |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 364 | return mRollo.mReadback.zoom > 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 | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 386 | Log.d(TAG, "setApps mRollo=" + mRollo + " list=" + list); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 387 | mLocks &= ~LOCK_ICONS_PENDING; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | private void invokeIcon(int index) { |
| 391 | Log.d(TAG, "launch it!!!! index=" + index); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | private static int countPages(int iconCount) { |
| 395 | int iconsPerPage = Defines.COLUMNS_PER_PAGE * Defines.ROWS_PER_PAGE; |
| 396 | int pages = iconCount / iconsPerPage; |
| 397 | if (pages*iconsPerPage != iconCount) { |
| 398 | pages++; |
| 399 | } |
| 400 | return pages; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 401 | } |
| 402 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 403 | public class RolloRS { |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 404 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 405 | // Allocations ====== |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 406 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 407 | private int mWidth; |
| 408 | private int mHeight; |
| 409 | |
| 410 | private Resources mRes; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 411 | private Script mScript; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 412 | |
| 413 | private Script.Invokable mInvokeMove; |
| 414 | private Script.Invokable mInvokeFling; |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 415 | private Script.Invokable mInvokeSetZoomTarget; |
| 416 | private Script.Invokable mInvokeSetZoom; |
Joe Onorato | 360d035 | 2009-09-28 14:37:53 -0400 | [diff] [blame] | 417 | private Script.Invokable mInvokeTouchUp; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 418 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame^] | 419 | private ProgramStore mPSIcons; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 420 | private ProgramStore mPSText; |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame^] | 421 | private ProgramFragment mPFColor; |
| 422 | private ProgramFragment mPFTexLinear; |
| 423 | private ProgramFragment mPFTexNearest; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 424 | private ProgramVertex mPV; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 425 | private ProgramVertex mPVOrtho; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 426 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 427 | private Allocation mScrollHandle; |
| 428 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 429 | private Allocation[] mIcons; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 430 | private int[] mIconIds; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 431 | private Allocation mAllocIconID; |
| 432 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 433 | private Allocation[] mLabels; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 434 | private int[] mLabelIds; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 435 | private Allocation mAllocLabelID; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 436 | private Allocation mSelectedIcon; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 437 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 438 | private int[] mTouchYBorders; |
| 439 | private Allocation mAllocTouchYBorders; |
| 440 | private int[] mTouchXBorders; |
| 441 | private Allocation mAllocTouchXBorders; |
| 442 | |
| 443 | private Bitmap mSelectionBitmap; |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 444 | private Canvas mSelectionCanvas; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 445 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 446 | Params mParams; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 447 | State mState; |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 448 | Readback mReadback; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 449 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 450 | class BaseAlloc { |
| 451 | Allocation mAlloc; |
| 452 | Type mType; |
| 453 | |
| 454 | void save() { |
| 455 | mAlloc.data(this); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 456 | } |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 459 | class Params extends BaseAlloc { |
| 460 | Params() { |
| 461 | mType = Type.createFromClass(mRS, Params.class, 1, "ParamsClass"); |
| 462 | mAlloc = Allocation.createTyped(mRS, mType); |
| 463 | save(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 464 | } |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 465 | public int bubbleWidth; |
| 466 | public int bubbleHeight; |
| 467 | public int bubbleBitmapWidth; |
| 468 | public int bubbleBitmapHeight; |
| 469 | public int scrollHandleId; |
| 470 | public int scrollHandleTextureWidth; |
| 471 | public int scrollHandleTextureHeight; |
| 472 | } |
| 473 | |
| 474 | class State extends BaseAlloc { |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 475 | public float newPositionX; |
| 476 | public int newTouchDown; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 477 | public float flingVelocityX; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 478 | public int iconCount; |
| 479 | public int scrollX; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 480 | public int selectedIconIndex = -1; |
| 481 | public int selectedIconTexture; |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 482 | public float zoomTarget; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 483 | public float zoom; |
| 484 | |
| 485 | State() { |
| 486 | mType = Type.createFromClass(mRS, State.class, 1, "StateClass"); |
| 487 | mAlloc = Allocation.createTyped(mRS, mType); |
| 488 | save(); |
| 489 | } |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 492 | class Readback extends BaseAlloc { |
| 493 | public float posX; |
| 494 | public float velocity; |
| 495 | public float zoom; |
| 496 | |
| 497 | Readback() { |
| 498 | mType = Type.createFromClass(mRS, Readback.class, 1, "ReadbackClass"); |
| 499 | mAlloc = Allocation.createTyped(mRS, mType); |
| 500 | save(); |
| 501 | } |
| 502 | |
| 503 | void read() { |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 504 | if(mAlloc != null) { |
| 505 | mAlloc.read(this); |
| 506 | } |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 507 | } |
| 508 | } |
| 509 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 510 | public RolloRS() { |
| 511 | } |
| 512 | |
| 513 | public void init(Resources res, int width, int height) { |
| 514 | mRes = res; |
| 515 | mWidth = width; |
| 516 | mHeight = height; |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame^] | 517 | initProgramVertex(); |
| 518 | initProgramFragment(); |
| 519 | initProgramStore(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 520 | initGl(); |
| 521 | initData(); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 522 | initTouchState(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 523 | initRs(); |
| 524 | } |
| 525 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame^] | 526 | private void initProgramVertex() { |
| 527 | ProgramVertex.MatrixAllocation pva = new ProgramVertex.MatrixAllocation(mRS); |
| 528 | pva.setupProjectionNormalized(mWidth, mHeight); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 529 | |
| 530 | ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null); |
| 531 | mPV = pvb.create(); |
| 532 | mPV.setName("PV"); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame^] | 533 | mPV.bindAllocation(pva); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 534 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame^] | 535 | pva = new ProgramVertex.MatrixAllocation(mRS); |
| 536 | pva.setupOrthoWindow(mWidth, mHeight); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 537 | pvb.setTextureMatrixEnable(true); |
| 538 | mPVOrtho = pvb.create(); |
| 539 | mPVOrtho.setName("PVOrtho"); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame^] | 540 | mPVOrtho.bindAllocation(pva); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 541 | |
| 542 | mRS.contextBindProgramVertex(mPV); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame^] | 543 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 544 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame^] | 545 | private void initProgramFragment() { |
| 546 | Sampler.Builder sb = new Sampler.Builder(mRS); |
| 547 | sb.setMin(Sampler.Value.LINEAR); |
| 548 | sb.setMag(Sampler.Value.LINEAR); |
| 549 | sb.setWrapS(Sampler.Value.CLAMP); |
| 550 | sb.setWrapT(Sampler.Value.CLAMP); |
| 551 | Sampler linear = sb.create(); |
| 552 | |
| 553 | sb.setMin(Sampler.Value.NEAREST); |
| 554 | sb.setMag(Sampler.Value.NEAREST); |
| 555 | Sampler nearest = sb.create(); |
| 556 | |
| 557 | ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null); |
| 558 | mPFColor = bf.create(); |
| 559 | mPFColor.setName("PFColor"); |
| 560 | |
| 561 | bf.setTexEnable(true, 0); |
| 562 | bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0); |
| 563 | mPFTexLinear = bf.create(); |
| 564 | mPFTexLinear.setName("PFTexLinear"); |
| 565 | mPFTexLinear.bindSampler(linear, 0); |
| 566 | |
| 567 | mPFTexNearest = bf.create(); |
| 568 | mPFTexNearest.setName("PFTexNearest"); |
| 569 | mPFTexNearest.bindSampler(nearest, 0); |
| 570 | } |
| 571 | |
| 572 | private void initProgramStore() { |
| 573 | ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null); |
| 574 | bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); |
| 575 | bs.setDitherEnable(true); |
| 576 | bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, |
| 577 | ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA); |
| 578 | mPSIcons = bs.create(); |
| 579 | mPSIcons.setName("PSIcons"); |
| 580 | |
| 581 | //bs.setDitherEnable(false); |
| 582 | //mPSText = bs.create(); |
| 583 | //mPSText.setName("PSText"); |
| 584 | } |
| 585 | |
| 586 | private void initGl() { |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 587 | mTouchXBorders = new int[Defines.COLUMNS_PER_PAGE+1]; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 588 | mAllocTouchXBorders = Allocation.createSized(mRS, Element.USER_I32(mRS), |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 589 | mTouchXBorders.length); |
| 590 | mAllocTouchXBorders.data(mTouchXBorders); |
| 591 | |
| 592 | mTouchYBorders = new int[Defines.ROWS_PER_PAGE+1]; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 593 | mAllocTouchYBorders = Allocation.createSized(mRS, Element.USER_I32(mRS), |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 594 | mTouchYBorders.length); |
| 595 | mAllocTouchYBorders.data(mTouchYBorders); |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 596 | } |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 597 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 598 | private void initData() { |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 599 | mParams = new Params(); |
| 600 | mState = new State(); |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 601 | mReadback = new Readback(); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 602 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 603 | final Utilities.BubbleText bubble = new Utilities.BubbleText(getContext()); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 604 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 605 | mParams.bubbleWidth = bubble.getBubbleWidth(); |
| 606 | mParams.bubbleHeight = bubble.getMaxBubbleHeight(); |
| 607 | mParams.bubbleBitmapWidth = bubble.getBitmapWidth(); |
| 608 | mParams.bubbleBitmapHeight = bubble.getBitmapHeight(); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 609 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 610 | mScrollHandle = Allocation.createFromBitmapResource(mRS, mRes, |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 611 | R.drawable.all_apps_button_pow2, Element.RGBA_8888(mRS), false); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 612 | mScrollHandle.uploadToTexture(0); |
| 613 | mParams.scrollHandleId = mScrollHandle.getID(); |
| 614 | Log.d(TAG, "mParams.scrollHandleId=" + mParams.scrollHandleId); |
| 615 | mParams.scrollHandleTextureWidth = 128; |
| 616 | mParams.scrollHandleTextureHeight = 128; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 617 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 618 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 619 | mParams.save(); |
| 620 | mState.save(); |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 621 | mReadback.save(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 622 | |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 623 | mSelectionBitmap = Bitmap.createBitmap(Defines.ICON_TEXTURE_WIDTH_PX, |
| 624 | Defines.ICON_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888); |
| 625 | mSelectionCanvas = new Canvas(mSelectionBitmap); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 626 | |
| 627 | Log.d(TAG, "initData calling mRollo.setApps"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 628 | setApps(null); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 631 | private void initRs() { |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 632 | ScriptC.Builder sb = new ScriptC.Builder(mRS); |
| 633 | sb.setScript(mRes, R.raw.rollo); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 634 | sb.setRoot(true); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 635 | sb.addDefines(Defines.class); |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 636 | sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS); |
| 637 | sb.setType(mState.mType, "state", Defines.ALLOC_STATE); |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 638 | sb.setType(mReadback.mType, "readback", Defines.ALLOC_READBACK); |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 639 | mInvokeMove = sb.addInvokable("move"); |
| 640 | mInvokeFling = sb.addInvokable("fling"); |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 641 | mInvokeSetZoomTarget = sb.addInvokable("setZoomTarget"); |
| 642 | mInvokeSetZoom = sb.addInvokable("setZoom"); |
Joe Onorato | 360d035 | 2009-09-28 14:37:53 -0400 | [diff] [blame] | 643 | mInvokeTouchUp = sb.addInvokable("touchUp"); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 644 | mScript = sb.create(); |
| 645 | mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 646 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 647 | mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS); |
| 648 | mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE); |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 649 | mScript.bindAllocation(mReadback.mAlloc, Defines.ALLOC_READBACK); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 650 | mScript.bindAllocation(mAllocIconID, Defines.ALLOC_ICON_IDS); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 651 | mScript.bindAllocation(mAllocLabelID, Defines.ALLOC_LABEL_IDS); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 652 | mScript.bindAllocation(mAllocTouchXBorders, Defines.ALLOC_X_BORDERS); |
| 653 | mScript.bindAllocation(mAllocTouchYBorders, Defines.ALLOC_Y_BORDERS); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 654 | |
| 655 | mRS.contextBindRootScript(mScript); |
| 656 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 657 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 658 | private void setApps(ArrayList<ApplicationInfo> list) { |
| 659 | final int count = list != null ? list.size() : 0; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 660 | int allocCount = count; |
| 661 | if(allocCount < 1) { |
| 662 | allocCount = 1; |
| 663 | } |
| 664 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 665 | mIcons = new Allocation[count]; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 666 | mIconIds = new int[allocCount]; |
| 667 | mAllocIconID = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 668 | |
| 669 | mLabels = new Allocation[count]; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 670 | mLabelIds = new int[allocCount]; |
| 671 | mAllocLabelID = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 672 | |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 673 | Element ie8888 = Element.RGBA_8888(mRS); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 674 | |
| 675 | Utilities.BubbleText bubble = new Utilities.BubbleText(getContext()); |
| 676 | |
| 677 | for (int i=0; i<count; i++) { |
| 678 | final ApplicationInfo item = list.get(i); |
| 679 | |
| 680 | mIcons[i] = Allocation.createFromBitmap(mRS, item.iconBitmap, |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 681 | Element.RGBA_8888(mRS), false); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 682 | mLabels[i] = Allocation.createFromBitmap(mRS, item.titleBitmap, |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 683 | Element.RGBA_8888(mRS), false); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 684 | |
| 685 | mIcons[i].uploadToTexture(0); |
| 686 | mLabels[i].uploadToTexture(0); |
| 687 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 688 | mIconIds[i] = mIcons[i].getID(); |
| 689 | mLabelIds[i] = mLabels[i].getID(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 690 | } |
| 691 | |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 692 | mAllocIconID.data(mIconIds); |
| 693 | mAllocLabelID.data(mLabelIds); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 694 | |
| 695 | mState.iconCount = count; |
| 696 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 697 | if (mScript != null) { // wtf |
| 698 | mScript.bindAllocation(mAllocIconID, Defines.ALLOC_ICON_IDS); |
| 699 | mScript.bindAllocation(mAllocLabelID, Defines.ALLOC_LABEL_IDS); |
| 700 | } |
| 701 | |
| 702 | mState.save(); |
| 703 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 704 | |
| 705 | void initTouchState() { |
| 706 | int width = getWidth(); |
| 707 | int height = getHeight(); |
| 708 | |
| 709 | int iconsSize; |
| 710 | if (width < height) { |
| 711 | iconsSize = width; |
| 712 | } else { |
| 713 | iconsSize = height; |
| 714 | } |
| 715 | int cellHeight = iconsSize / Defines.ROWS_PER_PAGE; |
| 716 | int cellWidth = iconsSize / Defines.COLUMNS_PER_PAGE; |
| 717 | |
Joe Onorato | 56848b0 | 2009-09-25 13:59:59 -0700 | [diff] [blame] | 718 | int centerY = (height / 2) - (int)(cellHeight * 0.2f); |
| 719 | mTouchYBorders[0] = centerY - (int)(2.8f * cellHeight); |
| 720 | mTouchYBorders[1] = centerY - (int)(1.25f * cellHeight); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 721 | mTouchYBorders[2] = centerY; |
Joe Onorato | 56848b0 | 2009-09-25 13:59:59 -0700 | [diff] [blame] | 722 | mTouchYBorders[3] = centerY + (int)(1.25f * cellHeight);; |
| 723 | mTouchYBorders[4] = centerY + (int)(2.6f * cellHeight); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 724 | |
| 725 | mAllocTouchYBorders.data(mTouchYBorders); |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 726 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 727 | int centerX = (width / 2); |
| 728 | mTouchXBorders[0] = centerX - (2 * cellWidth); |
Joe Onorato | 56848b0 | 2009-09-25 13:59:59 -0700 | [diff] [blame] | 729 | mTouchXBorders[1] = centerX - (int)(0.85f * cellWidth); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 730 | mTouchXBorders[2] = centerX; |
Joe Onorato | 56848b0 | 2009-09-25 13:59:59 -0700 | [diff] [blame] | 731 | mTouchXBorders[3] = centerX + (int)(0.85f * cellWidth); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 732 | mTouchXBorders[4] = centerX + (2 * cellWidth); |
| 733 | |
| 734 | mAllocTouchXBorders.data(mTouchXBorders); |
| 735 | } |
| 736 | |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 737 | int chooseTappedIcon(int x, int y, float page) { |
| 738 | int currentPage = (int)page; |
| 739 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 740 | int col = -1; |
| 741 | int row = -1; |
| 742 | |
| 743 | for (int i=0; i<Defines.COLUMNS_PER_PAGE; i++) { |
| 744 | if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) { |
| 745 | col = i; |
| 746 | break; |
| 747 | } |
| 748 | } |
| 749 | for (int i=0; i<Defines.ROWS_PER_PAGE; i++) { |
| 750 | if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) { |
| 751 | row = i; |
| 752 | break; |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | if (row < 0 || col < 0) { |
| 757 | return -1; |
| 758 | } |
| 759 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 760 | return (currentPage * Defines.ROWS_PER_PAGE * Defines.COLUMNS_PER_PAGE) |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 761 | + (row * Defines.ROWS_PER_PAGE) + col; |
| 762 | } |
| 763 | |
| 764 | /** |
| 765 | * You need to call save() on mState on your own after calling this. |
| 766 | */ |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 767 | void selectIcon(int x, int y, float pos) { |
| 768 | int index = chooseTappedIcon(x, y, pos); |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 769 | selectIcon(index); |
| 770 | } |
| 771 | |
| 772 | void selectIcon(int index) { |
| 773 | Log.d(TAG, "selectIcon index=" + index); |
| 774 | int iconCount = mAllAppsList.size(); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 775 | if (index < 0 || index >= iconCount) { |
| 776 | mState.selectedIconIndex = -1; |
| 777 | return; |
| 778 | } else { |
| 779 | mState.selectedIconIndex = index; |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 780 | |
| 781 | Bitmap selectionBitmap = mSelectionBitmap; |
| 782 | |
| 783 | Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas, |
| 784 | selectionBitmap.getWidth(), selectionBitmap.getHeight(), |
| 785 | mAllAppsList.get(index).iconBitmap); |
| 786 | |
| 787 | mSelectedIcon = Allocation.createFromBitmap(mRS, selectionBitmap, |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 788 | Element.RGBA_8888(mRS), false); |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 789 | mSelectedIcon.uploadToTexture(0); |
| 790 | mState.selectedIconTexture = mSelectedIcon.getID(); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 791 | } |
| 792 | } |
| 793 | |
| 794 | /** |
| 795 | * You need to call save() on mState on your own after calling this. |
| 796 | */ |
| 797 | void clearSelectedIcon() { |
Joe Onorato | 2ca51dc | 2009-09-16 11:44:14 -0400 | [diff] [blame] | 798 | mState.selectedIconIndex = -1; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 799 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 800 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | |