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