Example usage for android.os ResultReceiver ResultReceiver

List of usage examples for android.os ResultReceiver ResultReceiver

Introduction

In this page you can find the example usage for android.os ResultReceiver ResultReceiver.

Prototype

ResultReceiver(Parcel in) 

Source Link

Usage

From source file:org.deviceconnect.android.deviceplugin.host.camera.CameraOverlay.java

/**
 * Overlay?./*from  w  w  w. j  av a 2s. c  o m*/
 * @param callback Overlay????
 */
public void show(@NonNull final Callback callback) {
    Executors.newSingleThreadExecutor().submit(new Runnable() {
        @Override
        public void run() {
            try {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    final ResultReceiver cameraCapabilityCallback = new ResultReceiver(mHandler) {
                        @Override
                        protected void onReceiveResult(int resultCode, Bundle resultData) {
                            try {
                                if (resultCode == Activity.RESULT_OK) {
                                    showInternal(callback);
                                } else {
                                    callback.onFail();
                                }
                            } catch (Throwable throwable) {
                                callback.onFail();
                            }
                        }
                    };
                    final ResultReceiver overlayDrawingCapabilityCallback = new ResultReceiver(mHandler) {
                        @Override
                        protected void onReceiveResult(int resultCode, Bundle resultData) {
                            try {
                                if (resultCode == Activity.RESULT_OK) {
                                    checkCameraCapability(cameraCapabilityCallback);
                                } else {
                                    callback.onFail();
                                }
                            } catch (Throwable throwable) {
                                callback.onFail();
                            }
                        }
                    };

                    checkOverlayDrawingCapability(overlayDrawingCapabilityCallback);
                } else {
                    showInternal(callback);
                }
            } catch (final Throwable throwable) {
                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {
                        throw throwable;
                    }
                });
            }
        }
    });
}

From source file:com.dsi.ant.antplus.pluginsampler.geocache.Dialog_GeoDeviceDetails.java

/**
 * Launches the dialog to program the device.
 *//*from   w  w  w . java  2s. c  om*/
public void showProgramDevice() {
    //Show the programming dialog
    Dialog_GeoProgramDevice programDialog = new Dialog_GeoProgramDevice(geoPcc, deviceData,
            new ResultReceiver(null) {
                @Override
                protected void onReceiveResult(int resultCode, Bundle resultData) {
                    if (resultCode == 0) //Succesful programming
                    {
                        //Update our current info
                        resultData.setClassLoader(this.getClass().getClassLoader());
                        ProgrammableGeocacheDeviceData progdData = ((GeocacheDeviceData) resultData
                                .getParcelable(
                                        GeocacheDeviceData.KEY_DEFAULT_GEOCACHEDEVICEDATAKEY)).programmableData;
                        if (progdData.identificationString != null)
                            deviceData.programmableData.identificationString = progdData.identificationString;
                        if (progdData.PIN != null)
                            deviceData.programmableData.PIN = progdData.PIN;
                        if (progdData.latitude != null)
                            deviceData.programmableData.latitude = progdData.latitude;
                        if (progdData.longitude != null)
                            deviceData.programmableData.longitude = progdData.longitude;
                        if (progdData.hintString != null)
                            deviceData.programmableData.hintString = progdData.hintString;
                        if (progdData.lastVisitTimestamp != null)
                            deviceData.programmableData.lastVisitTimestamp = progdData.lastVisitTimestamp;
                        if (progdData.numberOfVisits != null)
                            deviceData.programmableData.numberOfVisits = progdData.numberOfVisits;

                        getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(getActivity(), "Programming Successful", Toast.LENGTH_SHORT)
                                        .show();
                                refreshData();
                            }
                        });
                    } else if (resultCode == -1) //Device communication failure, device was removed from list and data is now invalid, bail to scan list
                    {
                        getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(getActivity(), "Device Communication Failure, dropped from list",
                                        Toast.LENGTH_SHORT).show();
                                dismiss();
                            }
                        });
                    }
                }
            });
    programDialog.show(getFragmentManager(), "ProgramDeviceDialog");
}

