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:ch.bfh.evoting.alljoyn.MessageEncrypter.java

/**
 * Set the salt/*from   ww  w .j  a  v a 2  s .  c  o  m*/
 * @param salt the Base64 encoded salt
 */
public void setSalt(String salt) {

    byte[] tempSalt = Base64.decode(salt, Base64.DEFAULT);

    if (this.saltShortDigest.equals(getSaltShortDigest(tempSalt))) {
        Log.d(TAG, "received salt digest is " + saltShortDigest + " and computed digest from received salt is "
                + getSaltShortDigest(tempSalt));
        this.salt = tempSalt;
        Log.d(TAG, "Saving salt " + salt);
        this.derivateKey(password.toCharArray());
    } else {
        Intent intent = new Intent("probablyWrongDecryptionKeyUsed");
        intent.putExtra("type", "salt");
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
        Log.e(TAG, "Salt is false!");
    }

}

From source file:ch.bfh.fbi.mobicomp.geofence.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    // Register the broadcast receiver to receive status updates
    LocalBroadcastManager.getInstance(this).registerReceiver(geofenceBroadcastReceiver, geofenceIntentFilter);
    /*//  ww w.  j a  v  a 2  s  .  co  m
     * Get existing geofences from the latitude, longitude, and
     * radius values stored in SharedPreferences. If no values
     * exist, null is returned.
     */
    geofence1 = geofenceSharedPreferences.getGeofence("1");
    geofence2 = geofenceSharedPreferences.getGeofence("2");
    /*
     * If the returned geofences have values, use them to set
     * values in the UI, using the previously-defined number
     * formats.
     */
    if (geofence1 != null) {
        latitude1.setText(latLngFormat.format(geofence1.getLatitude()));
        longitude1.setText(latLngFormat.format(geofence1.getLongitude()));
        radius1.setText(radiusFormat.format(geofence1.getRadius()));
    }
    if (geofence2 != null) {
        latitude2.setText(latLngFormat.format(geofence2.getLatitude()));
        longitude2.setText(latLngFormat.format(geofence2.getLongitude()));
        radius2.setText(radiusFormat.format(geofence2.getRadius()));
    }
}

From source file:com.aimfire.gallery.service.MovieProcessor.java

private void reportError(String path, int errorCode) {
    Bundle params = new Bundle();
    params.putString("captureErrorCode", Integer.toString(errorCode));
    mFirebaseAnalytics.logEvent(MainConsts.FIREBASE_CUSTOM_EVENT_SYNC_MOVIE_CAPTURE_ERROR, params);

    Intent messageIntent = new Intent(MainConsts.MOVIE_PROCESSOR_MESSAGE);
    messageIntent.putExtra(MainConsts.EXTRA_WHAT, MainConsts.MSG_MOVIE_PROCESSOR_ERROR);
    messageIntent.putExtra(MainConsts.EXTRA_PATH, path);
    messageIntent.putExtra(MainConsts.EXTRA_MSG, true/*isMyMedia*/);
    LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);

    /*/* ww w .  ja v  a  2s.c  o m*/
     * delete the placeholder file
     */
    MediaScanner.removeItemMediaList(path);
    (new File(path)).delete();
}

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

@Override
public void onActivityPaused(Activity activity) {
    if (activity.getLocalClassName().compareTo("MonitorActivity") == 0) {
        LocalBroadcastManager.getInstance(this).unregisterReceiver(addChargeControllerReceiver);
        LocalBroadcastManager.getInstance(this).unregisterReceiver(removeChargeControllerReceiver);
    }/*from  ww  w  .  ja v a2 s. c  om*/
}

From source file:cc.softwarefactory.lokki.android.fragments.PlacesFragment.java

private RoundedImageView createAvatar(final String email) {

    int sizeInDip = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) 65,
            getResources().getDisplayMetrics());
    RoundedImageView image = new RoundedImageView(getActivity());
    image.setTag(email);/*from   w w w.  j a  va 2s .  c  om*/
    image.setCornerRadius(100f);
    image.setBorderWidth(0f);
    image.setPadding(20, 0, 0, 0);
    image.setLayoutParams(new LinearLayout.LayoutParams(sizeInDip, sizeInDip));
    image.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            MainApplication.emailBeingTracked = email;
            LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(new Intent("LOCATION-UPDATE"));
            LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(new Intent("GO-TO-MAP"));
        }
    });

    return image;
}

From source file:ca.appvelopers.mcgillmobile.ui.search.SearchActivity.java

/**
 * Searches for courses based on the given information
 *//*from www.  j  a  va  2 s  .com*/
