android.support.v4.content.LocalBroadcastManager Java Examples
The following examples show how to use
android.support.v4.content.LocalBroadcastManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MentionsCommentTimeLineFragment.java From iBeebo with GNU General Public License v3.0 | 6 votes |
@Override public void onResume() { super.onResume(); setListViewPositionFromPositionsCache(); LocalBroadcastManager.getInstance(getActivity()).registerReceiver(newBroadcastReceiver, new IntentFilter(AppEventAction.NEW_MSG_BROADCAST)); // setActionBarTabCount(newMsgTipBar.getValues().size()); getNewMsgTipBar().setOnChangeListener(new TopTipsView.OnChangeListener() { @Override public void onChange(int count) { // ((MainTimeLineActivity) getActivity()).setMentionsCommentCount(count); // setActionBarTabCount(count); } }); checkUnreadInfo(); }
Example #2
Source File: MyFirebaseInstanceIDService.java From LNMOnlineAndroidSample with Apache License 2.0 | 6 votes |
@Override public void onTokenRefresh() { super.onTokenRefresh(); String refreshedToken = FirebaseInstanceId.getInstance().getToken(); // Saving reg id to shared preferences storeRegIdInPref(refreshedToken); // sending reg id to your server sendRegistrationToServer(refreshedToken); // Notify UI that registration has completed, so the progress indicator can be hidden. Intent registrationComplete = new Intent(REGISTRATION_COMPLETE); registrationComplete.putExtra("token", refreshedToken); LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete); }
Example #3
Source File: DownloadManagerService.java From HHComicViewer with Apache License 2.0 | 6 votes |
@Override public void onCompleted(Request request, int progress, int size) { if (request == null) return; if (mComicChapterDBHelper == null) { mComicChapterDBHelper = ComicChapterDBHelper.getInstance(HHApplication.getInstance()); } ComicChapter comicChapter = mComicChapterDBHelper.findByChapterId(request.getChid()); if (comicChapter == null) return; comicChapter.setDownloadPosition(progress); comicChapter.setPageCount(size); comicChapter.setDownloadStatus(Constants.DOWNLOAD_FINISHED); mComicChapterDBHelper.update(comicChapter); if (mNotificationUtil == null) { mNotificationUtil = NotificationUtil.getInstance(HHApplication.getInstance()); } mNotificationUtil.finishedNotification(comicChapter); //发送本地广播 Intent intent = new Intent(DownloadManagerService.ACTION_RECEIVER); intent.putExtra("comicChapter", comicChapter); intent.putExtra("state", Constants.DOWNLOAD_FINISHED); LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent); }
Example #4
Source File: MyFirebaseInstanceIDService.java From protrip with MIT License | 6 votes |
@Override public void onTokenRefresh() { super.onTokenRefresh(); String refreshedToken = FirebaseInstanceId.getInstance().getToken(); // Saving reg id to shared preferences storeRegIdInPref(refreshedToken); // sending reg id to your server sendRegistrationToServer(refreshedToken); // Notify UI that registration has completed, so the progress indicator can be hidden. Intent registrationComplete = new Intent(Constants.REGISTRATION_COMPLETE); registrationComplete.putExtra("token", refreshedToken); LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete); }
Example #5
Source File: BeaconLocatorApp.java From beaconloc with Apache License 2.0 | 6 votes |
@Override public void didExitRegion(Region region) { RegionName regName = RegionName.parseString(region.getUniqueId()); if (regName.isApplicationRegion()) { Log.d(Constants.TAG, "didExitRegion " + region); if (regName.getEventType() == ActionBeacon.EventType.EVENT_NEAR_YOU) { try { mBeaconManager.stopRangingBeaconsInRegion(region); // set "far" proximity mDataManager.updateBeaconDistance(regName.getBeaconId(), 99); } catch (RemoteException e) { Log.e(Constants.TAG, "Error stop ranging region: " + regName, e); } } if (regName.getEventType() == ActionBeacon.EventType.EVENT_LEAVES_REGION) { Intent intent = new Intent(); intent.setAction(Constants.NOTIFY_BEACON_LEAVES_REGION); intent.putExtra("REGION", (Parcelable) region); LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent); } } }
Example #6
Source File: CursorLoader.java From wifi_backend with GNU General Public License v3.0 | 6 votes |
@Override protected void onReset() { super.onReset(); LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(changeReceiver); changeReceiver = null; // stop loader onStopLoading(); if (cursor != null && !cursor.isClosed()) { cursor.close(); } cursor = null; }
Example #7
Source File: FileSourceBrowserFragment.java From Mizuu with Apache License 2.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); mIsMovie = getArguments().getBoolean(MOVIE, false); mType = getArguments().getInt(TYPE, FileSource.FILE); if (mType == FileSource.UPNP) { contentListAdapter = new ArrayAdapter<ContentItem>(getActivity(), android.R.layout.simple_list_item_1); } LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mMessageReceiver, new IntentFilter("onBackPressed")); }
Example #8
Source File: MovementSpeedService.java From privacy-friendly-pedometer with GNU General Public License v3.0 | 6 votes |
/** * Calculates the speed from current location object. * If location has speed, this one will be used else the speed will be calculated from current * and last position. */ private void calculateSpeed(Location location){ double newTime= System.currentTimeMillis(); double newLat = location.getLatitude(); double newLon = location.getLongitude(); if(location.hasSpeed()){ Log.i(LOG_TAG, "Location has speed"); speed = location.getSpeed(); } else { Log.i(LOG_TAG, "Location has no speed"); double distance = calculationBydistance(newLat,newLon,oldLat,oldLon); double timeDifferent = (newTime - curTime) / 1000; // seconds speed = (float) (distance / timeDifferent); curTime = newTime; oldLat = newLat; oldLon = newLon; } Intent localIntent = new Intent(BROADCAST_ACTION_SPEED_CHANGED) // Add new step count .putExtra(EXTENDED_DATA_CURRENT_SPEED, speed); // Broadcasts the Intent to receivers in this app. LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent); Log.i(LOG_TAG, "New speed is " + speed + "m/sec " + speed * 3.6 + "km/h" ); }
Example #9
Source File: UserApp.java From userapp-android with MIT License | 6 votes |
/** onResume event, should be called from the main activity */ public void onResume() { this._isResumed = true; // Check in preferences if there is a token String token = this.sharedPreferences.getString(UserApp.SESSION_TOKEN_KEY, null); if (token != null) { // Use the fixed token with the API setToken(token); user = deserializeUser(); this.callCallbacks(true, null); } else { this.callCallbacks(false, null); } LocalBroadcastManager.getInstance(this.activity).registerReceiver(this.loginReceiver, new IntentFilter(UserApp.ACTION_SESSION_LOGIN)); LocalBroadcastManager.getInstance(this.activity).registerReceiver(logoutReceiver, new IntentFilter(UserApp.ACTION_SESSION_LOGOUT)); LocalBroadcastManager.getInstance(this.activity).registerReceiver(userUpdateReceiver, new IntentFilter(UserApp.ACTION_USER_UPDATE)); }
Example #10
Source File: BathService.java From AcDisplay with GNU General Public License v2.0 | 6 votes |
public static void startService(Context context, Class<? extends ChildService> clazz) { synchronized (monitor) { if (sRunning) { Intent intent = new Intent(ACTION_ADD_SERVICE); intent.putExtra(EXTRA_SERVICE_CLASS, clazz); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); } else if (!sServiceMap.containsKey(clazz)) { ChildService instance; try { instance = clazz.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } sServiceMap.put(clazz, instance); if (!sCreated) context.startService(new Intent(context, BathService.class)); } } }
Example #11
Source File: MainActivity.java From bridgefy-android-samples with MIT License | 6 votes |
@Override public void onMessageReceived(Message message) { Log.i(TAG, "onMessageReceived: "); // direct messages carrying a Device name represent device handshakes if (message.getContent().get("device_name") != null) { Peer peer = new Peer(message.getSenderId(), (String) message.getContent().get("device_name")); peer.setNearby(true); peersAdapter.addPeer(peer); // any other direct bridgefyFile should be treated as such } else { Log.i(TAG, "onMessageReceived: sending broadcast to "+message.getSenderId()); LocalBroadcastManager.getInstance(getBaseContext()).sendBroadcast( new Intent(message.getSenderId()) .putExtra(INTENT_EXTRA_MSG, message)); } }
Example #12
Source File: MentionsWeiboTimeLineFragment.java From iBeebo with GNU General Public License v3.0 | 6 votes |
@Override public void onResume() { super.onResume(); setListViewPositionFromPositionsCache(); LocalBroadcastManager.getInstance(getActivity()).registerReceiver(newBroadcastReceiver, new IntentFilter(AppEventAction.NEW_MSG_BROADCAST)); // setActionBarTabCount(newMsgTipBar.getValues().size()); getNewMsgTipBar().setOnChangeListener(new TopTipsView.OnChangeListener() { @Override public void onChange(int count) { // ((MainTimeLineActivity) getActivity()).setMentionsWeiboCount(count); // setActionBarTabCount(count); } }); checkUnreadInfo(); }
Example #13
Source File: PluginMgr.java From springreplugin with Apache License 2.0 | 6 votes |
final void newPluginFound(PluginInfo info, boolean persistNeedRestart) { // 更新最新插件表 PluginTable.updatePlugin(info); // 更新可加载插件表 insertNewPlugin(info); // 清空插件的状态(解禁) PluginStatusController.setStatus(info.getName(), info.getVersion(), PluginStatusController.STATUS_OK); if (IPC.isPersistentProcess()) { persistNeedRestart = mNeedRestart; } // 输出一个日志 if (LOGR) { LogRelease.i(PLUGIN_TAG, "p.m. n p f n=" + info.getName() + " b1=" + persistNeedRestart + " b2=" + mNeedRestart); } // 通知本进程:通知给外部使用者 Intent intent = new Intent(RePluginConstants.ACTION_NEW_PLUGIN); intent.putExtra(RePluginConstants.KEY_PLUGIN_INFO, info); intent.putExtra(RePluginConstants.KEY_PERSIST_NEED_RESTART, persistNeedRestart); intent.putExtra(RePluginConstants.KEY_SELF_NEED_RESTART, mNeedRestart); LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent); }
Example #14
Source File: DownloadRecordActivity.java From Dainty with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); //startService(new Intent(this, FileListenerService.class)); setContentView(R.layout.activity_download_record); IntentFilter mFilter = new IntentFilter(); mFilter.addAction("download_progress_refresh"); LocalBroadcastManager.getInstance(this).registerReceiver(downloadStatus, mFilter); ButterKnife.bind(this); initData(); initView(); timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { showNetSpeed(); } }, 0, 1000); }
Example #15
Source File: BeaconLocatorApp.java From beaconloc with Apache License 2.0 | 6 votes |
@Override public void didEnterRegion(Region region) { RegionName regName = RegionName.parseString(region.getUniqueId()); if (regName.isApplicationRegion()) { Log.d(Constants.TAG, "didEnterRegion " + region); if (regName.getEventType() == ActionBeacon.EventType.EVENT_NEAR_YOU) { try { mBeaconManager.startRangingBeaconsInRegion(region); } catch (RemoteException e) { Log.e(Constants.TAG, "Error start ranging region: " + regName, e); } } if (regName.getEventType() == ActionBeacon.EventType.EVENT_ENTERS_REGION) { Intent intent = new Intent(); intent.setAction(Constants.NOTIFY_BEACON_ENTERS_REGION); intent.putExtra("REGION", (Parcelable)region); LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent); } } }
Example #16
Source File: SendRepostService.java From iBeebo with GNU General Public License v3.0 | 6 votes |
private void showSuccessfulNotification(final WeiboSendTask task) { Notification.Builder builder = new Notification.Builder(SendRepostService.this) .setTicker(getString(R.string.send_successfully)) .setContentTitle(getString(R.string.send_successfully)).setOnlyAlertOnce(true).setAutoCancel(true) .setSmallIcon(R.drawable.send_successfully).setOngoing(false); Notification notification = builder.getNotification(); final int id = tasksNotifications.get(task); NotificationUtility.show(notification, id); handler.postDelayed(new Runnable() { @Override public void run() { NotificationUtility.cancel(id); stopServiceIfTasksAreEnd(task); } }, 3000); LocalBroadcastManager.getInstance(SendRepostService.this).sendBroadcast( new Intent(AppEventAction.buildSendRepostSuccessfullyAction(oriMsg))); }
Example #17
Source File: MainActivity.java From PowerSwitch_Android with GNU General Public License v3.0 | 5 votes |
@Override protected void onStart() { super.onStart(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(LocalBroadcastConstants.INTENT_HISTORY_CHANGED); LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver, intentFilter); }
Example #18
Source File: CustomLanguagesActivity.java From GithubTrends with Apache License 2.0 | 5 votes |
@Override public void onBackPressed() { if (Arrays.equals(adapter.mItems.toArray(), LanguageHelper.getInstance().getSelectedLanguages())) { super.onBackPressed(); } else { ConfirmDialog confirmDialog = ConfirmDialog.newInstance("Confirm Exit", "Do you want to save your changes before exiting?", R.string.save, R.string.not_save); confirmDialog.setConfirmDialogListener(new ConfirmDialog.IConfirmDialogListener() { @Override public void onConfirm() { AnalyticsHelper.sendEvent("CustomLangs", "ExitDialog", "Save", 0l); LanguageHelper.getInstance().setSelectedLanguages(adapter.mItems); LocalBroadcastManager.getInstance(getContext()).sendBroadcast(new Intent(Constants.ACTION_SELECTED_LANGUAGES_CHANGE)); finish(); } }); confirmDialog.setNegativeClickListener(new ConfirmDialog.INegativeClickListener() { @Override public void onNegativeButtonClick() { AnalyticsHelper.sendEvent("CustomLangs", "ExitDialog", "GiveUp", 0l); finish(); } }); confirmDialog.show(getSupportFragmentManager(), "confirm"); } }
Example #19
Source File: ListenerService.java From NightWatch with GNU General Public License v3.0 | 5 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) { DataMap dataMap; for (DataEvent event : dataEvents) { if (event.getType() == DataEvent.TYPE_CHANGED) { String path = event.getDataItem().getUri().getPath(); if (path.equals(OPEN_SETTINGS)) { //TODO: OpenSettings Intent intent = new Intent(this, NWPreferences.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } else { dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap(); Intent messageIntent = new Intent(); messageIntent.setAction(Intent.ACTION_SEND); messageIntent.putExtra("data", dataMap.toBundle()); LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent); } } } }
Example #20
Source File: ChatActivity.java From bridgefy-android-samples with MIT License | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); ButterKnife.bind(this); // recover our Peer object conversationName = getIntent().getStringExtra(INTENT_EXTRA_NAME); conversationId = getIntent().getStringExtra(INTENT_EXTRA_UUID); // Configure the Toolbar Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Enable the Up button ActionBar ab = getSupportActionBar(); if (ab != null) { ab.setTitle(conversationName); ab.setDisplayHomeAsUpEnabled(true); } // register the receiver to listen for incoming messages LocalBroadcastManager.getInstance(getBaseContext()) .registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Message message = new Message(intent.getStringExtra(MainActivity.INTENT_EXTRA_MSG)); message.setDeviceName(intent.getStringExtra(MainActivity.INTENT_EXTRA_NAME)); message.setDirection(Message.INCOMING_MESSAGE); messagesAdapter.addMessage(message); } }, new IntentFilter(conversationId)); // configure the recyclerview RecyclerView messagesRecyclerView = findViewById(R.id.message_list); LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(this); mLinearLayoutManager.setReverseLayout(true); messagesRecyclerView.setLayoutManager(mLinearLayoutManager); messagesRecyclerView.setAdapter(messagesAdapter); }
Example #21
Source File: StepCountPersistenceHelper.java From privacy-friendly-pedometer with GNU General Public License v3.0 | 5 votes |
/** * Updates the given step count in database based on end timestamp * * @param stepCount The step count to save * @param context The application context * @return true if save was successful else false. */ public static boolean updateStepCount(StepCount stepCount, Context context) { new StepCountDbHelper(context).updateStepCount(stepCount); // broadcast the event Intent localIntent = new Intent(BROADCAST_ACTION_STEPS_UPDATED); // Broadcasts the Intent to receivers in this app. LocalBroadcastManager.getInstance(context).sendBroadcast(localIntent); return true; }
Example #22
Source File: MyProfileFragment.java From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onResume() { super.onResume(); LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getActivity()); manager.registerReceiver(mOnProfileInfoUploadListener, new IntentFilter(ON_UPLOAD_FINISHED_LISTENER_TAG)); manager.registerReceiver(mOnProfileInfoUpdateListener, new IntentFilter(ON_UPDATE_FINISHED_LISTENER_TAG)); }
Example #23
Source File: EpgSyncWithAdsJobServiceTest.java From androidtv-sample-inputs with Apache License 2.0 | 5 votes |
@Override public void tearDown() throws Exception { super.tearDown(); LocalBroadcastManager.getInstance(getActivity()) .unregisterReceiver(mSyncStatusChangedReceiver); // Delete these programs getActivity() .getContentResolver() .delete( TvContract.buildChannelsUriForInput(TestTvInputService.INPUT_ID), null, null); }
Example #24
Source File: SessionTracker.java From Klyph with MIT License | 5 votes |
/** * Constructs a SessionTracker to track the Session object passed in. * If the Session is null, then it will track the active Session instead. * * @param context the context object. * @param callback the callback to use whenever the Session's state changes * @param session the Session object to track * @param startTracking whether to start tracking the Session right away */ public SessionTracker(Context context, Session.StatusCallback callback, Session session, boolean startTracking) { this.callback = new CallbackWrapper(callback); this.session = session; this.receiver = new ActiveSessionBroadcastReceiver(); this.broadcastManager = LocalBroadcastManager.getInstance(context); if (startTracking) { startTracking(); } }
Example #25
Source File: ConnectionService.java From weMessage with GNU Affero General Public License v3.0 | 5 votes |
public void endService(){ Intent serviceClosedIntent = new Intent(); serviceClosedIntent.setAction(weMessage.BROADCAST_CONNECTION_SERVICE_STOPPED); LocalBroadcastManager.getInstance(this).sendBroadcast(serviceClosedIntent); getConnectionHandler().endConnection(); stopSelf(); }
Example #26
Source File: MainActivity.java From journaldev with MIT License | 5 votes |
private void setReceiver() { myReceiver = new MyReceiver(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(FILTER_ACTION_KEY); LocalBroadcastManager.getInstance(this).registerReceiver(myReceiver, intentFilter); }
Example #27
Source File: c.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
public void onReceiveLocation(Location location) { Debug.i("LocationManager", (new StringBuilder()).append("Location Received : ").append(location).toString()); Intent intent = new Intent("com.xiaomi.hm.health.LocationReceived"); intent.putExtra("Location", location); LocalBroadcastManager.getInstance(LocationManager.a(a)).sendBroadcast(intent); }
Example #28
Source File: AppLockActivity.java From LolliPin with MIT License | 5 votes |
/** * Override {@link #onBackPressed()} to prevent user for finishing the activity */ @Override public void onBackPressed() { if (getBackableTypes().contains(mType)) { if (AppLock.UNLOCK_PIN == getType()) { mLockManager.getAppLock().setPinChallengeCancelled(true); LocalBroadcastManager .getInstance(this) .sendBroadcast(new Intent().setAction(ACTION_CANCEL)); } super.onBackPressed(); } }
Example #29
Source File: ConfigureGeofenceDialogPage3ExitActionsFragment.java From PowerSwitch_Android with GNU General Public License v3.0 | 5 votes |
/** * Used to notify the setup page that some info has changed * * @param context any suitable context */ public static void sendActionsChangedBroadcast(Context context, ArrayList<Action> actions) { Intent intent = new Intent(LocalBroadcastConstants.INTENT_GEOFENCE_EXIT_ACTIONS_CHANGED); intent.putExtra("actions", actions); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); }
Example #30
Source File: HyperionScreenService.java From hyperion-android-grabber with MIT License | 5 votes |
private void notifyActivity() { Intent intent = new Intent(BROADCAST_FILTER); intent.putExtra(BROADCAST_TAG, isCommunicating()); intent.putExtra(BROADCAST_ERROR, mStartError); if (DEBUG) { Log.v(TAG, "Sending status broadcast - communicating: " + String.valueOf(isCommunicating())); if (mStartError != null) { Log.v(TAG, "Startup error: " + mStartError); } } LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent); }