Example usage for android.content Intent getDoubleExtra

List of usage examples for android.content Intent getDoubleExtra

Introduction

In this page you can find the example usage for android.content Intent getDoubleExtra.

Prototype

public double getDoubleExtra(String name, double defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:org.egov.android.view.activity.CreateComplaintActivity.java

/**
 * Event triggered when an action is completed in another activity(request from this activity)).
 * We have checked the request code value If the request code value is equal to the
 * CAPTURE_IMAGE value and RESULT_OK then _validateImageUrl will be called. If the request code
 * value is equal to the FROM_GALLERY then uri of the selected image file from gallery is stored
 * to the variable selectedImage and the selected image is accessed through the ContentProvider
 * object.The ContentResolver object communicates with the ContentProvider object and the result
 * is sent to the cursor object,the cursor object contains the imagepath. _createImageFile() is
 * called to store the selected gallery image to the complaint photos directory on the storage
 * device.If the request code value is equal to the GET_LOCATION then latitude,longitude are
 * retrieved from the map activity then the location is displayed to the create complaint
 * layout.//from   w ww .j  a v  a2  s . com
 */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == CAPTURE_IMAGE && resultCode == RESULT_OK) {
        compressImage(currentPhotoPath, currentPhotoPath);
        _validateImageUrl(currentPhotoPath);
    } else if (requestCode == FROM_GALLERY && data != null) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String imagePath = cursor.getString(columnIndex);
        cursor.close();
        _createImageFile(imagePath);
    } else if (requestCode == GET_LOCATION && data != null) {
        String city_name = data.getStringExtra("city_name");
        latitude = data.getDoubleExtra("latitude", 0);
        longitute = data.getDoubleExtra("longitute", 0);
        location.setText(city_name);
    }
}

