List of usage examples for android.os SystemClock sleep
public static void sleep(long ms)
From source file:com.andrew.apollo.ui.fragments.profile.AlbumSongFragment.java
/** * Restarts the loader.// w w w . j a va 2s . c om */ public void refresh() { // Scroll to the stop of the list before restarting the loader. // Otherwise, if the user has scrolled enough to move the header, it // becomes misplaced and needs to be reset. mListView.setSelection(0); // Wait a moment for the preference to change. SystemClock.sleep(10); mAdapter.notifyDataSetChanged(); getLoaderManager().restartLoader(LOADER, getArguments(), this); }
From source file:itstudio.instructor.fragment.ContactlistFragment.java
public void refresh() { try {// ww w . j ava2s .c o m if (adapter == null) { SystemClock.sleep(200); } if (adapter != null) { // ?? getActivity().runOnUiThread(new Runnable() { public void run() { blackList = EMContactManager.getInstance().getBlackListUsernames(); getContactList(); adapter.notifyDataSetChanged(); } }); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.andrew.apollo.ui.fragments.profile.GenreSongFragment.java
/** * Restarts the loader.//from w w w .ja v a2s . c o m */ public void refresh() { // Scroll to the stop of the list before restarting the loader. // Otherwise, if the user has scrolled enough to move the header, it // becomes misplaced and needs to be reset. mListView.setSelection(0); // Wait a moment for the preference to change. SystemClock.sleep(10); getLoaderManager().restartLoader(LOADER, getArguments(), this); }
From source file:com.andrew.apollo.ui.fragments.AlbumFragment.java
/** * Restarts the loader./*from w w w . ja v a2 s . c om*/ */ public void refresh() { // Wait a moment for the preference to change. SystemClock.sleep(10); getLoaderManager().restartLoader(LOADER, null, this); }
From source file:com.lambdasoup.watchlater.test.AddActivityTest.java
@Test public void longCallbackLifecycleInteraction() throws Exception { String testDescription = "Description for the Test video"; String testTitle = "Test Title"; int delaySeconds = 1; // set channel list response registerChannelListResponse();/* w w w . ja va2 s.com*/ // set add video to list response { JSONObject json = new JSONObject(); JSONObject snippet = new JSONObject(); snippet.put("title", testTitle); snippet.put("description", testDescription); json.put("snippet", snippet); MockResponse response = new MockResponse(); response.setBody(json.toString(8)); restfulDispatcher.registerResponse("/playlistItems?part=snippet", response); restfulDispatcher.setDelay(delaySeconds, TimeUnit.SECONDS); } // set account addAccount(ACCOUNT_1); // launch activity AddActivity activity = activityTestRuleHttpsUri.launchActivity(null); activity.finish(); // point here is to wait until the http request has finished // it would be nice if would could block until espresso says we've gone quiet // but onView requires the activity to exists SystemClock.sleep(TimeUnit.SECONDS.toMillis(delaySeconds)); }
From source file:com.alibaba.akita.io.HttpInvoker.java
/** * Vversion 2 remoteimageview download impl, use byte[] to decode. * Note: Recommanded to use this method instead of version 1. * NUM_RETRIES retry.//from www. j a v a2 s. c om * @param imgUrl * @param httpReferer http Referer * @return * @throws AkServerStatusException * @throws AkInvokeException */ public static Bitmap getBitmapFromUrl(String imgUrl, String httpReferer, ProgressBar progressBar) throws AkServerStatusException, AkInvokeException { imgUrl = imgUrl.trim(); Log.v(TAG, "getBitmapFromUrl:" + imgUrl); int timesTried = 1; while (timesTried <= NUM_RETRIES) { timesTried++; try { if (progressBar != null) { progressBar.setProgress(0); } HttpGet request = new HttpGet(imgUrl); if (httpReferer != null) request.addHeader("Referer", httpReferer); HttpResponse response = client.execute(request); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED || statusCode == HttpStatus.SC_ACCEPTED) { HttpEntity resEntity = response.getEntity(); InputStream inputStream = resEntity.getContent(); byte[] imgBytes = retrieveImageData(inputStream, (int) (resEntity.getContentLength()), progressBar); if (imgBytes == null) { SystemClock.sleep(DEFAULT_RETRY_SLEEP_TIME); continue; } Bitmap bm = null; try { bm = ImageUtil.decodeSampledBitmapFromByteArray(imgBytes, 0, imgBytes.length, 682, 682); } catch (OutOfMemoryError ooe) { Log.e(TAG, ooe.toString(), ooe); return null; // if oom, no need to retry. } if (bm == null) { SystemClock.sleep(DEFAULT_RETRY_SLEEP_TIME); continue; } return bm; } else { HttpEntity resEntity = response.getEntity(); throw new AkServerStatusException(response.getStatusLine().getStatusCode(), EntityUtils.toString(resEntity, CHARSET)); } } catch (ClientProtocolException cpe) { Log.e(TAG, cpe.toString(), cpe); throw new AkInvokeException(AkInvokeException.CODE_HTTP_PROTOCOL_ERROR, cpe.toString(), cpe); } catch (IOException ioe) { Log.e(TAG, ioe.toString(), ioe); throw new AkInvokeException(AkInvokeException.CODE_CONNECTION_ERROR, ioe.toString(), ioe); } catch (IllegalStateException ise) { Log.e(TAG, ise.toString(), ise); throw new AkInvokeException(AkInvokeException.CODE_TARGET_HOST_OR_URL_ERROR, ise.toString(), ise); } catch (IllegalArgumentException iae) { throw new AkInvokeException(AkInvokeException.CODE_TARGET_HOST_OR_URL_ERROR, iae.toString(), iae); } catch (Exception e) { throw new AkInvokeException(AkInvokeException.CODE_UNKOWN_ERROR, e.toString(), e); } } return null; }
From source file:com.DGSD.DGUtils.ImageDownloader.ImageLoader.java
protected Bitmap downloadImage() { int timesTried = 1; while (timesTried <= numRetries) { try {/*from w w w . j av a2 s . c o m*/ byte[] imageData = retrieveImageData(); if (imageData != null) { imageCache.put(imageUrl, imageData); } else { break; } return BitmapFactory.decodeByteArray(imageData, 0, imageData.length); } catch (Throwable e) { Log.w(LOG_TAG, "download for " + imageUrl + " failed (attempt " + timesTried + ")"); e.printStackTrace(); SystemClock.sleep(DEFAULT_RETRY_HANDLER_SLEEP_TIME); timesTried++; } } return null; }
From source file:org.zeroxlab.zeroxbenchmark.Benchmark.java
private void initAuto() { Intent intent = getIntent();/*from w ww.j a v a 2s . c o m*/ String TAG = intent.getStringExtra("TAG"); String CAT = intent.getStringExtra("CAT"); _checkAllCase(false); if (TAG != null) _checkTagCase(TAG.split(",")); if (CAT != null) _checkCatCase(CAT.split(",")); if (TAG == null && CAT == null) _checkAllCase(true); final Handler h = new Handler() { public void handleMessage(Message msg) { if (msg.what == 0x1234) onClick(mRun); } }; final ProgressDialog dialog = new ProgressDialog(this).show(this, "Starting Benchmark", "Please wait...", true, false); new Thread() { public void run() { SystemClock.sleep(1000); dialog.dismiss(); Message m = new Message(); m.what = 0x1234; h.sendMessage(m); } }.start(); mTouchable = true; }
From source file:com.kkbox.toolkit.internal.api.APIRequest.java
@Override public Void doInBackground(Object... params) { int readLength; final byte[] buffer = new byte[128]; listener = (APIRequestListener) params[0]; int retryTimes = 0; File cacheFile = null;//from w w w . j a v a 2 s . c om ConnectivityManager connectivityManager = null; if (context != null) { final File cacheDir = new File(context.getCacheDir().getAbsolutePath() + File.separator + "api"); if (!cacheDir.exists()) { cacheDir.mkdir(); } cacheFile = new File( cacheDir.getAbsolutePath() + File.separator + StringUtils.getMd5Hash(url + getParams)); connectivityManager = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE); } if (context != null && cacheTimeOut > 0 && cacheFile.exists() && ((System.currentTimeMillis() - cacheFile.lastModified() < cacheTimeOut) || connectivityManager.getActiveNetworkInfo() == null)) { try { parseInputStream(new FileInputStream(cacheFile), cipher); } catch (IOException e) { isNetworkError = true; } catch (Exception e) { e.printStackTrace(); } } else { do { try { KKDebug.i("Connect API url " + url + getParams); if (postParams != null || multipartEntity != null || stringEntity != null || fileEntity != null || byteArrayEntity != null || gzipStreamEntity != null || (headerParams != null && postParams != null)) { final HttpPost httppost = new HttpPost(url + getParams); if (postParams != null) { httppost.setEntity(new UrlEncodedFormEntity(postParams, HTTP.UTF_8)); } if (multipartEntity != null) { httppost.setEntity(multipartEntity); } if (stringEntity != null) { httppost.setEntity(stringEntity); } if (fileEntity != null) { httppost.setEntity(fileEntity); } if (byteArrayEntity != null) { httppost.setEntity(byteArrayEntity); } if (gzipStreamEntity != null) { httppost.setHeader("Accept-Encoding", "gzip"); httppost.setEntity(gzipStreamEntity); } if (headerParams != null) { for (NameValuePair header : headerParams) { httppost.setHeader(header.getName(), header.getValue()); } } response = httpclient.execute(httppost); } else { final HttpGet httpGet = new HttpGet(url + getParams); if (headerParams != null) { for (NameValuePair header : headerParams) { httpGet.setHeader(header.getName(), header.getValue()); } } response = httpclient.execute(httpGet); } httpStatusCode = response.getStatusLine().getStatusCode(); int httpStatusType = httpStatusCode / 100; switch (httpStatusType) { case 2: is = getInputStreamFromHttpResponse(); isNetworkError = false; break; case 4: KKDebug.w("Get client error " + httpStatusCode + " with connection : " + url + getParams); is = getInputStreamFromHttpResponse(); isHttpStatusError = true; isNetworkError = false; break; case 5: KKDebug.w("Get server error " + httpStatusCode + " with connection : " + url + getParams); is = getInputStreamFromHttpResponse(); isHttpStatusError = true; isNetworkError = false; break; default: KKDebug.w("connection to " + url + getParams + " returns " + httpStatusCode); retryTimes++; isNetworkError = true; SystemClock.sleep(1000); break; } } catch (final SSLException e) { KKDebug.w("connection to " + url + getParams + " failed with " + e.getClass().getName()); isNetworkError = true; errorMessage = e.getClass().getName(); return null; } catch (final Exception e) { KKDebug.w("connection to " + url + getParams + " failed!"); retryTimes++; isNetworkError = true; SystemClock.sleep(1000); } } while (isNetworkError && retryTimes < retryLimit); try { if (!isNetworkError && !isHttpStatusError && listener != null) { if (cacheTimeOut > 0) { FileOutputStream fileOutputStream = new FileOutputStream(cacheFile); while ((readLength = is.read(buffer, 0, buffer.length)) != -1) { fileOutputStream.write(buffer, 0, readLength); } fileOutputStream.close(); parseInputStream(new FileInputStream(cacheFile), cipher); } else { parseInputStream(is, cipher); } } else if (isHttpStatusError) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); while ((readLength = is.read(buffer, 0, buffer.length)) != -1) { byteArrayOutputStream.write(buffer, 0, readLength); } byteArrayOutputStream.flush(); errorMessage = byteArrayOutputStream.toString(); } response.getEntity().consumeContent(); } catch (IOException e) { isNetworkError = true; } catch (Exception e) { } } return null; }