blob: 76dfddb78c80fc1b3b88fe1427be00341e5ca257 [file] [log] [blame]
Jason Monkcaf37622015-08-18 12:33:50 -04001package com.android.systemui.qs;
2
Amin Shaikha07a17b2018-02-23 16:02:52 -05003import android.animation.Animator;
4import android.animation.AnimatorListenerAdapter;
5import android.animation.AnimatorSet;
6import android.animation.ObjectAnimator;
7import android.animation.PropertyValuesHolder;
Jason Monkcaf37622015-08-18 12:33:50 -04008import android.content.Context;
Fabian Kozynski407ddb22018-10-03 15:04:56 -04009import android.content.res.Configuration;
Fabian Kozynski6eaf3ac2018-10-01 15:59:05 -040010import android.content.res.Resources;
Fabian Kozynski52bd8c22018-10-08 12:52:51 -040011import android.graphics.Rect;
Fabian Kozynski407ddb22018-10-03 15:04:56 -040012import android.os.Bundle;
Jason Monkcaf37622015-08-18 12:33:50 -040013import android.util.AttributeSet;
14import android.util.Log;
15import android.view.LayoutInflater;
16import android.view.View;
17import android.view.ViewGroup;
Amin Shaikha07a17b2018-02-23 16:02:52 -050018import android.view.animation.Interpolator;
19import android.view.animation.OvershootInterpolator;
20import android.widget.Scroller;
Jason Monkdf36aed2016-07-25 11:21:56 -040021
Fabian Kozynski6eaf3ac2018-10-01 15:59:05 -040022import androidx.viewpager.widget.PagerAdapter;
23import androidx.viewpager.widget.ViewPager;
24
Jason Monkcaf37622015-08-18 12:33:50 -040025import com.android.systemui.R;
26import com.android.systemui.qs.QSPanel.QSTileLayout;
27import com.android.systemui.qs.QSPanel.TileRecord;
28
29import java.util.ArrayList;
Amin Shaikha07a17b2018-02-23 16:02:52 -050030import java.util.Set;
Jason Monkcaf37622015-08-18 12:33:50 -040031
32public class PagedTileLayout extends ViewPager implements QSTileLayout {
33
34 private static final boolean DEBUG = false;
Fabian Kozynski407ddb22018-10-03 15:04:56 -040035 private static final String CURRENT_PAGE = "current_page";
Jason Monkcaf37622015-08-18 12:33:50 -040036
37 private static final String TAG = "PagedTileLayout";
Amin Shaikha07a17b2018-02-23 16:02:52 -050038 private static final int REVEAL_SCROLL_DURATION_MILLIS = 750;
39 private static final float BOUNCE_ANIMATION_TENSION = 1.3f;
40 private static final long BOUNCE_ANIMATION_DURATION = 450L;
41 private static final int TILE_ANIMATION_STAGGER_DELAY = 85;
42 private static final Interpolator SCROLL_CUBIC = (t) -> {
43 t -= 1.0f;
44 return t * t * t + 1.0f;
45 };
46
Amin Shaikh9978c552018-03-22 07:24:41 -040047 private final ArrayList<TileRecord> mTiles = new ArrayList<>();
48 private final ArrayList<TilePage> mPages = new ArrayList<>();
Jason Monkcaf37622015-08-18 12:33:50 -040049
Jason Monkcaf37622015-08-18 12:33:50 -040050 private PageIndicator mPageIndicator;
Rohan Shah3090e792018-04-12 00:01:00 -040051 private float mPageIndicatorPosition;
Jason Monkcaf37622015-08-18 12:33:50 -040052
Jason Monk162011e2016-02-19 08:11:55 -050053 private PageListener mPageListener;
Jason Monkcaf37622015-08-18 12:33:50 -040054
Jason Monke5107a32016-05-31 15:40:58 -040055 private boolean mListening;
Amin Shaikha07a17b2018-02-23 16:02:52 -050056 private Scroller mScroller;
57
58 private AnimatorSet mBounceAnimatorSet;
Amin Shaikh4c9048c2018-04-20 11:27:46 -040059 private float mLastExpansion;
Fabian Kozynski712ae392018-09-12 09:11:16 -040060 private boolean mDistributeTiles = false;
Fabian Kozynski407ddb22018-10-03 15:04:56 -040061 private int mPageToRestore = -1;
62 private int mLayoutOrientation;
63 private int mLayoutDirection;
Fabian Kozynski52bd8c22018-10-08 12:52:51 -040064 private int mHorizontalClipBound;
Jason Monke5107a32016-05-31 15:40:58 -040065
Jason Monkcaf37622015-08-18 12:33:50 -040066 public PagedTileLayout(Context context, AttributeSet attrs) {
67 super(context, attrs);
Amin Shaikha07a17b2018-02-23 16:02:52 -050068 mScroller = new Scroller(context, SCROLL_CUBIC);
Jason Monkcaf37622015-08-18 12:33:50 -040069 setAdapter(mAdapter);
Amin Shaikha07a17b2018-02-23 16:02:52 -050070 setOnPageChangeListener(mOnPageChangeListener);
71 setCurrentItem(0, false);
Fabian Kozynski407ddb22018-10-03 15:04:56 -040072 mLayoutOrientation = getResources().getConfiguration().orientation;
73 mLayoutDirection = getLayoutDirection();
74 }
75
76 public void saveInstanceState(Bundle outState) {
77 outState.putInt(CURRENT_PAGE, getCurrentItem());
78 }
79
80 public void restoreInstanceState(Bundle savedInstanceState) {
81 // There's only 1 page at this point. We want to restore the correct page once the
82 // pages have been inflated
83 mPageToRestore = savedInstanceState.getInt(CURRENT_PAGE, -1);
84 }
85
86 @Override
87 protected void onConfigurationChanged(Configuration newConfig) {
88 super.onConfigurationChanged(newConfig);
89 if (mLayoutOrientation != newConfig.orientation) {
90 mLayoutOrientation = newConfig.orientation;
91 setCurrentItem(0, false);
92 }
Jason Monkcaf37622015-08-18 12:33:50 -040093 }
94
95 @Override
Jason Monk51fb85a2016-03-28 14:06:04 -040096 public void onRtlPropertiesChanged(int layoutDirection) {
97 super.onRtlPropertiesChanged(layoutDirection);
Fabian Kozynski407ddb22018-10-03 15:04:56 -040098 if (mLayoutDirection != layoutDirection) {
99 mLayoutDirection = layoutDirection;
100 setAdapter(mAdapter);
101 setCurrentItem(0, false);
102 }
Jason Monk51fb85a2016-03-28 14:06:04 -0400103 }
104
105 @Override
106 public void setCurrentItem(int item, boolean smoothScroll) {
107 if (isLayoutRtl()) {
108 item = mPages.size() - 1 - item;
109 }
110 super.setCurrentItem(item, smoothScroll);
111 }
112
113 @Override
Jason Monke5107a32016-05-31 15:40:58 -0400114 public void setListening(boolean listening) {
115 if (mListening == listening) return;
116 mListening = listening;
Amin Shaikh9978c552018-03-22 07:24:41 -0400117 updateListening();
118 }
119
120 private void updateListening() {
121 for (TilePage tilePage : mPages) {
122 tilePage.setListening(tilePage.getParent() == null ? false : mListening);
Jason Monke5107a32016-05-31 15:40:58 -0400123 }
124 }
125
Amin Shaikha07a17b2018-02-23 16:02:52 -0500126 @Override
Amin Shaikha07a17b2018-02-23 16:02:52 -0500127 public void computeScroll() {
128 if (!mScroller.isFinished() && mScroller.computeScrollOffset()) {
Amin Shaikh5484d0f2018-07-31 10:44:11 -0400129 fakeDragBy(getScrollX() - mScroller.getCurrX());
Amin Shaikha07a17b2018-02-23 16:02:52 -0500130 // Keep on drawing until the animation has finished.
131 postInvalidateOnAnimation();
132 return;
Amin Shaikh5484d0f2018-07-31 10:44:11 -0400133 } else if (isFakeDragging()) {
134 endFakeDrag();
Amin Shaikha07a17b2018-02-23 16:02:52 -0500135 mBounceAnimatorSet.start();
136 setOffscreenPageLimit(1);
Amin Shaikha07a17b2018-02-23 16:02:52 -0500137 }
138 super.computeScroll();
139 }
140
Jason Monke5107a32016-05-31 15:40:58 -0400141 @Override
Jason Monkc5bdafb2016-02-25 16:24:21 -0500142 public boolean hasOverlappingRendering() {
143 return false;
144 }
145
146 @Override
Jason Monkcaf37622015-08-18 12:33:50 -0400147 protected void onFinishInflate() {
148 super.onFinishInflate();
Jason Monk32508852017-01-18 09:17:13 -0500149 mPages.add((TilePage) LayoutInflater.from(getContext())
Jason Monke4e69302016-01-20 11:27:15 -0500150 .inflate(R.layout.qs_paged_page, this, false));
Fabian Kozynskifae42a82018-10-04 11:18:42 -0400151 mAdapter.notifyDataSetChanged();
Jason Monkcaf37622015-08-18 12:33:50 -0400152 }
153
Jason Monk32508852017-01-18 09:17:13 -0500154 public void setPageIndicator(PageIndicator indicator) {
155 mPageIndicator = indicator;
Fabian Kozynski712ae392018-09-12 09:11:16 -0400156 mPageIndicator.setNumPages(mPages.size());
Rohan Shah3090e792018-04-12 00:01:00 -0400157 mPageIndicator.setLocation(mPageIndicatorPosition);
Jason Monk32508852017-01-18 09:17:13 -0500158 }
159
Jason Monkcaf37622015-08-18 12:33:50 -0400160 @Override
161 public int getOffsetTop(TileRecord tile) {
Jason Monkae5bd032016-03-02 14:38:31 -0500162 final ViewGroup parent = (ViewGroup) tile.tileView.getParent();
163 if (parent == null) return 0;
164 return parent.getTop() + getTop();
Jason Monkcaf37622015-08-18 12:33:50 -0400165 }
166
167 @Override
Jason Monkcaf37622015-08-18 12:33:50 -0400168 public void addTile(TileRecord tile) {
169 mTiles.add(tile);
Fabian Kozynski712ae392018-09-12 09:11:16 -0400170 mDistributeTiles = true;
171 requestLayout();
Jason Monkcaf37622015-08-18 12:33:50 -0400172 }
173
174 @Override
175 public void removeTile(TileRecord tile) {
176 if (mTiles.remove(tile)) {
Fabian Kozynski712ae392018-09-12 09:11:16 -0400177 mDistributeTiles = true;
178 requestLayout();
Jason Monkcaf37622015-08-18 12:33:50 -0400179 }
180 }
181
Amin Shaikh0f8ea5432018-03-27 11:09:27 -0400182 @Override
183 public void setExpansion(float expansion) {
Amin Shaikh4c9048c2018-04-20 11:27:46 -0400184 mLastExpansion = expansion;
185 updateSelected();
186 }
187
188 private void updateSelected() {
189 // Start the marquee when fully expanded and stop when fully collapsed. Leave as is for
190 // other expansion ratios since there is no way way to pause the marquee.
191 if (mLastExpansion > 0f && mLastExpansion < 1f) {
192 return;
193 }
194 boolean selected = mLastExpansion == 1f;
Rohan Shah2dbcb572018-05-25 10:51:22 -0700195
196 // Disable accessibility temporarily while we update selected state purely for the
197 // marquee. This will ensure that accessibility doesn't announce the TYPE_VIEW_SELECTED
198 // event on any of the children.
199 setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
Amin Shaikh6f570742018-06-01 17:18:19 -0400200 int currentItem = isLayoutRtl() ? mPages.size() - 1 - getCurrentItem() : getCurrentItem();
Amin Shaikh4c9048c2018-04-20 11:27:46 -0400201 for (int i = 0; i < mPages.size(); i++) {
Amin Shaikh6f570742018-06-01 17:18:19 -0400202 mPages.get(i).setSelected(i == currentItem ? selected : false);
Amin Shaikh0f8ea5432018-03-27 11:09:27 -0400203 }
Rohan Shah2dbcb572018-05-25 10:51:22 -0700204 setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
Amin Shaikh0f8ea5432018-03-27 11:09:27 -0400205 }
206
Jason Monk162011e2016-02-19 08:11:55 -0500207 public void setPageListener(PageListener listener) {
208 mPageListener = listener;
209 }
210
Jason Monkcaf37622015-08-18 12:33:50 -0400211 private void distributeTiles() {
Fabian Kozynski712ae392018-09-12 09:11:16 -0400212 emptyAndInflateOrRemovePages();
213
214 final int tileCount = mPages.get(0).maxTiles();
Jason Monkcaf37622015-08-18 12:33:50 -0400215 if (DEBUG) Log.d(TAG, "Distributing tiles");
Jason Monkcaf37622015-08-18 12:33:50 -0400216 int index = 0;
217 final int NT = mTiles.size();
218 for (int i = 0; i < NT; i++) {
219 TileRecord tile = mTiles.get(i);
Fabian Kozynski712ae392018-09-12 09:11:16 -0400220 if (mPages.get(index).mRecords.size() == tileCount) index++;
221 if (DEBUG) {
222 Log.d(TAG, "Adding " + tile.tile.getClass().getSimpleName() + " to "
223 + index);
Jason Monkcaf37622015-08-18 12:33:50 -0400224 }
Jason Monkcaf37622015-08-18 12:33:50 -0400225 mPages.get(index).addTile(tile);
226 }
Fabian Kozynski712ae392018-09-12 09:11:16 -0400227 }
228
229 private void emptyAndInflateOrRemovePages() {
230 final int nTiles = mTiles.size();
231 int numPages = nTiles / mPages.get(0).maxTiles();
232 // Add one more not full page if needed
233 numPages += (nTiles % mPages.get(0).maxTiles() == 0 ? 0 : 1);
234
235 final int NP = mPages.size();
236 for (int i = 0; i < NP; i++) {
237 mPages.get(i).removeAllViews();
Jason Monkcaf37622015-08-18 12:33:50 -0400238 }
Fabian Kozynski712ae392018-09-12 09:11:16 -0400239 if (NP == numPages) {
240 return;
241 }
242 while (mPages.size() < numPages) {
243 if (DEBUG) Log.d(TAG, "Adding page");
244 mPages.add((TilePage) LayoutInflater.from(getContext())
245 .inflate(R.layout.qs_paged_page, this, false));
246 }
247 while (mPages.size() > numPages) {
248 if (DEBUG) Log.d(TAG, "Removing page");
249 mPages.remove(mPages.size() - 1);
250 }
251 mPageIndicator.setNumPages(mPages.size());
252 setAdapter(mAdapter);
253 mAdapter.notifyDataSetChanged();
Fabian Kozynski407ddb22018-10-03 15:04:56 -0400254 if (mPageToRestore != -1) {
255 setCurrentItem(mPageToRestore, false);
256 mPageToRestore = -1;
257 }
Jason Monkcaf37622015-08-18 12:33:50 -0400258 }
259
260 @Override
Jason Monk9d02a432016-01-20 16:33:46 -0500261 public boolean updateResources() {
Rohan Shah3090e792018-04-12 00:01:00 -0400262 // Update bottom padding, useful for removing extra space once the panel page indicator is
263 // hidden.
Fabian Kozynski6eaf3ac2018-10-01 15:59:05 -0400264 Resources res = getContext().getResources();
Fabian Kozynski52bd8c22018-10-08 12:52:51 -0400265 mHorizontalClipBound = res.getDimensionPixelSize(R.dimen.notification_side_paddings);
266 setPadding(0, 0, 0,
Rohan Shah3090e792018-04-12 00:01:00 -0400267 getContext().getResources().getDimensionPixelSize(
268 R.dimen.qs_paged_tile_layout_padding_bottom));
Jason Monk9d02a432016-01-20 16:33:46 -0500269 boolean changed = false;
Jason Monkcaf37622015-08-18 12:33:50 -0400270 for (int i = 0; i < mPages.size(); i++) {
Jason Monk9d02a432016-01-20 16:33:46 -0500271 changed |= mPages.get(i).updateResources();
Jason Monkcaf37622015-08-18 12:33:50 -0400272 }
Jason Monk9d02a432016-01-20 16:33:46 -0500273 if (changed) {
Fabian Kozynski712ae392018-09-12 09:11:16 -0400274 mDistributeTiles = true;
275 requestLayout();
Jason Monk9d02a432016-01-20 16:33:46 -0500276 }
277 return changed;
Jason Monkcaf37622015-08-18 12:33:50 -0400278 }
279
280 @Override
Fabian Kozynski52bd8c22018-10-08 12:52:51 -0400281 protected void onLayout(boolean changed, int l, int t, int r, int b) {
282 super.onLayout(changed, l, t, r, b);
283 Rect clipBounds = new Rect(mHorizontalClipBound, 0, (r-l) - mHorizontalClipBound, b - t);
284 setClipBounds(clipBounds);
285 }
286
287 @Override
Jason Monkcaf37622015-08-18 12:33:50 -0400288 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Fabian Kozynski712ae392018-09-12 09:11:16 -0400289
290 final int nTiles = mTiles.size();
291 if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) {
292
293 // Only change the pages if the number of rows or columns (from updateResources) has
294 // changed or the tiles have changed
295 if (mPages.get(0).updateMaxRows(heightMeasureSpec, nTiles) || mDistributeTiles) {
296 mDistributeTiles = false;
297 distributeTiles();
298 }
299
300 final int nRows = mPages.get(0).mRows;
301 for (int i = 0; i < mPages.size(); i++) {
302 TilePage t = mPages.get(i);
303 t.mRows = nRows;
304 }
305 }
306
Jason Monkcaf37622015-08-18 12:33:50 -0400307 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Fabian Kozynski712ae392018-09-12 09:11:16 -0400308
Jason Monkcaf37622015-08-18 12:33:50 -0400309 // The ViewPager likes to eat all of the space, instead force it to wrap to the max height
310 // of the pages.
311 int maxHeight = 0;
312 final int N = getChildCount();
313 for (int i = 0; i < N; i++) {
314 int height = getChildAt(i).getMeasuredHeight();
315 if (height > maxHeight) {
316 maxHeight = height;
317 }
318 }
Jason Monkf13413e2017-02-15 15:49:32 -0500319 setMeasuredDimension(getMeasuredWidth(), maxHeight + getPaddingBottom());
Jason Monkcaf37622015-08-18 12:33:50 -0400320 }
321
Jason Monk8fb77872016-03-03 16:39:42 -0500322 public int getColumnCount() {
323 if (mPages.size() == 0) return 0;
324 return mPages.get(0).mColumns;
325 }
326
Fabian Kozynski802279f2018-09-07 13:44:54 -0400327 public int getNumVisibleTiles() {
328 if (mPages.size() == 0) return 0;
329 TilePage currentPage = mPages.get(getCurrentItem());
330 return currentPage.mRecords.size();
331 }
332
Amin Shaikha07a17b2018-02-23 16:02:52 -0500333 public void startTileReveal(Set<String> tileSpecs, final Runnable postAnimation) {
Amin Shaikh5484d0f2018-07-31 10:44:11 -0400334 if (tileSpecs.isEmpty() || mPages.size() < 2 || getScrollX() != 0 || !beginFakeDrag()) {
Amin Shaikha07a17b2018-02-23 16:02:52 -0500335 // Do not start the reveal animation unless there are tiles to animate, multiple
336 // TilePages available and the user has not already started dragging.
337 return;
338 }
339
340 final int lastPageNumber = mPages.size() - 1;
341 final TilePage lastPage = mPages.get(lastPageNumber);
342 final ArrayList<Animator> bounceAnims = new ArrayList<>();
343 for (TileRecord tr : lastPage.mRecords) {
344 if (tileSpecs.contains(tr.tile.getTileSpec())) {
345 bounceAnims.add(setupBounceAnimator(tr.tileView, bounceAnims.size()));
346 }
347 }
348
349 if (bounceAnims.isEmpty()) {
350 // All tileSpecs are on the first page. Nothing to do.
351 // TODO: potentially show a bounce animation for first page QS tiles
Amin Shaikh5484d0f2018-07-31 10:44:11 -0400352 endFakeDrag();
Amin Shaikha07a17b2018-02-23 16:02:52 -0500353 return;
354 }
355
356 mBounceAnimatorSet = new AnimatorSet();
357 mBounceAnimatorSet.playTogether(bounceAnims);
358 mBounceAnimatorSet.addListener(new AnimatorListenerAdapter() {
359 @Override
360 public void onAnimationEnd(Animator animation) {
361 mBounceAnimatorSet = null;
362 postAnimation.run();
363 }
364 });
Amin Shaikh5484d0f2018-07-31 10:44:11 -0400365 setOffscreenPageLimit(lastPageNumber); // Ensure the page to reveal has been inflated.
366 int dx = getWidth() * lastPageNumber;
367 mScroller.startScroll(getScrollX(), getScrollY(), isLayoutRtl() ? -dx : dx, 0,
368 REVEAL_SCROLL_DURATION_MILLIS);
Amin Shaikha07a17b2018-02-23 16:02:52 -0500369 postInvalidateOnAnimation();
370 }
371
372 private static Animator setupBounceAnimator(View view, int ordinal) {
373 view.setAlpha(0f);
374 view.setScaleX(0f);
375 view.setScaleY(0f);
376 ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(view,
377 PropertyValuesHolder.ofFloat(View.ALPHA, 1),
378 PropertyValuesHolder.ofFloat(View.SCALE_X, 1),
379 PropertyValuesHolder.ofFloat(View.SCALE_Y, 1));
380 animator.setDuration(BOUNCE_ANIMATION_DURATION);
381 animator.setStartDelay(ordinal * TILE_ANIMATION_STAGGER_DELAY);
382 animator.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
383 return animator;
384 }
385
386 private final ViewPager.OnPageChangeListener mOnPageChangeListener =
387 new ViewPager.SimpleOnPageChangeListener() {
388 @Override
389 public void onPageSelected(int position) {
Amin Shaikh4c9048c2018-04-20 11:27:46 -0400390 updateSelected();
Amin Shaikha07a17b2018-02-23 16:02:52 -0500391 if (mPageIndicator == null) return;
392 if (mPageListener != null) {
393 mPageListener.onPageChanged(isLayoutRtl() ? position == mPages.size() - 1
394 : position == 0);
395 }
396 }
397
398 @Override
399 public void onPageScrolled(int position, float positionOffset,
400 int positionOffsetPixels) {
401 if (mPageIndicator == null) return;
Rohan Shah3090e792018-04-12 00:01:00 -0400402 mPageIndicatorPosition = position + positionOffset;
403 mPageIndicator.setLocation(mPageIndicatorPosition);
Amin Shaikha07a17b2018-02-23 16:02:52 -0500404 if (mPageListener != null) {
405 mPageListener.onPageChanged(positionOffsetPixels == 0 &&
406 (isLayoutRtl() ? position == mPages.size() - 1 : position == 0));
407 }
408 }
409 };
410
Jason Monkcaf37622015-08-18 12:33:50 -0400411 public static class TilePage extends TileLayout {
Fabian Kozynski712ae392018-09-12 09:11:16 -0400412
Jason Monkcaf37622015-08-18 12:33:50 -0400413 public TilePage(Context context, AttributeSet attrs) {
414 super(context, attrs);
Jason Monkbd6dbb02015-09-03 15:46:25 -0400415 }
416
Jason Monkbd6dbb02015-09-03 15:46:25 -0400417 public boolean isFull() {
Fabian Kozynski712ae392018-09-12 09:11:16 -0400418 return mRecords.size() >= mColumns * mRows;
419 }
420
421 public int maxTiles() {
422 return mColumns * mRows;
Jason Monkcaf37622015-08-18 12:33:50 -0400423 }
Fabian Kozynski52bd8c22018-10-08 12:52:51 -0400424
425 @Override
426 public boolean updateResources() {
427 final int sidePadding = getContext().getResources().getDimensionPixelSize(
428 R.dimen.notification_side_paddings);
429 setPadding(sidePadding, 0, sidePadding, 0);
430 return super.updateResources();
431 }
Jason Monkcaf37622015-08-18 12:33:50 -0400432 }
433
434 private final PagerAdapter mAdapter = new PagerAdapter() {
Amin Shaikh9978c552018-03-22 07:24:41 -0400435 @Override
Jason Monkcaf37622015-08-18 12:33:50 -0400436 public void destroyItem(ViewGroup container, int position, Object object) {
437 if (DEBUG) Log.d(TAG, "Destantiating " + position);
Jason Monkcaf37622015-08-18 12:33:50 -0400438 container.removeView((View) object);
Amin Shaikh9978c552018-03-22 07:24:41 -0400439 updateListening();
Jason Monkcaf37622015-08-18 12:33:50 -0400440 }
441
Amin Shaikh9978c552018-03-22 07:24:41 -0400442 @Override
Jason Monkcaf37622015-08-18 12:33:50 -0400443 public Object instantiateItem(ViewGroup container, int position) {
444 if (DEBUG) Log.d(TAG, "Instantiating " + position);
Jason Monk51fb85a2016-03-28 14:06:04 -0400445 if (isLayoutRtl()) {
446 position = mPages.size() - 1 - position;
447 }
Jason Monke4e69302016-01-20 11:27:15 -0500448 ViewGroup view = mPages.get(position);
Amin Shaikh53bc0832018-09-17 15:06:18 -0400449 if (view.getParent() != null) {
450 container.removeView(view);
451 }
Jason Monkcaf37622015-08-18 12:33:50 -0400452 container.addView(view);
Amin Shaikh9978c552018-03-22 07:24:41 -0400453 updateListening();
Jason Monkcaf37622015-08-18 12:33:50 -0400454 return view;
455 }
456
457 @Override
458 public int getCount() {
Fabian Kozynski712ae392018-09-12 09:11:16 -0400459 return mPages.size();
Jason Monkcaf37622015-08-18 12:33:50 -0400460 }
461
462 @Override
463 public boolean isViewFromObject(View view, Object object) {
464 return view == object;
465 }
466 };
Jason Monk162011e2016-02-19 08:11:55 -0500467
468 public interface PageListener {
Jason Monk66eaf312016-02-25 12:29:29 -0500469 void onPageChanged(boolean isFirst);
Jason Monk162011e2016-02-19 08:11:55 -0500470 }
Jason Monkcaf37622015-08-18 12:33:50 -0400471}