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.cyanogenmod.eleven.ui.fragments.AlbumFragment.java

/**
 * Restarts the loader.
 */
public void refresh() {
    // Wait a moment for the preference to change.
    SystemClock.sleep(10);
    restartLoader();
}

From source file:org.jraf.android.hellomundo.app.saveshare.SaveShareHelper.java

@Background(Type.DISK)
private WebcamInfo saveAndInsertImage(Context context, int appwidgetId) throws Exception {
    long webcamId;
    if (appwidgetId == WALLPAPER) {
        webcamId = getCurrentWallpaperWebcamId(context);
    } else {//from   w w  w.ja  va2s. co  m
        webcamId = AppwidgetManager.get().getCurrentWebcamId(context, appwidgetId);
        if (webcamId == Constants.WEBCAM_ID_NONE)
            throw new Exception("Could not get webcamId for appwidgetId=" + appwidgetId);
    }

    // 2.1 equivalent of File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    File picturesPath = new File(Environment.getExternalStorageDirectory(), "Pictures");
    File path = new File(picturesPath, "HelloMundo");
    WebcamInfo webcamInfo = getWebcamInfo(context, webcamId);
    if (webcamInfo == null) {
        throw new Exception("Could not get webcam info");
    }
    String fileName = webcamInfo.getFileName(context);
    File file = new File(path, fileName);
    path.mkdirs();
    String imageFile;
    if (appwidgetId == WALLPAPER) {
        imageFile = Constants.FILE_IMAGE_WALLPAPER;
    } else {
        imageFile = AppwidgetManager.get().getFileName(appwidgetId);
    }
    InputStream inputStream = context.openFileInput(imageFile);
    OutputStream outputStream = new FileOutputStream(file);
    try {
        IoUtil.copy(inputStream, outputStream);
    } finally {
        IoUtil.closeSilently(inputStream, outputStream);
    }

    // Scan it
    final AtomicReference<Uri> scannedImageUri = new AtomicReference<Uri>();
    MediaScannerUtil.scanFile(context, new String[] { file.getPath() }, null, new OnScanCompletedListener() {
        @Override
        public void onScanCompleted(String p, Uri uri) {
            Log.d("path=" + p + " uri=" + uri);
            scannedImageUri.set(uri);
        }
    });

    // Wait until the media scanner has found our file
    long start = System.currentTimeMillis();
    while (scannedImageUri.get() == null) {
        Log.d("Waiting 250ms for media scanner...");
        SystemClock.sleep(250);
        if (System.currentTimeMillis() - start > 5000) {
            throw new Exception("MediaScanner did not scan the file " + file + " after 5000ms");
        }
    }
    webcamInfo.localBitmapUriStr = scannedImageUri.get().toString();
    return webcamInfo;
}