From source file:com.google.android.apps.muzei.datalayer.ActivateMuzeiIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    String action = intent.getAction();
    if (TextUtils.equals(action, ACTION_MARK_NOTIFICATION_READ)) {
        preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
        return;/* ww w . ja v a 2 s  .  c o m*/
    } else if (TextUtils.equals(action, ACTION_REMOTE_INSTALL_MUZEI)) {
        Intent remoteIntent = new Intent(Intent.ACTION_VIEW).addCategory(Intent.CATEGORY_BROWSABLE)
                .setData(Uri.parse("market://details?id=" + getPackageName()));
        RemoteIntent.startRemoteActivity(this, remoteIntent, new ResultReceiver(new Handler()) {
            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
                if (resultCode == RemoteIntent.RESULT_OK) {
                    FirebaseAnalytics.getInstance(ActivateMuzeiIntentService.this)
                            .logEvent("activate_notif_install_sent", null);
                    preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
                } else {
                    Toast.makeText(ActivateMuzeiIntentService.this, R.string.activate_install_failed,
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
        return;
    }
    // else -> Open on Phone action
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).build();
    ConnectionResult connectionResult = googleApiClient.blockingConnect(30, TimeUnit.SECONDS);
    if (!connectionResult.isSuccess()) {
        Log.e(TAG, "Failed to connect to GoogleApiClient.");
        Toast.makeText(this, R.string.activate_failed, Toast.LENGTH_SHORT).show();
        return;
    }
    Set<Node> nodes = Wearable.CapabilityApi
            .getCapability(googleApiClient, "activate_muzei", CapabilityApi.FILTER_REACHABLE).await()
            .getCapability().getNodes();
    if (nodes.isEmpty()) {
        Toast.makeText(this, R.string.activate_failed, Toast.LENGTH_SHORT).show();
    } else {
        FirebaseAnalytics.getInstance(this).logEvent("activate_notif_message_sent", null);
        // Show the open on phone animation
        Intent openOnPhoneIntent = new Intent(this, ConfirmationActivity.class);
        openOnPhoneIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        openOnPhoneIntent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE,
                ConfirmationActivity.OPEN_ON_PHONE_ANIMATION);
        startActivity(openOnPhoneIntent);
        // Clear the notification
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.cancel(INSTALL_NOTIFICATION_ID);
        preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
        // Send the message to the phone to open Muzei
        for (Node node : nodes) {
            Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), "notification/open", null).await();
        }
    }
    googleApiClient.disconnect();
}

From source file:com.example.ramesh.p2pfileshare.ClientActivity.java

public void sendFile() {

    //Only try to send file if there isn't already a transfer active
    if (!transferActive) {
        if (!filePathProvided) {
            setClientFileTransferStatus("Select a file to send before pressing send");
        } else if (!connectedAndReadyToSendFile) {
            setClientFileTransferStatus("You must be connected to a server before attempting to send a file");
        }/*from w  w  w .  ja  v a2  s  .c  om*/
        /*
        else if(targetDevice == null)
        {
           setClientFileTransferStatus("Target Device network information unknown");
        }
        */
        else if (wifiInfo == null) {
            setClientFileTransferStatus("Missing Wifi P2P information");
        } else {
            //Launch client service
            clientServiceIntent = new Intent(this, ClientService.class);
            clientServiceIntent.putExtra("fileToSend", fileToSend);
            clientServiceIntent.putExtra("port", new Integer(port));
            //clientServiceIntent.putExtra("targetDevice", targetDevice);
            clientServiceIntent.putExtra("wifiInfo", wifiInfo);
            clientServiceIntent.putExtra("clientResult", new ResultReceiver(null) {
                @Override
                protected void onReceiveResult(int resultCode, final Bundle resultData) {

                    if (resultCode == port) {
                        if (resultData == null) {
                            //Client service has shut down, the transfer may or may not have been successful. Refer to message 
                            transferActive = false;
                        } else {
                            final TextView client_status_text = (TextView) findViewById(
                                    R.id.file_transfer_status);

                            client_status_text.post(new Runnable() {
                                public void run() {
                                    client_status_text.setText((String) resultData.get("message"));
                                }
                            });
                        }
                    }

                }
            });

            transferActive = true;
            startService(clientServiceIntent);

            //end
        }
    }
}

From source file:li.klass.fhem.fragments.ConnectionDetailFragment.java

