use of android.widget.Scroller in project EazeGraph by blackfizz.
the class BaseBarChart method initializeGraph.
/**
* This is the main entry point after the graph has been inflated. Used to initialize the graph
* and its corresponding members.
*/
@Override
protected void initializeGraph() {
super.initializeGraph();
mGraphPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mGraphPaint.setStyle(Paint.Style.FILL);
mLegendPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
mLegendPaint.setColor(mLegendColor);
mLegendPaint.setTextSize(mLegendTextSize);
mLegendPaint.setStrokeWidth(2);
mLegendPaint.setStyle(Paint.Style.FILL);
mMaxFontHeight = Utils.calculateMaxTextHeight(mLegendPaint, null);
mGestureDetector = new GestureDetector(getContext(), mGestureListener);
mScroller = new Scroller(getContext());
mRevealAnimator = ValueAnimator.ofFloat(0, 1);
mRevealAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mRevealValue = (animation.getAnimatedFraction());
mGraph.invalidate();
}
});
mRevealAnimator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
mStartedAnimation = false;
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
// The scroller doesn't have any built-in animation functions--it just supplies
// values when we ask it to. So we have to have a way to call it every frame
// until the fling ends. This code (ab)uses a ValueAnimator object to generate
// a callback on every animation frame. We don't use the animated value at all.
mScrollAnimator = ValueAnimator.ofFloat(0, 1);
mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator valueAnimator) {
tickScrollAnimation();
invalidateGlobal();
}
});
}
use of android.widget.Scroller in project horizontalpager by ysamlan.
the class HorizontalPager method init.
/**
* Sets up the scroller and touch/fling sensitivity parameters for the pager.
*/
private void init() {
mScroller = new Scroller(getContext());
// Calculate the density-dependent snap velocity in pixels
DisplayMetrics displayMetrics = new DisplayMetrics();
((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics);
mDensityAdjustedSnapVelocity = (int) (displayMetrics.density * SNAP_VELOCITY_DIP_PER_SECOND);
final ViewConfiguration configuration = ViewConfiguration.get(getContext());
mTouchSlop = configuration.getScaledTouchSlop();
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}
use of android.widget.Scroller in project XobotOS by xamarin.
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;
}
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;
}
use of android.widget.Scroller in project android_frameworks_base by AOSPA.
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;
}
Aggregations