Java Code Examples for androidx.fragment.app.FragmentActivity#runOnUiThread()
The following examples show how to use
androidx.fragment.app.FragmentActivity#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: FragmentOptionsConnection.java From FairEmail with GNU General Public License v3.0 | 6 votes |
private void showConnectionType() { FragmentActivity activity = getActivity(); if (activity == null) return; activity.runOnUiThread(new Runnable() { @Override public void run() { if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { ConnectionHelper.NetworkState networkState = ConnectionHelper.getNetworkState(getContext()); tvConnectionType.setText(networkState.isUnmetered() ? R.string.title_legend_unmetered : R.string.title_legend_metered); tvConnectionType.setVisibility(networkState.isConnected() ? View.VISIBLE : View.GONE); tvConnectionRoaming.setVisibility(networkState.isRoaming() ? View.VISIBLE : View.GONE); } } }); }
Example 2
Source File: ActivityScope.java From firebase-android-sdk with Apache License 2.0 | 6 votes |
private static void onFragmentActivityStopCallOnce(FragmentActivity activity, Runnable callback) { activity.runOnUiThread( () -> { StopListenerSupportFragment fragment = castFragment( StopListenerSupportFragment.class, activity.getSupportFragmentManager().findFragmentByTag(SUPPORT_FRAGMENT_TAG), SUPPORT_FRAGMENT_TAG); if (fragment == null || fragment.isRemoving()) { fragment = new StopListenerSupportFragment(); activity .getSupportFragmentManager() .beginTransaction() .add(fragment, SUPPORT_FRAGMENT_TAG) .commitAllowingStateLoss(); activity.getSupportFragmentManager().executePendingTransactions(); } fragment.callbacks.add(callback); }); }
Example 3
Source File: MediaItemsDataSource.java From YImagePicker with Apache License 2.0 | 6 votes |
/** * 回调所有数据 * * @param context FragmentActivity * @param imageItems 所有文件 * @param allVideoSet 当加载所有媒体库文件时,默认会生成一个全部视频的文件夹,是本地虚拟的文件夹 */ private void notifyMediaItem(final FragmentActivity context, final ArrayList<ImageItem> imageItems, final ImageSet allVideoSet) { context.runOnUiThread(new Runnable() { @Override public void run() { if (context.isDestroyed()) { return; } if (mediaItemProvider != null) { mediaItemProvider.providerMediaItems(imageItems, allVideoSet); } if (mLoaderManager != null) { mLoaderManager.destroyLoader(LOADER_ID); } } }); }
Example 4
Source File: KeychainModule.java From react-native-keychain with MIT License | 6 votes |
/** trigger interactive authentication. */ public void startAuthentication() { final FragmentActivity activity = (FragmentActivity) getCurrentActivity(); if (null == activity) throw new NullPointerException("Not assigned current activity"); // code can be executed only from MAIN thread if (Thread.currentThread() != Looper.getMainLooper().getThread()) { activity.runOnUiThread(this::startAuthentication); waitResult(); return; } final BiometricPrompt prompt = new BiometricPrompt(activity, executor, this); prompt.authenticate(this.promptInfo); }
Example 5
Source File: RuntimePermission.java From RuntimePermission with Apache License 2.0 | 5 votes |
/** * Ask for the permission. Which permission? Anything you register on your manifest that needs it. * It is safe to call this every time without querying `shouldAsk`. * In case you call `ask` without any permission, the method returns. */ public void ask() { final FragmentActivity activity = activityReference.get(); if (activity == null || activity.isFinishing()) { return; } //retrieve permissions we want final List<String> permissions = findNeededPermissions(activity); // No need to ask for permissions on API levels below Android Marshmallow if (permissions.isEmpty() || Build.VERSION.SDK_INT < Build.VERSION_CODES.M || arePermissionsAlreadyAccepted(activity, permissions)) { onAllAccepted(permissions); } else { final PermissionFragment oldFragment = (PermissionFragment) activity .getSupportFragmentManager() .findFragmentByTag(TAG); if (oldFragment != null) { oldFragment.setListener(listener); } else { final PermissionFragment newFragment = PermissionFragment.newInstance(permissions); newFragment.setListener(listener); activity.runOnUiThread(new Runnable() { @Override public void run() { activity.getSupportFragmentManager() .beginTransaction() .add(newFragment, TAG) .commitAllowingStateLoss(); // change to .commitNowAllowingStateLoss() to see the crash } }); } } }
Example 6
Source File: SmartLockHelper.java From samples-android with Apache License 2.0 | 5 votes |
private void showBiometricPromptCompat(FragmentActivity activity, FingerprintDialogCallbacks callback) { androidx.biometric.BiometricPrompt.PromptInfo promptInfo = new androidx.biometric.BiometricPrompt.PromptInfo.Builder() .setTitle(activity.getString(R.string.fingerprint_alert_title)) .setNegativeButtonText(activity.getString(R.string.cancel)) .build(); androidx.biometric.BiometricPrompt biometricPrompt = new androidx.biometric.BiometricPrompt(activity, Executors.newSingleThreadExecutor(), new androidx.biometric.BiometricPrompt.AuthenticationCallback() { @Override public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) { super.onAuthenticationError(errorCode, errString); if (errorCode == androidx.biometric.BiometricPrompt.ERROR_NEGATIVE_BUTTON) { callback.onFingerprintCancel(); } else { callback.onFingerprintError(errString.toString()); } } @Override public void onAuthenticationSucceeded(@NonNull androidx.biometric.BiometricPrompt.AuthenticationResult result) { super.onAuthenticationSucceeded(result); callback.onFingerprintSuccess(null); } @Override public void onAuthenticationFailed() { super.onAuthenticationFailed(); activity.runOnUiThread(() -> Toast.makeText(activity, "Fingerprint not recognized. Try again", Toast.LENGTH_SHORT).show()); } }); biometricPrompt.authenticate(promptInfo); }
Example 7
Source File: SmartLockHelper.java From samples-android with Apache License 2.0 | 5 votes |
private void showBiometricPromptCompat(FragmentActivity activity, FingerprintDialogCallbacks callback) { androidx.biometric.BiometricPrompt.PromptInfo promptInfo = new androidx.biometric.BiometricPrompt.PromptInfo.Builder() .setTitle(activity.getString(R.string.fingerprint_alert_title)) .setNegativeButtonText(activity.getString(R.string.cancel)) .build(); androidx.biometric.BiometricPrompt biometricPrompt = new androidx.biometric.BiometricPrompt(activity, Executors.newSingleThreadExecutor(), new androidx.biometric.BiometricPrompt.AuthenticationCallback() { @Override public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) { super.onAuthenticationError(errorCode, errString); if (errorCode == androidx.biometric.BiometricPrompt.ERROR_NEGATIVE_BUTTON) { callback.onFingerprintCancel(); } else { callback.onFingerprintError(errString.toString()); } } @Override public void onAuthenticationSucceeded(@NonNull androidx.biometric.BiometricPrompt.AuthenticationResult result) { super.onAuthenticationSucceeded(result); callback.onFingerprintSuccess(null); } @Override public void onAuthenticationFailed() { super.onAuthenticationFailed(); activity.runOnUiThread(() -> Toast.makeText(activity, "Fingerprint not recognized. Try again", Toast.LENGTH_SHORT).show()); } }); biometricPrompt.authenticate(promptInfo); }
Example 8
Source File: MediaItemsDataSource.java From YImagePicker with Apache License 2.0 | 5 votes |
/** * 回调预加载的媒体文件,主线程 * * @param context FragmentActivity * @param imageItems 预加载列表 */ private void notifyPreloadItem(final FragmentActivity context, final ArrayList<ImageItem> imageItems) { context.runOnUiThread(new Runnable() { @Override public void run() { if (context.isDestroyed()) { return; } preloadProvider.providerMediaItems(imageItems); preloadProvider = null; } }); }
Example 9
Source File: BaseFragment.java From igniter with GNU General Public License v3.0 | 4 votes |
protected void runOnUiThread(Runnable runnable) { FragmentActivity activity = getActivity(); if (activity != null) { activity.runOnUiThread(runnable); } }