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