Example usage for com.facebook.react.bridge ReadableMap hasKey

List of usage examples for com.facebook.react.bridge ReadableMap hasKey

Introduction

In this page you can find the example usage for com.facebook.react.bridge ReadableMap hasKey.

Prototype

boolean hasKey(@NonNull String name);

Source Link

Usage

From source file:com.microsoft.aad.adal.ReactNativeAdalPlugin.java

License:Open Source License

@ReactMethod
public void tokenCacheDeleteItem(ReadableMap obj, Callback callback) {

    final AuthenticationContext authContext;
    String authority = obj.hasKey("authority") ? obj.getString("authority") : null;
    boolean validateAuthority = obj.hasKey("validateAuthority") ? obj.getBoolean("validateAuthority") : false;
    String resourceId = obj.hasKey("resourceId") ? obj.getString("resourceId") : null;
    String clientId = obj.hasKey("clientId") ? obj.getString("clientId") : null;
    String userId = obj.hasKey("userId") ? obj.getString("userId") : null;
    String itemAuthority = obj.hasKey("itemAuthority") ? obj.getString("itemAuthority") : null;
    boolean isMultipleResourceRefreshToken = obj.hasKey("isMultipleResourceRefreshToken")
            ? obj.getBoolean("isMultipleResourceRefreshToken")
            : false;/*from www  . j a va  2s.  com*/

    try {
        authContext = getOrCreateContext(authority, validateAuthority);
    } catch (Exception e) {
        callback.invoke(e.getMessage());
        return;
    }

    String key = CacheKey.createCacheKey(itemAuthority, resourceId, clientId, isMultipleResourceRefreshToken,
            userId, "1");
    authContext.getCache().removeItem(key);

    callback.invoke();
}

From source file:com.microsoft.aad.adal.ReactNativeAdalPlugin.java

License:Open Source License

@ReactMethod
public void tokenCacheClear(ReadableMap obj, Callback callback) {
    final AuthenticationContext authContext;
    String authority = obj.hasKey("authority") ? obj.getString("authority") : null;
    boolean validateAuthority = obj.hasKey("validateAuthority") ? obj.getBoolean("validateAuthority") : false;
    try {/* www .j a  v  a  2s. c  om*/
        authContext = getOrCreateContext(authority, validateAuthority);
    } catch (Exception e) {
        callback.invoke(e.getMessage());
        return;
    }

    authContext.getCache().removeAll();
    callback.invoke();
}

From source file:com.microsoft.aad.adal.ReactNativeAdalPlugin.java

License:Open Source License

@ReactMethod
public void setUseBroker(ReadableMap obj, Callback callback) {

    boolean useBroker = obj.hasKey("useBroker") ? obj.getBoolean("useBroker") : false;
    this.permissionCallback = callback;
    try {//from  ww w.  j  a v a 2 s .  c  o m
        AuthenticationSettings.INSTANCE.setUseBroker(useBroker);

        // Android 6.0 "Marshmallow" introduced a new permissions model where the user can turn on and off permissions as necessary.
        // This means that applications must handle these permission in run time.
        // http://cordova.apache.org/docs/en/latest/guide/platforms/android/plugin.html#android-permissions
        if (useBroker && Build.VERSION.SDK_INT >= 23 /* Build.VERSION_CODES.M */ ) {

            requestBrokerPermissions();
            // Cordova callback will be handled by requestBrokerPermissions method
        }

    } catch (Exception e) {
        callback.invoke(e.getMessage());
    }
}

From source file:com.microsoft.appcenter.reactnative.crashes.AppCenterReactNativeCrashesModule.java

License:Open Source License

@ReactMethod
public void sendErrorAttachments(ReadableArray attachments, String errorId) {
    try {/*from   w  w  w .j av  a 2  s .c o m*/
        Collection<ErrorAttachmentLog> attachmentLogs = new LinkedList<>();
        for (int i = 0; i < attachments.size(); i++) {
            ReadableMap jsAttachment = attachments.getMap(i);
            String fileName = null;
            if (jsAttachment.hasKey(FILE_NAME_FIELD)) {
                fileName = jsAttachment.getString(FILE_NAME_FIELD);
            }
            if (jsAttachment.hasKey(TEXT_FIELD)) {
                String text = jsAttachment.getString(TEXT_FIELD);
                attachmentLogs.add(ErrorAttachmentLog.attachmentWithText(text, fileName));
            } else {
                String encodedData = jsAttachment.getString(DATA_FIELD);
                byte[] data = Base64.decode(encodedData, Base64.DEFAULT);
                String contentType = jsAttachment.getString(CONTENT_TYPE_FIELD);
                attachmentLogs.add(ErrorAttachmentLog.attachmentWithBinary(data, fileName, contentType));
            }
        }
        WrapperSdkExceptionManager.sendErrorAttachments(errorId, attachmentLogs);
    } catch (Exception e) {
        AppCenterReactNativeCrashesUtils.logError("Failed to get error attachment for report: " + errorId);
        AppCenterReactNativeCrashesUtils.logError(Log.getStackTraceString(e));
    }
}

