Search in sources :

Example 76 with Scroller

use of android.widget.Scroller in project AndroidDevelop by 7449.

the class WheelScroller method setInterpolator.

/**
     * Set the the specified scrolling interpolator
     *
     * @param interpolator the interpolator
     */
public void setInterpolator(Interpolator interpolator) {
    scroller.forceFinished(true);
    scroller = new Scroller(context, interpolator);
}
Also used : Scroller(android.widget.Scroller)

Example 77 with Scroller

use of android.widget.Scroller in project UltimateAndroid by cymcsg.

the class ViewPagerEx method initViewPager.

void initViewPager() {
    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffectCompat(context);
    mRightEdge = new EdgeEffectCompat(context);
    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);
    ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate());
    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
}
Also used : Context(android.content.Context) ViewConfiguration(android.view.ViewConfiguration) EdgeEffectCompat(android.support.v4.widget.EdgeEffectCompat) Scroller(android.widget.Scroller)

Example 78 with Scroller

use of android.widget.Scroller in project UltimateAndroid by cymcsg.

the class WeekView method init.

private void init() {
    // Get the date today.
    mToday = Calendar.getInstance();
    mToday.set(Calendar.HOUR_OF_DAY, 0);
    mToday.set(Calendar.MINUTE, 0);
    mToday.set(Calendar.SECOND, 0);
    // Scrolling initialization.
    mGestureDetector = new GestureDetectorCompat(mContext, mGestureListener);
    mScroller = new OverScroller(mContext);
    mStickyScroller = new Scroller(mContext);
    // Measure settings for time column.
    mTimeTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTimeTextPaint.setTextAlign(Paint.Align.RIGHT);
    mTimeTextPaint.setTextSize(mTextSize);
    mTimeTextPaint.setColor(mHeaderColumnTextColor);
    Rect rect = new Rect();
    mTimeTextPaint.getTextBounds("00 PM", 0, "00 PM".length(), rect);
    mTimeTextWidth = mTimeTextPaint.measureText("00 PM");
    mTimeTextHeight = rect.height();
    mHeaderMarginBottom = mTimeTextHeight / 2;
    // Measure settings for header row.
    mHeaderTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mHeaderTextPaint.setColor(mHeaderColumnTextColor);
    mHeaderTextPaint.setTextAlign(Paint.Align.CENTER);
    mHeaderTextPaint.setTextSize(mTextSize);
    mHeaderTextPaint.getTextBounds("00 PM", 0, "00 PM".length(), rect);
    mHeaderTextHeight = rect.height();
    mHeaderTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
    // Prepare header background paint.
    mHeaderBackgroundPaint = new Paint();
    mHeaderBackgroundPaint.setColor(mHeaderRowBackgroundColor);
    // Prepare day background color paint.
    mDayBackgroundPaint = new Paint();
    mDayBackgroundPaint.setColor(mDayBackgroundColor);
    // Prepare hour separator color paint.
    mHourSeparatorPaint = new Paint();
    mHourSeparatorPaint.setStyle(Paint.Style.STROKE);
    mHourSeparatorPaint.setStrokeWidth(mHourSeparatorHeight);
    mHourSeparatorPaint.setColor(mHourSeparatorColor);
    // Prepare today background color paint.
    mTodayBackgroundPaint = new Paint();
    mTodayBackgroundPaint.setColor(mTodayBackgroundColor);
    // Prepare today header text color paint.
    mTodayHeaderTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTodayHeaderTextPaint.setTextAlign(Paint.Align.CENTER);
    mTodayHeaderTextPaint.setTextSize(mTextSize);
    mTodayHeaderTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
    mTodayHeaderTextPaint.setColor(mTodayHeaderTextColor);
    // Prepare event background color.
    mEventBackgroundPaint = new Paint();
    mEventBackgroundPaint.setColor(Color.rgb(174, 208, 238));
    // Prepare header column background color.
    mHeaderColumnBackgroundPaint = new Paint();
    mHeaderColumnBackgroundPaint.setColor(mHeaderColumnBackgroundColor);
    // Prepare event text size and color.
    mEventTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    mEventTextPaint.setStyle(Paint.Style.FILL);
    mEventTextPaint.setColor(mEventTextColor);
    mEventTextPaint.setTextSize(mEventTextSize);
    mStartDate = (Calendar) mToday.clone();
    // Set default event color.
    mDefaultEventColor = Color.parseColor("#9fc6e7");
}
Also used : Rect(android.graphics.Rect) OverScroller(android.widget.OverScroller) Scroller(android.widget.Scroller) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat) OverScroller(android.widget.OverScroller) TextPaint(android.text.TextPaint)

