com.facebook.react.bridge.ReactMethod Java Examples

The following examples show how to use com.facebook.react.bridge.ReactMethod. 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: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 7 votes vote down vote up
@ReactMethod
public void play(final int reactTag) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.play();
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example #2
Source File: TcpSocketModule.java    From react-native-tcp-socket with MIT License 6 votes vote down vote up
@SuppressLint("StaticFieldLeak")
@SuppressWarnings("unused")
@ReactMethod
public void end(final Integer cId) {
    new GuardedAsyncTask<Void, Void>(mReactContext.getExceptionHandler()) {
        @Override
        protected void doInBackgroundGuarded(Void... params) {
            TcpSocketClient socketClient = socketClients.get(cId);
            if (socketClient == null) {
                return;
            }
            socketClient.close();
            socketClients.remove(cId);
        }
    }.executeOnExecutor(executorService);
}
 
Example #3
Source File: EscPosModule.java    From react-native-esc-pos with MIT License 6 votes vote down vote up
@ReactMethod
public void setPrintingSize(String printingSize) {
    int charsOnLine;
    int printingWidth;

    switch (printingSize) {
    case PRINTING_SIZE_80_MM:
        charsOnLine = LayoutBuilder.CHARS_ON_LINE_80_MM;
        printingWidth = PrinterService.PRINTING_WIDTH_80_MM;
        break;

    case PRINTING_SIZE_58_MM:
    default:
        charsOnLine = LayoutBuilder.CHARS_ON_LINE_58_MM;
        printingWidth = PrinterService.PRINTING_WIDTH_58_MM;
    }

    printerService.setCharsOnLine(charsOnLine);
    printerService.setPrintingWidth(printingWidth);
}
 
Example #4
Source File: RNStripeTerminalModule.java    From react-native-stripe-terminal with MIT License 6 votes vote down vote up
@ReactMethod
public void installUpdate(){
    pendingInstallUpdate = Terminal.getInstance().installUpdate(readerSoftwareUpdate,this, new Callback() {
        @Override
        public void onSuccess() {
            sendEventWithName(EVENT_UPDATE_INSTALL,Arguments.createMap());
            readerSoftwareUpdate = null;
        }

        @Override
        public void onFailure(@Nonnull TerminalException e) {
            WritableMap errorMap = Arguments.createMap();
            errorMap.putString(ERROR,e.getErrorMessage());
            sendEventWithName(EVENT_UPDATE_INSTALL,errorMap);
        }
    });
}
 
Example #5
Source File: ReactNativeGetLocationModule.java    From react-native-get-location with MIT License 6 votes vote down vote up
@ReactMethod
public void openWifiSettings(final Promise primise) {
    try {
        SettingsUtil.openWifiSettings(getReactApplicationContext());
        primise.resolve(null);
    } catch (Throwable ex) {
        primise.reject(ex);
    }
}
 
Example #6
Source File: RNStripeTerminalModule.java    From react-native-stripe-terminal with MIT License 6 votes vote down vote up
@ReactMethod
public void disconnectReader(){
   if(Terminal.getInstance().getConnectedReader()==null){
       sendEventWithName(EVENT_READER_DISCONNECTION_COMPLETION,Arguments.createMap());
   }else{
       Terminal.getInstance().disconnectReader(new Callback() {
           @Override
           public void onSuccess() {
               sendEventWithName(EVENT_READER_DISCONNECTION_COMPLETION,Arguments.createMap());
           }

           @Override
           public void onFailure(@Nonnull TerminalException e) {
                WritableMap errorMap = Arguments.createMap();
                errorMap.putString(ERROR,e.getErrorMessage());
                sendEventWithName(EVENT_READER_DISCONNECTION_COMPLETION,errorMap);
           }
       });
   }
}
 
Example #7
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void toggleSpeed(final int reactTag) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          float rate = playerView.mPlayer.getPlaybackRate();
          if (rate < 2) {
            playerView.mPlayer.setPlaybackRate(rate += 0.5);
          } else {
            playerView.mPlayer.setPlaybackRate((float) 0.5);
          }
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example #8
Source File: RNStripeTerminalModule.java    From react-native-stripe-terminal with MIT License 6 votes vote down vote up
@ReactMethod
public void processPayment(){
    Terminal.getInstance().processPayment(lastPaymentIntent, new PaymentIntentCallback() {
        @Override
        public void onSuccess(@Nonnull PaymentIntent paymentIntent) {
            lastPaymentIntent = paymentIntent;
            WritableMap processPaymentMap = Arguments.createMap();
            processPaymentMap.putMap(INTENT,serializePaymentIntent(paymentIntent,lastCurrency));
            sendEventWithName(EVENT_PROCESS_PAYMENT,processPaymentMap);
        }

        @Override
        public void onFailure(@Nonnull TerminalException e) {
            WritableMap errorMap = Arguments.createMap();
            errorMap.putString(ERROR,e.getErrorMessage());
            errorMap.putInt(CODE,e.getErrorCode().ordinal());
            errorMap.putString(DECLINE_CODE,e.getApiError().getDeclineCode());
            errorMap.putMap(INTENT,serializePaymentIntent(lastPaymentIntent,lastCurrency));
            sendEventWithName(EVENT_PROCESS_PAYMENT,errorMap);
        }
    });
}
 
