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:co.rewen.statex.StateXModule.java

private void notifyStateChanged(ArrayList<String> keys) {
    /*Intent intent = new Intent(StateX.ACTION_STATE_CHANGED);
    intent.putStringArrayListExtra(StateX.EXTRA_KEYS, keys);*/
    LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getReactApplicationContext());
    for (String key : keys) {
        Intent intent = new Intent(StateX.ACTION_STATE_CHANGED);
        Uri uri = StateX.uriForKey(key);
        intent.setData(uri);//from w ww .  j  av  a  2  s.  c  om
        broadcastManager.sendBroadcast(intent);
    }
}

From source file:cc.softwarefactory.lokki.android.utilities.ServerApi.java

public static void renamePlace(final Context context, final String placeId, final String newName)
        throws JSONException {
    Log.e(TAG, "renamePlace");
    AQuery aq = new AQuery(context);

    String userId = PreferenceUtils.getString(context, PreferenceUtils.KEY_USER_ID);
    String authorizationToken = PreferenceUtils.getString(context, PreferenceUtils.KEY_AUTH_TOKEN);
    String url = ApiUrl + "user/" + userId + "/place/" + placeId;

    String cleanName = newName.substring(0, 1).toUpperCase() + newName.substring(1).toLowerCase();

    // Get place info
    if (MainApplication.places == null) { // Read them from cache
        if (PreferenceUtils.getString(context, PreferenceUtils.KEY_PLACES).isEmpty()) {
            return;
        }//  w  w w .j av a2s . c  o  m
        MainApplication.places = new JSONObject(PreferenceUtils.getString(context, PreferenceUtils.KEY_PLACES));
    }
    JSONObject placeObj = MainApplication.places.getJSONObject(placeId);

    JSONObject JSONdata = new JSONObject().put("lat", placeObj.getString("lat"))
            .put("lon", placeObj.getString("lon")).put("rad", placeObj.getString("rad"))
            .put("img", placeObj.getString("img")).put("name", cleanName);

    AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {
        @Override
        public void callback(String url, JSONObject object, AjaxStatus status) {
            Log.e(TAG, "renamePlace result code: " + status.getCode());
            Log.e(TAG, "renamePlace result message: " + status.getMessage());
            Log.e(TAG, "renamePlace ERROR: " + status.getError());

            if (status.getError() == null) {
                Log.e(TAG, "No error, place renamed.");
                DataService.getPlaces(context);
                Intent intent = new Intent("PLACES-UPDATE");
                LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
                Toast.makeText(context, R.string.place_renamed, Toast.LENGTH_SHORT).show();
            }
        }
    };

    cb.header("authorizationtoken", authorizationToken);
    aq.put(url, JSONdata, JSONObject.class, cb);
}

From source file:com.alibaba.weex.IndexActivity.java

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

From source file:com.anjalimacwan.fragment.NoteViewFragment.java

@Override
public void onStart() {
    super.onStart();

    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(receiver, filter);
}

From source file:com.aimfire.gallery.GalleryActivity.java

/**
 * Override Activity lifecycle method.//from  w  w  w . ja  v a2 s.  com
 */
@Override
protected void onPause() {
    super.onPause();

    if (BuildConfig.DEBUG)
        if (VERBOSE)
            Log.d(TAG, "onPause: unregister local broadcast receiver");
    /*
     * de-register for intents sent by the download completion service
     */
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mDownloadMsgReceiver);

    /*
     * de-register for intents sent by the media processor service
     */
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mPhotoProcessorMsgReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mMovieProcessorMsgReceiver);
}

From source file:com.android.contacts.model.AccountTypeManager.java

private void notifyAccountsChanged() {
    ContactListFilterController.getInstance(mContext).checkFilterValidity(true);
    LocalBroadcastManager.getInstance(mContext).sendBroadcast(new Intent(BROADCAST_ACCOUNTS_CHANGED));
}

From source file:com.android.talkback.controller.GestureControllerApp.java

