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

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

源代码1 项目: DoraemonKit   文件: PicassoDrawable.java
PicassoDrawable(Context context, Bitmap bitmap, Drawable placeholder,
                DokitPicasso.LoadedFrom loadedFrom, boolean noFade, boolean debugging) {
  super(context.getResources(), bitmap);

  this.debugging = debugging;
  this.density = context.getResources().getDisplayMetrics().density;

  this.loadedFrom = loadedFrom;

  boolean fade = loadedFrom != MEMORY && !noFade;
  if (fade) {
    this.placeholder = placeholder;
    animating = true;
    startTimeMillis = SystemClock.uptimeMillis();
  }
}
 
源代码2 项目: FireFiles   文件: AsyncTaskLoader.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
void dispatchOnLoadComplete(LoadTask task, D data) {
    if (mTask != task) {
        if (DEBUG) Log.v(TAG, "Load complete of old task, trying to cancel");
        dispatchOnCancelled(task, data);
    } else {
        if (isAbandoned()) {
            // This cursor has been abandoned; just cancel the new data.
            onCanceled(data);
        } else {
        	if(Utils.hasJellyBeanMR2()){
        		commitContentChanged();
        	}
            mLastLoadCompleteTime = SystemClock.uptimeMillis();
            mTask = null;
            if (DEBUG) Log.v(TAG, "Delivering result");
            deliverResult(data);
        }
    }
}
 
源代码3 项目: letv   文件: DanmakuFilters.java
private void removeTimeoutDanmakus(LinkedHashMap<String, BaseDanmaku> danmakus, int limitTime) {
    Iterator<Entry<String, BaseDanmaku>> it = danmakus.entrySet().iterator();
    long startTime = SystemClock.uptimeMillis();
    while (it.hasNext()) {
        try {
            if (((BaseDanmaku) ((Entry) it.next()).getValue()).isTimeOut()) {
                it.remove();
                if (SystemClock.uptimeMillis() - startTime > ((long) limitTime)) {
                    return;
                }
            }
            return;
        } catch (Exception e) {
            return;
        }
    }
}
 
源代码4 项目: 365browser   文件: VrShellDelegate.java
/**
 * Exits VR Shell, performing all necessary cleanup.
 */
/* package */ void shutdownVr(
        boolean disableVrMode, boolean canReenter, boolean stayingInChrome) {
    cancelPendingVrEntry();
    if (!mInVr) return;
    if (mShowingDaydreamDoff) {
        onExitVrResult(true);
        return;
    }
    mInVr = false;
    mRequestedWebVr = false;
    mAutopresentWebVr = false;
    mLastVrExit = canReenter ? SystemClock.uptimeMillis() : 0;

    // The user has exited VR.
    RecordUserAction.record("VR.DOFF");

    restoreWindowMode();
    mVrShell.pause();
    removeVrViews();
    destroyVrShell();
    if (disableVrMode) mVrClassesWrapper.setVrModeEnabled(mActivity, false);

    promptForFeedbackIfNeeded(stayingInChrome);
}
 
源代码5 项目: Prodigal   文件: LinkagePager.java
/**
 * 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;
}
 
@Override
public void performLongClickOn(final Key key) {
    if (DEBUG_HOVER) {
        Log.d(TAG, "performLongClickOn: key=" + key);
    }
    final PointerTracker tracker = PointerTracker.getPointerTracker(HOVER_EVENT_POINTER_ID);
    final long eventTime = SystemClock.uptimeMillis();
    final int x = key.getHitBox().centerX();
    final int y = key.getHitBox().centerY();
    final MotionEvent downEvent = MotionEvent.obtain(
            eventTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0 /* metaState */);
    // Inject a fake down event to {@link PointerTracker} to handle a long press correctly.
    tracker.processMotionEvent(downEvent, mKeyDetector);
    downEvent.recycle();
    // Invoke {@link PointerTracker#onLongPressed()} as if a long press timeout has passed.
    tracker.onLongPressed();
    // If {@link Key#hasNoPanelAutoMoreKeys()} is true (such as "0 +" key on the phone layout)
    // or a key invokes IME switcher dialog, we should just ignore the next
    // {@link #onRegisterHoverKey(Key,MotionEvent)}. It can be determined by whether
    // {@link PointerTracker} is in operation or not.
    if (tracker.isInOperation()) {
        // This long press shows a more keys keyboard and further hover events should be
        // handled.
        mBoundsToIgnoreHoverEvent.setEmpty();
        return;
    }
    // This long press has handled at {@link MainKeyboardView#onLongPress(PointerTracker)}.
    // We should ignore further hover events on this key.
    mBoundsToIgnoreHoverEvent.set(key.getHitBox());
    if (key.hasNoPanelAutoMoreKey()) {
        // This long press has registered a code point without showing a more keys keyboard.
        // We should talk back the code point if possible.
        final int codePointOfNoPanelAutoMoreKey = key.getMoreKeys()[0].mCode;
        final String text = KeyCodeDescriptionMapper.getInstance().getDescriptionForCodePoint(
                mKeyboardView.getContext(), codePointOfNoPanelAutoMoreKey);
        if (text != null) {
            sendWindowStateChanged(text);
        }
    }
}
 
