List of usage examples for android.support.v4.content LocalBroadcastManager getInstance
public static LocalBroadcastManager getInstance(Context context)
From source file:com.air.mobilebrowser.ActivityWatchService.java
/** * Check for changes to key system settings (typically settings which don't fire Intents/Events * when they are changed).//from w w w . java 2 s .co m */ private void checkSettings() { // Clear the clipboard, regardless of contents mClipboardManager.setPrimaryClip(NEW_PLAIN_TEXT); // Check if the keyboard IME has changed, fire event and let someone else deal with the change String curKeyboard = KeyboardUtil.getKeyboardPackage(super.getContentResolver()); if (!curKeyboard.equals(mLastKeyboard)) { mLastKeyboard = curKeyboard; Intent intent = new Intent(super.getResources().getString(R.string.intent_keyboardchange)); LocalBroadcastManager.getInstance(super.getApplicationContext()).sendBroadcast(intent); } // Check if microphone mute flag changed, fire event and let someone else deal with the change boolean micMute = mAudioManager.isMicrophoneMute(); if (mMicMute != micMute) { mMicMute = micMute; Intent intent = new Intent(super.getResources().getString(R.string.intent_micmutechanged)); LocalBroadcastManager.getInstance(super.getApplicationContext()).sendBroadcast(intent); } }
From source file:ca.uwaterloo.magic.goodhikes.GPSLoggingService.java
private void broadcastLocation(Location location) { Log.d(LOG_TAG, "Thread: " + Thread.currentThread().getId() + "; Sending location update"); Intent intent = new Intent(locationUpdateCommand); intent.putExtra(locationUpdateCommand, location); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); }
From source file:com.android.tv.settings.system.CaptionFragment.java
private void setCaptionsStyle(int style) { Settings.Secure.putInt(getContext().getContentResolver(), Settings.Secure.ACCESSIBILITY_CAPTIONING_PRESET, style);/* www . ja v a 2s .c om*/ LocalBroadcastManager.getInstance(getContext()) .sendBroadcast(new Intent(CaptionSettingsFragment.ACTION_REFRESH_CAPTIONS_PREVIEW)); }
From source file:alaindc.crowdroid.SendIntentService.java
private void handleActionReceivedData(String response) { // Data got from server response int timeout; // sec double radius; // meters int sensor;/*from ww w .java 2 s. c o m*/ double latitude, longitude; // Update view sending a broadcast intent Intent intent = new Intent(Constants.INTENT_RECEIVED_DATA); intent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA, response); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); try { JSONArray jsonArray = new JSONArray(response); JSONObject jsonObject = jsonArray.getJSONObject(0); sensor = jsonObject.getInt("sensor"); // For time homogeneity timeout = jsonObject.getInt("timeout"); // For space homogeneity radius = jsonObject.getDouble("radius"); latitude = jsonObject.getDouble("lat"); longitude = jsonObject.getDouble("long"); } catch (JSONException e) { return; } if (sensor == Constants.TYPE_TEL) { SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean(Constants.THROUGHPUT_TAKEN, false); editor.commit(); } Intent geofenceIntent = new Intent(getApplicationContext(), GeofenceIntentService.class); geofenceIntent.putExtra(Constants.EXTRA_GEOFENCE_SENSORTYPE, sensor); geofenceIntent.putExtra(Constants.EXTRA_GEOFENCE_LATITUDE, latitude); geofenceIntent.putExtra(Constants.EXTRA_GEOFENCE_LONGITUDE, longitude); geofenceIntent.putExtra(Constants.EXTRA_GEOFENCE_RADIUS, String.valueOf(radius)); geofenceIntent.putExtra(Constants.EXTRA_GEOFENCE_EXPIRE_MILLISEC, String.valueOf(timeout * 1000)); getApplicationContext().startService(geofenceIntent); // Set timeout based on server response alarmMgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); Intent intentAlarm = new Intent(getApplicationContext(), SendIntentService.class); intentAlarm.setAction(Constants.ACTION_SENDDATA + sensor); intentAlarm.putExtra(Constants.EXTRA_TYPE_OF_SENSOR_TO_SEND, sensor); alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intentAlarm, 0); int seconds = timeout; alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + seconds * 1000, alarmIntent); }
From source file:com.android.screenspeak.tutorial.TutorialModule.java
/** * Unregisters a broadcast receiver with the parent tutorial's * {@link LocalBroadcastManager}.//w w w. ja va 2s . c o m * * @param receiver The broadcast receiver to unregister. */ void unregisterReceiver(BroadcastReceiver receiver) { final LocalBroadcastManager manager = LocalBroadcastManager.getInstance(mParentTutorial); if (manager == null) { return; } manager.unregisterReceiver(receiver); }
From source file:com.antew.redditinpictures.library.ui.RedditFragmentActivity.java
private void unregisterReceivers() { if (mLoginComplete != null) { LocalBroadcastManager.getInstance(this).unregisterReceiver(mLoginComplete); } }
From source file:com.air.mobilebrowser.BrowserActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ttsPlayer = new TTSPlayer(this); // Allow for out-of-band additions to thread queue (mainly for cleanup) mHandler = new Handler(); // Prevents user from taking screenshots. getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // Load layout mWebView = new AIRWebView(this, this); mWebView.requestFocus(View.FOCUS_DOWN); setContentView(R.layout.activity_browser); FrameLayout layout = (FrameLayout) findViewById(R.id.sec_webview); layout.addView(((AIRWebView) mWebView).getLayout()); // Initialize device monitoring mDeviceStatus = new DeviceStatus(this, this); mDeviceStatus.registerReceivers(this); // By default, lock to landscape setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); mDeviceStatus.lockedOrientation = "landscape"; // Configure the webview configureWebView(mWebView);/* ww w. j a v a 2s . c o m*/ // Configure Debug Console if (mIsDebugEnabled) { findViewById(R.id.slidingDrawer1).setVisibility(View.VISIBLE); findViewById(R.id.addressBarWrapper).setVisibility(View.VISIBLE); findViewById(R.id.goButton).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String url = ((EditText) findViewById(R.id.address_bar)).getText().toString(); mWebView.loadUrl(url); } }); } // Load the content SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); String url = preferences.getString("pref_default_url", getString(R.string.url_default_location)); // For testing, uncomment the following line to use a custom url: // Check for Internet connectivity if (mDeviceStatus.connectivity == DeviceStatus.CONNECTIVITY_CONNECTED) { mWebView.loadUrl(url); } else { mWebView.loadUrl("about:none"); } // Register BroadcastListener for service intents mSBReceiver = new SBReceiver(this); LocalBroadcastManager.getInstance(super.getApplicationContext()).registerReceiver(mSBReceiver, new IntentFilter(super.getResources().getString(R.string.intent_black_logtag))); LocalBroadcastManager.getInstance(super.getApplicationContext()).registerReceiver(mSBReceiver, new IntentFilter(super.getResources().getString(R.string.intent_micmutechanged))); LocalBroadcastManager.getInstance(super.getApplicationContext()).registerReceiver(mSBReceiver, new IntentFilter(super.getResources().getString(R.string.intent_keyboardchange))); // add receiver for bluetooth keyboard connection/disconnection events LocalBroadcastManager.getInstance(super.getApplicationContext()).registerReceiver(mSBReceiver, new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED)); LocalBroadcastManager.getInstance(super.getApplicationContext()).registerReceiver(mSBReceiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED)); IntentFilter testFilter = new IntentFilter(Intent.CATEGORY_HOME); super.getApplicationContext().registerReceiver(mSBReceiver, testFilter); // Get AudioManger mAudioManager = (AudioManager) super.getApplicationContext().getSystemService(Context.AUDIO_SERVICE); // Configure JS Command Processing configureJSCmdHandling(); // Begin monitoring for focus change. startService(new Intent(getApplicationContext(), ActivityWatchService.class)); }
From source file:com.aimfire.gallery.service.SamplesDownloader.java
private void parseLinkFile(String linkPath) { ArrayList<String> samplesResId = new ArrayList<String>(); ArrayList<String> samplesName = new ArrayList<String>(); try {/*from w w w. j ava 2s. c o m*/ FileInputStream fis = new FileInputStream(linkPath); //Construct BufferedReader from InputStreamReader BufferedReader br = new BufferedReader(new InputStreamReader(fis)); String line = null; while ((line = br.readLine()) != null) { if (line.startsWith("#")) { /* * comment line, skip */ continue; } String[] tokens = line.split(" "); if (tokens.length != 2) { if (BuildConfig.DEBUG) Log.e(TAG, "parseLinkFile: cannot parse this line = " + line); continue; } else { samplesResId.add(tokens[0]); samplesName.add(tokens[1]); } } br.close(); } catch (IOException e) { if (BuildConfig.DEBUG) Log.e(TAG, "parseLinkFile: couldn't read samples.lnk " + e.getMessage()); FirebaseCrash.report(e); } boolean needDownload = false; for (int i = 0; i < samplesResId.size(); i++) { String resId = samplesResId.get(i); String name = samplesName.get(i); String path = null; /* * SBS...jpg - this is a 3D SBS image * MPG...jpeg - this is a preview frame of cvr movie */ if (MediaScanner.isPreview(name)) { path = MediaScanner.getPreviewPathFromOrigName(name); if ((new File(path).exists())) { /* * we already have this sample */ continue; } /* * create an empty, placeholder movie file, so GalleryActivity/ThumbsFragment * knows its existence and show a progress bar while this file is downloaded */ String cvrPath = MediaScanner.getSharedMediaPathFromOrigName(name); if (!(new File(cvrPath).exists())) { try { MediaScanner.addItemMediaList(cvrPath); (new File(cvrPath)).createNewFile(); } catch (IOException e) { Toast.makeText(this, R.string.error_accessing_storage, Toast.LENGTH_LONG).show(); FirebaseCrash.report(e); continue; } } else { /* * we don't have a preview file, but have a .cvr file, strange */ if (BuildConfig.DEBUG) Log.e(TAG, "parseLinkFile: cvr file already exists " + "in Shared Media! shouldn't happen"); FirebaseCrash.report(new Exception( "parseLinkFile: cvr file already exists " + "in Shared Media! shouldn't happen")); } } else if (MediaScanner.isPhoto(name)) { path = MediaScanner.getSharedMediaPathFromOrigName(name); if ((new File(path)).exists()) { /* * we already have this sample */ continue; } else { try { MediaScanner.addItemMediaList(path); (new File(path)).createNewFile(); } catch (IOException e) { Toast.makeText(this, R.string.error_accessing_storage, Toast.LENGTH_LONG).show(); FirebaseCrash.report(e); continue; } } } else { /* * we are downloading preview and photo only. somehow a cvr * or some other file got into the link file. ignore */ if (BuildConfig.DEBUG) Log.e(TAG, "downloadSamples: file name = " + name + "shouldn't be here"); continue; } /* * we have at least one sample that needs to be downloaded */ needDownload = true; /* * save drive file record. */ saveDriveFileRecord(name, resId); } if (needDownload) { /* * notify Thumbs fragment or Gallery activity to update their list */ Intent messageIntent = new Intent(MainConsts.FILE_DOWNLOADER_MESSAGE); messageIntent.putExtra(MainConsts.EXTRA_WHAT, MainConsts.MSG_FILE_DOWNLOADER_SAMPLES_START); LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent); } }
From source file:com.antew.redditinpictures.library.ui.RedditFragmentActivity.java
private void registerReceivers() { LocalBroadcastManager.getInstance(this).registerReceiver(mLoginComplete, new IntentFilter(Constants.Broadcast.BROADCAST_LOGIN_COMPLETE)); }
From source file:co.ldln.android.MainActivity.java
@Override protected void onDestroy() { // Unregister since the activity is about to be closed. LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver); super.onDestroy(); }