Example 79 with Scroller

use of android.widget.Scroller in project cornerstone by Onskreen.

the class ViewRootImpl method scrollToRectOrFocus.

boolean scrollToRectOrFocus(Rect rectangle, boolean immediate) {
    final View.AttachInfo attachInfo = mAttachInfo;
    final Rect ci = attachInfo.mContentInsets;
    final Rect vi = attachInfo.mVisibleInsets;
    int scrollY = 0;
    boolean handled = false;
    if (vi.left > ci.left || vi.top > ci.top || vi.right > ci.right || vi.bottom > ci.bottom) {
        // We'll assume that we aren't going to change the scroll
        // offset, since we want to avoid that unless it is actually
        // going to make the focus visible...  otherwise we scroll
        // all over the place.
        scrollY = mScrollY;
        // We can be called for two different situations: during a draw,
        // to update the scroll position if the focus has changed (in which
        // case 'rectangle' is null), or in response to a
        // requestChildRectangleOnScreen() call (in which case 'rectangle'
        // is non-null and we just want to scroll to whatever that
        // rectangle is).
        View focus = mRealFocusedView;
        // line checks whether the view is still in our hierarchy.
        if (focus == null || focus.mAttachInfo != mAttachInfo) {
            mRealFocusedView = null;
            return false;
        }
        if (focus != mLastScrolledFocus) {
            // If the focus has changed, then ignore any requests to scroll
            // to a rectangle; first we want to make sure the entire focus
            // view is visible.
            rectangle = null;
        }
        if (DEBUG_INPUT_RESIZE)
            Log.v(TAG, "Eval scroll: focus=" + focus + " rectangle=" + rectangle + " ci=" + ci + " vi=" + vi);
        if (focus == mLastScrolledFocus && !mScrollMayChange && rectangle == null) {
            // as they are.
            if (DEBUG_INPUT_RESIZE)
                Log.v(TAG, "Keeping scroll y=" + mScrollY + " vi=" + vi.toShortString());
        } else if (focus != null) {
            // We need to determine if the currently focused view is
            // within the visible part of the window and, if not, apply
            // a pan so it can be seen.
            mLastScrolledFocus = focus;
            mScrollMayChange = false;
            if (DEBUG_INPUT_RESIZE)
                Log.v(TAG, "Need to scroll?");
            // Try to find the rectangle from the focus view.
            if (focus.getGlobalVisibleRect(mVisRect, null)) {
                if (DEBUG_INPUT_RESIZE)
                    Log.v(TAG, "Root w=" + mView.getWidth() + " h=" + mView.getHeight() + " ci=" + ci.toShortString() + " vi=" + vi.toShortString());
                if (rectangle == null) {
                    focus.getFocusedRect(mTempRect);
                    if (DEBUG_INPUT_RESIZE)
                        Log.v(TAG, "Focus " + focus + ": focusRect=" + mTempRect.toShortString());
                    if (mView instanceof ViewGroup) {
                        ((ViewGroup) mView).offsetDescendantRectToMyCoords(focus, mTempRect);
                    }
                    if (DEBUG_INPUT_RESIZE)
                        Log.v(TAG, "Focus in window: focusRect=" + mTempRect.toShortString() + " visRect=" + mVisRect.toShortString());
                } else {
                    mTempRect.set(rectangle);
                    if (DEBUG_INPUT_RESIZE)
                        Log.v(TAG, "Request scroll to rect: " + mTempRect.toShortString() + " visRect=" + mVisRect.toShortString());
                }
                if (mTempRect.intersect(mVisRect)) {
                    if (DEBUG_INPUT_RESIZE)
                        Log.v(TAG, "Focus window visible rect: " + mTempRect.toShortString());
                    if (mTempRect.height() > (mView.getHeight() - vi.top - vi.bottom)) {
                        // best is probably just to leave things as-is.
                        if (DEBUG_INPUT_RESIZE)
                            Log.v(TAG, "Too tall; leaving scrollY=" + scrollY);
                    } else if ((mTempRect.top - scrollY) < vi.top) {
                        scrollY -= vi.top - (mTempRect.top - scrollY);
                        if (DEBUG_INPUT_RESIZE)
                            Log.v(TAG, "Top covered; scrollY=" + scrollY);
                    } else if ((mTempRect.bottom - scrollY) > (mView.getHeight() - vi.bottom)) {
                        scrollY += (mTempRect.bottom - scrollY) - (mView.getHeight() - vi.bottom);
                        if (DEBUG_INPUT_RESIZE)
                            Log.v(TAG, "Bottom covered; scrollY=" + scrollY);
                    }
                    handled = true;
                }
            }
        }
    }
    if (scrollY != mScrollY) {
        if (DEBUG_INPUT_RESIZE)
            Log.v(TAG, "Pan scroll changed: old=" + mScrollY + " , new=" + scrollY);
        if (!immediate && mResizeBuffer == null) {
            if (mScroller == null) {
                mScroller = new Scroller(mView.getContext());
            }
            mScroller.startScroll(0, mScrollY, 0, scrollY - mScrollY);
        } else if (mScroller != null) {
            mScroller.abortAnimation();
        }
        mScrollY = scrollY;
    }
    return handled;
}
Also used : Rect(android.graphics.Rect) Scroller(android.widget.Scroller) Paint(android.graphics.Paint) Point(android.graphics.Point) AttachInfo(android.view.View.AttachInfo)