源代码7 项目: LibreTasks   文件: MediaActionService.java
/**
  * set the phone to silent
  */
 private void playMedia() {
   AudioManager audioManager =(AudioManager) getSystemService(Context.AUDIO_SERVICE);
   long eventtime = SystemClock.uptimeMillis() - 1;
KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY, 0);
KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY, 0);
audioManager.dispatchMediaKeyEvent(downEvent);
audioManager.dispatchMediaKeyEvent(upEvent);
  }
 
@Override
public void perform(UiController uiController, View view) {
  float[] precision = precisionDescriber.describePrecision();
  float[] start = this.start.calculateCoordinates(view);
  float[] end = this.end.calculateCoordinates(view);
  float[][] steps = interpolate(start, end, STEPS);
  int delayBetweenMovements = DURATION / steps.length;
  // Down
  MotionEvent downEvent = MotionEvents.sendDown(uiController, start, precision).down;
  try {
    for (int i = 0; i < steps.length; i++) {
      // Wait
      long desiredTime = downEvent.getDownTime() + (long) (delayBetweenMovements * i);
      long timeUntilDesired = desiredTime - SystemClock.uptimeMillis();
      if (timeUntilDesired > 10L) {
        uiController.loopMainThreadForAtLeast(timeUntilDesired);
      }
      // Move
      if (!MotionEvents.sendMovement(uiController, downEvent, steps[i])) {
        MotionEvents.sendCancel(uiController, downEvent);
        throw new RuntimeException("Cannot drag: failed to send a move event.");
      }
    }
    int duration = ViewConfiguration.getPressedStateDuration();
    if (duration > 0) {
      uiController.loopMainThreadForAtLeast((long) duration);
    }
  } finally {
    downEvent.recycle();
  }
}
 
源代码9 项目: android_9.0.0_r45   文件: Display.java
private void updateCachedAppSizeIfNeededLocked() {
    long now = SystemClock.uptimeMillis();
    if (now > mLastCachedAppSizeUpdate + CACHED_APP_SIZE_DURATION_MILLIS) {
        updateDisplayInfoLocked();
        mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
        mCachedAppWidthCompat = mTempMetrics.widthPixels;
        mCachedAppHeightCompat = mTempMetrics.heightPixels;
        mLastCachedAppSizeUpdate = now;
    }
}
 
源代码10 项目: AndroidComponentPlugin   文件: ActivityThread.java
void doGcIfNeeded() {
    mGcIdlerScheduled = false;
    final long now = SystemClock.uptimeMillis();
    //Slog.i(TAG, "**** WE MIGHT WANT TO GC: then=" + Binder.getLastGcTime()
    //        + "m now=" + now);
    if ((BinderInternal.getLastGcTime()+MIN_TIME_BETWEEN_GCS) < now) {
        //Slog.i(TAG, "**** WE DO, WE DO WANT TO GC!");
        BinderInternal.forceGc("bg");
    }
}
 
源代码11 项目: Viewer   文件: AndroidSpringLooperFactory.java
public LegacyAndroidSpringLooper(Handler handler) {
  mHandler = handler;
  mLooperRunnable = new Runnable() {
    @Override
    public void run() {
      if (!mStarted || mSpringSystem == null) {
        return;
      }
      long currentTime = SystemClock.uptimeMillis();
      mSpringSystem.loop(currentTime - mLastTime);
      mHandler.post(mLooperRunnable);
    }
  };
}
 
源代码12 项目: fresco   文件: StatFsHelper.java
/**
 * (Re)calculate the stats. It is the callers responsibility to ensure thread-safety. Assumes that
 * it is called after initialization (or at the end of it).
 */
@GuardedBy("lock")
private void updateStats() {
  mInternalStatFs = updateStatsHelper(mInternalStatFs, mInternalPath);
  mExternalStatFs = updateStatsHelper(mExternalStatFs, mExternalPath);
  mLastRestatTime = SystemClock.uptimeMillis();
}
 
