Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 19 | import java.util.ArrayList; |
| 20 | import java.util.HashMap; |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 21 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 22 | import android.content.Context; |
Adam Cohen | 9c4949e | 2010-10-05 12:27:22 -0700 | [diff] [blame] | 23 | import android.content.res.TypedArray; |
Winson Chung | 241c3b4 | 2010-08-25 16:53:03 -0700 | [diff] [blame] | 24 | import android.graphics.Bitmap; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 25 | import android.graphics.Canvas; |
| 26 | import android.graphics.Rect; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 27 | import android.os.Parcel; |
| 28 | import android.os.Parcelable; |
| 29 | import android.util.AttributeSet; |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 30 | import android.view.ActionMode; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 31 | import android.view.MotionEvent; |
| 32 | import android.view.VelocityTracker; |
| 33 | import android.view.View; |
| 34 | import android.view.ViewConfiguration; |
| 35 | import android.view.ViewGroup; |
| 36 | import android.view.ViewParent; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 37 | import android.view.animation.Animation; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 38 | import android.view.animation.AnimationUtils; |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 39 | import android.view.animation.Animation.AnimationListener; |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 40 | import android.widget.Checkable; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 41 | import android.widget.Scroller; |
| 42 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 43 | import com.android.launcher.R; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 44 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 45 | /** |
| 46 | * An abstraction of the original Workspace which supports browsing through a |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 47 | * sequential list of "pages" |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 48 | */ |
| 49 | public abstract class PagedView extends ViewGroup { |
| 50 | private static final String TAG = "PagedView"; |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 51 | protected static final int INVALID_PAGE = -1; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 52 | |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 53 | // the min drag distance for a fling to register, to prevent random page shifts |
Winson Chung | 9cfd25f | 2010-10-24 16:09:28 -0700 | [diff] [blame] | 54 | private static final int MIN_LENGTH_FOR_FLING = 25; |
| 55 | // The min drag distance to trigger a page shift (regardless of velocity) |
| 56 | private static final int MIN_LENGTH_FOR_MOVE = 200; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 57 | |
Winson Chung | e22a8e9 | 2010-11-12 13:40:58 -0800 | [diff] [blame] | 58 | private static final int PAGE_SNAP_ANIMATION_DURATION = 750; |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 59 | protected static final float NANOTIME_DIV = 1000000000.0f; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 60 | |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 61 | private static final float OVERSCROLL_DAMP_FACTOR = 0.22f; |
| 62 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 63 | // the velocity at which a fling gesture will cause us to snap to the next page |
| 64 | protected int mSnapVelocity = 500; |
| 65 | |
| 66 | protected float mSmoothingTime; |
| 67 | protected float mTouchX; |
| 68 | |
| 69 | protected boolean mFirstLayout = true; |
| 70 | |
| 71 | protected int mCurrentPage; |
| 72 | protected int mNextPage = INVALID_PAGE; |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 73 | protected int mMaxScrollX; |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 74 | protected Scroller mScroller; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 75 | private VelocityTracker mVelocityTracker; |
| 76 | |
| 77 | private float mDownMotionX; |
Michael Jurka | 7426c42 | 2010-11-11 15:23:47 -0800 | [diff] [blame] | 78 | protected float mLastMotionX; |
| 79 | protected float mLastMotionY; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 80 | private int mLastScreenCenter = -1; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 81 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 82 | protected final static int TOUCH_STATE_REST = 0; |
| 83 | protected final static int TOUCH_STATE_SCROLLING = 1; |
| 84 | protected final static int TOUCH_STATE_PREV_PAGE = 2; |
| 85 | protected final static int TOUCH_STATE_NEXT_PAGE = 3; |
Adam Cohen | e45440e | 2010-10-14 18:33:38 -0700 | [diff] [blame] | 86 | protected final static float ALPHA_QUANTIZE_LEVEL = 0.0001f; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 87 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 88 | protected int mTouchState = TOUCH_STATE_REST; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 89 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 90 | protected OnLongClickListener mLongClickListener; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 91 | |
Michael Jurka | 7426c42 | 2010-11-11 15:23:47 -0800 | [diff] [blame] | 92 | protected boolean mAllowLongPress = true; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 93 | |
Michael Jurka | 7426c42 | 2010-11-11 15:23:47 -0800 | [diff] [blame] | 94 | protected int mTouchSlop; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 95 | private int mPagingTouchSlop; |
| 96 | private int mMaximumVelocity; |
Adam Cohen | 9c4949e | 2010-10-05 12:27:22 -0700 | [diff] [blame] | 97 | protected int mPageSpacing; |
| 98 | protected int mPageLayoutPaddingTop; |
| 99 | protected int mPageLayoutPaddingBottom; |
| 100 | protected int mPageLayoutPaddingLeft; |
| 101 | protected int mPageLayoutPaddingRight; |
Winson Chung | df4b83d | 2010-10-20 17:49:27 -0700 | [diff] [blame] | 102 | protected int mPageLayoutWidthGap; |
| 103 | protected int mPageLayoutHeightGap; |
Adam Cohen | 9c4949e | 2010-10-05 12:27:22 -0700 | [diff] [blame] | 104 | protected int mCellCountX; |
| 105 | protected int mCellCountY; |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 106 | protected boolean mCenterPagesVertically; |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 107 | protected boolean mAllowOverScroll = true; |
| 108 | protected int mUnboundedScrollX; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 109 | |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 110 | protected static final int INVALID_POINTER = -1; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 111 | |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 112 | protected int mActivePointerId = INVALID_POINTER; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 113 | |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 114 | private PageSwitchListener mPageSwitchListener; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 115 | |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 116 | private ArrayList<Boolean> mDirtyPageContent; |
| 117 | private boolean mDirtyPageAlpha; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 118 | |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 119 | // choice modes |
| 120 | protected static final int CHOICE_MODE_NONE = 0; |
| 121 | protected static final int CHOICE_MODE_SINGLE = 1; |
| 122 | // Multiple selection mode is not supported by all Launcher actions atm |
| 123 | protected static final int CHOICE_MODE_MULTIPLE = 2; |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 124 | |
Michael Jurka | e17e19c | 2010-09-28 11:01:39 -0700 | [diff] [blame] | 125 | protected int mChoiceMode; |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 126 | private ActionMode mActionMode; |
| 127 | |
Winson Chung | 241c3b4 | 2010-08-25 16:53:03 -0700 | [diff] [blame] | 128 | protected PagedViewIconCache mPageViewIconCache; |
| 129 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 130 | // If true, syncPages and syncPageItems will be called to refresh pages |
| 131 | protected boolean mContentIsRefreshable = true; |
| 132 | |
| 133 | // If true, modify alpha of neighboring pages as user scrolls left/right |
| 134 | protected boolean mFadeInAdjacentScreens = true; |
| 135 | |
| 136 | // It true, use a different slop parameter (pagingTouchSlop = 2 * touchSlop) for deciding |
| 137 | // to switch to a new page |
| 138 | protected boolean mUsePagingTouchSlop = true; |
| 139 | |
| 140 | // If true, the subclass should directly update mScrollX itself in its computeScroll method |
| 141 | // (SmoothPagedView does this) |
| 142 | protected boolean mDeferScrollUpdate = false; |
| 143 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 144 | protected boolean mIsPageMoving = false; |
| 145 | |
Winson Chung | 241c3b4 | 2010-08-25 16:53:03 -0700 | [diff] [blame] | 146 | /** |
| 147 | * Simple cache mechanism for PagedViewIcon outlines. |
| 148 | */ |
| 149 | class PagedViewIconCache { |
| 150 | private final HashMap<Object, Bitmap> iconOutlineCache = new HashMap<Object, Bitmap>(); |
| 151 | |
| 152 | public void clear() { |
| 153 | iconOutlineCache.clear(); |
| 154 | } |
| 155 | public void addOutline(Object key, Bitmap b) { |
| 156 | iconOutlineCache.put(key, b); |
| 157 | } |
| 158 | public void removeOutline(Object key) { |
| 159 | if (iconOutlineCache.containsKey(key)) { |
| 160 | iconOutlineCache.remove(key); |
| 161 | } |
| 162 | } |
| 163 | public Bitmap getOutline(Object key) { |
| 164 | return iconOutlineCache.get(key); |
| 165 | } |
| 166 | } |
| 167 | |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 168 | public interface PageSwitchListener { |
| 169 | void onPageSwitch(View newPage, int newPageIndex); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 172 | public PagedView(Context context) { |
| 173 | this(context, null); |
| 174 | } |
| 175 | |
| 176 | public PagedView(Context context, AttributeSet attrs) { |
| 177 | this(context, attrs, 0); |
| 178 | } |
| 179 | |
| 180 | public PagedView(Context context, AttributeSet attrs, int defStyle) { |
| 181 | super(context, attrs, defStyle); |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 182 | mChoiceMode = CHOICE_MODE_NONE; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 183 | |
Adam Cohen | 9c4949e | 2010-10-05 12:27:22 -0700 | [diff] [blame] | 184 | TypedArray a = context.obtainStyledAttributes(attrs, |
| 185 | R.styleable.PagedView, defStyle, 0); |
| 186 | mPageSpacing = a.getDimensionPixelSize(R.styleable.PagedView_pageSpacing, 0); |
| 187 | mPageLayoutPaddingTop = a.getDimensionPixelSize( |
| 188 | R.styleable.PagedView_pageLayoutPaddingTop, 10); |
| 189 | mPageLayoutPaddingBottom = a.getDimensionPixelSize( |
| 190 | R.styleable.PagedView_pageLayoutPaddingBottom, 10); |
| 191 | mPageLayoutPaddingLeft = a.getDimensionPixelSize( |
| 192 | R.styleable.PagedView_pageLayoutPaddingLeft, 10); |
| 193 | mPageLayoutPaddingRight = a.getDimensionPixelSize( |
| 194 | R.styleable.PagedView_pageLayoutPaddingRight, 10); |
Winson Chung | df4b83d | 2010-10-20 17:49:27 -0700 | [diff] [blame] | 195 | mPageLayoutWidthGap = a.getDimensionPixelSize( |
| 196 | R.styleable.PagedView_pageLayoutWidthGap, -1); |
| 197 | mPageLayoutHeightGap = a.getDimensionPixelSize( |
| 198 | R.styleable.PagedView_pageLayoutHeightGap, -1); |
Adam Cohen | 9c4949e | 2010-10-05 12:27:22 -0700 | [diff] [blame] | 199 | a.recycle(); |
| 200 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 201 | setHapticFeedbackEnabled(false); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 202 | init(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Initializes various states for this workspace. |
| 207 | */ |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 208 | protected void init() { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 209 | mDirtyPageContent = new ArrayList<Boolean>(); |
| 210 | mDirtyPageContent.ensureCapacity(32); |
Winson Chung | 241c3b4 | 2010-08-25 16:53:03 -0700 | [diff] [blame] | 211 | mPageViewIconCache = new PagedViewIconCache(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 212 | mScroller = new Scroller(getContext()); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 213 | mCurrentPage = 0; |
Winson Chung | 7da1025 | 2010-10-28 16:07:04 -0700 | [diff] [blame] | 214 | mCenterPagesVertically = true; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 215 | |
| 216 | final ViewConfiguration configuration = ViewConfiguration.get(getContext()); |
| 217 | mTouchSlop = configuration.getScaledTouchSlop(); |
| 218 | mPagingTouchSlop = configuration.getScaledPagingTouchSlop(); |
| 219 | mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); |
| 220 | } |
| 221 | |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 222 | public void setPageSwitchListener(PageSwitchListener pageSwitchListener) { |
| 223 | mPageSwitchListener = pageSwitchListener; |
| 224 | if (mPageSwitchListener != null) { |
| 225 | mPageSwitchListener.onPageSwitch(getPageAt(mCurrentPage), mCurrentPage); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
| 229 | /** |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 230 | * Returns the index of the currently displayed page. |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 231 | * |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 232 | * @return The index of the currently displayed page. |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 233 | */ |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 234 | int getCurrentPage() { |
| 235 | return mCurrentPage; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 238 | int getPageCount() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 239 | return getChildCount(); |
| 240 | } |
| 241 | |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 242 | View getPageAt(int index) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 243 | return getChildAt(index); |
| 244 | } |
| 245 | |
| 246 | int getScrollWidth() { |
| 247 | return getWidth(); |
| 248 | } |
| 249 | |
| 250 | /** |
Winson Chung | bbc60d8 | 2010-11-11 16:34:41 -0800 | [diff] [blame] | 251 | * Updates the scroll of the current page immediately to its final scroll position. We use this |
| 252 | * in CustomizePagedView to allow tabs to share the same PagedView while resetting the scroll of |
| 253 | * the previous tab page. |
| 254 | */ |
| 255 | protected void updateCurrentPageScroll() { |
| 256 | int newX = getChildOffset(mCurrentPage) - getRelativeChildOffset(mCurrentPage); |
| 257 | scrollTo(newX, 0); |
| 258 | mScroller.setFinalX(newX); |
| 259 | } |
| 260 | |
| 261 | /** |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 262 | * Sets the current page. |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 263 | */ |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 264 | void setCurrentPage(int currentPage) { |
Patrick Dubroy | 72e0d34 | 2010-11-09 15:23:28 -0800 | [diff] [blame] | 265 | if (!mScroller.isFinished()) { |
| 266 | mScroller.abortAnimation(); |
| 267 | } |
| 268 | if (getChildCount() == 0 || currentPage == mCurrentPage) { |
| 269 | return; |
| 270 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 271 | |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 272 | mCurrentPage = Math.max(0, Math.min(currentPage, getPageCount() - 1)); |
Winson Chung | bbc60d8 | 2010-11-11 16:34:41 -0800 | [diff] [blame] | 273 | updateCurrentPageScroll(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 274 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 275 | invalidate(); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 276 | notifyPageSwitchListener(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 279 | protected void notifyPageSwitchListener() { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 280 | if (mPageSwitchListener != null) { |
| 281 | mPageSwitchListener.onPageSwitch(getPageAt(mCurrentPage), mCurrentPage); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 285 | private void pageBeginMoving() { |
| 286 | mIsPageMoving = true; |
| 287 | onPageBeginMoving(); |
| 288 | } |
| 289 | |
| 290 | private void pageEndMoving() { |
| 291 | onPageEndMoving(); |
| 292 | mIsPageMoving = false; |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | // a method that subclasses can override to add behavior |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 296 | protected void onPageBeginMoving() { |
| 297 | } |
| 298 | |
| 299 | // a method that subclasses can override to add behavior |
| 300 | protected void onPageEndMoving() { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 303 | /** |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 304 | * Registers the specified listener on each page contained in this workspace. |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 305 | * |
| 306 | * @param l The listener used to respond to long clicks. |
| 307 | */ |
| 308 | @Override |
| 309 | public void setOnLongClickListener(OnLongClickListener l) { |
| 310 | mLongClickListener = l; |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 311 | final int count = getPageCount(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 312 | for (int i = 0; i < count; i++) { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 313 | getPageAt(i).setOnLongClickListener(l); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
| 317 | @Override |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 318 | public void scrollBy(int x, int y) { |
| 319 | scrollTo(mUnboundedScrollX + x, mScrollY + y); |
| 320 | } |
| 321 | |
| 322 | @Override |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 323 | public void scrollTo(int x, int y) { |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 324 | mUnboundedScrollX = x; |
| 325 | |
| 326 | if (x < 0) { |
| 327 | super.scrollTo(0, y); |
| 328 | if (mAllowOverScroll) { |
| 329 | overScroll(x); |
| 330 | } |
| 331 | } else if (x > mMaxScrollX) { |
| 332 | super.scrollTo(mMaxScrollX, y); |
| 333 | if (mAllowOverScroll) { |
| 334 | overScroll(x - mMaxScrollX); |
| 335 | } |
| 336 | } else { |
| 337 | super.scrollTo(x, y); |
| 338 | } |
| 339 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 340 | mTouchX = x; |
| 341 | mSmoothingTime = System.nanoTime() / NANOTIME_DIV; |
| 342 | } |
| 343 | |
| 344 | // we moved this functionality to a helper function so SmoothPagedView can reuse it |
| 345 | protected boolean computeScrollHelper() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 346 | if (mScroller.computeScrollOffset()) { |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 347 | mDirtyPageAlpha = true; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 348 | scrollTo(mScroller.getCurrX(), mScroller.getCurrY()); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 349 | invalidate(); |
| 350 | return true; |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 351 | } else if (mNextPage != INVALID_PAGE) { |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 352 | mDirtyPageAlpha = true; |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 353 | mCurrentPage = Math.max(0, Math.min(mNextPage, getPageCount() - 1)); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 354 | mNextPage = INVALID_PAGE; |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 355 | notifyPageSwitchListener(); |
| 356 | pageEndMoving(); |
| 357 | return true; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 358 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 359 | return false; |
| 360 | } |
| 361 | |
| 362 | @Override |
| 363 | public void computeScroll() { |
| 364 | computeScrollHelper(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | @Override |
| 368 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 369 | final int widthMode = MeasureSpec.getMode(widthMeasureSpec); |
| 370 | final int widthSize = MeasureSpec.getSize(widthMeasureSpec); |
| 371 | if (widthMode != MeasureSpec.EXACTLY) { |
| 372 | throw new IllegalStateException("Workspace can only be used in EXACTLY mode."); |
| 373 | } |
| 374 | |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 375 | /* Allow the height to be set as WRAP_CONTENT. This allows the particular case |
| 376 | * of the All apps view on XLarge displays to not take up more space then it needs. Width |
| 377 | * is still not allowed to be set as WRAP_CONTENT since many parts of the code expect |
| 378 | * each page to have the same width. |
| 379 | */ |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 380 | final int heightMode = MeasureSpec.getMode(heightMeasureSpec); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 381 | int heightSize = MeasureSpec.getSize(heightMeasureSpec); |
| 382 | int maxChildHeight = 0; |
| 383 | |
| 384 | final int verticalPadding = mPaddingTop + mPaddingBottom; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 385 | |
| 386 | // The children are given the same width and height as the workspace |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 387 | // unless they were set to WRAP_CONTENT |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 388 | final int childCount = getChildCount(); |
| 389 | for (int i = 0; i < childCount; i++) { |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 390 | // disallowing padding in paged view (just pass 0) |
| 391 | final View child = getChildAt(i); |
| 392 | final LayoutParams lp = (LayoutParams) child.getLayoutParams(); |
| 393 | |
| 394 | int childWidthMode; |
| 395 | if (lp.width == LayoutParams.WRAP_CONTENT) { |
| 396 | childWidthMode = MeasureSpec.AT_MOST; |
| 397 | } else { |
| 398 | childWidthMode = MeasureSpec.EXACTLY; |
| 399 | } |
| 400 | |
| 401 | int childHeightMode; |
| 402 | if (lp.height == LayoutParams.WRAP_CONTENT) { |
| 403 | childHeightMode = MeasureSpec.AT_MOST; |
| 404 | } else { |
| 405 | childHeightMode = MeasureSpec.EXACTLY; |
| 406 | } |
| 407 | |
| 408 | final int childWidthMeasureSpec = |
| 409 | MeasureSpec.makeMeasureSpec(widthSize, childWidthMode); |
| 410 | final int childHeightMeasureSpec = |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 411 | MeasureSpec.makeMeasureSpec(heightSize - verticalPadding, childHeightMode); |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 412 | |
| 413 | child.measure(childWidthMeasureSpec, childHeightMeasureSpec); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 414 | maxChildHeight = Math.max(maxChildHeight, child.getMeasuredHeight()); |
| 415 | } |
| 416 | |
| 417 | if (heightMode == MeasureSpec.AT_MOST) { |
| 418 | heightSize = maxChildHeight + verticalPadding; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 419 | } |
Adam Cohen | faa2830 | 2010-11-19 12:02:18 -0800 | [diff] [blame^] | 420 | if (childCount > 0) { |
| 421 | mMaxScrollX = getChildOffset(childCount - 1) - getRelativeChildOffset(childCount - 1); |
| 422 | } else { |
| 423 | mMaxScrollX = 0; |
| 424 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 425 | |
| 426 | setMeasuredDimension(widthSize, heightSize); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | @Override |
Michael Jurka | 28750fb | 2010-09-24 17:43:49 -0700 | [diff] [blame] | 430 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Michael Jurka | cfc6294 | 2010-09-14 14:01:07 -0700 | [diff] [blame] | 431 | if (mFirstLayout && mCurrentPage >= 0 && mCurrentPage < getChildCount()) { |
| 432 | setHorizontalScrollBarEnabled(false); |
| 433 | int newX = getChildOffset(mCurrentPage) - getRelativeChildOffset(mCurrentPage); |
| 434 | scrollTo(newX, 0); |
| 435 | mScroller.setFinalX(newX); |
| 436 | setHorizontalScrollBarEnabled(true); |
| 437 | mFirstLayout = false; |
| 438 | } |
| 439 | |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 440 | final int verticalPadding = mPaddingTop + mPaddingBottom; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 441 | final int childCount = getChildCount(); |
| 442 | int childLeft = 0; |
| 443 | if (childCount > 0) { |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 444 | childLeft = getRelativeChildOffset(0); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | for (int i = 0; i < childCount; i++) { |
| 448 | final View child = getChildAt(i); |
| 449 | if (child.getVisibility() != View.GONE) { |
| 450 | final int childWidth = child.getMeasuredWidth(); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 451 | final int childHeight = child.getMeasuredHeight(); |
| 452 | int childTop = mPaddingTop; |
| 453 | if (mCenterPagesVertically) { |
| 454 | childTop += ((getMeasuredHeight() - verticalPadding) - childHeight) / 2; |
| 455 | } |
| 456 | child.layout(childLeft, childTop, |
| 457 | childLeft + childWidth, childTop + childHeight); |
Adam Cohen | 9c4949e | 2010-10-05 12:27:22 -0700 | [diff] [blame] | 458 | childLeft += childWidth + mPageSpacing; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 463 | protected void updateAdjacentPagesAlpha() { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 464 | if (mFadeInAdjacentScreens) { |
| 465 | if (mDirtyPageAlpha || (mTouchState == TOUCH_STATE_SCROLLING) || !mScroller.isFinished()) { |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 466 | int halfScreenSize = getMeasuredWidth() / 2; |
| 467 | int screenCenter = mScrollX + halfScreenSize; |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 468 | final int childCount = getChildCount(); |
| 469 | for (int i = 0; i < childCount; ++i) { |
| 470 | View layout = (View) getChildAt(i); |
| 471 | int childWidth = layout.getMeasuredWidth(); |
| 472 | int halfChildWidth = (childWidth / 2); |
| 473 | int childCenter = getChildOffset(i) + halfChildWidth; |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 474 | |
Winson Chung | b0b2e6f | 2010-10-12 17:49:56 -0700 | [diff] [blame] | 475 | // On the first layout, we may not have a width nor a proper offset, so for now |
| 476 | // we should just assume full page width (and calculate the offset according to |
| 477 | // that). |
| 478 | if (childWidth <= 0) { |
| 479 | childWidth = getMeasuredWidth(); |
| 480 | childCenter = (i * childWidth) + (childWidth / 2); |
| 481 | } |
| 482 | |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 483 | int d = halfChildWidth; |
| 484 | int distanceFromScreenCenter = childCenter - screenCenter; |
| 485 | if (distanceFromScreenCenter > 0) { |
| 486 | if (i > 0) { |
| 487 | d += getChildAt(i - 1).getMeasuredWidth() / 2; |
| 488 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 489 | } else { |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 490 | if (i < childCount - 1) { |
| 491 | d += getChildAt(i + 1).getMeasuredWidth() / 2; |
| 492 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 493 | } |
Adam Cohen | 9c4949e | 2010-10-05 12:27:22 -0700 | [diff] [blame] | 494 | d += mPageSpacing; |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 495 | |
Winson Chung | b0b2e6f | 2010-10-12 17:49:56 -0700 | [diff] [blame] | 496 | // Preventing potential divide-by-zero |
| 497 | d = Math.max(1, d); |
| 498 | |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 499 | float dimAlpha = (float) (Math.abs(distanceFromScreenCenter)) / d; |
| 500 | dimAlpha = Math.max(0.0f, Math.min(1.0f, (dimAlpha * dimAlpha))); |
| 501 | float alpha = 1.0f - dimAlpha; |
| 502 | |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 503 | if (alpha < ALPHA_QUANTIZE_LEVEL) { |
| 504 | alpha = 0.0f; |
| 505 | } else if (alpha > 1.0f - ALPHA_QUANTIZE_LEVEL) { |
| 506 | alpha = 1.0f; |
| 507 | } |
| 508 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 509 | if (Float.compare(alpha, layout.getAlpha()) != 0) { |
| 510 | layout.setAlpha(alpha); |
| 511 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 512 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 513 | mDirtyPageAlpha = false; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 514 | } |
| 515 | } |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 518 | protected void screenScrolled(int screenCenter) { |
| 519 | } |
| 520 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 521 | @Override |
| 522 | protected void dispatchDraw(Canvas canvas) { |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 523 | int halfScreenSize = getMeasuredWidth() / 2; |
| 524 | int screenCenter = mScrollX + halfScreenSize; |
| 525 | |
| 526 | if (screenCenter != mLastScreenCenter) { |
| 527 | screenScrolled(screenCenter); |
| 528 | updateAdjacentPagesAlpha(); |
| 529 | mLastScreenCenter = screenCenter; |
| 530 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 531 | |
| 532 | // Find out which screens are visible; as an optimization we only call draw on them |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 533 | // As an optimization, this code assumes that all pages have the same width as the 0th |
| 534 | // page. |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 535 | final int pageCount = getChildCount(); |
Michael Jurka | c4fb917 | 2010-09-02 17:19:20 -0700 | [diff] [blame] | 536 | if (pageCount > 0) { |
| 537 | final int pageWidth = getChildAt(0).getMeasuredWidth(); |
| 538 | final int screenWidth = getMeasuredWidth(); |
| 539 | int x = getRelativeChildOffset(0) + pageWidth; |
| 540 | int leftScreen = 0; |
| 541 | int rightScreen = 0; |
| 542 | while (x <= mScrollX) { |
| 543 | leftScreen++; |
Adam Cohen | 9c4949e | 2010-10-05 12:27:22 -0700 | [diff] [blame] | 544 | x += pageWidth + mPageSpacing; |
Michael Jurka | c4fb917 | 2010-09-02 17:19:20 -0700 | [diff] [blame] | 545 | // replace above line with this if you don't assume all pages have same width as 0th |
| 546 | // page: |
| 547 | // x += getChildAt(leftScreen).getMeasuredWidth(); |
| 548 | } |
| 549 | rightScreen = leftScreen; |
| 550 | while (x < mScrollX + screenWidth) { |
| 551 | rightScreen++; |
Adam Cohen | 9c4949e | 2010-10-05 12:27:22 -0700 | [diff] [blame] | 552 | x += pageWidth + mPageSpacing; |
Michael Jurka | c4fb917 | 2010-09-02 17:19:20 -0700 | [diff] [blame] | 553 | // replace above line with this if you don't assume all pages have same width as 0th |
| 554 | // page: |
| 555 | //if (rightScreen < pageCount) { |
| 556 | // x += getChildAt(rightScreen).getMeasuredWidth(); |
| 557 | //} |
| 558 | } |
| 559 | rightScreen = Math.min(getChildCount() - 1, rightScreen); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 560 | |
Michael Jurka | c4fb917 | 2010-09-02 17:19:20 -0700 | [diff] [blame] | 561 | final long drawingTime = getDrawingTime(); |
| 562 | for (int i = leftScreen; i <= rightScreen; i++) { |
| 563 | drawChild(canvas, getChildAt(i), drawingTime); |
| 564 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 565 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | @Override |
| 569 | public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 570 | int page = indexOfChild(child); |
| 571 | if (page != mCurrentPage || !mScroller.isFinished()) { |
| 572 | snapToPage(page); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 573 | return true; |
| 574 | } |
| 575 | return false; |
| 576 | } |
| 577 | |
| 578 | @Override |
| 579 | protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 580 | int focusablePage; |
| 581 | if (mNextPage != INVALID_PAGE) { |
| 582 | focusablePage = mNextPage; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 583 | } else { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 584 | focusablePage = mCurrentPage; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 585 | } |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 586 | View v = getPageAt(focusablePage); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 587 | if (v != null) { |
| 588 | v.requestFocus(direction, previouslyFocusedRect); |
| 589 | } |
| 590 | return false; |
| 591 | } |
| 592 | |
| 593 | @Override |
| 594 | public boolean dispatchUnhandledMove(View focused, int direction) { |
| 595 | if (direction == View.FOCUS_LEFT) { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 596 | if (getCurrentPage() > 0) { |
| 597 | snapToPage(getCurrentPage() - 1); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 598 | return true; |
| 599 | } |
| 600 | } else if (direction == View.FOCUS_RIGHT) { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 601 | if (getCurrentPage() < getPageCount() - 1) { |
| 602 | snapToPage(getCurrentPage() + 1); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 603 | return true; |
| 604 | } |
| 605 | } |
| 606 | return super.dispatchUnhandledMove(focused, direction); |
| 607 | } |
| 608 | |
| 609 | @Override |
| 610 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 611 | if (mCurrentPage >= 0 && mCurrentPage < getPageCount()) { |
| 612 | getPageAt(mCurrentPage).addFocusables(views, direction); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 613 | } |
| 614 | if (direction == View.FOCUS_LEFT) { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 615 | if (mCurrentPage > 0) { |
| 616 | getPageAt(mCurrentPage - 1).addFocusables(views, direction); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 617 | } |
| 618 | } else if (direction == View.FOCUS_RIGHT){ |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 619 | if (mCurrentPage < getPageCount() - 1) { |
| 620 | getPageAt(mCurrentPage + 1).addFocusables(views, direction); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | /** |
| 626 | * If one of our descendant views decides that it could be focused now, only |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 627 | * pass that along if it's on the current page. |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 628 | * |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 629 | * This happens when live folders requery, and if they're off page, they |
| 630 | * end up calling requestFocus, which pulls it on page. |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 631 | */ |
| 632 | @Override |
| 633 | public void focusableViewAvailable(View focused) { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 634 | View current = getPageAt(mCurrentPage); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 635 | View v = focused; |
| 636 | while (true) { |
| 637 | if (v == current) { |
| 638 | super.focusableViewAvailable(focused); |
| 639 | return; |
| 640 | } |
| 641 | if (v == this) { |
| 642 | return; |
| 643 | } |
| 644 | ViewParent parent = v.getParent(); |
| 645 | if (parent instanceof View) { |
| 646 | v = (View)v.getParent(); |
| 647 | } else { |
| 648 | return; |
| 649 | } |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * {@inheritDoc} |
| 655 | */ |
| 656 | @Override |
| 657 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
| 658 | if (disallowIntercept) { |
| 659 | // We need to make sure to cancel our long press if |
| 660 | // a scrollable widget takes over touch events |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 661 | final View currentPage = getChildAt(mCurrentPage); |
| 662 | currentPage.cancelLongPress(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 663 | } |
| 664 | super.requestDisallowInterceptTouchEvent(disallowIntercept); |
| 665 | } |
| 666 | |
| 667 | @Override |
| 668 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 669 | /* |
| 670 | * This method JUST determines whether we want to intercept the motion. |
| 671 | * If we return true, onTouchEvent will be called and we do the actual |
| 672 | * scrolling there. |
| 673 | */ |
| 674 | |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 675 | // Skip touch handling if there are no pages to swipe |
| 676 | if (getChildCount() <= 0) return super.onInterceptTouchEvent(ev); |
| 677 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 678 | /* |
| 679 | * Shortcut the most recurring case: the user is in the dragging |
| 680 | * state and he is moving his finger. We want to intercept this |
| 681 | * motion. |
| 682 | */ |
| 683 | final int action = ev.getAction(); |
| 684 | if ((action == MotionEvent.ACTION_MOVE) && |
| 685 | (mTouchState == TOUCH_STATE_SCROLLING)) { |
| 686 | return true; |
| 687 | } |
| 688 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 689 | switch (action & MotionEvent.ACTION_MASK) { |
| 690 | case MotionEvent.ACTION_MOVE: { |
| 691 | /* |
| 692 | * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check |
| 693 | * whether the user has moved far enough from his original down touch. |
| 694 | */ |
Michael Jurka | 1ff706b | 2010-09-14 17:35:20 -0700 | [diff] [blame] | 695 | if (mActivePointerId != INVALID_POINTER) { |
| 696 | determineScrollingStart(ev); |
| 697 | break; |
| 698 | } |
| 699 | // if mActivePointerId is INVALID_POINTER, then we must have missed an ACTION_DOWN |
| 700 | // event. in that case, treat the first occurence of a move event as a ACTION_DOWN |
| 701 | // i.e. fall through to the next case (don't break) |
| 702 | // (We sometimes miss ACTION_DOWN events in Workspace because it ignores all events |
| 703 | // while it's small- this was causing a crash before we checked for INVALID_POINTER) |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | case MotionEvent.ACTION_DOWN: { |
| 707 | final float x = ev.getX(); |
| 708 | final float y = ev.getY(); |
| 709 | // Remember location of down touch |
| 710 | mDownMotionX = x; |
| 711 | mLastMotionX = x; |
| 712 | mLastMotionY = y; |
| 713 | mActivePointerId = ev.getPointerId(0); |
| 714 | mAllowLongPress = true; |
| 715 | |
| 716 | /* |
| 717 | * If being flinged and user touches the screen, initiate drag; |
| 718 | * otherwise don't. mScroller.isFinished should be false when |
| 719 | * being flinged. |
| 720 | */ |
Michael Jurka | fd177c1 | 2010-10-19 15:50:43 -0700 | [diff] [blame] | 721 | final int xDist = Math.abs(mScroller.getFinalX() - mScroller.getCurrX()); |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 722 | final boolean finishedScrolling = (mScroller.isFinished() || xDist < mTouchSlop); |
| 723 | if (finishedScrolling) { |
| 724 | mTouchState = TOUCH_STATE_REST; |
| 725 | mScroller.abortAnimation(); |
| 726 | } else { |
| 727 | mTouchState = TOUCH_STATE_SCROLLING; |
| 728 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 729 | |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 730 | // check if this can be the beginning of a tap on the side of the pages |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 731 | // to scroll the current page |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 732 | if ((mTouchState != TOUCH_STATE_PREV_PAGE) && !handlePagingClicks() && |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 733 | (mTouchState != TOUCH_STATE_NEXT_PAGE)) { |
| 734 | if (getChildCount() > 0) { |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 735 | int width = getMeasuredWidth(); |
| 736 | int offset = getRelativeChildOffset(mCurrentPage); |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 737 | if (x < offset - mPageSpacing) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 738 | mTouchState = TOUCH_STATE_PREV_PAGE; |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 739 | } else if (x > (width - offset + mPageSpacing)) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 740 | mTouchState = TOUCH_STATE_NEXT_PAGE; |
| 741 | } |
| 742 | } |
| 743 | } |
| 744 | break; |
| 745 | } |
| 746 | |
| 747 | case MotionEvent.ACTION_CANCEL: |
| 748 | case MotionEvent.ACTION_UP: |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 749 | mTouchState = TOUCH_STATE_REST; |
| 750 | mAllowLongPress = false; |
| 751 | mActivePointerId = INVALID_POINTER; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 752 | break; |
| 753 | |
| 754 | case MotionEvent.ACTION_POINTER_UP: |
| 755 | onSecondaryPointerUp(ev); |
| 756 | break; |
| 757 | } |
| 758 | |
| 759 | /* |
| 760 | * The only time we want to intercept motion events is if we are in the |
| 761 | * drag mode. |
| 762 | */ |
| 763 | return mTouchState != TOUCH_STATE_REST; |
| 764 | } |
| 765 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 766 | protected void animateClickFeedback(View v, final Runnable r) { |
| 767 | // animate the view slightly to show click feedback running some logic after it is "pressed" |
| 768 | Animation anim = AnimationUtils.loadAnimation(getContext(), |
| 769 | R.anim.paged_view_click_feedback); |
| 770 | anim.setAnimationListener(new AnimationListener() { |
| 771 | @Override |
| 772 | public void onAnimationStart(Animation animation) {} |
| 773 | @Override |
| 774 | public void onAnimationRepeat(Animation animation) { |
| 775 | r.run(); |
| 776 | } |
| 777 | @Override |
| 778 | public void onAnimationEnd(Animation animation) {} |
| 779 | }); |
| 780 | v.startAnimation(anim); |
| 781 | } |
| 782 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 783 | /* |
| 784 | * Determines if we should change the touch state to start scrolling after the |
| 785 | * user moves their touch point too far. |
| 786 | */ |
Michael Jurka | 1adf539 | 2010-10-18 18:10:22 -0700 | [diff] [blame] | 787 | protected void determineScrollingStart(MotionEvent ev) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 788 | /* |
| 789 | * Locally do absolute value. mLastMotionX is set to the y value |
| 790 | * of the down event. |
| 791 | */ |
| 792 | final int pointerIndex = ev.findPointerIndex(mActivePointerId); |
| 793 | final float x = ev.getX(pointerIndex); |
| 794 | final float y = ev.getY(pointerIndex); |
| 795 | final int xDiff = (int) Math.abs(x - mLastMotionX); |
| 796 | final int yDiff = (int) Math.abs(y - mLastMotionY); |
| 797 | |
| 798 | final int touchSlop = mTouchSlop; |
| 799 | boolean xPaged = xDiff > mPagingTouchSlop; |
| 800 | boolean xMoved = xDiff > touchSlop; |
| 801 | boolean yMoved = yDiff > touchSlop; |
| 802 | |
| 803 | if (xMoved || yMoved) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 804 | if (mUsePagingTouchSlop ? xPaged : xMoved) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 805 | // Scroll if the user moved far enough along the X axis |
| 806 | mTouchState = TOUCH_STATE_SCROLLING; |
| 807 | mLastMotionX = x; |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 808 | mTouchX = mScrollX; |
| 809 | mSmoothingTime = System.nanoTime() / NANOTIME_DIV; |
| 810 | pageBeginMoving(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 811 | } |
| 812 | // Either way, cancel any pending longpress |
| 813 | if (mAllowLongPress) { |
| 814 | mAllowLongPress = false; |
| 815 | // Try canceling the long press. It could also have been scheduled |
| 816 | // by a distant descendant, so use the mAllowLongPress flag to block |
| 817 | // everything |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 818 | final View currentPage = getPageAt(mCurrentPage); |
Winson Chung | 10fefb1 | 2010-11-01 11:57:06 -0700 | [diff] [blame] | 819 | if (currentPage != null) { |
| 820 | currentPage.cancelLongPress(); |
| 821 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 822 | } |
| 823 | } |
| 824 | } |
| 825 | |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 826 | protected boolean handlePagingClicks() { |
| 827 | return false; |
| 828 | } |
| 829 | |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 830 | protected void overScroll(float amount) { |
| 831 | int overScrollAmount = (int) Math.round(OVERSCROLL_DAMP_FACTOR * amount); |
| 832 | if (amount < 0) { |
| 833 | mScrollX = overScrollAmount; |
| 834 | } else { |
| 835 | mScrollX = mMaxScrollX + overScrollAmount; |
| 836 | } |
| 837 | invalidate(); |
| 838 | } |
| 839 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 840 | @Override |
| 841 | public boolean onTouchEvent(MotionEvent ev) { |
Winson Chung | 45e1d6e | 2010-11-09 17:19:49 -0800 | [diff] [blame] | 842 | // Skip touch handling if there are no pages to swipe |
| 843 | if (getChildCount() <= 0) return super.onTouchEvent(ev); |
| 844 | |
Michael Jurka | b8f0672 | 2010-10-10 15:58:46 -0700 | [diff] [blame] | 845 | acquireVelocityTrackerAndAddMovement(ev); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 846 | |
| 847 | final int action = ev.getAction(); |
| 848 | |
| 849 | switch (action & MotionEvent.ACTION_MASK) { |
| 850 | case MotionEvent.ACTION_DOWN: |
| 851 | /* |
| 852 | * If being flinged and user touches, stop the fling. isFinished |
| 853 | * will be false if being flinged. |
| 854 | */ |
| 855 | if (!mScroller.isFinished()) { |
| 856 | mScroller.abortAnimation(); |
| 857 | } |
| 858 | |
| 859 | // Remember where the motion event started |
| 860 | mDownMotionX = mLastMotionX = ev.getX(); |
| 861 | mActivePointerId = ev.getPointerId(0); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 862 | if (mTouchState == TOUCH_STATE_SCROLLING) { |
| 863 | pageBeginMoving(); |
| 864 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 865 | break; |
| 866 | |
| 867 | case MotionEvent.ACTION_MOVE: |
| 868 | if (mTouchState == TOUCH_STATE_SCROLLING) { |
| 869 | // Scroll to follow the motion event |
| 870 | final int pointerIndex = ev.findPointerIndex(mActivePointerId); |
| 871 | final float x = ev.getX(pointerIndex); |
| 872 | final int deltaX = (int) (mLastMotionX - x); |
| 873 | mLastMotionX = x; |
| 874 | |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 875 | if (deltaX != 0) { |
| 876 | mTouchX += deltaX; |
| 877 | mSmoothingTime = System.nanoTime() / NANOTIME_DIV; |
| 878 | if (!mDeferScrollUpdate) { |
| 879 | scrollBy(deltaX, 0); |
| 880 | } else { |
| 881 | invalidate(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 882 | } |
| 883 | } else { |
| 884 | awakenScrollBars(); |
| 885 | } |
Adam Cohen | 564976a | 2010-10-13 18:52:07 -0700 | [diff] [blame] | 886 | } else { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 887 | determineScrollingStart(ev); |
| 888 | } |
| 889 | break; |
| 890 | |
| 891 | case MotionEvent.ACTION_UP: |
| 892 | if (mTouchState == TOUCH_STATE_SCROLLING) { |
| 893 | final int activePointerId = mActivePointerId; |
| 894 | final int pointerIndex = ev.findPointerIndex(activePointerId); |
| 895 | final float x = ev.getX(pointerIndex); |
| 896 | final VelocityTracker velocityTracker = mVelocityTracker; |
| 897 | velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); |
| 898 | int velocityX = (int) velocityTracker.getXVelocity(activePointerId); |
Winson Chung | 9cfd25f | 2010-10-24 16:09:28 -0700 | [diff] [blame] | 899 | final int deltaX = (int) (x - mDownMotionX); |
| 900 | boolean isfling = Math.abs(deltaX) > MIN_LENGTH_FOR_FLING; |
| 901 | boolean isSignificantMove = Math.abs(deltaX) > MIN_LENGTH_FOR_MOVE; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 902 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 903 | final int snapVelocity = mSnapVelocity; |
Winson Chung | 9cfd25f | 2010-10-24 16:09:28 -0700 | [diff] [blame] | 904 | if ((isSignificantMove && deltaX > 0 || |
| 905 | (isfling && velocityX > snapVelocity)) && |
| 906 | mCurrentPage > 0) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 907 | snapToPageWithVelocity(mCurrentPage - 1, velocityX); |
Winson Chung | 9cfd25f | 2010-10-24 16:09:28 -0700 | [diff] [blame] | 908 | } else if ((isSignificantMove && deltaX < 0 || |
| 909 | (isfling && velocityX < -snapVelocity)) && |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 910 | mCurrentPage < getChildCount() - 1) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 911 | snapToPageWithVelocity(mCurrentPage + 1, velocityX); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 912 | } else { |
| 913 | snapToDestination(); |
| 914 | } |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 915 | } else if (mTouchState == TOUCH_STATE_PREV_PAGE && !handlePagingClicks()) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 916 | // at this point we have not moved beyond the touch slop |
| 917 | // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so |
| 918 | // we can just page |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 919 | int nextPage = Math.max(0, mCurrentPage - 1); |
| 920 | if (nextPage != mCurrentPage) { |
| 921 | snapToPage(nextPage); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 922 | } else { |
| 923 | snapToDestination(); |
| 924 | } |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 925 | } else if (mTouchState == TOUCH_STATE_NEXT_PAGE && !handlePagingClicks()) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 926 | // at this point we have not moved beyond the touch slop |
| 927 | // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so |
| 928 | // we can just page |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 929 | int nextPage = Math.min(getChildCount() - 1, mCurrentPage + 1); |
| 930 | if (nextPage != mCurrentPage) { |
| 931 | snapToPage(nextPage); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 932 | } else { |
| 933 | snapToDestination(); |
| 934 | } |
| 935 | } |
| 936 | mTouchState = TOUCH_STATE_REST; |
| 937 | mActivePointerId = INVALID_POINTER; |
Michael Jurka | b8f0672 | 2010-10-10 15:58:46 -0700 | [diff] [blame] | 938 | releaseVelocityTracker(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 939 | break; |
| 940 | |
| 941 | case MotionEvent.ACTION_CANCEL: |
Michael Jurka | b8f0672 | 2010-10-10 15:58:46 -0700 | [diff] [blame] | 942 | if (mTouchState == TOUCH_STATE_SCROLLING) { |
| 943 | snapToDestination(); |
| 944 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 945 | mTouchState = TOUCH_STATE_REST; |
| 946 | mActivePointerId = INVALID_POINTER; |
Michael Jurka | b8f0672 | 2010-10-10 15:58:46 -0700 | [diff] [blame] | 947 | releaseVelocityTracker(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 948 | break; |
| 949 | |
| 950 | case MotionEvent.ACTION_POINTER_UP: |
| 951 | onSecondaryPointerUp(ev); |
| 952 | break; |
| 953 | } |
| 954 | |
| 955 | return true; |
| 956 | } |
| 957 | |
Michael Jurka | b8f0672 | 2010-10-10 15:58:46 -0700 | [diff] [blame] | 958 | private void acquireVelocityTrackerAndAddMovement(MotionEvent ev) { |
| 959 | if (mVelocityTracker == null) { |
| 960 | mVelocityTracker = VelocityTracker.obtain(); |
| 961 | } |
| 962 | mVelocityTracker.addMovement(ev); |
| 963 | } |
| 964 | |
| 965 | private void releaseVelocityTracker() { |
| 966 | if (mVelocityTracker != null) { |
| 967 | mVelocityTracker.recycle(); |
| 968 | mVelocityTracker = null; |
| 969 | } |
| 970 | } |
| 971 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 972 | private void onSecondaryPointerUp(MotionEvent ev) { |
| 973 | final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> |
| 974 | MotionEvent.ACTION_POINTER_INDEX_SHIFT; |
| 975 | final int pointerId = ev.getPointerId(pointerIndex); |
| 976 | if (pointerId == mActivePointerId) { |
| 977 | // This was our active pointer going up. Choose a new |
| 978 | // active pointer and adjust accordingly. |
| 979 | // TODO: Make this decision more intelligent. |
| 980 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0; |
| 981 | mLastMotionX = mDownMotionX = ev.getX(newPointerIndex); |
| 982 | mLastMotionY = ev.getY(newPointerIndex); |
| 983 | mActivePointerId = ev.getPointerId(newPointerIndex); |
| 984 | if (mVelocityTracker != null) { |
| 985 | mVelocityTracker.clear(); |
| 986 | } |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | @Override |
| 991 | public void requestChildFocus(View child, View focused) { |
| 992 | super.requestChildFocus(child, focused); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 993 | int page = indexOfChild(child); |
| 994 | if (page >= 0 && !isInTouchMode()) { |
| 995 | snapToPage(page); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 996 | } |
| 997 | } |
| 998 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 999 | protected int getChildIndexForRelativeOffset(int relativeOffset) { |
| 1000 | final int childCount = getChildCount(); |
Adam Cohen | 9c4949e | 2010-10-05 12:27:22 -0700 | [diff] [blame] | 1001 | int left; |
| 1002 | int right; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 1003 | for (int i = 0; i < childCount; ++i) { |
Adam Cohen | 9c4949e | 2010-10-05 12:27:22 -0700 | [diff] [blame] | 1004 | left = getRelativeChildOffset(i); |
| 1005 | right = (left + getChildAt(i).getMeasuredWidth()); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 1006 | if (left <= relativeOffset && relativeOffset <= right) { |
| 1007 | return i; |
| 1008 | } |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 1009 | } |
| 1010 | return -1; |
| 1011 | } |
| 1012 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1013 | protected int getRelativeChildOffset(int index) { |
| 1014 | return (getMeasuredWidth() - getChildAt(index).getMeasuredWidth()) / 2; |
| 1015 | } |
| 1016 | |
| 1017 | protected int getChildOffset(int index) { |
| 1018 | if (getChildCount() == 0) |
| 1019 | return 0; |
| 1020 | |
| 1021 | int offset = getRelativeChildOffset(0); |
| 1022 | for (int i = 0; i < index; ++i) { |
Adam Cohen | 9c4949e | 2010-10-05 12:27:22 -0700 | [diff] [blame] | 1023 | offset += getChildAt(i).getMeasuredWidth() + mPageSpacing; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1024 | } |
| 1025 | return offset; |
| 1026 | } |
| 1027 | |
Adam Cohen | d19d3ca | 2010-09-15 14:43:42 -0700 | [diff] [blame] | 1028 | int getPageNearestToCenterOfScreen() { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1029 | int minDistanceFromScreenCenter = getMeasuredWidth(); |
| 1030 | int minDistanceFromScreenCenterIndex = -1; |
| 1031 | int screenCenter = mScrollX + (getMeasuredWidth() / 2); |
| 1032 | final int childCount = getChildCount(); |
| 1033 | for (int i = 0; i < childCount; ++i) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1034 | View layout = (View) getChildAt(i); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1035 | int childWidth = layout.getMeasuredWidth(); |
| 1036 | int halfChildWidth = (childWidth / 2); |
| 1037 | int childCenter = getChildOffset(i) + halfChildWidth; |
| 1038 | int distanceFromScreenCenter = Math.abs(childCenter - screenCenter); |
| 1039 | if (distanceFromScreenCenter < minDistanceFromScreenCenter) { |
| 1040 | minDistanceFromScreenCenter = distanceFromScreenCenter; |
| 1041 | minDistanceFromScreenCenterIndex = i; |
| 1042 | } |
| 1043 | } |
Adam Cohen | d19d3ca | 2010-09-15 14:43:42 -0700 | [diff] [blame] | 1044 | return minDistanceFromScreenCenterIndex; |
| 1045 | } |
| 1046 | |
| 1047 | protected void snapToDestination() { |
| 1048 | snapToPage(getPageNearestToCenterOfScreen(), PAGE_SNAP_ANIMATION_DURATION); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1051 | protected void snapToPageWithVelocity(int whichPage, int velocity) { |
| 1052 | // We ignore velocity in this implementation, but children (e.g. SmoothPagedView) |
| 1053 | // can use it |
| 1054 | snapToPage(whichPage); |
| 1055 | } |
| 1056 | |
| 1057 | protected void snapToPage(int whichPage) { |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 1058 | snapToPage(whichPage, PAGE_SNAP_ANIMATION_DURATION); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1061 | protected void snapToPage(int whichPage, int duration) { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1062 | whichPage = Math.max(0, Math.min(whichPage, getPageCount() - 1)); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1063 | |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1064 | int newX = getChildOffset(whichPage) - getRelativeChildOffset(whichPage); |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 1065 | final int sX = mUnboundedScrollX; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1066 | final int delta = newX - sX; |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1067 | snapToPage(whichPage, delta, duration); |
| 1068 | } |
| 1069 | |
| 1070 | protected void snapToPage(int whichPage, int delta, int duration) { |
| 1071 | mNextPage = whichPage; |
| 1072 | |
| 1073 | View focusedChild = getFocusedChild(); |
| 1074 | if (focusedChild != null && whichPage != mCurrentPage && |
| 1075 | focusedChild == getChildAt(mCurrentPage)) { |
| 1076 | focusedChild.clearFocus(); |
| 1077 | } |
| 1078 | |
| 1079 | pageBeginMoving(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1080 | awakenScrollBars(duration); |
| 1081 | if (duration == 0) { |
| 1082 | duration = Math.abs(delta); |
| 1083 | } |
| 1084 | |
| 1085 | if (!mScroller.isFinished()) mScroller.abortAnimation(); |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 1086 | mScroller.startScroll(mUnboundedScrollX, 0, delta, 0, duration); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1087 | |
| 1088 | // only load some associated pages |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1089 | loadAssociatedPages(mNextPage); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1090 | notifyPageSwitchListener(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1091 | invalidate(); |
| 1092 | } |
| 1093 | |
| 1094 | @Override |
| 1095 | protected Parcelable onSaveInstanceState() { |
| 1096 | final SavedState state = new SavedState(super.onSaveInstanceState()); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1097 | state.currentPage = mCurrentPage; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1098 | return state; |
| 1099 | } |
| 1100 | |
| 1101 | @Override |
| 1102 | protected void onRestoreInstanceState(Parcelable state) { |
| 1103 | SavedState savedState = (SavedState) state; |
| 1104 | super.onRestoreInstanceState(savedState.getSuperState()); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1105 | if (savedState.currentPage != -1) { |
| 1106 | mCurrentPage = savedState.currentPage; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | public void scrollLeft() { |
| 1111 | if (mScroller.isFinished()) { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1112 | if (mCurrentPage > 0) snapToPage(mCurrentPage - 1); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1113 | } else { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1114 | if (mNextPage > 0) snapToPage(mNextPage - 1); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | public void scrollRight() { |
| 1119 | if (mScroller.isFinished()) { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1120 | if (mCurrentPage < getChildCount() -1) snapToPage(mCurrentPage + 1); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1121 | } else { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1122 | if (mNextPage < getChildCount() -1) snapToPage(mNextPage + 1); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1123 | } |
| 1124 | } |
| 1125 | |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1126 | public int getPageForView(View v) { |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1127 | int result = -1; |
| 1128 | if (v != null) { |
| 1129 | ViewParent vp = v.getParent(); |
| 1130 | int count = getChildCount(); |
| 1131 | for (int i = 0; i < count; i++) { |
| 1132 | if (vp == getChildAt(i)) { |
| 1133 | return i; |
| 1134 | } |
| 1135 | } |
| 1136 | } |
| 1137 | return result; |
| 1138 | } |
| 1139 | |
| 1140 | /** |
| 1141 | * @return True is long presses are still allowed for the current touch |
| 1142 | */ |
| 1143 | public boolean allowLongPress() { |
| 1144 | return mAllowLongPress; |
| 1145 | } |
| 1146 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1147 | /** |
| 1148 | * Set true to allow long-press events to be triggered, usually checked by |
| 1149 | * {@link Launcher} to accept or block dpad-initiated long-presses. |
| 1150 | */ |
| 1151 | public void setAllowLongPress(boolean allowLongPress) { |
| 1152 | mAllowLongPress = allowLongPress; |
| 1153 | } |
| 1154 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1155 | public static class SavedState extends BaseSavedState { |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1156 | int currentPage = -1; |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1157 | |
| 1158 | SavedState(Parcelable superState) { |
| 1159 | super(superState); |
| 1160 | } |
| 1161 | |
| 1162 | private SavedState(Parcel in) { |
| 1163 | super(in); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1164 | currentPage = in.readInt(); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | @Override |
| 1168 | public void writeToParcel(Parcel out, int flags) { |
| 1169 | super.writeToParcel(out, flags); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1170 | out.writeInt(currentPage); |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | public static final Parcelable.Creator<SavedState> CREATOR = |
| 1174 | new Parcelable.Creator<SavedState>() { |
| 1175 | public SavedState createFromParcel(Parcel in) { |
| 1176 | return new SavedState(in); |
| 1177 | } |
| 1178 | |
| 1179 | public SavedState[] newArray(int size) { |
| 1180 | return new SavedState[size]; |
| 1181 | } |
| 1182 | }; |
| 1183 | } |
| 1184 | |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1185 | public void loadAssociatedPages(int page) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1186 | if (mContentIsRefreshable) { |
| 1187 | final int count = getChildCount(); |
| 1188 | if (page < count) { |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 1189 | int lowerPageBound = getAssociatedLowerPageBound(page); |
| 1190 | int upperPageBound = getAssociatedUpperPageBound(page); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1191 | for (int i = 0; i < count; ++i) { |
| 1192 | final ViewGroup layout = (ViewGroup) getChildAt(i); |
| 1193 | final int childCount = layout.getChildCount(); |
| 1194 | if (lowerPageBound <= i && i <= upperPageBound) { |
| 1195 | if (mDirtyPageContent.get(i)) { |
| 1196 | syncPageItems(i); |
| 1197 | mDirtyPageContent.set(i, false); |
| 1198 | } |
| 1199 | } else { |
| 1200 | if (childCount > 0) { |
| 1201 | layout.removeAllViews(); |
| 1202 | } |
| 1203 | mDirtyPageContent.set(i, true); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1204 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1205 | } |
| 1206 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1207 | } |
| 1208 | } |
| 1209 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 1210 | protected int getAssociatedLowerPageBound(int page) { |
| 1211 | return Math.max(0, page - 1); |
| 1212 | } |
| 1213 | protected int getAssociatedUpperPageBound(int page) { |
| 1214 | final int count = getChildCount(); |
| 1215 | return Math.min(page + 1, count - 1); |
| 1216 | } |
| 1217 | |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 1218 | protected void startChoiceMode(int mode, ActionMode.Callback callback) { |
Patrick Dubroy | 430c53b | 2010-09-08 16:01:19 -0700 | [diff] [blame] | 1219 | if (isChoiceMode(CHOICE_MODE_NONE)) { |
| 1220 | mChoiceMode = mode; |
| 1221 | mActionMode = startActionMode(callback); |
| 1222 | } |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 1225 | public void endChoiceMode() { |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 1226 | if (!isChoiceMode(CHOICE_MODE_NONE)) { |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 1227 | mChoiceMode = CHOICE_MODE_NONE; |
| 1228 | resetCheckedGrandchildren(); |
Michael Jurka | e17e19c | 2010-09-28 11:01:39 -0700 | [diff] [blame] | 1229 | if (mActionMode != null) mActionMode.finish(); |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 1230 | mActionMode = null; |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | protected boolean isChoiceMode(int mode) { |
| 1235 | return mChoiceMode == mode; |
| 1236 | } |
| 1237 | |
| 1238 | protected ArrayList<Checkable> getCheckedGrandchildren() { |
| 1239 | ArrayList<Checkable> checked = new ArrayList<Checkable>(); |
| 1240 | final int childCount = getChildCount(); |
| 1241 | for (int i = 0; i < childCount; ++i) { |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 1242 | final ViewGroup layout = (ViewGroup) getChildAt(i); |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 1243 | final int grandChildCount = layout.getChildCount(); |
| 1244 | for (int j = 0; j < grandChildCount; ++j) { |
| 1245 | final View v = layout.getChildAt(j); |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 1246 | if (v instanceof Checkable && ((Checkable) v).isChecked()) { |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 1247 | checked.add((Checkable) v); |
| 1248 | } |
| 1249 | } |
| 1250 | } |
| 1251 | return checked; |
| 1252 | } |
| 1253 | |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 1254 | /** |
| 1255 | * If in CHOICE_MODE_SINGLE and an item is checked, returns that item. |
| 1256 | * Otherwise, returns null. |
| 1257 | */ |
| 1258 | protected Checkable getSingleCheckedGrandchild() { |
| 1259 | if (mChoiceMode == CHOICE_MODE_SINGLE) { |
| 1260 | final int childCount = getChildCount(); |
| 1261 | for (int i = 0; i < childCount; ++i) { |
Winson Chung | d0d4301 | 2010-09-26 17:26:45 -0700 | [diff] [blame] | 1262 | final ViewGroup layout = (ViewGroup) getChildAt(i); |
Patrick Dubroy | 9f7aec8 | 2010-09-06 11:03:37 -0700 | [diff] [blame] | 1263 | final int grandChildCount = layout.getChildCount(); |
| 1264 | for (int j = 0; j < grandChildCount; ++j) { |
| 1265 | final View v = layout.getChildAt(j); |
| 1266 | if (v instanceof Checkable && ((Checkable) v).isChecked()) { |
| 1267 | return (Checkable) v; |
| 1268 | } |
| 1269 | } |
| 1270 | } |
| 1271 | } |
| 1272 | return null; |
| 1273 | } |
| 1274 | |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 1275 | public Object getChosenItem() { |
| 1276 | View checkedView = (View) getSingleCheckedGrandchild(); |
| 1277 | if (checkedView != null) { |
| 1278 | return checkedView.getTag(); |
| 1279 | } |
| 1280 | return null; |
| 1281 | } |
| 1282 | |
Winson Chung | 5f2aa4e | 2010-08-20 14:49:25 -0700 | [diff] [blame] | 1283 | protected void resetCheckedGrandchildren() { |
| 1284 | // loop through children, and set all of their children to _not_ be checked |
| 1285 | final ArrayList<Checkable> checked = getCheckedGrandchildren(); |
| 1286 | for (int i = 0; i < checked.size(); ++i) { |
| 1287 | final Checkable c = checked.get(i); |
| 1288 | c.setChecked(false); |
| 1289 | } |
| 1290 | } |
| 1291 | |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1292 | /** |
| 1293 | * This method is called ONLY to synchronize the number of pages that the paged view has. |
| 1294 | * To actually fill the pages with information, implement syncPageItems() below. It is |
| 1295 | * guaranteed that syncPageItems() will be called for a particular page before it is shown, |
| 1296 | * and therefore, individual page items do not need to be updated in this method. |
| 1297 | */ |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1298 | public abstract void syncPages(); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1299 | |
| 1300 | /** |
| 1301 | * This method is called to synchronize the items that are on a particular page. If views on |
| 1302 | * the page can be reused, then they should be updated within this method. |
| 1303 | */ |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1304 | public abstract void syncPageItems(int page); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1305 | |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1306 | public void invalidatePageData() { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1307 | if (mContentIsRefreshable) { |
| 1308 | // Update all the pages |
| 1309 | syncPages(); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1310 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1311 | // Mark each of the pages as dirty |
| 1312 | final int count = getChildCount(); |
| 1313 | mDirtyPageContent.clear(); |
| 1314 | for (int i = 0; i < count; ++i) { |
| 1315 | mDirtyPageContent.add(true); |
| 1316 | } |
| 1317 | |
| 1318 | // Load any pages that are necessary for the current window of views |
| 1319 | loadAssociatedPages(mCurrentPage); |
| 1320 | mDirtyPageAlpha = true; |
Winson Chung | b0b2e6f | 2010-10-12 17:49:56 -0700 | [diff] [blame] | 1321 | updateAdjacentPagesAlpha(); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1322 | requestLayout(); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 1323 | } |
Winson Chung | 321e9ee | 2010-08-09 13:37:56 -0700 | [diff] [blame] | 1324 | } |
| 1325 | } |