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);
}
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);
}
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));
}
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]);
}
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);
}
Aggregations