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