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