本文整理汇总了Java中android.os.SystemClock类的典型用法代码示例。如果您正苦于以下问题:Java SystemClock类的具体用法?Java SystemClock怎么用?Java SystemClock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SystemClock类属于android.os包,在下文中一共展示了SystemClock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setTimeInterval
import android.os.SystemClock; //导入依赖的package包/类
public static void setTimeInterval(Context context){
Log.d(TAG, "Entered set time interval");
Intent selfIntent = getIntent(context);
PendingIntent pendingIntent = PendingIntent.getService(context, 0,
selfIntent, 0);
AlarmManager manager = (AlarmManager) context.getSystemService
(Context.ALARM_SERVICE);
if (isTimeAlarmOn(context)){
manager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime(), REPEAT_TIME,
pendingIntent);
Log.d(TAG, "Alarm is not on, starting it now");
}else {
manager.cancel(pendingIntent);
pendingIntent.cancel();
Log.d(TAG, "Alarm is on, cancelling it now");
}
}
示例2: onVisibilityChanged
import android.os.SystemClock; //导入依赖的package包/类
@Override
protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
super.onVisibilityChanged(changedView, visibility);
// avoid doing this check before View is even visible
if (timeStart != -1) {
if ((visibility == View.INVISIBLE || visibility == View.GONE) &&
previousVisibility == View.VISIBLE) {
invisibleTimeStart = SystemClock.elapsedRealtime();
}
if ((previousVisibility == View.INVISIBLE || previousVisibility == View.GONE) &&
visibility == View.VISIBLE) {
timeStart += SystemClock.elapsedRealtime() - invisibleTimeStart;
}
} else {
timeStart = SystemClock.elapsedRealtime();
}
previousVisibility = visibility;
}
开发者ID:PacktPublishing,项目名称:Building-Android-UIs-with-Custom-Views,代码行数:24,代码来源:FixedTimestepExample.java
示例3: onClick
import android.os.SystemClock; //导入依赖的package包/类
@Override
public final void onClick(View v) {
final long lastClickTime = mLastClickTime;
final long now = SystemClock.uptimeMillis(); //guaranteed 100% monotonic
if (now - lastClickTime < MIN_DELAY_MS && !override) {
// Too fast: ignore
if (Config.LOGD) {
Log.d(TAG, "onClick Clicked too quickly: ignored");
}
} else {
override = false;
// Update mLastClickTime and register the click
mLastClickTime = now;
onSingleClick(v);
}
}
示例4: doWork
import android.os.SystemClock; //导入依赖的package包/类
@Override
public void doWork() {
final long invalidationDelay = mGifDrawable.mNativeInfoHandle.renderFrame(mGifDrawable.mBuffer);
if (invalidationDelay >= 0) {
mGifDrawable.mNextFrameRenderTime = SystemClock.uptimeMillis() + invalidationDelay;
if (mGifDrawable.isVisible()) {
if (mGifDrawable.mIsRunning && !mGifDrawable.mIsRenderingTriggeredOnDraw) {
mGifDrawable.mExecutor.schedule(this, invalidationDelay, TimeUnit.MILLISECONDS);
}
}
if (!mGifDrawable.mListeners.isEmpty() && mGifDrawable.getCurrentFrameIndex() == mGifDrawable.mNativeInfoHandle.frameCount - 1) {
mGifDrawable.scheduleSelf(mNotifyListenersTask, mGifDrawable.mNextFrameRenderTime);
}
} else {
mGifDrawable.mNextFrameRenderTime = Long.MIN_VALUE;
mGifDrawable.mIsRunning = false;
}
if (mGifDrawable.isVisible() && !mGifDrawable.mInvalidationHandler.hasMessages(0)) {
mGifDrawable.mInvalidationHandler.sendEmptyMessageAtTime(0, 0);
}
}
示例5: startAndStopRun
import android.os.SystemClock; //导入依赖的package包/类
@Test
public void startAndStopRun() {
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
onView(withId(R.id.nav_view)).perform(NavigationViewActions.navigateTo(R.id.nav_run));
// Jenkins sleep (1/3)
//
// Sleep necessary in order to successfully build on Jenkins, I wasn't able to
// reproduce the failure in local. After a lot of attempts I decided to keep it.
SystemClock.sleep(FIREBASE_DURATION);
onView(isRoot()).perform(waitForMatch(withId(R.id.start_run), UI_TEST_TIMEOUT));
onView(withId(R.id.start_run)).perform(click());
SystemClock.sleep(MOCK_LOCATION_DURATION);
onView(isRoot()).perform(waitForMatch(withId(R.id.stop_run), UI_TEST_TIMEOUT));
onView(withId(R.id.stop_run)).perform(click());
onView(isRoot()).perform(waitForMatch(withId(R.id.button_history), UI_TEST_TIMEOUT));
onView(withId(R.id.button_history)).perform(click());
}
示例6: onStart
import android.os.SystemClock; //导入依赖的package包/类
@Override
protected void onStart() {
super.onStart();
compositeSubscription.add(RxView.clicks(binding.buttonDebounce)
.observeOn(Schedulers.computation())
.debounce(3, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(v -> binding.textDebounceResult.setText("Debounce Completed")));
compositeSubscription.add(RxView.clicks(binding.buttonSleep)
.observeOn(Schedulers.io())
.map(v -> {
SystemClock.sleep(3000L);
return v;
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(v -> binding.textSleepResult.setText("Sleep Completed")));
}
示例7: onStart
import android.os.SystemClock; //导入依赖的package包/类
@Override
protected void onStart() {
super.onStart();
compositeDisposable.add(RxView.clicks(binding.buttonDebounce)
.observeOn(Schedulers.computation())
.debounce(3, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(v -> binding.textDebounceResult.setText("Debounce Completed")));
compositeDisposable.add(RxView.clicks(binding.buttonSleep)
.observeOn(Schedulers.io())
.map(v -> {
SystemClock.sleep(3000L);
return v;
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(v -> binding.textSleepResult.setText("Sleep Completed")));
}
示例8: onPlayerStateChanged
import android.os.SystemClock; //导入依赖的package包/类
@Override
public final void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
Log.d(tag, "state [" + playWhenReady + ", " + playbackState + "]");
playerWasPrepared |= playbackState != ExoPlayer.STATE_IDLE;
if (playbackState == ExoPlayer.STATE_ENDED
|| (playbackState == ExoPlayer.STATE_IDLE && playerWasPrepared)) {
playerFinished = true;
}
boolean playing = playWhenReady && playbackState == ExoPlayer.STATE_READY;
if (!this.playing && playing) {
lastPlayingStartTimeMs = SystemClock.elapsedRealtime();
} else if (this.playing && !playing) {
totalPlayingTimeMs += SystemClock.elapsedRealtime() - lastPlayingStartTimeMs;
}
this.playing = playing;
}
示例9: loadValues
import android.os.SystemClock; //导入依赖的package包/类
private void loadValues() {
long startTime = SystemClock.elapsedRealtime();
Timber.i("Loading preferences from DB into Storage");
Cursor cursor = null;
SQLiteDatabase mDb = null;
try {
mDb = openDB();
cursor = mDb.rawQuery("SELECT primkey, value FROM preferences_storage", null);
while (cursor.moveToNext()) {
String key = cursor.getString(0);
String value = cursor.getString(1);
Timber.d("Loading key '%s', value = '%s'", key, value);
storage.put(key, value);
}
} finally {
Utility.closeQuietly(cursor);
if (mDb != null) {
mDb.close();
}
long endTime = SystemClock.elapsedRealtime();
Timber.i("Preferences load took %d ms", endTime - startTime);
}
}
示例10: a
import android.os.SystemClock; //导入依赖的package包/类
public void a(int i, String str, String str2, String str3, String str4, Long l, int i2, int
i3, String str5) {
long j;
long elapsedRealtime = SystemClock.elapsedRealtime() - l.longValue();
if (l.longValue() == 0 || elapsedRealtime < 0) {
j = 0;
} else {
j = elapsedRealtime;
}
StringBuffer stringBuffer = new StringBuffer("http://c.isdspeed.qq.com/code.cgi");
stringBuffer.append("?domain=mobile.opensdk.com&cgi=opensdk&type=").append(i).append
("&code=").append(i2).append("&time=").append(j).append("&rate=").append(i3)
.append("&uin=").append(str2).append("&data=");
g.a().a(stringBuffer.toString(), "GET", Util.composeHaboCgiReportParams(String.valueOf(i)
, String.valueOf(i2), String.valueOf(j), String.valueOf(i3), str, str2, str3,
str4, str5), true);
}
示例11: saveImage
import android.os.SystemClock; //导入依赖的package包/类
public void saveImage(String location, Bitmap bmp) {
if (TextUtils.isEmpty(location)) {
location = Environment.getExternalStorageDirectory()
+ File.pathSeparator + SystemClock.currentThreadTimeMillis() + ".jpg";
}
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
File file = new File(location);
try {
file.createNewFile();
FileOutputStream outputStream = new FileOutputStream(file);
outputStream.write(bytes.toByteArray());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例12: onStartCommand
import android.os.SystemClock; //导入依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
updateWeather();
updateBingPic();
AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
int anHour = 4 * 60 * 60 * 1000;//4个小时的毫秒数
long triggerAtTime = SystemClock.elapsedRealtime() + anHour;
Intent i = new Intent(this, AutoUpdateService.class);
PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
manager.cancel(pi);
manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pi);
return super.onStartCommand(intent, flags, startId);
}
示例13: run
import android.os.SystemClock; //导入依赖的package包/类
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
if (elapsed > duration) {
isAnimationStarted = false;
handler.removeCallbacks(runnable);
chart.setCurrentViewport(targetViewport);
animationListener.onAnimationFinished();
return;
}
float scale = Math.min(interpolator.getInterpolation((float) elapsed / duration), 1);
float diffLeft = (targetViewport.left - startViewport.left) * scale;
float diffTop = (targetViewport.top - startViewport.top) * scale;
float diffRight = (targetViewport.right - startViewport.right) * scale;
float diffBottom = (targetViewport.bottom - startViewport.bottom) * scale;
newViewport.set(startViewport.left + diffLeft, startViewport.top + diffTop,
startViewport.right + diffRight, startViewport.bottom + diffBottom);
chart.setCurrentViewport(newViewport);
handler.postDelayed(this, 16);
}
示例14: beginFakeDrag
import android.os.SystemClock; //导入依赖的package包/类
/**
* Start a fake drag of the pager.
*
* <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
* with the touch scrolling of another view, while still letting the ViewPager
* control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
* Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
* {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
*
* <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
* is already in progress, this method will return false.
*
* @return true if the fake drag began successfully, false if it could not be started.
*
* @see #fakeDragBy(float)
* @see #endFakeDrag()
*/
public boolean beginFakeDrag() {
if (mIsBeingDragged) {
return false;
}
mFakeDragging = true;
setScrollState(SCROLL_STATE_DRAGGING);
mInitialMotionX = mLastMotionX = 0;
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
} else {
mVelocityTracker.clear();
}
final long time = SystemClock.uptimeMillis();
final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
mFakeDragBeginTime = time;
return true;
}
示例15: setAlarm
import android.os.SystemClock; //导入依赖的package包/类
public void setAlarm(long millisecondsInFuture) {
long currentTime = SystemClock.uptimeMillis();
mAlarmPending = true;
long oldTriggerTime = mAlarmTriggerTime;
mAlarmTriggerTime = currentTime + millisecondsInFuture;
// If the previous alarm was set for a longer duration, cancel it.
if (mWaitingForCallback && oldTriggerTime > mAlarmTriggerTime) {
mHandler.removeCallbacks(this);
mWaitingForCallback = false;
}
if (!mWaitingForCallback) {
mHandler.postDelayed(this, mAlarmTriggerTime - currentTime);
mWaitingForCallback = true;
}
}