Example #9
Source File: TcpSocketModule.java    From react-native-tcp-socket with MIT License 6 votes vote down vote up
@SuppressLint("StaticFieldLeak")
@SuppressWarnings("unused")
@ReactMethod
public void write(@NonNull final Integer cId, @NonNull final String base64String, @Nullable final Callback callback) {
    new GuardedAsyncTask<Void, Void>(mReactContext.getExceptionHandler()) {
        @Override
        protected void doInBackgroundGuarded(Void... params) {
            TcpSocketClient socketClient = socketClients.get(cId);
            if (socketClient == null) {
                return;
            }
            try {
                socketClient.write(Base64.decode(base64String, Base64.NO_WRAP));
                if (callback != null) {
                    callback.invoke();
                }
            } catch (IOException e) {
                if (callback != null) {
                    callback.invoke(e.toString());
                }
                onError(cId, e.toString());
            }
        }
    }.executeOnExecutor(executorService);
}
 
Example #10
Source File: TcpSocketModule.java    From react-native-tcp-socket with MIT License 6 votes vote down vote up
@SuppressLint("StaticFieldLeak")
@SuppressWarnings("unused")
@ReactMethod
public void listen(final Integer cId, final ReadableMap options) {
    new GuardedAsyncTask<Void, Void>(mReactContext.getExceptionHandler()) {
        @Override
        protected void doInBackgroundGuarded(Void... params) {
            try {
                TcpSocketServer server = new TcpSocketServer(socketClients, TcpSocketModule.this, cId, options);
                socketClients.put(cId, server);
                int port = options.getInt("port");
                String host = options.getString("host");
                onConnect(cId, host, port);
            } catch (Exception uhe) {
                onError(cId, uhe.getMessage());
            }
        }
    }.executeOnExecutor(executorService);
}
 
Example #11
Source File: RNStripeTerminalModule.java    From react-native-stripe-terminal with MIT License 6 votes vote down vote up
@ReactMethod
public void cancelPaymentIntent(){
    Terminal.getInstance().cancelPaymentIntent(lastPaymentIntent, new PaymentIntentCallback() {
        @Override
        public void onSuccess(@Nonnull PaymentIntent paymentIntent) {
            WritableMap paymentIntentCancelMap = Arguments.createMap();
            paymentIntentCancelMap.putMap(INTENT,serializePaymentIntent(paymentIntent,lastCurrency));
            sendEventWithName(EVENT_PAYMENT_INTENT_CANCEL,paymentIntentCancelMap);
        }

        @Override
        public void onFailure(@Nonnull TerminalException e) {
            WritableMap errorMap = Arguments.createMap();
            errorMap.putString(ERROR,e.getErrorMessage());
            errorMap.putInt(CODE,e.getErrorCode().ordinal());
            errorMap.putMap(INTENT,serializePaymentIntent(lastPaymentIntent,lastCurrency));
            sendEventWithName(EVENT_PAYMENT_INTENT_CANCEL,errorMap);
        }
    });
}
 
Example #12
Source File: RNStripeTerminalModule.java    From react-native-stripe-terminal with MIT License 6 votes vote down vote up
@ReactMethod
public void collectPaymentMethod(){
    pendingCreatePaymentIntent = Terminal.getInstance().collectPaymentMethod(lastPaymentIntent, this, new PaymentIntentCallback() {
        @Override
        public void onSuccess(@Nonnull PaymentIntent paymentIntent) {
            pendingCreatePaymentIntent = null;
            lastPaymentIntent = paymentIntent;
            WritableMap collectPaymentMethodMap = Arguments.createMap();
            collectPaymentMethodMap.putMap(INTENT,serializePaymentIntent(paymentIntent,lastCurrency));
            sendEventWithName(EVENT_PAYMENT_METHOD_COLLECTION,collectPaymentMethodMap);
        }

        @Override
        public void onFailure(@Nonnull TerminalException e) {
            pendingCreatePaymentIntent = null;
            WritableMap errorMap = Arguments.createMap();
            errorMap.putString(ERROR,e.getErrorMessage());
            errorMap.putInt(CODE,e.getErrorCode().ordinal());
            errorMap.putMap(INTENT,serializePaymentIntent(lastPaymentIntent,lastCurrency));
            sendEventWithName(EVENT_PAYMENT_METHOD_COLLECTION,errorMap);
        }
    });
}
 
