Search in sources :

Example 21 with HandlerThread

use of android.os.HandlerThread in project chromeview by pwnall.

the class DeviceMotionAndOrientation method getHandler.

private Handler getHandler() {
    // use the same polling thread (also see crbug/234282).
    synchronized (mHandlerLock) {
        if (mHandler == null) {
            HandlerThread thread = new HandlerThread("DeviceMotionAndOrientation");
            thread.start();
            // blocks on thread start
            mHandler = new Handler(thread.getLooper());
        }
        return mHandler;
    }
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler)

Example 22 with HandlerThread

use of android.os.HandlerThread in project robolectric by robolectric.

the class ShadowContextWrapperTest method sendBroadcast_shouldSendIntentUsingHandlerIfOneIsProvided.

@Test
public void sendBroadcast_shouldSendIntentUsingHandlerIfOneIsProvided() {
    HandlerThread handlerThread = new HandlerThread("test");
    handlerThread.start();
    Handler handler = new Handler(handlerThread.getLooper());
    assertNotSame(handler.getLooper(), Looper.getMainLooper());
    BroadcastReceiver receiver = broadcastReceiver("Larry");
    contextWrapper.registerReceiver(receiver, intentFilter("foo", "baz"), null, handler);
    assertThat(shadowOf(handler.getLooper()).getScheduler().size()).isEqualTo(0);
    contextWrapper.sendBroadcast(new Intent("foo"));
    assertThat(shadowOf(handler.getLooper()).getScheduler().size()).isEqualTo(1);
    shadowOf(handlerThread.getLooper()).idle();
    assertThat(shadowOf(handler.getLooper()).getScheduler().size()).isEqualTo(0);
    assertThat(transcript).containsExactly("Larry notified of foo");
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) Test(org.junit.Test)

Example 23 with HandlerThread

use of android.os.HandlerThread in project reark by reark.

the class ContentProviderStoreCoreBase method createHandler.

@NonNull
public static Handler createHandler(@NonNull final String name) {
    checkNotNull(name);
    HandlerThread handlerThread = new HandlerThread(name);
    handlerThread.start();
    return new Handler(handlerThread.getLooper());
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler) ObjectLockHandler(io.reark.reark.utils.ObjectLockHandler) NonNull(android.support.annotation.NonNull)

Example 24 with HandlerThread

use of android.os.HandlerThread in project robolectric by robolectric.

the class ShadowLooperTest method schedulerOnAnotherLooper_shouldNotBeMaster_byDefault.

@Test
public void schedulerOnAnotherLooper_shouldNotBeMaster_byDefault() {
    HandlerThread ht = getHandlerThread();
    assertThat(shadowOf(ht.getLooper()).getScheduler()).isNotSameAs(RuntimeEnvironment.getMasterScheduler());
}
Also used : HandlerThread(android.os.HandlerThread) Test(org.junit.Test)

Example 25 with HandlerThread

use of android.os.HandlerThread in project robolectric by robolectric.

the class ShadowLooperTest method shouldSetNewScheduler_whenLooperIsReset.

@Test
public void shouldSetNewScheduler_whenLooperIsReset() {
    HandlerThread ht = getHandlerThread();
    Looper looper = ht.getLooper();
    ShadowLooper sLooper = shadowOf(looper);
    Scheduler old = sLooper.getScheduler();
    sLooper.reset();
    assertThat(old).isNotSameAs(sLooper.getScheduler());
}
Also used : Looper(android.os.Looper) HandlerThread(android.os.HandlerThread) Scheduler(org.robolectric.util.Scheduler) Test(org.junit.Test)

Aggregations

HandlerThread (android.os.HandlerThread)292 Handler (android.os.Handler)128 Message (android.os.Message)26 IntentFilter (android.content.IntentFilter)24 Intent (android.content.Intent)22 Context (android.content.Context)20 Test (org.junit.Test)20 PowerManager (android.os.PowerManager)15 Runnable (java.lang.Runnable)15 ComponentName (android.content.ComponentName)14 View (android.view.View)14 PendingIntent (android.app.PendingIntent)12 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 Looper (android.os.Looper)11 RemoteException (android.os.RemoteException)11 MediaFormat (android.media.MediaFormat)10 Pair (android.util.Pair)10 SmallTest (android.test.suitebuilder.annotation.SmallTest)9 Uri (android.net.Uri)8 IOException (java.io.IOException)8