Example usage for android.os SystemClock sleep

List of usage examples for android.os SystemClock sleep

Introduction

In this page you can find the example usage for android.os SystemClock sleep.

Prototype

public static void sleep(long ms) 

Source Link

Document

Waits a given number of milliseconds (of uptimeMillis) before returning.

Usage

From source file:com.google.sample.cast.refplayer.Synchronization.java

/**
 *  Setting the Normal Clip bar(orange)//from w w  w. j a  v  a  2s. c om
 */
private void SetNormalClipBar() {
    /**
     *  Setting the clip bar (orange) */
    prev_end_p = (int) mDuration;
    seekBar = new RangeSeekBar(0, (int) mDuration, this);
    seekBar.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener<Integer>() {
        @Override
        public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer start_p, Integer end_p) {
            // handle changed range values
            Log.i(TAG, "Selected new range values: MIN=" + start_p + ", MAX=" + end_p);

            CurSysTime = System.currentTimeMillis();
            if (end_p > (CurSysTime - SysStartTime)) {
                seekBar.setSelectedMaxValue((int) (CurSysTime - SysStartTime));
                prev_end_p = (int) (CurSysTime - SysStartTime);
                seekVideoView();
                mVideoView.start();
                SystemClock.sleep(100);
                mVideoView.pause();
                mPreview.setVisibility(View.VISIBLE);
                if (condition == 2)
                    mSendClip.setVisibility(View.VISIBLE);
                SetReturnBtn();
            } else if (condition == 2 || condition == 3) {
                // Clip Condition
                mClipDuration.setText("  " + com.google.android.libraries.cast.companionlibrary.utils.Utils
                        .formatMillis(prev_end_p - prev_start_p) + "  ");
                mPreview.setVisibility(View.VISIBLE);
                if (condition == 2) {
                    mSendClip.setVisibility(View.VISIBLE);
                }
                SetReturnBtn();

                if (start_p != prev_start_p) {
                    mCurTime = start_p;
                    seekVideoView();

                    prev_start_p = start_p;
                    mVideoView.start();
                    SystemClock.sleep(100);
                    mVideoView.pause();
                }
                if (end_p != prev_end_p) {
                    mCurTime = end_p;
                    seekVideoView();

                    prev_end_p = end_p;
                    mVideoView.start();
                    SystemClock.sleep(100);
                    mVideoView.pause();
                }
            }

        }
    });
    seekVideoView();
    seekBar.setSelectedMaxValue(mCurTime); //Let the rangeseekbar start at the begin

    // add RangeSeekBar to pre-defined layout
    RelativeLayout layout = (RelativeLayout) findViewById(R.id.synchronization);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, seekBar.getId());
    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, seekBar.getId());
    params.addRule(RelativeLayout.BELOW, mVideoView.getId());
    seekBar.setVisibility(View.VISIBLE);
    layout.addView(seekBar, params);
}

From source file:com.andrew.apollo.ui.activities.ProfileActivity.java

/**
 * Removes the header image from the cache.
 *//*from   w  w  w . ja  v a2  s .co  m*/
private void removeFromCache() {
    String key = mProfileName;
    if (isArtist()) {
        key = mArtistName;
    } else if (isAlbum()) {
        key = mProfileName + Config.ALBUM_ART_SUFFIX;
    }
    mImageFetcher.removeFromCache(key);
    // Give the disk cache a little time before requesting a new image.
    SystemClock.sleep(80);
}

From source file:com.boko.vimusic.ui.activities.ProfileActivity.java

/**
 * Removes the header image from the cache.
 *//*from ww  w .j a  v  a 2 s. c o  m*/
private void removeFromCache() {
    String key = mProfileName;
    if (isArtist()) {
        key = mArtistName;
    } else if (isAlbum()) {
        key = ImageFetcher.generateAlbumCacheKey(mProfileName, mArtistName);
    }
    mImageFetcher.removeFromCache(key);
    // Give the disk cache a little time before requesting a new image.
    SystemClock.sleep(80);
}

From source file:edu.umich.flowfence.service.Sandbox.java

private void unbind() {
    if (localLOGD) {
        Log.d(TAG, "unbind: " + this);
    }/*  ww  w  .jav a2s  . c o m*/
    onBeforeDisconnect.fire(this, null);
    ISandboxService sandbox;
    synchronized (mSync) {
        sandbox = mSandboxService;
        mApplication.unbindService(mConnection);
    }

    if (sandbox != null) {
        handleDisconnected();
    } else {
        return;
    }

    synchronized (mSync) {
        // Ask it to terminate itself.
        try {
            IBinder binder = sandbox.asBinder();
            sandbox.kill();

            if (!binder.isBinderAlive()) {
                return;
            }

            int timeout = DEATH_PING_MAX;
            while (--timeout >= 0) {
                if (!binder.pingBinder() || !binder.isBinderAlive()) {
                    return;
                }
                SystemClock.sleep(DEATH_PING_INTERVAL);
            }
            throw new SecurityException("Sandbox process has not died");
        } catch (RemoteException e) {
            // Object's already dead, or we're getting a spurious TransactionTooLarge.
        }
    }
}