private void handleSave() {
    Intent intent = new Intent();
    intent.setClass(getActivity(), ConnectionsIntentService.class);
    if (isModify) {
        intent.setAction(Actions.CONNECTION_UPDATE);
        intent.putExtra(BundleExtraKeys.CONNECTION_ID, connectionId);
    } else {/*  w w w  . j  a  va2s .co m*/
        intent.setAction(Actions.CONNECTION_CREATE);
    }

    intent.putExtra(BundleExtraKeys.CONNECTION_TYPE, connectionType.name());

    String name = getTextViewContent(R.id.connectionName);
    if (enforceNotEmpty(R.string.connectionName, name))
        return;
    intent.putExtra(BundleExtraKeys.CONNECTION_NAME, name);

    intent.putExtra(BundleExtraKeys.CONNECTION_PASSWORD, getTextViewContent(R.id.password));

    switch (connectionType) {
    case TELNET:
        if (!handleTelnetSave(intent)) {
            return;
        }
        break;

    case FHEMWEB:
        if (!handleFHEMWEBSave(intent)) {
            return;
        }
        break;
    }

    intent.putExtra(BundleExtraKeys.RESULT_RECEIVER, new ResultReceiver(new Handler()) {
        @Override
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            super.onReceiveResult(resultCode, resultData);

            if (resultCode != ResultCodes.SUCCESS) {
                Log.e(TAG, "could not save! resultCode=" + resultCode + ",resultData=" + resultData);
                return;
            }

            Intent intent = new Intent(Actions.BACK);
            getActivity().sendBroadcast(intent);
        }
    });

    getActivity().startService(intent);
}

From source file:org.opensilk.video.tv.ui.playback.PlaybackControlsFragment.java

void updateSubtitles() {
    if (mMediaController == null || mAdapter == null || mSubtitleRow == null) {
        return;//ww w  .jav a2  s .co  m
    }
    mAdapter.clear(SUBTITLE_ROW);
    final SubtitleAdapter subtitleAdapter = (SubtitleAdapter) mSubtitleRow.getAdapter();
    subtitleAdapter.clear();
    mMediaController.sendCommand(PlaybackService.CMD.GET_SPU_TRACKS, null, new ResultReceiver(mMainHandler) {
        @Override
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            switch (resultCode) {
            case 0:
                break;
            case 1: {
                if (mAdapter.indexOf(SUBTITLE_ROW) < 0) {
                    mAdapter.set(SUBTITLE_ROW, mSubtitleRow);
                }
                subtitleAdapter.add(resultData);
                break;
            }
            }
        }
    });
}

From source file:org.deviceconnect.android.deviceplugin.host.camera.CameraOverlay.java

/**
 * ??????./*from  ww  w.  j a va  2s  .  c  o m*/
 * @param resultReceiver ????
 */
@TargetApi(23)
private void checkOverlayDrawingCapability(@NonNull final ResultReceiver resultReceiver) {
    if (Settings.canDrawOverlays(mContext)) {
        resultReceiver.send(Activity.RESULT_OK, null);
    } else {
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                Uri.parse("package:" + mContext.getPackageName()));
        IntentHandlerActivity.startActivityForResult(mContext, intent, new ResultReceiver(mHandler) {
            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
                if (Settings.canDrawOverlays(mContext)) {
                    resultReceiver.send(Activity.RESULT_OK, null);
                } else {
                    resultReceiver.send(Activity.RESULT_CANCELED, null);
                }
            }
        });
    }
}

From source file:androidx.media.MediaController2.java

private void connectToSession(MediaSessionCompat.Token sessionCompatToken) {
    MediaControllerCompat controllerCompat = null;
    try {/*from   ww w.j a va  2 s.  c om*/
        controllerCompat = new MediaControllerCompat(mContext, sessionCompatToken);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    synchronized (mLock) {
        mControllerCompat = controllerCompat;
        mControllerCompatCallback = new ControllerCompatCallback();
        mControllerCompat.registerCallback(mControllerCompatCallback, mHandler);
    }

    if (controllerCompat.isSessionReady()) {
        sendCommand(CONTROLLER_COMMAND_CONNECT, new ResultReceiver(mHandler) {
            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
                if (!mHandlerThread.isAlive()) {
                    return;
                }
                switch (resultCode) {
                case CONNECT_RESULT_CONNECTED:
                    onConnectedNotLocked(resultData);
                    break;
                case CONNECT_RESULT_DISCONNECTED:
                    mCallback.onDisconnected(MediaController2.this);
                    close();
                    break;
                }
            }
        });
    }
}