List of usage examples for android.os Handler post
public final boolean post(Runnable r)
From source file:org.schabi.newpipe.report.ErrorActivity.java
public static void reportError(Handler handler, final Context context, final List<Throwable> el, final Class returnAcitivty, final View rootView, final ErrorInfo errorInfo) { handler.post(new Runnable() { @Override/*from w w w . j a v a 2s. c o m*/ public void run() { reportError(context, el, returnAcitivty, rootView, errorInfo); } }); }
From source file:com.codemobiles.util.CMNotification.java
public static void notify(final Context ctx, final int iconResID, final String remote_image_url, final String title, final String desc, final Class<?> receiver) { final Handler handler = new Handler(); new Thread(new Runnable() { @Override/*w ww . jav a 2 s . co m*/ public void run() { try { remote_picture = BitmapFactory .decodeStream((InputStream) new URL(remote_image_url).getContent()); // remote_picture = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.ic_launcher); } catch (IOException e) { e.printStackTrace(); } handler.post(new Runnable() { @Override public void run() { // TODO Auto-generated method stub mNotificationManager = (NotificationManager) ctx .getSystemService(Context.NOTIFICATION_SERVICE); Notification noti = setNormalNotification(ctx, iconResID, remote_picture, title, desc, receiver); // Notification noti = setBigTextStyleNotification(ctx); noti.defaults |= Notification.DEFAULT_LIGHTS; noti.defaults |= Notification.DEFAULT_VIBRATE; noti.defaults |= Notification.DEFAULT_SOUND; noti.defaults |= Notification.FLAG_AUTO_CANCEL; noti.flags |= Notification.FLAG_ONLY_ALERT_ONCE; final int notificationID = new Random().nextInt(); noti.when = System.currentTimeMillis() + 1000 * 60; mNotificationManager.notify(notificationID, noti); } }); } }).start(); }
From source file:ir.rasen.charsoo.controller.image_loader.core.LoadAndDisplayImageTask.java
static void runTask(Runnable r, boolean sync, Handler handler, ImageLoaderEngine engine) { if (sync) {/* www .j a v a2 s.c om*/ r.run(); } else if (handler == null) { engine.fireCallback(r); } else { handler.post(r); } }
From source file:com.tagaugmentedreality.utilties.Utilities.java
public static void showToast(final Context context, final String message) { Handler handler = new Handler(); /**/* w w w . jav a2 s . c om*/ * * source for showing Toast notification to the ui thread from a thread. * http://www.codeproject.com/Articles/109735/Toast-A-User-Notification * * I need to pass a handler which can send messages to the ui thread. * */ handler.post(new Runnable() { public void run() { Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); } }); }
From source file:com.facebook.Settings.java
static void publishInstallAsync(final Context context, final String applicationId, final Request.Callback callback) { // grab the application context ahead of time, since we will return to the caller immediately. final Context applicationContext = context.getApplicationContext(); Settings.getExecutor().execute(new Runnable() { @Override// w ww.j a va 2s .c o m public void run() { final Response response = Settings.publishInstallAndWaitForResponse(applicationContext, applicationId); if (callback != null) { // invoke the callback on the main thread. Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { callback.onCompleted(response); } }); } } }); }
From source file:com.mrcaps.taskswidget.TasksHelper.java
public static void refreshAuthTokenImpl5(final Context context, final boolean invalidate, final Runnable continuation) { final Handler handl = getHandler(); new Thread(new Runnable() { public void run() { AccountManager mgr = AccountManager.get(context); Account[] accts = mgr.getAccountsByType(ACCOUNT_TYPE); if (accts.length < 1) { handl.post(new Runnable() { public void run() { Toast.makeText(context, "Error: could not find a Google account on this phone", Toast.LENGTH_SHORT).show(); }//from w w w . j a v a2 s . c o m }); return; } Account acct = accts[0]; if (invalidate) { long now = System.currentTimeMillis(); Log.v(TAG, "I5 Auth Token Invalidation Requested"); if (now - lastInvalidation > invalidationDelta) { Log.v(TAG, "I5 Invalidating Auth Token"); try { String token = mgr.blockingGetAuthToken(acct, SERVICE_NAME, true); mgr.invalidateAuthToken(ACCOUNT_TYPE, token); } catch (Exception e) { Log.e(TAG, "I5 couldn't invalidate token", e); } } } try { String token = mgr.blockingGetAuthToken(acct, SERVICE_NAME, true); Log.v(TAG, "I5 got auth token: " + token); authToken = token; } catch (Exception e) { Log.e(TAG, "I5 couldn't authenticate", e); handl.post(new Runnable() { @Override public void run() { Toast.makeText(context, "Error: I5 could not authenticate with Google account", Toast.LENGTH_SHORT).show(); } }); } continuation.run(); } }).start(); }
From source file:github.popeen.dsub.util.Notifications.java
public static void hidePlayingNotification(final Context context, final DownloadService downloadService, Handler handler) { playShowing = false;/*from www .j av a 2 s. c o m*/ // Remove notification and remove the service from the foreground handler.post(new Runnable() { @Override public void run() { stopForeground(downloadService, true); if (persistentPlayingShowing) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(NOTIFICATION_ID_PLAYING); persistentPlayingShowing = false; } } }); // Get downloadNotification in foreground if playing if (downloadShowing) { showDownloadingNotification(context, downloadService, handler, downloadService.getCurrentDownloading(), downloadService.getBackgroundDownloads().size()); } // Update widget DSubWidgetProvider.notifyInstances(context, downloadService, false); }
From source file:com.github.vseguip.sweet.rest.SugarRestAPI.java
/** * Sends the authentication response from server back to the caller main UI * thread through its handler.//from w w w. ja va2s. c o m * * @param result * The boolean holding authentication result * @param handler * The main UI thread's handler instance. * @param context * The caller Activity's context. * @param message * SessionID if login was successful or error message if it was * not. */ private static void sendResult(final Boolean result, final Handler handler, final Context context, final String message) { if (handler == null || context == null) { return; } handler.post(new Runnable() { public void run() { ((SweetAuthenticatorActivity) context).onValidationResult(result, message); } }); }
From source file:github.daneren2005.dsub.util.Notifications.java
public static void hideDownloadingNotification(final Context context, final DownloadService downloadService, Handler handler) { downloadShowing = false;//from www .j a v a 2s .c o m if (playShowing) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(NOTIFICATION_ID_DOWNLOADING); } else { downloadForeground = false; handler.post(new Runnable() { @Override public void run() { downloadService.stopForeground(true); } }); } }
From source file:it.mb.whatshare.Dialogs.java
/** * Shows a dialog to get a name for the inbound device being paired and * starts a new {@link CallGooGlInbound} action if the chosen name is valid. * //w w w. ja v a2 s.co m * @param deviceType * the model of the device being paired as suggested by the * device itself * @param sharedSecret * the keys used when encrypting the message between devices * @param activity * the caller activity */ public static void promptForInboundName(final String deviceType, final int[] sharedSecret, final MainActivity activity) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { DialogFragment prompt = new PatchedDialogFragment() { public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = getBuilder(activity); final EditText input = new EditText(getContext()); input.setInputType(InputType.TYPE_CLASS_TEXT); input.setText(deviceType); input.setSelection(deviceType.length()); // @formatter:off builder.setTitle(R.string.device_name_chooser_title).setView(input) .setPositiveButton(android.R.string.ok, null); // @formatter:on final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener( new DeviceNameChooserPrompt(alertDialog, input, activity, new Callback<String>() { @Override public void run() { // @formatter:off new CallGooGlInbound(activity, getParam(), deviceType) .execute(sharedSecret); ((InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(input.getWindowToken(), 0); // @formatter:on } })); return alertDialog; } }; prompt.show(activity.getSupportFragmentManager(), "chooseName"); } }); }