Example usage for android.widget OverScroller OverScroller

List of usage examples for android.widget OverScroller OverScroller

Introduction

In this page you can find the example usage for android.widget OverScroller OverScroller.

Prototype

public OverScroller(Context context) 

Source Link

Document

Creates an OverScroller with a viscous fluid scroll interpolator and flywheel.

Usage

From source file:com.iangclifton.auid.horizontaliconview.HorizontalIconView.java

/**
 * Perform one-time initialization//from  ww  w  . j a v  a  2  s . co  m
 * 
 * @param context Context to load Resources and ViewConfiguration data
 */
private void init(Context context) {
    final Resources res = context.getResources();
    mIconSize = res.getDimensionPixelSize(R.dimen.icon_size);
    mIconSpacing = res.getDimensionPixelSize(R.dimen.icon_spacing);

    // Cache ViewConfiguration values
    final ViewConfiguration config = ViewConfiguration.get(context);
    mTouchSlop = config.getScaledTouchSlop();
    mMinimumVelocity = config.getScaledMinimumFlingVelocity();
    mMaximumVelocity = config.getScaledMaximumFlingVelocity();
    mOverflingDistance = config.getScaledOverflingDistance();
    mOverscrollDistance = config.getScaledOverscrollDistance();

    // Verify this View will be drawn
    setWillNotDraw(false);

    // Other setup
    mEdgeEffectLeft = new EdgeEffectCompat(context);
    mEdgeEffectRight = new EdgeEffectCompat(context);
    mScroller = new OverScroller(context);
    setFocusable(true);
}

From source file:com.facebook.react.views.scroll.ReactScrollView.java

private int predictFinalScrollPosition(int velocityY) {
    // ScrollView can *only* scroll for 250ms when using smoothScrollTo and there's
    // no way to customize the scroll duration. So, we create a temporary OverScroller
    // so we can predict where a fling would land and snap to nearby that point.
    OverScroller scroller = new OverScroller(getContext());
    scroller.setFriction(1.0f - mDecelerationRate);

    // predict where a fling would end up so we can scroll to the nearest snap offset
    int maximumOffset = getMaxScrollY();
    int height = getHeight() - getPaddingBottom() - getPaddingTop();
    scroller.fling(getScrollX(), // startX
            getScrollY(), // startY
            0, // velocityX
            velocityY, // velocityY
            0, // minX
            0, // maxX
            0, // minY
            maximumOffset, // maxY
            0, // overX
            height / 2 // overY
    );/*from w w w.j  a  v a  2 s  .  c o  m*/
    return scroller.getFinalY();
}

From source file:com.facebook.react.views.scroll.ReactHorizontalScrollView.java

private int predictFinalScrollPosition(int velocityX) {
    // ScrollView can *only* scroll for 250ms when using smoothScrollTo and there's
    // no way to customize the scroll duration. So, we create a temporary OverScroller
    // so we can predict where a fling would land and snap to nearby that point.
    OverScroller scroller = new OverScroller(getContext());
    scroller.setFriction(1.0f - mDecelerationRate);

    // predict where a fling would end up so we can scroll to the nearest snap offset
    int maximumOffset = Math.max(0, computeHorizontalScrollRange() - getWidth());
    int width = getWidth() - getPaddingStart() - getPaddingEnd();
    scroller.fling(getScrollX(), // startX
            getScrollY(), // startY
            velocityX, // velocityX
            0, // velocityY
            0, // minX
            maximumOffset, // maxX
            0, // minY
            0, // maxY
            width / 2, // overX
            0 // overY
    );//from  w w  w . j a  v a 2  s.  co  m
    return scroller.getFinalX();
}

From source file:com.jjoe64.graphview.Viewport.java

/**
 * creates the viewport/*w w w. j a v a  2s.  c  om*/
 *
 * @param graphView graphview
 */