From source file:org.odk.collect.android.activities.GeoPointMapActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    if (savedInstanceState != null) {
        mLocationCount = savedInstanceState.getInt(LOCATION_COUNT);
    }//ww  w. j  ava 2s .com

    try {
        setContentView(R.layout.geopoint_layout);
    } catch (NoClassDefFoundError e) {
        e.printStackTrace();
        Toast.makeText(getBaseContext(), getString(R.string.google_play_services_error_occured),
                Toast.LENGTH_SHORT).show();
        finish();
        return;
    }

    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    if (mMap == null) {
        Toast.makeText(getBaseContext(), getString(R.string.google_play_services_error_occured),
                Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
    mMap.setMyLocationEnabled(true);
    mMap.getUiSettings().setCompassEnabled(true);
    mMap.getUiSettings().setMyLocationButtonEnabled(false);
    mMap.getUiSettings().setZoomControlsEnabled(false);
    mMarkerOption = new MarkerOptions();
    mHelper = new MapHelper(this, mMap);

    mLocationAccuracy = GeoPointWidget.DEFAULT_LOCATION_ACCURACY;

    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mLocationStatus = (TextView) findViewById(R.id.location_status);
    mlocationInfo = (TextView) findViewById(R.id.location_info);

    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    mAcceptLocation = (Button) findViewById(R.id.accept_location);

    mAcceptLocation.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "acceptLocation", "OK");
            returnLocation();
        }
    });

    mReloadLocation = (Button) findViewById(R.id.reload_location);
    mReloadLocation.setEnabled(false);
    mReloadLocation.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mMarker != null) {
                mMarker.remove();
            }
            mLatLng = null;
            mMarker = null;
            setClear = false;
            mLatLng = new LatLng(mLocation.getLatitude(), mLocation.getLongitude());
            mMarkerOption.position(mLatLng);
            if (mMarker == null) {
                mMarker = mMap.addMarker(mMarkerOption);
                if (draggable && !read_only) {
                    mMarker.setDraggable(true);
                }
            }
            mCaptureLocation = true;
            mIsDragged = false;
            zoomToPoint();
        }

    });

    // Focuses on marked location
    mShowLocation = ((Button) findViewById(R.id.show_location));
    //      mShowLocation.setClickable(false);
    mShowLocation.setEnabled(false);
    mShowLocation.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showZoomDialog();
        }
    });

    // Menu Layer Toggle
    mLayers = ((Button) findViewById(R.id.layer_menu));
    mLayers.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mHelper.showLayersDialog();
        }
    });
    zoomDialogView = getLayoutInflater().inflate(R.layout.geopoint_zoom_dialog, null);
    zoomLocationButton = (Button) zoomDialogView.findViewById(R.id.zoom_location);
    zoomLocationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            zoomToLocation();
            zoomDialog.dismiss();
        }
    });

    zoomPointButton = (Button) zoomDialogView.findViewById(R.id.zoom_point);
    zoomPointButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            zoomToPoint();
            zoomDialog.dismiss();
        }
    });

    clearPointButton = (Button) findViewById(R.id.clear);
    clearPointButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mMarker != null) {
                mMarker.remove();
            }
            if (mLocation != null) {
                mReloadLocation.setEnabled(true);
                //               mLocationStatus.setVisibility(View.VISIBLE);
            }
            //            mReloadLocation.setEnabled(true);
            mlocationInfo.setVisibility(View.VISIBLE);
            mLocationStatus.setVisibility(View.VISIBLE);
            mLatLng = null;
            mMarker = null;
            setClear = true;
            mIsDragged = false;
            mCaptureLocation = false;
            draggable = intent_draggable;
            location_from_intent = false;
            overlayMyLocationLayers();
        }
    });

    Intent intent = getIntent();
    if (intent != null && intent.getExtras() != null) {
        if (intent.hasExtra(GeoPointWidget.DRAGGABLE_ONLY)) {
            draggable = intent.getBooleanExtra(GeoPointWidget.DRAGGABLE_ONLY, false);
            intent_draggable = draggable;
            if (!intent_draggable) {
                // Not Draggable, set text for Map else leave as placement-map text
                mlocationInfo.setText(getString(R.string.geopoint_no_draggable_instruction));
            }
        }

        if (intent.hasExtra(GeoPointWidget.READ_ONLY)) {
            read_only = intent.getBooleanExtra(GeoPointWidget.READ_ONLY, false);
            if (read_only) {
                mCaptureLocation = true;
                clearPointButton.setEnabled(false);
            }
        }

        if (intent.hasExtra(GeoPointWidget.LOCATION)) {
            double[] location = intent.getDoubleArrayExtra(GeoPointWidget.LOCATION);
            mLatLng = new LatLng(location[0], location[1]);
            mCaptureLocation = true;
            mReloadLocation.setEnabled(false);
            draggable = false; // If data loaded, must clear first
            location_from_intent = true;

        }
        if (intent.hasExtra(GeoPointWidget.ACCURACY_THRESHOLD)) {
            mLocationAccuracy = intent.getDoubleExtra(GeoPointWidget.ACCURACY_THRESHOLD,
                    GeoPointWidget.DEFAULT_LOCATION_ACCURACY);
        }

    }

    /*Zoom only if there's a previous location*/
    if (mLatLng != null) {
        mlocationInfo.setVisibility(View.GONE);
        mLocationStatus.setVisibility(View.GONE);
        mShowLocation.setEnabled(true);
        mMarkerOption.position(mLatLng);
        mMarker = mMap.addMarker(mMarkerOption);
        mCaptureLocation = true;
        foundFirstLocation = true;
        mZoomed = true;
        zoomToPoint();
    }
}

