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