當前位置: 首頁>>代碼示例>>Java>>正文


Java SystemClock類代碼示例

本文整理匯總了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");
    }
}
 
開發者ID:aumarbello,項目名稱:WalkGraph,代碼行數:21,代碼來源:TimeService.java

示例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);
    }
}
 
開發者ID:ccrama,項目名稱:Slide-RSS,代碼行數:18,代碼來源:OnSingleClickListener.java

示例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);
    }
}
 
開發者ID:smartbeng,項目名稱:PaoMovie,代碼行數:22,代碼來源:RenderTask.java

示例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());
}
 
開發者ID:IrrilevantHappyLlamas,項目名稱:Runnest,代碼行數:23,代碼來源:RunTest.java

示例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")));
}
 
開發者ID:sumio,項目名稱:RxJavaEspressoSample,代碼行數:19,代碼來源:RxJava1Activity.java

示例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")));
}
 
開發者ID:sumio,項目名稱:RxJavaEspressoSample,代碼行數:19,代碼來源:RxJava2Activity.java

示例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;
}
 
開發者ID:ashwanijanghu,項目名稱:ExoPlayer-Offline,代碼行數:17,代碼來源:ExoHostedTest.java

示例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);
    }
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:25,代碼來源:Storage.java

示例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);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:18,代碼來源:d.java

示例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();
	}
}
 
開發者ID:MobClub,項目名稱:BBSSDK-for-Android,代碼行數:18,代碼來源:ImageUtils.java

示例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);
}
 
開發者ID:zhegeshijiehuiyouai,項目名稱:Weather365,代碼行數:14,代碼來源:AutoUpdateService.java

示例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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:ChartViewportAnimatorV8.java

示例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;
}
 
開發者ID:sega4revenge,項目名稱:Sega,代碼行數:37,代碼來源:ViewPagerEx.java

示例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;
    }
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:17,代碼來源:Alarm.java


注:本文中的android.os.SystemClock類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。