@ReactMethod public void capture(final ReadableMap options, final Promise promise) { int orientation = options.hasKey("orientation") ? options.getInt("orientation") : RCTCamera.getInstance().getOrientation(); if (orientation == RCT_CAMERA_ORIENTATION_AUTO) { _sensorOrientationChecker.onResume(); _sensorOrientationChecker.registerOrientationListener(new RCTSensorOrientationListener() { @Override public void orientationEvent() { int deviceOrientation = _sensorOrientationChecker.getOrientation(); _sensorOrientationChecker.unregisterOrientationListener(); _sensorOrientationChecker.onPause(); captureWithOrientation(options, promise, deviceOrientation); } }); } else { captureWithOrientation(options, promise, orientation); } }
/** * 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; }
public FrescoBasedReactTextInlineImageSpan( Resources resources, int height, int width, @Nullable Uri uri, ReadableMap headers, AbstractDraweeControllerBuilder draweeControllerBuilder, @Nullable Object callerContext) { mDraweeHolder = new DraweeHolder( GenericDraweeHierarchyBuilder.newInstance(resources) .build() ); mDraweeControllerBuilder = draweeControllerBuilder; mCallerContext = callerContext; mHeight = height; mWidth = width; mUri = (uri != null) ? uri : Uri.EMPTY; mHeaders = headers; }
private Bundle createFragmentArguments(ReadableMap options) { final Bundle args = new Bundle(); if (options.hasKey(ARG_DATE) && !options.isNull(ARG_DATE)) { args.putLong(ARG_DATE, (long) options.getDouble(ARG_DATE)); } if (options.hasKey(ARG_MINDATE) && !options.isNull(ARG_MINDATE)) { args.putLong(ARG_MINDATE, (long) options.getDouble(ARG_MINDATE)); } if (options.hasKey(ARG_MAXDATE) && !options.isNull(ARG_MAXDATE)) { args.putLong(ARG_MAXDATE, (long) options.getDouble(ARG_MAXDATE)); } if (options.hasKey(ARG_MODE) && !options.isNull(ARG_MODE)) { args.putString(ARG_MODE, options.getString(ARG_MODE)); } return args; }
/** * Invoked by React to create a new node with a given tag, class name and properties. */ public void createView(int tag, String className, int rootViewTag, ReadableMap props) { ReactShadowNode cssNode = createShadowNode(className); ReactShadowNode rootNode = mShadowNodeRegistry.getNode(rootViewTag); cssNode.setReactTag(tag); cssNode.setViewClassName(className); cssNode.setRootNode(rootNode); cssNode.setThemedContext(rootNode.getThemedContext()); mShadowNodeRegistry.addNode(cssNode); ReactStylesDiffMap styles = null; if (props != null) { styles = new ReactStylesDiffMap(props); cssNode.updateProperties(styles); } handleCreateView(cssNode, rootViewTag, styles); }
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(); }
@ReactMethod public void startAnimatingNode( final int animationId, final int animatedNodeTag, final ReadableMap animationConfig, final Callback endCallback) { mOperations.add(new UIThreadOperation() { @Override public void execute(NativeAnimatedNodesManager animatedNodesManager) { animatedNodesManager.startAnimatingNode( animationId, animatedNodeTag, animationConfig, endCallback); } }); }
public void testArrayWithMaps() { mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnArrayWithMaps(); waitForBridgeAndUIIdle(); List<ReadableArray> calls = mRecordingTestModule.getArrayCalls(); assertEquals(1, calls.size()); ReadableArray array = calls.get(0); assertEquals(2, array.size()); assertFalse(array.isNull(0)); ReadableMap m1 = array.getMap(0); ReadableMap m2 = array.getMap(1); assertEquals("m1v1", m1.getString("m1k1")); assertEquals("m1v2", m1.getString("m1k2")); assertEquals("m2v1", m2.getString("m2k1")); }
private Intent createIntent(String action, ReadableMap extra) { final Intent intent = new Intent(action); for ( ReadableMapKeySetIterator it = extra.keySetIterator(); it.hasNextKey(); ) { String key = it.nextKey(); ReadableType type = extra.getType(key); switch(type) { case Null: break; case Boolean: intent.putExtra(key, extra.getBoolean(key)); break; case Number: intent.putExtra(key, extra.getInt(key)); break; case String: intent.putExtra(key, extra.getString(key)); break; default: throw new IllegalArgumentException("Unsupported type " + type); } } return intent; }
@ReactProp(name = PROP_SHADOW_OFFSET) public void setTextShadowOffset(ReadableMap offsetMap) { mTextShadowOffsetDx = 0; mTextShadowOffsetDy = 0; if (offsetMap != null) { if (offsetMap.hasKey(PROP_SHADOW_OFFSET_WIDTH) && !offsetMap.isNull(PROP_SHADOW_OFFSET_WIDTH)) { mTextShadowOffsetDx = PixelUtil.toPixelFromDIP(offsetMap.getDouble(PROP_SHADOW_OFFSET_WIDTH)); } if (offsetMap.hasKey(PROP_SHADOW_OFFSET_HEIGHT) && !offsetMap.isNull(PROP_SHADOW_OFFSET_HEIGHT)) { mTextShadowOffsetDy = PixelUtil.toPixelFromDIP(offsetMap.getDouble(PROP_SHADOW_OFFSET_HEIGHT)); } } markUpdated(); }
@ReactMethod public void createChannel(ReadableMap options, final Promise promise) { final JSONObject attributes = RCTConvert.readableMapToJson(options.getMap("attributes")); final String uniqueName = options.getString("uniqueName"); String friendlyName = options.getString("friendlyName"); Channel.ChannelType type = (options.getString("type").compareTo("CHANNEL_TYPE_PRIVATE") == 0) ? Channel.ChannelType.PRIVATE : Channel.ChannelType.PUBLIC; channels().channelBuilder() .withUniqueName(uniqueName) .withFriendlyName(friendlyName) .withType(type) .withAttributes(attributes) .build(new CallbackListener<Channel>() { @Override public void onError(final ErrorInfo errorInfo) { super.onError(errorInfo); promise.reject("create-channel-error", "Error occurred while attempting to createChannel."); } @Override public void onSuccess(final Channel newChannel) { promise.resolve(RCTConvert.Channel(newChannel)); } }); }
public 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("title")); setMenuItemIcon(item, action.getMap("icon")); if (action.getBoolean("disabled")) { item.setEnabled(false); } } } }
private void setIconSource(ReadableMap source, IconControllerListener controllerListener, DraweeHolder holder) { String uri = source != null ? source.getString("uri") : null; if (uri == null) { controllerListener.setIconImageInfo(null); controllerListener.setDrawable(null); } else if (uri.startsWith("http://") || uri.startsWith("https://") || uri.startsWith("file://")) { controllerListener.setIconImageInfo(getIconImageInfo(source)); DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(Uri.parse(uri)) .setControllerListener(controllerListener) .setOldController(holder.getController()) .build(); holder.setController(controller); holder.getTopLevelDrawable().setVisible(true, true); } else { controllerListener.setDrawable(getDrawableByName(uri)); } }
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; }
private ColorStateList buildColorStateList(ReadableMap colorMap) { int[][] states = new int[][] { new int[] { android.R.attr.state_checked }, new int[] {-android.R.attr.state_enabled }, new int[] { }, }; Map<String, String> colorStates = unifyColors(colorMap); int[] colors = new int[] { Color.parseColor(colorStates.get("active")), Color.parseColor(colorStates.get("disabled")), Color.parseColor(colorStates.get("default")) }; return new ColorStateList(states, colors); }
SocketClient(ReadableMap params, ReactContext reactContext) { //String addr, int port, boolean autoReconnect mReactContext = reactContext; dstAddress = params.getString("address"); dstPort = params.getInt("port"); if (params.hasKey("reconnect")) { reconnectOnClose = params.getBoolean("reconnect"); } if (params.hasKey("maxReconnectAttempts")) { maxReconnectAttempts = params.getInt("maxReconnectAttempts"); } if (params.hasKey("reconnectDelay")) { reconnectDelay = params.getInt("reconnectDelay"); } Thread socketClientThread = new Thread(new SocketClientThread()); socketClientThread.start(); }
public void testGetWrongTypeFromMap() { mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class) .returnMapWithStringDoubleIntMapArrayBooleanNull(); waitForBridgeAndUIIdle(); List<ReadableMap> calls = mRecordingTestModule.getMapCalls(); assertEquals(1, calls.size()); ReadableMap map = calls.get(0); assertUnexpectedTypeExceptionThrown(map, "string", "double"); assertUnexpectedTypeExceptionThrown(map, "double", "map"); assertUnexpectedTypeExceptionThrown(map, "int", "boolean"); assertUnexpectedTypeExceptionThrown(map, "map", "array"); assertUnexpectedTypeExceptionThrown(map, "array", "boolean"); assertUnexpectedTypeExceptionThrown(map, "boolean", "string"); }
private String[] getStringArray(ReadableMap map, String key) { ReadableArray array = getArray(map, key); if (array == null) return null; ArrayList<String> list = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { if (array.getType(i) == ReadableType.String) { String str = array.getString(i); if (!isEmpty(str)) { list.add(str); } } } String[] arr = new String[list.size()]; return list.toArray(arr); }
@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); } }
public AdditionAnimatedNode( ReadableMap config, NativeAnimatedNodesManager nativeAnimatedNodesManager) { mNativeAnimatedNodesManager = nativeAnimatedNodesManager; ReadableArray inputNodes = config.getArray("input"); mInputNodes = new int[inputNodes.size()]; for (int i = 0; i < mInputNodes.length; i++) { mInputNodes[i] = inputNodes.getInt(i); } }
@ReactMethod public void peerConnectionInit( ReadableMap configuration, ReadableMap constraints, int id) { PeerConnectionObserver observer = new PeerConnectionObserver(this, id); PeerConnection peerConnection = mFactory.createPeerConnection( parseRTCConfiguration(configuration), parseMediaConstraints(constraints), observer); observer.setPeerConnection(peerConnection); mPeerConnectionObservers.put(id, observer); }
@ReactMethod public void createAnimatedNode(final int tag, final ReadableMap config) { mOperations.add(new UIThreadOperation() { @Override public void execute(NativeAnimatedNodesManager animatedNodesManager) { animatedNodesManager.createAnimatedNode(tag, config); } }); }
@ReactMethod public void createDataChannel(final int peerConnectionId, String label, ReadableMap config) { // Forward to PeerConnectionObserver which deals with DataChannels // because DataChannel is owned by PeerConnection. PeerConnectionObserver pco = mPeerConnectionObservers.get(peerConnectionId); if (pco == null || pco.getPeerConnection() == null) { Log.d(TAG, "createDataChannel() peerConnection is null"); } else { pco.createDataChannel(label, config); } }
/** * 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(); }
@ReactMethod public void download(final ReadableMap params, Callback callback){ // 获取参数 String url = params.hasKey("url") ? params.getString("url") : null; String description = params.hasKey("description") ? params.getString("description") : "downloading"; // 判断是否未回调继续调用 if(rctCallback!=null){ WritableMap map = Arguments.createMap(); map.putInt("status", -2); map.putString("description", "busy"); map.putString("url",url); callback.invoke(map); return; } rctCallback = callback; rctParams = params; // 设置参数 DownloadManager.Request request = new Request(Uri.parse(url)); request.setAllowedNetworkTypes(Request.NETWORK_WIFI); request.setNotificationVisibility(Request.VISIBILITY_VISIBLE); // 是否通知 MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); String mimeString = mimeTypeMap.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(url)); request.setMimeType(mimeString); // 下载的文件类型 request.setTitle("下载"); // 通知栏的标题 request.setDescription(description); // 通知栏描述 request.setAllowedOverRoaming(false); //漫游网络是否可以下载 request.setAllowedOverMetered(false); request.setVisibleInDownloadsUi(true); //设置文件存放目录 request.setDestinationInExternalFilesDir(mApplicationContext, Environment.DIRECTORY_DOWNLOADS, description); mTaskId = downloadManager.enqueue(request); //注册广播接收者,监听下载状态 mApplicationContext.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); }
public static JSONObject toJSONObject(ReadableMap readableMap) throws JSONException { JSONObject jsonObject = new JSONObject(); ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); ReadableType type = readableMap.getType(key); switch (type) { case Null: jsonObject.put(key, null); break; case Boolean: jsonObject.put(key, readableMap.getBoolean(key)); break; case Number: jsonObject.put(key, readableMap.getDouble(key)); break; case String: jsonObject.put(key, readableMap.getString(key)); break; case Map: jsonObject.put(key, MapUtil.toJSONObject(readableMap.getMap(key))); break; case Array: jsonObject.put(key, ArrayUtil.toJSONArray(readableMap.getArray(key))); break; } } return jsonObject; }
FrameBasedAnimationDriver(ReadableMap config) { ReadableArray frames = config.getArray("frames"); int numberOfFrames = frames.size(); mFrames = new double[numberOfFrames]; for (int i = 0; i < numberOfFrames; i++) { mFrames[i] = frames.getDouble(i); } mToValue = config.getDouble("toValue"); mIterations = config.hasKey("iterations") ? config.getInt("iterations") : 1; mCurrentLoop = 1; mHasFinished = mIterations == 0; }
@Override public void loadWithConfig(ReadableMap config, RNWebGLTextureCompletionBlock callback) { int tag = config.getInt("view"); try { UIManagerModule uiManager = this.reactContext.getNativeModule(UIManagerModule.class); uiManager.addUIBlock(new RNWebGLTextureViewUIBlock(config, tag, callback)); } catch (Exception e) { callback.call(e, null); } }
private byte[] getBlobFromUri(ReadableMap map, String key) { if (map.hasKey(key) && map.getType(key) == ReadableType.String) { String uri = map.getString(key); if (uri != null && !uri.isEmpty()) { return byteArrayFromUrl(uri); } } return null; }
public ModulusAnimatedNode( ReadableMap config, NativeAnimatedNodesManager nativeAnimatedNodesManager) { mNativeAnimatedNodesManager = nativeAnimatedNodesManager; mInputNode = config.getInt("input"); mModulus = config.getInt("modulus"); }
@ReactMethod public void updateView(int tag, String className, ReadableMap props) { if (DEBUG) { FLog.d( ReactConstants.TAG, "(UIManager.updateView) tag: " + tag + ", class: " + className + ", props: " + props); } mUIImplementation.updateView(tag, className, props); }
/** * Main point of interaction from JS users - allows them to specify the scheduling etc for the * background task. * * Default values are specified in JS (more accessible for the average user). * * @param config the config options passed in from JS: * - period (required): how frequently to carry out the task in seconds * - timeout (required): after how many seconds should the task be auto-killed */ @ReactMethod public void schedule(final ReadableMap config) { Log.d(TAG, "@ReactMethod BackgroundTask.schedule"); // Period can't be below 15m int period = config.getInt("period"); if (period < 900) { period = 900; } // Flex must be between 5m and 15m int flex = config.getInt("flex"); if (flex < 300) { flex = 300; } if (flex > 900) { flex = 900; } // Extra info to store with the JobRequest PersistableBundleCompat extras = new PersistableBundleCompat(); extras.putInt("timeout", config.getInt("timeout")); mJobRequest = new JobRequest.Builder(RNJob.JOB_TAG) .setPeriodic(TimeUnit.SECONDS.toMillis(period), TimeUnit.SECONDS.toMillis(flex)) .setPersisted(true) .setExtras(extras) .build(); if (!mForeground) { commitSchedule(); } }
public void createAnimatedNode(int tag, ReadableMap config) { if (mAnimatedNodes.get(tag) != null) { throw new JSApplicationIllegalArgumentException("Animated node with tag " + tag + " already exists"); } String type = config.getString("type"); final AnimatedNode node; if ("style".equals(type)) { node = new StyleAnimatedNode(config, this); } else if ("value".equals(type)) { node = new ValueAnimatedNode(config); } else if ("props".equals(type)) { node = new PropsAnimatedNode(config, this); } else if ("interpolation".equals(type)) { node = new InterpolationAnimatedNode(config); } else if ("addition".equals(type)) { node = new AdditionAnimatedNode(config, this); } else if ("division".equals(type)) { node = new DivisionAnimatedNode(config, this); } else if ("multiplication".equals(type)) { node = new MultiplicationAnimatedNode(config, this); } else if ("modulus".equals(type)) { node = new ModulusAnimatedNode(config, this); } else if ("diffclamp".equals(type)) { node = new DiffClampAnimatedNode(config, this); } else if ("transform".equals(type)) { node = new TransformAnimatedNode(config, this); } else { throw new JSApplicationIllegalArgumentException("Unsupported node type: " + type); } node.mTag = tag; mAnimatedNodes.put(tag, node); mUpdatedNodes.put(tag, node); }