Example #13
Source File: RNStripeTerminalModule.java    From react-native-stripe-terminal with MIT License 6 votes vote down vote up
@ReactMethod
public void abortCreatePayment(){
    if(pendingCreatePaymentIntent!=null && !pendingCreatePaymentIntent.isCompleted()){
        pendingCreatePaymentIntent.cancel(new Callback() {
            @Override
            public void onSuccess() {
                pendingCreatePaymentIntent = null;
                sendEventWithName(EVENT_ABORT_CREATE_PAYMENT_COMPLETION,Arguments.createMap());
            }

            @Override
            public void onFailure(@Nonnull TerminalException e) {
                WritableMap errorMap = Arguments.createMap();
                errorMap.putString(ERROR,e.getErrorMessage());
                sendEventWithName(EVENT_ABORT_CREATE_PAYMENT_COMPLETION,errorMap);
            }
        });
    }else{
        sendEventWithName(EVENT_ABORT_CREATE_PAYMENT_COMPLETION,Arguments.createMap());
    }
}
 
Example #14
Source File: RNWifiModule.java    From react-native-wifi-reborn with ISC License 6 votes vote down vote up
/**
 * Returns if the device is currently connected to a WiFi network.
 */
@ReactMethod
public void connectionStatus(final Promise promise) {
    final ConnectivityManager connectivityManager = (ConnectivityManager) getReactApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    if(connectivityManager == null) {
        promise.resolve(false);
        return;
    }

    NetworkInfo wifiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiInfo == null) {
        promise.resolve(false);
        return;
    }

    promise.resolve(wifiInfo.isConnected());
}
 
Example #15
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void setSpeed(final int reactTag, final float speed) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.setPlaybackRate(speed);
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example #16
Source File: RNWifiModule.java    From react-native-wifi-reborn with ISC License 6 votes vote down vote up
/**
 * This method will remove the wifi network configuration.
 * If you are connected to that network, it will disconnect.
 *
 * @param SSID wifi SSID to remove configuration for
 */
@ReactMethod
public void isRemoveWifiNetwork(final String SSID, final Promise promise) {
    final boolean locationPermissionGranted = PermissionUtils.isLocationPermissionGranted(context);
    if (!locationPermissionGranted) {
        promise.reject(IsRemoveWifiNetworkErrorCodes.locationPermissionMissing.toString(), "Location permission (ACCESS_FINE_LOCATION) is not granted");
        return;
    }

    final List<WifiConfiguration> mWifiConfigList = wifi.getConfiguredNetworks();
    final String comparableSSID = ('"' + SSID + '"'); //Add quotes because wifiConfig.SSID has them

    for (WifiConfiguration wifiConfig : mWifiConfigList) {
        if (wifiConfig.SSID.equals(comparableSSID)) {
            promise.resolve(wifi.removeNetwork(wifiConfig.networkId));
            wifi.saveConfiguration();
            return;
        }
    }

    promise.resolve(true);
}
 
Example #17
Source File: LayoutBuilderModule.java    From react-native-esc-pos with MIT License 6 votes vote down vote up
@ReactMethod
public void setPrintingSize(String printingSize) {
    int charsOnLine;

    switch (printingSize) {
    case EscPosModule.PRINTING_SIZE_80_MM:
        charsOnLine = LayoutBuilder.CHARS_ON_LINE_80_MM;
        break;

    case EscPosModule.PRINTING_SIZE_58_MM:
    default:
        charsOnLine = LayoutBuilder.CHARS_ON_LINE_58_MM;
    }

    layoutBuilder.setCharsOnLine(charsOnLine);
}
 
Example #18
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void stop(final int reactTag) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.stop();
          playerView.userPaused = true;
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example #19
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void seekTo(final int reactTag, final double time) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.seek(time);
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example #20
Source File: YouTubeSdkModule.java    From react-native-youtube-sdk with Apache License 2.0 5 votes vote down vote up
@ReactMethod
public void getCurrentTime(final int reactTag, final Promise promise) {
  try {
    UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(nvhm -> {
      YouTubeView youTubeView = (YouTubeView) nvhm.resolveView(reactTag);
      promise.resolve(youTubeView.getYouTubePlayerProps().getTracker().getCurrentSecond());
    });
  } catch (Exception e) {
    promise.reject("getCurrentTime", e);
  }
}
 