From source file:org.odk.collect.android.activities.GeoPointOsmMapActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    if (savedInstanceState != null) {
        mLocationCount = savedInstanceState.getInt(LOCATION_COUNT);
    }/*from   w  ww . j av a  2s .c o m*/

    try {
        setContentView(R.layout.geopoint_osm_layout);
    } catch (NoClassDefFoundError e) {
        e.printStackTrace();
        Toast.makeText(getBaseContext(), getString(R.string.google_play_services_error_occured),
                Toast.LENGTH_SHORT).show();
        finish();
        return;
    }

    mMap = (MapView) findViewById(R.id.omap);
    mHelper = new MapHelper(this, mMap, GeoPointOsmMapActivity.this);
    mMap.setMultiTouchControls(true);
    mMap.setBuiltInZoomControls(true);
    mMarker = new Marker(mMap);
    mMarker.setIcon(getResources().getDrawable(R.drawable.ic_place_black_36dp));
    mMyLocationOverlay = new MyLocationNewOverlay(this, mMap);

    handler.postDelayed(new Runnable() {
        public void run() {
            GeoPoint point = new GeoPoint(34.08145, -39.85007);
            mMap.getController().setZoom(4);
            mMap.getController().setCenter(point);
        }
    }, 100);

    mLocationAccuracy = GeoPointWidget.DEFAULT_LOCATION_ACCURACY;
    mLocationStatus = (TextView) findViewById(R.id.location_status);
    mlocationInfo = (TextView) findViewById(R.id.location_info);

    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    mSaveLocationButton = (Button) findViewById(R.id.accept_location);
    mSaveLocationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "acceptLocation", "OK");
            returnLocation();
        }
    });

    mReloadLocationButton = (Button) findViewById(R.id.reload_location);
    mReloadLocationButton.setEnabled(false);
    mReloadLocationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mMap.getOverlays().add(mMarker);
            setClear = false;
            mLatLng = new GeoPoint(mLocation.getLatitude(), mLocation.getLongitude());
            mMarker.setPosition(mLatLng);
            mCaptureLocation = true;
            mIsDragged = false;
            zoomToPoint();
        }

    });

    // Focuses on marked location
    mShowLocationButton = ((Button) findViewById(R.id.show_location));
    mShowLocationButton.setVisibility(View.VISIBLE);
    mShowLocationButton.setEnabled(false);
    mShowLocationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "showLocation", "onClick");
            showZoomDialog();
        }
    });

    // not clickable until we have a marker set....
    mShowLocationButton.setClickable(false);

    // Menu Layer Toggle
    mLayersButton = ((Button) findViewById(R.id.layer_menu));
    mLayersButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mHelper.showLayersDialog();

        }
    });

    zoomDialogView = getLayoutInflater().inflate(R.layout.geopoint_zoom_dialog, null);

    zoomLocationButton = (Button) zoomDialogView.findViewById(R.id.zoom_location);
    zoomLocationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            zoomToLocation();
            mMap.invalidate();
            zoomDialog.dismiss();
        }
    });

    zoomPointButton = (Button) zoomDialogView.findViewById(R.id.zoom_point);
    zoomPointButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            zoomToPoint();
            mMap.invalidate();
            zoomDialog.dismiss();
        }
    });

    clearPointButton = (Button) findViewById(R.id.clear);
    clearPointButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mMap.getOverlays().remove(mMarker);
            mMarker.remove(mMap);
            if (mLocation != null) {
                mReloadLocationButton.setEnabled(true);
                //               mLocationStatus.setVisibility(View.VISIBLE);
            }
            mLocationStatus.setVisibility(View.VISIBLE);
            mMap.getOverlays().remove(mMarker);
            mMarker.remove(mMap);
            setClear = true;
            mIsDragged = false;
            mCaptureLocation = false;
            draggable = intent_draggable;
            location_from_intent = false;
            overlayMyLocationLayers();
            mMap.invalidate();
        }
    });

    Intent intent = getIntent();
    if (intent != null && intent.getExtras() != null) {

        if (intent.hasExtra(GeoPointWidget.DRAGGABLE_ONLY)) {
            draggable = intent.getBooleanExtra(GeoPointWidget.DRAGGABLE_ONLY, false);
            intent_draggable = draggable;
            if (!intent_draggable) {
                // Not Draggable, set text for Map else leave as placement-map text
                mlocationInfo.setText(getString(R.string.geopoint_no_draggable_instruction));
            }
        }

        if (intent.hasExtra(GeoPointWidget.READ_ONLY)) {
            read_only = intent.getBooleanExtra(GeoPointWidget.READ_ONLY, false);
            if (read_only) {
                mCaptureLocation = true;
                clearPointButton.setEnabled(false);
            }
        }

        if (intent.hasExtra(GeoPointWidget.LOCATION)) {
            double[] location = intent.getDoubleArrayExtra(GeoPointWidget.LOCATION);
            mLatLng = new GeoPoint(location[0], location[1]);
            mReloadLocationButton.setEnabled(false);
            mCaptureLocation = true;
            mIsDragged = true;
            draggable = false; // If data loaded, must clear first
            location_from_intent = true;

        }
        if (intent.hasExtra(GeoPointWidget.ACCURACY_THRESHOLD)) {
            mLocationAccuracy = intent.getDoubleExtra(GeoPointWidget.ACCURACY_THRESHOLD,
                    GeoPointWidget.DEFAULT_LOCATION_ACCURACY);
        }

    }

    if (mLatLng != null) {
        mMarker.setPosition(mLatLng);
        mMap.getOverlays().add(mMarker);
        mMap.invalidate();
        mCaptureLocation = true;
        foundFirstLocation = true;
        mZoomed = true;
        zoomToPoint();
    }

}

