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:Main.java

private static void getLocalBroadcastManager(Context context) {
    mLocalBroadcastManager = LocalBroadcastManager.getInstance(context);
}

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

@Override
protected void onStop() {
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mClearDisplayReceiver);
    super.onStop();
}

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

@Override
public void onPause() {

    super.onPause();
    LocalBroadcastManager.getInstance(context).unregisterReceiver(mMessageReceiver);
}

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

@Override
public void processHttpResponse(Context context) {
    ContentResolver resolver = context.getContentResolver();

    // Delete old logins
    resolver.delete(RedditContract.Login.CONTENT_URI, null, null);

    RedditLoginResponse response = JsonDeserializer.deserialize(result.getJson(), RedditLoginResponse.class);

    if (response == null) {
        Ln.e("Error parsing Reddit login response");
        return;/*w  w  w  .  j  av a 2 s.c  om*/
    }

    // The username isn't sent back with the login response, so we have it passed
    // through from the login request
    String username = BundleUtil.getString(result.getExtraData(), RedditContract.Login.USERNAME, null);
    if (response.getLoginResponse() != null && response.getLoginResponse().getData() != null) {
        response.getLoginResponse().getData().setUsername(username);
    }

    ContentValues loginValues = response.getContentValues();
    Intent loginNotify = new Intent(Constants.Broadcast.BROADCAST_LOGIN_COMPLETE);
    loginNotify.putExtra(Constants.Extra.EXTRA_USERNAME, username);
    Integer loginSuccess = loginValues.getAsInteger(RedditContract.Login.SUCCESS);
    if (loginSuccess != null && loginSuccess == 1) {
        loginNotify.putExtra(Constants.Extra.EXTRA_SUCCESS, true);
        resolver.insert(RedditContract.Login.CONTENT_URI, loginValues);
    } else {
        loginNotify.putExtra(Constants.Extra.EXTRA_SUCCESS, false);
        loginNotify.putExtra(Constants.Extra.EXTRA_ERROR_MESSAGE,
                loginValues.getAsString(RedditContract.Login.ERROR_MESSAGE));
        loginNotify.putExtra(Constants.Extra.EXTRA_USERNAME, username);
    }

    LocalBroadcastManager.getInstance(context).sendBroadcast(loginNotify);
}

From source file:com.andresrcb.gcmtest.LoggingService.java

private void doLog(Intent intent) {
    int priority = intent.getIntExtra(EXTRA_LOG_PRIORITY, Log.INFO);
    String msg = intent.getStringExtra(EXTRA_LOG_MESSAGE);

    // Make the log available through adb logcat
    Log.println(priority, LOG_TAG, msg);

    // Add the timestamp to the message
    String timestamp = dateFormat.format(new Date());
    msg = timestamp + " " + msg;

    // Forward the log to LocalBroadcast subscribers (i.e. UI)
    Intent localIntent = new Intent(ACTION_LOG);
    localIntent.putExtra(EXTRA_LOG_MESSAGE, msg);
    LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);

    // Write log to file
    try {//  w ww  .ja v a  2 s  .c om
        FileOutputStream outputFile = openFileOutput(LOG_FILE, MODE_APPEND);
        outputFile.write(msg.getBytes());
        outputFile.write(LOG_SEPARATOR.getBytes());
        outputFile.close();
    } catch (IOException ex) {
        Log.e(LOG_TAG, "Error while writing in the log file", ex);
    }
}

From source file:com.antew.redditinpictures.ui.RedditImageListFragmentFree.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    RelativeLayout v = (RelativeLayout) super.onCreateView(inflater, container, savedInstanceState);

    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mHideAds,
            new IntentFilter(ConstsFree.REMOVE_ADS));
    /**//from w w  w.ja  v a 2  s.  co  m
     * If ads are disabled we don't need to load any
     */
    if (!SharedPreferencesHelperFree.getDisableAds(getActivity())) {
        mAdView = new AdView(getActivity(), AdSize.SMART_BANNER, ConstsFree.ADMOB_ID);

        /**
         * The AdView should be attached to the bottom of the screen, with the GridView position above it
         */
        RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        v.addView(mAdView, adParams);

        mAdView.loadAd(AdUtil.getAdRequest());
    }

    return v;
}

From source file:com.amazon.analytics.AnalyticsManager.java

/**
 * Singleton constructor./*from w  w  w . j a  va 2s . c om*/
 *
 * @param context Context.
 */
private AnalyticsManager(Context context) {

    mAppContext = context.getApplicationContext();

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ANALYTICS_INTENT_ACTION);
    LocalBroadcastManager.getInstance(mAppContext).registerReceiver(mLocalBroadcastReceiver, intentFilter);
}

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

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    View view = inflater.inflate(R.layout.dialog_static_address, null);
    builder.setView(view);//w w w  .  j  a  va 2  s .  c  o m
    EditText edAddress = (EditText) view.findViewById(R.id.ipAddress);
    edAddress.setKeyListener(IPAddressKeyListener.getInstance());

    builder.setPositiveButton(R.string.ApplyButton, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            String port = ((EditText) getDialog().findViewById(R.id.port)).getText().toString();
            String edAddress = ((EditText) getDialog().findViewById(R.id.ipAddress)).getText().toString();
            if (!port.isEmpty() && !edAddress.isEmpty()) {
                if (IPV4_PATTERN.matcher(edAddress).matches()) {
                    ChargeControllerInfo cc = new ChargeControllerInfo(edAddress, Integer.valueOf(port), true);
                    cc.setIsReachable(false);
                    LocalBroadcastManager broadcaster = LocalBroadcastManager
                            .getInstance(IPAddressDialog.this.getActivity());
                    Intent pkg = new Intent(Constants.CA_FARRELLTONSOLAR_CLASSIC_ADD_CHARGE_CONTROLLER);
                    pkg.putExtra("ChargeController", GSON.toJson(cc));
                    pkg.putExtra("ForceRefresh", true);
                    broadcaster.sendBroadcast(pkg);
                    dialog.dismiss();
                }
            }
        }
    }).setNegativeButton(R.string.CancelButton, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // User cancelled the dialog
        }
    });
    // Create the AlertDialog object and return it
    return builder.create();
}

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

@Override
public void onStart() {
    LocalBroadcastManager.getInstance(this.getActivity()).registerReceiver(updateChargeControllersReceiver,
            new IntentFilter(Constants.CA_FARRELLTONSOLAR_CLASSIC_UPDATE_CHARGE_CONTROLLERS));
    super.onStart();
}

From source file:br.ufc.quixada.dsdm.myapplicationtestemulttabs.googleGCM.MyGcmListenerService.java

/**
 * Called when message is received.//from   w  w w  . j a  v a  2  s  .c  o  m
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
    final String messageJson = data.getString("msg");

    Log.d(TAG, "From: " + from);
    Log.i(TAG, "Message: " + messageJson);

    if (from.startsWith("/topics/")) {
        // message received from some topic.
    } else {
        // normal downstream message.
    }

    // [START_EXCLUDE]
    /**
     * Production applications would usually process the message here.
     * Eg: - Syncing with server.
     *     - Store message in local database.
     *     - Update UI.
     */

    /**
     * In some cases it may be useful to show a notification indicating to the user
     * that a message was received.
     */

    if (messageJson != null) {

        Intent registrationComplete = new Intent("MENSAGENS");
        registrationComplete.putExtra("mensagem", messageJson);
        LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);

        sendNotification(messageJson);

    }
    // [END_EXCLUDE]
}