Search in sources :

Example 31 with Scroller

use of android.widget.Scroller in project android_frameworks_base by DirtyUnicorns.

the class ViewRootImpl method scrollToRectOrFocus.

boolean scrollToRectOrFocus(Rect rectangle, boolean immediate) {
    final Rect ci = mAttachInfo.mContentInsets;
    final Rect vi = mAttachInfo.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).
        final View focus = mView.findFocus();
        if (focus == null) {
            return false;
        }
        View lastScrolledFocus = (mLastScrolledFocus != null) ? mLastScrolledFocus.get() : null;
        if (focus != lastScrolledFocus) {
            // 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(mTag, "Eval scroll: focus=" + focus + " rectangle=" + rectangle + " ci=" + ci + " vi=" + vi);
        if (focus == lastScrolledFocus && !mScrollMayChange && rectangle == null) {
            // as they are.
            if (DEBUG_INPUT_RESIZE)
                Log.v(mTag, "Keeping scroll y=" + mScrollY + " vi=" + vi.toShortString());
        } else {
            // 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 = new WeakReference<View>(focus);
            mScrollMayChange = false;
            if (DEBUG_INPUT_RESIZE)
                Log.v(mTag, "Need to scroll?");
            // Try to find the rectangle from the focus view.
            if (focus.getGlobalVisibleRect(mVisRect, null)) {
                if (DEBUG_INPUT_RESIZE)
                    Log.v(mTag, "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(mTag, "Focus " + focus + ": focusRect=" + mTempRect.toShortString());
                    if (mView instanceof ViewGroup) {
                        ((ViewGroup) mView).offsetDescendantRectToMyCoords(focus, mTempRect);
                    }
                    if (DEBUG_INPUT_RESIZE)
                        Log.v(mTag, "Focus in window: focusRect=" + mTempRect.toShortString() + " visRect=" + mVisRect.toShortString());
                } else {
                    mTempRect.set(rectangle);
                    if (DEBUG_INPUT_RESIZE)
                        Log.v(mTag, "Request scroll to rect: " + mTempRect.toShortString() + " visRect=" + mVisRect.toShortString());
                }
                if (mTempRect.intersect(mVisRect)) {
                    if (DEBUG_INPUT_RESIZE)
                        Log.v(mTag, "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(mTag, "Too tall; leaving scrollY=" + scrollY);
                    } else // and bottom both visible, but we still need to scroll it back to 0.
                    if (mTempRect.top < vi.top) {
                        scrollY = mTempRect.top - vi.top;
                        if (DEBUG_INPUT_RESIZE)
                            Log.v(mTag, "Top covered; scrollY=" + scrollY);
                    } else if (mTempRect.bottom > (mView.getHeight() - vi.bottom)) {
                        scrollY = mTempRect.bottom - (mView.getHeight() - vi.bottom);
                        if (DEBUG_INPUT_RESIZE)
                            Log.v(mTag, "Bottom covered; scrollY=" + scrollY);
                    } else {
                        scrollY = 0;
                    }
                    handled = true;
                }
            }
        }
    }
    if (scrollY != mScrollY) {
        if (DEBUG_INPUT_RESIZE)
            Log.v(mTag, "Pan scroll changed: old=" + mScrollY + " , new=" + scrollY);
        if (!immediate) {
            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) Point(android.graphics.Point)

Example 32 with Scroller

use of android.widget.Scroller in project android_frameworks_base by ParanoidAndroid.

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).
        final View focus = mView.findFocus();
        if (focus == null) {
            return false;
        }
        View lastScrolledFocus = (mLastScrolledFocus != null) ? mLastScrolledFocus.get() : null;
        if (focus != lastScrolledFocus) {
            // 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 == lastScrolledFocus && !mScrollMayChange && rectangle == null) {
            // as they are.
            if (DEBUG_INPUT_RESIZE)
                Log.v(TAG, "Keeping scroll y=" + mScrollY + " vi=" + vi.toShortString());
        } else {
            // 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 = new WeakReference<View>(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 33 with Scroller

use of android.widget.Scroller in project android_frameworks_base by ParanoidAndroid.

the class WebViewClassic method init.

/**
     * See {@link WebViewProvider#init(Map, boolean)}
     */
@Override
public void init(Map<String, Object> javaScriptInterfaces, boolean privateBrowsing) {
    Context context = mContext;
    // Used by the chrome stack to find application paths
    JniUtil.setContext(context);
    mCallbackProxy = new CallbackProxy(context, this);
    mViewManager = new ViewManager(this);
    L10nUtils.setApplicationContext(context.getApplicationContext());
    mWebViewCore = new WebViewCore(context, this, mCallbackProxy, javaScriptInterfaces);
    mDatabase = WebViewDatabaseClassic.getInstance(context);
    //TODO Use OverScroller's flywheel
    mScroller = new OverScroller(context, null, 0, 0, false);
    mZoomManager = new ZoomManager(this, mCallbackProxy);
    /* The init method must follow the creation of certain member variables,
         * such as the mZoomManager.
         */
    init();
    setupPackageListener(context);
    setupProxyListener(context);
    setupTrustStorageListener(context);
    updateMultiTouchSupport(context);
    if (privateBrowsing) {
        startPrivateBrowsing();
    }
    mAutoFillData = new WebViewCore.AutoFillData();
    mEditTextScroller = new Scroller(context);
    // Calculate channel distance
    calculateChannelDistance(context);
}
Also used : Context(android.content.Context) OverScroller(android.widget.OverScroller) Scroller(android.widget.Scroller) OverScroller(android.widget.OverScroller)

Example 34 with Scroller

use of android.widget.Scroller in project NewXmPluginSDK by MiEcosystem.

the class NumberPicker method computeScroll.

@Override
public void computeScroll() {
    Scroller scroller = mFlingScroller;
    if (scroller.isFinished()) {
        scroller = mAdjustScroller;
        if (scroller.isFinished()) {
            return;
        }
    }
    scroller.computeScrollOffset();
    int currentScrollerY = scroller.getCurrY();
    if (mPreviousScrollerY == 0) {
        mPreviousScrollerY = scroller.getStartY();
    }
    scrollBy(0, currentScrollerY - mPreviousScrollerY);
    mPreviousScrollerY = currentScrollerY;
    if (scroller.isFinished()) {
        onScrollerFinished(scroller);
    } else {
        invalidate();
    }
}
Also used : Scroller(android.widget.Scroller) Paint(android.graphics.Paint)

Example 35 with Scroller

use of android.widget.Scroller in project ABPlayer by winkstu.

the class XMultiColumnListView method initWithContext.

protected void initWithContext(Context context) {
    mScroller = new Scroller(context, new DecelerateInterpolator());
    // XListView need the scroll event, and it will dispatch the event to
    // user's listener (as a proxy).
    super.setOnScrollListener(this);
    // init header view
    mHeaderView = new XListViewHeader(context);
    mHeaderViewContent = (RelativeLayout) mHeaderView.findViewById(R.id.xlistview_header_content);
    mHeaderTimeView = (TextView) mHeaderView.findViewById(R.id.xlistview_header_time);
    addHeaderView(mHeaderView);
    // init footer view
    mFooterView = new XListViewFooter(context);
    // init header height
    mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            mHeaderViewHeight = mHeaderViewContent.getHeight();
            getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
    });
    // 默认关闭所有操作
    disablePullLoad();
    disablePullRefreash();
// setPullRefreshEnable(mEnablePullRefresh);
// setPullLoadEnable(mEnablePullLoad);
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) Scroller(android.widget.Scroller) XListViewHeader(me.maxwin.view.XListViewHeader) XListViewFooter(me.maxwin.view.XListViewFooter)

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