Java Code Examples for android.app.Activity#runOnUiThread()
The following examples show how to use
android.app.Activity#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: Utils.java From flickr-uploader with GNU General Public License v2.0 | 7 votes |
private static void onPaymentAccepted(String method, final Activity activity, final Callback<Boolean> callback) { try { setPremium(true, true, true); activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onResult(true); } }); thankYou(activity); long firstInstallTime = FlickrUploader.getAppContext().getPackageManager().getPackageInfo(FlickrUploader.getAppContext().getPackageName(), 0).firstInstallTime; long timeSinceInstall = System.currentTimeMillis() - firstInstallTime; Utils.sendMail("[FlickrUploader] PremiumSuccess " + method + " - " + ToolString.formatDuration(timeSinceInstall) + " - " + getCountryCode(), Utils.getDeviceId() + " - " + Utils.getEmail() + " - " + Utils.getStringProperty(STR.userId) + " - " + Utils.getStringProperty(STR.userName)); } catch (Throwable e) { LOG.error(ToolString.stack2string(e)); } }
Example 2
Source File: BotInit.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
public void updateCommandList(boolean showCommandList, String message, Activity activity, boolean backToMenu) { activity.runOnUiThread(new Runnable() { @Override public void run() { fillList(message, backToMenu); if (botActionList.size() == 0) { return; } if (showCommandList) { makeTxtList(rootView); } else { makeButtonList(rootView); } setLayoutBot(false, false); } }); }
Example 3
Source File: UVCDeviceListFragment.java From DeviceConnect-Android with MIT License | 6 votes |
/** * Added the view at ListView. */ private void addFooterView() { final Activity activity = getActivity(); if (activity == null) { return; } activity.runOnUiThread(() -> { UVCDeviceManager mgr = getManager(); if (mgr == null) { return; } LayoutInflater inflater = activity.getLayoutInflater(); if (mFooterView != null) { mListView.removeFooterView(mFooterView); } if (mgr.getDeviceList().size() == 0) { mFooterView = inflater.inflate(R.layout.item_uvc_error, null); mListView.addFooterView(mFooterView); } }); }
Example 4
Source File: DictionarySettingsFragment.java From Indic-Keyboard with Apache License 2.0 | 6 votes |
@Override public void wordListDownloadFinished(final String wordListId, final boolean succeeded) { final WordListPreference pref = findWordListPreference(wordListId); if (null == pref) return; // TODO: Report to the user if !succeeded final Activity activity = getActivity(); if (null == activity) return; activity.runOnUiThread(new Runnable() { @Override public void run() { // We have to re-read the db in case the description has changed, and to // find out what state it ended up if the download wasn't successful // TODO: don't redo everything, only re-read and set this word list status refreshInterface(); } }); }
Example 5
Source File: Util.java From androidnative.pri with Apache License 2.0 | 6 votes |
static void setTranslucentStatusBar(Map message) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ) { return; } final Boolean value = (Boolean) message.get("value"); final Activity activity = QtNative.activity(); Runnable runnable = new Runnable () { public void run() { Window w = activity.getWindow(); // in Activity's onCreate() for instance if (value) { // w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } else { // w.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); w.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } } }; activity.runOnUiThread(runnable); }
Example 6
Source File: Util.java From PLDroidMediaStreaming with Apache License 2.0 | 5 votes |
public static void showToast(final Activity activity, final String msg) { activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(activity, msg, Toast.LENGTH_LONG).show(); } }); }
Example 7
Source File: AuthorizedServiceTask.java From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void handleAuthException(final Activity activity, final Exception e) { activity.runOnUiThread(new Runnable() { @Override public void run() { if (e instanceof GooglePlayServicesAvailabilityException) { // The Google Play services APK is old, disabled, or not present. // Show a dialog created by Google Play services that allows // the user to update the APK int statusCode = ((GooglePlayServicesAvailabilityException) e).getConnectionStatusCode(); Dialog dialog; if(authScope.equals(AUTH_PROXIMITY_API)) { dialog = GooglePlayServicesUtil.getErrorDialog( statusCode, activity, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_PRX_API); } else { dialog = GooglePlayServicesUtil.getErrorDialog( statusCode, activity, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_URL_SHORTNER); } dialog.show(); } else if (e instanceof UserRecoverableAuthException) { // Unable to authenticate, such as when the user has not yet granted // the app access to the account, but the user can fix this. // Forward the user to an activity in Google Play services. Intent intent = ((UserRecoverableAuthException) e).getIntent(); if(authScope.equals(AUTH_PROXIMITY_API)) { activity.startActivityForResult( intent, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_PRX_API); } else { activity.startActivityForResult( intent, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_URL_SHORTNER); } } } }); }
Example 8
Source File: UiUtils.java From tindroid with Apache License 2.0 | 5 votes |
static void setupToolbar(final Activity activity, final VxCard pub, final String topicName, final boolean online, final Date lastSeen) { if (activity == null || activity.isDestroyed() || activity.isFinishing()) { return; } final Toolbar toolbar = activity.findViewById(R.id.toolbar); if (toolbar == null) { return; } activity.runOnUiThread(new Runnable() { @Override public void run() { if (!TextUtils.isEmpty(topicName)) { final String title = pub != null && pub.fn != null ? pub.fn : activity.getString(R.string.placeholder_contact_title); toolbar.setTitle(title); if (lastSeen != null && !online) { toolbar.setSubtitle(relativeDateFormat(activity, lastSeen)); } else { toolbar.setSubtitle(null); } constructToolbarLogo(activity, pub != null ? pub.getBitmap() : null, pub != null ? pub.fn : null, topicName, online); } else { toolbar.setTitle(R.string.app_name); toolbar.setSubtitle(null); toolbar.setLogo(null); } } }); }
Example 9
Source File: SoomlaProfile.java From android-profile with Apache License 2.0 | 5 votes |
/** * Shares the given status to the user's feed with confirmation dialog and grants the user a reward. * * @param provider The provider to use * @param status The text to share * @param payload a String to receive when the function returns. * @param reward The reward to give the user * @param activity activity to use as context for the dialog * @param customMessage the message to show in the dialog * @throws ProviderNotFoundException if the supplied provider is not * supported by the framework */ public void updateStatusWithConfirmation(final IProvider.Provider provider, final String status, final String payload, final Reward reward, final Activity activity, final String customMessage) throws ProviderNotFoundException { final ISocialProvider socialProvider = mProviderManager.getSocialProvider(provider); if (activity != null) { final String message = customMessage != null ? customMessage : String.format("Are you sure you want to publish this message to %s: %s?", provider.toString(), status); activity.runOnUiThread(new Runnable() { @Override public void run() { new AlertDialog.Builder(activity) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle("Confirmation") .setMessage(message) .setPositiveButton("yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { internalUpdateStatus(socialProvider, provider, status, payload, reward); } }) .setNegativeButton("no", null) .show(); } }); } else { internalUpdateStatus(socialProvider, provider, status, payload, reward); } }
Example 10
Source File: Camera2BasicFragment.java From Android-Camera2-Front-with-Face-Detection with Apache License 2.0 | 5 votes |
/** * Shows a {@link Toast} on the UI thread. * * @param text The message to show */ private void showToast(final String text) { final Activity activity = getActivity(); if (activity != null) { activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(activity, text, Toast.LENGTH_SHORT).show(); } }); } }
Example 11
Source File: ColorPickerFragment.java From ColorBox-library with GNU General Public License v3.0 | 5 votes |
static void updatePreview(final Activity activity, final boolean isOnCreate, final Integer fromLatest, final View previewView, final SeekBar alphaSeekBar, final SeekBar RSeekBar, final SeekBar GSeekBar, final SeekBar BSeekBar) { activity.runOnUiThread(new Runnable() { @Override public void run() { int A = getColorARGB(0, alphaSeekBar, RSeekBar, GSeekBar, BSeekBar); int R = getColorARGB(1, alphaSeekBar, RSeekBar, GSeekBar, BSeekBar); int G = getColorARGB(2, alphaSeekBar, RSeekBar, GSeekBar, BSeekBar); int B = getColorARGB(3, alphaSeekBar, RSeekBar, GSeekBar, BSeekBar); int ARGB = getColorARGB(4, alphaSeekBar, RSeekBar, GSeekBar, BSeekBar); if (isOnCreate) { int savedColor = fromLatest != null ? fromLatest : ColorBox.getColor(ColorBox.getTag(), activity); A = Color.alpha(savedColor); R = Color.red(savedColor); G = Color.green(savedColor); B = Color.blue(savedColor); ARGB = savedColor; } alphaSeekBar.setProgress(A); RSeekBar.setProgress(R); GSeekBar.setProgress(G); BSeekBar.setProgress(B); previewView.setBackground(Utils.round(activity.getResources(), isLand(activity.getResources()), android.R.dimen.thumbnail_height, ARGB)); } }); }
Example 12
Source File: NowPlayingView.java From odyssey with GNU General Public License v3.0 | 5 votes |
@Override public void run() { Activity activity = (Activity) getContext(); // Run on the UI thread because we are updating gui elements if (activity != null) { activity.runOnUiThread(NowPlayingView.this::updateTrackPosition); } }
Example 13
Source File: CrosswalkWebViewGroupManager.java From react-native-webview-crosswalk with MIT License | 5 votes |
@ReactProp(name = "url") public void setUrl (final CrosswalkWebView view, @Nullable final String url) { Activity _activity = reactContext.getCurrentActivity(); if (_activity != null) { _activity.runOnUiThread(new Runnable() { @Override public void run () { view.load(url, null); } }); } }
Example 14
Source File: Utils.java From flickr-uploader with GNU General Public License v2.0 | 5 votes |
public static void confirmSignIn(final Activity context) { context.runOnUiThread(new Runnable() { @Override public void run() { AlertDialog alertDialog = new AlertDialog.Builder(context).setTitle("Sign into Flickr").setMessage("A Flickr account is required to upload photos.") .setPositiveButton("Sign in now", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { context.startActivityForResult(FlickrWebAuthActivity_.intent(context).get(), 14); } }).setNegativeButton("Later", null).setCancelable(false).show(); setButtonSize(alertDialog); } }); }
Example 15
Source File: UtilsGUI.java From WhereYouGo with GNU General Public License v3.0 | 5 votes |
public static void dialogDoItem(final Activity activity, final CharSequence title, final int icon, final CharSequence msg, final String posText, final DialogInterface.OnClickListener posLis, final String negText, final DialogInterface.OnClickListener negLis, final String cancelText, final DialogInterface.OnClickListener cancelLis) { activity.runOnUiThread(new Runnable() { public void run() { if (activity.isFinishing()) return; AlertDialog.Builder b = new AlertDialog.Builder(activity); b.setCancelable(true); b.setTitle(title); b.setIcon(icon); b.setMessage(msg); if (!TextUtils.isEmpty(posText)) { b.setPositiveButton(posText, posLis); } if (!TextUtils.isEmpty(negText)) { b.setNegativeButton(negText, negLis); } if (!TextUtils.isEmpty(cancelText)) { b.setNeutralButton(cancelText, cancelLis); } if (!activity.isFinishing()) b.show(); } }); }
Example 16
Source File: ToastUtils.java From SUtil with Artistic License 2.0 | 5 votes |
/** * @param context Context * @param string 内容 */ public static void show(final Activity context, final String string) { //判断是否为主线程 if ("main".equals(Thread.currentThread().getName())) { Toast.makeText(context, string, Toast.LENGTH_SHORT).show(); } else {//如果不是,就用该方法使其在ui线程中运行 context.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(context, string, Toast.LENGTH_SHORT).show(); } }); } }
Example 17
Source File: BannerManager.java From arcusandroid with Apache License 2.0 | 4 votes |
public boolean showBanner(@NonNull final Banner banner) { logger.debug("Attempting to show banner {}.", banner.getClass().getSimpleName()); if (getBannerActivity() == null) { logger.error("Bug! Attempt to showBanner() with null activity. Are you invoking BannerManager from an unattached lifecycle phase?"); return false; } Activity activity = getActivity(); if (activity == null) { return false; } banner.setBannerAdapter(getBanners()); banner.setActivity(activity); final ListView bannersView = activity.findViewById(R.id.banner_list); if (bannersView == null) { logger.warn("Not able to find/inflate banners view in this context ({}); banner will not be shown.", activity); return false; } if (getBanners() != null) { // Since we seem to only want to show 1 banner at a time this could be a good time to revamp BannerManager? // However, if we do stick with this (ListView), we could attach all banners and as each one gets addressed, // and then later removed, we could show the 'next in line' by doing a simple display trick in the adapter // Manipulate the item count -> return super.getCount() > 0 ? 1 : 0. activity.runOnUiThread(() -> { BannerAdapter bannerAdapter = getBanners(); if (BannerManagerHelper.canShowBanner(getActivity(), banner) && bannerAdapter != null) { bannerAdapter.clear(); bannerAdapter.add(banner); bannersView.setAdapter(bannerAdapter); logger.debug("Attaching banner list with {} banners visible.", getBanners().getCount()); } }); return true; } else { logger.error("No banner list defined in this activity; banner {} will not be shown.", banner.getClass().getSimpleName()); } return false; }
Example 18
Source File: ImageWrapper.java From Yahala-Messenger with MIT License | 4 votes |
public void runOnUiThread(BitmapDisplayer displayer) { Activity a = (Activity) imageView.getContext(); a.runOnUiThread(displayer); }
Example 19
Source File: SnackbarHelper.java From poly-sample-android with Apache License 2.0 | 4 votes |
private void show( final Activity activity, final String message, final DismissBehavior dismissBehavior) { activity.runOnUiThread( new Runnable() { @Override public void run() { messageSnackbar = Snackbar.make( activity.findViewById(android.R.id.content), message, Snackbar.LENGTH_INDEFINITE); messageSnackbar.getView().setBackgroundColor(BACKGROUND_COLOR); if (dismissBehavior != DismissBehavior.HIDE) { messageSnackbar.setAction( "Dismiss", new View.OnClickListener() { @Override public void onClick(View v) { messageSnackbar.dismiss(); } }); if (dismissBehavior == DismissBehavior.FINISH) { messageSnackbar.addCallback( new BaseTransientBottomBar.BaseCallback<Snackbar>() { @Override public void onDismissed(Snackbar transientBottomBar, int event) { super.onDismissed(transientBottomBar, event); activity.finish(); } }); } } ((TextView) messageSnackbar .getView() .findViewById(android.support.design.R.id.snackbar_text)) .setMaxLines(maxLines); messageSnackbar.show(); } }); }
Example 20
Source File: IntentUtility.java From NClientV2 with Apache License 2.0 | 4 votes |
public static void startAnotherActivity(Activity activity, Intent intent){ activity.runOnUiThread(()->activity.startActivity(intent)); }