Example usage for android.os Handler postDelayed

List of usage examples for android.os Handler postDelayed

Introduction

In this page you can find the example usage for android.os Handler postDelayed.

Prototype

public final boolean postDelayed(Runnable r, long delayMillis) 

Source Link

Document

Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.

Usage

From source file:com.brq.wallet.activity.modern.ModernMain.java

@Override
protected void onResume() {
    _mbwManager.getEventBus().register(this);

    // Start WAPI as a delayed action. This way we don't immediately block the account
    // while synchronizing
    Handler h = new Handler();
    if (_lastSync == 0 || new Date().getTime() - _lastSync > MIN_AUTOSYNC_INTERVAL) {
        h.postDelayed(new Runnable() {
            @Override//from  w ww .  jav  a  2 s . com
            public void run() {
                _mbwManager.getVersionManager().checkForUpdate();
                _mbwManager.getExchangeRateManager().requestRefresh();

                // if the last full sync is too old (or not known), start a full sync for _all_ accounts
                // otherwise just run a normal sync for the current account
                final Optional<Long> lastFullSync = _mbwManager.getMetadataStorage().getLastFullSync();
                if (lastFullSync.isPresent()
                        && (new Date().getTime() - lastFullSync.get() < MIN_FULLSYNC_INTERVAL)) {
                    _mbwManager.getWalletManager(false).startSynchronization();
                } else {
                    _mbwManager.getWalletManager(false).startSynchronization(SyncMode.FULL_SYNC_ALL_ACCOUNTS);
                    _mbwManager.getMetadataStorage().setLastFullSync(new Date().getTime());
                }
            }
        }, 70);
        _lastSync = new Date().getTime();
    }

    supportInvalidateOptionsMenu();
    super.onResume();
}

From source file:com.evandroid.musica.nowplaying.BaseNowplayingFragment.java

private void setSongDetails() {
    updateSongDetails();/*w  w  w. j  a  va  2  s  .  c o m*/

    if (recyclerView != null)
        setQueueSongs();

    setSeekBarListener();

    if (next != null) {
        next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        MusicPlayer.next();
                        notifyPlayingDrawableChange();
                    }
                }, 200);

            }
        });
    }
    if (previous != null) {
        previous.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        MusicPlayer.previous(getActivity(), false);
                        notifyPlayingDrawableChange();
                    }
                }, 200);

            }
        });
    }

    if (playPauseWrapper != null)
        playPauseWrapper.setOnClickListener(mButtonListener);

    if (playPauseFloating != null)
        playPauseFloating.setOnClickListener(mFloatingButtonListener);

    updateShuffleState();
    updateRepeatState();

}

From source file:com.mendhak.gpslogger.loggers.LiveTrack24FileLogger.java

private void delayedDoLogin(int msecs) {
    if (instance == null) {
        Utilities.LogDebug("livetrack24: was trying to login but tracking has stopped before success");
        return;/*from  w w w .ja v a 2 s  .c om*/
    }

    Handler handler = new Handler();
    Utilities.LogDebug("livetrack24: will try login in " + msecs + " millisecs");

    Runnable login_retry = new Runnable() {
        @Override
        public void run() {
            Utilities.LogDebug("livetrack24: new try");
            doLogin();
        }
    };
    handler.postDelayed(login_retry, msecs);
}

From source file:com.glabs.homegenie.util.VoiceControl.java

public void interpretInput(String sentence) {
    _currentInput = sentence;/*from  w w w  . j ava2s  . c o m*/
    Handler hnd = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message message) {
            return false;
        }
    });
    hnd.postDelayed(new Runnable() {
        @Override
        public void run() {
            _doInterpretInput();
        }
    }, 100);
}

From source file:com.bluros.music.nowplaying.BaseNowplayingFragment.java

private void setSongDetails() {
    updateSongDetails();/*w  w  w  .ja va 2 s  . co m*/

    if (recyclerView != null)
        setQueueSongs();

    setSeekBarListener();

    if (next != null) {
        next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        MusicPlayer.next();
                        notifyPlayingDrawableChange();
                    }
                }, 200);

            }
        });
    }
    if (previous != null) {
        previous.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        MusicPlayer.previous(getActivity(), false);
                        notifyPlayingDrawableChange();
                    }
                }, 200);

            }
        });
    }

    if (playPauseWrapper != null)
        playPauseWrapper.setOnClickListener(mButtonListener);

    if (playPauseFloating != null)
        playPauseFloating.setOnClickListener(mFLoatingButtonListener);

    updateShuffleState();
    updateRepeatState();

}

From source file:me.happy.win3win.menu.SmartMatchFragment.java

private void setLoadingDialog() {

    Handler mHandler = new Handler();
    dialog.setContentView(R.layout.matching);
    dialog.setCancelable(false);/*from  ww  w .j a v a  2 s .co m*/
    dialog.create();

    ViewGroup.LayoutParams params = dialog.getWindow().getAttributes();
    params.width = ViewGroup.LayoutParams.MATCH_PARENT;
    params.height = ViewGroup.LayoutParams.MATCH_PARENT;
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    dialog.show();

    mHandler.postDelayed(mRunnable, 2000);
}

