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 | |
Mike Cleron | b6082fa0 | 2009-10-19 17:03:36 -0700 | [diff] [blame^] | 377 | /* |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 378 | @Override |
| 379 | public boolean onTrackballEvent(MotionEvent ev) |
| 380 | { |
| 381 | float x = ev.getX(); |
| 382 | float y = ev.getY(); |
| 383 | //Float tx = new Float(x); |
| 384 | //Float ty = new Float(y); |
| 385 | //Log.e("rs", "tbe " + tx.toString() + ", " + ty.toString()); |
| 386 | |
| 387 | |
| 388 | return true; |
| 389 | } |
Mike Cleron | b6082fa0 | 2009-10-19 17:03:36 -0700 | [diff] [blame^] | 390 | */ |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 391 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 392 | public void setApps(ArrayList<ApplicationInfo> list) { |
| 393 | mAllAppsList = list; |
| 394 | if (mRollo != null) { |
| 395 | mRollo.setApps(list); |
| 396 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 397 | mPageCount = countPages(list.size()); |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 398 | mLocks &= ~LOCK_ICONS_PENDING; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 401 | public void addApps(ArrayList<ApplicationInfo> list) { |
| 402 | final int N = list.size(); |
| 403 | if (mRollo != null) { |
| 404 | mRollo.reallocAppsList(mRollo.mState.iconCount + N); |
| 405 | } |
| 406 | |
| 407 | for (int i=0; i<N; i++) { |
| 408 | final ApplicationInfo item = list.get(i); |
| 409 | int index = Collections.binarySearch(mAllAppsList, item, mAppNameComp); |
| 410 | if (index < 0) { |
| 411 | index = -(index+1); |
| 412 | } |
| 413 | mAllAppsList.add(index, item); |
| 414 | if (mRollo != null) { |
| 415 | mRollo.addApp(index, item); |
| 416 | mRollo.mState.iconCount++; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | if (mRollo != null) { |
| 421 | mRollo.saveAppsList(); |
| 422 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 425 | public void removeApps(ArrayList<ApplicationInfo> list) { |
| 426 | final int N = list.size(); |
| 427 | for (int i=0; i<N; i++) { |
| 428 | final ApplicationInfo item = list.get(i); |
| 429 | int index = Collections.binarySearch(mAllAppsList, item, mAppIntentComp); |
| 430 | if (index >= 0) { |
| 431 | mAllAppsList.remove(index); |
| 432 | if (mRollo != null) { |
| 433 | mRollo.removeApp(index); |
| 434 | mRollo.mState.iconCount--; |
| 435 | } |
| 436 | } else { |
| 437 | Log.e(TAG, "couldn't find a match for item \"" + item + "\""); |
| 438 | // Try to recover. This should keep us from crashing for now. |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | if (mRollo != null) { |
| 443 | mRollo.saveAppsList(); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | public void updateApps(String packageName, ArrayList<ApplicationInfo> list) { |
| 448 | // Just remove and add, because they may need to be re-sorted. |
| 449 | removeApps(list); |
| 450 | addApps(list); |
| 451 | } |
| 452 | |
| 453 | private Comparator<ApplicationInfo> mAppNameComp = new Comparator<ApplicationInfo>() { |
| 454 | public int compare(ApplicationInfo a, ApplicationInfo b) { |
| 455 | int result = a.title.toString().compareTo(b.toString()); |
| 456 | if (result != 0) { |
| 457 | return result; |
| 458 | } |
| 459 | return a.intent.getComponent().compareTo(b.intent.getComponent()); |
| 460 | } |
| 461 | }; |
| 462 | |
| 463 | private Comparator<ApplicationInfo> mAppIntentComp = new Comparator<ApplicationInfo>() { |
| 464 | public int compare(ApplicationInfo a, ApplicationInfo b) { |
| 465 | return a.intent.getComponent().compareTo(b.intent.getComponent()); |
| 466 | } |
| 467 | }; |
| 468 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 469 | private static int countPages(int iconCount) { |
| 470 | int iconsPerPage = Defines.COLUMNS_PER_PAGE * Defines.ROWS_PER_PAGE; |
| 471 | int pages = iconCount / iconsPerPage; |
| 472 | if (pages*iconsPerPage != iconCount) { |
| 473 | pages++; |
| 474 | } |
| 475 | return pages; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 476 | } |
| 477 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 478 | public class RolloRS { |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 479 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 480 | // Allocations ====== |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 481 | private int mWidth; |
| 482 | private int mHeight; |
| 483 | |
| 484 | private Resources mRes; |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 485 | private Script mScript; |
| 486 | private Script.Invokable mInvokeMove; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 487 | private Script.Invokable mInvokeMoveTo; |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 488 | private Script.Invokable mInvokeFling; |
| 489 | private Script.Invokable mInvokeResetWAR; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 490 | |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 491 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 492 | private ProgramStore mPSIcons; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 493 | private ProgramStore mPSText; |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 494 | private ProgramFragment mPFColor; |
| 495 | private ProgramFragment mPFTexLinear; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 496 | private ProgramVertex mPV; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 497 | private ProgramVertex mPVOrtho; |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 498 | private SimpleMesh mMesh; |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 499 | private SimpleMesh mMesh2; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 500 | |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 501 | private Allocation mHomeButtonNormal; |
| 502 | private Allocation mHomeButtonPressed; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 503 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 504 | private Allocation[] mIcons; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 505 | private int[] mIconIds; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 506 | private Allocation mAllocIconIds; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 507 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 508 | private Allocation[] mLabels; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 509 | private int[] mLabelIds; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 510 | private Allocation mAllocLabelIds; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 511 | private Allocation mSelectedIcon; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 512 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 513 | private int[] mTouchYBorders; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 514 | private int[] mTouchXBorders; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 515 | |
| 516 | private Bitmap mSelectionBitmap; |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 517 | private Canvas mSelectionCanvas; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 518 | |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 519 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 520 | Params mParams; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 521 | State mState; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 522 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 523 | class BaseAlloc { |
| 524 | Allocation mAlloc; |
| 525 | Type mType; |
| 526 | |
| 527 | void save() { |
| 528 | mAlloc.data(this); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 529 | } |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 532 | class AAMessage extends RenderScript.RSMessage { |
| 533 | public void run() { |
| 534 | mPosX = ((float)mData[0]) / (1 << 16); |
| 535 | mVelocity = ((float)mData[1]) / (1 << 16); |
| 536 | mZoom = ((float)mData[2]) / (1 << 16); |
| 537 | //Log.d("rs", "new msg " + mPosX + " " + mVelocity + " " + mZoom); |
| 538 | } |
| 539 | float mZoom; |
| 540 | float mPosX; |
| 541 | float mVelocity; |
| 542 | } |
| 543 | AAMessage mMessageProc; |
| 544 | |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 545 | private boolean checkClickOK() { |
| 546 | //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] | 547 | return (Math.abs(mMessageProc.mVelocity) < 0.1f) && |
| 548 | (Math.abs(mMessageProc.mPosX - Math.round(mMessageProc.mPosX)) < 0.1f); |
Jason Sams | 476339d | 2009-09-29 18:14:38 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 551 | class Params extends BaseAlloc { |
| 552 | Params() { |
| 553 | mType = Type.createFromClass(mRS, Params.class, 1, "ParamsClass"); |
| 554 | mAlloc = Allocation.createTyped(mRS, mType); |
| 555 | save(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 556 | } |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 557 | public int bubbleWidth; |
| 558 | public int bubbleHeight; |
| 559 | public int bubbleBitmapWidth; |
| 560 | public int bubbleBitmapHeight; |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 561 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 562 | public int homeButtonWidth; |
| 563 | public int homeButtonHeight; |
| 564 | public int homeButtonTextureWidth; |
| 565 | public int homeButtonTextureHeight; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | class State extends BaseAlloc { |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 569 | public float newPositionX; |
| 570 | public int newTouchDown; |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 571 | public float flingVelocity; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 572 | public int iconCount; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 573 | public int selectedIconIndex = -1; |
| 574 | public int selectedIconTexture; |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 575 | public float zoomTarget; |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 576 | public int homeButtonId; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 577 | public float targetPos; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 578 | |
| 579 | State() { |
| 580 | mType = Type.createFromClass(mRS, State.class, 1, "StateClass"); |
| 581 | mAlloc = Allocation.createTyped(mRS, mType); |
| 582 | save(); |
| 583 | } |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | public RolloRS() { |
| 587 | } |
| 588 | |
| 589 | public void init(Resources res, int width, int height) { |
| 590 | mRes = res; |
| 591 | mWidth = width; |
| 592 | mHeight = height; |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 593 | mDefines.recompute(width, height); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 594 | initProgramVertex(); |
| 595 | initProgramFragment(); |
| 596 | initProgramStore(); |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 597 | initMesh(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 598 | initGl(); |
| 599 | initData(); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 600 | initTouchState(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 601 | initRs(); |
| 602 | } |
| 603 | |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 604 | public void initMesh() { |
| 605 | SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(mRS, 3, |
| 606 | SimpleMesh.TriangleMeshBuilder.TEXTURE_0 | SimpleMesh.TriangleMeshBuilder.COLOR); |
| 607 | |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 608 | float y = 0; |
| 609 | float z = 0; |
| 610 | for (int ct=0; ct < 200; ct++) { |
| 611 | float angle = 0; |
| 612 | float maxAngle = 3.14f * 0.16f; |
| 613 | float l = 1.f; |
| 614 | |
| 615 | l = 1 - ((ct-5) * 0.10f); |
| 616 | if (ct > 7) { |
| 617 | angle = maxAngle * (ct - 7) * 0.2f; |
| 618 | angle = Math.min(angle, maxAngle); |
| 619 | } |
| 620 | l = Math.max(0.3f, l); |
| 621 | l = Math.min(1.0f, l); |
| 622 | |
| 623 | y += 0.1f * Math.cos(angle); |
| 624 | z += 0.1f * Math.sin(angle); |
| 625 | |
| 626 | float t = 0.1f * ct; |
| 627 | float ds = 0.08f; |
| 628 | tm.setColor(l, l, l, 0.99f); |
| 629 | tm.setTexture(ds, t); |
| 630 | tm.addVertex(-0.5f, y, z); |
| 631 | tm.setTexture(1 - ds, t); |
| 632 | tm.addVertex(0.5f, y, z); |
| 633 | } |
| 634 | for (int ct=0; ct < (200 * 2 - 2); ct+= 2) { |
| 635 | tm.addTriangle(ct, ct+1, ct+2); |
| 636 | tm.addTriangle(ct+1, ct+3, ct+2); |
| 637 | } |
| 638 | mMesh2 = tm.create(); |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 639 | mMesh2.setName("SMMesh"); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 640 | } |
| 641 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 642 | private void initProgramVertex() { |
| 643 | ProgramVertex.MatrixAllocation pva = new ProgramVertex.MatrixAllocation(mRS); |
| 644 | pva.setupProjectionNormalized(mWidth, mHeight); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 645 | |
| 646 | ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null); |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 647 | pvb.setTextureMatrixEnable(true); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 648 | mPV = pvb.create(); |
| 649 | mPV.setName("PV"); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 650 | mPV.bindAllocation(pva); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 651 | |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 652 | //pva = new ProgramVertex.MatrixAllocation(mRS); |
| 653 | //pva.setupOrthoWindow(mWidth, mHeight); |
| 654 | //pvb.setTextureMatrixEnable(true); |
| 655 | //mPVOrtho = pvb.create(); |
| 656 | //mPVOrtho.setName("PVOrtho"); |
| 657 | //mPVOrtho.bindAllocation(pva); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 658 | |
| 659 | mRS.contextBindProgramVertex(mPV); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 660 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 661 | |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 662 | private void initProgramFragment() { |
| 663 | Sampler.Builder sb = new Sampler.Builder(mRS); |
| 664 | sb.setMin(Sampler.Value.LINEAR); |
| 665 | sb.setMag(Sampler.Value.LINEAR); |
| 666 | sb.setWrapS(Sampler.Value.CLAMP); |
| 667 | sb.setWrapT(Sampler.Value.CLAMP); |
| 668 | Sampler linear = sb.create(); |
| 669 | |
| 670 | sb.setMin(Sampler.Value.NEAREST); |
| 671 | sb.setMag(Sampler.Value.NEAREST); |
| 672 | Sampler nearest = sb.create(); |
| 673 | |
| 674 | ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null); |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 675 | //mPFColor = bf.create(); |
| 676 | //mPFColor.setName("PFColor"); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 677 | |
| 678 | bf.setTexEnable(true, 0); |
| 679 | bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0); |
| 680 | mPFTexLinear = bf.create(); |
| 681 | mPFTexLinear.setName("PFTexLinear"); |
| 682 | mPFTexLinear.bindSampler(linear, 0); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | private void initProgramStore() { |
| 686 | ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null); |
| 687 | bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 688 | bs.setColorMask(true,true,true,false); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 689 | bs.setDitherEnable(true); |
| 690 | bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, |
| 691 | ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA); |
| 692 | mPSIcons = bs.create(); |
| 693 | mPSIcons.setName("PSIcons"); |
| 694 | |
| 695 | //bs.setDitherEnable(false); |
| 696 | //mPSText = bs.create(); |
| 697 | //mPSText.setName("PSText"); |
| 698 | } |
| 699 | |
| 700 | private void initGl() { |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 701 | mTouchXBorders = new int[Defines.COLUMNS_PER_PAGE+1]; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 702 | mTouchYBorders = new int[Defines.ROWS_PER_PAGE+1]; |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 703 | } |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 704 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 705 | private void initData() { |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 706 | mParams = new Params(); |
| 707 | mState = new State(); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 708 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 709 | final Utilities.BubbleText bubble = new Utilities.BubbleText(getContext()); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 710 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 711 | mParams.bubbleWidth = bubble.getBubbleWidth(); |
| 712 | mParams.bubbleHeight = bubble.getMaxBubbleHeight(); |
| 713 | mParams.bubbleBitmapWidth = bubble.getBitmapWidth(); |
| 714 | mParams.bubbleBitmapHeight = bubble.getBitmapHeight(); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 715 | |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 716 | mHomeButtonNormal = Allocation.createFromBitmapResource(mRS, mRes, |
| 717 | R.drawable.home_button_normal, Element.RGBA_8888(mRS), false); |
| 718 | mHomeButtonNormal.uploadToTexture(0); |
| 719 | mHomeButtonPressed = Allocation.createFromBitmapResource(mRS, mRes, |
| 720 | R.drawable.home_button_pressed, Element.RGBA_8888(mRS), false); |
| 721 | mHomeButtonPressed.uploadToTexture(0); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 722 | mParams.homeButtonWidth = 76; |
| 723 | mParams.homeButtonHeight = 68; |
| 724 | mParams.homeButtonTextureWidth = 128; |
| 725 | mParams.homeButtonTextureHeight = 128; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 726 | |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 727 | mState.homeButtonId = mHomeButtonNormal.getID(); |
| 728 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 729 | mParams.save(); |
| 730 | mState.save(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 731 | |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 732 | mSelectionBitmap = Bitmap.createBitmap(Defines.ICON_TEXTURE_WIDTH_PX, |
| 733 | Defines.ICON_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888); |
| 734 | mSelectionCanvas = new Canvas(mSelectionBitmap); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 735 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 736 | setApps(null); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 737 | } |
| 738 | |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 739 | private void initScript(int id) { |
| 740 | } |
| 741 | |
| 742 | private void initRs() { |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 743 | ScriptC.Builder sb = new ScriptC.Builder(mRS); |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 744 | sb.setScript(mRes, R.raw.rollo3); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 745 | sb.setRoot(true); |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 746 | sb.addDefines(mDefines); |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 747 | sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS); |
| 748 | sb.setType(mState.mType, "state", Defines.ALLOC_STATE); |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 749 | mInvokeMove = sb.addInvokable("move"); |
| 750 | mInvokeFling = sb.addInvokable("fling"); |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 751 | mInvokeMoveTo = sb.addInvokable("moveTo"); |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 752 | mInvokeResetWAR = sb.addInvokable("resetHWWar"); |
| 753 | mScript = sb.create(); |
| 754 | mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 755 | mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS); |
| 756 | mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE); |
| 757 | mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS); |
| 758 | mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 759 | |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame] | 760 | mMessageProc = new AAMessage(); |
| 761 | mRS.mMessageCallback = mMessageProc; |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 762 | mRS.contextBindRootScript(mScript); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 763 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 764 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 765 | private void setApps(ArrayList<ApplicationInfo> list) { |
| 766 | final int count = list != null ? list.size() : 0; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 767 | int allocCount = count; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 768 | if (allocCount < 1) { |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 769 | allocCount = 1; |
| 770 | } |
| 771 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 772 | mIcons = new Allocation[count]; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 773 | mIconIds = new int[allocCount]; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 774 | mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 775 | |
| 776 | mLabels = new Allocation[count]; |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 777 | mLabelIds = new int[allocCount]; |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 778 | mAllocLabelIds = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 779 | |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 780 | Element ie8888 = Element.RGBA_8888(mRS); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 781 | |
| 782 | Utilities.BubbleText bubble = new Utilities.BubbleText(getContext()); |
| 783 | |
| 784 | for (int i=0; i<count; i++) { |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 785 | uploadAppIcon(i, list.get(i)); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 786 | } |
| 787 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 788 | mState.iconCount = count; |
| 789 | |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 790 | saveAppsList(); |
| 791 | } |
| 792 | |
| 793 | private void uploadAppIcon(int index, ApplicationInfo item) { |
| 794 | mIcons[index] = Allocation.createFromBitmap(mRS, item.iconBitmap, |
| 795 | Element.RGBA_8888(mRS), false); |
| 796 | mLabels[index] = Allocation.createFromBitmap(mRS, item.titleBitmap, |
| 797 | Element.RGBA_8888(mRS), false); |
| 798 | |
| 799 | mIcons[index].uploadToTexture(0); |
| 800 | mLabels[index].uploadToTexture(0); |
| 801 | |
| 802 | mIconIds[index] = mIcons[index].getID(); |
| 803 | mLabelIds[index] = mLabels[index].getID(); |
| 804 | } |
| 805 | |
| 806 | /** |
| 807 | * Puts the empty spaces at the end. Updates mState.iconCount. You must |
| 808 | * fill in the values and call saveAppsList(). |
| 809 | */ |
| 810 | private void reallocAppsList(int count) { |
| 811 | Allocation[] icons = new Allocation[count]; |
| 812 | int[] iconIds = new int[count]; |
| 813 | mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), count); |
| 814 | |
| 815 | Allocation[] labels = new Allocation[count]; |
| 816 | int[] labelIds = new int[count]; |
| 817 | mAllocLabelIds = Allocation.createSized(mRS, Element.USER_I32(mRS), count); |
| 818 | |
| 819 | final int oldCount = mIcons.length; |
| 820 | |
| 821 | System.arraycopy(mIcons, 0, icons, 0, oldCount); |
| 822 | System.arraycopy(mIconIds, 0, iconIds, 0, oldCount); |
| 823 | System.arraycopy(mLabels, 0, labels, 0, oldCount); |
| 824 | System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount); |
| 825 | |
| 826 | mIcons = icons; |
| 827 | mIconIds = iconIds; |
| 828 | mLabels = labels; |
| 829 | mLabelIds = labelIds; |
| 830 | } |
| 831 | |
| 832 | /** |
| 833 | * Handle the allocations for the new app. Make sure you call saveAppsList when done. |
| 834 | */ |
| 835 | private void addApp(int index, ApplicationInfo item) { |
| 836 | final int count = mState.iconCount - index; |
| 837 | final int dest = index + 1; |
| 838 | |
| 839 | System.arraycopy(mIcons, index, mIcons, dest, count); |
| 840 | System.arraycopy(mIconIds, index, mIconIds, dest, count); |
| 841 | System.arraycopy(mLabels, index, mLabels, dest, count); |
| 842 | System.arraycopy(mLabelIds, index, mLabelIds, dest, count); |
| 843 | |
| 844 | uploadAppIcon(index, item); |
| 845 | } |
| 846 | |
| 847 | /** |
| 848 | * Handle the allocations for the removed app. Make sure you call saveAppsList when done. |
| 849 | */ |
| 850 | private void removeApp(int index) { |
| 851 | final int count = mState.iconCount - index - 1; |
| 852 | final int src = index + 1; |
| 853 | |
| 854 | System.arraycopy(mIcons, src, mIcons, index, count); |
| 855 | System.arraycopy(mIconIds, src, mIconIds, index, count); |
| 856 | System.arraycopy(mLabels, src, mLabels, index, count); |
| 857 | System.arraycopy(mLabelIds, src, mLabelIds, index, count); |
| 858 | |
| 859 | final int last = mState.iconCount - 1; |
| 860 | mIcons[last] = null; |
| 861 | mIconIds[last] = 0; |
| 862 | mLabels[last] = null; |
| 863 | mLabelIds[last] = 0; |
| 864 | } |
| 865 | |
| 866 | /** |
| 867 | * Send the apps list structures to RS. |
| 868 | */ |
| 869 | private void saveAppsList() { |
| 870 | mRS.contextBindRootScript(null); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 871 | |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 872 | mAllocIconIds.data(mIconIds); |
| 873 | mAllocLabelIds.data(mLabelIds); |
| 874 | |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 875 | if (mScript != null) { // this happens when we init it |
| 876 | mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS); |
| 877 | mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | mState.save(); |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 881 | |
| 882 | // Note: mScript may be null if we haven't initialized it yet. |
| 883 | // In that case, this is a no-op. |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 884 | if (mInvokeResetWAR != null) { |
| 885 | mInvokeResetWAR.execute(); |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 886 | } |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 887 | mRS.contextBindRootScript(mScript); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 888 | } |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 889 | |
| 890 | void initTouchState() { |
| 891 | int width = getWidth(); |
| 892 | int height = getHeight(); |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 893 | int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE; |
| 894 | int cellWidth = width / Defines.COLUMNS_PER_PAGE; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 895 | |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 896 | int centerY = (height / 2); |
| 897 | mTouchYBorders[0] = centerY - (cellHeight * 2); |
| 898 | mTouchYBorders[1] = centerY - cellHeight; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 899 | mTouchYBorders[2] = centerY; |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 900 | mTouchYBorders[3] = centerY + cellHeight; |
| 901 | mTouchYBorders[4] = centerY + (cellHeight * 2); |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 902 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 903 | int centerX = (width / 2); |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 904 | mTouchXBorders[0] = 0; |
| 905 | mTouchXBorders[1] = centerX - (width / 4); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 906 | mTouchXBorders[2] = centerX; |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 907 | mTouchXBorders[3] = centerX + (width / 4); |
| 908 | mTouchXBorders[4] = width; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 911 | int chooseTappedIcon(int x, int y, float pos) { |
| 912 | // Adjust for scroll position if not zero. |
| 913 | y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]); |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 914 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 915 | int col = -1; |
| 916 | int row = -1; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 917 | for (int i=0; i<Defines.COLUMNS_PER_PAGE; i++) { |
| 918 | if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) { |
| 919 | col = i; |
| 920 | break; |
| 921 | } |
| 922 | } |
| 923 | for (int i=0; i<Defines.ROWS_PER_PAGE; i++) { |
| 924 | if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) { |
| 925 | row = i; |
| 926 | break; |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | if (row < 0 || col < 0) { |
| 931 | return -1; |
| 932 | } |
| 933 | |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 934 | return (((int)pos) * Defines.COLUMNS_PER_PAGE) |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 935 | + (row * Defines.ROWS_PER_PAGE) + col; |
| 936 | } |
| 937 | |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 938 | void fling() { |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 939 | mInvokeFling.execute(); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | void move() { |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 943 | mInvokeMove.execute(); |
Jason Sams | d8152b9 | 2009-10-13 17:19:10 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 946 | void moveTo(float row) { |
| 947 | mState.targetPos = row; |
| 948 | mState.save(); |
| 949 | mInvokeMoveTo.execute(); |
| 950 | } |
| 951 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 952 | /** |
| 953 | * 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] | 954 | * |
| 955 | * @return the index of the icon that was selected. |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 956 | */ |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 957 | int selectIcon(int x, int y, float pos) { |
| 958 | final int index = chooseTappedIcon(x, y, pos); |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 959 | selectIcon(index); |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 960 | return index; |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | void selectIcon(int index) { |
Joe Onorato | 82ca550 | 2009-10-15 16:59:23 -0700 | [diff] [blame] | 964 | if (index < 0) { |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 965 | mState.selectedIconIndex = -1; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 966 | } else { |
| 967 | mState.selectedIconIndex = index; |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 968 | |
| 969 | Bitmap selectionBitmap = mSelectionBitmap; |
| 970 | |
| 971 | Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas, |
| 972 | selectionBitmap.getWidth(), selectionBitmap.getHeight(), |
| 973 | mAllAppsList.get(index).iconBitmap); |
| 974 | |
| 975 | mSelectedIcon = Allocation.createFromBitmap(mRS, selectionBitmap, |
Jason Sams | 0a8dc2c | 2009-09-27 17:51:44 -0700 | [diff] [blame] | 976 | Element.RGBA_8888(mRS), false); |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 977 | mSelectedIcon.uploadToTexture(0); |
| 978 | mState.selectedIconTexture = mSelectedIcon.getID(); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 979 | } |
| 980 | } |
| 981 | |
| 982 | /** |
| 983 | * You need to call save() on mState on your own after calling this. |
| 984 | */ |
| 985 | void clearSelectedIcon() { |
Joe Onorato | 2ca51dc | 2009-09-16 11:44:14 -0400 | [diff] [blame] | 986 | mState.selectedIconIndex = -1; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 987 | } |
Joe Onorato | a8138d5 | 2009-10-06 19:25:30 -0700 | [diff] [blame] | 988 | |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 989 | void setHomeSelected(boolean pressed) { |
| 990 | if (pressed) { |
| 991 | mState.homeButtonId = mHomeButtonPressed.getID(); |
| 992 | } else { |
| 993 | mState.homeButtonId = mHomeButtonNormal.getID(); |
| 994 | } |
| 995 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 996 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | |