Java Code Examples for android.os.SystemClock#sleep()
The following examples show how to use
android.os.SystemClock#sleep() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BLEComm.java From AndroidAPS with GNU Affero General Public License v3.0 | 6 votes |
public synchronized void disconnect(String from) { if (L.isEnabled(L.PUMPBTCOMM)) log.debug("disconnect from: " + from); // cancel previous scheduled disconnection to prevent closing upcomming connection if (scheduledDisconnection != null) scheduledDisconnection.cancel(false); scheduledDisconnection = null; if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { log.error("disconnect not possible: (mBluetoothAdapter == null) " + (mBluetoothAdapter == null)); log.error("disconnect not possible: (mBluetoothGatt == null) " + (mBluetoothGatt == null)); return; } setCharacteristicNotification(getUARTReadBTGattChar(), false); mBluetoothGatt.disconnect(); isConnected = false; SystemClock.sleep(2000); }
Example 2
Source File: SelectAppWizard.java From fuckView with GNU Affero General Public License v3.0 | 6 votes |
@SuppressLint({"ApplySharedPref", "WorldReadableFiles"}) @Override public void onWizardComplete() { super.onWizardComplete(); if (Step1.sSelected == null) { return; } mCon.getSharedPreferences("data", Context.MODE_WORLD_READABLE) .edit().putString(Constant.PACKAGE_NAME_NAME, Step1.sSelected.packageName).commit(); //等待數據寫入完成 SystemClock.sleep(100); PackageUtils.asyncStopProcess(Step1.sSelected.packageName, new Runnable() { @Override public void run() { mCon.runOnUiThread(new Runnable() { @Override public void run() { startActivity(); } }); } }, null); }
Example 3
Source File: DanaRv2ExecutionService.java From AndroidAPS with GNU Affero General Public License v3.0 | 6 votes |
public boolean tempBasalShortDuration(int percent, int durationInMinutes) { DanaRPump danaRPump = DanaRPump.getInstance(); if (durationInMinutes != 15 && durationInMinutes != 30) { log.error("Wrong duration param"); return false; } if (!isConnected()) return false; if (danaRPump.isTempBasalInProgress) { RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStop()); SystemClock.sleep(500); } RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.settingtempbasal))); mSerialIOThread.sendMessage(new MsgSetAPSTempBasalStart_v2(percent, durationInMinutes == 15, durationInMinutes == 30)); mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2()); loadEvents(); RxBus.INSTANCE.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); return true; }
Example 4
Source File: UIAutomatorWD.java From UIAutomatorWD with MIT License | 6 votes |
@Test public void MacacaTestRunner() throws Exception { Bundle args = InstrumentationRegistry.getArguments(); int port = 9001; if (args.containsKey("port")) { port = Integer.parseInt(args.getString("port")); } UIAutomatorWDServer server = UIAutomatorWDServer.getInstance(port); Utils.print("UIAutomatorWD->" + "http://localhost:" + server.getListeningPort() + "<-UIAutomatorWD"); if (args.containsKey("permissionPattern")) { JSONArray permissionPatterns = JSON.parseArray(args.getString("permissionPattern")); skipPermission(permissionPatterns, 15); } while (true) { SystemClock.sleep(1000); } }
Example 5
Source File: MyInteractionController.java From PUMA with Apache License 2.0 | 5 votes |
/** * Returns a Runnable for use in {@link #runAndWaitForEvents(Runnable, Predicate, long) to * perform a click. * * @param x coordinate * @param y coordinate * @return Runnable */ private Runnable clickRunnable(final int x, final int y) { return new Runnable() { @Override public void run() { if (touchDown(x, y)) { SystemClock.sleep(REGULAR_CLICK_LENGTH); touchUp(x, y); } } }; }
Example 6
Source File: MediaPlaybackService.java From coursera-android with MIT License | 5 votes |
@Override public void onCompletion(MediaPlayer mp) { if (mNextPlayer != null) { // as it turns out, starting a new MediaPlayer on the completion // of a previous player ends up slightly overlapping the two // playbacks, so slightly delaying the start of the next player // gives a better user experience SystemClock.sleep(50); mNextPlayer.start(); } mCompletion.onCompletion(this); }
Example 7
Source File: HistoryBrowseActivity.java From AndroidAPS with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onResume() { super.onResume(); disposable.add(RxBus.INSTANCE .toObservable(EventAutosensCalculationFinished.class) .observeOn(AndroidSchedulers.mainThread()) .subscribe(event -> { if (event.getCause() == eventCustomCalculationFinished) { log.debug("EventAutosensCalculationFinished"); synchronized (HistoryBrowseActivity.this) { updateGUI("EventAutosensCalculationFinished"); } } }, FabricPrivacy::logException) ); disposable.add(RxBus.INSTANCE .toObservable(EventIobCalculationProgress.class) .observeOn(AndroidSchedulers.mainThread()) .subscribe(event -> { if (iobCalculationProgressView != null) iobCalculationProgressView.setText(event.getProgress()); }, FabricPrivacy::logException) ); // set start of current day Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR_OF_DAY, 0); start = calendar.getTimeInMillis(); runCalculation("onResume"); SystemClock.sleep(1000); updateGUI("onResume"); }
Example 8
Source File: CardSwipeDismissFragmentTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test public void testSnackbarBehavior_afterSwipingCard() { // Test snackbar is displayed after swipe and undo action makes the card be visible. onView(withId(R.id.card_content_layout)).perform(swipeRight()); // Sleep until espresso can recognize the Snackbar SystemClock.sleep(300); onView(withText(R.string.cat_card_dismissed)).check(matches(isDisplayed())); onView(withText(R.string.cat_card_undo)).perform(click()); onView(withId(R.id.card_content_layout)).check(matches(ViewMatchers.withAlpha(1))); }
Example 9
Source File: RestServiceRegistry.java From moserp with Apache License 2.0 | 5 votes |
private void waitForInitialized() { int sleepTime = 200; int timeElapsed = 0; while (!initialized && !(timeElapsed > LOOP_TIMEOUT)) { Log.d("RestServiceRegistry", "waiting..."); SystemClock.sleep(sleepTime); timeElapsed += sleepTime; } }
Example 10
Source File: MyPlane.java From StormPlane with Apache License 2.0 | 5 votes |
/** * 设置飞机的无敌时间 * * @param time */ public void setInvincibleTime(long time) { if (DebugConstant.INVINCIBLE) { isInvincible = true; SystemClock.sleep(time); isInvincible = false; } }
Example 11
Source File: LandscapeUITests.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
/** * <p>Mock User LoggedIn.</p> * Navigate to My Account. Presses Edit Store. Modify store description. Switch to * landscape. Check if the change is still there */ @Test public void landscapeEditStoreDescription() { TestType.initialization = TestType.TestTypes.LOGGEDINWITHSTORE; goToMyAccount(); SystemClock.sleep(5000); onView(withId(R.id.my_account_edit_user_store)).perform(click()); onView(withId(R.id.edit_store_description)).perform(click()); Activity activity = mActivityRule.getActivity(); onView(withId(R.id.edit_store_description)).perform(replaceText("D011"), closeSoftKeyboard()); activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); onView(withId(R.id.edit_store_description)).check(matches(withText("D011"))); }
Example 12
Source File: InteractionController.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
public boolean sendText(String text) { if (DEBUG) { Log.d(LOG_TAG, "sendText (" + text + ")"); } KeyEvent[] events = mKeyCharacterMap.getEvents(text.toCharArray()); if (events != null) { long keyDelay = Configurator.getInstance().getKeyInjectionDelay(); for (KeyEvent event2 : events) { // We have to change the time of an event before injecting it // because // all KeyEvents returned by KeyCharacterMap.getEvents() have // the same // time stamp and the system rejects too old events. Hence, it // is // possible for an event to become stale before it is injected // if it // takes too long to inject the preceding ones. KeyEvent event = KeyEvent.changeTimeRepeat(event2, SystemClock.uptimeMillis(), 0); if (!injectEventSync(event)) { return false; } SystemClock.sleep(keyDelay); } } return true; }
Example 13
Source File: MessageManager.java From JayPS-AndroidApp with MIT License | 5 votes |
private void consumeAsync() { if (debug) Log.v(TAG, "consumeAsync"); boolean needToWait = false; synchronized (_hasStarted) { if (_hasStarted.booleanValue() == false) { needToWait = true; } } if (needToWait) { Log.d(TAG, "Race condition, wait for run()"); SystemClock.sleep(2000); } synchronized (_hasStarted) { messageHandler.post(new Runnable() { @Override public void run() { synchronized (isMessagePending) { if (isMessagePending.booleanValue()) { return; } synchronized (messageQueue) { if (messageQueue.size() == 0) { return; } transID = (transID + 1) % 256; PebbleDictionary data = messageQueue.peek(); if (debug) Log.i(TAG, "sendDataToPebble s:" + messageQueue.size() + " transID:" + transID + " " + data.toJsonString()); PebbleKit.sendDataToPebbleWithTransactionId(_applicationContext, Constants.WATCH_UUID, data, transID); } isMessagePending = Boolean.valueOf(true); } } }); } }
Example 14
Source File: VideoPlayer.java From fitness_Android with Apache License 2.0 | 5 votes |
private void showInfo() { String message = ""; switch (tag) { case 1: message = "“肌撕裂者-初级”"; break; case 2: message = "“肌撕裂者-中级”"; break; case 3: message = "“肌撕裂者-极致”"; break; } SystemClock.sleep(1000); AlertDialog.Builder builder = new AlertDialog.Builder(VideoPlayer.this); builder.setTitle("锻炼结束") .setMessage("恭喜你," + message + "锻炼结束!") .setPositiveButton("好的", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }) .create() .show(); }
Example 15
Source File: CompassRenderer.java From PTVGlass with MIT License | 5 votes |
@Override public void run() { while (shouldRun()) { long frameStart = SystemClock.elapsedRealtime(); repaint(); long frameLength = SystemClock.elapsedRealtime() - frameStart; long sleepTime = FRAME_TIME_MILLIS - frameLength; if (sleepTime > 0) { SystemClock.sleep(sleepTime); } } }
Example 16
Source File: SplashActivity.java From opencdk-appwidget with Apache License 2.0 | 5 votes |
protected boolean subHandlerCallback(Message msg) { switch (msg.what) { case MSG_SUB_INIT_TASK: SystemClock.sleep(2 * 1000); // SystemClock.sleep(600); getUiHandler().sendEmptyMessage(MSG_UI_INIT_FINISH); break; } return false; }
Example 17
Source File: RequestQueueTest.java From android-discourse with Apache License 2.0 | 4 votes |
@Override protected Response<Object> parseNetworkResponse(NetworkResponse response) { mParsedCount.incrementAndGet(); SystemClock.sleep(mDelayMillis); return Response.success(new Object(), CacheTestUtils.makeRandomCacheEntry(null)); }
Example 18
Source File: DanaRSService.java From AndroidAPS with GNU Affero General Public License v3.0 | 4 votes |
public PumpEnactResult loadHistory(byte type) { PumpEnactResult result = new PumpEnactResult(); if (!isConnected()) return result; DanaRS_Packet_History_ msg = null; switch (type) { case RecordTypes.RECORD_TYPE_ALARM: msg = new DanaRS_Packet_History_Alarm(); break; case RecordTypes.RECORD_TYPE_PRIME: msg = new DanaRS_Packet_History_Prime(); break; case RecordTypes.RECORD_TYPE_BASALHOUR: msg = new DanaRS_Packet_History_Basal(); break; case RecordTypes.RECORD_TYPE_BOLUS: msg = new DanaRS_Packet_History_Bolus(); break; case RecordTypes.RECORD_TYPE_CARBO: msg = new DanaRS_Packet_History_Carbohydrate(); break; case RecordTypes.RECORD_TYPE_DAILY: msg = new DanaRS_Packet_History_Daily(); break; case RecordTypes.RECORD_TYPE_GLUCOSE: msg = new DanaRS_Packet_History_Blood_Glucose(); break; case RecordTypes.RECORD_TYPE_REFILL: msg = new DanaRS_Packet_History_Refill(); break; case RecordTypes.RECORD_TYPE_SUSPEND: msg = new DanaRS_Packet_History_Suspend(); break; } if (msg != null) { bleComm.sendMessage(new DanaRS_Packet_General_Set_History_Upload_Mode(1)); SystemClock.sleep(200); bleComm.sendMessage(msg); while (!msg.done && isConnected()) { SystemClock.sleep(100); } SystemClock.sleep(200); bleComm.sendMessage(new DanaRS_Packet_General_Set_History_Upload_Mode(0)); } result.success = true; result.comment = "OK"; return result; }
Example 19
Source File: FragmentBudget.java From fingen with Apache License 2.0 | 4 votes |
@SuppressLint("DefaultLocale") private void loadData() throws Exception { if (getActivity() == null) return; // Debug.startMethodTracing("BudgetLoadData"); // Log.d(TAG, String.format("Start loading %d %d...", mMonth, mYear)); long totalTime = System.currentTimeMillis(); long time = System.currentTimeMillis(); while (!((ActivityBudget) getActivity()).canAccessDb) { SystemClock.sleep(50); } Log.d(TAG, "Wait for db " + String.valueOf(System.currentTimeMillis() - time)); ((ActivityBudget) getActivity()).canAccessDb = false; time = System.currentTimeMillis(); adapter.setmTree( CategoryManager.convertListToTree(CategoriesDAO.getInstance(getActivity()) .getAllCategoriesWithPlanFact(mYear, mMonth)) .addDebtsCategories(getActivity(), mYear, mMonth) .removeEmptySums() ); Log.d(TAG, "Load plan and fact for categories " + String.valueOf(System.currentTimeMillis() - time)); time = System.currentTimeMillis(); CategoryManager.updatePlanAndFactForParents(adapter.getmTree()); Log.d(TAG, "Update plan and fact for parents " + String.valueOf(System.currentTimeMillis() - time)); updateRwHandler.sendMessage(updateRwHandler.obtainMessage(0, 0, 0)); time = System.currentTimeMillis(); ioSums = getIoSumsFromTree(adapter.getmTree().getFlatChildrenList()); isIoSumsLoaded = true; Log.d(TAG, "Get IO sums from categories tree " + String.valueOf(System.currentTimeMillis() - time)); adapterSummary.setmTree(new CNode(new Category(), null)); int ind = 0; CNode newNode; Category categoryTotalIO = new Category(AdapterBudget.BUDGET_ITEM_TOTAL_IO, getActivity().getString(R.string.ent_budget_total_io_for_month), new Category(), 0, true); newNode = adapterSummary.getmTree().insertChild(ind++, categoryTotalIO); newNode.getmCategory().setBudget(new BudgetForCategory(ioSums, AdapterBudget.INFO_TYPE_TR_TOTAL)); newNode = adapterSummary.getmTree().addChild(new Category(AdapterBudget.BUDGET_ITEM_INCOME, getActivity().getString(R.string.ent_budget_total_income), categoryTotalIO, 0, true)); newNode.getmCategory().setBudget(new BudgetForCategory(ioSums, AdapterBudget.INFO_TYPE_TR_INCOME)); newNode = adapterSummary.getmTree().addChild(new Category(AdapterBudget.BUDGET_ITEM_OUTCOME, getActivity().getString(R.string.ent_budget_total_outcome), categoryTotalIO, 0, true)); newNode.getmCategory().setBudget(new BudgetForCategory(ioSums, AdapterBudget.INFO_TYPE_TR_OUTCOME)); time = System.currentTimeMillis(); if (CreditsDAO.getInstance(getActivity()).getAllDebts().size() > 0) { Category categoryTotalDebts = new Category(AdapterBudget.BUDGET_ITEM_TOTAL_DEBTS, getActivity().getString(R.string.ent_budget_total_credits), new Category(), 0, true); ListSumsByCabbage creditSums = getDebtSums(); newNode = adapterSummary.getmTree().insertChild(ind++, categoryTotalDebts); newNode.getmCategory().setBudget(new BudgetForCategory(creditSums, AdapterBudget.INFO_TYPE_ALL_TOTAL)); newNode = adapterSummary.getmTree().addChild(new Category(AdapterBudget.BUDGET_ITEM_BORROW, getActivity().getString(R.string.ent_budget_total_borrow), categoryTotalDebts, 0, true)); newNode.getmCategory().setBudget(new BudgetForCategory(creditSums, AdapterBudget.INFO_TYPE_OUTCOME_TOTAL)); newNode = adapterSummary.getmTree().addChild(new Category(AdapterBudget.BUDGET_ITEM_REPAY, getActivity().getString(R.string.ent_budget_total_repay), categoryTotalDebts, 0, true)); newNode.getmCategory().setBudget(new BudgetForCategory(creditSums, AdapterBudget.INFO_TYPE_INCOME_TOTAL)); } Log.d(TAG, "Get debts from DB " + String.valueOf(System.currentTimeMillis() - time)); Log.d(TAG, String.format("Total time %d %d - %d ms", mYear, mMonth, System.currentTimeMillis() - totalTime)); updateRwHandler.sendMessage(updateRwHandler.obtainMessage(0, 0, 0)); isUpdating = false; ((ActivityBudget) getActivity()).canAccessDb = true; // Debug.stopMethodTracing(); }
Example 20
Source File: TestTriggerActivity.java From Trigger with Apache License 2.0 | 4 votes |
@Override void run() { lock.acquire(); SystemClock.sleep(10); lock.release(); }