android.os.SystemClock#sleep ( )源码实例Demo

下面列出了android.os.SystemClock#sleep ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AndroidAPS   文件: BLEComm.java
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);
}
 
源代码2 项目: UIAutomatorWD   文件: UIAutomatorWD.java
@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);
    }
}
 
源代码3 项目: AndroidAPS   文件: DanaRv2ExecutionService.java
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;
}
 
源代码4 项目: fuckView   文件: SelectAppWizard.java
@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);
}
 
源代码5 项目: opencdk-appwidget   文件: SplashActivity.java
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;
}
 
源代码6 项目: PTVGlass   文件: CompassRenderer.java
@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);
        }
    }
}
 
源代码7 项目: fitness_Android   文件: VideoPlayer.java
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();
}
 
源代码8 项目: JayPS-AndroidApp   文件: MessageManager.java
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);
                }
            }
        });
    }
}
 
源代码9 项目: JsDroidCmd   文件: InteractionController.java
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;
}
 
源代码10 项目: aptoide-client-v8   文件: LandscapeUITests.java
/**
 * <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")));
}
 
源代码11 项目: StormPlane   文件: MyPlane.java
/**
 * 设置飞机的无敌时间
 *
 * @param time
 */
public void setInvincibleTime(long time) {
    if (DebugConstant.INVINCIBLE) {
        isInvincible = true;
        SystemClock.sleep(time);
        isInvincible = false;
    }
}
 
源代码12 项目: PUMA   文件: MyInteractionController.java
/**
 * 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);
			}
		}
	};
}
 
源代码13 项目: moserp   文件: RestServiceRegistry.java
private void waitForInitialized() {
    int sleepTime = 200;
    int timeElapsed = 0;
    while (!initialized && !(timeElapsed > LOOP_TIMEOUT)) {
        Log.d("RestServiceRegistry", "waiting...");
        SystemClock.sleep(sleepTime);
        timeElapsed += sleepTime;
    }
}
 
@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)));
}
 
源代码15 项目: AndroidAPS   文件: HistoryBrowseActivity.java
@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");
}
 
源代码16 项目: coursera-android   文件: MediaPlaybackService.java
@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);
}
 
源代码17 项目: android-discourse   文件: RequestQueueTest.java
@Override
protected Response<Object> parseNetworkResponse(NetworkResponse response) {
    mParsedCount.incrementAndGet();
    SystemClock.sleep(mDelayMillis);
    return Response.success(new Object(), CacheTestUtils.makeRandomCacheEntry(null));
}
 
源代码18 项目: AndroidAPS   文件: DanaRSService.java
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;
}
 
源代码19 项目: fingen   文件: FragmentBudget.java
@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();
    }
 
源代码20 项目: Trigger   文件: TestTriggerActivity.java
@Override
void run() {
    lock.acquire();
    SystemClock.sleep(10);
    lock.release();
}