use of android.widget.Scroller in project simplefacebook by androidquery.
the class PagedView method initPagedView.
private void initPagedView() {
final Context context = getContext();
mScroller = new Scroller(context, new DecelerateInterpolator());
final ViewConfiguration conf = ViewConfiguration.get(context);
// getScaledPagingTouchSlop() only available in API Level 8
mPagingTouchSlop = conf.getScaledTouchSlop() * 2;
mMaximumVelocity = conf.getScaledMaximumFlingVelocity();
final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
mMinimumVelocity = (int) (metrics.density * MINIMUM_PAGE_CHANGE_VELOCITY + 0.5f);
WebView wv = new WebView(context);
initScale = wv.getScale();
AQUtility.debug("seed scale", initScale);
}
use of android.widget.Scroller in project platform_packages_apps_launcher by android.
the class Workspace method initWorkspace.
/**
* Initializes various states for this workspace.
*/
private void initWorkspace() {
mScroller = new Scroller(getContext());
mCurrentScreen = mDefaultScreen;
Launcher.setScreen(mCurrentScreen);
mPaint = new Paint();
mPaint.setDither(false);
final ViewConfiguration configuration = ViewConfiguration.get(getContext());
mTouchSlop = configuration.getScaledTouchSlop();
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}
use of android.widget.Scroller in project platform_frameworks_base by android.
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;
}
use of android.widget.Scroller in project TransitionPlayer by linfaxin.
the class XiaoMaIntroDemo method initSmoothScrollToViewPager.
private void initSmoothScrollToViewPager(ViewPager viewPager) {
try {
Interpolator sInterpolator = new Interpolator() {
public float getInterpolation(float t) {
t -= 1.0f;
return t * t * t * t * t + 1.0f;
}
};
Field field = ViewPager.class.getDeclaredField("mScroller");
field.setAccessible(true);
field.set(viewPager, new Scroller(this, sInterpolator) {
@Override
public void startScroll(int startX, int startY, int dx, int dy, int duration) {
super.startScroll(startX, startY, dx, dy, duration * 2);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
use of android.widget.Scroller in project AndroidTreeView by bmelnychuk.
the class TwoDScrollView method initTwoDScrollView.
private void initTwoDScrollView() {
mScroller = new Scroller(getContext());
setFocusable(true);
setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
setWillNotDraw(false);
final ViewConfiguration configuration = ViewConfiguration.get(getContext());
mTouchSlop = configuration.getScaledTouchSlop();
mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}
Aggregations