List of usage examples for android.os Handler post
public final boolean post(Runnable r)
From source file:org.kontalk.service.msgcenter.MessageCenterService.java
@Override public synchronized void created(final XMPPConnection connection) { Log.v(TAG, "connection created."); mConnection = (KontalkConnection) connection; // setup version manager final VersionManager verMgr = VersionManager.getInstanceFor(connection); verMgr.setVersion(getString(R.string.app_name), SystemUtils.getVersionFullName(this)); // setup roster Roster roster = getRoster();//from www . j a v a2 s .c om roster.addRosterLoadedListener(new RosterLoadedListener() { @Override public void onRosterLoaded(Roster roster) { final Handler handler = mHandler; if (handler != null) { handler.post(new Runnable() { @Override public void run() { // send pending subscription replies sendPendingSubscriptionReplies(); // resend failed and pending messages resendPendingMessages(false, false); // resend failed and pending received receipts resendPendingReceipts(); // roster has been loaded broadcast(ACTION_ROSTER_LOADED); } }); } } }); roster.setRosterStore(mRosterStore); // enable ping manager AndroidAdaptiveServerPingManager.getInstanceFor(connection, this).setEnabled(true); mPingFailedListener = new PingFailedListener() { @Override public void pingFailed() { if (isStarted() && mConnection == connection) { Log.v(TAG, "ping failed, restarting message center"); // restart message center restart(getApplicationContext()); } } }; PingManagerV2 pingManager = PingManagerV2.getInstanceFor(connection); pingManager.registerPingFailedListener(mPingFailedListener); pingManager.setPingInterval(0); StanzaFilter filter; filter = new StanzaTypeFilter(Presence.class); connection.addAsyncStanzaListener(new PresenceListener(this), filter); filter = new StanzaTypeFilter(RosterMatch.class); connection.addAsyncStanzaListener(new RosterMatchListener(this), filter); filter = new StanzaTypeFilter(org.jivesoftware.smack.packet.Message.class); connection.addSyncStanzaListener(new MessageListener(this), filter); filter = new StanzaTypeFilter(LastActivity.class); connection.addAsyncStanzaListener(new LastActivityListener(this), filter); filter = new StanzaTypeFilter(Version.class); connection.addAsyncStanzaListener(new VersionListener(this), filter); filter = new StanzaTypeFilter(PublicKeyPublish.class); connection.addAsyncStanzaListener(new PublicKeyListener(this), filter); }
From source file:org.mobicents.restcomm.android.client.sdk.RCConnection.java
@Override public void onIceServersReady(final LinkedList<PeerConnection.IceServer> iceServers) { // Important: need to fire the event in UI context to make sure no races will arise Handler mainHandler = new Handler(RCClient.getContext().getMainLooper()); Runnable myRunnable = new Runnable() { @Override/* w ww .j av a2s.c om*/ public void run() { if (!RCConnection.this.incoming) { // we are the initiator // create a new hash map HashMap<String, String> sipHeaders = null; if (RCConnection.this.callParams.containsKey(ParameterKeys.CONNECTION_CUSTOM_SIP_HEADERS)) { sipHeaders = (HashMap<String, String>) RCConnection.this.callParams .get(ParameterKeys.CONNECTION_CUSTOM_SIP_HEADERS); } RCConnection.this.signalingParameters = new SignalingParameters(iceServers, true, "", (String) RCConnection.this.callParams.get(ParameterKeys.CONNECTION_PEER), "", null, null, sipHeaders, (Boolean) RCConnection.this.callParams.get(ParameterKeys.CONNECTION_VIDEO_ENABLED)); } else { // we are not the initiator RCConnection.this.signalingParameters = new SignalingParameters(iceServers, false, "", "", "", null, null, null, (Boolean) RCConnection.this.callParams.get(ParameterKeys.CONNECTION_VIDEO_ENABLED)); SignalingParameters params = SignalingParameters.extractCandidates( new SessionDescription(SessionDescription.Type.OFFER, incomingCallSdp)); RCConnection.this.signalingParameters.offerSdp = params.offerSdp; RCConnection.this.signalingParameters.iceCandidates = params.iceCandidates; } startCall(RCConnection.this.signalingParameters); } }; mainHandler.post(myRunnable); }
From source file:com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.java
/** * Set new password and send verification code to Cognito Identity Provider * service, in background./*ww w. j ava 2 s. c o m*/ * <p> * This method will be called by {@link ForgotPasswordContinuation} * continuation object. * </p> * * @param verificationCode REQUIRED: Code sent from Cognito Identity * Provider Service. * @param newPassword REQUIRED: New password. On successful verification of * {@code verificationCode}, this will be the new password for * this user. * @param callback REQUIRED: {@link ForgotPasswordHandler} callback. */ public void confirmPasswordInBackground(final String verificationCode, final String newPassword, final ForgotPasswordHandler callback) { if (callback == null) { throw new CognitoParameterInvalidException("callback is null"); } new Thread(new Runnable() { @Override public void run() { final Handler handler = new Handler(context.getMainLooper()); Runnable returnCallback; try { confirmPasswordInternal(verificationCode, newPassword); returnCallback = new Runnable() { @Override public void run() { callback.onSuccess(); } }; } 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
/** * Set's user settings, in background./*from w w w . jav a 2 s .co m*/ * * @param cognitoUserSettings REQUIRED: User settings as * {@link CognitoUserSettings}. * @param callback REQUIRED: {@link GenericHandler} callback. */ public void setUserSettingsInBackground(final CognitoUserSettings cognitoUserSettings, final GenericHandler callback) { if (callback == null) { throw new CognitoParameterInvalidException("callback is null"); } final CognitoUserSession session = this.getCachedSession(); new Thread(new Runnable() { @Override public void run() { final Handler handler = new Handler(context.getMainLooper()); Runnable returnCallback; try { setUserSettingsInternal(cognitoUserSettings, session); returnCallback = new Runnable() { @Override public void run() { callback.onSuccess(); } }; } 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
/** * Confirms user registration in background. * <p>//w w w . j av a2 s.c om * Confirming a user is required to complete the user's registration. Any * other operations on a user. are possible only after registration * confirmation. * </p> * * @param confirmationCode REQUIRED: Code sent to the phone-number or email * used to register the user. * @param forcedAliasCreation REQUIRED: This flag indicates if the * confirmation should go-through in case of parameter * contentions. * @param callback REQUIRED: This is a reference to {@link GenericHandler} * callback handler. */ public void confirmSignUpInBackground(final String confirmationCode, final boolean forcedAliasCreation, final GenericHandler callback) { if (callback == null) { throw new CognitoParameterInvalidException("callback is null"); } new Thread(new Runnable() { @Override public void run() { final Handler handler = new Handler(context.getMainLooper()); Runnable returnCallback; try { confirmSignUpInternal(confirmationCode, forcedAliasCreation); returnCallback = new Runnable() { @Override public void run() { callback.onSuccess(); } }; } catch (final Exception e) { returnCallback = new Runnable() { @Override public void run() { callback.onFailure(e); } }; } handler.post(returnCallback); } }).start(); }
From source file:com.newsrob.EntryManager.java
private void runSimpleJob(final String name, final Runnable runnable, final Handler handler) { new Thread(new Runnable() { public void run() { try { runJob(new Job(name, EntryManager.this) { @Override//from w ww. j a va2s .c o m public void run() throws Exception { try { Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST); synchronized (this) { if (isModelCurrentlyUpdated()) return; lockModel(name); } runnable.run(); } finally { synchronized (this) { unlockModel(name); } } } }); } catch (final Throwable e) { if (handler != null) { handler.post(new Runnable() { public void run() { showExceptionToast(name, e); } }); } } } }).start(); }
From source file:com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.java
/** * Deletes this user, in background.//from w w w . j a v a 2s. c o m * * @param callback REQUIRED: @link GenericHandler} callback. */ public void deleteUserInBackground(final GenericHandler 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(); deleteUserInternal(session); returnCallback = new Runnable() { @Override public void run() { callback.onSuccess(); } }; } 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
/** * Deletes user attributes, in background. * * @param attributeNamesToDelete REQUIRED: List of user attributes that have * to be deleted./*from ww w . ja va 2 s.c o m*/ * @param callback REQUIRED: {@link GenericHandler} callback */ public void deleteAttributesInBackground(final List<String> attributeNamesToDelete, final GenericHandler 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(); deleteAttributesInternal(attributeNamesToDelete, session); returnCallback = new Runnable() { @Override public void run() { callback.onSuccess(); } }; } catch (final Exception e) { returnCallback = new Runnable() { @Override public void run() { callback.onFailure(e); } }; } handler.post(returnCallback); } }).start(); }