List of usage examples for android.os Handler post
public final boolean post(Runnable r)
From source file:com.sentaroh.android.SMBSync.SMBSyncMain.java
private void checkLastModifiedListValidity() { final ArrayList<LocalFileLastModifiedMaintListItem> maint_list = new ArrayList<LocalFileLastModifiedMaintListItem>(); final Handler hndl = new Handler(); Thread th = new Thread(new Runnable() { @Override// www.j a v a 2 s. c om public void run() { LocalFileLastModified.createLastModifiedMaintList(mContext, mGp.profileAdapter, maint_list); hndl.post(new Runnable() { @Override public void run() { checkMixedMountPoint(maint_list); } }); } }); th.start(); }
From source file:com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.java
/** * Requests code to verify a user attribute, in background. * <p>/*from ww w .jav a 2s. c o m*/ * The user attributes that can be verified are those attributes that can be * used to communicate with the user, e.g. phone_number and email. The * verification code is sent to the medium that is represented by the * attribute. Attribute verification is required to enable the attribute to * be used an attribute as alias for the user. Aliases attributes can be * used in lieu of the userId to authenticate the user. If an attribute was * used in the confirm the user after sign-up, then that alias is already * verified and does not require re-verification. * </p> * * @param attributeName REQUIRED: Name of the attribute that requires * verification. * @param callback REQUIRED: callback. */ public void getAttributeVerificationCodeInBackground(final String attributeName, final VerificationHandler callback) { if (callback == null) { throw new CognitoParameterInvalidException("callback is null"); } final CognitoUser user = this; new Thread(new Runnable() { @Override public void run() { final Handler handler = new Handler(context.getMainLooper()); Runnable returnCallback; try { final CognitoUserSession session = user.getCachedSession(); final GetUserAttributeVerificationCodeResult getUserAttributeVerificationCodeResult = getAttributeVerificationCodeInternal( attributeName, session); returnCallback = new Runnable() { @Override public void run() { callback.onSuccess(new CognitoUserCodeDeliveryDetails( getUserAttributeVerificationCodeResult.getCodeDeliveryDetails())); } }; } catch (final Exception e) { returnCallback = new Runnable() { @Override public void run() { callback.onFailure(e); } }; } handler.post(returnCallback); } }).start(); }
From source file:com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.java
/** * Starts the process to set a new password for forgotten password case, in * background.//from ww w .ja v a 2 s.c om * <p> * This will initiate the process to set a new password when the current * password is forgotten. The new password will be successfully set only * after the verification code, sent to the registered email or phone number * of the user, successfully verified by Cognito Identity Provider service. * This method will pass a continuation object to the callback. Use setters * in the Continuation object {@link ForgotPasswordContinuation} to set the * new password and verification code and call continue on the continuation * object, {@code CognitoIdentityProviderContinuation.continueTask()}. * </p> * * @param callback REQUIRED: {@link ForgotPasswordHandler} callback */ public void forgotPasswordInBackground(final ForgotPasswordHandler callback) { if (callback == null) { throw new CognitoParameterInvalidException("callback is null"); } final CognitoUser cognitoUser = this; new Thread(new Runnable() { @Override public void run() { final Handler handler = new Handler(context.getMainLooper()); Runnable returnCallback; try { final ForgotPasswordResult forgotPasswordResult = forgotPasswordInternal(); final ForgotPasswordContinuation continuation = new ForgotPasswordContinuation(cognitoUser, new CognitoUserCodeDeliveryDetails(forgotPasswordResult.getCodeDeliveryDetails()), ForgotPasswordContinuation.RUN_IN_BACKGROUND, callback); returnCallback = new Runnable() { @Override public void run() { callback.getResetCode(continuation); } }; } catch (final Exception e) { returnCallback = new Runnable() { @Override public void run() { callback.onFailure(e); } }; } handler.post(returnCallback); } }).start(); }
From source file:com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.java
/** * Fetches the list of all remembered devices for this user. * * @param limit REQUIRED: Maximum number of devices to be returned in this * call, defaults to 10./*from w w w . j a va 2 s. com*/ * @param paginationToken REQUIRED: Token to continue an earlier search. * @param callback REQUIRED: {@link DevicesHandler} callback. */ public void listDevicesInBackground(final int limit, final String paginationToken, final DevicesHandler callback) { if (callback == null) { throw new CognitoParameterInvalidException("callback is null"); } final CognitoUser user = this; new Thread(new Runnable() { @Override public void run() { final Handler handler = new Handler(context.getMainLooper()); Runnable returnCallback; try { final ListDevicesResult listDevicesResult = listDevicesInternal(user.getCachedSession(), limit, paginationToken); final List<CognitoDevice> devicesList = new ArrayList<CognitoDevice>(); for (final DeviceType device : listDevicesResult.getDevices()) { devicesList.add(new CognitoDevice(device, user, context)); } returnCallback = new Runnable() { @Override public void run() { callback.onSuccess(devicesList); } }; } catch (final Exception e) { returnCallback = new Runnable() { @Override public void run() { callback.onFailure(e); } }; } handler.post(returnCallback); } }).start(); }
From source file:com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.java
/** * Returns a valid tokens for a user through the callback method. Runs in * background.//from w ww .ja v a2 s .c o m * {@link AuthenticationHandler#onSuccess(CognitoUserSession, CognitoDevice)} * . * <p> * Tokens are passed as instance of {@link CognitoUserSession}. Call this * method to get valid tokens for a user. This method returns any valid * cached tokens for the user. If no valid cached tokens are available this * method initiates the process to authenticate the user and get tokens from * Cognito Identity Provider service. Implement the interface * {@link AuthenticationHandler} and pass it as callback to this method. * This method uses the callback to interact with application at different * stages of the authentication process. Continuation objects are used when * the authentication process requires more data to continue. See * {@link com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.CognitoIdentityProviderContinuation} * for details on continuation objects. * </p> * * @param callback REQUIRED: {@link AuthenticationHandler} callback */ public void getSessionInBackground(final AuthenticationHandler callback) { if (callback == null) { throw new CognitoParameterInvalidException("callback is null"); } final CognitoUser cognitoUser = this; new Thread(new Runnable() { @Override public void run() { final Handler handler = new Handler(context.getMainLooper()); Runnable returnCallback; try { getCachedSession(); returnCallback = new Runnable() { @Override public void run() { callback.onSuccess(cipSession, null); } }; } catch (final CognitoNotAuthorizedException e) { returnCallback = new Runnable() { @Override public void run() { final AuthenticationContinuation authenticationContinuation = new AuthenticationContinuation( cognitoUser, context, AuthenticationContinuation.RUN_IN_BACKGROUND, callback); callback.getAuthenticationDetails(authenticationContinuation, cognitoUser.getUserId()); } }; } catch (final Exception e) { returnCallback = new Runnable() { @Override public void run() { callback.onFailure(e); } }; } handler.post(returnCallback); } }).start(); }
From source file:com.sentaroh.android.SMBSync.SMBSyncMain.java
private void autoTimer(final ThreadCtrl threadCtl, final NotifyEvent at_ne, final String msg) { setUiDisabled();// w w w . ja v a2 s . c om final Handler handler = new Handler(); new Thread(new Runnable() { @Override public void run() {//non UI thread ProgressBar pb = (ProgressBar) findViewById(R.id.profile_progress_bar_progress); pb.setMax(ATERM_WAIT_TIME); final TextView pm = (TextView) findViewById(R.id.profile_progress_bar_msg); for (int i = 0; i < ATERM_WAIT_TIME; i++) { try { if (threadCtl.isEnabled()) { final int ix = i; handler.post(new Runnable() { //UI thread @Override public void run() { String t_msg = String.format(msg, (ATERM_WAIT_TIME - ix)); pm.setText(t_msg); showNotificationMsg(t_msg); } }); // non UI thread pb.setProgress(i); } else { break; } Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } // dismiss progress bar dialog handler.post(new Runnable() {// UI thread @Override public void run() { LinearLayout ll_bar = (LinearLayout) findViewById(R.id.profile_progress_bar); ll_bar.setVisibility(LinearLayout.GONE); setUiEnabled(); if (mRequestAutoTimerExpired) {//Immediate process requested at_ne.notifyToListener(true, null); } else { if (threadCtl.isEnabled()) at_ne.notifyToListener(true, null); else at_ne.notifyToListener(false, null); } } }); } }).start(); }
From source file:be.ac.ucl.lfsab1509.llncampus.ADE.java
/** * Start information update from ADE./* w w w . ja v a2 s . c o m*/ * * @param sa * Activity that launches the update thread. * @param updateRunnable * Runnable that launches the display update. * @param handler * Handler to allow the display update at the end of the execution. */ public static void runUpdateADE(final ScheduleActivity sa, final Handler handler, final Runnable updateRunnable) { final Resources r = sa.getResources(); final NotificationManager nm = (NotificationManager) sa.getSystemService(Context.NOTIFICATION_SERVICE); final NotificationCompat.Builder nb = new NotificationCompat.Builder(sa) .setSmallIcon(android.R.drawable.stat_sys_download) .setContentTitle(r.getString(R.string.download_from_ADE)) .setContentText(r.getString(R.string.download_progress)).setAutoCancel(true); final NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(r.getString(R.string.download_from_ADE)); nm.notify(NOTIFY_ID, nb.build()); new Thread(new Runnable() { @Override public void run() { /* * Fetching of code of courses to load. */ ArrayList<Course> courses = Course.getList(); if (courses == null || courses.isEmpty()) { // Take the context of the ScheduleActivity SharedPreferences preferences = new SecurePreferences(sa); String username = preferences.getString("username", null); String password = preferences.getString("password", null); if (username != null && password != null) { UCLouvain.downloadCoursesFromUCLouvain(sa, username, password, new Runnable() { public void run() { runUpdateADE(sa, handler, updateRunnable); } }, handler); } } /* * Number of weeks. To download all the schedule, the numbers go from 0 to 51 * (0 = beginning of first semester, 51 = ending of the September exams session). */ String weeks = getWeeks(); /* * Fetching data from ADE and updating the database */ int nbError = 0; int i = 0; ArrayList<Event> events; for (Course course : courses) { i++; nb.setProgress(courses.size(), i, false); nb.setContentText(r.getString(R.string.download_for) + " " + course.getCourseCode() + "..."); nm.notify(NOTIFY_ID, nb.build()); events = ADE.getInfo(course.getCourseCode(), weeks); if (events == null) { nbError++; inboxStyle.addLine(course.getCourseCode() + " : " + r.getString(R.string.download_error)); } else { // Removing old data LLNCampus.getDatabase().delete("Horaire", "COURSE = ?", new String[] { course.getCourseCode() }); // Adding new data for (Event e : events) { ContentValues cv = e.toContentValues(); cv.put("COURSE", course.getCourseCode()); if (LLNCampus.getDatabase().insert("Horaire", cv) < 0) { nbError++; } } inboxStyle.addLine(course.getCourseCode() + " : " + events.size() + " " + r.getString(R.string.events)); nb.setStyle(inboxStyle); } } nb.setProgress(courses.size(), courses.size(), false); if (nbError == 0) { nb.setContentText(r.getString(R.string.download_done)); inboxStyle.setBigContentTitle(r.getString(R.string.download_done)); nb.setSmallIcon(android.R.drawable.stat_sys_download_done); nb.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } else { nb.setContentText(r.getString(R.string.download_done) + ". " + r.getString(R.string.nb_error) + nbError + " :/"); inboxStyle.setBigContentTitle(r.getString(R.string.download_done) + ". " + r.getString(R.string.nb_error) + nbError + " :/"); nb.setSmallIcon(android.R.drawable.stat_notify_error); nb.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } nb.setStyle(inboxStyle); nm.notify(NOTIFY_ID, nb.build()); handler.post(updateRunnable); } }).start(); }
From source file:com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.java
/** * Updates attributes for a user. Runs in background. * <p>// www .j av a2 s . c om * Requires valid accessToken. * </p> * * @param attributes REQUIRED: All attributes and values that need to be * updated for this user. * @param callback REQUIRED: {@link UpdateAttributesHandler} callback. */ public void updateAttributesInBackground(final CognitoUserAttributes attributes, final UpdateAttributesHandler callback) { if (callback == null) { throw new CognitoParameterInvalidException("callback is null"); } final CognitoUser user = this; new Thread(new Runnable() { @Override public void run() { final Handler handler = new Handler(context.getMainLooper()); Runnable returnCallback; try { final CognitoUserSession session = user.getCachedSession(); final UpdateUserAttributesResult updateUserAttributesResult = updateAttributesInternal( attributes, session); final List<CognitoUserCodeDeliveryDetails> attributesVerificationList = new ArrayList<CognitoUserCodeDeliveryDetails>(); if (updateUserAttributesResult.getCodeDeliveryDetailsList() != null) { for (final CodeDeliveryDetailsType details : updateUserAttributesResult .getCodeDeliveryDetailsList()) { attributesVerificationList.add(new CognitoUserCodeDeliveryDetails(details)); } } returnCallback = new Runnable() { @Override public void run() { callback.onSuccess(attributesVerificationList); } }; } catch (final Exception e) { returnCallback = new Runnable() { @Override public void run() { callback.onFailure(e); } }; } handler.post(returnCallback); } }).start(); }
From source file:self.philbrown.droidQuery.$.java
/** * Schedule a task for single execution after a specified delay. * @param function the task to schedule. Receives no args. Note that the function will be * run on the thread on this method was called. * @param delay amount of time in milliseconds before execution. * @return the created Timer/*from w ww.ja v a2s . c om*/ */ public static Timer setTimeout(final Function function, long delay) { Timer t = new Timer(); final Handler h = new Handler(); t.schedule(new TimerTask() { @Override public void run() { h.post(new Runnable() { @Override public void run() { function.invoke(null); } }); } }, delay); return t; }
From source file:self.philbrown.droidQuery.$.java
/** * Schedule a task for repeated fixed-rate execution after a specific delay has passed. * @param the task to schedule. Receives no args. Note that the function will be * run on a the thread on which this method was called. * @param delay amount of time in milliseconds before execution. * @return the created Timer/*from w w w . j a va2s . c om*/ */ public static Timer setInterval(final Function function, long delay) { Timer t = new Timer(); final Handler h = new Handler(); t.scheduleAtFixedRate(new TimerTask() { @Override public void run() { h.post(new Runnable() { @Override public void run() { function.invoke(null); } }); } }, 0, delay); return t; }