Java Code Examples for com.facebook.react.bridge.UiThreadUtil#runOnUiThread()
The following examples show how to use
com.facebook.react.bridge.UiThreadUtil#runOnUiThread() .
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: InCallManagerModule.java From react-native-incall-manager with ISC License | 6 votes |
private void manualTurnScreenOff() { Log.d(TAG, "manualTurnScreenOff()"); UiThreadUtil.runOnUiThread(new Runnable() { public void run() { Activity mCurrentActivity = getCurrentActivity(); if (mCurrentActivity == null) { Log.d(TAG, "ReactContext doesn't hava any Activity attached."); return; } Window window = mCurrentActivity.getWindow(); WindowManager.LayoutParams params = window.getAttributes(); lastLayoutParams = params; // --- store last param params.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF; // --- Dim as dark as possible. see BRIGHTNESS_OVERRIDE_OFF window.setAttributes(params); window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } }); }
Example 2
Source File: RNCustomKeyboardKitModule.java From react-native-custom-keyboard-kit with MIT License | 6 votes |
@ReactMethod public void switchSystemKeyboard(final int tag) { UiThreadUtil.runOnUiThread(new Runnable() { @Override public void run() { final Activity activity = getCurrentActivity(); final ReactEditText edit = getEditById(tag); if (edit == null) { return; } View keyboard = (View)edit.getTag(TAG_ID); if (keyboard.getParent() != null) { ((ViewGroup) keyboard.getParent()).removeView(keyboard); } UiThreadUtil.runOnUiThread(new Runnable() { @Override public void run() { ((InputMethodManager) getReactApplicationContext().getSystemService(Activity.INPUT_METHOD_SERVICE)).showSoftInput(edit, InputMethodManager.SHOW_IMPLICIT); } }); } }); }
Example 3
Source File: RNImmersiveModule.java From react-native-immersive with MIT License | 6 votes |
private void _addImmersiveListener() { final Activity activity = getCurrentActivity(); if (activity == null) return; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { UiThreadUtil.runOnUiThread(new Runnable() { @TargetApi(Build.VERSION_CODES.KITKAT) @Override public void run() { activity.getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { boolean isImmersiveOn = 0 != (visibility & UI_FLAG_IMMERSIVE); if (isImmersiveOn != _isImmersiveOn) { emitImmersiveStateChangeEvent(); } } }); } }); } }
Example 4
Source File: RNCustomKeyboardKitModule.java From react-native-custom-keyboard-kit with MIT License | 6 votes |
@ReactMethod public void doDelete(final int tag) { UiThreadUtil.runOnUiThread(new Runnable() { @Override public void run() { final Activity activity = getCurrentActivity(); final ReactEditText edit = getEditById(tag); if (edit == null) { return; } int start = Math.max(edit.getSelectionStart(), 0); int end = Math.max(edit.getSelectionEnd(), 0); if (start != end) { edit.getText().delete(start, end); } else if (start > 0){ edit.getText().delete(start, end+1); } } }); }
Example 5
Source File: DevSupportManagerImpl.java From react-native-GPay with MIT License | 5 votes |
@Override public void reloadSettings() { if (UiThreadUtil.isOnUiThread()) { reload(); } else { UiThreadUtil.runOnUiThread(new Runnable() { @Override public void run() { reload(); } }); } }
Example 6
Source File: DevLoadingViewController.java From react-native-GPay with MIT License | 5 votes |
public void showMessage(final String message) { if (!sEnabled) { return; } UiThreadUtil.runOnUiThread(new Runnable() { @Override public void run() { showInternal(message); } }); }
Example 7
Source File: NativeAnimatedNodesManager.java From react-native-GPay with MIT License | 5 votes |
@Override public void onEventDispatch(final Event event) { // Events can be dispatched from any thread so we have to make sure handleEvent is run from the // UI thread. if (UiThreadUtil.isOnUiThread()) { handleEvent(event); } else { UiThreadUtil.runOnUiThread(new Runnable() { @Override public void run() { handleEvent(event); } }); } }
Example 8
Source File: EventDispatcher.java From react-native-GPay with MIT License | 5 votes |
public void onCatalystInstanceDestroyed() { UiThreadUtil.runOnUiThread(new Runnable() { @Override public void run() { stopFrameCallback(); } }); }
Example 9
Source File: ToastModule.java From react-native-GPay with MIT License | 5 votes |
@ReactMethod public void showWithGravity(final String message, final int duration, final int gravity) { UiThreadUtil.runOnUiThread(new Runnable() { @Override public void run() { Toast toast = Toast.makeText(getReactApplicationContext(), message, duration); toast.setGravity(gravity, 0, 0); toast.show(); } }); }
Example 10
Source File: ViewRenderingTestCase.java From react-native-GPay with MIT License | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); List<ViewManager> viewManagers = Arrays.<ViewManager>asList(new ReactViewManager()); final UIManagerModule uiManager = new UIManagerModule(getContext(), viewManagers, 0); UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { uiManager.onHostResume(); } }); waitForIdleSync(); mCatalystInstance = ReactTestHelper.catalystInstanceBuilder(this) .addNativeModule(uiManager) .addNativeModule(new AndroidInfoModule(getContext())) .addNativeModule(new DeviceInfoModule(getContext())) .addNativeModule(new AppStateModule(getContext())) .addNativeModule(new FakeWebSocketModule()) .build(); mRootView = new ReactRootView(getContext()); mRootTag = uiManager.addRootView(mRootView); }
Example 11
Source File: ProgressBarTestCase.java From progress-bar-android with MIT License | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); List<ViewManager> viewManagers = Arrays.<ViewManager>asList( new ReactViewManager(), new ReactProgressBarViewManager()); mUIManager = new UIManagerModule(getContext(), viewManagers, 0); UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { mUIManager.onHostResume(); } }); waitForIdleSync(); mInstance = ReactTestHelper.catalystInstanceBuilder(this) .addNativeModule(mUIManager) .addNativeModule(new AndroidInfoModule(getContext())) .addNativeModule(new DeviceInfoModule(getContext())) .addNativeModule(new AppStateModule(getContext())) .addNativeModule(new FakeWebSocketModule()) .build(); mRootView = new ReactRootView(getContext()); DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); mRootView.setLayoutParams( new FrameLayout.LayoutParams(metrics.widthPixels, metrics.heightPixels)); int rootTag = mUIManager.addRootView(mRootView); mInstance.getJSModule(ProgressBarTestModule.class).renderProgressBarApplication(rootTag); waitForBridgeAndUIIdle(); }
Example 12
Source File: CatalystNativeJSToJavaParametersTestCase.java From react-native-GPay with MIT License | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); List<ViewManager> viewManagers = Arrays.<ViewManager>asList( new ReactViewManager()); final UIManagerModule mUIManager = new UIManagerModule(getContext(), viewManagers, 0); UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { mUIManager.onHostResume(); } }); waitForIdleSync(); mRecordingTestModule = new RecordingTestModule(); mCatalystInstance = ReactTestHelper.catalystInstanceBuilder(this) .addNativeModule(mRecordingTestModule) .addNativeModule(new AndroidInfoModule(getContext())) .addNativeModule(new DeviceInfoModule(getContext())) .addNativeModule(new AppStateModule(getContext())) .addNativeModule(new FakeWebSocketModule()) .addNativeModule(mUIManager) .build(); }
Example 13
Source File: RNCustomKeyboardKitModule.java From react-native-custom-keyboard-kit with MIT License | 5 votes |
@ReactMethod public void uninstall(final int tag) { UiThreadUtil.runOnUiThread(new Runnable() { @Override public void run() { final Activity activity = getCurrentActivity(); final ReactEditText edit = getEditById(tag); if (edit == null) { return; } edit.setTag(TAG_ID, null); } }); }
Example 14
Source File: ReactNativeBiometrics.java From react-native-biometrics with MIT License | 5 votes |
@ReactMethod public void simplePrompt(final ReadableMap params, final Promise promise) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { try { String cancelButtomText = params.getString("cancelButtonText"); String promptMessage = params.getString("promptMessage"); AuthenticationCallback authCallback = new SimplePromptCallback(promise); FragmentActivity fragmentActivity = (FragmentActivity) getCurrentActivity(); Executor executor = Executors.newSingleThreadExecutor(); BiometricPrompt biometricPrompt = new BiometricPrompt(fragmentActivity, executor, authCallback); PromptInfo promptInfo = new PromptInfo.Builder() .setDeviceCredentialAllowed(false) .setNegativeButtonText(cancelButtomText) .setTitle(promptMessage) .build(); biometricPrompt.authenticate(promptInfo); } catch (Exception e) { promise.reject("Error displaying local biometric prompt: " + e.getMessage(), "Error displaying local biometric prompt: " + e.getMessage()); } } }); } else { promise.reject("Cannot display biometric prompt on android versions below 6.0", "Cannot display biometric prompt on android versions below 6.0"); } }
Example 15
Source File: RNJitsiMeetModule.java From react-native-jitsi-meet with Apache License 2.0 | 5 votes |
@ReactMethod public void endCall() { UiThreadUtil.runOnUiThread(new Runnable() { @Override public void run() { if (mJitsiMeetViewReference.getJitsiMeetView() != null) { mJitsiMeetViewReference.getJitsiMeetView().leave(); } } }); }
Example 16
Source File: RNJitsiMeetModule.java From react-native-jitsi-meet with Apache License 2.0 | 5 votes |
@ReactMethod public void audioCall(String url, ReadableMap userInfo) { UiThreadUtil.runOnUiThread(new Runnable() { @Override public void run() { if (mJitsiMeetViewReference.getJitsiMeetView() != null) { RNJitsiMeetUserInfo _userInfo = new RNJitsiMeetUserInfo(); if (userInfo != null) { if (userInfo.hasKey("displayName")) { _userInfo.setDisplayName(userInfo.getString("displayName")); } if (userInfo.hasKey("email")) { _userInfo.setEmail(userInfo.getString("email")); } if (userInfo.hasKey("avatar")) { String avatarURL = userInfo.getString("avatar"); try { _userInfo.setAvatar(new URL(avatarURL)); } catch (MalformedURLException e) { } } } RNJitsiMeetConferenceOptions options = new RNJitsiMeetConferenceOptions.Builder() .setRoom(url) .setAudioOnly(true) .setUserInfo(_userInfo) .build(); mJitsiMeetViewReference.getJitsiMeetView().join(options); } } }); }
Example 17
Source File: RNJitsiMeetModule.java From react-native-jitsi-meet with Apache License 2.0 | 5 votes |
@ReactMethod public void call(String url, ReadableMap userInfo) { UiThreadUtil.runOnUiThread(new Runnable() { @Override public void run() { if (mJitsiMeetViewReference.getJitsiMeetView() != null) { RNJitsiMeetUserInfo _userInfo = new RNJitsiMeetUserInfo(); if (userInfo != null) { if (userInfo.hasKey("displayName")) { _userInfo.setDisplayName(userInfo.getString("displayName")); } if (userInfo.hasKey("email")) { _userInfo.setEmail(userInfo.getString("email")); } if (userInfo.hasKey("avatar")) { String avatarURL = userInfo.getString("avatar"); try { _userInfo.setAvatar(new URL(avatarURL)); } catch (MalformedURLException e) { } } } RNJitsiMeetConferenceOptions options = new RNJitsiMeetConferenceOptions.Builder() .setRoom(url) .setAudioOnly(false) .setUserInfo(_userInfo) .build(); mJitsiMeetViewReference.getJitsiMeetView().join(options); } } }); }
Example 18
Source File: ReactNativeBiometrics.java From react-native-biometrics with MIT License | 4 votes |
@ReactMethod public void createSignature(final ReadableMap params, final Promise promise) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { try { String cancelButtomText = params.getString("cancelButtonText"); String promptMessage = params.getString("promptMessage"); String payload = params.getString("payload"); Signature signature = Signature.getInstance("SHA256withRSA"); KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore"); keyStore.load(null); PrivateKey privateKey = (PrivateKey) keyStore.getKey(biometricKeyAlias, null); signature.initSign(privateKey); BiometricPrompt.CryptoObject cryptoObject = new BiometricPrompt.CryptoObject(signature); AuthenticationCallback authCallback = new CreateSignatureCallback(promise, payload); FragmentActivity fragmentActivity = (FragmentActivity) getCurrentActivity(); Executor executor = Executors.newSingleThreadExecutor(); BiometricPrompt biometricPrompt = new BiometricPrompt(fragmentActivity, executor, authCallback); PromptInfo promptInfo = new PromptInfo.Builder() .setDeviceCredentialAllowed(false) .setNegativeButtonText(cancelButtomText) .setTitle(promptMessage) .build(); biometricPrompt.authenticate(promptInfo, cryptoObject); } catch (Exception e) { promise.reject("Error signing payload: " + e.getMessage(), "Error generating signature: " + e.getMessage()); } } }); } else { promise.reject("Cannot generate keys on android versions below 6.0", "Cannot generate keys on android versions below 6.0"); } }
Example 19
Source File: DialogModule.java From react-native-GPay with MIT License | 4 votes |
@ReactMethod public void showAlert( ReadableMap options, Callback errorCallback, final Callback actionCallback) { final FragmentManagerHelper fragmentManagerHelper = getFragmentManagerHelper(); if (fragmentManagerHelper == null) { errorCallback.invoke("Tried to show an alert while not attached to an Activity"); return; } final Bundle args = new Bundle(); if (options.hasKey(KEY_TITLE)) { args.putString(AlertFragment.ARG_TITLE, options.getString(KEY_TITLE)); } if (options.hasKey(KEY_MESSAGE)) { args.putString(AlertFragment.ARG_MESSAGE, options.getString(KEY_MESSAGE)); } if (options.hasKey(KEY_BUTTON_POSITIVE)) { args.putString(AlertFragment.ARG_BUTTON_POSITIVE, options.getString(KEY_BUTTON_POSITIVE)); } if (options.hasKey(KEY_BUTTON_NEGATIVE)) { args.putString(AlertFragment.ARG_BUTTON_NEGATIVE, options.getString(KEY_BUTTON_NEGATIVE)); } if (options.hasKey(KEY_BUTTON_NEUTRAL)) { args.putString(AlertFragment.ARG_BUTTON_NEUTRAL, options.getString(KEY_BUTTON_NEUTRAL)); } if (options.hasKey(KEY_ITEMS)) { ReadableArray items = options.getArray(KEY_ITEMS); CharSequence[] itemsArray = new CharSequence[items.size()]; for (int i = 0; i < items.size(); i ++) { itemsArray[i] = items.getString(i); } args.putCharSequenceArray(AlertFragment.ARG_ITEMS, itemsArray); } if (options.hasKey(KEY_CANCELABLE)) { args.putBoolean(KEY_CANCELABLE, options.getBoolean(KEY_CANCELABLE)); } UiThreadUtil.runOnUiThread(new Runnable() { @Override public void run() { fragmentManagerHelper.showNewAlert(mIsInForeground, args, actionCallback); } }); }
Example 20
Source File: ReactInstanceManager.java From react-native-GPay with MIT License | 4 votes |
private void setupReactContext(final ReactApplicationContext reactContext) { Log.d(ReactConstants.TAG, "ReactInstanceManager.setupReactContext()"); ReactMarker.logMarker(PRE_SETUP_REACT_CONTEXT_END); ReactMarker.logMarker(SETUP_REACT_CONTEXT_START); Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "setupReactContext"); synchronized (mReactContextLock) { mCurrentReactContext = Assertions.assertNotNull(reactContext); } CatalystInstance catalystInstance = Assertions.assertNotNull(reactContext.getCatalystInstance()); catalystInstance.initialize(); mDevSupportManager.onNewReactContextCreated(reactContext); mMemoryPressureRouter.addMemoryPressureListener(catalystInstance); moveReactContextToCurrentLifecycleState(); ReactMarker.logMarker(ATTACH_MEASURED_ROOT_VIEWS_START); synchronized (mAttachedRootViews) { for (ReactRootView rootView : mAttachedRootViews) { attachRootViewToInstance(rootView); } } ReactMarker.logMarker(ATTACH_MEASURED_ROOT_VIEWS_END); ReactInstanceEventListener[] listeners = new ReactInstanceEventListener[mReactInstanceEventListeners.size()]; final ReactInstanceEventListener[] finalListeners = mReactInstanceEventListeners.toArray(listeners); UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { for (ReactInstanceEventListener listener : finalListeners) { listener.onReactContextInitialized(reactContext); } } }); Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); ReactMarker.logMarker(SETUP_REACT_CONTEXT_END); reactContext.runOnJSQueueThread( new Runnable() { @Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); } }); reactContext.runOnNativeModulesQueueThread( new Runnable() { @Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); } }); }