@Override
public void performAction(String action) {
    if (action.equals(mService.getString(R.string.shortcut_value_unassigned))) {
        // Do Nothing
    } else if (action.equals(mService.getString(R.string.shortcut_value_previous))) {
        boolean result = mCursorController.previous(true /* shouldWrap */, true /* shouldScroll */,
                true /*useInputFocusAsPivotIfEmpty*/, InputModeManager.INPUT_MODE_TOUCH);
        if (!result)
            mFeedbackController.playAuditory(R.raw.complete);
    } else if (action.equals(mService.getString(R.string.shortcut_value_next))) {
        boolean result = mCursorController.next(true /* shouldWrap */, true /* shouldScroll */,
                true /*useInputFocusAsPivotIfEmpty*/, InputModeManager.INPUT_MODE_TOUCH);
        if (!result)
            mFeedbackController.playAuditory(R.raw.complete);
    } else if (action.equals(mService.getString(R.string.shortcut_value_scroll_back))) {
        boolean result = mCursorController.less();
        if (!result)
            mFeedbackController.playAuditory(R.raw.complete);
    } else if (action.equals(mService.getString(R.string.shortcut_value_scroll_forward))) {
        boolean result = mCursorController.more();
        if (!result)
            mFeedbackController.playAuditory(R.raw.complete);
    } else if (action.equals(mService.getString(R.string.shortcut_value_first_in_screen))) {
        boolean result = mCursorController.jumpToTop(InputModeManager.INPUT_MODE_TOUCH);
        if (!result)
            mFeedbackController.playAuditory(R.raw.complete);
    } else if (action.equals(mService.getString(R.string.shortcut_value_last_in_screen))) {
        boolean result = mCursorController.jumpToBottom(InputModeManager.INPUT_MODE_TOUCH);
        if (!result)
            mFeedbackController.playAuditory(R.raw.complete);
    } else if (action.equals(mService.getString(R.string.shortcut_value_back))) {
        mService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
    } else if (action.equals(mService.getString(R.string.shortcut_value_home))) {
        mService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME);
    } else if (action.equals(mService.getString(R.string.shortcut_value_overview))) {
        mService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS);
    } else if (action.equals(mService.getString(R.string.shortcut_value_notifications))) {
        mService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS);
    } else if (action.equals(mService.getString(R.string.shortcut_value_talkback_breakout))) {
        mMenuManager.showMenu(R.menu.global_context_menu);
    } else if (action.equals(mService.getString(R.string.shortcut_value_local_breakout))) {
        mMenuManager.showMenu(R.menu.local_context_menu);
    } else if (action.equals(mService.getString(R.string.shortcut_value_show_custom_actions))) {
        mMenuManager.showMenu(R.id.custom_action_menu);
    } else if (action.equals(mService.getString(R.string.shortcut_value_previous_granularity))) {
        boolean result = mCursorController.previousGranularity();
        if (!result)
            mFeedbackController.playAuditory(R.raw.complete);
    } else if (action.equals(mService.getString(R.string.shortcut_value_next_granularity))) {
        boolean result = mCursorController.nextGranularity();
        if (!result)
            mFeedbackController.playAuditory(R.raw.complete);
    } else if (action.equals(mService.getString(R.string.shortcut_value_read_from_top))) {
        mFullScreenReadController.startReadingFromBeginning();
    } else if (action.equals(mService.getString(R.string.shortcut_value_read_from_current))) {
        mFullScreenReadController.startReadingFromNextNode();
    } else if (action.equals(mService.getString(R.string.shortcut_value_print_node_tree))) {
        TreeDebug.logNodeTree(AccessibilityServiceCompatUtils.getRootInActiveWindow(mService));
    }/*www  .  ja v  a  2s  . c o m*/

    Intent intent = new Intent(GestureActionMonitor.ACTION_GESTURE_ACTION_PERFORMED);
    intent.putExtra(GestureActionMonitor.EXTRA_SHORTCUT_GESTURE_ACTION, action);
    LocalBroadcastManager.getInstance(mService).sendBroadcast(intent);
}

From source file:com.android.screenspeak.controller.GestureControllerApp.java

