Search in sources :

Example 1 with ResultReceiver

use of android.os.ResultReceiver in project RESTDroid by PCreations.

the class RestService method handleRESTServiceCallback.

/**
	 * Handles the binder callback fires by the Processor in {@link Processor#postRequestProcess(int, RESTRequest, java.io.InputStream)}
	 * Current intent is retrieved in {@link RestService#intentsMap} in order to send results to {@link RestResultReceiver}
	 * 
	 * @param statusCode
	 * 		The status code resulting of all process
	 * 
	 * @param r
	 * 		The actual {@link RESTRequest}
	 * 
	 * @see Processor#postRequestProcess(int, RESTRequest, java.io.InputStream)
	 * @see RestResultReceiver
	 * @see RestService#intentsMap
	 */
private void handleRESTServiceCallback(int statusCode, RESTRequest<? extends Resource> r) {
    Bundle bundle = mCurrentIntent.getExtras();
    ResultReceiver receiver = bundle.getParcelable(RestService.RECEIVER_KEY);
    //Log.e(RestService.TAG, "resource dans handleRESTServiceCallback = " + r.getResourceRepresentation().toString());
    Bundle resultData = new Bundle();
    resultData.putSerializable(RestService.REQUEST_KEY, r);
    resultData.putParcelable(RestService.INTENT_KEY, mCurrentIntent);
    receiver.send(statusCode, resultData);
}
Also used : Bundle(android.os.Bundle) ResultReceiver(android.os.ResultReceiver)

Example 2 with ResultReceiver

use of android.os.ResultReceiver in project mobile-android by photo.

the class MemePanel method beginEditText.

/**
	 * Begin edit text.
	 * 
	 * @param view
	 *           the view
	 */
private void beginEditText(final DrawableHighlightView view) {
    mLogger.info("beginEditText", view);
    EditText editText = null;
    if (view == topHv) {
        editText = editTopText;
    } else if (view == bottomHv) {
        editText = editBottomText;
    }
    if (editText != null) {
        mEditTextWatcher.view = null;
        editText.removeTextChangedListener(mEditTextWatcher);
        final EditableDrawable editable = (EditableDrawable) view.getContent();
        final String oldText = (String) editable.getText();
        editText.setText(oldText);
        editText.setSelection(editText.length());
        editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        editText.requestFocusFromTouch();
        Handler handler = new Handler();
        ResultReceiver receiver = new ResultReceiver(handler);
        if (!mInputManager.showSoftInput(editText, 0, receiver)) {
            // TODO: verify
            mInputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        }
        mEditTextWatcher.view = view;
        editText.setOnEditorActionListener(this);
        editText.addTextChangedListener(mEditTextWatcher);
        ((ImageViewDrawableOverlay) mImageView).setSelectedHighlightView(view);
        ((EditableDrawable) view.getContent()).setText(((EditableDrawable) view.getContent()).getText());
        view.forceUpdate();
    }
}
Also used : EditText(android.widget.EditText) ImageViewDrawableOverlay(com.aviary.android.feather.widget.ImageViewDrawableOverlay) EditableDrawable(com.aviary.android.feather.library.graphics.drawable.EditableDrawable) Handler(android.os.Handler) ResultReceiver(android.os.ResultReceiver)

Example 3 with ResultReceiver

use of android.os.ResultReceiver in project android-app by spark.

the class SimpleSparkApiService method processResponse.

void processResponse(Response response, Intent intent) {
    Bundle extras = intent.getExtras();
    Bundle resultBundle = new Bundle();
    int resultCode = REQUEST_FAILURE_CODE;
    String error = getString(R.string.error_communicating_with_server);
    if (response != null) {
        resultCode = response.responseCode;
        resultBundle.putString(EXTRA_API_RESPONSE_JSON, response.apiResponse);
        resultBundle.putInt(EXTRA_RESULT_CODE, resultCode);
    } else {
        resultBundle.putString(EXTRA_ERROR_MSG, error);
    }
    ResultReceiver receiver = extras.getParcelable(EXTRA_RESULT_RECEIVER);
    if (receiver != null) {
        receiver.send(resultCode, resultBundle);
    }
    String bcastAction = extras.getString(EXTRA_BROADCAST_ACTION);
    if (truthy(bcastAction)) {
        Intent responseIntent = new Intent().replaceExtras(resultBundle).setAction(bcastAction);
        localBroadcastManager.sendBroadcast(responseIntent);
    }
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) ResultReceiver(android.os.ResultReceiver)

