blob: bb159a9ba2e8fbafe2a691f2951c0e9aa41d5489 [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;
Fabian Kozynski87bdf0d2019-04-01 09:52:57 -040065 private final Rect mClippingRect;
Jason Monke5107a32016-05-31 15:40:58 -040066
Jason Monkcaf37622015-08-18 12:33:50 -040067 public PagedTileLayout(Context context, AttributeSet attrs) {
68 super(context, attrs);
Amin Shaikha07a17b2018-02-23 16:02:52 -050069 mScroller = new Scroller(context, SCROLL_CUBIC);
Jason Monkcaf37622015-08-18 12:33:50 -040070 setAdapter(mAdapter);
Amin Shaikha07a17b2018-02-23 16:02:52 -050071 setOnPageChangeListener(mOnPageChangeListener);
72 setCurrentItem(0, false);
Fabian Kozynski407ddb22018-10-03 15:04:56 -040073 mLayoutOrientation = getResources().getConfiguration().orientation;
74 mLayoutDirection = getLayoutDirection();
Fabian Kozynski87bdf0d2019-04-01 09:52:57 -040075 mClippingRect = new Rect();
Fabian Kozynski407ddb22018-10-03 15:04:56 -040076 }
77
78 public void saveInstanceState(Bundle outState) {
79 outState.putInt(CURRENT_PAGE, getCurrentItem());
80 }
81
82 public void restoreInstanceState(Bundle savedInstanceState) {
83 // There's only 1 page at this point. We want to restore the correct page once the
84 // pages have been inflated
85 mPageToRestore = savedInstanceState.getInt(CURRENT_PAGE, -1);
86 }
87
88 @Override
89 protected void onConfigurationChanged(Configuration newConfig) {
90 super.onConfigurationChanged(newConfig);
91 if (mLayoutOrientation != newConfig.orientation) {
92 mLayoutOrientation = newConfig.orientation;
93 setCurrentItem(0, false);
94 }
Jason Monkcaf37622015-08-18 12:33:50 -040095 }
96
97 @Override
Jason Monk51fb85a2016-03-28 14:06:04 -040098 public void onRtlPropertiesChanged(int layoutDirection) {
99 super.onRtlPropertiesChanged(layoutDirection);
Fabian Kozynski407ddb22018-10-03 15:04:56 -0400100 if (mLayoutDirection != layoutDirection) {
101 mLayoutDirection = layoutDirection;
102 setAdapter(mAdapter);
103 setCurrentItem(0, false);
104 }
Jason Monk51fb85a2016-03-28 14:06:04 -0400105 }
106
107 @Override
108 public void setCurrentItem(int item, boolean smoothScroll) {
109 if (isLayoutRtl()) {
110 item = mPages.size() - 1 - item;
111 }
112 super.setCurrentItem(item, smoothScroll);
113 }
114
115 @Override
Jason Monke5107a32016-05-31 15:40:58 -0400116 public void setListening(boolean listening) {
117 if (mListening == listening) return;
118 mListening = listening;
Amin Shaikh9978c552018-03-22 07:24:41 -0400119 updateListening();
120 }
121
122 private void updateListening() {
123 for (TilePage tilePage : mPages) {
124 tilePage.setListening(tilePage.getParent() == null ? false : mListening);
Jason Monke5107a32016-05-31 15:40:58 -0400125 }
126 }
127
Amin Shaikha07a17b2018-02-23 16:02:52 -0500128 @Override
Amin Shaikha07a17b2018-02-23 16:02:52 -0500129 public void computeScroll() {
130 if (!mScroller.isFinished() && mScroller.computeScrollOffset()) {
Amin Shaikh5484d0f2018-07-31 10:44:11 -0400131 fakeDragBy(getScrollX() - mScroller.getCurrX());
Amin Shaikha07a17b2018-02-23 16:02:52 -0500132 // Keep on drawing until the animation has finished.
133 postInvalidateOnAnimation();
134 return;
Amin Shaikh5484d0f2018-07-31 10:44:11 -0400135 } else if (isFakeDragging()) {
136 endFakeDrag();
Amin Shaikha07a17b2018-02-23 16:02:52 -0500137 mBounceAnimatorSet.start();
138 setOffscreenPageLimit(1);
Amin Shaikha07a17b2018-02-23 16:02:52 -0500139 }
140 super.computeScroll();
141 }
142
Jason Monke5107a32016-05-31 15:40:58 -0400143 @Override
Jason Monkc5bdafb2016-02-25 16:24:21 -0500144 public boolean hasOverlappingRendering() {
145 return false;
146 }
147
148 @Override
Jason Monkcaf37622015-08-18 12:33:50 -0400149 protected void onFinishInflate() {
150 super.onFinishInflate();
Jason Monk32508852017-01-18 09:17:13 -0500151 mPages.add((TilePage) LayoutInflater.from(getContext())
Jason Monke4e69302016-01-20 11:27:15 -0500152 .inflate(R.layout.qs_paged_page, this, false));
Fabian Kozynskifae42a82018-10-04 11:18:42 -0400153 mAdapter.notifyDataSetChanged();
Jason Monkcaf37622015-08-18 12:33:50 -0400154 }
155
Jason Monk32508852017-01-18 09:17:13 -0500156 public void setPageIndicator(PageIndicator indicator) {
157 mPageIndicator = indicator;
Fabian Kozynski712ae392018-09-12 09:11:16 -0400158 mPageIndicator.setNumPages(mPages.size());
Rohan Shah3090e792018-04-12 00:01:00 -0400159 mPageIndicator.setLocation(mPageIndicatorPosition);
Jason Monk32508852017-01-18 09:17:13 -0500160 }
161
Jason Monkcaf37622015-08-18 12:33:50 -0400162 @Override
163 public int getOffsetTop(TileRecord tile) {
Jason Monkae5bd032016-03-02 14:38:31 -0500164 final ViewGroup parent = (ViewGroup) tile.tileView.getParent();
165 if (parent == null) return 0;
166 return parent.getTop() + getTop();
Jason Monkcaf37622015-08-18 12:33:50 -0400167 }
168
169 @Override
Jason Monkcaf37622015-08-18 12:33:50 -0400170 public void addTile(TileRecord tile) {
171 mTiles.add(tile);
Fabian Kozynski712ae392018-09-12 09:11:16 -0400172 mDistributeTiles = true;
173 requestLayout();
Jason Monkcaf37622015-08-18 12:33:50 -0400174 }
175
176 @Override
177 public void removeTile(TileRecord tile) {
178 if (mTiles.remove(tile)) {
Fabian Kozynski712ae392018-09-12 09:11:16 -0400179 mDistributeTiles = true;
180 requestLayout();
Jason Monkcaf37622015-08-18 12:33:50 -0400181 }
182 }
183
Amin Shaikh0f8ea5432018-03-27 11:09:27 -0400184 @Override
185 public void setExpansion(float expansion) {
Amin Shaikh4c9048c2018-04-20 11:27:46 -0400186 mLastExpansion = expansion;
187 updateSelected();
188 }
189
190 private void updateSelected() {
191 // Start the marquee when fully expanded and stop when fully collapsed. Leave as is for
192 // other expansion ratios since there is no way way to pause the marquee.
193 if (mLastExpansion > 0f && mLastExpansion < 1f) {
194 return;
195 }
196 boolean selected = mLastExpansion == 1f;
Rohan Shah2dbcb572018-05-25 10:51:22 -0700197
198 // Disable accessibility temporarily while we update selected state purely for the
199 // marquee. This will ensure that accessibility doesn't announce the TYPE_VIEW_SELECTED
200 // event on any of the children.
201 setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
Amin Shaikh6f570742018-06-01 17:18:19 -0400202 int currentItem = isLayoutRtl() ? mPages.size() - 1 - getCurrentItem() : getCurrentItem();
Amin Shaikh4c9048c2018-04-20 11:27:46 -0400203 for (int i = 0; i < mPages.size(); i++) {
Amin Shaikh6f570742018-06-01 17:18:19 -0400204 mPages.get(i).setSelected(i == currentItem ? selected : false);
Amin Shaikh0f8ea5432018-03-27 11:09:27 -0400205 }
Rohan Shah2dbcb572018-05-25 10:51:22 -0700206 setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
Amin Shaikh0f8ea5432018-03-27 11:09:27 -0400207 }
208
Jason Monk162011e2016-02-19 08:11:55 -0500209 public void setPageListener(PageListener listener) {
210 mPageListener = listener;
211 }
212
Jason Monkcaf37622015-08-18 12:33:50 -0400213 private void distributeTiles() {
Fabian Kozynski712ae392018-09-12 09:11:16 -0400214 emptyAndInflateOrRemovePages();
215
216 final int tileCount = mPages.get(0).maxTiles();
Jason Monkcaf37622015-08-18 12:33:50 -0400217 if (DEBUG) Log.d(TAG, "Distributing tiles");
Jason Monkcaf37622015-08-18 12:33:50 -0400218 int index = 0;
219 final int NT = mTiles.size();
220 for (int i = 0; i < NT; i++) {
221 TileRecord tile = mTiles.get(i);
Fabian Kozynski712ae392018-09-12 09:11:16 -0400222 if (mPages.get(index).mRecords.size() == tileCount) index++;
223 if (DEBUG) {
224 Log.d(TAG, "Adding " + tile.tile.getClass().getSimpleName() + " to "
225 + index);
Jason Monkcaf37622015-08-18 12:33:50 -0400226 }
Jason Monkcaf37622015-08-18 12:33:50 -0400227 mPages.get(index).addTile(tile);
228 }
Fabian Kozynski712ae392018-09-12 09:11:16 -0400229 }
230
231 private void emptyAndInflateOrRemovePages() {
232 final int nTiles = mTiles.size();
233 int numPages = nTiles / mPages.get(0).maxTiles();
234 // Add one more not full page if needed
235 numPages += (nTiles % mPages.get(0).maxTiles() == 0 ? 0 : 1);
236
237 final int NP = mPages.size();
238 for (int i = 0; i < NP; i++) {
239 mPages.get(i).removeAllViews();
Jason Monkcaf37622015-08-18 12:33:50 -0400240 }
Fabian Kozynski712ae392018-09-12 09:11:16 -0400241 if (NP == numPages) {
242 return;
243 }
244 while (mPages.size() < numPages) {
245 if (DEBUG) Log.d(TAG, "Adding page");
246 mPages.add((TilePage) LayoutInflater.from(getContext())
247 .inflate(R.layout.qs_paged_page, this, false));
248 }
249 while (mPages.size() > numPages) {
250 if (DEBUG) Log.d(TAG, "Removing page");
251 mPages.remove(mPages.size() - 1);
252 }
253 mPageIndicator.setNumPages(mPages.size());
254 setAdapter(mAdapter);
255 mAdapter.notifyDataSetChanged();
Fabian Kozynski407ddb22018-10-03 15:04:56 -0400256 if (mPageToRestore != -1) {
257 setCurrentItem(mPageToRestore, false);
258 mPageToRestore = -1;
259 }
Jason Monkcaf37622015-08-18 12:33:50 -0400260 }
261
262 @Override
Jason Monk9d02a432016-01-20 16:33:46 -0500263 public boolean updateResources() {
Rohan Shah3090e792018-04-12 00:01:00 -0400264 // Update bottom padding, useful for removing extra space once the panel page indicator is
265 // hidden.
Fabian Kozynski6eaf3ac2018-10-01 15:59:05 -0400266 Resources res = getContext().getResources();
Fabian Kozynski52bd8c22018-10-08 12:52:51 -0400267 mHorizontalClipBound = res.getDimensionPixelSize(R.dimen.notification_side_paddings);
268 setPadding(0, 0, 0,
Rohan Shah3090e792018-04-12 00:01:00 -0400269 getContext().getResources().getDimensionPixelSize(
270 R.dimen.qs_paged_tile_layout_padding_bottom));
Jason Monk9d02a432016-01-20 16:33:46 -0500271 boolean changed = false;
Jason Monkcaf37622015-08-18 12:33:50 -0400272 for (int i = 0; i < mPages.size(); i++) {
Jason Monk9d02a432016-01-20 16:33:46 -0500273 changed |= mPages.get(i).updateResources();
Jason Monkcaf37622015-08-18 12:33:50 -0400274 }
Jason Monk9d02a432016-01-20 16:33:46 -0500275 if (changed) {
Fabian Kozynski712ae392018-09-12 09:11:16 -0400276 mDistributeTiles = true;
277 requestLayout();
Jason Monk9d02a432016-01-20 16:33:46 -0500278 }
279 return changed;
Jason Monkcaf37622015-08-18 12:33:50 -0400280 }
281
282 @Override
Fabian Kozynski52bd8c22018-10-08 12:52:51 -0400283 protected void onLayout(boolean changed, int l, int t, int r, int b) {
284 super.onLayout(changed, l, t, r, b);
Fabian Kozynski87bdf0d2019-04-01 09:52:57 -0400285 mClippingRect.set(mHorizontalClipBound, 0, (r - l) - mHorizontalClipBound, b - t);
286 setClipBounds(mClippingRect);
Fabian Kozynski52bd8c22018-10-08 12:52:51 -0400287 }
288
289 @Override
Jason Monkcaf37622015-08-18 12:33:50 -0400290 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Fabian Kozynski712ae392018-09-12 09:11:16 -0400291
292 final int nTiles = mTiles.size();
293 if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) {
294
295 // Only change the pages if the number of rows or columns (from updateResources) has
296 // changed or the tiles have changed
297 if (mPages.get(0).updateMaxRows(heightMeasureSpec, nTiles) || mDistributeTiles) {
298 mDistributeTiles = false;
299 distributeTiles();
300 }
301
302 final int nRows = mPages.get(0).mRows;
303 for (int i = 0; i < mPages.size(); i++) {
304 TilePage t = mPages.get(i);
305 t.mRows = nRows;
306 }
307 }
308
Jason Monkcaf37622015-08-18 12:33:50 -0400309 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Fabian Kozynski712ae392018-09-12 09:11:16 -0400310
Jason Monkcaf37622015-08-18 12:33:50 -0400311 // The ViewPager likes to eat all of the space, instead force it to wrap to the max height
312 // of the pages.
313 int maxHeight = 0;
314 final int N = getChildCount();
315 for (int i = 0; i < N; i++) {
316 int height = getChildAt(i).getMeasuredHeight();
317 if (height > maxHeight) {
318 maxHeight = height;
319 }
320 }
Jason Monkf13413e2017-02-15 15:49:32 -0500321 setMeasuredDimension(getMeasuredWidth(), maxHeight + getPaddingBottom());
Jason Monkcaf37622015-08-18 12:33:50 -0400322 }
323
Jason Monk8fb77872016-03-03 16:39:42 -0500324 public int getColumnCount() {
325 if (mPages.size() == 0) return 0;
326 return mPages.get(0).mColumns;
327 }
328
Fabian Kozynski802279f2018-09-07 13:44:54 -0400329 public int getNumVisibleTiles() {
330 if (mPages.size() == 0) return 0;
331 TilePage currentPage = mPages.get(getCurrentItem());
332 return currentPage.mRecords.size();
333 }
334
Amin Shaikha07a17b2018-02-23 16:02:52 -0500335 public void startTileReveal(Set<String> tileSpecs, final Runnable postAnimation) {
Amin Shaikh5484d0f2018-07-31 10:44:11 -0400336 if (tileSpecs.isEmpty() || mPages.size() < 2 || getScrollX() != 0 || !beginFakeDrag()) {
Amin Shaikha07a17b2018-02-23 16:02:52 -0500337 // Do not start the reveal animation unless there are tiles to animate, multiple
338 // TilePages available and the user has not already started dragging.
339 return;
340 }
341
342 final int lastPageNumber = mPages.size() - 1;
343 final TilePage lastPage = mPages.get(lastPageNumber);
344 final ArrayList<Animator> bounceAnims = new ArrayList<>();
345 for (TileRecord tr : lastPage.mRecords) {
346 if (tileSpecs.contains(tr.tile.getTileSpec())) {
347 bounceAnims.add(setupBounceAnimator(tr.tileView, bounceAnims.size()));
348 }
349 }
350
351 if (bounceAnims.isEmpty()) {
352 // All tileSpecs are on the first page. Nothing to do.
353 // TODO: potentially show a bounce animation for first page QS tiles
Amin Shaikh5484d0f2018-07-31 10:44:11 -0400354 endFakeDrag();
Amin Shaikha07a17b2018-02-23 16:02:52 -0500355 return;
356 }
357
358 mBounceAnimatorSet = new AnimatorSet();
359 mBounceAnimatorSet.playTogether(bounceAnims);
360 mBounceAnimatorSet.addListener(new AnimatorListenerAdapter() {
361 @Override
362 public void onAnimationEnd(Animator animation) {
363 mBounceAnimatorSet = null;
364 postAnimation.run();
365 }
366 });
Amin Shaikh5484d0f2018-07-31 10:44:11 -0400367 setOffscreenPageLimit(lastPageNumber); // Ensure the page to reveal has been inflated.
368 int dx = getWidth() * lastPageNumber;
369 mScroller.startScroll(getScrollX(), getScrollY(), isLayoutRtl() ? -dx : dx, 0,
370 REVEAL_SCROLL_DURATION_MILLIS);
Amin Shaikha07a17b2018-02-23 16:02:52 -0500371 postInvalidateOnAnimation();
372 }
373
374 private static Animator setupBounceAnimator(View view, int ordinal) {
375 view.setAlpha(0f);
376 view.setScaleX(0f);
377 view.setScaleY(0f);
378 ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(view,
379 PropertyValuesHolder.ofFloat(View.ALPHA, 1),
380 PropertyValuesHolder.ofFloat(View.SCALE_X, 1),
381 PropertyValuesHolder.ofFloat(View.SCALE_Y, 1));
382 animator.setDuration(BOUNCE_ANIMATION_DURATION);
383 animator.setStartDelay(ordinal * TILE_ANIMATION_STAGGER_DELAY);
384 animator.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
385 return animator;
386 }
387
388 private final ViewPager.OnPageChangeListener mOnPageChangeListener =
389 new ViewPager.SimpleOnPageChangeListener() {
390 @Override
391 public void onPageSelected(int position) {
Amin Shaikh4c9048c2018-04-20 11:27:46 -0400392 updateSelected();
Amin Shaikha07a17b2018-02-23 16:02:52 -0500393 if (mPageIndicator == null) return;
394 if (mPageListener != null) {
395 mPageListener.onPageChanged(isLayoutRtl() ? position == mPages.size() - 1
396 : position == 0);
397 }
398 }
399
400 @Override
401 public void onPageScrolled(int position, float positionOffset,
402 int positionOffsetPixels) {
403 if (mPageIndicator == null) return;
Rohan Shah3090e792018-04-12 00:01:00 -0400404 mPageIndicatorPosition = position + positionOffset;
405 mPageIndicator.setLocation(mPageIndicatorPosition);
Amin Shaikha07a17b2018-02-23 16:02:52 -0500406 if (mPageListener != null) {
407 mPageListener.onPageChanged(positionOffsetPixels == 0 &&
408 (isLayoutRtl() ? position == mPages.size() - 1 : position == 0));
409 }
410 }
411 };
412
Jason Monkcaf37622015-08-18 12:33:50 -0400413 public static class TilePage extends TileLayout {
Fabian Kozynski712ae392018-09-12 09:11:16 -0400414
Jason Monkcaf37622015-08-18 12:33:50 -0400415 public TilePage(Context context, AttributeSet attrs) {
416 super(context, attrs);
Jason Monkbd6dbb02015-09-03 15:46:25 -0400417 }
418
Jason Monkbd6dbb02015-09-03 15:46:25 -0400419 public boolean isFull() {
Fabian Kozynski712ae392018-09-12 09:11:16 -0400420 return mRecords.size() >= mColumns * mRows;
421 }
422
423 public int maxTiles() {
424 return mColumns * mRows;
Jason Monkcaf37622015-08-18 12:33:50 -0400425 }
Fabian Kozynski52bd8c22018-10-08 12:52:51 -0400426
427 @Override
428 public boolean updateResources() {
429 final int sidePadding = getContext().getResources().getDimensionPixelSize(
430 R.dimen.notification_side_paddings);
431 setPadding(sidePadding, 0, sidePadding, 0);
432 return super.updateResources();
433 }
Jason Monkcaf37622015-08-18 12:33:50 -0400434 }
435
436 private final PagerAdapter mAdapter = new PagerAdapter() {
Amin Shaikh9978c552018-03-22 07:24:41 -0400437 @Override
Jason Monkcaf37622015-08-18 12:33:50 -0400438 public void destroyItem(ViewGroup container, int position, Object object) {
439 if (DEBUG) Log.d(TAG, "Destantiating " + position);
Jason Monkcaf37622015-08-18 12:33:50 -0400440 container.removeView((View) object);
Amin Shaikh9978c552018-03-22 07:24:41 -0400441 updateListening();
Jason Monkcaf37622015-08-18 12:33:50 -0400442 }
443
Amin Shaikh9978c552018-03-22 07:24:41 -0400444 @Override
Jason Monkcaf37622015-08-18 12:33:50 -0400445 public Object instantiateItem(ViewGroup container, int position) {
446 if (DEBUG) Log.d(TAG, "Instantiating " + position);
Jason Monk51fb85a2016-03-28 14:06:04 -0400447 if (isLayoutRtl()) {
448 position = mPages.size() - 1 - position;
449 }
Jason Monke4e69302016-01-20 11:27:15 -0500450 ViewGroup view = mPages.get(position);
Amin Shaikh53bc0832018-09-17 15:06:18 -0400451 if (view.getParent() != null) {
452 container.removeView(view);
453 }
Jason Monkcaf37622015-08-18 12:33:50 -0400454 container.addView(view);
Amin Shaikh9978c552018-03-22 07:24:41 -0400455 updateListening();
Jason Monkcaf37622015-08-18 12:33:50 -0400456 return view;
457 }
458
459 @Override
460 public int getCount() {
Fabian Kozynski712ae392018-09-12 09:11:16 -0400461 return mPages.size();
Jason Monkcaf37622015-08-18 12:33:50 -0400462 }
463
464 @Override
465 public boolean isViewFromObject(View view, Object object) {
466 return view == object;
467 }
468 };
Jason Monk162011e2016-02-19 08:11:55 -0500469
470 public interface PageListener {
Jason Monk66eaf312016-02-25 12:29:29 -0500471 void onPageChanged(boolean isFirst);
Jason Monk162011e2016-02-19 08:11:55 -0500472 }
Jason Monkcaf37622015-08-18 12:33:50 -0400473}