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