Search in sources :

Example 56 with ResultReceiver

use of android.os.ResultReceiver in project easy by MehdiBenmesa.

the class ModuleService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        switch(intent.getAction()) {
            case GET_MODULES_TEACHER:
                final ResultReceiver receiverTeacher = intent.getParcelableExtra(DATA_RECEIVER);
                final Bundle bundleTeacher = new Bundle();
                receiverTeacher.send(STATUS_RUNNING, Bundle.EMPTY);
                try {
                    getModulesByTeacher(new IModule() {

                        @Override
                        public void onDataRecieved(JSONArray object) {
                            bundleTeacher.putString("action", GET_MODULES_TEACHER);
                            bundleTeacher.putSerializable("result", object.toString());
                            receiverTeacher.send(STATUS_FINISHED, bundleTeacher);
                        }
                    });
                } catch (Exception e) {
                    /* Sending error message back to activity */
                    bundleTeacher.putString(Intent.EXTRA_TEXT, e.toString());
                    receiverTeacher.send(STATUS_ERROR, bundleTeacher);
                }
                break;
            case GET_MODULES_STUDENT:
                final ResultReceiver receiverStudent = intent.getParcelableExtra(DATA_RECEIVER);
                final Bundle bundleStudent = new Bundle();
                receiverStudent.send(STATUS_RUNNING, Bundle.EMPTY);
                try {
                    getModulesByStudent(new IModule() {

                        @Override
                        public void onDataRecieved(JSONArray object) {
                            bundleStudent.putString("action", GET_MODULES_STUDENT);
                            bundleStudent.putSerializable("result", object.toString());
                            receiverStudent.send(STATUS_FINISHED, bundleStudent);
                        }
                    });
                } catch (Exception e) {
                    /* Sending error message back to activity */
                    bundleStudent.putString(Intent.EXTRA_TEXT, e.toString());
                    receiverStudent.send(STATUS_ERROR, bundleStudent);
                }
                break;
            case GET_TEACHERS:
                final ResultReceiver receiverTeachers = intent.getParcelableExtra(DATA_RECEIVER);
                final Bundle bundleTeachers = new Bundle();
                receiverTeachers.send(STATUS_RUNNING, Bundle.EMPTY);
                try {
                    getModulesByStudent(new IModule() {

                        @Override
                        public void onDataRecieved(JSONArray object) {
                            bundleTeachers.putString("action", GET_TEACHERS);
                            bundleTeachers.putSerializable("result", object.toString());
                            receiverTeachers.send(STATUS_FINISHED, bundleTeachers);
                        }
                    });
                } catch (Exception e) {
                    /* Sending error message back to activity */
                    bundleTeachers.putString(Intent.EXTRA_TEXT, e.toString());
                    receiverTeachers.send(STATUS_ERROR, bundleTeachers);
                }
                break;
        }
        this.stopSelf();
    }
}
Also used : Bundle(android.os.Bundle) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ResultReceiver(android.os.ResultReceiver)

Example 57 with ResultReceiver

use of android.os.ResultReceiver in project android_frameworks_base by AOSPA.

the class Tethering method getProxyReceiver.

/**
     * Creates a proxy {@link ResultReceiver} which enables tethering if the provsioning 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)

Example 58 with ResultReceiver

use of android.os.ResultReceiver in project android_frameworks_base by AOSPA.

the class Tethering method runUiTetherProvisioningAndEnable.

private void runUiTetherProvisioningAndEnable(int type, ResultReceiver receiver) {
    ResultReceiver proxyReceiver = getProxyReceiver(type, receiver);
    sendUiTetherProvisionIntent(type, proxyReceiver);
}
Also used : ResultReceiver(android.os.ResultReceiver)

Example 59 with ResultReceiver

use of android.os.ResultReceiver in project android_frameworks_base by AOSPA.

the class Tethering method runSilentTetherProvisioningAndEnable.

private void runSilentTetherProvisioningAndEnable(int type, ResultReceiver receiver) {
    ResultReceiver proxyReceiver = getProxyReceiver(type, receiver);
    sendSilentTetherProvisionIntent(type, proxyReceiver);
}
Also used : ResultReceiver(android.os.ResultReceiver)

Example 60 with ResultReceiver

use of android.os.ResultReceiver in project android_frameworks_base by ResurrectionRemix.

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)

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