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:com.morlunk.leeroy.LeeroyAppFragment.java

/**
 * Mandatory empty constructor for the fragment manager to instantiate the
 * fragment (e.g. upon screen orientation changes).
 *///from  ww  w.  j  a v  a  2  s  .  com
public LeeroyAppFragment() {
    mUpdateReceiver = new ResultReceiver(new Handler()) {
        @Override
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            super.onReceiveResult(resultCode, resultData);
            List<LeeroyAppUpdate> updates = resultData
                    .getParcelableArrayList(LeeroyUpdateService.EXTRA_UPDATE_LIST);
            List<LeeroyApp> appsWithoutUpdates = resultData
                    .getParcelableArrayList(LeeroyUpdateService.EXTRA_NO_UPDATE_LIST);
            List<LeeroyException> errors = resultData
                    .getParcelableArrayList(LeeroyUpdateService.EXTRA_EXCEPTION_LIST);
            LeeroyAppAdapter adapter = new LeeroyAppAdapter(getActivity(), updates, appsWithoutUpdates);
            setListAdapter(adapter);
            setListShown(true);

            if (errors.size() > 0) {
                AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
                adb.setTitle(R.string.error);
                StringBuilder sb = new StringBuilder();
                for (LeeroyException e : errors) {
                    CharSequence appName = e.getApp().getApplicationInfo()
                            .loadLabel(getActivity().getPackageManager());
                    sb.append(appName).append(": ").append(e.getLocalizedMessage()).append('\n');
                }
                adb.setMessage(sb.toString());
                adb.setPositiveButton(android.R.string.ok, null);
                adb.show();
            }
        }
    };
}

From source file:li.klass.fhem.fragments.core.DeviceDetailFragment.java

@Override
public void update(boolean doUpdate) {
    hideEmptyView();/*from   w  ww  . j av  a2  s.co  m*/

    if (doUpdate)
        getActivity().sendBroadcast(new Intent(Actions.SHOW_EXECUTING_DIALOG));

    Intent intent = new Intent(Actions.GET_DEVICE_FOR_NAME);
    intent.setClass(getActivity(), RoomListIntentService.class);
    intent.putExtra(BundleExtraKeys.DO_REFRESH, doUpdate);
    intent.putExtra(BundleExtraKeys.DEVICE_NAME, deviceName);
    intent.putExtra(BundleExtraKeys.RESULT_RECEIVER, new ResultReceiver(new Handler()) {
        @Override
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            super.onReceiveResult(resultCode, resultData);

            FragmentActivity activity = getActivity();
            if (activity == null)
                return;

            activity.sendBroadcast(new Intent(Actions.DISMISS_EXECUTING_DIALOG));

            if (resultCode == ResultCodes.SUCCESS && getView() != null) {
                FhemDevice device = (FhemDevice) resultData.getSerializable(BundleExtraKeys.DEVICE);
                long lastUpdate = resultData.getLong(BundleExtraKeys.LAST_UPDATE);

                if (device == null)
                    return;

                DeviceAdapter adapter = DeviceType.getAdapterFor(device);
                if (adapter == null) {
                    return;
                }
                adapter.attach(DeviceDetailFragment.this.getActivity());
                ScrollView scrollView = (ScrollView) getView().findViewById(R.id.deviceDetailView);
                if (scrollView != null) {
                    scrollView.removeAllViews();
                    scrollView.addView(adapter.createDetailView(activity, device, lastUpdate));
                }
            }
        }
    });
    getActivity().startService(intent);
}

From source file:org.deviceconnect.android.deviceplugin.hvcc2w.setting.fragment.HVCC2WPairingFragment.java

