Search in sources :

Example 51 with Scroller

use of android.widget.Scroller in project EazeGraph by blackfizz.

the class PieChart 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();
    Utils.setLayerToSW(this);
    mPieData = new ArrayList<PieModel>();
    mTotalValue = 0;
    mGraphPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mLegendPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mLegendPaint.setTextSize(mLegendTextSize);
    mLegendPaint.setColor(mLegendColor);
    mLegendPaint.setStyle(Paint.Style.FILL);
    mValuePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mValuePaint.setTextSize(mValueTextSize);
    mValuePaint.setColor(mValueTextColor);
    mValuePaint.setStyle(Paint.Style.FILL);
    mGraph.rotateTo(mPieRotation);
    mGraph.decelerate();
    mRevealAnimator = ValueAnimator.ofFloat(0, 1);
    mRevealAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mRevealValue = animation.getAnimatedFraction();
            invalidateGlobal();
        }
    });
    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) {
        }
    });
    if (mUsePieRotation) {
        // Set up an animator to animate the PieRotation property. This is used to
        // correct the pie's orientation after the user lets go of it.
        mAutoCenterAnimator = ObjectAnimator.ofInt(PieChart.this, "PieRotation", 0);
        // Add a listener to hook the onAnimationEnd event so that we can do
        // some cleanup when the pie stops moving.
        mAutoCenterAnimator.addListener(new Animator.AnimatorListener() {

            public void onAnimationStart(Animator animator) {
            }

            public void onAnimationEnd(Animator animator) {
                mGraph.decelerate();
            }

            public void onAnimationCancel(Animator animator) {
            }

            public void onAnimationRepeat(Animator animator) {
            }
        });
        // Create a Scroller to handle the fling gesture.
        if (Build.VERSION.SDK_INT < 11) {
            mScroller = new Scroller(getContext());
        } else {
            mScroller = new Scroller(getContext(), null, true);
        }
        // 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();
            }
        });
        // Create a gesture detector to handle onTouch messages
        mDetector = new GestureDetector(PieChart.this.getContext(), new GestureListener());
        // Turn off long press--this control doesn't use it, and if long press is enabled,
        // you can't scroll for a bit, pause, then scroll some more (the pause is interpreted
        // as a long press, apparently)
        mDetector.setIsLongpressEnabled(false);
    }
    if (this.isInEditMode()) {
        addPieSlice(new PieModel("Breakfast", 15, Color.parseColor("#FE6DA8")));
        addPieSlice(new PieModel("Lunch", 25, Color.parseColor("#56B7F1")));
        addPieSlice(new PieModel("Dinner", 35, Color.parseColor("#CDA67F")));
        addPieSlice(new PieModel("Snack", 25, Color.parseColor("#FED70E")));
    }
}
Also used : ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator) GestureDetector(android.view.GestureDetector) PieModel(org.eazegraph.lib.models.PieModel) Paint(android.graphics.Paint) Scroller(android.widget.Scroller) ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Example 52 with Scroller

use of android.widget.Scroller in project EazeGraph by blackfizz.