From source file:com.phxrb.CWebView.RNWebViewManager.java

License:Open Source License

@ReactProp(name = "source")
public void setSource(WebView view, @Nullable ReadableMap source) {
    if (source != null) {
        if (source.hasKey("html")) {
            String html = source.getString("html");
            if (source.hasKey("baseUrl")) {
                view.loadDataWithBaseURL(source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING,
                        null);//ww  w  .j av  a 2s  .c  om
            } else {
                view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING);
            }
            return;
        }
        if (source.hasKey("uri")) {
            String url = source.getString("uri");
            String previousUrl = view.getUrl();
            if (previousUrl != null && previousUrl.equals(url)) {
                return;
            }
            if (source.hasKey("method")) {
                String method = source.getString("method");
                if (method.equals(HTTP_METHOD_POST)) {
                    byte[] postData = null;
                    if (source.hasKey("body")) {
                        String body = source.getString("body");
                        try {
                            postData = body.getBytes("UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            postData = body.getBytes();
                        }
                    }
                    if (postData == null) {
                        postData = new byte[0];
                    }
                    view.postUrl(url, postData);
                    return;
                }
            }
            HashMap<String, String> headerMap = new HashMap<>();
            if (source.hasKey("headers")) {
                ReadableMap headers = source.getMap("headers");
                ReadableMapKeySetIterator iter = headers.keySetIterator();
                while (iter.hasNextKey()) {
                    String key = iter.nextKey();
                    if ("user-agent".equals(key.toLowerCase(Locale.ENGLISH))) {
                        if (view.getSettings() != null) {
                            view.getSettings().setUserAgentString(headers.getString(key));
                        }
                    } else {
                        headerMap.put(key, headers.getString(key));
                    }
                }
            }
            view.loadUrl(url, headerMap);
            return;
        }
    }
    view.loadUrl(BLANK_URL);
}

From source file:com.pspdfkit.react.ConfigurationAdapter.java

License:Open Source License

public ConfigurationAdapter(@NonNull Context context, ReadableMap configuration) {
    ReadableMapKeySetIterator iterator = configuration.keySetIterator();
    boolean hasConfiguration = iterator.hasNextKey();
    this.configuration = new PdfActivityConfiguration.Builder(context);
    if (hasConfiguration) {
        if (configuration.hasKey(PAGE_SCROLL_DIRECTION)) {
            configurePageScrollDirection(configuration.getString(PAGE_SCROLL_DIRECTION));
        }//from   w  w w.  j  a  v a 2s  .  c om
        if (configuration.hasKey(PAGE_SCROLL_CONTINUOUS)) {
            configurePageScrollContinuous(configuration.getBoolean(PAGE_SCROLL_CONTINUOUS));
        }
        if (configuration.hasKey(FIT_PAGE_TO_WIDTH)) {
            configureFitPageToWidth(configuration.getBoolean(FIT_PAGE_TO_WIDTH));
        }
        if (configuration.hasKey(INLINE_SEARCH)) {
            configureInlineSearch(configuration.getBoolean(INLINE_SEARCH));
        }
        if (configuration.hasKey(USER_INTERFACE_VIEW_MODE)) {
            configureUserInterfaceViewMode(configuration.getString(USER_INTERFACE_VIEW_MODE));
        }
        if (configuration.hasKey(START_PAGE)) {
            configureStartPage(configuration.getInt(START_PAGE));
        }
        if (configuration.hasKey(SHOW_SEARCH_ACTION)) {
            configureShowSearchAction(configuration.getBoolean(SHOW_SEARCH_ACTION));
        }
        if (configuration.hasKey(IMMERSIVE_MODE)) {
            configureImmersiveMode(configuration.getBoolean(IMMERSIVE_MODE));
        }
        if (configuration.hasKey(SHOW_THUMBNAIL_GRID_ACTION)) {
            configureShowThumbnailGridAction(configuration.getBoolean(SHOW_THUMBNAIL_GRID_ACTION));
        }
        if (configuration.hasKey(SHOW_OUTLINE_ACTION)) {
            configureShowOutlineAction(configuration.getBoolean(SHOW_OUTLINE_ACTION));
        }
        if (configuration.hasKey(SHOW_ANNOTATION_LIST_ACTION)) {
            configureShowAnnotationListAction(configuration.getBoolean(SHOW_ANNOTATION_LIST_ACTION));
        }
        if (configuration.hasKey(SHOW_PAGE_NUMBER_OVERLAY)) {
            configureShowPageNumberOverlay(configuration.getBoolean(SHOW_PAGE_NUMBER_OVERLAY));
        }
        if (configuration.hasKey(SHOW_PAGE_LABELS)) {
            configureShowPageLabels(configuration.getBoolean(SHOW_PAGE_LABELS));
        }
        if (configuration.hasKey(GRAY_SCALE)) {
            configureGrayScale(configuration.getBoolean(GRAY_SCALE));
        }
        if (configuration.hasKey(INVERT_COLORS)) {
            configureInvertColors(configuration.getBoolean(INVERT_COLORS));
        }
        if (configuration.hasKey(ENABLE_ANNOTATION_EDITING)) {
            configureEnableAnnotationEditing(configuration.getBoolean(ENABLE_ANNOTATION_EDITING));
        }
        if (configuration.hasKey(SHOW_SHARE_ACTION)) {
            configureShowShareAction(configuration.getBoolean(SHOW_SHARE_ACTION));
        }
        if (configuration.hasKey(SHOW_PRINT_ACTION)) {
            configureShowPrintAction(configuration.getBoolean(SHOW_PRINT_ACTION));
        }
        if (configuration.hasKey(ENABLE_TEXT_SELECTION)) {
            configureEnableTextSelection(configuration.getBoolean(ENABLE_TEXT_SELECTION));
        }
        if (configuration.hasKey(SHOW_THUMBNAIL_BAR)) {
            configureShowThumbnailBar(configuration.getString(SHOW_THUMBNAIL_BAR));
        }
        if (configuration.hasKey(SHOW_DOCUMENT_INFO_VIEW)) {
            configureDocumentInfoView(configuration.getBoolean(SHOW_DOCUMENT_INFO_VIEW));
        }
        if (configuration.hasKey(SHOW_DOCUMENT_TITLE_OVERLAY)) {
            configureShowDocumentTitleOverlay(configuration.getBoolean(SHOW_DOCUMENT_TITLE_OVERLAY));
        }
        if (configuration.hasKey(PAGE_MODE)) {
            configurePageMode(configuration.getString(PAGE_MODE));
        }
        if (configuration.hasKey(FIRST_PAGE_ALWAYS_SINGLE)) {
            configureFirstPageAlwaysSingle(configuration.getBoolean(FIRST_PAGE_ALWAYS_SINGLE));
        }
    }
}