/** Check Permission. */
private void checkPermission() {
    // WiFi scan requires location permissions.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP + 1) {
        if (PermissionChecker.checkSelfPermission(getContext(),
                Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED
                && PermissionChecker.checkSelfPermission(getContext(),
                        Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            searchWifi();//from   www  . j a va  2s.c o  m
        } else {
            PermissionRequestActivity.requestPermissions(getContext(),
                    new String[] { Manifest.permission.ACCESS_COARSE_LOCATION,
                            Manifest.permission.ACCESS_FINE_LOCATION },
                    new ResultReceiver(new Handler(Looper.getMainLooper())) {
                        @Override
                        protected void onReceiveResult(final int resultCode, final Bundle resultData) {
                            String[] retPermissions = resultData.getStringArray("EXTRA_PERMISSIONS");
                            int[] retGrantResults = resultData.getIntArray("EXTRA_GRANT_RESULTS");
                            if (retPermissions == null || retGrantResults == null) {
                                HVCC2WDialogFragment.showAlert(getActivity(), getString(R.string.hw_name),
                                        "WiFi scan aborted.", null);
                                return;
                            }
                            for (int i = 0; i < retPermissions.length; ++i) {
                                if (retGrantResults[i] == PackageManager.PERMISSION_DENIED) {
                                    HVCC2WDialogFragment.showAlert(getActivity(), getString(R.string.hw_name),
                                            "WiFi scan aborted.", null);
                                    return;
                                }
                            }
                            searchWifi();
                        }
                    });
        }
    }
}

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

private void sendCommandIntent(String command) {
    final Context context = getActivity();
    Intent intent = new Intent(Actions.EXECUTE_COMMAND);
    intent.setClass(getActivity(), SendCommandIntentService.class);
    intent.putExtra(BundleExtraKeys.COMMAND, command);
    intent.putExtra(BundleExtraKeys.RESULT_RECEIVER, new ResultReceiver(new Handler()) {
        @Override//w  ww.j a v  a2  s .  c  o  m
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            if (resultData != null && resultCode == ResultCodes.SUCCESS
                    && resultData.containsKey(BundleExtraKeys.COMMAND_RESULT)) {
                String result = resultData.getString(BundleExtraKeys.COMMAND_RESULT);
                if (result == null || result.equals("")) {
                    update(false);
                    return;
                }

                if (isEmpty(result.replaceAll("[\\r\\n]", "")))
                    return;
                new AlertDialog.Builder(context).setTitle(R.string.command_execution_result).setMessage(result)
                        .setPositiveButton(R.string.okButton, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                dialogInterface.cancel();
                                update(false);
                            }
                        }).show();
            }
        }
    });
    getActivity().startService(intent);
}

From source file:fi.ohtu.mobilityprofile.ui.fragments.SettingsFragment.java

public void setupServiceReceiver() {
    resultReceiver = new ResultReceiver(new Handler()) {
        @Override//  w w  w  . j a  v a 2 s .c o m
        public void onReceiveResult(int resultCode, Bundle resultData) {
            if (resultCode == 100) {
                gpsCheckBox.setChecked(false);
            }
        }
    };
}

From source file:org.deviceconnect.android.observer.fragment.WarningDialogFragment.java

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

    if (!mDisableFlg) {
        Intent i = new Intent();
        i.setAction(DConnectObservationService.ACTION_START);
        i.setClass(getActivity(), ObserverReceiver.class);
        i.putExtra(DConnectObservationService.PARAM_RESULT_RECEIVER, new ResultReceiver(new Handler()) {
            @Override/*from  www .ja  v a 2  s .co m*/
            protected void onReceiveResult(int resultCode, Bundle resultData) {
            }
        });
        getActivity().sendBroadcast(i);
    }
    getActivity().finish();
}