Example #21
Source File: EscPosModule.java    From react-native-esc-pos with MIT License 5 votes vote down vote up
@ReactMethod
public void initBluetoothConnectionListener() {
    // Add listener when bluetooth conencted
    reactContext.registerReceiver(bluetoothConnectionEventListener,
            new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED));

    // Add listener when bluetooth disconnected
    reactContext.registerReceiver(bluetoothConnectionEventListener,
            new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
}
 
Example #22
Source File: EscPosModule.java    From react-native-esc-pos with MIT License 5 votes vote down vote up
@ReactMethod
public void print(String text, Promise promise) {
    try {
        printerService.print(text);
        promise.resolve(true);
    } catch (UnsupportedEncodingException e) {
        promise.reject(e);
    }
}
 
Example #23
Source File: EscPosModule.java    From react-native-esc-pos with MIT License 5 votes vote down vote up
@ReactMethod
public void connectBluetoothPrinter(String address, Promise promise) {
    try {
        if (!"bluetooth".equals(config.getString("type"))) {
            promise.reject("config.type is not a bluetooth type");
        }
        Printer printer = new BluetoothPrinter(address);
        printerService = new PrinterService(printer);
        promise.resolve(true);
    } catch (IOException e) {
        promise.reject(e);
    }
}
 
Example #24
Source File: EscPosModule.java    From react-native-esc-pos with MIT License 5 votes vote down vote up
@ReactMethod
public void printBarcode(String code, String bc, int width, int height, String pos, String font, Promise promise) {
    try {
        printerService.printBarcode(code, bc, width, height, pos, font);
        promise.resolve(true);
    } catch (BarcodeSizeError e) {
        promise.reject(e);
    }
}
 
Example #25
Source File: RNWifiModule.java    From react-native-wifi-reborn with ISC License 5 votes vote down vote up
/**
 * Returns the IP of the currently connected WiFi network.
 */
@ReactMethod
public void getIP(final Promise promise) {
    final WifiInfo info = wifi.getConnectionInfo();
    final String stringIP = longToIP(info.getIpAddress());
    promise.resolve(stringIP);
}
 
Example #26
Source File: RNWifiModule.java    From react-native-wifi-reborn with ISC License 5 votes vote down vote up
/**
 * Returns the frequency of the currently connected WiFi network.
 */
@ReactMethod
public void getFrequency(final Promise promise) {
    final WifiInfo info = wifi.getConnectionInfo();
    final int frequency = info.getFrequency();
    promise.resolve(frequency);
}
 
Example #27
Source File: EscPosModule.java    From react-native-esc-pos with MIT License 5 votes vote down vote up
@ReactMethod
public void printImage(String filePath, Promise promise) {
    try {
        printerService.printImage(filePath);
        promise.resolve(true);
    } catch (IOException e) {
        promise.reject(e);
    }
}
 
Example #28
Source File: RNWifiModule.java    From react-native-wifi-reborn with ISC License 5 votes vote down vote up
/**
 * Returns the BSSID (basic service set identifier) of the currently connected WiFi network.
 */
@ReactMethod
public void getBSSID(final Promise promise) {
    final WifiInfo info = wifi.getConnectionInfo();
    final String bssid = info.getBSSID();
    promise.resolve(bssid.toUpperCase());
}
 
Example #29
Source File: EscPosModule.java    From react-native-esc-pos with MIT License 5 votes vote down vote up
@ReactMethod
public void connectNetworkPrinter(String address, int port, Promise promise) {
    try {
        if (!"network".equals(config.getString("type"))) {
            promise.reject("config.type is not a network type");
        }
        Printer printer = new NetworkPrinter(address, port);
        printerService = new PrinterService(printer);
        promise.resolve(true);
    } catch (IOException e) {
        promise.reject(e);
    }
}
 
Example #30
Source File: RNWifiModule.java    From react-native-wifi-reborn with ISC License 5 votes vote down vote up
/**
 * This method will return current SSID
 *
 * @param promise to send error/result feedback
 */
@ReactMethod
public void getCurrentWifiSSID(final Promise promise) {
    WifiInfo info = wifi.getConnectionInfo();

    // This value should be wrapped in double quotes, so we need to unwrap it.
    String ssid = info.getSSID();
    if (ssid.startsWith("\"") && ssid.endsWith("\"")) {
        ssid = ssid.substring(1, ssid.length() - 1);
    }

    promise.resolve(ssid);
}