Java Code Examples for com.facebook.react.bridge.ReadableMap#getMap()

The following examples show how to use com.facebook.react.bridge.ReadableMap#getMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserProfileBridgeTest.java    From react-native-lock with MIT License 6 votes vote down vote up
@Test
public void shouldBridgeMetadata() throws Exception {
    final HashMap<String, Object> user = Maps.newHashMap();
    user.put("first_name", "John");
    user.put("last_name", "Doe");
    user.put("friend_count", 14);

    final HashMap<String, Object> app = Maps.newHashMap();
    app.put("subscription", "bronze");

    final UserProfile profile = withMetadata(INFO_AUTH0_COM, user, app);
    final ReadableMap map = bridge(profile);

    assertThat(map.getString(EMAIL), equalTo(INFO_AUTH0_COM));

    final ReadableMap userMetadata = map.getMap(USER_METADATA);
    assertThat(userMetadata.getString("first_name"), equalTo("John"));
    assertThat(userMetadata.getString("last_name"), equalTo("Doe"));
    assertThat(userMetadata.getInt("friend_count"), equalTo(14));

    final ReadableMap appMetadata = map.getMap(APP_METADATA);
    assertThat(appMetadata.getString("subscription"), equalTo("bronze"));
}
 
Example 2
Source File: BlobModule.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
public RequestBody toRequestBody(ReadableMap data, String contentType) {
  String type = contentType;
  if (data.hasKey("type") && !data.getString("type").isEmpty()) {
    type = data.getString("type");
  }
  if (type == null) {
    type = "application/octet-stream";
  }
  ReadableMap blob = data.getMap("blob");
  String blobId = blob.getString("blobId");
  byte[] bytes = resolve(
    blobId,
    blob.getInt("offset"),
    blob.getInt("size"));

  return RequestBody.create(MediaType.parse(type), bytes);
}
 
Example 3
Source File: KeychainModule.java    From react-native-keychain with MIT License 6 votes vote down vote up
/** Extract user specified prompt info from options. */
@NonNull
private static PromptInfo getPromptInfo(@Nullable final ReadableMap options) {
  final ReadableMap promptInfoOptionsMap = (options != null && options.hasKey(Maps.AUTH_PROMPT)) ? options.getMap(Maps.AUTH_PROMPT) : null;

  final PromptInfo.Builder promptInfoBuilder = new PromptInfo.Builder();
  if (null != promptInfoOptionsMap && promptInfoOptionsMap.hasKey(AuthPromptOptions.TITLE)) {
    String promptInfoTitle = promptInfoOptionsMap.getString(AuthPromptOptions.TITLE);
    promptInfoBuilder.setTitle(promptInfoTitle);
  }
  if (null != promptInfoOptionsMap && promptInfoOptionsMap.hasKey(AuthPromptOptions.SUBTITLE)) {
    String promptInfoSubtitle = promptInfoOptionsMap.getString(AuthPromptOptions.SUBTITLE);
    promptInfoBuilder.setSubtitle(promptInfoSubtitle);
  }
  if (null != promptInfoOptionsMap && promptInfoOptionsMap.hasKey(AuthPromptOptions.DESCRIPTION)) {
    String promptInfoDescription = promptInfoOptionsMap.getString(AuthPromptOptions.DESCRIPTION);
    promptInfoBuilder.setDescription(promptInfoDescription);
  }
  if (null != promptInfoOptionsMap && promptInfoOptionsMap.hasKey(AuthPromptOptions.CANCEL)) {
    String promptInfoNegativeButton = promptInfoOptionsMap.getString(AuthPromptOptions.CANCEL);
    promptInfoBuilder.setNegativeButtonText(promptInfoNegativeButton);
  }
  final PromptInfo promptInfo = promptInfoBuilder.build();

  return promptInfo;
}
 
