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