private WritableMap serializeEventData() {
    WritableMap eventData = Arguments.createMap();

    WritableMap selectionData = Arguments.createMap();
    selectionData.putInt("start", mSelectionStart);
    selectionData.putInt("end", mSelectionEnd);

    eventData.putMap("selection", selectionData);
    return eventData;
  }
  @ReactProp(name = PROP_CENTER)
  public void setPropCenter(MapView view, @Nullable ReadableMap center) {
    WritableMap properties = getProperties();
    if (center != null) {
      WritableMap centerLatLng = Arguments.createMap();
      WritableMap centerMap = Arguments.createMap();
      centerLatLng.putDouble("lat", center.getDouble("lat"));
      centerLatLng.putDouble("lng", center.getDouble("lng"));

      centerMap.putMap("center", centerLatLng);
      properties.merge(centerMap);
      updateCenter();
    }
  }
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // robustness code
    if (mCallback == null
        || (mCameraCaptureURI == null && requestCode == REQUEST_LAUNCH_CAMERA)
        || (requestCode != REQUEST_LAUNCH_CAMERA
            && requestCode != REQUEST_LAUNCH_IMAGE_LIBRARY
            && requestCode != REQUEST_IMAGE_CROPPING)) {
      return;
    }

    // user cancel
    if (resultCode != Activity.RESULT_OK) {
      response.putBoolean("didCancel", true);
      mCallback.invoke(response);
      return;
    }

    Uri uri;
    switch (requestCode) {
      case REQUEST_LAUNCH_CAMERA:
        uri = mCameraCaptureURI;
        break;
      case REQUEST_IMAGE_CROPPING:
        uri = mCropImagedUri;
        break;
      default:
        uri = data.getData();
    }

    if (requestCode != REQUEST_IMAGE_CROPPING && allowEditing == true) {
      Intent cropIntent = new Intent("com.android.camera.action.CROP");
      cropIntent.setDataAndType(uri, "image/*");
      cropIntent.putExtra("crop", "true");

      if (aspectX > 0 && aspectY > 0) {
        // aspectX:aspectY, the ratio of width to height
        cropIntent.putExtra("aspectX", aspectX);
        cropIntent.putExtra("aspectY", aspectY);
        cropIntent.putExtra("scale", true);
      }

      // we create a file to save the result
      File imageFile = createNewFile();
      mCropImagedUri = Uri.fromFile(imageFile);
      cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCropImagedUri);

      try {
        mMainActivity.startActivityForResult(cropIntent, REQUEST_IMAGE_CROPPING);
      } catch (ActivityNotFoundException e) {
        e.printStackTrace();
      }
      return;
    }

    String realPath = getRealPathFromURI(uri);
    boolean isUrl = false;

    if (realPath != null) {
      try {
        URL url = new URL(realPath);
        isUrl = true;
      } catch (MalformedURLException e) {
        // not a url
      }
    }

    if (realPath == null || isUrl) {
      try {
        File file = createFileFromURI(uri);
        realPath = file.getAbsolutePath();
        uri = Uri.fromFile(file);
      } catch (Exception e) {
        response.putString("error", "Could not read photo");
        response.putString("uri", uri.toString());
        mCallback.invoke(response);
        return;
      }
    }

    ExifInterface exif = null;
    int CurrentAngle = 0;
    try {
      exif = new ExifInterface(realPath);
      int orientation =
          exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
      boolean isVertical = true;
      switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_270:
          isVertical = false;
          CurrentAngle = 270;
          break;
        case ExifInterface.ORIENTATION_ROTATE_90:
          isVertical = false;
          CurrentAngle = 90;
          break;
        case ExifInterface.ORIENTATION_ROTATE_180:
          CurrentAngle = 180;
          break;
      }
      response.putBoolean("isVertical", isVertical);
    } catch (IOException e) {
      e.printStackTrace();
      response.putString("error", e.getMessage());
      mCallback.invoke(response);
      return;
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    Bitmap photo = BitmapFactory.decodeFile(realPath, options);
    int initialWidth = options.outWidth;
    int initialHeight = options.outHeight;

    // don't create a new file if contraint are respected
    if (((initialWidth < maxWidth && maxWidth > 0) || maxWidth == 0)
        && ((initialHeight < maxHeight && maxHeight > 0) || maxHeight == 0)
        && quality == 100
        && (!forceAngle || (forceAngle && CurrentAngle == angle))) {
      response.putInt("width", initialWidth);
      response.putInt("height", initialHeight);
    } else {
      File resized = getResizedImage(getRealPathFromURI(uri), initialWidth, initialHeight);
      realPath = resized.getAbsolutePath();
      uri = Uri.fromFile(resized);
      photo = BitmapFactory.decodeFile(realPath, options);
      response.putInt("width", options.outWidth);
      response.putInt("height", options.outHeight);
    }

    response.putString("uri", uri.toString());
    response.putString("path", realPath);

    if (!noData) {
      response.putString("data", getBase64StringFromFile(realPath));
    }

    if (assetProperties) {
      WritableNativeMap assetPropertiesMap = new WritableNativeMap();

      if (options.outMimeType != null) {
        assetPropertiesMap.putString("mimeType", options.outMimeType);
      }

      String[] splitPath = realPath.split("/");
      if (splitPath.length > 0) {
        assetPropertiesMap.putString("fileName", splitPath[splitPath.length - 1]);
      }

      File file = new File(realPath);
      if (file != null) {
        assetPropertiesMap.putDouble("fileSize", file.length());
      }

      response.putMap("assetProperties", assetPropertiesMap);
      mCallback.invoke(response);
    } else {
      mCallback.invoke(response);
    }
  }