From source file:com.farmerbb.taskbar.service.TaskbarService.java

private void startRefreshingRecents() {
    if (thread != null)
        thread.interrupt();//from ww w  . j a v a2 s  .  c om
    stopThread2 = true;

    SharedPreferences pref = U.getSharedPreferences(this);
    showHideAutomagically = pref.getBoolean("hide_when_keyboard_shown", false);

    currentTaskbarIds.clear();

    handler = new Handler();
    thread = new Thread(() -> {
        updateRecentApps(true);

        if (!isRefreshingRecents) {
            isRefreshingRecents = true;

            while (shouldRefreshRecents) {
                SystemClock.sleep(refreshInterval);
                updateRecentApps(false);

                if (showHideAutomagically && !positionIsVertical
                        && !StartMenuHelper.getInstance().isStartMenuOpen())
                    handler.post(() -> {
                        if (layout != null) {
                            int[] location = new int[2];
                            layout.getLocationOnScreen(location);

                            if (location[1] != 0) {
                                if (location[1] > currentTaskbarPosition) {
                                    currentTaskbarPosition = location[1];
                                } else if (location[1] < currentTaskbarPosition) {
                                    if (currentTaskbarPosition - location[1] == getNavBarSize())
                                        currentTaskbarPosition = location[1];
                                    else if (!startThread2) {
                                        startThread2 = true;
                                        tempHideTaskbar(true);
                                    }
                                }
                            }
                        }
                    });
            }

            isRefreshingRecents = false;
        }
    });

    thread.start();
}

From source file:org.durka.hallmonitor.CoreStateManager.java

public void restartServices() {
    stopServices();
    SystemClock.sleep(1000);
    startServices();
}

From source file:com.hzx.luoyechat.activity.ChatActivity.java

protected void onListViewCreation() {
    adapter = new MessageAdapter(ChatActivity.this, toChatUsername, chatType);
    // ?/*from w w w.  j a  v a2s.  com*/
    listView.setAdapter(adapter);

    listView.setOnScrollListener(new ListScrollListener());
    adapter.refreshSelectLast();

    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            hideKeyboard();
            iv_emoticons_checked.setVisibility(View.INVISIBLE);

            exeTask(new Runnable() {
                @Override
                public void run() {
                    SystemClock.sleep(SLEEP_MILLIES);

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            more.setVisibility(View.GONE);
                            iv_emoticons_normal.setVisibility(View.VISIBLE);
                            emojiIconContainer.setVisibility(View.GONE);
                            btnContainer.setVisibility(View.GONE);
                        }
                    });
                }
            });

            return false;
        }
    });
}

From source file:br.com.viniciuscr.notification2android.mediaPlayer.MediaPlaybackService.java