Viewport(GraphView graphView) {
    mScroller = new OverScroller(graphView.getContext());
    mEdgeEffectTop = new EdgeEffectCompat(graphView.getContext());
    mEdgeEffectBottom = new EdgeEffectCompat(graphView.getContext());
    mEdgeEffectLeft = new EdgeEffectCompat(graphView.getContext());
    mEdgeEffectRight = new EdgeEffectCompat(graphView.getContext());
    mGestureDetector = new GestureDetector(graphView.getContext(), mGestureListener);
    mScaleGestureDetector = new ScaleGestureDetector(graphView.getContext(), mScaleGestureListener);

    mGraphView = graphView;
    mXAxisBoundsStatus = AxisBoundsStatus.INITIAL;
    mYAxisBoundsStatus = AxisBoundsStatus.INITIAL;
    mBackgroundColor = Color.TRANSPARENT;
    mPaint = new Paint();
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

public DayView(Context context, CalendarController controller, ViewSwitcher viewSwitcher,
        EventLoader eventLoader, int numDays) {
    super(context);
    mContext = context;/*w  w w . java  2 s .  c o  m*/

    mResources = context.getResources();
    mNumDays = numDays;

    DATE_HEADER_FONT_SIZE = (int) mResources.getDimension(R.dimen.date_header_text_size);
    DAY_HEADER_FONT_SIZE = (int) mResources.getDimension(R.dimen.day_label_text_size);
    DAY_HEADER_HEIGHT = (int) mResources.getDimension(R.dimen.day_header_height);
    DAY_HEADER_BOTTOM_MARGIN = (int) mResources.getDimension(R.dimen.day_header_bottom_margin);
    HOURS_TEXT_SIZE = (int) mResources.getDimension(R.dimen.hours_text_size);
    AMPM_TEXT_SIZE = (int) mResources.getDimension(R.dimen.ampm_text_size);
    MIN_HOURS_WIDTH = (int) mResources.getDimension(R.dimen.min_hours_width);
    HOURS_LEFT_MARGIN = (int) mResources.getDimension(R.dimen.hours_left_margin);
    HOURS_RIGHT_MARGIN = (int) mResources.getDimension(R.dimen.hours_right_margin);
    int eventTextSizeId;
    if (mNumDays == 1) {
        eventTextSizeId = R.dimen.day_view_event_text_size;
    } else {
        eventTextSizeId = R.dimen.week_view_event_text_size;
    }
    EVENT_TEXT_FONT_SIZE = (int) mResources.getDimension(eventTextSizeId);
    MIN_EVENT_HEIGHT = mResources.getDimension(R.dimen.event_min_height);
    EVENT_TEXT_TOP_MARGIN = (int) mResources.getDimension(R.dimen.event_text_vertical_margin);
    EVENT_TEXT_BOTTOM_MARGIN = EVENT_TEXT_TOP_MARGIN;

    EVENT_TEXT_LEFT_MARGIN = (int) mResources.getDimension(R.dimen.event_text_horizontal_margin);
    EVENT_TEXT_RIGHT_MARGIN = EVENT_TEXT_LEFT_MARGIN;

    if (mScale == 0) {

        mScale = mResources.getDisplayMetrics().density;
        if (mScale != 1) {

            GRID_LINE_LEFT_MARGIN *= mScale;
            HOURS_TOP_MARGIN *= mScale;
            MIN_CELL_WIDTH_FOR_TEXT *= mScale;

            CURRENT_TIME_LINE_SIDE_BUFFER *= mScale;
            CURRENT_TIME_LINE_TOP_OFFSET *= mScale;

            MIN_Y_SPAN *= mScale;
            MAX_CELL_HEIGHT *= mScale;
            DEFAULT_CELL_HEIGHT *= mScale;
            DAY_HEADER_RIGHT_MARGIN *= mScale;
            DAY_HEADER_ONE_DAY_LEFT_MARGIN *= mScale;
            DAY_HEADER_ONE_DAY_RIGHT_MARGIN *= mScale;
            DAY_HEADER_ONE_DAY_BOTTOM_MARGIN *= mScale;
            EVENT_RECT_TOP_MARGIN *= mScale;
            EVENT_RECT_BOTTOM_MARGIN *= mScale;
            EVENT_RECT_LEFT_MARGIN *= mScale;
            EVENT_RECT_RIGHT_MARGIN *= mScale;
            EVENT_RECT_STROKE_WIDTH *= mScale;
        }
    }
    HOURS_MARGIN = HOURS_LEFT_MARGIN + HOURS_RIGHT_MARGIN;

    mCurrentTimeLine = mResources.getDrawable(R.drawable.timeline_indicator_holo_light);
    mCurrentTimeAnimateLine = mResources.getDrawable(R.drawable.timeline_indicator_activated_holo_light);
    mTodayHeaderDrawable = mResources.getDrawable(R.drawable.today_blue_week_holo_light);
    mAcceptedOrTentativeEventBoxDrawable = mResources.getDrawable(R.drawable.panel_month_event_holo_light);

    mEventLoader = eventLoader;
    mEventGeometry = new EventGeometry();
    mEventGeometry.setMinEventHeight(MIN_EVENT_HEIGHT);
    mEventGeometry.setHourGap(HOUR_GAP);
    mEventGeometry.setCellMargin(DAY_GAP);
    mController = controller;
    mViewSwitcher = viewSwitcher;
    mGestureDetector = new GestureDetector(context, new CalendarGestureListener());
    mScaleGestureDetector = new ScaleGestureDetector(getContext(), this);
    if (mCellHeight == 0) {
        mCellHeight = DEFAULT_CELL_HEIGHT;
    }
    mScroller = new OverScroller(context);
    mHScrollInterpolator = new ScrollInterpolator();
    mEdgeEffectTop = new EdgeEffectCompat(context);
    mEdgeEffectBottom = new EdgeEffectCompat(context);
    ViewConfiguration vc = ViewConfiguration.get(context);
    mScaledPagingTouchSlop = vc.getScaledPagingTouchSlop();
    mOnDownDelay = ViewConfiguration.getTapTimeout();
    OVERFLING_DISTANCE = vc.getScaledOverflingDistance();

    init(context);
}

From source file:com.ruesga.timelinechart.TimelineChartView.java

private void init(Context ctx, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mUiHandler = new Handler(Looper.getMainLooper(), mMessenger);
    if (!isInEditMode()) {
        mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
    }/*from  ww  w . j a  va  2 s. c  o  m*/

    final Resources res = getResources();
    final Resources.Theme theme = ctx.getTheme();

    mTickFormats = getResources().getStringArray(R.array.tlcDefTickLabelFormats);
    mTickLabels = getResources().getStringArray(R.array.tlcDefTickLabelValues);

    final DisplayMetrics dp = getResources().getDisplayMetrics();
    mSize8 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 8, dp);
    mSize12 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, dp);
    mSize20 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 20, dp);

    final ViewConfiguration vc = ViewConfiguration.get(ctx);
    mLongPressTimeout = ViewConfiguration.getLongPressTimeout();
    mTouchSlop = vc.getScaledTouchSlop() / 2;
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mScroller = new OverScroller(ctx);

    int graphBgColor = ContextCompat.getColor(ctx, R.color.tlcDefGraphBackgroundColor);
    int footerBgColor = ContextCompat.getColor(ctx, R.color.tlcDefFooterBackgroundColor);

    mDefFooterBarHeight = mFooterBarHeight = res.getDimension(R.dimen.tlcDefFooterBarHeight);
    mShowFooter = res.getBoolean(R.bool.tlcDefShowFooter);
    mGraphMode = res.getInteger(R.integer.tlcDefGraphMode);
    mPlaySelectionSoundEffect = res.getBoolean(R.bool.tlcDefPlaySelectionSoundEffect);
    mSelectionSoundEffectSource = res.getInteger(R.integer.tlcDefSelectionSoundEffectSource);
    mAnimateCursorTransition = res.getBoolean(R.bool.tlcDefAnimateCursorTransition);
    mFollowCursorPosition = res.getBoolean(R.bool.tlcDefFollowCursorPosition);
    mAlwaysEnsureSelection = res.getBoolean(R.bool.tlcDefAlwaysEnsureSelection);

    mGraphAreaBgPaint = new Paint();
    mGraphAreaBgPaint.setColor(graphBgColor);
    mFooterAreaBgPaint = new Paint();
    mFooterAreaBgPaint.setColor(footerBgColor);
    mTickLabelFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    mTickLabelFgPaint.setFakeBoldText(true);
    mTickLabelFgPaint.setColor(MaterialPaletteHelper.isDarkColor(footerBgColor) ? Color.LTGRAY : Color.DKGRAY);

    mBarItemWidth = res.getDimension(R.dimen.tlcDefBarItemWidth);
    mBarItemSpace = res.getDimension(R.dimen.tlcDefBarItemSpace);

    TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.tlcTimelineChartView, defStyleAttr,
            defStyleRes);
    try {
        int n = a.getIndexCount();
        for (int i = 0; i < n; i++) {
            int attr = a.getIndex(i);
            if (attr == R.styleable.tlcTimelineChartView_tlcGraphBackground) {
                graphBgColor = a.getColor(attr, graphBgColor);
                mGraphAreaBgPaint.setColor(graphBgColor);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcShowFooter) {
                mShowFooter = a.getBoolean(attr, mShowFooter);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcFooterBackground) {
                footerBgColor = a.getColor(attr, footerBgColor);
                mFooterAreaBgPaint.setColor(footerBgColor);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcFooterBarHeight) {
                mFooterBarHeight = a.getDimension(attr, mFooterBarHeight);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcGraphMode) {
                mGraphMode = a.getInt(attr, mGraphMode);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcAnimateCursorTransition) {
                mAnimateCursorTransition = a.getBoolean(attr, mAnimateCursorTransition);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcFollowCursorPosition) {
                mFollowCursorPosition = a.getBoolean(attr, mFollowCursorPosition);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcAlwaysEnsureSelection) {
                mAlwaysEnsureSelection = a.getBoolean(attr, mAlwaysEnsureSelection);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcBarItemWidth) {
                mBarItemWidth = a.getDimension(attr, mBarItemWidth);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcBarItemSpace) {
                mBarItemSpace = a.getDimension(attr, mBarItemSpace);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcPlaySelectionSoundEffect) {
                mPlaySelectionSoundEffect = a.getBoolean(attr, mPlaySelectionSoundEffect);
            } else if (attr == R.styleable.tlcTimelineChartView_tlcSelectionSoundEffectSource) {
                mSelectionSoundEffectSource = a.getInt(attr, mSelectionSoundEffectSource);
            }
        }
    } finally {
        a.recycle();
    }

    // SurfaceView requires a background
    if (getBackground() == null) {
        setBackgroundColor(ContextCompat.getColor(ctx, android.R.color.transparent));
    }

    // Minimize the impact of create dynamic layouts by assume that in most case
    // we will have a day formatter
    mTickHasDayFormat = true;

    // Initialize stuff
    setupBackgroundHandler();
    setupTickLabels();
    if (ViewCompat.getOverScrollMode(this) != ViewCompat.OVER_SCROLL_NEVER) {
        setupEdgeEffects();
    }
    setupAnimators();
    setupSoundEffects();

    // Initialize the drawing refs (this will be update when we have
    // the real size of the canvas)
    computeBoundAreas();

    // Create a fake data for the edit mode
    if (isInEditMode()) {
        setupViewInEditMode();
    }
}