本文整理汇总了Java中com.facebook.react.bridge.ReadableMap.hasKey方法的典型用法代码示例。如果您正苦于以下问题:Java ReadableMap.hasKey方法的具体用法?Java ReadableMap.hasKey怎么用?Java ReadableMap.hasKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.facebook.react.bridge.ReadableMap
的用法示例。
在下文中一共展示了ReadableMap.hasKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPhotos
import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
/**
* Get photos from {@link MediaStore.Images}, most recent first.
*
* @param params a map containing the following keys:
* <ul>
* <li>first (mandatory): a number representing the number of photos to fetch</li>
* <li>
* after (optional): a cursor that matches page_info[end_cursor] returned by a
* previous call to {@link #getPhotos}
* </li>
* <li>groupName (optional): an album name</li>
* <li>
* mimeType (optional): restrict returned images to a specific mimetype (e.g.
* image/jpeg)
* </li>
* </ul>
* @param promise the Promise to be resolved when the photos are loaded; for a format of the
* parameters passed to this callback, see {@code getPhotosReturnChecker} in CameraRoll.js
*/
@ReactMethod
public void getPhotos(final ReadableMap params, final Promise promise) {
int first = params.getInt("first");
String after = params.hasKey("after") ? params.getString("after") : null;
String groupName = params.hasKey("groupName") ? params.getString("groupName") : null;
ReadableArray mimeTypes = params.hasKey("mimeTypes")
? params.getArray("mimeTypes")
: null;
if (params.hasKey("groupTypes")) {
throw new JSApplicationIllegalArgumentException("groupTypes is not supported on Android");
}
new GetPhotosTask(
getReactApplicationContext(),
first,
after,
groupName,
mimeTypes,
promise)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
示例2: getSourceIdConstraint
import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
/**
* Retreives "sourceId" constraint value.
* @param mediaConstraints a <tt>ReadableMap</tt> which represents "GUM"
* constraints argument
* @return String value of "sourceId" optional "GUM" constraint or
* <tt>null</tt> if not specified in the given map.
*/
private String getSourceIdConstraint(ReadableMap mediaConstraints) {
if (mediaConstraints.hasKey("optional")
&& mediaConstraints.getType("optional") == ReadableType.Array) {
ReadableArray optional = mediaConstraints.getArray("optional");
for (int i = 0, size = optional.size(); i < size; i++) {
if (optional.getType(i) == ReadableType.Map) {
ReadableMap option = optional.getMap(i);
if (option.hasKey("sourceId")
&& option.getType("sourceId") == ReadableType.String) {
return option.getString("sourceId");
}
}
}
}
return null;
}
示例3: getMapStrValue
import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
/**
* Reads a value from given <tt>ReadableMap</tt> and returns it as
* a <tt>String</tt>. Note that integer value is converted to double, before
* it gets converted to a string.
* @param map the <tt>ReadableMap</tt> from which the value will be obtained
* @param key the map's key under which the value has been mapped.
* @return a <tt>String</tt> representation of the value if exists or
* <tt>null</tt> if there is no value mapped for given <tt>key</tt>.
*/
public static String getMapStrValue(ReadableMap map, String key) {
if(!map.hasKey(key)){
return null;
}
ReadableType type = map.getType(key);
switch (type) {
case Boolean:
return String.valueOf(map.getBoolean(key));
case Number:
// Don't know how to distinguish between Int and Double from
// ReadableType.Number. 'getInt' will fail on double value,
// while 'getDouble' works for both.
// return String.valueOf(map.getInt(key));
return String.valueOf(map.getDouble(key));
case String:
return map.getString(key);
default:
return null;
}
}
示例4: setTextShadowOffset
import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
@ReactProp(name = PROP_SHADOW_OFFSET)
public void setTextShadowOffset(@Nullable ReadableMap offsetMap) {
float dx = 0;
float dy = 0;
if (offsetMap != null) {
if (offsetMap.hasKey("width")) {
dx = PixelUtil.toPixelFromDIP(offsetMap.getDouble("width"));
}
if (offsetMap.hasKey("height")) {
dy = PixelUtil.toPixelFromDIP(offsetMap.getDouble("height"));
}
}
if (!mShadowStyleSpan.offsetMatches(dx, dy)) {
getShadowSpan().setOffset(dx, dy);
notifyChanged(false);
}
}
示例5: stackTraceToString
import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
private String stackTraceToString(String message, ReadableArray stack) {
StringBuilder stringBuilder = new StringBuilder(message).append(", stack:\n");
for (int i = 0; i < stack.size(); i++) {
ReadableMap frame = stack.getMap(i);
stringBuilder
.append(frame.getString("methodName"))
.append("@")
.append(stackFrameToModuleId(frame))
.append(frame.getInt("lineNumber"));
if (frame.hasKey("column") &&
!frame.isNull("column") &&
frame.getType("column") == ReadableType.Number) {
stringBuilder
.append(":")
.append(frame.getInt("column"));
}
stringBuilder.append("\n");
}
return stringBuilder.toString();
}
示例6: getView
import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
private View getView(int position, View convertView, ViewGroup parent, boolean isDropdown) {
ReadableMap item = getItem(position);
if (convertView == null) {
int layoutResId = isDropdown
? android.R.layout.simple_spinner_dropdown_item
: android.R.layout.simple_spinner_item;
convertView = mInflater.inflate(layoutResId, parent, false);
}
TextView textView = (TextView) convertView;
textView.setText(item.getString("label"));
if (!isDropdown && mPrimaryTextColor != null) {
textView.setTextColor(mPrimaryTextColor);
} else if (item.hasKey("color") && !item.isNull("color")) {
textView.setTextColor(item.getInt("color"));
}
return convertView;
}
示例7: setActions
import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
void setActions(@Nullable ReadableArray actions) {
Menu menu = getMenu();
menu.clear();
mActionsHolder.clear();
if (actions != null) {
for (int i = 0; i < actions.size(); i++) {
ReadableMap action = actions.getMap(i);
MenuItem item = menu.add(Menu.NONE, Menu.NONE, i, action.getString(PROP_ACTION_TITLE));
if (action.hasKey(PROP_ACTION_ICON)) {
setMenuItemIcon(item, action.getMap(PROP_ACTION_ICON));
}
int showAsAction = action.hasKey(PROP_ACTION_SHOW)
? action.getInt(PROP_ACTION_SHOW)
: MenuItem.SHOW_AS_ACTION_NEVER;
if (action.hasKey(PROP_ACTION_SHOW_WITH_TEXT) &&
action.getBoolean(PROP_ACTION_SHOW_WITH_TEXT)) {
showAsAction = showAsAction | MenuItem.SHOW_AS_ACTION_WITH_TEXT;
}
item.setShowAsAction(showAsAction);
}
}
}
示例8: initPush
import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
@ReactMethod
public void initPush(final ReadableMap options){
allocServer = options.getString("allocServer");
String userId = options.getString("userId");
String tags = options.getString("tags");
String publicKey = options.getString("publicKey");
String version = options.hasKey("version") ? options.getString("version") : "1.0.0";
if(TextUtils.isEmpty(allocServer) || TextUtils.isEmpty(userId) || TextUtils.isEmpty(publicKey)) return;
//公钥有服务端提供和私钥对应
@SuppressLint("HardwareIds")
String deviceId = Settings.Secure.getString(getReactApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
ClientConfig cc = ClientConfig.build()
.setPublicKey(publicKey)
.setAllotServer(allocServer)
.setDeviceId(deviceId)
.setClientVersion(version)
.setLogger(new MPushLog())
.setLogEnabled(BuildConfig.DEBUG)
.setEnableHttpProxy(true)
.setUserId(userId).setTags(tags);
MPush.I.checkInit(getReactApplicationContext()).setClientConfig(cc);
}
示例9: initializeFromConfig
import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
public void initializeFromConfig(final @Nullable ReadableMap config) {
if (!ENABLED) {
return;
}
if (config == null) {
reset();
return;
}
mShouldAnimateLayout = false;
int globalDuration = config.hasKey("duration") ? config.getInt("duration") : 0;
if (config.hasKey(LayoutAnimationType.CREATE.toString())) {
mLayoutCreateAnimation.initializeFromConfig(
config.getMap(LayoutAnimationType.CREATE.toString()), globalDuration);
mShouldAnimateLayout = true;
}
if (config.hasKey(LayoutAnimationType.UPDATE.toString())) {
mLayoutUpdateAnimation.initializeFromConfig(
config.getMap(LayoutAnimationType.UPDATE.toString()), globalDuration);
mShouldAnimateLayout = true;
}
if (config.hasKey(LayoutAnimationType.DELETE.toString())) {
mLayoutDeleteAnimation.initializeFromConfig(
config.getMap(LayoutAnimationType.DELETE.toString()), globalDuration);
mShouldAnimateLayout = true;
}
}
示例10: parseMediaConstraints
import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
/**
* Parses mandatory and optional "GUM" constraints described by a specific
* <tt>ReadableMap</tt>.
*
* @param constraints A <tt>ReadableMap</tt> which represents a JavaScript
* object specifying the constraints to be parsed into a
* <tt>MediaConstraints</tt> instance.
* @return A new <tt>MediaConstraints</tt> instance initialized with the
* mandatory and optional constraint keys and values specified by
* <tt>constraints</tt>.
*/
private MediaConstraints parseMediaConstraints(ReadableMap constraints) {
MediaConstraints mediaConstraints = new MediaConstraints();
if (constraints.hasKey("mandatory")
&& constraints.getType("mandatory") == ReadableType.Map) {
parseConstraints(
constraints.getMap("mandatory"),
mediaConstraints.mandatory);
} else {
Log.d(TAG, "mandatory constraints are not a map");
}
if (constraints.hasKey("optional")
&& constraints.getType("optional") == ReadableType.Array) {
ReadableArray optional = constraints.getArray("optional");
for (int i = 0, size = optional.size(); i < size; i++) {
if (optional.getType(i) == ReadableType.Map) {
parseConstraints(
optional.getMap(i),
mediaConstraints.optional);
}
}
} else {
Log.d(TAG, "optional constraints are not an array");
}
return mediaConstraints;
}
示例11: stackFrameToModuleId
import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
static private String stackFrameToModuleId(ReadableMap frame) {
if (frame.hasKey("file") &&
!frame.isNull("file") &&
frame.getType("file") == ReadableType.String) {
final Matcher matcher = mJsModuleIdPattern.matcher(frame.getString("file"));
if (matcher.find()) {
return matcher.group(1) + ":";
}
}
return "";
}
示例12: hasAndNotEmpty
import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
public static @NonNull boolean hasAndNotEmpty(@NonNull final ReadableMap target,
@NonNull final String key)
{
if (!target.hasKey(key))
{
return false;
}
final String value = target.getString(key);
return !TextUtils.isEmpty(value);
}
示例13: fromReactMap
import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
private static LocationOptions fromReactMap(ReadableMap map) {
// precision might be dropped on timeout (double -> int conversion), but that's OK
long timeout =
map.hasKey("timeout") ? (long) map.getDouble("timeout") : Long.MAX_VALUE;
double maximumAge =
map.hasKey("maximumAge") ? map.getDouble("maximumAge") : Double.POSITIVE_INFINITY;
boolean highAccuracy =
map.hasKey("enableHighAccuracy") && map.getBoolean("enableHighAccuracy");
float distanceFilter = map.hasKey("distanceFilter") ?
(float) map.getDouble("distanceFilter") :
RCT_DEFAULT_LOCATION_ACCURACY;
return new LocationOptions(timeout, maximumAge, highAccuracy, distanceFilter);
}
示例14: setSource
import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
@ReactProp(name = "source")
public void setSource(PLVideoView mVideoView, ReadableMap source) {
AVOptions options = new AVOptions();
String uri = source.getString("uri");
boolean mediaController = source.hasKey("controller") && source.getBoolean("controller");
int avFrameTimeout = source.hasKey("timeout") ? source.getInt("timeout") : -1; //10 * 1000 ms
//boolean liveStreaming = source.hasKey("live") && source.getBoolean("live"); //1 or 0 // 1 -> live
boolean codec = source.hasKey("hardCodec") && source.getBoolean("hardCodec"); //1 or 0 // 1 -> hw codec enable, 0 -> disable [recommended]
// the unit of timeout is ms
if (avFrameTimeout >= 0) {
options.setInteger(AVOptions.KEY_PREPARE_TIMEOUT, avFrameTimeout);
}
// Some optimization with buffering mechanism when be set to 1
options.setInteger(AVOptions.KEY_LIVE_STREAMING, 1);
// }
// 1 -> hw codec enable, 0 -> disable [recommended]
if (codec) {
options.setInteger(AVOptions.KEY_MEDIACODEC, 1);
} else {
options.setInteger(AVOptions.KEY_MEDIACODEC, 0);
}
mVideoView.setAVOptions(options);
// After setVideoPath, the play will start automatically
// mVideoView.start() is not required
mVideoView.setVideoPath(uri);
// if (mediaController) {
// // You can also use a custom `MediaController` widget
// MediaController mMediaController = new MediaController(reactContext, false, isLiveStreaming(uri));
// mVideoView.setMediaController(mMediaController);
// }
}
示例15: extractHeaders
import com.facebook.react.bridge.ReadableMap; //导入方法依赖的package包/类
/**
* Extracts the headers from the Array. If the format is invalid, this method will return null.
*/
private @Nullable Headers extractHeaders(
@Nullable ReadableArray headersArray,
@Nullable ReadableMap requestData) {
if (headersArray == null) {
return null;
}
Headers.Builder headersBuilder = new Headers.Builder();
for (int headersIdx = 0, size = headersArray.size(); headersIdx < size; headersIdx++) {
ReadableArray header = headersArray.getArray(headersIdx);
if (header == null || header.size() != 2) {
return null;
}
String headerName = header.getString(0);
String headerValue = header.getString(1);
if (headerName == null || headerValue == null) {
return null;
}
headersBuilder.add(headerName, headerValue);
}
if (headersBuilder.get(USER_AGENT_HEADER_NAME) == null && mDefaultUserAgent != null) {
headersBuilder.add(USER_AGENT_HEADER_NAME, mDefaultUserAgent);
}
// Sanitize content encoding header, supported only when request specify payload as string
boolean isGzipSupported = requestData != null && requestData.hasKey(REQUEST_BODY_KEY_STRING);
if (!isGzipSupported) {
headersBuilder.removeAll(CONTENT_ENCODING_HEADER_NAME);
}
return headersBuilder.build();
}