From source file:com.reactlibrary.SGScanditPicker.java

License:Apache License

@Override
public void receiveCommand(BarcodePicker view, int commandType, @Nullable final ReadableArray args) {

    int argCount = args == null ? 0 : args.size();
    final WritableMap promiseResponse = Arguments.createMap();
    if (argCount > 0) {
        if (args.getType(args.size() - 1) == ReadableType.Map) {
            ReadableMap map = args.getMap(args.size() - 1);
            if (map.hasKey("commandid")) {
                int commandid = map.getInt("commandid");
                promiseResponse.putInt("commandid", commandid);
                argCount--;/*from w w  w  .  j  av a 2  s.  c om*/
            }
        }
    }

    switch (commandType) {
    case COMMAND_STOP_SCANNING: {
        picker.stopScanning();
        return;
    }
    case COMMAND_START_SCANNING: {
        picker.startScanning(false, new Runnable() {
            @Override
            public void run() {
                new PromiseSender(promiseResponse) {
                    @Override
                    public Object getResponse() {
                        return "Scan started";
                    }
                };
            }
        });
        return;
    }
    case COMMAND_START_SCANNING_IN_PAUSED_STATE: {
        picker.startScanning(true);
        return;
    }
    case COMMAND_PAUSE_SCANNING: {
        picker.pauseScanning();
        return;
    }
    case COMMAND_SET_SETTINGS: {
        if (argCount > 0) {
            ReadableMap map = args.getMap(0);
            setSettings(null, map);
            new PromiseSender(promiseResponse) {
                @Override
                public Object getResponse() {
                    return ScanditBarcodeHelpers.scanSettingsToWritableMap(scanSettings);
                }
            };
        } else {
            final int c = argCount;
            new PromiseSender(promiseResponse) {
                @Override
                public Object getResponse() {
                    promiseFailed = true;
                    return "Cannot set null settings" + c;
                }
            };
        }
        return;
    }
    case COMMAND_GET_SETTINGS: {
        new PromiseSender(promiseResponse) {
            @Override
            public Object getResponse() {
                return ScanditBarcodeHelpers.scanSettingsToWritableMap(scanSettings);
            }
        };
        emitSettings();
        return;
    }

    default:
        throw new IllegalArgumentException(String.format(Locale.ENGLISH,
                "Unsupported command %d received by %s.", commandType, getClass().getSimpleName()));
    }
}

From source file:com.roihuapp.CacheClearableWebViewManager.java

License:Open Source License

