Java Code Examples for android.os.SystemClock#uptimeMillis()

The following examples show how to use android.os.SystemClock#uptimeMillis() . These examples are extracted from open source projects. 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 Project: DoraemonKit   File: PicassoDrawable.java    License: Apache License 2.0 6 votes vote down vote up
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();
  }
}
 
Example 2
Source Project: FireFiles   File: AsyncTaskLoader.java    License: Apache License 2.0 6 votes vote down vote up
@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);
        }
    }
}
 
Example 3
Source Project: letv   File: DanmakuFilters.java    License: Apache License 2.0 6 votes vote down vote up
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;
        }
    }
}
 
Example 4
Source Project: 365browser   File: VrShellDelegate.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source Project: Prodigal   File: LinkagePager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 6
@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);
        }
    }
}
 
Example 7
Source Project: LibreTasks   File: MediaActionService.java    License: Apache License 2.0 5 votes vote down vote up
/**
  * 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);
  }
 
Example 8
@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();
  }
}
 
Example 9
Source Project: android_9.0.0_r45   File: Display.java    License: Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example 10
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");
    }
}
 
Example 11
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);
    }
  };
}
 
Example 12
Source Project: fresco   File: StatFsHelper.java    License: MIT License 5 votes vote down vote up
/**
 * (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();
}
 
Example 13
Source Project: letv   File: AsyncTaskLoader.java    License: Apache License 2.0 5 votes vote down vote up
void dispatchOnCancelled(LoadTask task, D data) {
    onCanceled(data);
    if (this.mCancellingTask == task) {
        rollbackContentChanged();
        this.mLastLoadCompleteTime = SystemClock.uptimeMillis();
        this.mCancellingTask = null;
        deliverCancellation();
        executePendingTask();
    }
}
 
Example 14
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();
}
 
Example 15
Source Project: Camera2   File: FilmstripView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onDown(float x, float y)
{
    mLastDownTime = SystemClock.uptimeMillis();
    mLastDownY = y;
    mController.cancelFlingAnimation();
    if (!mController.stopScrolling(false))
    {
        return false;
    }

    return true;
}
 
Example 16
Source Project: FileManager   File: ProgressWheel.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Puts the view on spin mode
 */
public void spin() {
    lastTimeAnimated = SystemClock.uptimeMillis();
    isSpinning = true;
    invalidate();
}
 
Example 17
Source Project: beaconloc   File: RadarScanView.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Turn on the sweep animation starting with the next draw
 */
public void startSweep() {
    mInfoView.setText(R.string.text_scanning);
    mSweepTime = SystemClock.uptimeMillis();
    mSweepBefore = true;
}
 
Example 18
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;
}
 
Example 19
Source Project: za-Farmer   File: InteractionController.java    License: MIT License 4 votes vote down vote up
/**
 * 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;
}
 
Example 20
Source Project: talkback   File: EditTextActionHistory.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Stores the start time for a cut action. This should be called immediately before {@link
 * AccessibilityNodeInfoCompat#performAction}.
 */
public void beforeCut() {
  mCutStartTime = SystemClock.uptimeMillis();
}