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:com.android.madpausa.cardnotificationviewer.ConcreteNotificationListenerService.java

private void handleRemovedNotification(StatusBarNotification sbn) {
    //Remove notification from service
    removeServiceNotification(sbn);/*from  ww  w .  j  av a2 s.c  om*/

    //sending information about the removed notification
    Intent intent = new Intent(REMOVE_NOTIFICATION_ACTION);
    intent.putExtra(NOTIFICATION_EXTRA, sbn);
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}

From source file:com.acrr.acdisplay.services.activemode.ActiveModeService.java

@Override
public void onDestroy() {
    LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(mLocalReceiver);
    NotificationPresenter.getInstance().unregisterListener(this);
    super.onDestroy();

    // Watch for the leaks
    AppHeap.getRefWatcher().watch(this);
}

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

@Override
protected void onResume() {
    super.onResume();
    if (!isReceiverRegistered) {
        LocalBroadcastManager.getInstance(this).registerReceiver(mMonitorReceiver,
                new IntentFilter(Constants.CA_FARRELLTONSOLAR_CLASSIC_MONITOR_CHARGE_CONTROLLER));
        LocalBroadcastManager.getInstance(this).registerReceiver(mReadingsReceiver,
                new IntentFilter(Constants.CA_FARRELLTONSOLAR_CLASSIC_READINGS));
        LocalBroadcastManager.getInstance(this).registerReceiver(updateChargeControllersReceiver,
                new IntentFilter(Constants.CA_FARRELLTONSOLAR_CLASSIC_UPDATE_CHARGE_CONTROLLERS));
        LocalBroadcastManager.getInstance(this).registerReceiver(receiveAToast,
                new IntentFilter(Constants.CA_FARRELLTONSOLAR_CLASSIC_TOAST));
        isReceiverRegistered = true;//from  ww  w .  j a va  2 s  .com
    }
}

From source file:com.amazon.android.ui.fragments.LogoutSettingsFragment.java

/**
 * Adds actions to the accept logout button of the view.
 *
 * @param context  The application context.
 * @param result   The view on which the reject button exists.
 * @param fragment The fragment ot dismiss.
 *//*from   ww w. j  ava2 s.com*/
private void addActionsForAcceptLogoutButton(final Context context, View result,
        final ReadDialogFragment fragment) {

    Button acceptLogout = (Button) result.findViewById(R.id.accept_logout);
    if (acceptLogout == null) {
        return;
    }

    // Font needs to be applied since this was created dynamically.
    CalligraphyUtils.applyFontToTextView(context, acceptLogout,
            ConfigurationManager.getInstance(context).getTypefacePath(ConfigurationConstants.REGULAR_FONT));

    acceptLogout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            LocalBroadcastManager.getInstance(context)
                    .sendBroadcast(new Intent().setAction(LOGOUT_BUTTON_BROADCAST_INTENT_ACTION));
            fragment.dismiss();
        }
    });
}