@OnClick(R.id.search_button)
@SuppressWarnings("deprecation, NewApi")
protected void searchCourses() {
    //Subject Input
    String subject = mSubject.getText().toString().toUpperCase().trim();
    if (subject.isEmpty()) {
        Utils.toast(this, R.string.registration_error_no_faculty);
        return;
    } else if (!subject.matches("[A-Za-z]{4}")) {
        Utils.toast(this, R.string.registration_invalid_subject);
        return;
    }

    //Check that the credits are valid
    int minCredits = 0;
    try {
        minCredits = Integer.valueOf(mMinCredits.getText().toString());
    } catch (NumberFormatException ignored) {
    }

    int maxCredits = 0;
    try {
        maxCredits = Integer.valueOf(mMaxCredits.getText().toString());
    } catch (NumberFormatException ignored) {
    }

    if (maxCredits < minCredits) {
        Utils.toast(this, R.string.registration_error_credits);
        return;
    }

    //Show the user we are downloading new information
    showToolbarProgress(true);

    int startHour;
    int startMinute;
    boolean startAM;
    int endHour;
    int endMinute;
    boolean endAM;

    if (Device.isMarshmallow()) {
        startHour = mStartTime.getHour() % 12;
        startMinute = mStartTime.getMinute();
        startAM = mStartTime.getHour() < 12;
        endHour = mEndTime.getHour() % 12;
        endMinute = mEndTime.getMinute();
        endAM = mEndTime.getHour() < 12;
    } else {
        startHour = mStartTime.getCurrentHour() % 12;
        startMinute = mStartTime.getCurrentMinute();
        startAM = mStartTime.getCurrentHour() < 12;
        endHour = mEndTime.getCurrentHour() % 12;
        endMinute = mEndTime.getCurrentMinute();
        endAM = mEndTime.getCurrentHour() < 12;
    }

    //Days
    List<DayOfWeek> days = new ArrayList<>();

    if (mMonday.isChecked()) {
        days.add(DayOfWeek.MONDAY);
    }
    if (mTuesday.isChecked()) {
        days.add(DayOfWeek.TUESDAY);
    }
    if (mWednesday.isChecked()) {
        days.add(DayOfWeek.WEDNESDAY);
    }
    if (mThursday.isChecked()) {
        days.add(DayOfWeek.THURSDAY);
    }
    if (mFriday.isChecked()) {
        days.add(DayOfWeek.FRIDAY);
    }
    if (mSaturday.isChecked()) {
        days.add(DayOfWeek.SATURDAY);
    }
    if (mSunday.isChecked()) {
        days.add(DayOfWeek.SUNDAY);
    }

    List<Character> dayChars = new ArrayList<>(days.size());
    for (DayOfWeek day : days) {
        dayChars.add(DayUtils.getDayChar(day));
    }

    // Check if we can refresh
    if (!canRefresh()) {
        return;
    }

    // Execute the request
    mcGillService.search(term, subject, mNumber.getText().toString(), mTitle.getText().toString(), minCredits,
            maxCredits, startHour, startMinute, startAM ? "a" : "p", endHour, endMinute, endAM ? "a" : "p",
            dayChars).enqueue(new Callback<List<CourseResult>>() {
                @Override
                public void onResponse(Call<List<CourseResult>> call, Response<List<CourseResult>> response) {
                    showToolbarProgress(false);
                    if (response.body() != null) {
                        Intent intent = new Intent(SearchActivity.this, SearchResultsActivity.class)
                                .putExtra(Constants.TERM, term)
                                .putExtra(Constants.COURSES, (ArrayList<CourseResult>) response.body());
                        startActivity(intent);
                    }
                }

                @Override
                public void onFailure(Call<List<CourseResult>> call, Throwable t) {
                    Timber.e(t, "Error searching for courses");
                    showToolbarProgress(false);
                    //If this is a MinervaException, broadcast it
                    if (t instanceof MinervaException) {
                        LocalBroadcastManager.getInstance(SearchActivity.this)
                                .sendBroadcast(new Intent(Constants.BROADCAST_MINERVA));
                    } else {
                        DialogHelper.error(SearchActivity.this, R.string.error_other);
                    }
                }
            });
}

From source file:com.android.cts.verifier.sensors.SignificantMotionTestActivity.java

@Override
protected void activitySetUp() {
    mSensorManager = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
    mSensorSignificantMotion = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION);
    if (mSensorSignificantMotion == null) {
        throw new SensorNotSupportedException(Sensor.TYPE_SIGNIFICANT_MOTION);
    }/*from   www .  j a v a 2  s .  co  m*/

    mScreenManipulator = new SensorTestScreenManipulator(this);
    try {
        mScreenManipulator.initialize(this);
    } catch (InterruptedException e) {
    }
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    LocalBroadcastManager.getInstance(this).registerReceiver(myBroadCastReceiver,
            new IntentFilter(ACTION_ALARM));
}

From source file:com.android.managedprovisioning.DeviceOwnerProvisioningActivity.java

@Override
public void onDestroy() {
    if (DEBUG)//from www .  j ava2  s  .c  o m
        ProvisionLogger.logd("Device owner provisioning activity ONDESTROY");
    if (mServiceMessageReceiver != null) {
        LocalBroadcastManager.getInstance(this).unregisterReceiver(mServiceMessageReceiver);
        mServiceMessageReceiver = null;
    }
    super.onDestroy();
}

From source file:com.android.managedprovisioning.ProfileOwnerProvisioningActivity.java

@Override
public void onPause() {
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mServiceMessageReceiver);
    super.onPause();
}

From source file:com.android.test.gallery3d.data.DataManager.java

public void broadcastLocalDeletion() {
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(mApplication.getAndroidContext());
    Intent intent = new Intent(ACTION_DELETE_PICTURE);
    manager.sendBroadcast(intent);//from   w  w  w.j  a v  a 2 s .c  o  m
}