From source file:org.mitre.svmp.activities.AppRTCVideoActivity.java

private void sendAppsMessageToOvalAppSrvc() {

    SVMPProtocol.Request.Builder msg = SVMPProtocol.Request.newBuilder();
    SVMPProtocol.Intent.Builder intentProtoBuffer = SVMPProtocol.Intent.newBuilder();
    intentProtoBuffer.setAction(IntentAction.ACTION_VIEW);
    intentProtoBuffer.setData(apkPath);/*from   w w  w.  j  a  v a  2s  .co  m*/

    // Set the Request message params and send it off.
    msg.setType(RequestType.INTENT);
    msg.setIntent(intentProtoBuffer.build());

    sendMessage(msg.build());

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {

            sendAppsMessage();

        }
    }, 30000);
}

From source file:de.lespace.apprtc.WebSocketRTCClient.java

public void processSignalingQueue() {
    try {//from   w  w  w .  java 2 s. c o m

        while (getSignalingQueue().size() > 0) {
            setQueuing(true);
            JSONObject json = getSignalingQueue().remove(0);
            String msg = json.toString();
            if (json.has("params")) {
                Log.i(TAG, "Got appConfig" + msg + " parsing into roomParameters");
                //this.roomParametersFetcher.parseAppConfig(msg);

                Log.i(TAG, "app config: " + msg);
                try {
                    JSONObject appConfig = new JSONObject(msg);

                    String result = appConfig.getString("result");
                    Log.i(TAG, "client debug ");
                    if (!result.equals("SUCCESS")) {
                        return;
                    }

                    String params = appConfig.getString("params");
                    appConfig = new JSONObject(params);
                    LinkedList<PeerConnection.IceServer> iceServers = iceServersFromPCConfigJSON(
                            appConfig.getString("pc_config"));

                    AppRTCClient.SignalingParameters signalingParameters = new SignalingParameters(iceServers);

                    wsClient.register(RTCConnection.from);
                } catch (JSONException e) {
                    getSignalingEvents().onChannelError("app config JSON parsing error: " + e.toString());
                }
                setQueuing(false);
                return;
            }

            if (wsClient.getState() != WebSocketConnectionState.REGISTERED
                    && wsClient.getState() != WebSocketConnectionState.CONNECTED) {
                Log.e(TAG, "websocket still in non registered state.");
                setQueuing(false);
                return;
            }

            String id = "";
            String response = "";

            if (json.has("id"))
                id = json.getString("id");

            if (id.equals("registerResponse")) {

                response = json.getString("response"); //TODO if not accepted what todo?
                String message = json.getString("message");

                if (response.equals("accepted")) {
                    wsClient.setState(WebSocketConnectionState.REGISTERED);
                }

                else if (response.equals("rejected")) {
                    getSignalingEvents().onChannelError("register rejected: " + message);
                }

                else if (response.equals("skipped")) {
                    getSignalingEvents().onChannelError("register rejected: " + message); // Log.e(TAG, "registration was skipped because: "+message);
                }
            }

            if (id.equals("ping")) {
                if (getSignalingEvents() != null) {
                    getSignalingEvents().onPing();
                }
            }

            if (id.equals("registeredUsers")) {
                response = json.getString("response");
                getSignalingEvents().onUserListUpdate(response);
            }

            if (id.equals("incomingCall")) {
                Log.d(TAG, "incomingCall " + json.toString());
                getSignalingEvents().onIncomingCall(json.getString("from"), json.has("screensharing"));
            }

            if (id.equals("incomingScreenCall")) {
                Log.d(TAG, "incomingScreenCall " + json.toString());
                getSignalingEvents().onIncomingScreenCall(json);
            }

            if (id.equals("callResponse")) {
                response = json.getString("response");

                if (response.startsWith("rejected")) {
                    Log.d(TAG, "call got rejected: " + response);
                    getSignalingEvents().onChannelClose();
                } else {
                    Log.d(TAG, "sending sdpAnswer: " + response);
                    SessionDescription sdp = new SessionDescription(SessionDescription.Type.ANSWER,
                            json.getString("sdpAnswer"));

                    getSignalingEvents().onRemoteDescription(sdp);
                }
            }

            if (id.equals("callScreenResponse")) {
                response = json.getString("response");

                if (response.startsWith("rejected")) {
                    Log.d(TAG, "call got rejected: " + response);
                    getSignalingEvents().onChannelScreenClose();
                } else {
                    Log.d(TAG, "sending sdpAnswer: " + response);
                    SessionDescription sdp = new SessionDescription(SessionDescription.Type.ANSWER,
                            json.getString("sdpAnswer"));

                    getSignalingEvents().onRemoteScreenDescription(sdp);
                }
            }

            if (id.equals("startCommunication")) {
                Log.d(TAG, "startCommunication " + json.toString());
                SessionDescription sdp = new SessionDescription(SessionDescription.Type.ANSWER,
                        json.getString("sdpAnswer"));
                getSignalingEvents().onStartCommunication(sdp);
            }

            if (id.equals("startScreenCommunication")) {
                Log.d(TAG, "startScreenCommunication " + json.toString());
                SessionDescription sdp = new SessionDescription(SessionDescription.Type.ANSWER,
                        json.getString("sdpAnswer"));
                // signalingEvents.onStartScreenCommunication(sdp); //remove if not needed!
                getSignalingEvents().onStartScreenCommunication(sdp);
            }

            if (id.equals("stopCommunication")) {
                Log.d(TAG, "stopCommunication " + json.toString());

                getSignalingEvents().onChannelClose();
                if (json.has("callback")) {
                    final Handler handler = new Handler();
                    handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            //Do something after 3000ms
                            getSignalingEvents().onCallback();
                        }
                    }, 3000);

                }
            }

            if (id.equals("stopScreenCommunication")) {
                Log.d(TAG, "stopCommunication " + json.toString());
                getSignalingEvents().onChannelScreenClose();
            }

            if (id.equals("iceCandidateScreen")) {

                JSONObject candidateJson = json.getJSONObject("candidate");

                IceCandidate candidate = new IceCandidate(candidateJson.getString("sdpMid"),
                        candidateJson.getInt("sdpMLineIndex"), candidateJson.getString("candidate"));

                getSignalingEvents().onRemoteScreenIceCandidate(candidate);

            }

            if (id.equals("iceCandidate")) {
                Log.d(TAG, "iceCandidate " + json.toString());

                JSONObject candidateJson = json.getJSONObject("candidate");

                IceCandidate candidate = new IceCandidate(candidateJson.getString("sdpMid"),
                        candidateJson.getInt("sdpMLineIndex"), candidateJson.getString("candidate"));

                getSignalingEvents().onRemoteIceCandidate(candidate);
            }

            if (id.equals("stop")) {
                getSignalingEvents().onChannelClose();
            }

            if (id.equals("callback")) {
                getSignalingEvents().onChannelClose();
            }

            if (id.equals("stopScreen")) {
                getSignalingEvents().onChannelScreenClose();
            }
        }
        setQueuing(false);
    } catch (JSONException e) {
        reportError("WebSocket message JSON parsing error: " + e.toString());
    }

}