源代码13 项目: letv   文件: AsyncTaskLoader.java
void dispatchOnCancelled(LoadTask task, D data) {
    onCanceled(data);
    if (this.mCancellingTask == task) {
        rollbackContentChanged();
        this.mLastLoadCompleteTime = SystemClock.uptimeMillis();
        this.mCancellingTask = null;
        deliverCancellation();
        executePendingTask();
    }
}
 
源代码14 项目: CustomViewSets   文件: HorizontalCarouselLayout.java
public void run() {
    HorizontalCarouselLayout.this.mCurTime = SystemClock.uptimeMillis();
    long totalTime = HorizontalCarouselLayout.this.mCurTime - HorizontalCarouselLayout.this.mStartTime;
    if (totalTime > HorizontalCarouselLayout.this.DURATION) {
        if (HorizontalCarouselLayout.this.mItemtoReach > HorizontalCarouselLayout.this.mCurrentItem) {
            HorizontalCarouselLayout.this.fillBottom();
        } else {
            HorizontalCarouselLayout.this.fillTop();
        }
        HorizontalCarouselLayout.this.mCurrentItem = HorizontalCarouselLayout.this.mItemtoReach;
        HorizontalCarouselLayout.this.mGap = 0.0F;
        HorizontalCarouselLayout.this.mIsAnimating = false;

        HorizontalCarouselLayout.this.mCenterView = HorizontalCarouselLayout.this.mCurrentItem;
        if (HorizontalCarouselLayout.this.mCurrentItem >= HorizontalCarouselLayout.this.mMaxChildUnderCenter) {
            HorizontalCarouselLayout.this.mCenterView = HorizontalCarouselLayout.this.mMaxChildUnderCenter;
        }
        HorizontalCarouselLayout.this.removeCallbacks(HorizontalCarouselLayout.this.animationTask);
        if (HorizontalCarouselLayout.this.mCallback != null) {
            HorizontalCarouselLayout.this.mCallback.onItemChangedListener(mAdapter.getView(mCurrentItem, null, HorizontalCarouselLayout.this), mCurrentItem);
        }
    } else {
        float perCent = (float) totalTime / HorizontalCarouselLayout.this.DURATION;
        HorizontalCarouselLayout.this.mGap = ((HorizontalCarouselLayout.this.mCurrentItem - HorizontalCarouselLayout.this.mItemtoReach) * perCent);
        HorizontalCarouselLayout.this.post(this);
    }
    HorizontalCarouselLayout.this.childrenLayout(HorizontalCarouselLayout.this.mGap);
    HorizontalCarouselLayout.this.invalidate();
}
 
源代码15 项目: Camera2   文件: FilmstripView.java
@Override
public boolean onDown(float x, float y)
{
    mLastDownTime = SystemClock.uptimeMillis();
    mLastDownY = y;
    mController.cancelFlingAnimation();
    if (!mController.stopScrolling(false))
    {
        return false;
    }

    return true;
}
 
源代码16 项目: FileManager   文件: ProgressWheel.java
/**
 * Puts the view on spin mode
 */
public void spin() {
    lastTimeAnimated = SystemClock.uptimeMillis();
    isSpinning = true;
    invalidate();
}
 
源代码17 项目: beaconloc   文件: RadarScanView.java
/**
 * Turn on the sweep animation starting with the next draw
 */
public void startSweep() {
    mInfoView.setText(R.string.text_scanning);
    mSweepTime = SystemClock.uptimeMillis();
    mSweepBefore = true;
}
 
boolean showCurrentInputLocked(int flags, ResultReceiver resultReceiver) {
    mShowRequested = true;
    if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) {
        mShowExplicitlyRequested = true;
    }
    if ((flags&InputMethodManager.SHOW_FORCED) != 0) {
        mShowExplicitlyRequested = true;
        mShowForced = true;
    }

    if (!mSystemReady) {
        return false;
    }

    boolean res = false;
    if (mCurMethod != null) {
        if (DEBUG) Slog.d(TAG, "showCurrentInputLocked: mCurToken=" + mCurToken);
        executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO(
                MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod,
                resultReceiver));
        mInputShown = true;
        if (mHaveConnection && !mVisibleBound) {
            bindCurrentInputMethodService(
                    mCurIntent, mVisibleConnection, Context.BIND_AUTO_CREATE);
            mVisibleBound = true;
        }
        res = true;
    } else if (mHaveConnection && SystemClock.uptimeMillis()
            >= (mLastBindTime+TIME_TO_RECONNECT)) {
        // The client has asked to have the input method shown, but
        // we have been sitting here too long with a connection to the
        // service and no interface received, so let's disconnect/connect
        // to try to prod things along.
        EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId,
                SystemClock.uptimeMillis()-mLastBindTime,1);
        Slog.w(TAG, "Force disconnect/connect to the IME in showCurrentInputLocked()");
        mContext.unbindService(this);
        bindCurrentInputMethodService(mCurIntent, this, Context.BIND_AUTO_CREATE
                | Context.BIND_NOT_VISIBLE);
    } else {
        if (DEBUG) {
            Slog.d(TAG, "Can't show input: connection = " + mHaveConnection + ", time = "
                    + ((mLastBindTime+TIME_TO_RECONNECT) - SystemClock.uptimeMillis()));
        }
    }

    return res;
}
 