From source file:android.support.mediacompat.client.ClientBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();//from   www.j av  a 2  s. c  o m
    MediaControllerCompat controller;
    try {
        controller = new MediaControllerCompat(context,
                (MediaSessionCompat.Token) extras.getParcelable(KEY_SESSION_TOKEN));
    } catch (RemoteException ex) {
        // Do nothing.
        return;
    }
    int method = extras.getInt(KEY_METHOD_ID, 0);

    if (ACTION_CALL_MEDIA_CONTROLLER_METHOD.equals(intent.getAction()) && extras != null) {
        Bundle arguments;
        switch (method) {
        case SEND_COMMAND:
            arguments = extras.getBundle(KEY_ARGUMENT);
            controller.sendCommand(arguments.getString("command"), arguments.getBundle("extras"),
                    new ResultReceiver(null));
            break;
        case ADD_QUEUE_ITEM:
            controller.addQueueItem((MediaDescriptionCompat) extras.getParcelable(KEY_ARGUMENT));
            break;
        case ADD_QUEUE_ITEM_WITH_INDEX:
            arguments = extras.getBundle(KEY_ARGUMENT);
            controller.addQueueItem((MediaDescriptionCompat) arguments.getParcelable("description"),
                    arguments.getInt("index"));
            break;
        case REMOVE_QUEUE_ITEM:
            controller.removeQueueItem((MediaDescriptionCompat) extras.getParcelable(KEY_ARGUMENT));
            break;
        case SET_VOLUME_TO:
            controller.setVolumeTo(extras.getInt(KEY_ARGUMENT), 0);
            break;
        case ADJUST_VOLUME:
            controller.adjustVolume(extras.getInt(KEY_ARGUMENT), 0);
            break;
        }
    } else if (ACTION_CALL_TRANSPORT_CONTROLS_METHOD.equals(intent.getAction()) && extras != null) {
        TransportControls controls = controller.getTransportControls();
        Bundle arguments;
        switch (method) {
        case PLAY:
            controls.play();
            break;
        case PAUSE:
            controls.pause();
            break;
        case STOP:
            controls.stop();
            break;
        case FAST_FORWARD:
            controls.fastForward();
            break;
        case REWIND:
            controls.rewind();
            break;
        case SKIP_TO_PREVIOUS:
            controls.skipToPrevious();
            break;
        case SKIP_TO_NEXT:
            controls.skipToNext();
            break;
        case SEEK_TO:
            controls.seekTo(extras.getLong(KEY_ARGUMENT));
            break;
        case SET_RATING:
            controls.setRating((RatingCompat) extras.getParcelable(KEY_ARGUMENT));
            break;
        case PLAY_FROM_MEDIA_ID:
            arguments = extras.getBundle(KEY_ARGUMENT);
            controls.playFromMediaId(arguments.getString("mediaId"), arguments.getBundle("extras"));
            break;
        case PLAY_FROM_SEARCH:
            arguments = extras.getBundle(KEY_ARGUMENT);
            controls.playFromSearch(arguments.getString("query"), arguments.getBundle("extras"));
            break;
        case PLAY_FROM_URI:
            arguments = extras.getBundle(KEY_ARGUMENT);
            controls.playFromUri((Uri) arguments.getParcelable("uri"), arguments.getBundle("extras"));
            break;
        case SEND_CUSTOM_ACTION:
            arguments = extras.getBundle(KEY_ARGUMENT);
            controls.sendCustomAction(arguments.getString("action"), arguments.getBundle("extras"));
            break;
        case SEND_CUSTOM_ACTION_PARCELABLE:
            arguments = extras.getBundle(KEY_ARGUMENT);
            controls.sendCustomAction((PlaybackStateCompat.CustomAction) arguments.getParcelable("action"),
                    arguments.getBundle("extras"));
            break;
        case SKIP_TO_QUEUE_ITEM:
            controls.skipToQueueItem(extras.getLong(KEY_ARGUMENT));
            break;
        case PREPARE:
            controls.prepare();
            break;
        case PREPARE_FROM_MEDIA_ID:
            arguments = extras.getBundle(KEY_ARGUMENT);
            controls.prepareFromMediaId(arguments.getString("mediaId"), arguments.getBundle("extras"));
            break;
        case PREPARE_FROM_SEARCH:
            arguments = extras.getBundle(KEY_ARGUMENT);
            controls.prepareFromSearch(arguments.getString("query"), arguments.getBundle("extras"));
            break;
        case PREPARE_FROM_URI:
            arguments = extras.getBundle(KEY_ARGUMENT);
            controls.prepareFromUri((Uri) arguments.getParcelable("uri"), arguments.getBundle("extras"));
            break;
        case SET_CAPTIONING_ENABLED:
            controls.setCaptioningEnabled(extras.getBoolean(KEY_ARGUMENT));
            break;
        case SET_REPEAT_MODE:
            controls.setRepeatMode(extras.getInt(KEY_ARGUMENT));
            break;
        case SET_SHUFFLE_MODE:
            controls.setShuffleMode(extras.getInt(KEY_ARGUMENT));
            break;
        }
    }
}

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

@Override
public void update(boolean doUpdate) {
    Intent intent = new Intent(Actions.RECENT_COMMAND_LIST);
    intent.setClass(getActivity(), SendCommandIntentService.class);
    intent.putExtra(BundleExtraKeys.RESULT_RECEIVER, new ResultReceiver(new Handler()) {
        @Override// w  w w  .j  a va 2  s  . com
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            if (resultCode != ResultCodes.SUCCESS || resultData == null
                    || !resultData.containsKey(BundleExtraKeys.RECENT_COMMANDS)) {
                return;
            }

            View view = getView();
            if (view == null)
                return;

            recentCommands = resultData.getStringArrayList(BundleExtraKeys.RECENT_COMMANDS);
            recentCommandsAdapter.clear();

            // careful: addAll method is only available since API level 11 (Android 3.0)
            for (String recentCommand : recentCommands) {
                recentCommandsAdapter.add(recentCommand);
            }
            recentCommandsAdapter.notifyDataSetChanged();

            ListViewUtil.setHeightBasedOnChildren((ListView) view.findViewById(R.id.command_history));

            getActivity().sendBroadcast(new Intent(Actions.DISMISS_EXECUTING_DIALOG));
        }
    });
    getActivity().startService(intent);
}

From source file:edu.nust.distributed.downloader.ClientActivity.java

public void sendFile(View view) {

    //Only try to send file if there isn't already a transfer active
    if (!transferActive) {

        if (!connectedAndReadyToSendFile) {
            setClientFileTransferStatus("You must be connected to a server before attempting to send a file");
        }/*from  ww  w  .ja v  a 2  s  .c  o m*/
        /*
        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);
            TextView location = (TextView) (TextView) findViewById(R.id.textView);
            clientServiceIntent.putExtra("fileToSend", location.getText());
            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:edu.pdx.cs410.wifi.direct.file.transfer.ClientActivity.java

public void sendFile(View view) {

    //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");
        }//  w w w  . ja  va2s.c o  m
        /*
        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
        }
    }
}