List of usage examples for android.support.v4.content LocalBroadcastManager getInstance
public static LocalBroadcastManager getInstance(Context context)
From source file:com.android.contacts.DynamicShortcuts.java
public synchronized static void initialize(Context context) { if (Log.isLoggable(TAG, Log.DEBUG)) { final Flags flags = Flags.getInstance(); Log.d(TAG, "DyanmicShortcuts.initialize\nVERSION >= N_MR1? " + (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) + "\nisJobScheduled? " + (CompatUtils.isLauncherShortcutCompatible() && isJobScheduled(context)) + "\nminDelay=" + flags.getInteger(Experiments.DYNAMIC_MIN_CONTENT_CHANGE_UPDATE_DELAY_MILLIS) + "\nmaxDelay=" + flags.getInteger(Experiments.DYNAMIC_MAX_CONTENT_CHANGE_UPDATE_DELAY_MILLIS)); }/* w w w . ja va2s. c om*/ if (!CompatUtils.isLauncherShortcutCompatible()) return; final DynamicShortcuts shortcuts = new DynamicShortcuts(context); if (!shortcuts.hasRequiredPermissions()) { final IntentFilter filter = new IntentFilter(); filter.addAction(RequestPermissionsActivity.BROADCAST_PERMISSIONS_GRANTED); LocalBroadcastManager.getInstance(shortcuts.mContext).registerReceiver(new PermissionsGrantedReceiver(), filter); } else if (!isJobScheduled(context)) { // Update the shortcuts. If the job is already scheduled then either the app is being // launched to run the job in which case the shortcuts will get updated when it runs or // it has been launched for some other reason and the data we care about for shortcuts // hasn't changed. Because the job reschedules itself after completion this check // essentially means that this will run on each app launch that happens after a reboot. // Note: the task schedules the job after completing. new ShortcutUpdateTask(shortcuts).execute(); } }
From source file:cgeo.geocaching.CacheDetailActivity.java
@Override public void onStart() { super.onStart(); LocalBroadcastManager.getInstance(this).registerReceiver(updateReceiver, new IntentFilter(Intents.INTENT_CACHE_CHANGED)); }
From source file:com.anjalimacwan.MainActivity.java
private void reallyDeleteNote() { // Build the pathname to delete each file, them perform delete operation for (Object file : filesToDelete) { File fileToDelete = new File(getFilesDir() + File.separator + file); fileToDelete.delete();// www .jav a 2 s .co m } String[] filesToDelete2 = new String[filesToDelete.length]; Arrays.asList(filesToDelete).toArray(filesToDelete2); // Send broadcasts to update UI Intent deleteIntent = new Intent(); deleteIntent.setAction("com.anjalimacwan.DELETE_NOTES"); deleteIntent.putExtra("files", filesToDelete2); LocalBroadcastManager.getInstance(this).sendBroadcast(deleteIntent); Intent listIntent = new Intent(); listIntent.setAction("com.anjalimacwan.LIST_NOTES"); LocalBroadcastManager.getInstance(this).sendBroadcast(listIntent); // Show toast notification if (filesToDelete.length == 1) showToast(R.string.note_deleted); else showToast(R.string.notes_deleted); filesToDelete = null; }
From source file:ca.rmen.android.scrumchatter.main.MainActivity.java
/** * The user tapped on the OK button of a confirmation dialog. Execute the action requested by the user. * * @param actionId the action id which was provided to the {@link DialogFragmentFactory} when creating the dialog. * @param extras any extras which were provided to the {@link DialogFragmentFactory} when creating the dialog. * @see ca.rmen.android.scrumchatter.dialog.ConfirmDialogFragment.DialogButtonListener#onOkClicked(int, android.os.Bundle) *///from w ww . j a va 2 s . c o m @Override public void onOkClicked(int actionId, Bundle extras) { Log.v(TAG, "onClicked: actionId = " + actionId + ", extras = " + extras); if (actionId == R.id.action_delete_meeting) { long meetingId = extras.getLong(Meetings.EXTRA_MEETING_ID); mMeetings.delete(meetingId); } else if (actionId == R.id.btn_stop_meeting) { MeetingFragment meetingFragment = MeetingFragment.lookupMeetingFragment(getSupportFragmentManager()); if (meetingFragment != null) meetingFragment.stopMeeting(); } else if (actionId == R.id.action_delete_member) { long memberId = extras.getLong(Members.EXTRA_MEMBER_ID); mMembers.deleteMember(memberId); } else if (actionId == R.id.action_team_delete) { Uri teamUri = extras.getParcelable(Teams.EXTRA_TEAM_URI); mTeams.deleteTeam(teamUri); } else if (actionId == R.id.action_import) { final Uri uri = extras.getParcelable(EXTRA_IMPORT_URI); DialogFragmentFactory.showProgressDialog(MainActivity.this, getString(R.string.progress_dialog_message), PROGRESS_DIALOG_FRAGMENT_TAG); Schedulers.io().scheduleDirect(() -> { boolean result = false; try { Log.v(TAG, "Importing db from " + uri); DBImport.importDB(MainActivity.this, uri); result = true; } catch (Exception e) { Log.e(TAG, "Error importing db: " + e.getMessage(), e); } // Notify ourselves with a broadcast. If the user rotated the device, this activity // won't be visible any more. The new activity will receive the broadcast and update // the UI. Intent intent = new Intent(ACTION_IMPORT_COMPLETE).putExtra(EXTRA_IMPORT_RESULT, result); LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent); }); } }
From source file:com.anjalimacwan.fragment.NoteEditFragment.java
private void saveNote() throws IOException { // Set current note contents to a String noteContents = (EditText) getActivity().findViewById(R.id.editText1); contents = noteContents.getText().toString(); // Write the String to a new file with filename of current milliseconds of Unix time if (contents.equals("") && filename.equals("draft")) finish(null);//from ww w. j a va 2 s .co m else { // Set a new filename if this is not a draft String newFilename; if (filename.equals("draft")) newFilename = filename; else newFilename = String.valueOf(System.currentTimeMillis()); // Write note to disk FileOutputStream output = getActivity().openFileOutput(newFilename, Context.MODE_PRIVATE); output.write(contents.getBytes()); output.close(); // Delete old file if (!filename.equals("draft")) deleteNote(filename); // Show toast notification if (filename.equals("draft")) showToast(R.string.draft_saved); else showToast(R.string.note_saved); // Old file is no more if (!filename.equals("draft")) { filename = newFilename; contentsOnLoad = contents; length = contentsOnLoad.length(); } // Send broadcast to MainActivity to refresh list of notes Intent listNotesIntent = new Intent(); listNotesIntent.setAction("com.anjalimacwan.LIST_NOTES"); LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(listNotesIntent); } }
From source file:cgeo.geocaching.CacheDetailActivity.java
@Override public void onStop() { if (cache != null) { cache.setChangeNotificationHandler(null); }/*from w ww. j a v a2 s . com*/ LocalBroadcastManager.getInstance(this).unregisterReceiver(updateReceiver); super.onStop(); }
From source file:arun.com.chromer.webheads.WebHeadService.java
private void registerReceivers() { final IntentFilter localEvents = new IntentFilter(); localEvents.addAction(ACTION_WEBHEAD_COLOR_SET); localEvents.addAction(ACTION_REBIND_WEBHEAD_TAB_CONNECTION); localEvents.addAction(ACTION_CLOSE_WEBHEAD_BY_URL); localEvents.addAction(ACTION_OPEN_CONTEXT_ACTIVITY); LocalBroadcastManager.getInstance(this).registerReceiver(localReceiver, localEvents); final IntentFilter notificationFilter = new IntentFilter(); notificationFilter.addAction(ACTION_STOP_WEBHEAD_SERVICE); notificationFilter.addAction(ACTION_OPEN_CONTEXT_ACTIVITY); notificationFilter.addAction(ACTION_OPEN_NEW_TAB); registerReceiver(notificationActionReceiver, notificationFilter); }
From source file:com.antew.redditinpictures.library.ui.ImageViewerFragment.java
/** * This handles receiving the touch events in the WebView so that we can * toggle between fullscreen and windowed mode. * <p/>/*from w w w . ja v a2 s. c o m*/ * The first time the user touches the screen we save the X and Y coordinates. * If we receive a {@link MotionEvent#ACTION_DOWN} event we compare the previous * X and Y coordinates to the saved coordinates, if they are greater than {@link * #MOVE_THRESHOLD} * we prevent the toggle from windowed mode to fullscreen mode or vice versa, the idea * being that the user is either dragging the image or using pinch-to-zoom. * <p/> * TODO: Implement handling for double tap to zoom. * * @return The {@link OnTouchListener} for the {@link WebView} to use. */ public OnTouchListener getWebViewOnTouchListener() { return new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mCancelClick = false; mDownXPos = event.getX(); mDownYPos = event.getY(); break; case MotionEvent.ACTION_UP: if (!mCancelClick) { Intent intent = new Intent(Constants.Broadcast.BROADCAST_TOGGLE_FULLSCREEN); intent.putExtra(Constants.Extra.EXTRA_IS_SYSTEM_UI_VISIBLE, mSystemUiStateProvider.isSystemUiVisible()); LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intent); } break; case MotionEvent.ACTION_MOVE: if (Math.abs(event.getX() - mDownXPos) > MOVE_THRESHOLD || Math.abs(event.getY() - mDownYPos) > MOVE_THRESHOLD) { mCancelClick = true; } break; } // Return false so that we still let the WebView consume the event return false; } }; }
From source file:com.anjalimacwan.fragment.NoteViewFragment.java
public void onDeleteDialogPositiveClick() { // User touched the dialog's positive button deleteNote(filename);//from w w w.j ava 2 s. c o m showToast(R.string.note_deleted); if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large")) { // Send broadcast to NoteListFragment to refresh list of notes Intent listNotesIntent = new Intent(); listNotesIntent.setAction("com.anjalimacwan.LIST_NOTES"); LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(listNotesIntent); } // Add NoteListFragment or WelcomeFragment Fragment fragment; if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-normal")) fragment = new NoteListFragment(); else fragment = new WelcomeFragment(); getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteListFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit(); }
From source file:au.org.ala.fielddata.mobile.MobileFieldDataDashboard.java
private void listenForSurveyDownload() { broadcastReceiver = new BroadcastReceiver() { @Override/*w w w.j av a 2 s. c o m*/ public void onReceive(Context context, Intent intent) { boolean success = intent.getBooleanExtra(SurveyDownloadService.RESULT_EXTRA, false); if (success) { Toast.makeText(MobileFieldDataDashboard.this, "Surveys refreshed", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(MobileFieldDataDashboard.this, "Refresh failed - please check your network", Toast.LENGTH_LONG).show(); } reloadTabs(); setSupportProgressBarIndeterminateVisibility(false); stopListeningForSurveyDownload(); } }; IntentFilter downloadFilter = new IntentFilter(SurveyDownloadService.FINISHED_ACTION); LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver, downloadFilter); }