Search in sources :

Example 1 with LocalBroadcastManager

use of android.support.v4.content.LocalBroadcastManager in project phonegap-facebook-plugin by Wizcorp.

the class LikeActionController method registerSessionBroadcastReceivers.

//
// In-memory mru-caching code
//
private static void registerSessionBroadcastReceivers(Context context) {
    LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(context);
    IntentFilter filter = new IntentFilter();
    filter.addAction(Session.ACTION_ACTIVE_SESSION_UNSET);
    filter.addAction(Session.ACTION_ACTIVE_SESSION_CLOSED);
    filter.addAction(Session.ACTION_ACTIVE_SESSION_OPENED);
    broadcastManager.registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context receiverContext, Intent intent) {
            if (isPendingBroadcastReset) {
                return;
            }
            String action = intent.getAction();
            final boolean shouldClearDisk = Utility.areObjectsEqual(Session.ACTION_ACTIVE_SESSION_UNSET, action) || Utility.areObjectsEqual(Session.ACTION_ACTIVE_SESSION_CLOSED, action);
            isPendingBroadcastReset = true;
            // Delaying sending the broadcast to reset, because we might get many successive calls from Session
            // (to UNSET, SET & OPEN) and a delay would prevent excessive chatter.
            final Context broadcastContext = receiverContext;
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    // incrementing the objectSuffix and clearing the caches here.
                    if (shouldClearDisk) {
                        objectSuffix = (objectSuffix + 1) % MAX_OBJECT_SUFFIX;
                        broadcastContext.getSharedPreferences(LIKE_ACTION_CONTROLLER_STORE, Context.MODE_PRIVATE).edit().putInt(LIKE_ACTION_CONTROLLER_STORE_OBJECT_SUFFIX_KEY, objectSuffix).apply();
                        // Only clearing the actual caches. The MRU index will self-clean with usage.
                        // Clearing the caches is necessary to prevent leaking like-state across sessions.
                        cache.clear();
                        controllerDiskCache.clearCache();
                    }
                    broadcastAction(broadcastContext, null, ACTION_LIKE_ACTION_CONTROLLER_DID_RESET);
                    isPendingBroadcastReset = false;
                }
            }, 100);
        }
    }, filter);
}
Also used : LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager)

Example 2 with LocalBroadcastManager

use of android.support.v4.content.LocalBroadcastManager in project phonegap-facebook-plugin by Wizcorp.

the class LikeView method associateWithLikeActionController.

private void associateWithLikeActionController(LikeActionController likeActionController) {
    this.likeActionController = likeActionController;
    this.broadcastReceiver = new LikeControllerBroadcastReceiver();
    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(getContext());
    // add the broadcast receiver
    IntentFilter filter = new IntentFilter();
    filter.addAction(LikeActionController.ACTION_LIKE_ACTION_CONTROLLER_UPDATED);
    filter.addAction(LikeActionController.ACTION_LIKE_ACTION_CONTROLLER_DID_ERROR);
    filter.addAction(LikeActionController.ACTION_LIKE_ACTION_CONTROLLER_DID_RESET);
    localBroadcastManager.registerReceiver(broadcastReceiver, filter);
}
Also used : IntentFilter(android.content.IntentFilter) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager)

Example 3 with LocalBroadcastManager

use of android.support.v4.content.LocalBroadcastManager in project robolectric by robolectric.

the class ShadowLocalBroadcastManagerTest method shouldGetInstance.

@Test
public void shouldGetInstance() throws Exception {
    LocalBroadcastManager instance = LocalBroadcastManager.getInstance(RuntimeEnvironment.application);
    assertNotNull(instance);
    assertSame(instance, LocalBroadcastManager.getInstance(RuntimeEnvironment.application));
}
Also used : LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Test(org.junit.Test)

Example 4 with LocalBroadcastManager

use of android.support.v4.content.LocalBroadcastManager in project robolectric by robolectric.

the class ShadowLocalBroadcastManagerTest method shouldSendBroadcasts.

@Test
public void shouldSendBroadcasts() throws Exception {
    LocalBroadcastManager instance = LocalBroadcastManager.getInstance(RuntimeEnvironment.application);
    final boolean[] called = new boolean[1];
    final BroadcastReceiver receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            called[0] = true;
        }
    };
    instance.registerReceiver(receiver, new IntentFilter("com.foo"));
    instance.sendBroadcast(new Intent("com.bar"));
    assertFalse(called[0]);
    instance.sendBroadcast(new Intent("com.foo"));
    assertTrue(called[0]);
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Test(org.junit.Test)

Example 5 with LocalBroadcastManager

use of android.support.v4.content.LocalBroadcastManager in project facebook-api-android-maven by avianey.

the class BoltsMeasurementEventListener method close.

private void close() {
    LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(applicationContext);
    broadcastManager.unregisterReceiver(this);
}
Also used : LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager)

Aggregations

LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)36 IntentFilter (android.content.IntentFilter)15 Intent (android.content.Intent)11 Test (org.junit.Test)10 Context (android.content.Context)9 BroadcastReceiver (android.content.BroadcastReceiver)7 Bundle (android.os.Bundle)3 AccessToken (com.facebook.AccessToken)2 WaitForBroadcastReceiver (com.facebook.WaitForBroadcastReceiver)2 AppEventsLogger (com.facebook.appevents.AppEventsLogger)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Uri (android.net.Uri)1 Parcel (android.os.Parcel)1 Parcelable (android.os.Parcelable)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 RecipeList (com.se491.chef_ly.model.RecipeList)1 IOException (java.io.IOException)1 Type (java.lang.reflect.Type)1