Search in sources :

Example 31 with VelocityTracker

use of android.view.VelocityTracker in project android_frameworks_base by ParanoidAndroid.

the class VelocityTest method testDragDeceleration.

@MediumTest
public void testDragDeceleration() {
    long t = System.currentTimeMillis();
    VelocityTracker vt = VelocityTracker.obtain();
    drag(vt, 100, 200, 100, 200, 15, t, 400, new DecelerateInterpolator());
    vt.computeCurrentVelocity(1000);
    assertLower(250.0f, vt.getXVelocity());
    assertLower(250.0f, vt.getYVelocity());
    vt.recycle();
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) VelocityTracker(android.view.VelocityTracker) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 32 with VelocityTracker

use of android.view.VelocityTracker in project android_frameworks_base by ParanoidAndroid.

the class VelocityTest method testStabilityInNbPoints.

/**
     * Velocity is independent of the number of points used during
     * the same interval
     */
@MediumTest
public void testStabilityInNbPoints() {
    long t = System.currentTimeMillis();
    VelocityTracker vt = VelocityTracker.obtain();
    // 10 steps over 400ms
    drag(vt, 100, 200, 100, 200, 10, t, 400);
    vt.computeCurrentVelocity(1);
    float firstX = vt.getXVelocity();
    float firstY = vt.getYVelocity();
    vt.clear();
    // 20 steps over 400ms
    drag(vt, 100, 200, 100, 200, 20, t, 400);
    vt.computeCurrentVelocity(1);
    float secondX = vt.getXVelocity();
    float secondY = vt.getYVelocity();
    assertEqualFuzzy(firstX, secondX, 0.1f);
    assertEqualFuzzy(firstY, secondY, 0.1f);
    vt.recycle();
}
Also used : VelocityTracker(android.view.VelocityTracker) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 33 with VelocityTracker

use of android.view.VelocityTracker in project android_frameworks_base by ParanoidAndroid.

the class VelocityTest method testClear.

/**
     * Test that {@link android.view.VelocityTracker}.clear() clears
     * the previous values after a call to computeCurrentVelocity()
     */
@MediumTest
public void testClear() {
    long t = System.currentTimeMillis();
    VelocityTracker vt = VelocityTracker.obtain();
    drag(vt, 100, 200, 100, 200, 10, t, 300);
    vt.computeCurrentVelocity(1);
    assertFalse("Velocity should not be null", vt.getXVelocity() == 0.0f);
    assertFalse("Velocity should not be null", vt.getYVelocity() == 0.0f);
    vt.clear();
    vt.computeCurrentVelocity(1);
    assertEquals(0.0f, vt.getXVelocity());
    assertEquals(0.0f, vt.getYVelocity());
    vt.recycle();
}
Also used : VelocityTracker(android.view.VelocityTracker) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 34 with VelocityTracker

use of android.view.VelocityTracker in project android_frameworks_base by ParanoidAndroid.

the class VelocityTest method testStabilityInSpace.

/**
     * Velocity is independent of the position of the events,
     * it only depends on their relative distance.
     */
@MediumTest
public void testStabilityInSpace() {
    long t = System.currentTimeMillis();
    VelocityTracker vt = VelocityTracker.obtain();
    drag(vt, 100, 200, 100, 200, 10, t, 400);
    vt.computeCurrentVelocity(1);
    float firstX = vt.getXVelocity();
    float firstY = vt.getYVelocity();
    vt.clear();
    // 100px further
    drag(vt, 200, 300, 200, 300, 10, t, 400);
    vt.computeCurrentVelocity(1);
    float secondX = vt.getXVelocity();
    float secondY = vt.getYVelocity();
    assertEqualFuzzy(firstX, secondX, 0.1f);
    assertEqualFuzzy(firstY, secondY, 0.1f);
    vt.recycle();
}
Also used : VelocityTracker(android.view.VelocityTracker) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 35 with VelocityTracker

use of android.view.VelocityTracker in project android_frameworks_base by ParanoidAndroid.

the class VelocityTest method testStabilityOfComputation.

/**
     * Test that calls to {@link android.view.VelocityTracker}.computeCurrentVelocity()
     * will output same values when using the same data.
     */
@MediumTest
public void testStabilityOfComputation() {
    long t = System.currentTimeMillis();
    VelocityTracker vt = VelocityTracker.obtain();
    drag(vt, 100, 200, 100, 200, 10, t, 300);
    vt.computeCurrentVelocity(1);
    float firstX = vt.getXVelocity();
    float firstY = vt.getYVelocity();
    vt.computeCurrentVelocity(1);
    float secondX = vt.getXVelocity();
    float secondY = vt.getYVelocity();
    assertEquals(firstX, secondX);
    assertEquals(firstY, secondY);
    vt.recycle();
}
Also used : VelocityTracker(android.view.VelocityTracker) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

VelocityTracker (android.view.VelocityTracker)125 ViewParent (android.view.ViewParent)32 Paint (android.graphics.Paint)23 View (android.view.View)14 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 Drawable (android.graphics.drawable.Drawable)10 TransitionDrawable (android.graphics.drawable.TransitionDrawable)10 MotionEvent (android.view.MotionEvent)9 Handler (android.os.Handler)3 AnimatorSet (android.animation.AnimatorSet)2 SuppressLint (android.annotation.SuppressLint)2 PointF (android.graphics.PointF)2 Rect (android.graphics.Rect)1 ViewPager (android.support.v4.view.ViewPager)1 TextPaint (android.text.TextPaint)1 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)1 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)1 ListView (android.widget.ListView)1 OnClickHandler (android.widget.RemoteViews.OnClickHandler)1 Field (java.lang.reflect.Field)1