Example usage for android.os SystemClock uptimeMillis

List of usage examples for android.os SystemClock uptimeMillis

Introduction

In this page you can find the example usage for android.os SystemClock uptimeMillis.

Prototype

@CriticalNative
native public static long uptimeMillis();

Source Link

Document

Returns milliseconds since boot, not counting time spent in deep sleep.

Usage

From source file:cn.ismartv.tvrecyclerview.widget.RecyclerView.java

/**
 * Enable or disable layout and scroll.  After <code>setLayoutFrozen(true)</code> is called,
 * Layout requests will be postponed until <code>setLayoutFrozen(false)</code> is called;
 * child views are not updated when RecyclerView is frozen, {@link #smoothScrollBy(int, int)},
 * {@link #scrollBy(int, int)}, {@link #scrollToPosition(int)} and
 * {@link #smoothScrollToPosition(int)} are dropped; TouchEvents and GenericMotionEvents are
 * dropped; {@link LayoutManager#onFocusSearchFailed(View, int, Recycler, State)} will not be
 * called./*from   w ww. j  a  v a2  s  .co m*/
 *
 * <p>
 * <code>setLayoutFrozen(true)</code> does not prevent app from directly calling {@link
 * LayoutManager#scrollToPosition(int)}, {@link LayoutManager#smoothScrollToPosition(
 * RecyclerView, State, int)}.
 * <p>
 * {@link #setAdapter(Adapter)} and {@link #swapAdapter(Adapter, boolean)} will automatically
 * stop frozen.
 * <p>
 * Note: Running ItemAnimator is not stopped automatically,  it's caller's
 * responsibility to call ItemAnimator.end().
 *
 * @param frozen   true to freeze layout and scroll, false to re-enable.
 */
public void setLayoutFrozen(boolean frozen) {
    if (frozen != mLayoutFrozen) {
        assertNotInLayoutOrScroll("Do not setLayoutFrozen in layout or scroll");
        if (!frozen) {
            mLayoutFrozen = false;
            if (mLayoutRequestEaten && mLayout != null && mAdapter != null) {
                requestLayout();
            }
            mLayoutRequestEaten = false;
        } else {
            final long now = SystemClock.uptimeMillis();
            MotionEvent cancelEvent = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0);
            onTouchEvent(cancelEvent);
            mLayoutFrozen = true;
            mIgnoreMotionEventTillDown = true;
            stopScroll();
        }
    }
}

From source file:org.bangbang.support.v4.widget.VerticalViewPager.java

/**
 * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first.
 *
 * @param yOffset Offset in pixels to drag by.
 * @see #beginFakeDrag()//from   w w  w.  j av  a2  s.  c  o m
 * @see #endFakeDrag()
 */
public void fakeDragBy(float yOffset) {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }

    mLastMotionY += yOffset;

    float oldScrollY = getScrollY();
    float scrollY = oldScrollY - yOffset;
    final int height = getHeight();

    float bottomBound = height * mFirstOffset;
    float topBound = height * mLastOffset;

    final ItemInfo firstItem = mItems.get(0);
    final ItemInfo lastItem = mItems.get(mItems.size() - 1);
    if (firstItem.position != 0) {
        bottomBound = firstItem.offset * height;
    }
    if (lastItem.position != mAdapter.getCount() - 1) {
        topBound = lastItem.offset * height;
    }

    if (scrollY < bottomBound) {
        scrollY = bottomBound;
    } else if (scrollY > topBound) {
        scrollY = topBound;
    }
    // Don't lose the rounded component
    // bangbang.S
    //        mLastMotionX += scrollX - (int) scrollX;
    mLastMotionY += scrollY - (int) scrollY;
    scrollTo(getScrollX(), (int) scrollY);
    pageScrolled((int) scrollY);

    // Synthesize an event for the VelocityTracker.
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, 0,
            mLastMotionY, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
}

From source file:org.mozilla.gecko.GeckoApp.java

@Override
public void onStart() {
    Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onStart");

    Log.i(LOGTAG, "start");
    GeckoAppShell.sendEventToGecko(GeckoEvent.createStartEvent(mOwnActivityDepth));
    super.onStart();
}

From source file:com.brantapps.viewpagerindicator.vertical.VerticalViewPager.java

/**
 * Start a fake drag of the pager./*  ww  w . java2  s. com*/
 *
 * <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);
    // BrantApps Change: Changed setting of mLastMotionX to mLastMotionY
    mInitialMotionY = mLastMotionY = 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;
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

private void pauseVideoRecording() {
    if (!isRecording)
        return;// w  ww . java2  s .  c om

    // Continue video recording
    if (this.modeDRO()) {
        long now = SystemClock.uptimeMillis();
        long delta = now - mRecordingStartTime;
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                pauseDRORecording();
            }
        }, 1500 - delta);
    } else {
        if (lockPauseButton) {
            return;
        }

        if (onPause) {
            startVideoRecording();
            onPause = false;
        }
        // Pause video recording, merge files and remove last.
        else {
            lockPauseButton = true;
            long now = SystemClock.uptimeMillis();
            long delta = now - mRecordingStartTime;
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                public void run() {
                    pauseRecording();
                    Toast.makeText(ApplicationScreen.instance,
                            ApplicationScreen.instance.getString(R.string.video_paused), Toast.LENGTH_SHORT)
                            .show();
                }
            }, 1500 - delta);
        }
    }
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