the class ValueLineChart 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();
    mDrawMatrix.setValues(mDrawMatrixValues);
    mGraphOverlay.decelerate();
    mSeries = new ArrayList<ValueLineSeries>();
    mLegendList = new ArrayList<LegendModel>();
    mLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mLinePaint.setStrokeWidth(mLineStroke);
    mLegendPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mLegendPaint.setColor(mLegendColor);
    mLegendPaint.setTextSize(mLegendTextSize);
    mLegendPaint.setStrokeWidth(2);
    mLegendPaint.setStyle(Paint.Style.FILL);
    mMaxFontHeight = Utils.calculateMaxTextHeight(mLegendPaint, null);
    mIndicatorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mIndicatorPaint.setColor(mIndicatorLineColor);
    mIndicatorPaint.setTextSize(mIndicatorTextSize);
    mIndicatorPaint.setStrokeWidth(mIndicatorWidth);
    mIndicatorPaint.setStyle(Paint.Style.FILL);
    mScaleGestureDetector = new ScaleGestureDetector(getContext(), mScaleGestureListener);
    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();
            mDrawMatrix.reset();
            mDrawMatrix.setScale(1, 1.f * mRevealValue, 0, mGraphHeight - mNegativeOffset);
            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();
        }
    });
    if (this.isInEditMode()) {
        ValueLineSeries series1 = new ValueLineSeries();
        series1.setColor(0xFF63CBB0);
        series1.addPoint(new ValueLinePoint(1.4f));
        series1.addPoint(new ValueLinePoint(4.4f));
        series1.addPoint(new ValueLinePoint(2.4f));
        series1.addPoint(new ValueLinePoint(3.2f));
        series1.addPoint(new ValueLinePoint(2.6f));
        series1.addPoint(new ValueLinePoint(5.0f));
        series1.addPoint(new ValueLinePoint(3.5f));
        series1.addPoint(new ValueLinePoint(2.4f));
        series1.addPoint(new ValueLinePoint(0.4f));
        series1.addPoint(new ValueLinePoint(3.4f));
        series1.addPoint(new ValueLinePoint(2.5f));
        series1.addPoint(new ValueLinePoint(1.0f));
        series1.addPoint(new ValueLinePoint(4.2f));
        series1.addPoint(new ValueLinePoint(2.4f));
        series1.addPoint(new ValueLinePoint(3.6f));
        series1.addPoint(new ValueLinePoint(1.0f));
        series1.addPoint(new ValueLinePoint(2.5f));
        series1.addPoint(new ValueLinePoint(1.4f));
        addSeries(series1);
    }
}
Also used : GestureDetector(android.view.GestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector) Paint(android.graphics.Paint) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) ValueLinePoint(org.eazegraph.lib.models.ValueLinePoint) ValueLineSeries(org.eazegraph.lib.models.ValueLineSeries) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) ScaleGestureDetector(android.view.ScaleGestureDetector) Scroller(android.widget.Scroller) LegendModel(org.eazegraph.lib.models.LegendModel)

Example 53 with Scroller

use of android.widget.Scroller in project Android-Terminal-Emulator by jackpal.

the class EmulatorView method commonConstructor.

private void commonConstructor(Context context) {
    // TODO: See if we want to use the API level 11 constructor to get new flywheel feature.
    mScroller = new Scroller(context);
    mMouseTrackingFlingRunner.mScroller = new Scroller(context);
}
Also used : Scroller(android.widget.Scroller)

Example 54 with Scroller

use of android.widget.Scroller in project FlipViewPager.Draco by Yalantis.

the class FlipViewPager method init.

private void init() {
    ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mScroller = new Scroller(getContext(), new LinearInterpolator());
    mTouchSlop = configuration.getScaledPagingTouchSlop();
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdgeEffect = new EdgeEffect(getContext());
    mRightEdgeEffect = new EdgeEffect(getContext());
    mShadePaint.setColor(Color.BLACK);
    mShinePaint.setColor(Color.WHITE);
}
Also used : ViewConfiguration(android.view.ViewConfiguration) LinearInterpolator(android.view.animation.LinearInterpolator) Scroller(android.widget.Scroller) EdgeEffect(android.widget.EdgeEffect)

Example 55 with Scroller

use of android.widget.Scroller in project lottie-android by airbnb.

the class AppIntroActivity method setViewPagerScroller.

private void setViewPagerScroller() {
    //noinspection TryWithIdenticalCatches
    try {
        Field scrollerField = ViewPager.class.getDeclaredField("mScroller");
        scrollerField.setAccessible(true);
        Field interpolator = ViewPager.class.getDeclaredField("sInterpolator");
        interpolator.setAccessible(true);
        Scroller scroller = new Scroller(this, (Interpolator) interpolator.get(null)) {

            @Override
            public void startScroll(int startX, int startY, int dx, int dy, int duration) {
                super.startScroll(startX, startY, dx, dy, duration * 7);
            }
        };
        scrollerField.set(viewPager, scroller);
    } catch (NoSuchFieldException e) {
    // Do nothing.
    } catch (IllegalAccessException e) {
    // Do nothing.
    }
}
Also used : Field(java.lang.reflect.Field) 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