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 onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_history); database = RoutesDatabaseManager.getInstance(this); userManager = new UserManager(getApplicationContext()); routes = database.getAllRoutes(Route.filterByUser(userManager.getUser())); routesAdapter = new RoutesAdapter(this, routes); View rootView = findViewById(android.R.id.content); mListView = (ListView) rootView.findViewById(R.id.routes_list); mListView.setAdapter(routesAdapter); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/*from w ww. j a v a2s. com*/ public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { Route route = (Route) adapterView.getItemAtPosition(position); if (route != null) { Intent intent = new Intent(); intent.putExtra(RouteEntry._ID, route.getId()); setResult(RESULT_OK, intent); finish(); } mPosition = position; } }); LocalBroadcastManager.getInstance(this).registerReceiver(deleteItemMessageReceiver, new IntentFilter(DELETE_ROUTE)); }
From source file:ca.farrelltonsolar.classic.DayLogChart.java
@Override public void onStart() { super.onStart(); if (!isReceiverRegistered) { LocalBroadcastManager.getInstance(DayLogChart.this.getActivity()).registerReceiver(mReadingsReceiver, new IntentFilter(Constants.CA_FARRELLTONSOLAR_CLASSIC_DAY_LOGS)); isReceiverRegistered = true;//from w w w. j ava 2 s .co m } Log.d(getClass().getName(), "onStart"); }
From source file:br.com.bign.push.RegistrationIntentService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); try {/*from www .j a v a2 s. c o m*/ // [START register_for_gcm] // Initially this call goes out to the network to retrieve the token, subsequent calls // are local. // [START get_token] InstanceID instanceID = InstanceID.getInstance(this); String token = instanceID.getToken(SEND_ID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); // [END get_token] Log.i(TAG, "GCM Registration Token: " + token); sharedPreferences.edit().putString("idgcm", token).apply(); // 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. sharedPreferences.edit().putBoolean("sendTokenToServer", true).apply(); // [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("sendTokenToServer", false).apply(); } // Notify UI that registration has completed, so the progress indicator can be hidden. Intent registrationComplete = new Intent("registrationComplete"); LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete); }
From source file:ca.zadrox.dota2esportticker.util.steamapi.SAPILiveGamesLoader.java
/** * @return DotaGameData[], an array of all live games, if matchId wasn't supplied, or if * a matchId was supplied, an array of length 1, containing just the live game specified, * or if no games were found, null.//from w w w .j ava2s .co m */ @Override public DotaGameData[] loadInBackground() { String steamAPIKey = SteamAuth.getSteamApiKey(getContext()); String getLiveLeagueGamesEndpoint = "http://api.steampowered.com/IDOTA2Match_570/GetLiveLeagueGames/v1/"; try { OkHttpClient okHttpClient = new OkHttpClient(); String rawJson = okHttpClient.newCall(new Request.Builder().url(getLiveLeagueGamesEndpoint + "?key=" + steamAPIKey + (matchId != 0 ? "&match_id=" + matchId : "")).build()).execute().body() .string(); if (rawJson.contains("<title>Forbidden</title>")) { LocalBroadcastManager.getInstance(getContext()) .sendBroadcast(new Intent(SteamAuth.STEAM_API_KEY_INCORRECT)); return null; } Gson gson = new Gson(); try { LiveLeagueGames liveLeagueGames = gson.fromJson(rawJson, LiveLeagueGames.class); if (liveLeagueGames == null) { return null; // no live data. } else if (liveLeagueGames.result == null) { return null; } else if (liveLeagueGames.result.games == null) { return null; } else if (liveLeagueGames.result.games.length == 0) { return null; } else { mGame = liveLeagueGames.result.games; // return all live games. return mGame; } } catch (RuntimeException e) { LogUtils.LOGD(TAG, "Steam Web API is down"); } } catch (IOException e) { LogUtils.LOGD(TAG, "Could not grab match json"); } return null; }
From source file:ch.luethi.skylinestracker.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (!getIntent().hasExtra(ISTESTING)) { BugSenseHandler.sendDataOverWiFiOnly(); BugSenseHandler.initAndStartSession(this, "a9b9af2d"); }// www. ja va 2 s . c o m app = ((SkyLinesApp) getApplicationContext()); positionService = new Intent(this, PositionService.class); SkyLinesPrefs prefs = new SkyLinesPrefs(this); prefs.setIpAddress(prefs.getIpAddress(getResources().getString(R.string.ip_address_dns))); setContentView(R.layout.activity_main); statusText = (TextView) findViewById(R.id.statusText); checkLiveTracking = (CheckBox) findViewById(R.id.checkLiveTracking); msgPosSent = " " + getResources().getString(R.string.msg_pos_sent); msgNoInet = getResources().getString(R.string.msg_no_inet); msgWaitGps = getResources().getString(R.string.resume); LocalBroadcastManager.getInstance(this).registerReceiver(onStatusChange, brFilter); }
From source file:com.airbop.library.simple.CommonUtilities.java
static void sendLocalBroadcast(Context context, Intent intent) { LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); if ((lbm != null) && (intent != null)) { lbm.sendBroadcast(intent);/*from w w w . j a va 2 s. c o m*/ } }
From source file:ca.farrelltonsolar.classic.DayLogCalendar.java
@Override public void onStart() { super.onStart(); if (!isReceiverRegistered) { LocalBroadcastManager.getInstance(DayLogCalendar.this.getActivity()).registerReceiver(mReadingsReceiver, new IntentFilter(Constants.CA_FARRELLTONSOLAR_CLASSIC_DAY_LOGS)); isReceiverRegistered = true;//w ww . ja v a2 s .co m } Log.d(getClass().getName(), "onStart"); }
From source file:com.aluvi.android.services.push.RegistrationIntentService.java
/** * Persist registration to third-party servers. * * @param token The new token./*from ww w . j a v a 2 s . c om*/ */ private void sendRegistrationToServer(String token) { DevicesApi.updatePushToken(token, new DevicesApi.Callback() { @Override public void success() { SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(RegistrationIntentService.this); sharedPreferences.edit().putBoolean(PushPreferences.SENT_TOKEN_TO_SERVER, true).apply(); // Notify UI that registration has completed, so the progress indicator can be hidden. Intent registrationComplete = new Intent(PushPreferences.REGISTRATION_COMPLETE); LocalBroadcastManager.getInstance(RegistrationIntentService.this) .sendBroadcast(registrationComplete); } @Override public void failure(int statusCode) { } }); }
From source file:com.achep.acdisplay.receiver.LocalReceiverActivity.java
private void handleIntent(Intent intent) { String host = extractHost(intent); if (host == null) { Log.wtf(TAG, "Got an empty launch intent."); return;//from w ww . java 2s . c om } switch (host) { case HOST_LAUNCH_DEVICE_ADMINS: Intent launchIntent = new Intent().setComponent( new ComponentName("com.android.settings", "com.android.settings.DeviceAdminSettings")); if (IntentUtils.hasActivityForThat(this, launchIntent)) { startActivity(launchIntent); } else { ToastUtils.showShort(this, getString(R.string.device_admin_could_not_be_started)); } break; case HOST_UNINSTALL: Uri packageUri = Uri.parse("package:" + PackageUtils.getName(this)); launchIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri); if (IntentUtils.hasActivityForThat(this, launchIntent)) { startActivity(launchIntent); } else { ToastUtils.showShort(this, getString(R.string.package_could_not_be_uninstalled)); } break; default: Log.wtf(TAG, "Got an unknown intent: " + host); return; } Intent broadcastIntent = new Intent(); broadcastIntent.setAction(host); LocalBroadcastManager.getInstance(this).sendBroadcast(broadcastIntent); }
From source file:com.achep.activedisplay.receiver.LocalReceiverActivity.java
private void handleIntent(Intent intent) { String host = extractHost(intent); if (host == null) { Log.wtf(TAG, "Got an empty launch intent."); return;/* w ww .j a v a2 s . c om*/ } switch (host) { case HOST_LAUNCH_DEVICE_ADMINS: Intent launchIntent = new Intent().setComponent( new ComponentName("com.android.settings", "com.android.settings.DeviceAdminSettings")); if (IntentUtils.hasActivityForThat(this, launchIntent)) { startActivity(launchIntent); } else { ToastUtils.showShort(this, getString(R.string.device_admin_could_not_be_started)); } break; case HOST_UNINSTALL: Uri packageUri = Uri.parse("package:" + Project.getPackageName(this)); launchIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri); if (IntentUtils.hasActivityForThat(this, launchIntent)) { startActivity(launchIntent); } else { ToastUtils.showShort(this, getString(R.string.package_could_not_be_uninstalled)); } break; default: Log.wtf(TAG, "Got an unknown intent: " + host); return; } Intent broadcastIntent = new Intent(); broadcastIntent.setAction(host); LocalBroadcastManager.getInstance(this).sendBroadcast(broadcastIntent); }