List of usage examples for android.support.v4.content LocalBroadcastManager getInstance
public static LocalBroadcastManager getInstance(Context context)
From source file:com.achep.acdisplay.services.activemode.ActiveModeService.java
@Override public void onDestroy() { for (ActiveModeHandler handler : mHandlers) { handler.destroy();/*from w w w. jav a2 s . c om*/ } stopListening(); LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(mLocalReceiver); NotificationPresenter.getInstance().unregisterListener(this); }
From source file:com.allthatseries.RNAudioPlayer.MediaNotificationManager.java
@Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); Intent newIntent = new Intent("change-playback-action-event"); switch (action) { case ACTION_PAUSE: newIntent.putExtra("action", PlaybackAction.PAUSE); LocalBroadcastManager.getInstance(context).sendBroadcast(newIntent); break;/*from ww w. j a v a2s . c om*/ case ACTION_PLAY: newIntent.putExtra("action", PlaybackAction.PLAY); LocalBroadcastManager.getInstance(context).sendBroadcast(newIntent); break; case ACTION_NEXT: newIntent.putExtra("action", PlaybackAction.SKIP_TO_NEXT); LocalBroadcastManager.getInstance(context).sendBroadcast(newIntent); break; case ACTION_PREV: newIntent.putExtra("action", PlaybackAction.SKIP_TO_PREVIOUS); LocalBroadcastManager.getInstance(context).sendBroadcast(newIntent); break; default: break; } }
From source file:com.aimfire.gallery.service.PhotoProcessor.java
private void reportResult(String path, boolean isComfy) { mFirebaseAnalytics.logEvent(MainConsts.FIREBASE_CUSTOM_EVENT_SYNC_PHOTO_CAPTURE_COMPLETE, null); Intent messageIntent = new Intent(MainConsts.PHOTO_PROCESSOR_MESSAGE); messageIntent.putExtra(MainConsts.EXTRA_WHAT, MainConsts.MSG_PHOTO_PROCESSOR_RESULT); messageIntent.putExtra(MainConsts.EXTRA_PATH, path); messageIntent.putExtra(MainConsts.EXTRA_MSG, true/*isMyMedia*/); messageIntent.putExtra(MainConsts.EXTRA_COMFY, isComfy); LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent); }
From source file:com.android.camera.ActivityBase.java
@Override protected void onPause() { super.onPause(); LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this); manager.unregisterReceiver(mDeletePictureReceiver); if (LOGV)/*from w w w .j av a2 s . c o m*/ Log.v(TAG, "onPause"); saveThumbnailToFile(); if (mLoadThumbnailTask != null) { mLoadThumbnailTask.cancel(true); mLoadThumbnailTask = null; } if (mStorageHint != null) { mStorageHint.cancel(); mStorageHint = null; } }
From source file:com.android.fpuna.activityrecognition.MainActivity.java
@Override protected void onPause() { // Unregister the broadcast receiver that was registered during onResume(). LocalBroadcastManager.getInstance(this).unregisterReceiver(mBroadcastReceiver); super.onPause(); }
From source file:alaindc.memenguage.View.MainActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); checkLoggedIn();/* w ww . j av a2s . co m*/ setContentView(R.layout.activity_main); dbmanager = new DBManager(getApplicationContext()); crs = dbmanager.getAllWords(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); if (fab != null) fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent createWordIntentActivity = new Intent(MainActivity.this, CreateEditActivity.class); createWordIntentActivity.setAction(Constants.ACTION_ADD_WORD); MainActivity.this.startActivity(createWordIntentActivity); } }); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); if (drawer != null) drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); if (navigationView != null) navigationView.setNavigationItemSelectedListener(this); ImageView navlogo = (ImageView) navigationView.getHeaderView(0).findViewById(R.id.navLogoImageView); TextView navtitle = (TextView) navigationView.getHeaderView(0).findViewById(R.id.navTitle); TextView navsubtitle = (TextView) navigationView.getHeaderView(0).findViewById(R.id.navSubTitle); progressDialog = new ProgressDialog(this); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Constants.INTENT_VIEW_UPDATE)) { adapter.getFilter().filter(""); adapter.notifyDataSetChanged(); } else if (intent.getAction().equals(Constants.INTENT_COMMSERV_UPDATE)) { boolean success = intent.getBooleanExtra(Constants.EXTRA_COMMSERV_SUCCESS, false); String message = (intent.getIntExtra(Constants.EXTRA_COMMSERV_TYPE, 0) == Constants.UPLOAD) ? "Databased uploaded " : "Databased downloaded "; message = (success) ? message + "successfully!" : "An error occurred, try again."; progressDialog.setMessage(message); new Handler().postDelayed(new Runnable() { @Override public void run() { progressDialog.dismiss(); } }, 1500); } else { Log.d("", ""); } } }; IntentFilter updateviewIntFilt = new IntentFilter(Constants.INTENT_VIEW_UPDATE); IntentFilter serverCommIntFilt = new IntentFilter(Constants.INTENT_COMMSERV_UPDATE); LocalBroadcastManager.getInstance(this).registerReceiver(receiver, updateviewIntFilt); LocalBroadcastManager.getInstance(this).registerReceiver(receiver, serverCommIntFilt); SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE); personName = sharedPref.getString(Constants.PREF_GOOGLEACCOUNT_NAME, ""); personEmail = sharedPref.getString(Constants.PREF_GOOGLEACCOUNT_EMAIL, ""); personId = sharedPref.getString(Constants.PREF_GOOGLEACCOUNT_ID, ""); personPhoto = sharedPref.getString(Constants.PREF_GOOGLEACCOUNT_PHOTOURI, ""); // if (!personPhoto.equals("")) // new AsyncImageTask(navlogo).execute(personPhoto); navtitle.setText(personName); navsubtitle.setText(personEmail); // TODO Just one time and in bcast receiver start phone Intent randomStart = new Intent(MainActivity.this, RandomIntentService.class); randomStart.setAction(Constants.ACTION_RANDOM_START); getApplicationContext().startService(randomStart); updateWordsList(); }
From source file:alaindc.crowdroid.View.StakeholdersActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_stakeholders); linearLayout = (LinearLayout) findViewById(R.id.subscribesLinearLayout); updateStakeButton = (Button) findViewById(R.id.updateStakeButton); sendStakeButton = (Button) findViewById(R.id.sendStakeButton); updateStakeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent subscrIntent = new Intent(getApplicationContext(), SendIntentService.class); subscrIntent.setAction(Constants.ACTION_GETSUBSCRIPTION); getApplicationContext().startService(subscrIntent); }//from w ww. j av a 2 s.c o m }); sendStakeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { JSONArray jsonArr = new JSONArray(); JSONObject jsonObj = new JSONObject(); jsonObj.put("user", RadioUtils.getMyDeviceId(getApplicationContext())); jsonArr.put(jsonObj); for (int i = 0; i < linearLayout.getChildCount(); i++) { View view = linearLayout.getChildAt(i); if (view instanceof CheckBox) { CheckBox c = (CheckBox) view; if (c.isChecked()) { jsonObj = new JSONObject(); jsonObj.put("id", c.getId()); jsonArr.put(jsonObj); } } } String body = jsonArr.toString(); Intent subscrIntent = new Intent(getApplicationContext(), SendIntentService.class); subscrIntent.setAction(Constants.ACTION_UPDATESUBSCRIPTION); subscrIntent.putExtra(Constants.EXTRA_BODY_UPDATESUBSCRIPTION, body); getApplicationContext().startService(subscrIntent); } catch (JSONException e) { return; } } }); Intent subscrIntent = new Intent(getApplicationContext(), SendIntentService.class); subscrIntent.setAction(Constants.ACTION_GETSUBSCRIPTION); getApplicationContext().startService(subscrIntent); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Constants.INTENTVIEW_RECEIVED_SUBSCRIPTION)) { String response = intent.getStringExtra(Constants.EXTRAVIEW_RECEIVED_SUBSCRIPTION); //Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG).show(); linearLayout.removeAllViews(); try { JSONArray jsonArray = new JSONArray(response); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); int id = jsonObject.getInt("id"); String name = jsonObject.getString("name"); boolean subscribed = jsonObject.getInt("subscribed") == 1; CheckBox checkBox = new CheckBox(getApplicationContext()); checkBox.setTextColor(Color.BLACK); checkBox.setText(name); checkBox.setId(id); checkBox.setChecked(subscribed); linearLayout.addView(checkBox); int idx = linearLayout.indexOfChild(checkBox); checkBox.setTag(Integer.toString(idx)); } } catch (JSONException e) { return; } } else { Log.d("", ""); } } }; IntentFilter rcvDataIntFilter = new IntentFilter(Constants.INTENTVIEW_RECEIVED_SUBSCRIPTION); LocalBroadcastManager.getInstance(this).registerReceiver(receiver, rcvDataIntFilter); }
From source file:au.id.micolous.frogjump.LoginActivity.java
@Override protected void onResume() { super.onResume(); LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver, new IntentFilter(ApplicationPreferences.REGISTRATION_COMPLETE)); }
From source file:ca.appvelopers.mcgillmobile.ui.search.SearchResultsActivity.java
private static void startRegistration(final BaseActivity activity, Term term, final List<CourseResult> courses) { List<Course> theCourses = new ArrayList<>(); theCourses.addAll(courses);//from w w w . ja va 2 s. c o m activity.getMcGillService().registration(McGillManager.getRegistrationURL(term, theCourses, false)) .enqueue(new Callback<List<RegistrationError>>() { @Override public void onResponse(Call<List<RegistrationError>> call, Response<List<RegistrationError>> response) { activity.showToolbarProgress(false); //If there are no errors, show the success message if (response.body() == null || response.body().isEmpty()) { Utils.toast(activity, R.string.registration_success); return; } //Prepare the error message String String errorMessage = ""; List<Course> errorCourses = new ArrayList<>(); errorCourses.addAll(courses); for (RegistrationError error : response.body()) { errorMessage += error.getString(errorCourses); errorMessage += "\n"; } DialogHelper.error(activity, errorMessage); //Remove the courses from the wishlist if they were there List<CourseResult> wishlist = App.getWishlist(); wishlist.removeAll(courses); //Set the new wishlist App.setWishlist(wishlist); } @Override public void onFailure(Call<List<RegistrationError>> call, Throwable t) { Timber.e(t, "Error (un)registering for courses"); activity.showToolbarProgress(false); //If this is a MinervaException, broadcast it if (t instanceof MinervaException) { LocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(Constants.BROADCAST_MINERVA)); } else { DialogHelper.error(activity, R.string.error_other); } } }); }
From source file:com.android.tv.settings.MainFragment.java
@Override public void onStart() { super.onStart(); mAuthenticatorHelper.listenToAccountUpdates(); final IntentFilter filter = new IntentFilter(BluetoothConnectionsManager.ACTION_BLUETOOTH_UPDATE); LocalBroadcastManager.getInstance(getContext()).registerReceiver(mBCMReceiver, filter); }