From source file:alaindc.crowdroid.View.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    listGeofenceCircle = new HashMap<>();
    listCircles = new HashMap<>();

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    textView = (TextView) findViewById(R.id.textView);
    textView.setMovementMethod(new ScrollingMovementMethod());

    sensorsCheckbox = (CheckBox) findViewById(R.id.sensorscheck);
    requestsCheckbox = (CheckBox) findViewById(R.id.requestscheck);

    this.settingsButton = (Button) findViewById(R.id.settbutton);
    settingsButton.setOnClickListener(new View.OnClickListener() {
        @Override/*w w w .  j a va2 s . c om*/
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), StakeholdersActivity.class);
            startActivity(i);
        }
    });

    this.requestButton = (Button) findViewById(R.id.button);
    requestButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // TODO: Disable
            //requestButton.setEnabled(false);

            // Start sending messages to server
            Intent serviceIntent[] = new Intent[Constants.MONITORED_SENSORS.length];
            for (int i = 0; i < Constants.MONITORED_SENSORS.length; i++) {
                serviceIntent[i] = new Intent(getApplicationContext(), SendIntentService.class);
                serviceIntent[i].setAction(Constants.ACTION_SENDDATA + Constants.MONITORED_SENSORS[i]);
                serviceIntent[i].putExtra(Constants.EXTRA_TYPE_OF_SENSOR_TO_SEND,
                        Constants.MONITORED_SENSORS[i]); // TODO Here set to send all kind of sensor for start
                getApplicationContext().startService(serviceIntent[i]);

            }
        }
    });

    this.sensorButton = (Button) findViewById(R.id.buttonLoc);
    sensorButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            sensorButton.setEnabled(false);

            // Clear preferences
            getSharedPreferences(Constants.PREF_FILE, Context.MODE_PRIVATE).edit().clear().commit();

            // Start service for PhoneListener
            Intent phoneListIntent = new Intent(getApplicationContext(), NeverSleepService.class);
            getApplicationContext().startService(phoneListIntent);

            // Start intent service for update position
            Intent posintent = new Intent(getApplicationContext(), PositionIntentService.class);
            getApplicationContext().startService(posintent);

            // Start intent service for update sensors
            Intent sensorintent = new Intent(getApplicationContext(), SensorsIntentService.class);
            sensorintent.setAction(Constants.INTENT_START_SENSORS);
            getApplicationContext().startService(sensorintent);

            // Start intent service for update amplitude sensing
            Intent amplintent = new Intent(getApplicationContext(), SensorsIntentService.class);
            amplintent.setAction(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE);
            getApplicationContext().startService(amplintent);
        }
    });

    BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Constants.INTENT_RECEIVED_DATA)) {
                String response = intent.getStringExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA);
                if (response != null && requestsCheckbox.isChecked())
                    textView.append(response + "\n");
            } else if (intent.getAction().equals(Constants.INTENT_UPDATE_POS)) {
                setLocationAndMap();
            } else if (intent.getAction().equals(Constants.INTENT_UPDATE_SENSORS)) {
                String response = intent.getStringExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA);
                if (response != null && sensorsCheckbox.isChecked())
                    textView.append(response + "\n");
            } else if (intent.getAction().equals(Constants.INTENT_UPDATE_GEOFENCEVIEW)) { // Geofencing
                addGeofenceView(intent.getIntExtra(Constants.INTENT_GEOFENCEEXTRA_SENSOR, 0),
                        intent.getDoubleExtra(Constants.INTENT_GEOFENCEEXTRA_LATITUDE, 0),
                        intent.getDoubleExtra(Constants.INTENT_GEOFENCEEXTRA_LONGITUDE, 0),
                        intent.getFloatExtra(Constants.INTENT_GEOFENCEEXTRA_RADIUS, 100));
            } else {
                Log.d("", "");
            }
        }
    };

    IntentFilter rcvDataIntFilter = new IntentFilter(Constants.INTENT_RECEIVED_DATA);
    IntentFilter updatePosIntFilter = new IntentFilter(Constants.INTENT_UPDATE_POS);
    IntentFilter updateSenseIntFilter = new IntentFilter(Constants.INTENT_UPDATE_SENSORS);
    IntentFilter updateGeofenceViewIntFilter = new IntentFilter(Constants.INTENT_UPDATE_GEOFENCEVIEW);
    LocalBroadcastManager.getInstance(this).registerReceiver(receiver, rcvDataIntFilter);
    LocalBroadcastManager.getInstance(this).registerReceiver(receiver, updatePosIntFilter);
    LocalBroadcastManager.getInstance(this).registerReceiver(receiver, updateSenseIntFilter);
    LocalBroadcastManager.getInstance(this).registerReceiver(receiver, updateGeofenceViewIntFilter);

}

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

@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "registering broadcast listener");
    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ACTION_DISMISS);
    intentFilter.addAction(ACTION_LAUNCH);
    LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, intentFilter);
}

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

public static void monitorChargeController(int device) {
    if (device < 0 || device >= chargeControllers.count()) {
        return;//from  ww w .jav  a  2 s  . c  o  m
    }
    if (chargeControllers.setCurrent(device)) {
        LocalBroadcastManager broadcaster = LocalBroadcastManager.getInstance(context);
        Intent pkg = new Intent(Constants.CA_FARRELLTONSOLAR_CLASSIC_MONITOR_CHARGE_CONTROLLER);
        pkg.putExtra("DifferentController", true);
        broadcaster.sendBroadcast(pkg); //notify activity
    }
}

From source file:ch.bfh.evoting.alljoyn.MessageEncrypter.java

private void countFailedDecryption() {
    if (countDecryptionFailed) {
        //Rememeber the number of decryption failed
        numberOfDecryptionFailed++;// w ww  . ja v a2 s.c o m
        //if this number reaches 10 indicate it to the user
        if (numberOfDecryptionFailed == 5) {
            Intent intent = new Intent("probablyWrongDecryptionKeyUsed");
            intent.putExtra("type", "password");
            LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
        }
    }
}

From source file:com.android.tv.settings.about.AboutFragment.java

@Override
public void onStart() {
    super.onStart();
    refreshDeviceName();/*from  w  w  w  .j  a va 2  s.c  o m*/

    LocalBroadcastManager.getInstance(getContext()).registerReceiver(mDeviceNameReceiver,
            new IntentFilter(DeviceManager.ACTION_DEVICE_NAME_UPDATE));
}

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

@Override
public void onDestroy() {
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mBroadcastReceiver);
    super.onDestroy();
}