Example 80 with Scroller

use of android.widget.Scroller in project BookReader by JustWayward.

the class DirectionalViewpager method initViewPager.

void initViewPager() {
    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffectCompat(context);
    mRightEdge = new EdgeEffectCompat(context);
    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);
    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);
    ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate());
    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {

        private final Rect mTempRect = new Rect();

        @Override
        public WindowInsetsCompat onApplyWindowInsets(final View v, final WindowInsetsCompat originalInsets) {
            // First let the ViewPager itself try and consume them...
            final WindowInsetsCompat applied = ViewCompat.onApplyWindowInsets(v, originalInsets);
            if (applied.isConsumed()) {
                // If the ViewPager consumed all insets, return now
                return applied;
            }
            // Now we'll manually dispatch the insets to our children. Since ViewPager
            // children are always full-height, we do not want to use the standard
            // ViewGroup dispatchApplyWindowInsets since if child 0 consumes them,
            // the rest of the children will not receive any insets. To workaround this
            // we manually dispatch the applied insets, not allowing children to
            // consume them from each other. We do however keep track of any insets
            // which are consumed, returning the union of our children's consumption
            final Rect res = mTempRect;
            res.left = applied.getSystemWindowInsetLeft();
            res.top = applied.getSystemWindowInsetTop();
            res.right = applied.getSystemWindowInsetRight();
            res.bottom = applied.getSystemWindowInsetBottom();
            for (int i = 0, count = getChildCount(); i < count; i++) {
                final WindowInsetsCompat childInsets = ViewCompat.dispatchApplyWindowInsets(getChildAt(i), applied);
                // Now keep track of any consumed by tracking each dimension's min
                // value
                res.left = Math.min(childInsets.getSystemWindowInsetLeft(), res.left);
                res.top = Math.min(childInsets.getSystemWindowInsetTop(), res.top);
                res.right = Math.min(childInsets.getSystemWindowInsetRight(), res.right);
                res.bottom = Math.min(childInsets.getSystemWindowInsetBottom(), res.bottom);
            }
            // Now return a new WindowInsets, using the consumed window insets
            return applied.replaceSystemWindowInsets(res.left, res.top, res.right, res.bottom);
        }
    });
}
Also used : Context(android.content.Context) Rect(android.graphics.Rect) View(android.view.View) WindowInsetsCompat(android.support.v4.view.WindowInsetsCompat) ViewConfiguration(android.view.ViewConfiguration) EdgeEffectCompat(android.support.v4.widget.EdgeEffectCompat) Scroller(android.widget.Scroller)

Aggregations

Scroller (android.widget.Scroller)89 ViewConfiguration (android.view.ViewConfiguration)41 Context (android.content.Context)29 Paint (android.graphics.Paint)14 EdgeEffectCompat (android.support.v4.widget.EdgeEffectCompat)14 GestureDetector (android.view.GestureDetector)13 Rect (android.graphics.Rect)12 Point (android.graphics.Point)8 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)8 DisplayMetrics (android.util.DisplayMetrics)6 View (android.view.View)4 OnGlobalLayoutListener (android.view.ViewTreeObserver.OnGlobalLayoutListener)4 BounceInterpolator (android.view.animation.BounceInterpolator)4 Interpolator (android.view.animation.Interpolator)4 SuppressLint (android.annotation.SuppressLint)3 TypedArray (android.content.res.TypedArray)3 LinearInterpolator (android.view.animation.LinearInterpolator)3 ImageView (android.widget.ImageView)3 OverScroller (android.widget.OverScroller)3 Animator (com.nineoldandroids.animation.Animator)3