Example 4 with ResultReceiver

use of android.os.ResultReceiver in project platform_frameworks_base by android.

the class MediaBrowser method getItem.

/**
     * Retrieves a specific {@link MediaItem} from the connected service. Not
     * all services may support this, so falling back to subscribing to the
     * parent's id should be used when unavailable.
     *
     * @param mediaId The id of the item to retrieve.
     * @param cb The callback to receive the result on.
     */
public void getItem(@NonNull final String mediaId, @NonNull final ItemCallback cb) {
    if (TextUtils.isEmpty(mediaId)) {
        throw new IllegalArgumentException("mediaId is empty.");
    }
    if (cb == null) {
        throw new IllegalArgumentException("cb is null.");
    }
    if (mState != CONNECT_STATE_CONNECTED) {
        Log.i(TAG, "Not connected, unable to retrieve the MediaItem.");
        mHandler.post(new Runnable() {

            @Override
            public void run() {
                cb.onError(mediaId);
            }
        });
        return;
    }
    ResultReceiver receiver = new ResultReceiver(mHandler) {

        @Override
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            if (resultCode != 0 || resultData == null || !resultData.containsKey(MediaBrowserService.KEY_MEDIA_ITEM)) {
                cb.onError(mediaId);
                return;
            }
            Parcelable item = resultData.getParcelable(MediaBrowserService.KEY_MEDIA_ITEM);
            if (!(item instanceof MediaItem)) {
                cb.onError(mediaId);
                return;
            }
            cb.onItemLoaded((MediaItem) item);
        }
    };
    try {
        mServiceBinder.getMediaItem(mediaId, receiver, mServiceCallbacks);
    } catch (RemoteException e) {
        Log.i(TAG, "Remote error getting media item.");
        mHandler.post(new Runnable() {

            @Override
            public void run() {
                cb.onError(mediaId);
            }
        });
    }
}
Also used : Bundle(android.os.Bundle) Parcelable(android.os.Parcelable) RemoteException(android.os.RemoteException) ResultReceiver(android.os.ResultReceiver)

Example 5 with ResultReceiver

use of android.os.ResultReceiver in project platform_frameworks_base by android.

the class Tethering method getProxyReceiver.

/**
     * Creates a proxy {@link ResultReceiver} which enables tethering if the provisioning result
     * is successful before firing back up to the wrapped receiver.
     *
     * @param type The type of tethering being enabled.
     * @param receiver A ResultReceiver which will be called back with an int resultCode.
     * @return The proxy receiver.
     */
private ResultReceiver getProxyReceiver(final int type, final ResultReceiver receiver) {
    ResultReceiver rr = new ResultReceiver(null) {

        @Override
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            // If provisioning is successful, enable tethering, otherwise just send the error.
            if (resultCode == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
                enableTetheringInternal(type, true, receiver);
            } else {
                sendTetherResult(receiver, resultCode);
            }
        }
    };
    // The following is necessary to avoid unmarshalling issues when sending the receiver
    // across processes.
    Parcel parcel = Parcel.obtain();
    rr.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    ResultReceiver receiverForSending = ResultReceiver.CREATOR.createFromParcel(parcel);
    parcel.recycle();
    return receiverForSending;
}
Also used : Bundle(android.os.Bundle) Parcel(android.os.Parcel) ResultReceiver(android.os.ResultReceiver)

Aggregations

ResultReceiver (android.os.ResultReceiver)70 Bundle (android.os.Bundle)38 RemoteException (android.os.RemoteException)11 Handler (android.os.Handler)9 HandlerThread (android.os.HandlerThread)6 OnSharedElementsReadyListener (android.app.SharedElementCallback.OnSharedElementsReadyListener)5 Intent (android.content.Intent)5 Parcel (android.os.Parcel)5 Parcelable (android.os.Parcelable)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 JSONArray (org.json.JSONArray)5 JSONException (org.json.JSONException)5 ParcelFileDescriptor (android.os.ParcelFileDescriptor)4 File (java.io.File)4 SharedPreferences (android.content.SharedPreferences)3 IOException (java.io.IOException)3 Point (android.graphics.Point)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 IResultReceiver (com.android.internal.os.IResultReceiver)2 JSONObject (org.json.JSONObject)2