From source file:org.wheelmap.android.fragment.POIDetailEditableFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE_LOGIN) {
        if (resultCode != Activity.RESULT_OK) {
            getActivity().onBackPressed();
        }/*from  w  w w  .  j  a v a  2 s .  c  o  m*/
    }

    if (requestCode == Request.SELECT_WHEELCHAIRSTATE && resultCode == Activity.RESULT_OK && data != null) {

        if (data.hasExtra(WheelchairAccessibilityStateFragment.TAG)) {
            WheelchairFilterState state = WheelchairFilterState
                    .valueOf(data.getIntExtra(WheelchairAccessibilityStateFragment.TAG, Extra.UNKNOWN));
            if (state != null && mListener != null) {
                setWheelchairState(state);
                mListener.onEditWheelchairState(state);
            }
        } else if (data.hasExtra(WheelchairToiletStateFragment.TAG)) {
            WheelchairFilterState state = WheelchairFilterState
                    .valueOf(data.getIntExtra(WheelchairToiletStateFragment.TAG, Extra.UNKNOWN));
            if (state != null && mListener != null) {
                setWheelchairToiletState(state);
                mListener.onEditWheelchairToiletState(state);
            }
        }
    }

    if (requestCode == Request.SELECT_GEOLOCATION && resultCode == Activity.RESULT_OK && data != null) {
        double latitude = data.getDoubleExtra(Extra.LATITUDE, mLatitude);
        double longitude = data.getDoubleExtra(Extra.LONGITUDE, mLongitude);
        setGeolocation(latitude, longitude);
        if (mListener != null) {
            mListener.onEditGeolocation(latitude, longitude);
        }
    }

    if (requestCode == Request.SELECT_NODETYPE && resultCode == Activity.RESULT_OK && data != null) {
        int nodeType = data.getIntExtra(Extra.NODETYPE, mNodeType);
        setNodetype(nodeType);
        if (mListener != null) {
            mListener.onEditNodetype(nodeType);
        }
    }
}

From source file:alaindc.crowdroid.SensorsIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (action.equals(Constants.INTENT_START_SENSORS)) {

            // Init throughput taken
            SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE,
                    Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putBoolean(Constants.THROUGHPUT_TAKEN, false);
            editor.commit();/*  www  .j  ava2 s . c o m*/

            // Configure sensors and eventlistener
            mSensorManager = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
            List<Sensor> sensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
            for (Sensor sensor : sensorList) {
                if (Constants.isInMonitoredSensors(sensor.getType()))
                    mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
            }

            // TODO STUB: Comment this in release
            for (int type : Constants.STUBBED_MONITORED_SENSORS) {
                stub_onSensorChanged(type);
            }

        }

        if (action.equals(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE)) {
            // Configure amplitude and start TEST
            amplitudeTask = new GetAmplitudeTask(this);
            amplitudeTask.getData();
        }

        if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_AMBIENT_TEMPERATURE)) {
            stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1));
        }

        if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_PRESSURE)) {
            stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1));
        }

        if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_RELATIVE_HUMIDITY)) {
            stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1));
        }

        if (action.equals(Constants.INTENT_RECEIVED_AMPLITUDE)) {
            double amplitude = intent.getDoubleExtra(Constants.EXTRA_AMPLITUDE, -1);

            if (amplitude > 0) {
                SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE,
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putString(Constants.PREF_SENSOR_ + Constants.TYPE_AMPLITUDE, Double.toString(amplitude));
                editor.commit();

                // Update view
                Intent senseintent = new Intent(Constants.INTENT_UPDATE_SENSORS);
                senseintent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA,
                        "Sensor " + Constants.getNameOfSensor(Constants.TYPE_AMPLITUDE) + " value: "
                                + Double.toString(amplitude));
                LocalBroadcastManager.getInstance(this).sendBroadcast(senseintent);
            }

            int index = Constants.getIndexAlarmForSensor(Constants.TYPE_AMPLITUDE);

            // Set the alarms for next sensing of amplitude
            alarmMgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
            Intent intentAlarm = new Intent(getApplicationContext(), SensorsIntentService.class);
            intentAlarm.setAction(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE);
            alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intentAlarm, 0);

            // TIMEOUT for another monitoring of audio
            int seconds = 30; // TODO: De-hardcode this
            alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + seconds * 1000,
                    alarmIntent);

        }
    }
}

