Example usage for android.support.v4.content LocalBroadcastManager getInstance

List of usage examples for android.support.v4.content LocalBroadcastManager getInstance

Introduction

In this page you can find the example usage for android.support.v4.content LocalBroadcastManager getInstance.

Prototype

public static LocalBroadcastManager getInstance(Context context) 

Source Link

Usage

From source file:christensenjohnsrud.funfit.DetectedActivitiesIntentService.java

/**
 * Handles incoming intents.//from  ww w . j  av  a 2 s.c o m
 * @param intent The Intent is provided (inside a PendingIntent) when requestActivityUpdates()
 *               is called.
 */
@Override
protected void onHandleIntent(Intent intent) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    Intent localIntent = new Intent(Constants.BROADCAST_ACTION);

    // Get the list of the probable activities associated with the current state of the
    // device. Each activity is associated with a confidence level, which is an int between
    // 0 and 100.
    ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();

    // Log each activity.
    Log.i(TAG, "activities detected");
    for (DetectedActivity da : detectedActivities) {
        Log.i(TAG, Constants.getActivityString(getApplicationContext(), da.getType()) + " " + da.getConfidence()
                + "%");
    }

    // Broadcast the list of detected activities.
    localIntent.putExtra(Constants.ACTIVITY_EXTRA, detectedActivities);
    LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
}

From source file:com.android.settings.overlay.SurveyFeatureProvider.java

/**
 * Unregisters the broadcast receiver for this activity. Should only be called once per activity
 * after a call to {@link #createAndRegisterReceiver(Activity)}.
 * @param activity The activity that was used to register the BroadcastReceiver.
 *///from   w w w . java 2  s.com
static void unregisterReceiver(Activity activity, BroadcastReceiver receiver) {
    if (activity == null) {
        throw new IllegalStateException("Cannot unregister receiver if activity is null");
    }

    LocalBroadcastManager.getInstance(activity).unregisterReceiver(receiver);
}

From source file:ca.farrelltonsolar.classic.HourLogChart.java

@Override
public void onStart() {
    super.onStart();
    if (!isReceiverRegistered) {
        LocalBroadcastManager.getInstance(HourLogChart.this.getActivity()).registerReceiver(mReadingsReceiver,
                new IntentFilter(Constants.CA_FARRELLTONSOLAR_CLASSIC_MINUTE_LOGS));
        isReceiverRegistered = true;/* w w  w.j a v  a2s. c  o  m*/
    }
    Log.d(getClass().getName(), "onStart");
}

From source file:com.android.incallui.CircularRevealActivity.java

@Override
protected void onStart() {
    super.onStart();
    if (!InCallPresenter.getInstance().isServiceBound()) {
        clearDisplay();// w  w  w  .  j a  v  a2s  .com
    }
    final IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_CLEAR_DISPLAY);
    LocalBroadcastManager.getInstance(this).registerReceiver(mClearDisplayReceiver, filter);
}

From source file:alaindc.crowdroid.CustomPhoneStateListener.java

@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
    super.onSignalStrengthsChanged(signalStrength);
    int strength = 0;
    String[] values = signalStrength.toString().split(" ");
    String wcdmaStrength = values[3];
    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    String type = RadioUtils.getNetClass(mContext);
    //if (activeNetwork != null && activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE && (type.equals("2G") || type.equals("3G") || type.equals("4G"))) {
    try {//from   w  w  w  .ja v a  2 s . c  o  m
        strength = signalStrength.getGsmSignalStrength();
        strength = (strength != 0) ? (2 * strength) - 113 : Integer.parseInt(wcdmaStrength); // GSM / UMTS(WCDMA)
    } catch (Exception e) {
        strength = 0;
        Log.d("Hack", "Big hack");
    }
    //}

    SharedPreferences sharedPref = mContext.getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPref.edit();
    editor.putString(Constants.PREF_SENSOR_ + Constants.TYPE_TEL, Integer.toString(strength));
    editor.commit();

    // Update view
    Intent senseintent = new Intent(Constants.INTENT_UPDATE_SENSORS);
    senseintent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA, "Sensor "
            + Constants.getNameOfSensor(Constants.TYPE_TEL) + " value: " + Integer.toString(strength));
    LocalBroadcastManager.getInstance(mContext).sendBroadcast(senseintent);
}

From source file:com.android.example.notificationlistener.NotificationListenerActivity.java

@Override
public void onStart() {
    super.onStart();
    final IntentFilter intentFilter = new IntentFilter(Listener.ACTION_REFRESH);
    LocalBroadcastManager.getInstance(this).registerReceiver(mRefreshListener, intentFilter);
    updateList(null);/*from   w ww  . ja  v a2  s  .  c  om*/
}

From source file:com.android.screenspeak.contextmenu.ContextMenuItemClickProcessor.java

public boolean onMenuItemClicked(MenuItem menuItem) {
    if (menuItem == null) {
        // Let the manager handle cancellations.
        return false;
    }//from   w ww. j  a v  a2 s .  co m

    final int itemId = menuItem.getItemId();
    if (itemId == R.id.read_from_top) {
        mService.getFullScreenReadController().startReadingFromBeginning();
    } else if (itemId == R.id.read_from_current) {
        mService.getFullScreenReadController().startReadingFromNextNode();
    } else if (itemId == R.id.repeat_last_utterance) {
        mService.getSpeechController().repeatLastUtterance();
    } else if (itemId == R.id.spell_last_utterance) {
        mService.getSpeechController().spellLastUtterance();
    } else if (itemId == R.id.pause_feedback) {
        mService.requestSuspendScreenSpeak();
    } else if (itemId == R.id.screenspeak_settings) {
        final Intent settingsIntent = new Intent(mService, ScreenSpeakPreferencesActivity.class);
        settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        settingsIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        mService.startActivity(settingsIntent);
    } else if (itemId == R.id.tts_settings) {
        Intent intent = new Intent();
        intent.setAction("com.android.settings.TTS_SETTINGS");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mService.startActivity(intent);
    } else {
        // The menu item was not recognized.
        return false;
    }

    // Broadcast a notification that a menu item was clicked.
    Intent intent = new Intent(ContextMenuMonitor.ACTION_CONTEXT_MENU_ITEM_CLICKED);
    intent.putExtra(ContextMenuMonitor.EXTRA_ITEM_ID, itemId);
    LocalBroadcastManager.getInstance(mService).sendBroadcast(intent);

    return true;
}

From source file:ca.farrelltonsolar.classic.NavigationDrawerFragment.java

@Override
public void onStop() {
    LocalBroadcastManager.getInstance(this.getActivity()).unregisterReceiver(updateChargeControllersReceiver);

    super.onStop();
}

From source file:anipr.stampitgo.android.Locator.java

public boolean getCurrentLocation() {
    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
    MainActivity.currentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
    if (mLastLocation != null) {
        status = true;//from  w w w  .j av  a 2s.  co m
        Intent i = new Intent();
        i.setAction("com.stampitgo.location_update");
        lat = mLastLocation.getLatitude();
        lng = mLastLocation.getLongitude();
        Bundle extras = new Bundle();
        extras.putDouble("lat", lat);
        extras.putDouble("lng", lng);
        i.putExtras(extras);

        LocalBroadcastManager.getInstance(AppController.getInstance().getApplicationContext()).sendBroadcast(i);

    } else {
        status = false;
    }
    return status;
}

From source file:asia.covisoft.goom.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
            new IntentFilter(QuickstartPreferences.REGISTRATION_COMPLETE));
}