@Override
public void performAction(String action) {
    if (action.equals(mService.getString(R.string.shortcut_value_unassigned))) {
        // Do Nothing
    } else if (action.equals(mService.getString(R.string.shortcut_value_previous))) {
        boolean result = mCursorController.previous(true /* shouldWrap */, true /* shouldScroll */,
                true /*useInputFocusAsPivotIfEmpty*/);
        if (!result)
            mFeedbackController.playAuditory(R.raw.complete);
    } else if (action.equals(mService.getString(R.string.shortcut_value_next))) {
        boolean result = mCursorController.next(true /* shouldWrap */, true /* shouldScroll */,
                true /*useInputFocusAsPivotIfEmpty*/);
        if (!result)
            mFeedbackController.playAuditory(R.raw.complete);
    } else if (action.equals(mService.getString(R.string.shortcut_value_scroll_back))) {
        boolean result = mCursorController.less();
        if (!result)
            mFeedbackController.playAuditory(R.raw.complete);
    } else if (action.equals(mService.getString(R.string.shortcut_value_scroll_forward))) {
        boolean result = mCursorController.more();
        if (!result)
            mFeedbackController.playAuditory(R.raw.complete);
    } else if (action.equals(mService.getString(R.string.shortcut_value_first_in_screen))) {
        boolean result = mCursorController.jumpToTop();
        if (!result)
            mFeedbackController.playAuditory(R.raw.complete);
    } else if (action.equals(mService.getString(R.string.shortcut_value_last_in_screen))) {
        boolean result = mCursorController.jumpToBottom();
        if (!result)
            mFeedbackController.playAuditory(R.raw.complete);
    } else if (action.equals(mService.getString(R.string.shortcut_value_back))) {
        mService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
    } else if (action.equals(mService.getString(R.string.shortcut_value_home))) {
        mService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME);
    } else if (action.equals(mService.getString(R.string.shortcut_value_overview))) {
        mService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS);
    } else if (action.equals(mService.getString(R.string.shortcut_value_notifications))) {
        mService.performGlobalAction(AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS);
    } else if (action.equals(mService.getString(R.string.shortcut_value_screenspeak_breakout))) {
        mMenuManager.showMenu(R.menu.global_context_menu);
    } else if (action.equals(mService.getString(R.string.shortcut_value_local_breakout))) {
        mMenuManager.showMenu(R.menu.local_context_menu);
    } else if (action.equals(mService.getString(R.string.shortcut_value_previous_granularity))) {
        boolean result = mCursorController.previousGranularity();
        if (!result)
            mFeedbackController.playAuditory(R.raw.complete);
    } else if (action.equals(mService.getString(R.string.shortcut_value_next_granularity))) {
        boolean result = mCursorController.nextGranularity();
        if (!result)
            mFeedbackController.playAuditory(R.raw.complete);
    } else if (action.equals(mService.getString(R.string.shortcut_value_read_from_top))) {
        mFullScreenReadController.startReadingFromBeginning();
    } else if (action.equals(mService.getString(R.string.shortcut_value_read_from_current))) {
        mFullScreenReadController.startReadingFromNextNode();
    } else if (action.equals(mService.getString(R.string.shortcut_value_print_node_tree))) {
        TreeDebug.logNodeTree(AccessibilityServiceCompatUtils.getRootInActiveWindow(mService));
    }/*from  w  w w . j  a v a2 s .  c  o m*/

    Intent intent = new Intent(GestureActionMonitor.ACTION_GESTURE_ACTION_PERFORMED);
    intent.putExtra(GestureActionMonitor.EXTRA_SHORTCUT_GESTURE_ACTION, action);
    LocalBroadcastManager.getInstance(mService).sendBroadcast(intent);
}

From source file:com.alibaba.weex.commons.AbsWeexActivity.java

public void unregisterBroadcastReceiver() {
    if (mBroadcastReceiver != null) {
        LocalBroadcastManager.getInstance(getApplicationContext()).unregisterReceiver(mBroadcastReceiver);
        mBroadcastReceiver = null;// w  w w.  ja v  a  2 s .c o m
    }
    setReloadListener(null);
    setRefreshListener(null);
}

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

private void BroadcastToast(String message) {
    Intent intent2 = new Intent(Constants.CA_FARRELLTONSOLAR_CLASSIC_TOAST);
    intent2.putExtra("message", message);
    LocalBroadcastManager.getInstance(context).sendBroadcast(intent2);
}