源代码19 项目: za-Farmer   文件: InteractionController.java
/**
 * Performs a multi-touch gesture
 *
 * Takes a series of touch coordinates for at least 2 pointers. Each pointer must have
 * all of its touch steps defined in an array of {@link PointerCoords}. By having the ability
 * to specify the touch points along the path of a pointer, the caller is able to specify
 * complex gestures like circles, irregular shapes etc, where each pointer may take a
 * different path.
 *
 * To create a single point on a pointer's touch path
 * <code>
 *       PointerCoords p = new PointerCoords();
 *       p.x = stepX;
 *       p.y = stepY;
 *       p.pressure = 1;
 *       p.size = 1;
 * </code>
 * @param touches each array of {@link PointerCoords} constitute a single pointer's touch path.
 *        Multiple {@link PointerCoords} arrays constitute multiple pointers, each with its own
 *        path. Each {@link PointerCoords} in an array constitute a point on a pointer's path.
 * @return <code>true</code> if all points on all paths are injected successfully, <code>false
 *        </code>otherwise
 * @since API Level 18
 */
public boolean performMultiPointerGesture(PointerCoords[] ... touches) {
    boolean ret = true;
    if (touches.length < 2) {
        throw new IllegalArgumentException("Must provide coordinates for at least 2 pointers");
    }

    // Get the pointer with the max steps to inject.
    int maxSteps = 0;
    for (int x = 0; x < touches.length; x++)
        maxSteps = (maxSteps < touches[x].length) ? touches[x].length : maxSteps;

    // specify the properties for each pointer as finger touch
    PointerProperties[] properties = new PointerProperties[touches.length];
    PointerCoords[] pointerCoords = new PointerCoords[touches.length];
    for (int x = 0; x < touches.length; x++) {
        PointerProperties prop = new PointerProperties();
        prop.id = x;
        prop.toolType = MotionEvent.TOOL_TYPE_FINGER;
        properties[x] = prop;

        // for each pointer set the first coordinates for touch down
        pointerCoords[x] = touches[x][0];
    }

    // Touch down all pointers
    long downTime = SystemClock.uptimeMillis();
    MotionEvent event;
    event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 1,
            properties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
    ret &= injectEventSync(event);

    for (int x = 1; x < touches.length; x++) {
        event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(),
                getPointerAction(MotionEvent.ACTION_POINTER_DOWN, x), x + 1, properties,
                pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
        ret &= injectEventSync(event);
    }

    // Move all pointers
    for (int i = 1; i < maxSteps - 1; i++) {
        // for each pointer
        for (int x = 0; x < touches.length; x++) {
            // check if it has coordinates to move
            if (touches[x].length > i)
                pointerCoords[x] = touches[x][i];
            else
                pointerCoords[x] = touches[x][touches[x].length - 1];
        }

        event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(),
                MotionEvent.ACTION_MOVE, touches.length, properties, pointerCoords, 0, 0, 1, 1,
                0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);

        ret &= injectEventSync(event);
        SystemClock.sleep(MOTION_EVENT_INJECTION_DELAY_MILLIS);
    }

    // For each pointer get the last coordinates
    for (int x = 0; x < touches.length; x++)
        pointerCoords[x] = touches[x][touches[x].length - 1];

    // touch up
    for (int x = 1; x < touches.length; x++) {
        event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(),
                getPointerAction(MotionEvent.ACTION_POINTER_UP, x), x + 1, properties,
                pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
        ret &= injectEventSync(event);
    }

    Log.i(LOG_TAG, "x " + pointerCoords[0].x);
    // first to touch down is last up
    event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 1,
            properties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
    ret &= injectEventSync(event);
    return ret;
}
 
源代码20 项目: talkback   文件: EditTextActionHistory.java
/**
 * Stores the start time for a cut action. This should be called immediately before {@link
 * AccessibilityNodeInfoCompat#performAction}.
 */
public void beforeCut() {
  mCutStartTime = SystemClock.uptimeMillis();
}