From source file:hr.foicore.varazdinlandmarksdemo.POIMapActivity.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == 0) { // qr code scanner
        if (resultCode == RESULT_OK) {
            String contents = data.getStringExtra("SCAN_RESULT");
            // String format = data.getStringExtra("SCAN_RESULT_FORMAT");

            // Toast.makeText( POIMapActivity.this, contents,
            // Toast.LENGTH_LONG).show();

            POIAdapter POIa = new POIAdapter(POIMapActivity.this);
            POIa.openToWrite();//from  w ww  .j a v  a 2s.  co  m
            int returnedId = POIa.checkQRCode(contents);
            POIa.close();

            if (returnedId != -1) {
                Toast.makeText(POIMapActivity.this,
                        POIMapActivity.this.getResources().getString(R.string.content_unlocked),
                        Toast.LENGTH_LONG).show();

                if (mActionPlay) {
                    gmm.addPlayMarkers(POIMapActivity.this);
                } else {
                    gmm.addAllMarkers(POIMapActivity.this);
                }

                Intent i = new Intent(POIMapActivity.this, POIDetailsActivity.class);
                i.putExtra("poiId", returnedId);
                startActivity(i);
            } else {
                Toast.makeText(POIMapActivity.this,
                        POIMapActivity.this.getResources().getString(R.string.qr_code_incorrect),
                        Toast.LENGTH_LONG).show();
            }

            // Handle successful scan
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }

    if (requestCode == 1) {

        if (resultCode == RESULT_OK) {
            String type = data.getStringExtra("type");
            mLatitude = data.getDoubleExtra("latitude", 46.307506);
            mLongitude = data.getDoubleExtra("longitude", 16.33829);
            if (type.equalsIgnoreCase("location")) {

                mAnimateCameraToMarker = true;
            } else if (type.equalsIgnoreCase("directions")) {

                mCalculateDirections = true;

            } else if (type.equalsIgnoreCase("play")) {
                mStartGame = true;
            }

        }
        if (resultCode == RESULT_CANCELED) {
            // code if there's no result
        }
    }
}

From source file:com.ysls.imhere.ChatActivity.java

/**
 * /*from   w w  w .j a v  a2 s  .c o  m*/
 */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_CODE_EXIT_GROUP) {
        setResult(RESULT_OK);
        finish();
        return;
    }
    if (requestCode == REQUEST_CODE_CONTEXT_MENU) {
        switch (resultCode) {
        case RESULT_CODE_COPY: // ??
            EMMessage copyMsg = ((EMMessage) adapter.getItem(data.getIntExtra("position", -1)));
            if (copyMsg.getType() == EMMessage.Type.IMAGE) {
                ImageMessageBody imageBody = (ImageMessageBody) copyMsg.getBody();
                // ???
                clipboard.setText(COPY_IMAGE + imageBody.getLocalUrl());
            } else {
                // clipboard.setText(SmileUtils.getSmiledText(ChatActivity.this,
                // ((TextMessageBody) copyMsg.getBody()).getMessage()));
                clipboard.setText(((TextMessageBody) copyMsg.getBody()).getMessage());
            }
            break;
        case RESULT_CODE_DELETE: // ?
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            conversation.removeMessage(deleteMsg.getMsgId());
            adapter.refresh();
            listView.setSelection(data.getIntExtra("position", adapter.getCount()) - 1);
            break;

        case RESULT_CODE_FORWARD: // ??
            EMMessage forwardMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", 0));
            Intent intent = new Intent(this, ForwardMessageActivity.class);
            intent.putExtra("forward_msg_id", forwardMsg.getMsgId());
            startActivity(intent);

            break;

        default:
            break;
        }
    }
    if (resultCode == RESULT_OK) { // ?
        if (requestCode == REQUEST_CODE_EMPTY_HISTORY) {
            // ?
            EMChatManager.getInstance().clearConversation(toChatUsername);
            adapter.refresh();
        } else if (requestCode == REQUEST_CODE_CAMERA) { // ??
            if (cameraFile != null && cameraFile.exists())
                sendPicture(cameraFile.getAbsolutePath());
        } else if (requestCode == REQUEST_CODE_LOCAL) { // ??
            if (data != null) {
                Uri selectedImage = data.getData();
                if (selectedImage != null)
                    sendPicByUri(selectedImage);
            }
        } else if (requestCode == REQUEST_CODE_MAP) { // 
            double latitude = data.getDoubleExtra("latitude", 0);
            double longitude = data.getDoubleExtra("longitude", 0);
            String locationAddress = data.getStringExtra("address");
            if (locationAddress != null && !locationAddress.equals("")) {
                more(more);
                sendLocationMsg(latitude, longitude, "", locationAddress);
            } else {
                Toast.makeText(this, "????", 0).show();
            }
            // ???
        } else if (requestCode == REQUEST_CODE_TEXT) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_VOICE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_PICTURE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_LOCATION) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) {
            // 
            if (!TextUtils.isEmpty(clipboard.getText())) {
                String pasteText = clipboard.getText().toString();
                if (pasteText.startsWith(COPY_IMAGE)) {
                    // ??path
                    sendPicture(pasteText.replace(COPY_IMAGE, ""));
                }

            }
        } else if (conversation.getMsgCount() > 0) {
            adapter.refresh();
            setResult(RESULT_OK);
        } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) {
            EMChatManager.getInstance().getConversation(toChatUsername);
            adapter.refresh();
        }
    }
}

