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; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 23 | import java.util.Collections; |
| 24 | import java.util.Comparator; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 25 | |
| 26 | import android.renderscript.RSSurfaceView; |
| 27 | import android.renderscript.RenderScript; |
| 28 | |
| 29 | import android.renderscript.RenderScript; |
| 30 | import android.renderscript.ProgramVertex; |
| 31 | import android.renderscript.Element; |
| 32 | import android.renderscript.Allocation; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 33 | import android.renderscript.Type; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 34 | import android.renderscript.Script; |
| 35 | import android.renderscript.ScriptC; |
| 36 | import android.renderscript.ProgramFragment; |
| 37 | import android.renderscript.ProgramStore; |
| 38 | import android.renderscript.Sampler; |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 39 | import android.renderscript.SimpleMesh; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 40 | |
| 41 | import android.content.Context; |
| 42 | import android.content.res.Resources; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 43 | import android.database.DataSetObserver; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 44 | import android.graphics.Bitmap; |
| 45 | import android.graphics.BitmapFactory; |
| 46 | import android.graphics.Canvas; |
| 47 | import android.graphics.Paint; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 48 | import android.graphics.drawable.BitmapDrawable; |
| 49 | import android.graphics.drawable.Drawable; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 50 | import android.os.Message; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 51 | import android.os.SystemClock; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 52 | import android.util.AttributeSet; |
| 53 | import android.util.Log; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 54 | import android.view.KeyEvent; |
| 55 | import android.view.MotionEvent; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 56 | import android.view.Surface; |
| 57 | import android.view.SurfaceHolder; |
| 58 | import android.view.SurfaceView; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 59 | import android.view.View; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 60 | import android.view.VelocityTracker; |
| 61 | import android.view.ViewConfiguration; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 62 | import android.graphics.PixelFormat; |
| 63 | |
| 64 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 65 | public class AllAppsView extends RSSurfaceView |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 66 | implements View.OnClickListener, View.OnLongClickListener, DragSource { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 67 | private static final String TAG = "Launcher.AllAppsView"; |
| 68 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 69 | /** Bit for mLocks for when there are icons being loaded. */ |
| 70 | private static final int LOCK_ICONS_PENDING = 1; |
| 71 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 72 | private static final int TRACKING_FLING = 0; |
| 73 | private static final int TRACKING_HOME = 1; |
| 74 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 75 | private Launcher mLauncher; |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 76 | private DragController mDragController; |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 77 | |
| 78 | /** When this is 0, modifications are allowed, when it's not, they're not. |
| 79 | * TODO: What about scrolling? */ |
| 80 | private int mLocks = LOCK_ICONS_PENDING; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 81 | |
Joe Onorato | f7b0e01 | 2009-10-01 14:09:15 -0700 | [diff] [blame] | 82 | private int mSlopX; |
| 83 | private int mMaxFlingVelocity; |
| 84 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 85 | private Defines mDefines = new Defines(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 86 | private RenderScript mRS; |
| 87 | private RolloRS mRollo; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 88 | private ArrayList<ApplicationInfo> mAllAppsList; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 89 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 90 | private int mPageCount; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 91 | private boolean mStartedScrolling; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 92 | private VelocityTracker mVelocity; |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 93 | private int mTouchTracking; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 94 | private int mLastMotionX; |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 95 | private int mLastMotionY; |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 96 | private int mMotionDownRawX; |
| 97 | private int mMotionDownRawY; |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 98 | private int mHomeButtonTop; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 99 | private long mTouchTime; |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 100 | private boolean mRotateMove = true; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 101 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 102 | static class Defines { |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 103 | public static final int ALLOC_PARAMS = 0; |
| 104 | public static final int ALLOC_STATE = 1; |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 105 | public static final int ALLOC_ICON_IDS = 3; |
| 106 | public static final int ALLOC_LABEL_IDS = 4; |
| 107 | public static final int ALLOC_X_BORDERS = 5; |
| 108 | public static final int ALLOC_Y_BORDERS = 6; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 109 | |
| 110 | public static final int COLUMNS_PER_PAGE = 4; |
| 111 | public static final int ROWS_PER_PAGE = 4; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 112 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 113 | public static final float RADIUS = 4.0f; |
| 114 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 115 | public static final int ICON_WIDTH_PX = 64; |
| 116 | public static final int ICON_TEXTURE_WIDTH_PX = 128; |
| 117 | |
| 118 | public static final int ICON_HEIGHT_PX = 64; |
| 119 | public static final int ICON_TEXTURE_HEIGHT_PX = 128; |
| 120 | public static final float ICON_TOP_OFFSET = 0.2f; |
| 121 | |
| 122 | public static final float CAMERA_Z = -2; |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 123 | |
| 124 | public int SCREEN_WIDTH_PX; |
| 125 | public int SCREEN_HEIGHT_PX; |
| 126 | |
| 127 | public float FAR_ICON_SIZE; |
| 128 | |
| 129 | public void recompute(int w, int h) { |
| 130 | SCREEN_WIDTH_PX = 480; |
| 131 | SCREEN_HEIGHT_PX = 800; |
| 132 | FAR_ICON_SIZE = farSize(2 * ICON_WIDTH_PX / (float)w); |
| 133 | } |
| 134 | |
| 135 | private static float farSize(float sizeAt0) { |
| 136 | return sizeAt0 * (Defines.RADIUS - Defines.CAMERA_Z) / -Defines.CAMERA_Z; |
| 137 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 138 | } |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 139 | |
| 140 | public AllAppsView(Context context, AttributeSet attrs) { |
| 141 | super(context, attrs); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 142 | setFocusable(true); |
| 143 | getHolder().setFormat(PixelFormat.TRANSLUCENT); |
Joe Onorato | f7b0e01 | 2009-10-01 14:09:15 -0700 | [diff] [blame] | 144 | final ViewConfiguration config = ViewConfiguration.get(context); |
| 145 | mSlopX = config.getScaledTouchSlop(); |
| 146 | mMaxFlingVelocity = config.getScaledMaximumFlingVelocity(); |
| 147 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 148 | setOnClickListener(this); |
| 149 | setOnLongClickListener(this); |
Dianne Hackborn | e52a1b5 | 2009-09-30 22:36:20 -0700 | [diff] [blame] | 150 | setZOrderOnTop(true); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 151 | getHolder().setFormat(PixelFormat.TRANSLUCENT); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 154 | public AllAppsView(Context context, AttributeSet attrs, int defStyle) { |
| 155 | this(context, attrs); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 158 | public void setLauncher(Launcher launcher) { |
| 159 | mLauncher = launcher; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 162 | @Override |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 163 | public void surfaceDestroyed(SurfaceHolder holder) { |
| 164 | super.surfaceDestroyed(holder); |
| 165 | |
| 166 | destroyRenderScript(); |
| 167 | mRS = null; |
| 168 | mRollo = null; |
| 169 | } |
| 170 | |
| 171 | @Override |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 172 | public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { |
| 173 | super.surfaceChanged(holder, format, w, h); |
| 174 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 175 | long startTime = SystemClock.uptimeMillis(); |
| 176 | |
Jason Sams | 05de32a | 2009-09-27 14:01:40 -0700 | [diff] [blame] | 177 | mRS = createRenderScript(true); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 178 | mRollo = new RolloRS(); |
| 179 | mRollo.init(getResources(), w, h); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 180 | if (mAllAppsList != null) { |
| 181 | mRollo.setApps(mAllAppsList); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 182 | Log.d(TAG, "surfaceChanged... calling mRollo.setApps"); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 183 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 184 | |
| 185 | Resources res = getContext().getResources(); |
| 186 | int barHeight = (int)res.getDimension(R.dimen.button_bar_height); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 187 | mHomeButtonTop = h - barHeight; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 188 | |
| 189 | long endTime = SystemClock.uptimeMillis(); |
| 190 | Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms"); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public boolean onKeyDown(int keyCode, KeyEvent event) |
| 195 | { |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 196 | // this method doesn't work when 'extends View' include 'extends ScrollView'. |
| 197 | return super.onKeyDown(keyCode, event); |
| 198 | } |
| 199 | |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 200 | private int mRSMode = 0; |
| 201 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 202 | @Override |
| 203 | public boolean onTouchEvent(MotionEvent ev) |
| 204 | { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 205 | if (!isVisible()) { |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 206 | return true; |
Joe Onorato | e3406a2 | 2009-09-03 14:36:25 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 209 | if (mLocks != 0) { |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 210 | return true; |
| 211 | } |
| 212 | |
| 213 | super.onTouchEvent(ev); |
| 214 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 215 | int x = (int)ev.getX(); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 216 | int y = (int)ev.getY(); |
| 217 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 218 | int action = ev.getAction(); |
| 219 | switch (action) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 220 | case MotionEvent.ACTION_DOWN: |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 221 | if (x < 60 && y > 700) { |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 222 | //mRotateMove = mRollo.setView((++mRSMode) & 3); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 225 | if (y > mRollo.mTouchYBorders[mRollo.mTouchYBorders.length-1]) { |
| 226 | mTouchTracking = TRACKING_HOME; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 227 | } else { |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 228 | mTouchTracking = TRACKING_FLING; |
| 229 | |
| 230 | mMotionDownRawX = (int)ev.getRawX(); |
| 231 | mMotionDownRawY = (int)ev.getRawY(); |
| 232 | mLastMotionX = x; |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 233 | mLastMotionY = y; |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 234 | |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 235 | if (mRotateMove) { |
| 236 | mRollo.mState.newPositionX = ev.getRawY() / mDefines.SCREEN_WIDTH_PX; |
| 237 | } else { |
| 238 | mRollo.mState.newPositionX = ev.getRawX() / mDefines.SCREEN_WIDTH_PX; |
| 239 | } |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 240 | mRollo.mState.newTouchDown = 1; |
| 241 | |
| 242 | if (!mRollo.checkClickOK()) { |
| 243 | mRollo.clearSelectedIcon(); |
| 244 | } else { |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 245 | mRollo.selectIcon(x, y, mRollo.mMessageProc.mPosX); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 246 | } |
| 247 | mRollo.mState.save(); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 248 | mRollo.move(); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 249 | mVelocity = VelocityTracker.obtain(); |
| 250 | mVelocity.addMovement(ev); |
| 251 | mStartedScrolling = false; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 252 | } |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 253 | break; |
| 254 | case MotionEvent.ACTION_MOVE: |
| 255 | case MotionEvent.ACTION_OUTSIDE: |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 256 | if (mTouchTracking == TRACKING_HOME) { |
| 257 | // TODO: highlight? |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 258 | } else { |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 259 | int slopX; |
| 260 | if (mRotateMove) { |
| 261 | slopX = Math.abs(y - mLastMotionY); |
| 262 | } else { |
| 263 | slopX = Math.abs(x - mLastMotionX); |
| 264 | } |
| 265 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 266 | if (!mStartedScrolling && slopX < mSlopX) { |
| 267 | // don't update mLastMotionX so slopX is right and when we do start scrolling |
| 268 | // below, we get the right delta. |
| 269 | } else { |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 270 | if (mRotateMove) { |
| 271 | mRollo.mState.newPositionX = ev.getRawY() / mDefines.SCREEN_WIDTH_PX; |
| 272 | } else { |
| 273 | mRollo.mState.newPositionX = ev.getRawX() / mDefines.SCREEN_WIDTH_PX; |
| 274 | } |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 275 | mRollo.mState.newTouchDown = 1; |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 276 | mRollo.move(); |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 277 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 278 | mStartedScrolling = true; |
| 279 | mRollo.clearSelectedIcon(); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 280 | mVelocity.addMovement(ev); |
| 281 | mRollo.mState.save(); |
| 282 | mLastMotionX = x; |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 283 | mLastMotionY = y; |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 284 | } |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 285 | } |
| 286 | break; |
| 287 | case MotionEvent.ACTION_UP: |
| 288 | case MotionEvent.ACTION_CANCEL: |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 289 | if (mTouchTracking == TRACKING_HOME) { |
| 290 | if (action == MotionEvent.ACTION_UP) { |
| 291 | if (y > mRollo.mTouchYBorders[mRollo.mTouchYBorders.length-1]) { |
| 292 | mLauncher.closeAllApps(true); |
| 293 | } |
| 294 | } |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 295 | } else { |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 296 | mRollo.mState.newTouchDown = 0; |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 297 | if (mRotateMove) { |
| 298 | mRollo.mState.newPositionX = ev.getRawY() / mDefines.SCREEN_WIDTH_PX; |
| 299 | } else { |
| 300 | mRollo.mState.newPositionX = ev.getRawX() / mDefines.SCREEN_WIDTH_PX; |
| 301 | } |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 302 | |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 303 | mVelocity.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 304 | if (mRotateMove) { |
| 305 | mRollo.mState.flingVelocityX |
| 306 | = mVelocity.getYVelocity() / mDefines.SCREEN_WIDTH_PX; |
| 307 | } else { |
| 308 | mRollo.mState.flingVelocityX |
| 309 | = mVelocity.getXVelocity() / mDefines.SCREEN_WIDTH_PX; |
| 310 | } |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 311 | mRollo.clearSelectedIcon(); |
| 312 | mRollo.mState.save(); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 313 | mRollo.fling(); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 314 | |
| 315 | mLastMotionX = -10000; |
Joe Onorato | 539ed9d | 2009-10-02 10:22:14 -0700 | [diff] [blame] | 316 | if (mVelocity != null) { |
| 317 | mVelocity.recycle(); |
| 318 | mVelocity = null; |
| 319 | } |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 320 | break; |
| 321 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 322 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 323 | |
| 324 | return true; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 327 | public void onClick(View v) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 328 | if (mLocks != 0 || !isVisible()) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 329 | return; |
| 330 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 331 | int index = mRollo.mState.selectedIconIndex; |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 332 | if (mRollo.checkClickOK() && index >= 0 && index < mAllAppsList.size()) { |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 333 | ApplicationInfo app = mAllAppsList.get(index); |
| 334 | mLauncher.startActivitySafely(app.intent); |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | public boolean onLongClick(View v) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 339 | if (mLocks != 0 || !isVisible()) { |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 340 | return true; |
| 341 | } |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 342 | int index = mRollo.mState.selectedIconIndex; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 343 | |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 344 | if (mRollo.checkClickOK() && index >= 0 && index < mAllAppsList.size()) { |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 345 | ApplicationInfo app = mAllAppsList.get(index); |
| 346 | |
| 347 | // 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] | 348 | int screenX = mMotionDownRawX - (mDefines.ICON_WIDTH_PX / 2); |
| 349 | int screenY = mMotionDownRawY - mDefines.ICON_HEIGHT_PX; |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 350 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 351 | int left = (mDefines.ICON_TEXTURE_WIDTH_PX - mDefines.ICON_WIDTH_PX) / 2; |
| 352 | int top = (mDefines.ICON_TEXTURE_HEIGHT_PX - mDefines.ICON_HEIGHT_PX) / 2; |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 353 | mDragController.startDrag(app.iconBitmap, screenX, screenY, |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 354 | left, top, mDefines.ICON_WIDTH_PX, mDefines.ICON_HEIGHT_PX, |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 355 | this, app, DragController.DRAG_ACTION_COPY); |
Joe Onorato | e3406a2 | 2009-09-03 14:36:25 -0700 | [diff] [blame] | 356 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 357 | mLauncher.closeAllApps(true); |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 358 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 359 | return true; |
| 360 | } |
| 361 | |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 362 | public void setDragController(DragController dragger) { |
| 363 | mDragController = dragger; |
| 364 | } |
| 365 | |
| 366 | public void onDropCompleted(View target, boolean success) { |
| 367 | } |
| 368 | |
Joe Onorato | 4db5231 | 2009-10-06 11:17:43 -0700 | [diff] [blame] | 369 | /** |
| 370 | * Zoom to the specifed amount. |
| 371 | * |
| 372 | * @param amount [0..1] 0 is hidden, 1 is open |
| 373 | * @param animate Whether to animate. |
| 374 | */ |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 375 | public void zoom(float amount) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 376 | if (mRollo == null) { |
| 377 | return; |
| 378 | } |
| 379 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 380 | cancelLongPress(); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 381 | mRollo.clearSelectedIcon(); |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 382 | if (amount > 0.001f) { |
Joe Onorato | c5acd42 | 2009-10-01 14:21:24 -0700 | [diff] [blame] | 383 | // set in readback, so we're correct even before the next frame |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 384 | mRollo.mState.zoomTarget = amount; |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 385 | } else { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 386 | mRollo.mState.zoomTarget = 0; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 387 | } |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 388 | mRollo.mState.save(); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | public boolean isVisible() { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 392 | if (mRollo == null) { |
| 393 | return false; |
| 394 | } |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 395 | return mRollo.mMessageProc.mZoom > 0.001f; |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 396 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 397 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 398 | @Override |
| 399 | public boolean onTrackballEvent(MotionEvent ev) |
| 400 | { |
| 401 | float x = ev.getX(); |
| 402 | float y = ev.getY(); |
| 403 | //Float tx = new Float(x); |
| 404 | //Float ty = new Float(y); |
| 405 | //Log.e("rs", "tbe " + tx.toString() + ", " + ty.toString()); |
| 406 | |
| 407 | |
| 408 | return true; |
| 409 | } |
| 410 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 411 | public void setApps(ArrayList<ApplicationInfo> list) { |
| 412 | mAllAppsList = list; |
| 413 | if (mRollo != null) { |
| 414 | mRollo.setApps(list); |
| 415 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 416 | mPageCount = countPages(list.size()); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 417 | mLocks &= ~LOCK_ICONS_PENDING; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 420 | public void addApps(ArrayList<ApplicationInfo> list) { |
| 421 | final int N = list.size(); |
| 422 | if (mRollo != null) { |
| 423 | mRollo.reallocAppsList(mRollo.mState.iconCount + N); |
| 424 | } |
| 425 | |
| 426 | for (int i=0; i<N; i++) { |
| 427 | final ApplicationInfo item = list.get(i); |
| 428 | int index = Collections.binarySearch(mAllAppsList, item, mAppNameComp); |
| 429 | if (index < 0) { |
| 430 | index = -(index+1); |
| 431 | } |
| 432 | mAllAppsList.add(index, item); |
| 433 | if (mRollo != null) { |
| 434 | mRollo.addApp(index, item); |
| 435 | mRollo.mState.iconCount++; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | if (mRollo != null) { |
| 440 | mRollo.saveAppsList(); |
| 441 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 444 | public void removeApps(ArrayList<ApplicationInfo> list) { |
| 445 | final int N = list.size(); |
| 446 | for (int i=0; i<N; i++) { |
| 447 | final ApplicationInfo item = list.get(i); |
| 448 | int index = Collections.binarySearch(mAllAppsList, item, mAppIntentComp); |
| 449 | if (index >= 0) { |
| 450 | mAllAppsList.remove(index); |
| 451 | if (mRollo != null) { |
| 452 | mRollo.removeApp(index); |
| 453 | mRollo.mState.iconCount--; |
| 454 | } |
| 455 | } else { |
| 456 | Log.e(TAG, "couldn't find a match for item \"" + item + "\""); |
| 457 | // Try to recover. This should keep us from crashing for now. |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | if (mRollo != null) { |
| 462 | mRollo.saveAppsList(); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | public void updateApps(String packageName, ArrayList<ApplicationInfo> list) { |
| 467 | // Just remove and add, because they may need to be re-sorted. |
| 468 | removeApps(list); |
| 469 | addApps(list); |
| 470 | } |
| 471 | |
| 472 | private Comparator<ApplicationInfo> mAppNameComp = new Comparator<ApplicationInfo>() { |
| 473 | public int compare(ApplicationInfo a, ApplicationInfo b) { |
| 474 | int result = a.title.toString().compareTo(b.toString()); |
| 475 | if (result != 0) { |
| 476 | return result; |
| 477 | } |
| 478 | return a.intent.getComponent().compareTo(b.intent.getComponent()); |
| 479 | } |
| 480 | }; |
| 481 | |
| 482 | private Comparator<ApplicationInfo> mAppIntentComp = new Comparator<ApplicationInfo>() { |
| 483 | public int compare(ApplicationInfo a, ApplicationInfo b) { |
| 484 | return a.intent.getComponent().compareTo(b.intent.getComponent()); |
| 485 | } |
| 486 | }; |
| 487 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 488 | private static int countPages(int iconCount) { |
| 489 | int iconsPerPage = Defines.COLUMNS_PER_PAGE * Defines.ROWS_PER_PAGE; |
| 490 | int pages = iconCount / iconsPerPage; |
| 491 | if (pages*iconsPerPage != iconCount) { |
| 492 | pages++; |
| 493 | } |
| 494 | return pages; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 495 | } |
| 496 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 497 | public class RolloRS { |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 498 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 499 | // Allocations ====== |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 500 | private int mViewMode = 0; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 501 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 502 | private int mWidth; |
| 503 | private int mHeight; |
| 504 | |
| 505 | private Resources mRes; |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 506 | private Script[] mScript = new Script[4]; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 507 | |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 508 | private Script.Invokable[] mInvokeMove = new Script.Invokable[4]; |
| 509 | private Script.Invokable[] mInvokeFling = new Script.Invokable[4]; |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame^] | 510 | private Script.Invokable[] mInvokeResetWAR = new Script.Invokable[4]; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 511 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 512 | private ProgramStore mPSIcons; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 513 | private ProgramStore mPSText; |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 514 | private ProgramFragment mPFColor; |
| 515 | private ProgramFragment mPFTexLinear; |
| 516 | private ProgramFragment mPFTexNearest; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 517 | private ProgramVertex mPV; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 518 | private ProgramVertex mPVOrtho; |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 519 | private SimpleMesh mMesh; |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 520 | private SimpleMesh mMesh2; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 521 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 522 | private Allocation mHomeButton; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 523 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 524 | private Allocation[] mIcons; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 525 | private int[] mIconIds; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 526 | private Allocation mAllocIconIds; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 527 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 528 | private Allocation[] mLabels; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 529 | private int[] mLabelIds; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 530 | private Allocation mAllocLabelIds; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 531 | private Allocation mSelectedIcon; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 532 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 533 | private int[] mTouchYBorders; |
| 534 | private Allocation mAllocTouchYBorders; |
| 535 | private int[] mTouchXBorders; |
| 536 | private Allocation mAllocTouchXBorders; |
| 537 | |
| 538 | private Bitmap mSelectionBitmap; |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 539 | private Canvas mSelectionCanvas; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 540 | |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 541 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 542 | Params mParams; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 543 | State mState; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 544 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 545 | class BaseAlloc { |
| 546 | Allocation mAlloc; |
| 547 | Type mType; |
| 548 | |
| 549 | void save() { |
| 550 | mAlloc.data(this); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 551 | } |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 554 | class AAMessage extends RenderScript.RSMessage { |
| 555 | public void run() { |
| 556 | mPosX = ((float)mData[0]) / (1 << 16); |
| 557 | mVelocity = ((float)mData[1]) / (1 << 16); |
| 558 | mZoom = ((float)mData[2]) / (1 << 16); |
| 559 | //Log.d("rs", "new msg " + mPosX + " " + mVelocity + " " + mZoom); |
| 560 | } |
| 561 | float mZoom; |
| 562 | float mPosX; |
| 563 | float mVelocity; |
| 564 | } |
| 565 | AAMessage mMessageProc; |
| 566 | |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 567 | private boolean checkClickOK() { |
| 568 | //android.util.Log.e("rs", "check click " + Float.toString(mReadback.velocity) + ", " + Float.toString(mReadback.posX)); |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 569 | return (Math.abs(mMessageProc.mVelocity) < 0.1f) && |
| 570 | (Math.abs(mMessageProc.mPosX - Math.round(mMessageProc.mPosX)) < 0.1f); |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 573 | class Params extends BaseAlloc { |
| 574 | Params() { |
| 575 | mType = Type.createFromClass(mRS, Params.class, 1, "ParamsClass"); |
| 576 | mAlloc = Allocation.createTyped(mRS, mType); |
| 577 | save(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 578 | } |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 579 | public int bubbleWidth; |
| 580 | public int bubbleHeight; |
| 581 | public int bubbleBitmapWidth; |
| 582 | public int bubbleBitmapHeight; |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 583 | |
| 584 | public int homeButtonId; |
| 585 | public int homeButtonWidth; |
| 586 | public int homeButtonHeight; |
| 587 | public int homeButtonTextureWidth; |
| 588 | public int homeButtonTextureHeight; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | class State extends BaseAlloc { |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 592 | public float newPositionX; |
| 593 | public int newTouchDown; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 594 | public float flingVelocityX; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 595 | public int iconCount; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 596 | public int selectedIconIndex = -1; |
| 597 | public int selectedIconTexture; |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 598 | public float zoomTarget; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 599 | |
| 600 | State() { |
| 601 | mType = Type.createFromClass(mRS, State.class, 1, "StateClass"); |
| 602 | mAlloc = Allocation.createTyped(mRS, mType); |
| 603 | save(); |
| 604 | } |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | public RolloRS() { |
| 608 | } |
| 609 | |
| 610 | public void init(Resources res, int width, int height) { |
| 611 | mRes = res; |
| 612 | mWidth = width; |
| 613 | mHeight = height; |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 614 | mDefines.recompute(width, height); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 615 | initProgramVertex(); |
| 616 | initProgramFragment(); |
| 617 | initProgramStore(); |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 618 | initMesh(); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 619 | initMesh2(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 620 | initGl(); |
| 621 | initData(); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 622 | initTouchState(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 623 | initRs(); |
| 624 | } |
| 625 | |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 626 | public void initMesh() { |
| 627 | SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(mRS, 3, |
| 628 | SimpleMesh.TriangleMeshBuilder.TEXTURE_0 | SimpleMesh.TriangleMeshBuilder.COLOR); |
| 629 | |
| 630 | for (int ct=0; ct < 450; ct++) { |
| 631 | float x = 0; |
| 632 | float z = 0; |
| 633 | float l = 1.f; |
| 634 | |
| 635 | if (ct < 190) { |
| 636 | z = 0.1f + 0.05f * (190 - ct); |
| 637 | x = -1; |
| 638 | l = 0.125f + (0.125f / 190.f) * ct; |
| 639 | } else if (ct >= 190 && ct < 200) { |
| 640 | float a = (3.14f * 0.5f) * (0.1f * (ct - 200)); |
| 641 | float s = (float)Math.sin(a); |
| 642 | float c = (float)Math.cos(a); |
| 643 | x = -0.9f + s * 0.1f; |
| 644 | z = 0.1f - c * 0.1f; |
| 645 | l = 0.25f + 0.075f * (ct - 190); |
| 646 | } else if (ct >= 200 && ct < 250) { |
| 647 | z = 0.f; |
| 648 | x = -0.9f + (1.8f * (ct - 200) / 50.f); |
| 649 | } else if (ct >= 250 && ct < 260) { |
| 650 | float a = (3.14f * 0.5f) * (0.1f * (ct - 250)); |
| 651 | float s = (float)Math.sin(a); |
| 652 | float c = (float)Math.cos(a); |
| 653 | x = 0.9f + s * 0.1f; |
| 654 | z = 0.1f - c * 0.1f; |
| 655 | l = 0.25f + 0.075f * (260 - ct); |
| 656 | } else if (ct >= 260) { |
| 657 | z = 0.1f + 0.05f * (ct - 260); |
| 658 | x = 1; |
| 659 | l = 0.125f + (0.125f / 190.f) * (450 - ct); |
| 660 | } |
| 661 | //Log.e("rs", "ct " + Integer.toString(ct) + " x = " + Float.toString(x) + ", z = " + Float.toString(z)); |
| 662 | //Log.e("rs", "ct " + Integer.toString(ct) + " l = " + Float.toString(l)); |
| 663 | float s = ct * 0.1f; |
| 664 | tm.setColor(l, l, l, 0.99f); |
| 665 | tm.setTexture(s, 1); |
| 666 | tm.addVertex(x, -0.5f, z); |
| 667 | tm.setTexture(s, 0); |
| 668 | tm.addVertex(x, 0.5f, z); |
| 669 | } |
| 670 | for (int ct=0; ct < (450*2 - 2); ct+= 2) { |
| 671 | tm.addTriangle(ct, ct+1, ct+2); |
| 672 | tm.addTriangle(ct+1, ct+3, ct+2); |
| 673 | } |
| 674 | mMesh = tm.create(); |
| 675 | mMesh.setName("SMMesh"); |
| 676 | |
| 677 | } |
| 678 | |
| 679 | |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 680 | public void initMesh2() { |
| 681 | SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(mRS, 3, |
| 682 | SimpleMesh.TriangleMeshBuilder.TEXTURE_0 | SimpleMesh.TriangleMeshBuilder.COLOR); |
| 683 | |
| 684 | float y = 0; |
| 685 | float z = 0; |
| 686 | for (int ct=0; ct < 200; ct++) { |
| 687 | float angle = 0; |
| 688 | float maxAngle = 3.14f * 0.16f; |
| 689 | float l = 1.f; |
| 690 | |
| 691 | l = 1 - ((ct-5) * 0.10f); |
| 692 | if (ct > 7) { |
| 693 | angle = maxAngle * (ct - 7) * 0.2f; |
| 694 | angle = Math.min(angle, maxAngle); |
| 695 | } |
| 696 | l = Math.max(0.3f, l); |
| 697 | l = Math.min(1.0f, l); |
| 698 | |
| 699 | y += 0.1f * Math.cos(angle); |
| 700 | z += 0.1f * Math.sin(angle); |
| 701 | |
| 702 | float t = 0.1f * ct; |
| 703 | float ds = 0.08f; |
| 704 | tm.setColor(l, l, l, 0.99f); |
| 705 | tm.setTexture(ds, t); |
| 706 | tm.addVertex(-0.5f, y, z); |
| 707 | tm.setTexture(1 - ds, t); |
| 708 | tm.addVertex(0.5f, y, z); |
| 709 | } |
| 710 | for (int ct=0; ct < (200 * 2 - 2); ct+= 2) { |
| 711 | tm.addTriangle(ct, ct+1, ct+2); |
| 712 | tm.addTriangle(ct+1, ct+3, ct+2); |
| 713 | } |
| 714 | mMesh2 = tm.create(); |
| 715 | mMesh2.setName("SMMesh2"); |
| 716 | } |
| 717 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 718 | private void initProgramVertex() { |
| 719 | ProgramVertex.MatrixAllocation pva = new ProgramVertex.MatrixAllocation(mRS); |
| 720 | pva.setupProjectionNormalized(mWidth, mHeight); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 721 | |
| 722 | ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null); |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 723 | pvb.setTextureMatrixEnable(true); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 724 | mPV = pvb.create(); |
| 725 | mPV.setName("PV"); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 726 | mPV.bindAllocation(pva); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 727 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 728 | pva = new ProgramVertex.MatrixAllocation(mRS); |
| 729 | pva.setupOrthoWindow(mWidth, mHeight); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 730 | pvb.setTextureMatrixEnable(true); |
| 731 | mPVOrtho = pvb.create(); |
| 732 | mPVOrtho.setName("PVOrtho"); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 733 | mPVOrtho.bindAllocation(pva); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 734 | |
| 735 | mRS.contextBindProgramVertex(mPV); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 736 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 737 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 738 | private void initProgramFragment() { |
| 739 | Sampler.Builder sb = new Sampler.Builder(mRS); |
| 740 | sb.setMin(Sampler.Value.LINEAR); |
| 741 | sb.setMag(Sampler.Value.LINEAR); |
| 742 | sb.setWrapS(Sampler.Value.CLAMP); |
| 743 | sb.setWrapT(Sampler.Value.CLAMP); |
| 744 | Sampler linear = sb.create(); |
| 745 | |
| 746 | sb.setMin(Sampler.Value.NEAREST); |
| 747 | sb.setMag(Sampler.Value.NEAREST); |
| 748 | Sampler nearest = sb.create(); |
| 749 | |
| 750 | ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null); |
| 751 | mPFColor = bf.create(); |
| 752 | mPFColor.setName("PFColor"); |
| 753 | |
| 754 | bf.setTexEnable(true, 0); |
| 755 | bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0); |
| 756 | mPFTexLinear = bf.create(); |
| 757 | mPFTexLinear.setName("PFTexLinear"); |
| 758 | mPFTexLinear.bindSampler(linear, 0); |
| 759 | |
| 760 | mPFTexNearest = bf.create(); |
| 761 | mPFTexNearest.setName("PFTexNearest"); |
| 762 | mPFTexNearest.bindSampler(nearest, 0); |
| 763 | } |
| 764 | |
| 765 | private void initProgramStore() { |
| 766 | ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null); |
| 767 | bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 768 | bs.setColorMask(true,true,true,false); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 769 | bs.setDitherEnable(true); |
| 770 | bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, |
| 771 | ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA); |
| 772 | mPSIcons = bs.create(); |
| 773 | mPSIcons.setName("PSIcons"); |
| 774 | |
| 775 | //bs.setDitherEnable(false); |
| 776 | //mPSText = bs.create(); |
| 777 | //mPSText.setName("PSText"); |
| 778 | } |
| 779 | |
| 780 | private void initGl() { |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 781 | mTouchXBorders = new int[Defines.COLUMNS_PER_PAGE+1]; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 782 | mAllocTouchXBorders = Allocation.createSized(mRS, Element.USER_I32(mRS), |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 783 | mTouchXBorders.length); |
| 784 | mAllocTouchXBorders.data(mTouchXBorders); |
| 785 | |
| 786 | mTouchYBorders = new int[Defines.ROWS_PER_PAGE+1]; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 787 | mAllocTouchYBorders = Allocation.createSized(mRS, Element.USER_I32(mRS), |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 788 | mTouchYBorders.length); |
| 789 | mAllocTouchYBorders.data(mTouchYBorders); |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 790 | } |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 791 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 792 | private void initData() { |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 793 | mParams = new Params(); |
| 794 | mState = new State(); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 795 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 796 | final Utilities.BubbleText bubble = new Utilities.BubbleText(getContext()); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 797 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 798 | mParams.bubbleWidth = bubble.getBubbleWidth(); |
| 799 | mParams.bubbleHeight = bubble.getMaxBubbleHeight(); |
| 800 | mParams.bubbleBitmapWidth = bubble.getBitmapWidth(); |
| 801 | mParams.bubbleBitmapHeight = bubble.getBitmapHeight(); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 802 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 803 | mHomeButton = Allocation.createFromBitmapResource(mRS, mRes, |
| 804 | R.drawable.home_button, Element.RGBA_8888(mRS), false); |
| 805 | mHomeButton.uploadToTexture(0); |
| 806 | mParams.homeButtonId = mHomeButton.getID(); |
| 807 | mParams.homeButtonWidth = 76; |
| 808 | mParams.homeButtonHeight = 68; |
| 809 | mParams.homeButtonTextureWidth = 128; |
| 810 | mParams.homeButtonTextureHeight = 128; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 811 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 812 | mParams.save(); |
| 813 | mState.save(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 814 | |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 815 | mSelectionBitmap = Bitmap.createBitmap(Defines.ICON_TEXTURE_WIDTH_PX, |
| 816 | Defines.ICON_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888); |
| 817 | mSelectionCanvas = new Canvas(mSelectionBitmap); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 818 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 819 | setApps(null); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 822 | private void initScript(int idx, int id) { |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 823 | ScriptC.Builder sb = new ScriptC.Builder(mRS); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 824 | sb.setScript(mRes, id); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 825 | sb.setRoot(true); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 826 | sb.addDefines(mDefines); |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 827 | sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS); |
| 828 | sb.setType(mState.mType, "state", Defines.ALLOC_STATE); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 829 | mInvokeMove[idx] = sb.addInvokable("move"); |
| 830 | mInvokeFling[idx] = sb.addInvokable("fling"); |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame^] | 831 | mInvokeResetWAR[idx] = sb.addInvokable("resetHWWar"); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 832 | mScript[idx] = sb.create(); |
| 833 | mScript[idx].setClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 834 | mScript[idx].bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS); |
| 835 | mScript[idx].bindAllocation(mState.mAlloc, Defines.ALLOC_STATE); |
| 836 | mScript[idx].bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS); |
| 837 | mScript[idx].bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS); |
| 838 | mScript[idx].bindAllocation(mAllocTouchXBorders, Defines.ALLOC_X_BORDERS); |
| 839 | mScript[idx].bindAllocation(mAllocTouchYBorders, Defines.ALLOC_Y_BORDERS); |
| 840 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 841 | |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 842 | private void initRs() { |
| 843 | mViewMode = 0; |
| 844 | initScript(0, R.raw.rollo3); |
| 845 | initScript(1, R.raw.rollo2); |
| 846 | initScript(2, R.raw.rollo); |
| 847 | initScript(3, R.raw.rollo4); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 848 | |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 849 | mMessageProc = new AAMessage(); |
| 850 | mRS.mMessageCallback = mMessageProc; |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 851 | mRS.contextBindRootScript(mScript[mViewMode]); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 852 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 853 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 854 | private void setApps(ArrayList<ApplicationInfo> list) { |
| 855 | final int count = list != null ? list.size() : 0; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 856 | int allocCount = count; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 857 | if (allocCount < 1) { |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 858 | allocCount = 1; |
| 859 | } |
| 860 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 861 | mIcons = new Allocation[count]; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 862 | mIconIds = new int[allocCount]; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 863 | mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 864 | |
| 865 | mLabels = new Allocation[count]; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 866 | mLabelIds = new int[allocCount]; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 867 | mAllocLabelIds = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 868 | |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 869 | Element ie8888 = Element.RGBA_8888(mRS); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 870 | |
| 871 | Utilities.BubbleText bubble = new Utilities.BubbleText(getContext()); |
| 872 | |
| 873 | for (int i=0; i<count; i++) { |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 874 | uploadAppIcon(i, list.get(i)); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 875 | } |
| 876 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 877 | mState.iconCount = count; |
| 878 | |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 879 | saveAppsList(); |
| 880 | } |
| 881 | |
| 882 | private void uploadAppIcon(int index, ApplicationInfo item) { |
| 883 | mIcons[index] = Allocation.createFromBitmap(mRS, item.iconBitmap, |
| 884 | Element.RGBA_8888(mRS), false); |
| 885 | mLabels[index] = Allocation.createFromBitmap(mRS, item.titleBitmap, |
| 886 | Element.RGBA_8888(mRS), false); |
| 887 | |
| 888 | mIcons[index].uploadToTexture(0); |
| 889 | mLabels[index].uploadToTexture(0); |
| 890 | |
| 891 | mIconIds[index] = mIcons[index].getID(); |
| 892 | mLabelIds[index] = mLabels[index].getID(); |
| 893 | } |
| 894 | |
| 895 | /** |
| 896 | * Puts the empty spaces at the end. Updates mState.iconCount. You must |
| 897 | * fill in the values and call saveAppsList(). |
| 898 | */ |
| 899 | private void reallocAppsList(int count) { |
| 900 | Allocation[] icons = new Allocation[count]; |
| 901 | int[] iconIds = new int[count]; |
| 902 | mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), count); |
| 903 | |
| 904 | Allocation[] labels = new Allocation[count]; |
| 905 | int[] labelIds = new int[count]; |
| 906 | mAllocLabelIds = Allocation.createSized(mRS, Element.USER_I32(mRS), count); |
| 907 | |
| 908 | final int oldCount = mIcons.length; |
| 909 | |
| 910 | System.arraycopy(mIcons, 0, icons, 0, oldCount); |
| 911 | System.arraycopy(mIconIds, 0, iconIds, 0, oldCount); |
| 912 | System.arraycopy(mLabels, 0, labels, 0, oldCount); |
| 913 | System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount); |
| 914 | |
| 915 | mIcons = icons; |
| 916 | mIconIds = iconIds; |
| 917 | mLabels = labels; |
| 918 | mLabelIds = labelIds; |
| 919 | } |
| 920 | |
| 921 | /** |
| 922 | * Handle the allocations for the new app. Make sure you call saveAppsList when done. |
| 923 | */ |
| 924 | private void addApp(int index, ApplicationInfo item) { |
| 925 | final int count = mState.iconCount - index; |
| 926 | final int dest = index + 1; |
| 927 | |
| 928 | System.arraycopy(mIcons, index, mIcons, dest, count); |
| 929 | System.arraycopy(mIconIds, index, mIconIds, dest, count); |
| 930 | System.arraycopy(mLabels, index, mLabels, dest, count); |
| 931 | System.arraycopy(mLabelIds, index, mLabelIds, dest, count); |
| 932 | |
| 933 | uploadAppIcon(index, item); |
| 934 | } |
| 935 | |
| 936 | /** |
| 937 | * Handle the allocations for the removed app. Make sure you call saveAppsList when done. |
| 938 | */ |
| 939 | private void removeApp(int index) { |
| 940 | final int count = mState.iconCount - index - 1; |
| 941 | final int src = index + 1; |
| 942 | |
| 943 | System.arraycopy(mIcons, src, mIcons, index, count); |
| 944 | System.arraycopy(mIconIds, src, mIconIds, index, count); |
| 945 | System.arraycopy(mLabels, src, mLabels, index, count); |
| 946 | System.arraycopy(mLabelIds, src, mLabelIds, index, count); |
| 947 | |
| 948 | final int last = mState.iconCount - 1; |
| 949 | mIcons[last] = null; |
| 950 | mIconIds[last] = 0; |
| 951 | mLabels[last] = null; |
| 952 | mLabelIds[last] = 0; |
| 953 | } |
| 954 | |
| 955 | /** |
| 956 | * Send the apps list structures to RS. |
| 957 | */ |
| 958 | private void saveAppsList() { |
| 959 | mRS.contextBindRootScript(null); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 960 | |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 961 | mAllocIconIds.data(mIconIds); |
| 962 | mAllocLabelIds.data(mLabelIds); |
| 963 | |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 964 | if (mScript[0] != null) { // this happens when we init it |
| 965 | for (int ct=0; ct < 4; ct++) { |
| 966 | mScript[ct].bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS); |
| 967 | mScript[ct].bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS); |
| 968 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | mState.save(); |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 972 | |
| 973 | // Note: mScript may be null if we haven't initialized it yet. |
| 974 | // In that case, this is a no-op. |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame^] | 975 | if (mInvokeResetWAR != null && |
| 976 | mInvokeResetWAR[mViewMode] != null) { |
| 977 | mInvokeResetWAR[mViewMode].execute(); |
| 978 | } |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 979 | mRS.contextBindRootScript(mScript[mViewMode]); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 980 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 981 | |
| 982 | void initTouchState() { |
| 983 | int width = getWidth(); |
| 984 | int height = getHeight(); |
| 985 | |
| 986 | int iconsSize; |
| 987 | if (width < height) { |
| 988 | iconsSize = width; |
| 989 | } else { |
| 990 | iconsSize = height; |
| 991 | } |
| 992 | int cellHeight = iconsSize / Defines.ROWS_PER_PAGE; |
| 993 | int cellWidth = iconsSize / Defines.COLUMNS_PER_PAGE; |
| 994 | |
Joe Onorato | 56848b0 | 2009-09-25 13:59:59 -0700 | [diff] [blame] | 995 | int centerY = (height / 2) - (int)(cellHeight * 0.2f); |
| 996 | mTouchYBorders[0] = centerY - (int)(2.8f * cellHeight); |
| 997 | mTouchYBorders[1] = centerY - (int)(1.25f * cellHeight); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 998 | mTouchYBorders[2] = centerY; |
Joe Onorato | 56848b0 | 2009-09-25 13:59:59 -0700 | [diff] [blame] | 999 | mTouchYBorders[3] = centerY + (int)(1.25f * cellHeight);; |
| 1000 | mTouchYBorders[4] = centerY + (int)(2.6f * cellHeight); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1001 | |
| 1002 | mAllocTouchYBorders.data(mTouchYBorders); |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 1003 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1004 | int centerX = (width / 2); |
| 1005 | mTouchXBorders[0] = centerX - (2 * cellWidth); |
Joe Onorato | 56848b0 | 2009-09-25 13:59:59 -0700 | [diff] [blame] | 1006 | mTouchXBorders[1] = centerX - (int)(0.85f * cellWidth); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1007 | mTouchXBorders[2] = centerX; |
Joe Onorato | 56848b0 | 2009-09-25 13:59:59 -0700 | [diff] [blame] | 1008 | mTouchXBorders[3] = centerX + (int)(0.85f * cellWidth); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1009 | mTouchXBorders[4] = centerX + (2 * cellWidth); |
| 1010 | |
| 1011 | mAllocTouchXBorders.data(mTouchXBorders); |
| 1012 | } |
| 1013 | |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 1014 | int chooseTappedIconHorz(int x, int y, float page) { |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 1015 | int currentPage = (int)page; |
| 1016 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1017 | int col = -1; |
| 1018 | int row = -1; |
| 1019 | |
| 1020 | for (int i=0; i<Defines.COLUMNS_PER_PAGE; i++) { |
| 1021 | if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) { |
| 1022 | col = i; |
| 1023 | break; |
| 1024 | } |
| 1025 | } |
| 1026 | for (int i=0; i<Defines.ROWS_PER_PAGE; i++) { |
| 1027 | if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) { |
| 1028 | row = i; |
| 1029 | break; |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | if (row < 0 || col < 0) { |
| 1034 | return -1; |
| 1035 | } |
| 1036 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 1037 | return (currentPage * Defines.ROWS_PER_PAGE * Defines.COLUMNS_PER_PAGE) |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1038 | + (row * Defines.ROWS_PER_PAGE) + col; |
| 1039 | } |
| 1040 | |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 1041 | int chooseTappedIconVert(int x, int y, float pos) { |
| 1042 | int ydead = (getHeight() - 4 * 145) / 2; |
| 1043 | if (y < ydead || y > (getHeight() - ydead)) { |
| 1044 | return -1; |
| 1045 | } |
| 1046 | |
| 1047 | y -= ydead; |
| 1048 | y += pos * 145; |
| 1049 | int row = y / 145; |
| 1050 | int col = x / 120; |
| 1051 | |
| 1052 | return row * 4 + col; |
| 1053 | } |
| 1054 | |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 1055 | boolean setView(int v) { |
| 1056 | mViewMode = v; |
| 1057 | mRS.contextBindRootScript(mScript[mViewMode]); |
| 1058 | return (v == 0); |
| 1059 | } |
| 1060 | |
| 1061 | void fling() { |
| 1062 | mInvokeFling[mViewMode].execute(); |
| 1063 | } |
| 1064 | |
| 1065 | void move() { |
| 1066 | mInvokeMove[mViewMode].execute(); |
| 1067 | } |
| 1068 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1069 | /** |
| 1070 | * You need to call save() on mState on your own after calling this. |
| 1071 | */ |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 1072 | void selectIcon(int x, int y, float pos) { |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 1073 | int index; |
| 1074 | //Log.e("rs", "select " + x + ", " + y + ", " + pos + ", " + mViewMode); |
| 1075 | if (mViewMode != 0) { |
| 1076 | index = chooseTappedIconHorz(x, y, pos); |
| 1077 | } else { |
| 1078 | index = chooseTappedIconVert(x, y, pos); |
| 1079 | } |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 1080 | selectIcon(index); |
| 1081 | } |
| 1082 | |
| 1083 | void selectIcon(int index) { |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 1084 | int iconCount = mAllAppsList.size(); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1085 | if (index < 0 || index >= iconCount) { |
| 1086 | mState.selectedIconIndex = -1; |
| 1087 | return; |
| 1088 | } else { |
| 1089 | mState.selectedIconIndex = index; |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 1090 | |
| 1091 | Bitmap selectionBitmap = mSelectionBitmap; |
| 1092 | |
| 1093 | Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas, |
| 1094 | selectionBitmap.getWidth(), selectionBitmap.getHeight(), |
| 1095 | mAllAppsList.get(index).iconBitmap); |
| 1096 | |
| 1097 | mSelectedIcon = Allocation.createFromBitmap(mRS, selectionBitmap, |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 1098 | Element.RGBA_8888(mRS), false); |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 1099 | mSelectedIcon.uploadToTexture(0); |
| 1100 | mState.selectedIconTexture = mSelectedIcon.getID(); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | /** |
| 1105 | * You need to call save() on mState on your own after calling this. |
| 1106 | */ |
| 1107 | void clearSelectedIcon() { |
Joe Onorato | 2ca51dc | 2009-09-16 11:44:14 -0400 | [diff] [blame] | 1108 | mState.selectedIconIndex = -1; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 1109 | } |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 1110 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 1111 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | |