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.actionbarsherlock.sample.demos.content.LocalServiceBroadcaster.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.local_service_broadcaster);

    // This is where we print the data we get back.
    final TextView callbackData = (TextView) findViewById(R.id.callback);

    // Put in some initial text.
    callbackData.setText("No broadcast received yet");

    // We use this to send broadcasts within our local process.
    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);

    // We are going to watch for interesting local broadcasts.
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_STARTED);/*from w  w w.  j  a  v  a  2 s.  c o m*/
    filter.addAction(ACTION_UPDATE);
    filter.addAction(ACTION_STOPPED);
    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(ACTION_STARTED)) {
                callbackData.setText("STARTED");
            } else if (intent.getAction().equals(ACTION_UPDATE)) {
                callbackData.setText("Got update: " + intent.getIntExtra("value", 0));
            } else if (intent.getAction().equals(ACTION_STOPPED)) {
                callbackData.setText("STOPPED");
            }
        }
    };
    mLocalBroadcastManager.registerReceiver(mReceiver, filter);

    // Watch for button clicks.
    Button button = (Button) findViewById(R.id.start);
    button.setOnClickListener(mStartListener);
    button = (Button) findViewById(R.id.stop);
    button.setOnClickListener(mStopListener);
}

From source file:ca.hoogit.garagepi.Controls.DoorManager.java

public void register() {
    if (!mIsRegistered) {
        LocalBroadcastManager.getInstance(mContext).registerReceiver(this,
                new IntentFilter(Consts.INTENT_MESSAGE_DOORS));
        mIsRegistered = true;//w ww  .  j a v  a2s  .c o  m
    }
}

From source file:com.anypresence.android.notifications.gcm.RegistrationIntentService.java

private void finishRegistration() {
    // Notify UI that registration has completed, so the progress indicator can be hidden.
    Intent registrationComplete = new Intent(QuickstartPreferences.GCM_REGISTRATION);
    registrationComplete.putExtra(GCMManager.EXTRA_REGISTRATION, true);
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}

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

public void broadcastLogs(Context context, String action) {
    if (isAvailable()) {
        Intent intent = new Intent(action);
        intent.putExtra("logs", this);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }//from  w  ww. ja va2 s . com
}

From source file:ac.robinson.bettertogether.api.messaging.PluginConnectionDelegate.java

public void onCreate(@SuppressWarnings("UnusedParameters") @Nullable Bundle savedInstanceState) {
    // note: savedInstanceState is passed for potential future usage; unused for now
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(PluginIntent.ACTION_STOP_PLUGIN);
    intentFilter.addAction(PluginIntent.ACTION_MESSAGE_RECEIVED);
    LocalBroadcastManager.getInstance(mContext).registerReceiver(mLocalBroadcastReceiver, intentFilter);
}

From source file:cn.edu.zafu.corepage.core.CoreConfig.java

/**
 * LocalBroadcastManager/* www.ja v a 2  s  . c om*/
 * @return LocalBroadcastManager
 */
public static LocalBroadcastManager getLocalBroadcastManager() {
    if (mLocalBroadcatManager == null) {
        mLocalBroadcatManager = LocalBroadcastManager.getInstance(mContext);
    }
    return mLocalBroadcatManager;
}

From source file:com.antew.redditinpictures.library.reddit.AboutResponse.java

@Override
public void processHttpResponse(Context context) {
    Ln.v("About Subreddit complete! = %s", result.getJson());
    About aboutSubreddit = JsonDeserializer.deserialize(result.getJson(), About.class);

    if (aboutSubreddit == null) {
        Ln.e("Something went wrong on About Subreddit status code: %d json: %s", result.getHttpStatusCode(),
                result.getJson());//from   ww  w.j a  v a  2 s  .  co m
        return;
    }

    ContentResolver resolver = context.getContentResolver();
    //TODO: Once API-11 is sunset, replace with an update instead of delete/insert.
    // Updates with parameters aren't supported prior to API-11 (Honeycomb). So instead we are just deleting the record if it exists and recreating it.
    resolver.delete(RedditContract.Subreddits.CONTENT_URI, "subredditId = ?",
            new String[] { aboutSubreddit.getData().getId() });
    Ln.v("Deleted row");
    resolver.insert(RedditContract.Subreddits.CONTENT_URI, aboutSubreddit.getContentValues());
    Ln.v("Inserted row");

    LocalBroadcastManager.getInstance(context)
            .sendBroadcast(new Intent(Constants.Broadcast.BROADCAST_ABOUT_SUBREDDIT));
}

From source file:biz.wiz.android.wallet.ui.MaybeMaintenanceFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    final WalletApplication application = ((AbstractWalletActivity) activity).getWalletApplication();
    this.wallet = application.getWallet();
    this.broadcastManager = LocalBroadcastManager.getInstance(activity);
}

From source file:at.jclehner.rxdroid.RxDroid.java

public static LocalBroadcastManager getLocalBroadcastManager() {
    return LocalBroadcastManager.getInstance(getContext());
}

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

public void broadcastReadings(Context context, String action) {
    if (!readings.isEmpty()) {
        Intent intent = new Intent(action);
        intent.putExtra("readings", readings);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    }/* www .j  av  a 2s. c  om*/
}