From source file:org.golang.app.WViewActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Fixed Portrait orientation
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    /*this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);*/

    setContentView(R.layout.webview);//  w  w w  . j  a  va  2  s.  co  m
    WebView webView = (WebView) findViewById(R.id.webView1);

    initWebView(webView);
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            Log.d("JavaGoWV: ", url);

            final Pattern p = Pattern.compile("dcoinKey&password=(.*)$");
            final Matcher m = p.matcher(url);
            if (m.find()) {
                try {
                    Thread thread = new Thread(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                //File root = android.os.Environment.getExternalStorageDirectory();
                                File dir = Environment
                                        .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
                                Log.d("JavaGoWV", "dir " + dir);

                                URL keyUrl = new URL(
                                        "http://127.0.0.1:8089/ajax?controllerName=dcoinKey&first=1"); //you can write here any link
                                //URL keyUrl = new URL("http://yandex.ru/"); //you can write here any link
                                File file = new File(dir, "dcoin-key.png");

                                long startTime = System.currentTimeMillis();
                                Log.d("JavaGoWV", "download begining");
                                Log.d("JavaGoWV", "download keyUrl:" + keyUrl);

                                /* Open a connection to that URL. */
                                URLConnection ucon = keyUrl.openConnection();

                                Log.d("JavaGoWV", "0");
                                /*
                                * Define InputStreams to read from the URLConnection.
                                */
                                InputStream is = ucon.getInputStream();

                                Log.d("JavaGoWV", "01");

                                BufferedInputStream bis = new BufferedInputStream(is);

                                Log.d("JavaGoWV", "1");
                                /*
                                * Read bytes to the Buffer until there is nothing more to read(-1).
                                */
                                ByteArrayBuffer baf = new ByteArrayBuffer(5000);
                                int current = 0;
                                while ((current = bis.read()) != -1) {
                                    baf.append((byte) current);
                                }

                                Log.d("JavaGoWV", "2");
                                /* Convert the Bytes read to a String. */
                                FileOutputStream fos = new FileOutputStream(file);
                                fos.write(baf.toByteArray());
                                fos.flush();
                                fos.close();

                                Log.d("JavaGoWV", "3");
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                                    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                                    Uri contentUri = Uri.fromFile(file);
                                    mediaScanIntent.setData(contentUri);
                                    WViewActivity.this.sendBroadcast(mediaScanIntent);
                                } else {
                                    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                                            Uri.parse("file://" + Environment.getExternalStorageDirectory())));
                                }

                                Log.d("JavaGoWV", "4");
                            } catch (Exception e) {
                                Log.e("JavaGoWV error 0", e.toString());
                                e.printStackTrace();
                            }
                        }
                    });
                    thread.start();

                } catch (Exception e) {
                    Log.e("JavaGoWV error", e.toString());
                    e.printStackTrace();
                }
            }
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            Log.e("JavaGoWV", "shouldOverrideUrlLoading " + url);

            if (url.endsWith(".mp4")) {
                Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(in);
                return true;
            } else {
                return false;
            }
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Log.d("JavaGoWV",
                    "failed: " + failingUrl + ", error code: " + errorCode + " [" + description + "]");
        }
    });

    SystemClock.sleep(1500);
    //if (MyService.DcoinStarted(8089)) {
    webView.loadUrl("http://localhost:8089/");
    //}

}

From source file:danonino.danonino_the_game.Core.GamePanel.java

public void update() {
    this.bg.update();
    this.bgFront.update();
    this.player.update();
    this.progress.update(this.player.getScore());

    if (this.event != null) {
        if (!this.event.isOnScreen()) {
            this.event = null;
        } else {/*w w w .  java2s .com*/
            this.event.update();
            if (this.event.intersects(this.player, 60, 60)) {
                this.event.executeEvent(this.player);
                if (this.event.getClass() == Danonino.class) {
                    this.event = null;
                }
            }
        }
    } else {
        this.event = EventFactory.Create();
    }

    for (int i = 0; i < this.butterflies.size(); i++) {
        Butterfly currentButterfly = this.butterflies.get(i);
        if (currentButterfly.isOutsideScreen()) {
            this.butterflies.remove(i);
        }
        currentButterfly.update();
    }
    for (int i = 0; i < this.enemies.size(); i++) {
        Fruit currentEnemy = this.enemies.get(i);
        if (currentEnemy.isDead()) {
            this.enemies.remove(i);
            continue;
        }

        currentEnemy.update();

        if (this.player.intersects(currentEnemy, 40,
                (int) (currentEnemy.getSpeedY() * 6.6666666666666666666666666666667))) {
            this.player.tryEat(currentEnemy);
        }
    }
    if (!this.player.isDead()) {
        if (this.enemies.size() <= 10) {
            initFish();
        }
    }

    if (this.player.isDead() && !this.alreadyEnded) {
        this.alreadyEnded = true;
        Thread thr = new Thread(new Runnable() {
            @Override
            public void run() {
                SystemClock.sleep(2000);
                setGameOver(true);
                SoundManager.playSound(SoundManager.GAME_OVER);
            }
        });
        thr.start();
    }
}