@ReactProp(name = "source")
public void setSource(WebView view, @Nullable ReadableMap source) {
    if (source != null) {
        if (source.hasKey("html")) {
            String html = source.getString("html");
            if (source.hasKey("baseUrl")) {
                view.loadDataWithBaseURL(source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING,
                        null);// w w w  .java2s  .  c o m
            } else {
                view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING);
            }
            return;
        }
        if (source.hasKey("uri")) {
            String url = source.getString("uri");
            if (source.hasKey("method")) {
                String method = source.getString("method");
                if (method.equals(HTTP_METHOD_POST)) {
                    byte[] postData = null;
                    if (source.hasKey("body")) {
                        String body = source.getString("body");
                        try {
                            postData = body.getBytes("UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            postData = body.getBytes();
                        }
                    }
                    if (postData == null) {
                        postData = new byte[0];
                    }
                    view.postUrl(url, postData);
                    return;
                }
            }
            HashMap<String, String> headerMap = new HashMap<>();
            if (source.hasKey("headers")) {
                ReadableMap headers = source.getMap("headers");
                ReadableMapKeySetIterator iter = headers.keySetIterator();
                while (iter.hasNextKey()) {
                    String key = iter.nextKey();
                    headerMap.put(key, headers.getString(key));
                }
            }
            view.loadUrl(url, headerMap);
            return;
        }
    }
    view.loadUrl(BLANK_URL);
}

From source file:com.shahenlibrary.Trimmer.Trimmer.java

License:Open Source License

public static void compress(String source, ReadableMap options, final Promise promise,
        final OnCompressVideoListener cb, ThemedReactContext tctx, ReactApplicationContext rctx) {
    Log.d(LOG_TAG, "OPTIONS: " + options.toString());

    Context ctx = tctx != null ? tctx : rctx;

    ReadableMap videoMetadata = getVideoRequiredMetadata(source, ctx);
    int videoWidth = videoMetadata.getInt("width");
    int videoHeight = videoMetadata.getInt("height");
    int videoBitrate = videoMetadata.getInt("bitrate");

    int width = options.hasKey("width") ? (int) (options.getDouble("width")) : 0;
    int height = options.hasKey("height") ? (int) (options.getDouble("height")) : 0;

    if (width != 0 && height != 0 && videoWidth != 0 && videoHeight != 0) {
        ReadableMap sizes = formatWidthAndHeightForFfmpeg(width, height, videoWidth, videoHeight);
        width = sizes.getInt("width");
        height = sizes.getInt("height");
    }/*  w w w.  jav a  2 s  .  c  o m*/

    Double minimumBitrate = options.hasKey("minimumBitrate") ? options.getDouble("minimumBitrate") : null;
    Double bitrateMultiplier = options.hasKey("bitrateMultiplier") ? options.getDouble("bitrateMultiplier")
            : 1.0;
    Boolean removeAudio = options.hasKey("removeAudio") ? options.getBoolean("removeAudio") : false;

    Double averageBitrate = videoBitrate / bitrateMultiplier;

    if (minimumBitrate != null) {
        if (averageBitrate < minimumBitrate) {
            averageBitrate = minimumBitrate;
        }
        if (videoBitrate < minimumBitrate) {
            averageBitrate = videoBitrate * 1.0;
        }
    }

    Log.d(LOG_TAG, "getVideoRequiredMetadata: averageBitrate - " + Double.toString(averageBitrate));

    final File tempFile = createTempFile("mp4", promise, ctx);

    ArrayList<String> cmd = new ArrayList<String>();
    cmd.add("-y");
    cmd.add("-i");
    cmd.add(source);
    cmd.add("-c:v");
    cmd.add("libx264");
    cmd.add("-b:v");
    cmd.add(Double.toString(averageBitrate / 1000) + "K");
    cmd.add("-bufsize");
    cmd.add(Double.toString(averageBitrate / 2000) + "K");
    if (width != 0 && height != 0) {
        cmd.add("-vf");
        cmd.add("scale=" + Integer.toString(width) + ":" + Integer.toString(height));
    }

    cmd.add("-preset");
    cmd.add("ultrafast");
    cmd.add("-pix_fmt");
    cmd.add("yuv420p");

    if (removeAudio) {
        cmd.add("-an");
    }
    cmd.add(tempFile.getPath());

    executeFfmpegCommand(cmd, tempFile.getPath(), rctx, promise, "compress error", cb);
}

From source file:com.shahenlibrary.Trimmer.TrimmerManager.java

License:Open Source License

@ReactMethod
public void getPreviewImageAtPosition(ReadableMap options, Promise promise) {
    String source = options.getString("source");
    double sec = options.hasKey("second") ? options.getDouble("second") : 0;
    String format = options.hasKey("format") ? options.getString("format") : null;
    Trimmer.getPreviewImageAtPosition(source, sec, format, promise, reactContext);
}