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