From source file:org.sufficientlysecure.keychain.ui.BackupCodeFragment.java

void switchState(BackupCodeState state, boolean animate) {

    switch (state) {
    case STATE_UNINITIALIZED:
        throw new AssertionError("can't switch to uninitialized state, this is a bug!");

    case STATE_DISPLAY:
        mTitleAnimator.setDisplayedChild(0, animate);
        mStatusAnimator.setDisplayedChild(0, animate);
        mCodeFieldsAnimator.setDisplayedChild(0, animate);
        break;// ww w.j a v  a  2s.c om

    case STATE_INPUT:
        mTitleAnimator.setDisplayedChild(1, animate);
        mStatusAnimator.setDisplayedChild(1, animate);
        mCodeFieldsAnimator.setDisplayedChild(1, animate);
        for (EditText editText : mCodeEditText) {
            editText.setText("");
        }

        pushBackStackEntry();

        break;

    case STATE_INPUT_ERROR: {
        mTitleAnimator.setDisplayedChild(1, false);
        mStatusAnimator.setDisplayedChild(2, animate);
        mCodeFieldsAnimator.setDisplayedChild(1, false);

        hideKeyboard();

        if (animate) {
            @ColorInt
            int black = mCodeEditText[0].getCurrentTextColor();
            @ColorInt
            int red = getResources().getColor(R.color.android_red_dark);
            animateFlashText(mCodeEditText, black, red, false);
        }

        break;
    }

    case STATE_OK: {
        mTitleAnimator.setDisplayedChild(2, animate);
        mCodeFieldsAnimator.setDisplayedChild(1, false);
        if (mExecuteBackupOperation) {
            mStatusAnimator.setDisplayedChild(3, animate);
        } else {
            mStatusAnimator.setDisplayedChild(1, animate);
        }

        hideKeyboard();

        for (EditText editText : mCodeEditText) {
            editText.setEnabled(false);
        }

        @ColorInt
        int green = getResources().getColor(R.color.android_green_dark);
        if (animate) {
            @ColorInt
            int black = mCodeEditText[0].getCurrentTextColor();
            animateFlashText(mCodeEditText, black, green, true);
        } else {
            for (TextView textView : mCodeEditText) {
                textView.setTextColor(green);
            }
        }

        popBackStackNoAction();

        // special case for remote API, see RemoteBackupActivity
        if (!mExecuteBackupOperation) {
            // wait for animation to finish...
            final Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    startBackup();
                }
            }, 2000);
        }

        break;
    }

    }

    mCurrentState = state;

}