From source file:com.kaixin.android.activity.ChatActivity.java

/**
 * // w w w .  ja v  a2s  .c  o  m
 */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_CODE_EXIT_GROUP) {
        setResult(RESULT_OK);
        finish();
        return;
    }
    if (requestCode == REQUEST_CODE_CONTEXT_MENU) {
        switch (resultCode) {
        case RESULT_CODE_COPY: // ??
            EMMessage copyMsg = ((EMMessage) adapter.getItem(data.getIntExtra("position", -1)));
            if (copyMsg.getType() == EMMessage.Type.IMAGE) {
                ImageMessageBody imageBody = (ImageMessageBody) copyMsg.getBody();
                // ???
                clipboard.setText(COPY_IMAGE + imageBody.getLocalUrl());
            } else {
                // clipboard.setText(SmileUtils.getSmiledText(ChatActivity.this,
                // ((TextMessageBody) copyMsg.getBody()).getMessage()));
                clipboard.setText(((TextMessageBody) copyMsg.getBody()).getMessage());
            }
            break;
        case RESULT_CODE_DELETE: // ?
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            conversation.removeMessage(deleteMsg.getMsgId());
            adapter.notifyDataSetChanged();
            listView.setSelection(data.getIntExtra("position", adapter.getCount()) - 1);
            break;

        /*case RESULT_CODE_FORWARD: // ??
           EMMessage forwardMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", 0));
           Intent intent = new Intent(this, ForwardMessageActivity.class);
           intent.putExtra("forward_msg_id", forwardMsg.getMsgId());
           startActivity(intent);
                
           break;*/

        default:
            break;
        }
    }
    if (resultCode == RESULT_OK) { // ?
        if (requestCode == REQUEST_CODE_EMPTY_HISTORY) {
            // ?
            EMChatManager.getInstance().clearConversation(toChatUsername);
            adapter.notifyDataSetChanged();
        } else if (requestCode == REQUEST_CODE_CAMERA) { // ??
            if (cameraFile != null && cameraFile.exists())
                sendPicture(cameraFile.getAbsolutePath());
        } else if (requestCode == REQUEST_CODE_LOCAL) { // ??
            if (data != null) {
                Uri selectedImage = data.getData();
                if (selectedImage != null)
                    sendPicByUri(selectedImage);
            }
        } else if (requestCode == REQUEST_CODE_MAP) { // 
            double latitude = data.getDoubleExtra("latitude", 0);
            double longitude = data.getDoubleExtra("longitude", 0);
            String locationAddress = data.getStringExtra("address");
            if (locationAddress != null && !locationAddress.equals("")) {
                more(more);
                sendLocationMsg(latitude, longitude, "", locationAddress);
            } else {
                Toast.makeText(this, "????", 0).show();
            }
            // ???
        } else if (requestCode == REQUEST_CODE_TEXT) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_VOICE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_PICTURE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_LOCATION) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) {
            // 
            if (!TextUtils.isEmpty(clipboard.getText())) {
                String pasteText = clipboard.getText().toString();
                if (pasteText.startsWith(COPY_IMAGE)) {
                    // ??path
                    sendPicture(pasteText.replace(COPY_IMAGE, ""));
                }

            }
        } else if (conversation.getMsgCount() > 0) {
            adapter.notifyDataSetChanged();
            setResult(RESULT_OK);
        } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) {
            EMChatManager.getInstance().getConversation(toChatUsername);
            adapter.notifyDataSetChanged();
        }
    }
}

