List of usage examples for android.support.v4.content LocalBroadcastManager registerReceiver
public void registerReceiver(BroadcastReceiver receiver, IntentFilter filter)
From source file:com.android.screenspeak.tutorial.TutorialModule.java
/** * Registers a broadcast receiver with the parent tutorial's * {@link LocalBroadcastManager} using the specified filter. * * @param receiver The broadcast receiver to register. * @param filter The filter for which {@code Intent} objects to receive. *//*w w w . j a v a 2 s . c o m*/ void registerReceiver(BroadcastReceiver receiver, IntentFilter filter) { final LocalBroadcastManager manager = LocalBroadcastManager.getInstance(mParentTutorial); if (manager == null) { return; } manager.registerReceiver(receiver, filter); }
From source file:com.facebook.AppEventsLoggerTests.java
public void testSimpleCall() throws InterruptedException { AppEventsLogger.setFlushBehavior(AppEventsLogger.FlushBehavior.EXPLICIT_ONLY); TestSession session1 = TestSession.createSessionWithSharedUser(getActivity(), null); TestSession session2 = TestSession.createSessionWithSharedUser(getActivity(), null, SECOND_TEST_USER_TAG); AppEventsLogger logger1 = AppEventsLogger.newLogger(getActivity(), session1); AppEventsLogger logger2 = AppEventsLogger.newLogger(getActivity(), session2); final WaitForBroadcastReceiver waitForBroadcastReceiver = new WaitForBroadcastReceiver(); waitForBroadcastReceiver.incrementExpectCount(); final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getActivity()); // Need to get notifications on another thread so we can wait for them. runOnBlockerThread(new Runnable() { @Override//from w w w . j av a2s .c o m public void run() { broadcastManager.registerReceiver(waitForBroadcastReceiver, new IntentFilter(AppEventsLogger.ACTION_APP_EVENTS_FLUSHED)); } }, true); logger1.logEvent("an_event"); logger2.logEvent("another_event"); logger1.flush(); waitForBroadcastReceiver.waitForExpectedCalls(); closeBlockerAndAssertSuccess(); broadcastManager.unregisterReceiver(waitForBroadcastReceiver); }
From source file:com.nadmm.airports.wx.PirepFragment.java
@Override public void onResume() { LocalBroadcastManager bm = LocalBroadcastManager.getInstance(getActivity()); bm.registerReceiver(mReceiver, mFilter); Bundle args = getArguments();//from w w w . j ava2 s . c o m String stationId = args.getString(NoaaService.STATION_ID); setBackgroundTask(new PirepDetailTask()).execute(stationId); super.onResume(); }
From source file:de.ribeiro.android.gso.activities.PlanActivity.java
@SuppressLint("NewApi") @Override//from w w w . j av a 2 s. co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ImageButton FAB; // Android Version prfen, wenn neuer als API11, Boolean actionBarAvailable = false; if (android.os.Build.VERSION.SDK_INT >= 11) { // ActionBar anfragen actionBarAvailable = getWindow().requestFeature(Window.FEATURE_ACTION_BAR); } _logger = new Logger(this, "PlanActivity"); setContentView(R.layout.activity_plan); this.ctxt = new MyContext(this, this); Configuration c = getResources().getConfiguration(); this.orientation = c.orientation; _logger.Info("Creating PlanActivity with orientation int: " + orientation); try { File f = new File(this.getCacheDir(), "date.bin"); if (f.exists() && f.canRead()) { ctxt.mProfil.stupid.currentDate = (Calendar) FileOPs.loadObject(f); f.delete(); } } catch (Exception e) { _logger.Error("An Error occurred while loading date.bin file", e); } ctxt.mProfil = new ProfilManager(ctxt).getCurrentProfil(); ctxt.mProfil.setPrefs(); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); lbm.registerReceiver(mMessageReceiver, new IntentFilter(Const.BROADCASTREFRESH)); Bundle extras = getIntent().getExtras(); if (extras != null) { int noticationId = extras.getInt("notificationId"); if (noticationId != 0) { extras.remove("notificationId"); //notication aus taskbar entfernen NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); nm.cancel(noticationId); Calendar date = new GregorianCalendar(); date.setTimeInMillis(extras.getLong("date")); extras.remove("weekIndex"); int profilIndex = extras.getInt("profilIndex"); extras.remove("profilIndex"); //alle Profile laden ProfilManager pm = new ProfilManager(ctxt); if (pm.profiles.size() >= pm.currentProfilIndex) { pm.profiles.get(pm.currentProfilIndex).setPrefs(); if (profilIndex > pm.profiles.size() - 1) profilIndex = 0; else pm.currentProfilIndex = profilIndex; pm.applyProfilIndex(); ctxt.mProfil.loadPrefs(); } ctxt.mProfil.stupid.currentDate = date; } ctxt.newVersionReqSetup = extras.getBoolean("newVersionInfo", false); } ActionBar actionBar = getActionBar(); if (ctxt.mIsRunning) actionBar.show(); ctxt.executor.post(new PlanActivityLuncher(PlanActivity.this)); // FAB = (ImageButton) findViewById(R.id.imageButton); // FAB.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // ctxt.getCurStupid().currentDate = new GregorianCalendar(); // ctxt.pager.setPage(ctxt.getCurStupid().currentDate); // } // }); }
From source file:com.example.evan.comp296.profile.MainActivity_Profile.java
@Override public void onStart() { super.onStart(); try {/*from ww w. jav a 2 s . c om*/ updateUI(mAuth.getCurrentUser()); } catch (IOException e) { e.printStackTrace(); } // Register receiver for uploads and downloads LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this); manager.registerReceiver(mBroadcastReceiver, MyDownloadService.getIntentFilter()); manager.registerReceiver(mBroadcastReceiver, MyUploadService.getIntentFilter()); }
From source file:com.linkbubble.ui.BubbleFlowActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { mDestroyed = false;// w w w.ja va2 s. com super.onCreate(savedInstanceState); Settings settings = Settings.get(); if (null != settings) { setTheme(settings.getDarkThemeEnabled() ? R.style.ThemeTransparentDark : R.style.ThemeTransparent); } Log.d("TAG", "!!!!! ON CREATE"); mContentViews = new ArrayList<>(); mPreClosedContentViews = new ArrayList<>(); setVisible(false); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_bubble_flow); IntentFilter filter = new IntentFilter(); filter.addAction(ACTIVITY_INTENT_NAME); LocalBroadcastManager bm = LocalBroadcastManager.getInstance(this); bm.registerReceiver(mBroadcastReceiver, filter); MainController controller = getMainController(); if (null != controller && null != controller.mBubbleFlowDraggable) { synchronized (MainApplication.mActivitySharedLock) { MainApplication.mActivitySharedLock.notify(); } if (MainApplication.mMoveWebViewsActivityToBack) { moveTaskToBack(true); } } else { moveTaskToBack(true); mDestroyed = true; finish(); startActivityForResult(new Intent(this, EntryActivity.class), 0); } int canvasMaskHeight = getResources().getDimensionPixelSize(R.dimen.canvas_mask_height); mTopMaskView = new ImageView(this); mTopMaskView.setImageResource(R.drawable.masked_background_half); mTopMaskView.setScaleType(ImageView.ScaleType.FIT_XY); FrameLayout.LayoutParams topMaskLP = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, canvasMaskHeight); topMaskLP.gravity = Gravity.TOP; mTopMaskView.setLayoutParams(topMaskLP); addContentView(mTopMaskView, topMaskLP); }
From source file:com.facebook.AppEventsLoggerTests.java
public void testPersistedEvents() throws IOException, ClassNotFoundException { AppEventsLogger.setFlushBehavior(AppEventsLogger.FlushBehavior.EXPLICIT_ONLY); final WaitForBroadcastReceiver waitForBroadcastReceiver = new WaitForBroadcastReceiver(); final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getActivity()); // Need to get notifications on another thread so we can wait for them. runOnBlockerThread(new Runnable() { @Override/*from w w w .j a va 2 s . c o m*/ public void run() { broadcastManager.registerReceiver(waitForBroadcastReceiver, new IntentFilter(AppEventsLogger.ACTION_APP_EVENTS_FLUSHED)); } }, true); getActivity().getFileStreamPath(AppEventsLogger.PersistedEvents.PERSISTED_EVENTS_FILENAME).delete(); TestSession session1 = TestSession.createSessionWithSharedUser(getActivity(), null); AppEventsLogger logger1 = AppEventsLogger.newLogger(getActivity(), session1); logger1.logEvent("an_event"); AppEventsLogger.onContextStop(); FileInputStream fis = getActivity() .openFileInput(AppEventsLogger.PersistedEvents.PERSISTED_EVENTS_FILENAME); assertNotNull(fis); ObjectInputStream ois = new ObjectInputStream(fis); Object obj = ois.readObject(); ois.close(); assertTrue(obj instanceof HashMap); logger1.flush(); logger1.logEvent("another_event"); waitForBroadcastReceiver.incrementExpectCount(); logger1.flush(); waitForBroadcastReceiver.waitForExpectedCalls(); List<Intent> receivedIntents = waitForBroadcastReceiver.getReceivedIntents(); assertEquals(1, receivedIntents.size()); Intent intent = receivedIntents.get(0); assertNotNull(intent); assertEquals(2, intent.getIntExtra(AppEventsLogger.APP_EVENTS_EXTRA_NUM_EVENTS_FLUSHED, 0)); broadcastManager.unregisterReceiver(waitForBroadcastReceiver); }
From source file:org.mozilla.gecko.home.HomeConfigPrefsBackend.java
private void registerReloadReceiver() { final LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(mContext); lbm.registerReceiver(mReloadBroadcastReceiver, new IntentFilter(RELOAD_BROADCAST)); }
From source file:com.physphil.android.restaurantroulette.RestaurantSelectorFragment.java
@Override public void onResume() { super.onResume(); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getActivity()); lbm.registerReceiver(mVisibleReceiver, new IntentFilter(HistoryListFragment.ACTION_HISTORY_CLEARED)); lbm.registerReceiver(mVisibleReceiver, new IntentFilter(LocationHelper.ACTION_LOCATION_RETRIEVED)); lbm.registerReceiver(mVisibleReceiver, new IntentFilter(NavigationDrawerFragment.ACTION_DRAWER_CLOSED)); }
From source file:com.coinblesk.client.wallet.Outputs.java
@Override public void onCreate(Bundle state) { super.onCreate(state); Intent walletServiceIntent = new Intent(getActivity(), WalletService.class); getActivity().bindService(walletServiceIntent, serviceConnection, Context.BIND_AUTO_CREATE); adapter = new OutputsAdapter(null, this); LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getActivity()); IntentFilter coinsSentOrReceivedFilter = new IntentFilter(); coinsSentOrReceivedFilter.addAction(Constants.WALLET_COINS_SENT_ACTION); coinsSentOrReceivedFilter.addAction(Constants.WALLET_COINS_RECEIVED_ACTION); broadcastManager.registerReceiver(onCoinsSentOrReceived, coinsSentOrReceivedFilter); }