Search in sources :

Example 6 with OnTickListener

use of com.tmall.wireless.tangram.support.TimerSupport.OnTickListener in project Tangram-Android by alibaba.

the class RxTimerSupportTest method testResume.

@Test
@SmallTest
@UiThreadTest
public void testResume() {
    assertEquals(mTimerSupport.getStatus(), TimerStatus.Waiting);
    mTimerSupport.register(1, new OnTickListener() {

        @Override
        public void onTick() {
            assertEquals(Looper.myLooper(), Looper.getMainLooper());
            assertEquals(mTimerSupport.getStatus(), TimerStatus.Running);
            Log.d("RxTimerSupportTest", "testResume");
        }
    });
    mTimerSupport.pause();
    mTimerSupport.restart();
}
Also used : OnTickListener(com.tmall.wireless.tangram.support.TimerSupport.OnTickListener) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 7 with OnTickListener

use of com.tmall.wireless.tangram.support.TimerSupport.OnTickListener in project Tangram-Android by alibaba.

the class RxTimerSupportTest method testTimerExecution.

@Test
@SmallTest
@UiThreadTest
public void testTimerExecution() {
    assertEquals(mTimerSupport.getStatus(), TimerStatus.Waiting);
    mTimerSupport.register(1, new OnTickListener() {

        long start = System.currentTimeMillis();

        @Override
        public void onTick() {
            assertEquals(Looper.myLooper(), Looper.getMainLooper());
            assertEquals(mTimerSupport.getStatus(), TimerStatus.Running);
            long end = System.currentTimeMillis();
            long time = (end - start);
            Log.d("RxTimerSupportTest", "testTimerExecution " + time);
            assertTrue(Math.abs(time - 1 * 1000) < 50);
            start = end;
        }
    });
}
Also used : OnTickListener(com.tmall.wireless.tangram.support.TimerSupport.OnTickListener) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 8 with OnTickListener

use of com.tmall.wireless.tangram.support.TimerSupport.OnTickListener in project Tangram-Android by alibaba.

the class RxTimerSupportTest method testPause.

@Test
@SmallTest
@UiThreadTest
public void testPause() {
    assertEquals(mTimerSupport.getStatus(), TimerStatus.Waiting);
    mTimerSupport.register(1, new OnTickListener() {

        long start = System.currentTimeMillis();

        @Override
        public void onTick() {
            // should not here
            assertTrue(false);
        }
    });
    mTimerSupport.pause();
}
Also used : OnTickListener(com.tmall.wireless.tangram.support.TimerSupport.OnTickListener) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 9 with OnTickListener

use of com.tmall.wireless.tangram.support.TimerSupport.OnTickListener in project Tangram-Android by alibaba.

the class RxTimer method stop.

@Override
public void stop() {
    for (Map.Entry<OnTickListener, Disposable> entry : tickCache.entrySet()) {
        Disposable disposable = entry.getValue();
        disposable.dispose();
    }
    tickCache.clear();
}
Also used : Disposable(io.reactivex.disposables.Disposable) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) OnTickListener(com.tmall.wireless.tangram.support.TimerSupport.OnTickListener)

Aggregations

OnTickListener (com.tmall.wireless.tangram.support.TimerSupport.OnTickListener)9 UiThreadTest (android.support.test.annotation.UiThreadTest)8 SmallTest (android.support.test.filters.SmallTest)8 Test (org.junit.Test)8 Disposable (io.reactivex.disposables.Disposable)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1