List of usage examples for android.app Activity runOnUiThread
public final void runOnUiThread(Runnable action)
From source file:Main.java
public static void showToast(final Activity context, final String msg) { if ("main".equals(Thread.currentThread().getName())) { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } else {/* w w w . j a va 2s .c o m*/ context.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } }); } }
From source file:Main.java
public static void show(final Activity activity, final String text) { if ("main".equalsIgnoreCase(Thread.currentThread().getName())) { Toast.makeText(activity, text, Toast.LENGTH_SHORT).show(); } else {/* ww w .j av a 2s .co m*/ activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(activity, text, Toast.LENGTH_SHORT).show(); } }); } }
From source file:Main.java
public static void showProgressDialog(final Activity context, final String dialogTitle, final String dialogMessage) { if (context == null) { return;// ww w . j a v a 2s . co m } context.runOnUiThread(new Runnable() { @Override public void run() { if (progressDialog == null) { progressDialog = new ProgressDialog(context); } if (progressDialog.isShowing() == true) { progressDialog.dismiss(); } if (dialogTitle != null && !"".equals(dialogTitle.trim())) { progressDialog.setTitle(dialogTitle); } if (dialogMessage != null && !"".equals(dialogMessage.trim())) { progressDialog.setMessage(dialogMessage); } progressDialog.setCanceledOnTouchOutside(false); progressDialog.show(); } }); }
From source file:com.doplgangr.secrecy.Util.java
public static void toast(final Activity context, final String msg, final Integer duration) { context.runOnUiThread(new Runnable() { public void run() { Toast.makeText(context, msg, duration).show(); }/* w w w . j a v a2 s . c o m*/ }); }
From source file:Main.java
public static void toActivity(final Activity context, final Intent intent, final int requestCode, final boolean showAnimation) { if (context == null || intent == null) { return;//from www . ja v a 2 s.c o m } context.runOnUiThread(new Runnable() { @Override public void run() { if (requestCode < 0) { context.startActivity(intent); } else { context.startActivityForResult(intent, requestCode); } // if (showAnimation) { // context.overridePendingTransition(R.anim.right_push_in, R.anim.hold); // } else { // context.overridePendingTransition(R.anim.null_anim, R.anim.null_anim); // } } }); }
From source file:org.rm3l.ddwrt.utils.Utils.java
public static void displayMessage(@NotNull final Activity activity, final String msg, final Style style) { activity.runOnUiThread(new Runnable() { public void run() { makeText(activity, msg, style).show(); }//from ww w . j ava 2 s .com }); }
From source file:Main.java
public static void yesNoMessage(final Activity activity, final String title, final String body, final String yesButtonLabel, final String noButtonLabel, final Runnable yesRunnable, final Runnable noRunnable) { activity.runOnUiThread(new Runnable() { @Override//from w ww . j a v a 2 s . co m public void run() { AlertDialog.Builder dialog = new AlertDialog.Builder(activity); dialog.setTitle(title); dialog.setMessage(body); dialog.setPositiveButton(yesButtonLabel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (yesRunnable != null) yesRunnable.run(); } }); dialog.setNegativeButton(noButtonLabel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (noRunnable != null) noRunnable.run(); } }); dialog.create(); dialog.show(); } }); }
From source file:Main.java
public static void performItemClickOnUIThread(final Activity activity, final ListView listView, final View view, final int position) { Runnable click = new Runnable() { public void run() { listView.performItemClick(view, position, 0); }// ww w . ja v a 2 s .com }; activity.runOnUiThread(click); }
From source file:com.androidexperiments.sprayscape.androidutils.PermissionRequester.java
public static void showPermissionRationaleDialog(final String permission, final String title, final String message, final String objectName, final String methodName) { final Activity currentActivity = UnityPlayer.currentActivity; // have to run the dialog in the UI thread: currentActivity.runOnUiThread(new Runnable() { @Override//from ww w .j a v a 2s. co m public void run() { new AlertDialog.Builder(currentActivity).setTitle(title).setMessage(message) .setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } // no-op, let OnDismissListener handle it }).setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { requestPermission(permission, objectName, methodName); } }).setCancelable(false).show(); } }); }
From source file:com.androidexperiments.sprayscape.androidutils.PermissionRequester.java
public static void showDialog(final String title, final String message, final String objectName, final String methodName) { final Activity currentActivity = UnityPlayer.currentActivity; // have to run the dialog in the UI thread: currentActivity.runOnUiThread(new Runnable() { @Override// w w w . j av a2s . co m public void run() { new AlertDialog.Builder(currentActivity).setTitle(title).setMessage(message) .setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } // no-op, let OnDismissListener handle it }).setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { SendMessage(objectName, methodName); } }).setCancelable(false).show(); } }); }