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