12c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer/*
22c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer * Copyright (C) 2017 The Android Open Source Project
32c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer *
42c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer * Licensed under the Apache License, Version 2.0 (the "License");
52c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer * you may not use this file except in compliance with the License.
62c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer * You may obtain a copy of the License at
72c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer *
82c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer *      http://www.apache.org/licenses/LICENSE-2.0
92c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer *
102c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer * Unless required by applicable law or agreed to in writing, software
112c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer * distributed under the License is distributed on an "AS IS" BASIS,
122c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer * See the License for the specific language governing permissions and
142c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer * limitations under the License.
152c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer */
162c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyerpackage com.android.car.view;
172c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
182c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyerimport android.content.Context;
192c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyerimport android.graphics.PorterDuff;
202c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyerimport android.util.AttributeSet;
212c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyerimport android.view.LayoutInflater;
222c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyerimport android.view.View;
232c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyerimport android.view.ViewGroup;
242c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyerimport android.view.animation.AccelerateDecelerateInterpolator;
252c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyerimport android.view.animation.Interpolator;
262c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyerimport android.widget.FrameLayout;
272c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyerimport android.widget.ImageView;
282c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
292c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyerimport com.android.car.stream.ui.R;
302c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
312c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer/**
322c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer * A custom view to provide list scroll behaviour -- up/down buttons and scroll indicator.
332c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer *
342c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer * @hide
352c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer */
362c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyerpublic class PagedScrollBarView extends FrameLayout
372c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        implements View.OnClickListener, View.OnLongClickListener {
382c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    private static final float BUTTON_DISABLED_ALPHA = 0.2f;
392c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
402c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    /**
412c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer     * Listener for when the list should paginate.
422c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer     */
432c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    public interface PaginationListener {
442c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        int PAGE_UP = 0;
452c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        int PAGE_DOWN = 1;
462c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
472c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        /** Called when the linked view should be paged in the given direction */
482c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        void onPaginate(int direction);
492c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
502c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
512c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    private final ImageView mUpButton;
522c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    private final ImageView mDownButton;
532c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    private final ImageView mScrollThumb;
542c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    /** The "filler" view between the up and down buttons */
552c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    private final View mFiller;
562c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    private final Interpolator mPaginationInterpolator = new AccelerateDecelerateInterpolator();
572c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    private final int mMinThumbLength;
582c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    private final int mMaxThumbLength;
592c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    private PaginationListener mPaginationListener;
602c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
612c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    public PagedScrollBarView(
622c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer            Context context, AttributeSet attrs) {
632c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        this(context, attrs, 0 /*defStyleAttrs*/, 0 /*defStyleRes*/);
642c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
652c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
662c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    public PagedScrollBarView(
672c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer            Context context, AttributeSet attrs, int defStyleAttrs) {
682c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        this(context, attrs, defStyleAttrs, 0 /*defStyleRes*/);
692c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
702c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
712c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    public PagedScrollBarView(
722c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer            Context context, AttributeSet attrs, int defStyleAttrs, int defStyleRes) {
732c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        super(context, attrs, defStyleAttrs, defStyleRes);
742c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
752c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        LayoutInflater inflater = (LayoutInflater) context
762c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
772c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        inflater.inflate(
782c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer                R.layout.car_paged_scrollbar_buttons, this /*root*/, true /*attachToRoot*/);
792c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
802c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mUpButton = (ImageView) findViewById(R.id.page_up);
812c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mUpButton.setImageDrawable(context.getDrawable(R.drawable.ic_up_button));
822c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mUpButton.setOnClickListener(this);
832c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mUpButton.setOnLongClickListener(this);
842c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mDownButton = (ImageView) findViewById(R.id.page_down);
852c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mDownButton.setImageDrawable(context.getDrawable(R.drawable.ic_down_button));
862c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mDownButton.setOnClickListener(this);
872c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mDownButton.setOnLongClickListener(this);
882c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
892c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mScrollThumb = (ImageView) findViewById(R.id.scrollbar_thumb);
902c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mScrollThumb.setAlpha(0.5f);
912c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
922c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mFiller = findViewById(R.id.filler);
932c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
942c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mMinThumbLength = getResources().getDimensionPixelSize(R.dimen.min_thumb_height);
952c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mMaxThumbLength = getResources().getDimensionPixelSize(R.dimen.max_thumb_height);
962c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
972c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        if (!context.getResources().getBoolean(R.bool.car_true_for_touch)) {
982c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer            // Don't show the pagination buttons if there isn't touch.
992c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer            mUpButton.setVisibility(View.GONE);
1002c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer            mDownButton.setVisibility(View.GONE);
1012c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        }
1022c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
1032c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1042c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    @Override
1052c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    public void onClick(View v) {
1062c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        dispatchPageClick(v);
1072c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
1082c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1092c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    @Override
1102c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    public boolean onLongClick(View v) {
1112c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        dispatchPageClick(v);
1122c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        return true;
1132c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
1142c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1152c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    public void setPaginationListener(PaginationListener listener) {
1162c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mPaginationListener = listener;
1172c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
1182c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1192c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    /** Returns {@code true} if the "up" button is pressed */
1202c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    public boolean isUpPressed() {
1212c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        return mUpButton.isPressed();
1222c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
1232c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1242c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    /** Returns {@code true} if the "down" button is pressed */
1252c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    public boolean isDownPressed() {
1262c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        return mDownButton.isPressed();
1272c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
1282c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1292c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    /** Sets the range, offset and extent of the scroll bar. See {@link android.view.View}. */
1302c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    protected void setParameters(int range, int offset, int extent, boolean animate) {
1312c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        final int size = mFiller.getHeight() - mFiller.getPaddingTop() - mFiller.getPaddingBottom();
1322c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1332c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        int thumbLength = extent * size / range;
1342c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        thumbLength = Math.max(Math.min(thumbLength, mMaxThumbLength), mMinThumbLength);
1352c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1362c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        int thumbOffset = size - thumbLength;
1372c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        if (isDownEnabled()) {
1382c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer            // We need to adjust the offset so that it fits into the possible space inside the
1392c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer            // filler with regarding to the constraints set by mMaxThumbLength and mMinThumbLength.
1402c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer            thumbOffset = (size - thumbLength) * offset / range;
1412c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        }
1422c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1432c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        // Sets the size of the thumb and request a redraw if needed.
1442c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        final ViewGroup.LayoutParams lp = mScrollThumb.getLayoutParams();
1452c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        if (lp.height != thumbLength) {
1462c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer            lp.height = thumbLength;
1472c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer            mScrollThumb.requestLayout();
1482c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        }
1492c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1502c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        moveY(mScrollThumb, thumbOffset, animate);
1512c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
1522c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1532c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    /** Sets auto day/night mode */
1542c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    protected void setAutoDayNightMode() {
1552c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        int color = getResources().getColor(R.color.car_tint);
1562c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mUpButton.setColorFilter(color, PorterDuff.Mode.SRC_IN);
1572c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mUpButton.setBackgroundResource(R.drawable.car_pagination_background);
1582c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mDownButton.setColorFilter(color, PorterDuff.Mode.SRC_IN);
1592c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mDownButton.setBackgroundResource(R.drawable.car_pagination_background);
1602c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1612c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mScrollThumb.setBackgroundColor(color);
1622c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
1632c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1642c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    /** Sets auto light mode */
1652c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    protected void setLightMode() {
1662c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        int color = getResources().getColor(R.color.car_tint_light);
1672c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mUpButton.setColorFilter(color, PorterDuff.Mode.SRC_IN);
1682c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mUpButton.setBackgroundResource(R.drawable.car_pagination_background_light);
1692c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mDownButton.setColorFilter(color, PorterDuff.Mode.SRC_IN);
1702c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mDownButton.setBackgroundResource(R.drawable.car_pagination_background_light);
1712c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1722c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mScrollThumb.setBackgroundColor(color);
1732c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
1742c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1752c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    /** Sets auto dark mode */
1762c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    protected void setDarkMode() {
1772c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        int color = getResources().getColor(R.color.car_tint_dark);
1782c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mUpButton.setColorFilter(color, PorterDuff.Mode.SRC_IN);
1792c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mUpButton.setBackgroundResource(R.drawable.car_pagination_background_dark);
1802c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mDownButton.setColorFilter(color, PorterDuff.Mode.SRC_IN);
1812c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mDownButton.setBackgroundResource(R.drawable.car_pagination_background_dark);
1822c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1832c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mScrollThumb.setBackgroundColor(color);
1842c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
1852c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1862c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    protected void setUpEnabled(boolean enabled) {
1872c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mUpButton.setEnabled(enabled);
1882c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mUpButton.setAlpha(enabled ? 1f : BUTTON_DISABLED_ALPHA);
1892c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
1902c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1912c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    protected void setDownEnabled(boolean enabled) {
1922c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mDownButton.setEnabled(enabled);
1932c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        mDownButton.setAlpha(enabled ? 1f : BUTTON_DISABLED_ALPHA);
1942c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
1952c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
1962c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    protected boolean isDownEnabled() {
1972c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        return mDownButton.isEnabled();
1982c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
1992c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
2002c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    private void dispatchPageClick(View v) {
2012c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        final PaginationListener listener = mPaginationListener;
2022c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        if (listener == null) {
2032c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer            return;
2042c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        }
2052c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
2062c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        final int direction = (v.getId() == R.id.page_up)
2072c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer                ? PaginationListener.PAGE_UP : PaginationListener.PAGE_DOWN;
2082c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        listener.onPaginate(direction);
2092c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
2102c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer
2112c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    /** Moves the given view to the specified 'y' position. */
2122c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    private void moveY(final View view, float newPosition, boolean animate) {
2132c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        final int duration = animate ? 200 : 0;
2142c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer        view.animate()
2152c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer                .y(newPosition)
2162c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer                .setDuration(duration)
2172c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer                .setInterpolator(mPaginationInterpolator)
2182c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer                .start();
2192c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer    }
2202c147cd63a518c3b779697d7b5cb53d86bfc2a00Rakesh Iyer}
221