private void pauseDRORecording() {
    if (onPause) {
        mRecordingStartTime = SystemClock.uptimeMillis();
        showRecordingUI(isRecording);/*from   w ww .ja v a 2  s  . c o m*/
        onPause = false;
        showRecordingUI(isRecording);

        pauseVideoButton.setImageDrawable(
                ApplicationScreen.getAppResources().getDrawable(R.drawable.plugin_capture_video_pause));
    } else {
        onPause = true;
        stopVideoButton.setImageDrawable(
                ApplicationScreen.getAppResources().getDrawable(R.drawable.plugin_capture_video_stop_square));
        pauseVideoButton.setImageDrawable(ApplicationScreen.getAppResources()
                .getDrawable(R.drawable.plugin_capture_video_pause_transparent));
        Toast.makeText(ApplicationScreen.instance, ApplicationScreen.instance.getString(R.string.video_paused),
                Toast.LENGTH_SHORT).show();
    }
    this.droEngine.setPaused(this.onPause);
}

From source file:com.suning.boxcontroller.control.ExViewPager.java

/**
 * Start a fake drag of the pager.//from ww  w  . ja  v  a  2 s  . com
 *
 * <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 = 0;
    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;
}

From source file:VerticalViewPager.java

/**
 * Start a fake drag of the pager.//from w w  w . ja va2s.  c om
 *
 * <p>A fake drag can be useful if you want to synchronize the motion of the VerticalViewPager
 * with the touch scrolling of another view, while still letting the VerticalViewPager
 * 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 VerticalViewPager 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);
    mInitialMotionY = mLastMotionY = 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;
}

From source file:android.support.custom.view.VerticalViewPager.java

/**
 * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first.
 *
 * @param xOffset Offset in pixels to drag by.
 * @see #beginFakeDrag()//from   www . j a  v a  2s .c  o  m
 * @see #endFakeDrag()
 */
//    public void fakeDragBy(float xOffset) {
public void fakeDragBy(float yOffset) {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }

    mLastMotionY += yOffset;

    float oldScrollY = getScrollY();
    float scrollY = oldScrollY - yOffset;
    final int height = getHeight();

    float topBound = height * mFirstOffset;
    float bottomBound = height * mLastOffset;

    final ItemInfo firstItem = mItems.get(0);
    final ItemInfo lastItem = mItems.get(mItems.size() - 1);
    if (firstItem.position != 0) {
        topBound = firstItem.offset * height;
    }
    if (lastItem.position != mAdapter.getCount() - 1) {
        bottomBound = lastItem.offset * height;
    }

    if (scrollY < topBound) {
        scrollY = topBound;
    } else if (scrollY > bottomBound) {
        scrollY = bottomBound;
    }

    // Don't lose the rounded component
    mLastMotionY += scrollY - (int) scrollY;
    scrollTo(getScrollX(), (int) scrollY);
    pageScrolled((int) scrollY);

    // Synthesize an event for the VelocityTracker.
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, 0,
            mLastMotionY, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
}

From source file:com.brantapps.viewpagerindicator.vertical.VerticalViewPager.java

/**
 * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first.
 *
 * @param yOffset Offset in pixels to drag by.
 * @see #beginFakeDrag()//from w ww  .  j ava  2  s.  co  m
 * @see #endFakeDrag()
 */
// BrantApps Change: Replaced all "X"s with "Y"s (except one noted later), "width"s with "height"s, "left"s with "top"s, "right"s with "bottom"s
public void fakeDragBy(float yOffset) {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }

    mLastMotionY += yOffset;

    float oldScrollY = getScrollY();
    float scrollY = oldScrollY - yOffset;
    final int height = getHeight();

    float topBound = height * mFirstOffset;
    float bottomBound = height * mLastOffset;

    final ItemInfo firstItem = mItems.get(0);
    final ItemInfo lastItem = mItems.get(mItems.size() - 1);
    if (firstItem.position != 0) {
        topBound = firstItem.offset * height;
    }
    if (lastItem.position != mAdapter.getCount() - 1) {
        bottomBound = lastItem.offset * height;
    }

    if (scrollY < topBound) {
        scrollY = topBound;
    } else if (scrollY > bottomBound) {
        scrollY = bottomBound;
    }
    // Don't lose the rounded component
    mLastMotionY += scrollY - (int) scrollY;
    // BrantApps Changed: Was scrollTo((int) scrollX, getScrollY());
    scrollTo(getScrollX(), (int) scrollY);
    pageScrolled((int) scrollY);

    // Synthesize an event for the VelocityTracker.
    final long time = SystemClock.uptimeMillis();
    // BrantApps Change: Was final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX, 0, 0);
    final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, 0,
            mLastMotionY, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
}