From source file:com.xxjwd.chat.ChatActivity.java

 /**
 * onActivityResult/*from w  ww  . j  a v  a  2 s . c  o  m*/
 */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   if (resultCode == RESULT_CODE_EXIT_GROUP) {
      setResult(RESULT_OK);
      finish();
      return;
   }
   if (requestCode == REQUEST_CODE_CONTEXT_MENU) {
      switch (resultCode) {
      case RESULT_CODE_COPY: // ??
         ChatMessage copyMsg = ((ChatMessage) adapter.getItem(data.getIntExtra("position", -1)));
         // clipboard.setText(SmileUtils.getSmiledText(ChatActivity.this,
         // ((TextMessageBody) copyMsg.getBody()).getMessage()));
         clipboard.setText(((TextMessageBody) copyMsg.getBody()).getMessage());
         break;
      case RESULT_CODE_DELETE: // ?
         ChatMessage deleteMsg = (ChatMessage) adapter.getItem(data.getIntExtra("position", -1));
         conversation.removeMessage(deleteMsg.getMsgId());
         adapter.refresh();
         listView.setSelection(data.getIntExtra("position", adapter.getCount()) - 1);
         break;

      case RESULT_CODE_FORWARD: // ??
         ChatMessage forwardMsg = (ChatMessage) adapter.getItem(data.getIntExtra("position", 0));
         Intent intent = new Intent(this, ForwardMessageActivity.class);
         intent.putExtra("forward_msg_id", forwardMsg.getMsgId());
         startActivity(intent);

         break;

      default:
         break;
      }
   }
   if (resultCode == RESULT_OK) { // ?
      if (requestCode == REQUEST_CODE_EMPTY_HISTORY) {
         // ?
         ChatManager.getInstance().clearConversation(toChatUsername);
         adapter.refresh();
      } else if (requestCode == REQUEST_CODE_CAMERA) { // ??
         if (cameraFile != null && cameraFile.exists())
            sendPicture(cameraFile.getAbsolutePath());
      } else if (requestCode == REQUEST_CODE_SELECT_VIDEO) { // ??

         int duration = data.getIntExtra("dur", 0);
         String videoPath = data.getStringExtra("path");
         File file = new File(ChatFileUtil.getInstance(this).getChatFilePath(FileType.Picture), "thvideo" + System.currentTimeMillis());
         Bitmap bitmap = null;
         FileOutputStream fos = null;
         try {
            if (!file.getParentFile().exists()) {
               file.getParentFile().mkdirs();
            }
            bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3);
            if (bitmap == null) {
               ChatLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon");
               bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.app_panel_video_icon);
            }
            fos = new FileOutputStream(file);

            bitmap.compress(CompressFormat.JPEG, 100, fos);

         } catch (Exception e) {
            e.printStackTrace();
         } finally {
            if (fos != null) {
               try {
                  fos.close();
               } catch (IOException e) {
                  e.printStackTrace();
               }
               fos = null;
            }
            if (bitmap != null) {
               bitmap.recycle();
               bitmap = null;
            }

         }
         sendVideo(videoPath, file.getAbsolutePath(), duration / 1000);

      } else if (requestCode == REQUEST_CODE_LOCAL) { // ??
         if (data != null) {
            Uri selectedImage = data.getData();
            if (selectedImage != null) {
               sendPicByUri(selectedImage);
            }
         }
      } else if (requestCode == REQUEST_CODE_SELECT_FILE) { // ??
         if (data != null) {
            Uri uri = data.getData();
            if (uri != null) {
               sendFile(uri);
            }
         }

      } else if (requestCode == REQUEST_CODE_MAP) { // 
         double latitude = data.getDoubleExtra("latitude", 0);
         double longitude = data.getDoubleExtra("longitude", 0);
         String locationAddress = data.getStringExtra("address");
         if (locationAddress != null && !locationAddress.equals("")) {
            more(more);
            sendLocationMsg(latitude, longitude, "", locationAddress);
         } else {
            Toast.makeText(this, "????", 0).show();
         }
         // ???
      } else if (requestCode == REQUEST_CODE_TEXT) {
         resendMessage();
      } else if (requestCode == REQUEST_CODE_VOICE) {
         resendMessage();
      } else if (requestCode == REQUEST_CODE_PICTURE) {
         resendMessage();
      } else if (requestCode == REQUEST_CODE_LOCATION) {
         resendMessage();
      } else if (requestCode == REQUEST_CODE_VIDEO || requestCode == REQUEST_CODE_FILE) {
         resendMessage();
      } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) {
         // 
         if (!TextUtils.isEmpty(clipboard.getText())) {
            String pasteText = clipboard.getText().toString();
            if (pasteText.startsWith(COPY_IMAGE)) {
               // ??path
               sendPicture(pasteText.replace(COPY_IMAGE, ""));
            }

         }
      } else if (requestCode == REQUEST_CODE_ADD_TO_BLACKLIST) { // ???
         ChatMessage deleteMsg = (ChatMessage) adapter.getItem(data.getIntExtra("position", -1));
         addUserToBlacklist(deleteMsg.getFrom());
      } else if (conversation.getMsgCount() > 0) {
         adapter.refresh();
         setResult(RESULT_OK);
      } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) {
         adapter.refresh();
      }
   }
}

