List of usage examples for android.support.v4.content LocalBroadcastManager getInstance
public static LocalBroadcastManager getInstance(Context context)
From source file:ca.uwaterloo.magic.goodhikes.HistoryActivity.java
@Override protected void onDestroy() { LocalBroadcastManager.getInstance(this).unregisterReceiver(deleteItemMessageReceiver); super.onDestroy(); }
From source file:cc.softwarefactory.lokki.android.utilities.ServerApi.java
public static void getPlaces(final Context context) { Log.e(TAG, "getPlaces"); AQuery aq = new AQuery(context); String userId = PreferenceUtils.getString(context, PreferenceUtils.KEY_USER_ID); String authorizationToken = PreferenceUtils.getString(context, PreferenceUtils.KEY_AUTH_TOKEN); String url = ApiUrl + "user/" + userId + "/places"; AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() { @Override/*from w w w . j a v a2 s. c om*/ public void callback(String url, JSONObject json, AjaxStatus status) { Log.e(TAG, "placesCallback"); if (json == null) { Log.e(TAG, "Error: " + status.getCode() + " - " + status.getMessage()); return; } Log.e(TAG, "json returned: " + json); MainApplication.places = json; PreferenceUtils.setString(context, PreferenceUtils.KEY_PLACES, json.toString()); Intent intent = new Intent("PLACES-UPDATE"); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); } }; cb.header("authorizationtoken", authorizationToken); aq.ajax(url, JSONObject.class, cb); }
From source file:arun.com.chromer.webheads.ui.context.WebHeadContextActivity.java
private void registerEventsReceiver() { final IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_EVENT_WEBHEAD_DELETED); filter.addAction(ACTION_EVENT_WEBSITE_UPDATED); LocalBroadcastManager.getInstance(this).registerReceiver(webHeadsEventsReceiver, filter); }
From source file:arun.com.chromer.settings.lookandfeel.LookAndFeelActivity.java
@Override public void onColorSelection(@NonNull ColorChooserDialog dialog, @ColorInt int selectedColor) { switch (dialog.getTitle()) { case R.string.default_toolbar_color: final Intent toolbarColorIntent = new Intent(ACTION_TOOLBAR_COLOR_SET); toolbarColorIntent.putExtra(EXTRA_KEY_TOOLBAR_COLOR, selectedColor); LocalBroadcastManager.getInstance(this).sendBroadcast(toolbarColorIntent); break;//from ww w . ja v a 2 s .c om case R.string.web_heads_color: final Intent webHeadColorIntent = new Intent(ACTION_WEBHEAD_COLOR_SET); webHeadColorIntent.putExtra(EXTRA_KEY_WEBHEAD_COLOR, selectedColor); LocalBroadcastManager.getInstance(this).sendBroadcast(webHeadColorIntent); break; } }
From source file:ca.appvelopers.mcgillmobile.ui.transcript.TranscriptActivity.java
/** * Refreshes the transcript/*from w w w . j a va 2 s. com*/ */ private void refresh() { if (!canRefresh()) { return; } mcGillService.transcript().enqueue(new Callback<Transcript>() { @Override public void onResponse(Call<Transcript> call, Response<Transcript> response) { transcriptManager.set(response.body()); update(); showToolbarProgress(false); } @Override public void onFailure(Call<Transcript> call, Throwable t) { Timber.e(t, "Error refreshing transcript"); showToolbarProgress(false); //If this is a MinervaException, broadcast it if (t instanceof MinervaException) { LocalBroadcastManager.getInstance(TranscriptActivity.this) .sendBroadcast(new Intent(Constants.BROADCAST_MINERVA)); } else { DialogHelper.error(TranscriptActivity.this, R.string.error_other); } } }); }
From source file:arun.com.chromer.settings.preferences.BasePreferenceFragment.java
@NonNull protected LocalBroadcastManager getLocalBroadcastManager() { return LocalBroadcastManager.getInstance(getActivity()); }
From source file:ca.hoogit.garagepi.Controls.DoorControlService.java
private void handleActionQuery() { try {// w w w.j a v a2s .c om OkHttpClient client = Client.authClient(SharedPrefs.getInstance().getToken()); Request request = new Request.Builder().url(Helpers.getApiRoute("api", "gpios")).build(); Response response = client.newCall(request).execute(); boolean success = response.isSuccessful(); if (!success) { throw new IOException(getString(R.string.request_failed)); } Door[] doors = mGson.fromJson(response.body().string(), Door[].class); response.body().close(); ArrayList<Door> doorsList = new ArrayList<>(); Collections.addAll(doorsList, doors); Intent intent = new Intent(Consts.INTENT_MESSAGE_DOORS); intent.putExtra(Consts.KEY_BROADCAST_ACTION, Consts.ACTION_DOORS_QUERY); intent.putExtra(Consts.KEY_BROADCAST_SUCCESS, true); intent.putExtra(Consts.KEY_DOORS, doorsList); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); Log.d(TAG, "handleActionQuery: Broadcasting door information"); } catch (IOException e) { Log.e(TAG, "handleActionQuery: Request failed " + e.getMessage()); Helpers.broadcast(this, Consts.INTENT_MESSAGE_DOORS, Consts.ACTION_DOORS_QUERY, false, e.getMessage()); } }
From source file:ca.zadrox.dota2esportticker.ui.MatchActivity.java
@Override protected void onResume() { super.onResume(); int i = mViewPager.getCurrentItem(); for (MatchListFragment fragment : mMatchListFragments) { if (fragment.getArguments().getInt(MatchListFragment.ARG_LIST_POSITION) == i) { if (mCurrentListView != null) { mCurrentListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override/*from ww w.j a v a2s .c om*/ public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }); } enableActionBarAutoHide(fragment.getListView()); mCurrentListView = fragment.getListView(); } } LocalBroadcastManager.getInstance(this).registerReceiver(mUpdateCompleteReceiver, new IntentFilter(UpdateMatchService.UPDATE_COMPLETE)); LocalBroadcastManager.getInstance(this).registerReceiver(mUpdateStartedReceiver, new IntentFilter(UpdateMatchService.UPDATE_STARTED)); LocalBroadcastManager.getInstance(this).registerReceiver(mNoConnectionReceiver, new IntentFilter(UpdateMatchService.UPDATE_NO_CONNECTIVITY)); LocalBroadcastManager.getInstance(this).registerReceiver(mSteamAPIKeyIncorrectReceiver, new IntentFilter(SteamAuth.STEAM_API_KEY_INCORRECT)); this.startService( new Intent(UpdateMatchService.ACTION_UPDATE_RESULTS, null, this, UpdateMatchService.class)); }
From source file:arun.com.chromer.webheads.ui.context.WebHeadContextActivity.java
@Override protected void onDestroy() { super.onDestroy(); LocalBroadcastManager.getInstance(this).unregisterReceiver(webHeadsEventsReceiver); }
From source file:com.agiledge.keocometemployee.GCM.RegistrationIntentService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); try {/* w w w . j a v a2 s.c o m*/ // sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // [START register_for_gcm] // Initially this call goes out to the network to retrieve the token, subsequent calls // are local. // R.string.gcm_defaultSenderId (the Sender ID) is typically derived from google-services.json. // See https://developers.google.com/cloud-messaging/android/start for details on this file. // [START get_token] InstanceID instanceID = InstanceID.getInstance(this); token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); // [END get_token] Log.i(TAG, "GCM Registration Token: " + token); // TODO: Implement this method to send any registration to your app's servers. sendRegistrationToServer(token); // Subscribe to topic channels subscribeTopics(token); // You should store a boolean that indicates whether the generated token has been // sent to your server. If the boolean is false, send the token to your server, // otherwise your server should have already received the token. // [END register_for_gcm] } catch (Exception e) { Log.d(TAG, "Failed to complete token refresh", e); // If an exception happens while fetching the new token or updating our registration data // on a third-party server, this ensures that we'll attempt the update at a later time. sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply(); } // Notify UI that registration has completed, so the progress indicator can be hidden. Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE); LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete); }