Example 4
Source File: RNJWPlayerViewManager.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactProp(name = "colors")
public void setColors(RNJWPlayerView view, ReadableMap prop) {
  if (prop != null) {
    if (prop.hasKey("icons")) {
      view.mPlayer.getConfig().getSkinConfig().setControlBarIcons("#" + prop.getString("icons"));
    }

    if (prop.hasKey("timeslider")) {
      ReadableMap timeslider = prop.getMap("timeslider");

      if (timeslider.hasKey("progress")) {
        view.mPlayer.getConfig().getSkinConfig().setTimeSliderProgress("#" + timeslider.getString("progress"));
      }

      if (timeslider.hasKey("rail")) {
        view.mPlayer.getConfig().getSkinConfig().setTimeSliderRail("#" + timeslider.getString("rail"));
      }
    }

    if (view.mPlayer != null) {
      view.mPlayer.setup(view.mPlayer.getConfig());
    }
  }
}
 
Example 5
Source File: MutableImage.java    From react-native-camera-face-detector with MIT License 6 votes vote down vote up
private void writeLocationExifData(ReadableMap options, ExifInterface exif) {
    if(!options.hasKey("metadata"))
        return;

    ReadableMap metadata = options.getMap("metadata");
    if (!metadata.hasKey("location"))
        return;

    ReadableMap location = metadata.getMap("location");
    if(!location.hasKey("coords"))
        return;

    try {
        ReadableMap coords = location.getMap("coords");
        double latitude = coords.getDouble("latitude");
        double longitude = coords.getDouble("longitude");

        GPS.writeExifData(latitude, longitude, exif);
    } catch (IOException e) {
        Log.e(TAG, "Couldn't write location data", e);
    }
}
 
Example 6
Source File: RNKakaoLinkModule.java    From react-native-kakao-links with MIT License 6 votes vote down vote up
private void sendCustom(ReadableMap options, Promise promise) {
  String templateId = options.getString("templateId");

  ReadableMap templateArgs = options.getMap("templateArgs");
  Map<String, String> templateArgsMap = (templateArgs == null) ? null : createTemplateArgsMap(templateArgs);

  ReadableMap serverCallbackArgs = options.getMap("serverCallbackArgs");
  Map<String, String> serverCallbackArgsMap = (serverCallbackArgs == null) ? null : createServerCallbackArgsMap(serverCallbackArgs);

  //check serverCallback
  if (serverCallbackArgsMap != null) {//has ServerCallback
    KakaoLinkService.getInstance().sendCustom(this.getCurrentActivity(), templateId, templateArgsMap, serverCallbackArgsMap, new co.jootopia.kakao.link.RNKakaoLinkModule.BasicResponseCallback<KakaoLinkResponse>(promise));
  } else { //no serverCallback
    KakaoLinkService.getInstance().sendCustom(this.getCurrentActivity(), templateId, templateArgsMap, new co.jootopia.kakao.link.RNKakaoLinkModule.BasicResponseCallback<KakaoLinkResponse>(promise));
  }
}
 
Example 7
Source File: PostalAddress.java    From react-native-paged-contacts with MIT License 5 votes vote down vote up
private void fillFromPostalAddressMap(ReadableMap postalAddressMap) {
    label =  postalAddressMap.getString("label");

    ReadableMap addressMap = postalAddressMap.getMap("value");

    formattedAddress = getWithDefault(addressMap, "formattedAddress");
    poBox = getWithDefault(addressMap, "poBox");
    street = getWithDefault(addressMap, "street");
    neighborhood = getWithDefault(addressMap, "neighborhood");
    city = getWithDefault(addressMap, "city");
    region = getWithDefault(addressMap, "region");
    postcode = getWithDefault(addressMap, "postalCode");
    country = getWithDefault(addressMap, "country");
}
 
Example 8
Source File: ImageEditingManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
/**
 * Crop an image. If all goes well, the success callback will be called with the file:// URI of
 * the new image as the only argument. This is a temporary file - consider using
 * CameraRollManager.saveImageWithTag to save it in the gallery.
 *
 * @param uri the MediaStore URI of the image to crop
 * @param options crop parameters specified as {@code {offset: {x, y}, size: {width, height}}}.
 *        Optionally this also contains  {@code {targetSize: {width, height}}}. If this is
 *        specified, the cropped image will be resized to that size.
 *        All units are in pixels (not DPs).
 * @param success callback to be invoked when the image has been cropped; the only argument that
 *        is passed to this callback is the file:// URI of the new image
 * @param error callback to be invoked when an error occurs (e.g. can't create file etc.)
 */