private void reloadQueue() {
    String q = null;//w  w w . j  av a2 s.  c o m

    boolean newstyle = false;
    int id = mCardId;
    if (mPreferences.contains("cardid")) {
        newstyle = true;
        id = mPreferences.getInt("cardid", ~mCardId);
    }
    if (id == mCardId) {
        // Only restore the saved playlist if the card is still
        // the same one as when the playlist was saved
        q = mPreferences.getString("queue", "");
    }
    int qlen = q != null ? q.length() : 0;
    if (qlen > 1) {
        //Log.i("@@@@ service", "loaded queue: " + q);
        int plen = 0;
        int n = 0;
        int shift = 0;
        for (int i = 0; i < qlen; i++) {
            char c = q.charAt(i);
            if (c == ';') {
                ensurePlayListCapacity(plen + 1);
                mPlayList[plen] = n;
                plen++;
                n = 0;
                shift = 0;
            } else {
                if (c >= '0' && c <= '9') {
                    n += ((c - '0') << shift);
                } else if (c >= 'a' && c <= 'f') {
                    n += ((10 + c - 'a') << shift);
                } else {
                    // bogus playlist data
                    plen = 0;
                    break;
                }
                shift += 4;
            }
        }
        mPlayListLen = plen;

        int pos = mPreferences.getInt("curpos", 0);
        if (pos < 0 || pos >= mPlayListLen) {
            // The saved playlist is bogus, discard it
            mPlayListLen = 0;
            return;
        }
        mPlayPos = pos;

        // When reloadQueue is called in response to a card-insertion,
        // we might not be able to query the media provider right away.
        // To deal with this, try querying for the current file, and if
        // that fails, wait a while and try again. If that too fails,
        // assume there is a problem and don't restore the state.
        Cursor crsr = MusicUtils.query(this, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                new String[] { "_id" }, "_id=" + mPlayList[mPlayPos], null, null);
        if (crsr == null || crsr.getCount() == 0) {
            // wait a bit and try again
            SystemClock.sleep(3000);
            crsr = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, mCursorCols,
                    "_id=" + mPlayList[mPlayPos], null, null);
        }
        if (crsr != null) {
            crsr.close();
        }

        // Make sure we don't auto-skip to the next song, since that
        // also starts playback. What could happen in that case is:
        // - music is paused
        // - go to UMS and delete some files, including the currently playing one
        // - come back from UMS
        // (time passes)
        // - music app is killed for some reason (out of memory)
        // - music service is restarted, service restores state, doesn't find
        //   the "current" file, goes to the next and: playback starts on its
        //   own, potentially at some random inconvenient time.
        mOpenFailedCounter = 20;
        mQuietMode = true;
        openCurrentAndNext();
        mQuietMode = false;
        if (!mPlayer.isInitialized()) {
            // couldn't restore the saved state
            mPlayListLen = 0;
            return;
        }

        long seekpos = mPreferences.getLong("seekpos", 0);
        seek(seekpos >= 0 && seekpos < duration() ? seekpos : 0);
        Log.d(LOGTAG, "restored queue, currently at position " + position() + "/" + duration() + " (requested "
                + seekpos + ")");

        int repmode = mPreferences.getInt("repeatmode", REPEAT_NONE);
        if (repmode != REPEAT_ALL && repmode != REPEAT_CURRENT) {
            repmode = REPEAT_NONE;
        }
        mRepeatMode = repmode;

        int shufmode = mPreferences.getInt("shufflemode", SHUFFLE_NONE);
        if (shufmode != SHUFFLE_AUTO && shufmode != SHUFFLE_NORMAL) {
            shufmode = SHUFFLE_NONE;
        }
        if (shufmode != SHUFFLE_NONE) {
            // in shuffle mode we need to restore the history too
            q = mPreferences.getString("history", "");
            qlen = q != null ? q.length() : 0;
            if (qlen > 1) {
                plen = 0;
                n = 0;
                shift = 0;
                mHistory.clear();
                for (int i = 0; i < qlen; i++) {
                    char c = q.charAt(i);
                    if (c == ';') {
                        if (n >= mPlayListLen) {
                            // bogus history data
                            mHistory.clear();
                            break;
                        }
                        mHistory.add(n);
                        n = 0;
                        shift = 0;
                    } else {
                        if (c >= '0' && c <= '9') {
                            n += ((c - '0') << shift);
                        } else if (c >= 'a' && c <= 'f') {
                            n += ((10 + c - 'a') << shift);
                        } else {
                            // bogus history data
                            mHistory.clear();
                            break;
                        }
                        shift += 4;
                    }
                }
            }
        }
        if (shufmode == SHUFFLE_AUTO) {
            if (!makeAutoShuffleList()) {
                shufmode = SHUFFLE_NONE;
            }
        }
        mShuffleMode = shufmode;
    }
}

From source file:com.google.sample.cast.refplayer.Synchronization.java

/**
 *  Setting the preview button//from w  w w .  j  av a  2  s  . c om
 */
private void SetPreviewBtn() {
    /** The Preview button:
    *  If enter the Preview mode,user can play the clips until its end point.
    *  If enter the Resume mode, resume to the TV progress */

    mPreview.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (previewMode) {

                /** Entering the preview mode */
                mDisplayPreviewMode.setText(" Previewing... ");
                //mPreview.setText("Resume");

                if (condition == 2 || condition == 3) {
                    SetReturnBtn();
                    if (Role == 1) {
                        seekBar.setVisibility(View.INVISIBLE);
                    }
                    setPreviewClip();
                }

                if (Role == 1) {
                    mProgressBar.setVisibility(View.INVISIBLE);
                }

                previewSeek.setVisibility(View.VISIBLE);

                SetPreviewPlayPause();

                previewMode = false;
                mCurTime = prev_start_p;
                previewing();
                CreatePreviewingSeekbar();

            } else {
                /** Continue to editing the clip */
                if (condition == 2 || condition == 3) {
                    if (timer != null) {
                        timer.cancel();
                        CreatePreviewingSeekbar();
                    }

                    prev_start_p = prev_start_p_ForPreview;
                    prev_end_p = prev_end_p_ForPreview;

                    setPreviewClip();

                    previewSeek.setProgress(prev_start_p);
                    mVideoView.seekTo(prev_start_p);
                    mVideoView.start();
                    SystemClock.sleep(100);
                    mVideoView.pause();

                }
            }
        }
    });
}

From source file:ee.ioc.phon.android.speak.RecognizerIntentActivity.java

private void playStartSound() {
    boolean soundPlayed = playSound(R.raw.explore_begin);
    if (soundPlayed) {
        SystemClock.sleep(DELAY_AFTER_START_BEEP);
    }//  w  w  w .  j ava2  s  . c  om
}