From source file:com.jaguarlandrover.auto.remote.vehicleentry.BeaconRanger.java

public Observable<RangeObject> getRangeStream() {
    Observable<RangeObject> myObservable = Observable.create(new Observable.OnSubscribe<RangeObject>() {

        @Override//from   w w w .  ja  va  2  s  . com
        public void call(Subscriber<? super RangeObject> sub) {
            BeaconRanger.this.sub = sub;
            while (true) {
                SystemClock.sleep(1000);
            }
        }
    });
    return myObservable;
}

From source file:com.andrew.apollo.ui.fragments.profile.LastAddedFragment.java

@Override
public boolean onContextItemSelected(final android.view.MenuItem item) {
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(getSherlockActivity(), new long[] { mSelectedId }, 0, false);
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getSherlockActivity(), new long[] { mSelectedId });
            return true;
        case FragmentMenuItems.ADD_TO_FAVORITES:
            FavoritesStore.getInstance(getSherlockActivity()).addSongId(Long.valueOf(mSelectedId), mSongName,
                    mAlbumName, mArtistName);
            return true;
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(new long[] { mSelectedId }).show(getFragmentManager(),
                    "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final long mPlaylistId = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(getSherlockActivity(), new long[] { mSelectedId }, mPlaylistId);
            return true;
        case FragmentMenuItems.MORE_BY_ARTIST:
            NavUtils.openArtistProfile(getSherlockActivity(), mArtistName);
            return true;
        case FragmentMenuItems.USE_AS_RINGTONE:
            MusicUtils.setRingtone(getSherlockActivity(), mSelectedId);
            return true;
        case FragmentMenuItems.DELETE:
            DeleteDialog.newInstance(mSong.mSongName, new long[] { mSelectedId }, null)
                    .show(getFragmentManager(), "DeleteDialog");
            SystemClock.sleep(10);
            mAdapter.notifyDataSetChanged();
            getLoaderManager().restartLoader(LOADER, null, this);
            return true;
        default:/*from   w w  w  .  j av  a2 s.c o  m*/
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:ru.mtuci.musicanalyzer.apollo.ui.fragments.profile.LastAddedFragment.java

@Override
public boolean onContextItemSelected(final android.view.MenuItem item) {
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(getActivity(), new long[] { mSelectedId }, 0, false);
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getActivity(), new long[] { mSelectedId });
            return true;
        case FragmentMenuItems.ADD_TO_FAVORITES:
            FavoritesStore.getInstance(getActivity()).addSongId(mSelectedId, mSongName, mAlbumName,
                    mArtistName);//  w ww  . j  a v a  2  s .c o  m
            return true;
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(new long[] { mSelectedId }).show(getFragmentManager(),
                    "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final long mPlaylistId = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(getActivity(), new long[] { mSelectedId }, mPlaylistId);
            return true;
        case FragmentMenuItems.MORE_BY_ARTIST:
            NavUtils.openArtistProfile(getActivity(), mArtistName);
            return true;
        case FragmentMenuItems.USE_AS_RINGTONE:
            MusicUtils.setRingtone(getActivity(), mSelectedId);
            return true;
        case FragmentMenuItems.DELETE:
            DeleteDialog.newInstance(mSong.mSongName, new long[] { mSelectedId }, null)
                    .show(getFragmentManager(), "DeleteDialog");
            SystemClock.sleep(10);
            mAdapter.notifyDataSetChanged();
            getLoaderManager().restartLoader(LOADER, null, this);
            return true;
        default:
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:android.support.test.testapp.WebViewTest.java

public void api19TestFrames() {
    // Sadly API 19 does not report progress changes when an iframe is loading new content (eg: a
    // user has clicked on a form submit button in an iframe.) It only reports progress changes once
    // all the new content is loaded. In this case we have to sleep after performing the click on
    // the submit button.
    ////  w  w  w.j  av a  2s . c  o m
    // At least API 19 does block the initial page load (caused by webview.loadURL()) until all the
    // content in each iframe is fully loaded.
    onWebView()
            // We're in the main frame.
            .check(webMatches(getCurrentUrl(), containsString("frames.html"))) // the main frame
            // Now lets switch to a sub frame named bar.
            .inWindow(selectFrameByIdOrName("bar"))
            // Now the URL of the frame should change.
            .check(webMatches(getCurrentUrl(), containsString("bar.html")))
            // Now lets switch to another subframe (of the MAIN frame).
            .inWindow(selectFrameByIdOrName("form"))
            // And interact with it's content.
            .withElement(findElement(Locator.NAME, "short_name")).perform(clearElement())
            .perform(webKeys("Steve")).withElement(findElement(Locator.ID, "submit")).perform(webClick());
    SystemClock.sleep(3000);

    onWebView().inWindow(selectFrameByIdOrName("form")).withElement(findElement(Locator.ID, "message"))
            .check(webMatches(getText(), containsString("Hello Steve!")));
}

From source file:com.andrew.apollo.ui.fragments.profile.FavoriteFragment.java

@Override
public boolean onContextItemSelected(final android.view.MenuItem item) {
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(getSherlockActivity(), new long[] { mSelectedId }, 0, false);
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getSherlockActivity(), new long[] { mSelectedId });
            return true;
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(new long[] { mSelectedId }).show(getFragmentManager(),
                    "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final long mPlaylistId = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(getSherlockActivity(), new long[] { mSelectedId }, mPlaylistId);
            return true;
        case FragmentMenuItems.MORE_BY_ARTIST:
            NavUtils.openArtistProfile(getSherlockActivity(), mArtistName);
            return true;
        case FragmentMenuItems.USE_AS_RINGTONE:
            MusicUtils.setRingtone(getSherlockActivity(), mSelectedId);
            return true;
        case FragmentMenuItems.REMOVE_FROM_FAVORITES:
            FavoritesStore.getInstance(getSherlockActivity()).removeItem(Long.valueOf(mSelectedId));
            getLoaderManager().restartLoader(LOADER, null, this);
            return true;
        case FragmentMenuItems.DELETE:
            DeleteDialog.newInstance(mSong.mSongName, new long[] { mSelectedId }, null)
                    .show(getFragmentManager(), "DeleteDialog");
            SystemClock.sleep(10);
            mAdapter.notifyDataSetChanged();
            getLoaderManager().restartLoader(LOADER, null, this);
            return true;
        default:/*from w ww  .j ava 2s .com*/
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:ru.mtuci.musicanalyzer.apollo.ui.fragments.profile.FavoriteFragment.java

@Override
public boolean onContextItemSelected(final android.view.MenuItem item) {
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(getActivity(), new long[] { mSelectedId }, 0, false);
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getActivity(), new long[] { mSelectedId });
            return true;
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(new long[] { mSelectedId }).show(getFragmentManager(),
                    "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final long mPlaylistId = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(getActivity(), new long[] { mSelectedId }, mPlaylistId);
            return true;
        case FragmentMenuItems.MORE_BY_ARTIST:
            NavUtils.openArtistProfile(getActivity(), mArtistName);
            return true;
        case FragmentMenuItems.USE_AS_RINGTONE:
            MusicUtils.setRingtone(getActivity(), mSelectedId);
            return true;
        case FragmentMenuItems.REMOVE_FROM_FAVORITES:
            FavoritesStore.getInstance(getActivity()).removeItem(mSelectedId);
            getLoaderManager().restartLoader(LOADER, null, this);
            return true;
        case FragmentMenuItems.DELETE:
            DeleteDialog.newInstance(mSong.mSongName, new long[] { mSelectedId }, null)
                    .show(getFragmentManager(), "DeleteDialog");
            SystemClock.sleep(10);
            mAdapter.notifyDataSetChanged();
            getLoaderManager().restartLoader(LOADER, null, this);
            return true;
        default:/* w ww .j  a  v  a 2s .c  om*/
            break;
        }
    }
    return super.onContextItemSelected(item);
}