@ReactMethod
public void cropImage(
    String uri,
    ReadableMap options,
    final Callback success,
    final Callback error) {
  ReadableMap offset = options.hasKey("offset") ? options.getMap("offset") : null;
  ReadableMap size = options.hasKey("size") ? options.getMap("size") : null;
  if (offset == null || size == null ||
      !offset.hasKey("x") || !offset.hasKey("y") ||
      !size.hasKey("width") || !size.hasKey("height")) {
    throw new JSApplicationIllegalArgumentException("Please specify offset and size");
  }
  if (uri == null || uri.isEmpty()) {
    throw new JSApplicationIllegalArgumentException("Please specify a URI");
  }

  CropTask cropTask = new CropTask(
      getReactApplicationContext(),
      uri,
      (int) offset.getDouble("x"),
      (int) offset.getDouble("y"),
      (int) size.getDouble("width"),
      (int) size.getDouble("height"),
      success,
      error);
  if (options.hasKey("displaySize")) {
    ReadableMap targetSize = options.getMap("displaySize");
    cropTask.setTargetSize(
      (int) targetSize.getDouble("width"),
      (int) targetSize.getDouble("height"));
  }
  cropTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
 
Example 9
Source File: NavBarStyle.java    From react-native-turbolinks with MIT License 5 votes vote down vote up
private NavBarStyle(ReadableMap rp) {
    ReadableMap menuIcon = rp.hasKey(MENU_ICON) ? rp.getMap(MENU_ICON) : null;
    this.titleTextColor = rp.hasKey(TITLE_TEXT_COLOR) && !rp.isNull(TITLE_TEXT_COLOR) ? rp.getInt(TITLE_TEXT_COLOR) : null;
    this.subtitleTextColor = rp.hasKey(SUBTITLE_TEXT_COLOR) && !rp.isNull(SUBTITLE_TEXT_COLOR) ? rp.getInt(SUBTITLE_TEXT_COLOR) : null;
    this.barTintColor = rp.hasKey(BAR_TINT_COLOR) && !rp.isNull(BAR_TINT_COLOR) ? rp.getInt(BAR_TINT_COLOR) : null;
    this.menuIcon = menuIcon != null ? Arguments.toBundle(menuIcon) : null;
}
 
Example 10
Source File: PropsAnimatedNode.java    From react-native-GPay with MIT License 5 votes vote down vote up
PropsAnimatedNode(ReadableMap config, NativeAnimatedNodesManager nativeAnimatedNodesManager, UIImplementation uiImplementation) {
  ReadableMap props = config.getMap("props");
  ReadableMapKeySetIterator iter = props.keySetIterator();
  mPropNodeMapping = new HashMap<>();
  while (iter.hasNextKey()) {
    String propKey = iter.nextKey();
    int nodeIndex = props.getInt(propKey);
    mPropNodeMapping.put(propKey, nodeIndex);
  }
  mPropMap = new JavaOnlyMap();
  mDiffMap = new ReactStylesDiffMap(mPropMap);
  mNativeAnimatedNodesManager = nativeAnimatedNodesManager;
  mUIImplementation = uiImplementation;
}
 
Example 11
Source File: TurbolinksRoute.java    From react-native-turbolinks with MIT License 5 votes vote down vote up
public TurbolinksRoute(ReadableMap rp) {
    ReadableMap props = rp.hasKey("passProps") ? rp.getMap("passProps") : null;
    ReadableArray actions = rp.hasKey("actions") ? rp.getArray("actions") : null;
    this.url = rp.hasKey("url") ? rp.getString("url") : null;
    this.component = rp.hasKey("component") ? rp.getString("component") : null;
    this.action = rp.hasKey("action") ? rp.getString("action") : ACTION_ADVANCE;
    this.modal = rp.hasKey("modal") && rp.getBoolean("modal");
    this.dismissable = rp.hasKey("dismissable") && rp.getBoolean("dismissable");
    this.passProps = props != null ? Arguments.toBundle(props) : null;
    this.title = rp.hasKey("title") ? rp.getString("title") : null;
    this.subtitle = rp.hasKey("subtitle") ? rp.getString("subtitle") : null;
    this.visibleDropDown = rp.hasKey("visibleDropDown") && rp.getBoolean("visibleDropDown");
    this.hidesNavBar = rp.hasKey("hidesNavBar") && rp.getBoolean("hidesNavBar");
    this.actions = rp.hasKey("actions") ? Arguments.toList(actions) : null;
}
 
Example 12
Source File: SipMessageDTO.java    From react-native-pjsip with GNU General Public License v3.0 5 votes vote down vote up
public static SipMessageDTO fromReadableMap(ReadableMap data) {
    SipMessageDTO result = new SipMessageDTO();

    if (data.hasKey("targetURI")) {
        result.setTargetUri(data.getString("targetURI"));
    }
    if (data.hasKey("headers")) {
        ReadableMap headersData = data.getMap("headers");
        ReadableMapKeySetIterator headersIt = headersData.keySetIterator();
        Map<String, String> headers = new HashMap<>();

        while (headersIt.hasNextKey()) {
            String key = headersIt.nextKey();
            headers.put(key, headersData.getString(key));
        }

        result.setHeaders(headers);
    }
    if (data.hasKey("contentType")) {
        result.setContentType(data.getString("contentType"));
    }
    if (data.hasKey("body")) {
        result.setBody(data.getString("body"));
    }

    return result;
}
 
Example 13
Source File: ReadableMapUtils.java    From react-native-google-cast with MIT License 5 votes vote down vote up
public static @Nullable ReadableMap getReadableMap(@NonNull ReadableMap map, @NonNull String key) {
    if (!map.hasKey(key)) {
        return null;
    }

    return map.getMap(key);
}
 
Example 14
Source File: ImageEditorModule.java    From react-native-image-editor with MIT License 5 votes vote down vote up
/**
 * Crop an image. If all goes well, the promise will be resolved with the file:// URI of
 * the new image as the only argument. This is a temporary file - consider using
 * CameraRollManager.saveImageWithTag to save it in the gallery.
 *
 * @param uri the URI of the image to crop
 * @param options crop parameters specified as {@code {offset: {x, y}, size: {width, height}}}.
 *        Optionally this also contains  {@code {targetSize: {width, height}}}. If this is
 *        specified, the cropped image will be resized to that size.
 *        All units are in pixels (not DPs).
 * @param promise Promise to be resolved when the image has been cropped; the only argument that
 *        is passed to this is the file:// URI of the new image
 */
@ReactMethod
public void cropImage(
    String uri,
    ReadableMap options,
    Promise promise) {
  ReadableMap offset = options.hasKey("offset") ? options.getMap("offset") : null;
  ReadableMap size = options.hasKey("size") ? options.getMap("size") : null;
  if (offset == null || size == null ||
      !offset.hasKey("x") || !offset.hasKey("y") ||
      !size.hasKey("width") || !size.hasKey("height")) {
    throw new JSApplicationIllegalArgumentException("Please specify offset and size");
  }
  if (uri == null || uri.isEmpty()) {
    throw new JSApplicationIllegalArgumentException("Please specify a URI");
  }

  CropTask cropTask = new CropTask(
      getReactApplicationContext(),
      uri,
      (int) offset.getDouble("x"),
      (int) offset.getDouble("y"),
      (int) size.getDouble("width"),
      (int) size.getDouble("height"),
      promise);
  if (options.hasKey("displaySize")) {
    ReadableMap targetSize = options.getMap("displaySize");
    cropTask.setTargetSize(
      (int) targetSize.getDouble("width"),
      (int) targetSize.getDouble("height"));
  }
  cropTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
 
Example 15
Source File: SQLitePluginConverter.java    From react-native-sqlite-storage with MIT License 5 votes vote down vote up
static Object get(ReadableMap map,String key,Object defaultValue){
    if (map == null){
        return defaultValue;
    }

    try {
        Object value = null;
        ReadableType type = map.getType(key);
        switch(type){
            case Boolean:
                value = map.getBoolean(key);
                break;
            case Number:
                value = map.getDouble(key);
                break;
            case String:
                value = map.getString(key);
                break;
            case Map:
                value = map.getMap(key);
                break;
            case Array:
                value = map.getArray(key);
                break;
            case Null:
                value = null;
                break;
        }
        return value;
    } catch (NoSuchKeyException ex){
        return defaultValue;
    }
}
 
Example 16
Source File: AuroraIMUIModule.java    From aurora-imui with MIT License 4 votes vote down vote up
private RCTMessage configMessage(ReadableMap message) {
    Log.d("AuroraIMUIModule", "configure message: " + message);
    RCTMessage rctMsg = new RCTMessage(message.getString(RCTMessage.MSG_ID),
            message.getString(RCTMessage.STATUS), message.getString(RCTMessage.MSG_TYPE),
            message.getBoolean(RCTMessage.IS_OUTGOING));
    switch (rctMsg.getType()) {
        case 5:
        case 6:
        case 7:
        case 8:
            rctMsg.setMediaFilePath(message.getString("mediaPath"));
            rctMsg.setDuration(message.getInt("duration"));
            break;
        case 3:
        case 4:
            rctMsg.setMediaFilePath(message.getString("mediaPath"));
            break;
        case 13:
        case 14:
        default:
            if (message.hasKey("content")) {
                rctMsg.setText(message.getString("content"));
            } else if (message.hasKey("text")) {
                rctMsg.setText(message.getString("text"));
            }
            if (message.hasKey("contentSize")) {
                ReadableMap size = message.getMap("contentSize");
                if (size.hasKey("width") && size.hasKey("height")) {
                    rctMsg.setContentSize(size.getInt("width"), size.getInt("height"));
                }
            }
    }
    ReadableMap user = message.getMap("fromUser");
    RCTUser rctUser = new RCTUser(user.getString("userId"), user.getString("displayName"),
            user.getString("avatarPath"));
    Log.d("AuroraIMUIModule", "fromUser: " + rctUser);
    rctMsg.setFromUser(rctUser);
    if (message.hasKey("timeString")) {
        String timeString = message.getString("timeString");
        if (timeString != null) {
            rctMsg.setTimeString(timeString);
        }
    }
    if (message.hasKey("progress")) {
        String progress = message.getString("progress");
        if (progress != null) {
            rctMsg.setProgress(progress);
        }
    }
    if (message.hasKey("extras")) {
        ReadableMap extra = message.getMap("extras");
        ReadableMapKeySetIterator iterator = extra.keySetIterator();
        while (iterator.hasNextKey()) {
            String key = iterator.nextKey();
            rctMsg.putExtra(key, extra.getString(key));
        }
    }
    return rctMsg;
}
 
Example 17
Source File: RNKakaoLinkModule.java    From react-native-kakao-links with MIT License 4 votes vote down vote up
@ReactMethod
public void link(ReadableMap options, final Promise promise) {
  String objectType = options.getString("objectType");
  TemplateParams params = null;
  ReadableMap serverCallbackArgs = null;
  Map<String, String> serverCallbackArgsMap = null;

  if (options.hasKey("serverCallbackArgs")) {
    serverCallbackArgs = options.getMap("serverCallbackArgs");
    serverCallbackArgsMap = createServerCallbackArgsMap(serverCallbackArgs);
  }

  options = new co.jootopia.kakao.link.RNKakaoLinkModule.NullSafeReadableMap(options);
  switch (objectType) {
    case "feed":
      params = createFeedTemplate(options);
      sendDefault(params, promise, serverCallbackArgsMap);
      break;
    case "text":
      params = createTextTemplate(options);
      sendDefault(params, promise, serverCallbackArgsMap);
      break;
    case "location":
      params = createLocationTemplate(options);
      sendDefault(params, promise, serverCallbackArgsMap);
      break;
    case "list":
      params = createListTemplate(options);
      sendDefault(params, promise, serverCallbackArgsMap);
      break;
    case "commerce":
      params = createCommerceTemplate(options);
      sendDefault(params, promise, serverCallbackArgsMap);
      break;
    case "custom":
      sendCustom(options, promise);
      return;
    case "scrap":
      sendScrap(options, promise);
      return;
    default:
      break;
  }
}
 
Example 18
Source File: ChartBaseManager.java    From react-native-mp-android-chart with MIT License 4 votes vote down vote up
/**
 * General axis config details: https://github.com/PhilJay/MPAndroidChart/wiki/The-Axis
 */
protected void setCommonAxisConfig(Chart chart, AxisBase axis, ReadableMap propMap) {
    // what is drawn
    if (BridgeUtils.validate(propMap, ReadableType.Boolean, "enabled")) {
        axis.setEnabled(propMap.getBoolean("enabled"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Boolean, "drawLabels")) {
        axis.setDrawLabels(propMap.getBoolean("drawLabels"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Boolean, "drawAxisLine")) {
        axis.setDrawAxisLine(propMap.getBoolean("drawAxisLine"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Boolean, "drawGridLines")) {
        axis.setDrawGridLines(propMap.getBoolean("drawGridLines"));
    }

    // style
    if (BridgeUtils.validate(propMap, ReadableType.String, "textColor")) {
        axis.setTextColor(Color.parseColor(propMap.getString("textColor")));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "textSize")) {
        axis.setTextSize((float) propMap.getDouble("textSize"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.String, "fontFamily") ||
            BridgeUtils.validate(propMap, ReadableType.Number, "fontStyle")) {
        axis.setTypeface(BridgeUtils.parseTypeface(chart.getContext(), propMap, "fontStyle", "fontFamily"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.String, "gridColor")) {
        axis.setGridColor(Color.parseColor(propMap.getString("gridColor")));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "gridLineWidth")) {
        axis.setGridLineWidth((float) propMap.getDouble("gridLineWidth"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.String, "axisLineColor")) {
        axis.setAxisLineColor(Color.parseColor(propMap.getString("axisLineColor")));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "axisLineWidth")) {
        axis.setAxisLineWidth((float) propMap.getDouble("axisLineWidth"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Map, "gridDashedLine")) {
        ReadableMap gridDashedLine = propMap.getMap("gridDashedLine");
        float lineLength = 0;
        float spaceLength = 0;
        float phase = 0;

        if (BridgeUtils.validate(gridDashedLine, ReadableType.Number, "lineLength")) {
            lineLength = (float) gridDashedLine.getDouble("lineLength");
        }
        if (BridgeUtils.validate(gridDashedLine, ReadableType.Number, "spaceLength")) {
            spaceLength = (float) gridDashedLine.getDouble("spaceLength");
        }
        if (BridgeUtils.validate(gridDashedLine, ReadableType.Number, "phase")) {
            phase = (float) gridDashedLine.getDouble("phase");
        }

        axis.enableGridDashedLine(lineLength, spaceLength, phase);
    }

    // limit lines
    if (BridgeUtils.validate(propMap, ReadableType.Array, "limitLines")) {
        ReadableArray limitLines = propMap.getArray("limitLines");

        for (int i = 0; i < limitLines.size(); i++) {
            if (!ReadableType.Map.equals(limitLines.getType(i))) {
                continue;
            }

            ReadableMap limitLineMap = limitLines.getMap(i);
            if (BridgeUtils.validate(limitLineMap, ReadableType.Number, "limit")) {
                LimitLine limitLine = new LimitLine((float) limitLineMap.getDouble("limit"));

                if (BridgeUtils.validate(limitLineMap, ReadableType.String, "label")) {
                    limitLine.setLabel(limitLineMap.getString("label"));
                }
                if (BridgeUtils.validate(limitLineMap, ReadableType.String, "lineColor")) {
                    limitLine.setLineColor(Color.parseColor(limitLineMap.getString("lineColor")));
                }
                if (BridgeUtils.validate(limitLineMap, ReadableType.Number, "lineWidth")) {
                    limitLine.setLineWidth((float) limitLineMap.getDouble("lineWidth"));
                }

                axis.addLimitLine(limitLine);
            }

        }
    }
    if (BridgeUtils.validate(propMap, ReadableType.Boolean, "drawLimitLinesBehindData")) {
        axis.setDrawLimitLinesBehindData(propMap.getBoolean("drawLimitLinesBehindData"));
    }
}
 
Example 19
Source File: LineChartManager.java    From react-native-mp-android-chart with MIT License 4 votes vote down vote up
@Override
void dataSetConfig(IDataSet<Entry> dataSet, ReadableMap config) {
    LineDataSet lineDataSet = (LineDataSet) dataSet;

    ChartDataSetConfigUtils.commonConfig(lineDataSet, config);
    ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(lineDataSet, config);
    ChartDataSetConfigUtils.commonLineScatterCandleRadarConfig(lineDataSet, config);
    ChartDataSetConfigUtils.commonLineRadarConfig(lineDataSet, config);

    // LineDataSet only config
    if (BridgeUtils.validate(config, ReadableType.Number, "circleRadius")) {
        lineDataSet.setCircleRadius((float) config.getDouble("circleRadius"));
    }
    if (BridgeUtils.validate(config, ReadableType.Boolean, "drawCircles")) {
        lineDataSet.setDrawCircles(config.getBoolean("drawCircles"));
    }
    if (BridgeUtils.validate(config, ReadableType.Boolean, "drawCubic")) {
        lineDataSet.setDrawCubic(config.getBoolean("drawCubic"));
    }
    if (BridgeUtils.validate(config, ReadableType.Number, "drawCubicIntensity")) {
        lineDataSet.setCubicIntensity((float) config.getDouble("drawCubicIntensity"));
    }
    if (BridgeUtils.validate(config, ReadableType.String, "circleColor")) {
        lineDataSet.setCircleColor(Color.parseColor(config.getString("circleColor")));
    }
    if (BridgeUtils.validate(config, ReadableType.Array, "circleColors")) {
        lineDataSet.setCircleColors(BridgeUtils.parseColors(config.getArray("circleColors")));
    }
    if (BridgeUtils.validate(config, ReadableType.String, "circleColorHole")) {
        lineDataSet.setCircleColorHole(Color.parseColor(config.getString("circleColorHole")));
    }
    if (BridgeUtils.validate(config, ReadableType.Boolean, "drawCircleHole")) {
        lineDataSet.setDrawCircleHole(config.getBoolean("drawCircleHole"));
    }
    if (BridgeUtils.validate(config, ReadableType.Map, "dashedLine")) {
        ReadableMap dashedLine = config.getMap("dashedLine");
        float lineLength = 0;
        float spaceLength = 0;
        float phase = 0;

        if (BridgeUtils.validate(dashedLine, ReadableType.Number, "lineLength")) {
            lineLength = (float) dashedLine.getDouble("lineLength");
        }
        if (BridgeUtils.validate(dashedLine, ReadableType.Number, "spaceLength")) {
            spaceLength = (float) dashedLine.getDouble("spaceLength");
        }
        if (BridgeUtils.validate(dashedLine, ReadableType.Number, "phase")) {
            phase = (float) dashedLine.getDouble("phase");
        }

        lineDataSet.enableDashedLine(lineLength, spaceLength, phase);
    }
}
 
Example 20
Source File: MerryPhotoViewManager.java    From photo-viewer with Apache License 2.0 4 votes vote down vote up
@ReactProp(name = "data")
public void setData(MerryPhotoView merryPhotoView, @Nonnull ReadableArray prop) {

    MerryPhotoData[] merryPhotoDatas = new MerryPhotoData[]{};

    ArrayList<MerryPhotoData> list = new ArrayList<>();

    for (int i = 0; i < prop.size(); i++) {


        try {
            MerryPhotoData merryPhotoData = new MerryPhotoData() {
            };
            ReadableMap rm = prop.getMap(i);

            if (rm.hasKey("source")) {
                merryPhotoData.source = rm.getMap("source");

            }
            if (rm.hasKey("summary")) {
                merryPhotoData.summary = rm.getString("summary");

            }
            if (rm.hasKey("summaryColor")) {
                merryPhotoData.summaryColor = rm.getInt("summaryColor");

            }
            if (rm.hasKey("title")) {
                merryPhotoData.title = rm.getString("title");

            }
            if (rm.hasKey("titleColor")) {
                merryPhotoData.titleColor = rm.getInt("titleColor");
            }
            list.add(merryPhotoData);

        } catch (Exception e) {
            Log.e("PHOTO_VIEWER: ", e.toString());
        }


    }

    merryPhotoView.setData(list.toArray(merryPhotoDatas));
}