From source file:com.ieeton.user.activity.ChatActivity.java

/**
 * onActivityResult/*from w  w  w.  j  a  va 2 s . c  o  m*/
 */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_CODE_EXIT_GROUP) {
        setResult(RESULT_OK);
        finish();
        return;
    }
    if (requestCode == REQUEST_CODE_CONTEXT_MENU) {
        switch (resultCode) {
        case RESULT_CODE_COPY: // ??
            EMMessage copyMsg = ((EMMessage) adapter.getItem(data.getIntExtra("position", -1)));
            // clipboard.setText(SmileUtils.getSmiledText(ChatActivity.this,
            // ((TextMessageBody) copyMsg.getBody()).getMessage()));
            clipboard.setText(((TextMessageBody) copyMsg.getBody()).getMessage());
            break;
        case RESULT_CODE_DELETE: // ?
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            conversation.removeMessage(deleteMsg.getMsgId());
            adapter.refresh();
            listView.setSelection(data.getIntExtra("position", adapter.getCount()) - 1);
            break;

        default:
            break;
        }
    }
    if (resultCode == RESULT_OK) { // ?
        if (requestCode == REQUEST_CODE_EMPTY_HISTORY) {
            // ?
            EMChatManager.getInstance().clearConversation(toChatUsername);
            adapter.refresh();
        } else if (requestCode == REQUEST_CODE_CAMERA) { // ??
            if (cameraFile != null && cameraFile.exists())
                sendPicture(cameraFile.getAbsolutePath());
        } else if (requestCode == REQUEST_CODE_SELECT_VIDEO) { // ??

            int duration = data.getIntExtra("dur", 0);
            String videoPath = data.getStringExtra("path");
            File file = new File(PathUtil.getInstance().getImagePath(), "thvideo" + System.currentTimeMillis());
            Bitmap bitmap = null;
            FileOutputStream fos = null;
            try {
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }
                bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3);
                if (bitmap == null) {
                    EMLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon");
                    bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.app_panel_video_icon);
                }
                fos = new FileOutputStream(file);

                bitmap.compress(CompressFormat.JPEG, 100, fos);

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (fos != null) {
                    try {
                        fos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    fos = null;
                }
                if (bitmap != null) {
                    bitmap.recycle();
                    bitmap = null;
                }

            }
            sendVideo(videoPath, file.getAbsolutePath(), duration / 1000);

        } else if (requestCode == REQUEST_CODE_LOCAL) { // ??
            if (data != null) {
                Uri selectedImage = data.getData();
                if (selectedImage != null) {
                    sendPicByUri(selectedImage);
                }
            }
        } else if (requestCode == REQUEST_CODE_SELECT_FILE) { // ??
            if (data != null) {
                Uri uri = data.getData();
                if (uri != null) {
                    sendFile(uri);
                }
            }

        } else if (requestCode == REQUEST_CODE_MAP) { // 
            double latitude = data.getDoubleExtra("latitude", 0);
            double longitude = data.getDoubleExtra("longitude", 0);
            String locationAddress = data.getStringExtra("address");
            if (locationAddress != null && !locationAddress.equals("")) {
                more(more);
                sendLocationMsg(latitude, longitude, "", locationAddress);
            } else {
                Toast.makeText(this, "????", 0).show();
            }
            // ???
        } else if (requestCode == REQUEST_CODE_TEXT) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_VOICE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_PICTURE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_LOCATION) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_VIDEO || requestCode == REQUEST_CODE_FILE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) {
            // 
            if (!TextUtils.isEmpty(clipboard.getText())) {
                String pasteText = clipboard.getText().toString();
                if (pasteText.startsWith(COPY_IMAGE)) {
                    // ??path
                    sendPicture(pasteText.replace(COPY_IMAGE, ""));
                }

            }
        } else if (requestCode == REQUEST_CODE_ADD_TO_BLACKLIST) { // ???
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            addUserToBlacklist(deleteMsg.getFrom());
        } else if (conversation.getMsgCount() > 0) {
            adapter.refresh();
            setResult(RESULT_OK);
        } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) {
            adapter.refresh();
        }
    }
}