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

The following are Jave code examples for showing how to use uptimeMillis() of the android.os.SystemClock class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: PaoMovie   File: RenderTask.java   View Source Code Vote up 6 votes
@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);
    }
}
 
Example 2
Project: MusicX-music-player   File: TouchManager.java   View Source Code Vote up 6 votes
@Override
        public void onLongPress(MotionEvent e) {
            if (callback != null) {
                callback.onLongClick(e.getX(), e.getY());
            }
            long downTime = SystemClock.uptimeMillis();
            long eventTime = SystemClock.uptimeMillis() + 100;
            float x = 0.0f;
            float y = 0.0f;
            int metaState = 0;
            MotionEvent event = MotionEvent.obtain(
                    downTime,
                    eventTime,
                    MotionEvent.ACTION_CANCEL,
                    x,
                    y,
                    metaState
            );
            view.dispatchTouchEvent(event);
//            onUpEvent(e);
        }
 
Example 3
Project: Toodoo   File: FloatingActionButton.java   View Source Code Vote up 6 votes
@Override
public void onRestoreInstanceState(Parcelable state) {
    if (!(state instanceof ProgressSavedState)) {
        super.onRestoreInstanceState(state);
        return;
    }

    ProgressSavedState ss = (ProgressSavedState) state;
    super.onRestoreInstanceState(ss.getSuperState());

    this.mCurrentProgress = ss.mCurrentProgress;
    this.mTargetProgress = ss.mTargetProgress;
    this.mSpinSpeed = ss.mSpinSpeed;
    this.mProgressWidth = ss.mProgressWidth;
    this.mProgressColor = ss.mProgressColor;
    this.mProgressBackgroundColor = ss.mProgressBackgroundColor;
    this.mShouldProgressIndeterminate = ss.mShouldProgressIndeterminate;
    this.mShouldSetProgress = ss.mShouldSetProgress;
    this.mProgress = ss.mProgress;
    this.mAnimateProgress = ss.mAnimateProgress;
    this.mShowProgressBackground = ss.mShowProgressBackground;

    this.mLastTimeAnimated = SystemClock.uptimeMillis();
}
 
Example 4
Project: GitHub   File: GifFrameLoader.java   View Source Code Vote up 6 votes
private void loadNextFrame() {
  if (!isRunning || isLoadPending) {
    return;
  }
  if (startFromFirstFrame) {
    gifDecoder.resetFrameIndex();
    startFromFirstFrame = false;
  }
  isLoadPending = true;
  // Get the delay before incrementing the pointer because the delay indicates the amount of time
  // we want to spend on the current frame.
  int delay = gifDecoder.getNextDelay();
  long targetTime = SystemClock.uptimeMillis() + delay;

  gifDecoder.advance();
  next = new DelayTarget(handler, gifDecoder.getCurrentFrameIndex(), targetTime);
  requestBuilder.clone().apply(signatureOf(new FrameSignature())).load(gifDecoder).into(next);
}
 
Example 5
Project: Building-Android-UIs-with-Custom-Views   File: GLDrawerES1.java   View Source Code Vote up 6 votes
@Override
public void onDrawFrame(GL10 gl) {
    gl.glClearColor(1.f, 0.f, 0.f, 1.f);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    gl.glLoadIdentity();
    gl.glTranslatef(0.f, 0.f, -50.f);

    long time = SystemClock.uptimeMillis() % 4000L;
    float angle = 0.090f * ((int) time);
    gl.glRotatef(angle, 0.f, 0.f, 1.f);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glColor4f(1.f, 1.f, 1.f, 1.f);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer);

    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
 
Example 6
Project: GitHub   File: DirectionalViewpager.java   View Source Code Vote up 6 votes
/**
 * Start a fake drag of the pager.
 *
 * @return true if the fake drag began successfully, false if it could not be started.
 */
public boolean beginFakeDrag() {
    if (mIsBeingDragged) {
        return false;
    }
    mFakeDragging = true;
    setScrollState(SCROLL_STATE_DRAGGING);
    if (isHorizontal()) {
        mInitialMotionX = mLastMotionX = 0;
    } else {
        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;
}
 
Example 7
Project: SmartChart   File: PieChartRotationAnimatorV8.java   View Source Code Vote up 6 votes
@Override
public void run() {
    long elapsed = SystemClock.uptimeMillis() - start;
    if (elapsed > duration) {
        isAnimationStarted = false;
        handler.removeCallbacks(runnable);
        chart.setChartRotation((int) targetRotation, false);
        animationListener.onAnimationFinished();
        return;
    }
    float scale = Math.min(interpolator.getInterpolation((float) elapsed / duration), 1);
    float rotation = startRotation + (targetRotation - startRotation) * scale;
    rotation = (rotation % 360 + 360) % 360;
    chart.setChartRotation((int) rotation, false);
    handler.postDelayed(this, 16);
}
 
Example 8
Project: Musicoco   File: MarkerDrawable.java   View Source Code Vote up 6 votes
@Override
public void run() {

    long currentTime = SystemClock.uptimeMillis();
    long diff = currentTime - mStartTime;
    if (diff < mDuration) {
        float interpolation = mInterpolator.getInterpolation((float) diff / (float) mDuration);
        scheduleSelf(mUpdater, currentTime + FRAME_DURATION);
        updateAnimation(interpolation);
    } else {
        unscheduleSelf(mUpdater);
        mRunning = false;
        updateAnimation(1f);
        notifyFinishedToListener();
    }
}
 
Example 9
Project: FlickLauncher   File: LauncherModel.java   View Source Code Vote up 5 votes
private void waitForIdle() {
    // Wait until the either we're stopped or the other threads are done.
    // This way we don't start loading all apps until the workspace has settled
    // down.
    synchronized (LoaderTask.this) {
        final long workspaceWaitTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0;

        mHandler.postIdle(new Runnable() {
                public void run() {
                    synchronized (LoaderTask.this) {
                        mLoadAndBindStepFinished = true;
                        if (DEBUG_LOADERS) {
                            Log.d(TAG, "done with previous binding step");
                        }
                        LoaderTask.this.notify();
                    }
                }
            });

        while (!mStopped && !mLoadAndBindStepFinished) {
            try {
                // Just in case mFlushingWorkerThread changes but we aren't woken up,
                // wait no longer than 1sec at a time
                this.wait(1000);
            } catch (InterruptedException ex) {
                // Ignore
            }
        }
        if (DEBUG_LOADERS) {
            Log.d(TAG, "waited "
                    + (SystemClock.uptimeMillis()-workspaceWaitTime)
                    + "ms for previous step to finish binding");
        }
    }
}
 
Example 10
Project: IdealMedia   File: AlmostRippleDrawable.java   View Source Code Vote up 5 votes
@Override
public void run() {

    long currentTime = SystemClock.uptimeMillis();
    long diff = currentTime - mStartTime;
    if (diff < mDuration) {
        float interpolation = mInterpolator.getInterpolation((float) diff / (float) mDuration);
        scheduleSelf(mUpdater, currentTime + FRAME_DURATION);
        updateAnimation(interpolation);
    } else {
        unscheduleSelf(mUpdater);
        mRunning = false;
        updateAnimation(1f);
    }
}
 
Example 11
Project: Instincts-2k17   File: WheelView.java   View Source Code Vote up 5 votes
private void flingWheel() {
    mIsDraggingWheel = false;

    mVelocityTracker.computeCurrentVelocity(1);

    //torque = r X F
    mForceVector.set(mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
    setRadiusVector(mLastWheelTouchX, mLastWheelTouchY);
    float torque = mForceVector.crossProduct(mRadiusVector);

    //dw/dt = torque / I = torque / mr^2
    float wheelRadiusSquared = mWheelBounds.getRadius() * mWheelBounds.getRadius();
    float angularAccel = torque / wheelRadiusSquared;

    //estimate an angular velocity based on the strength of the angular acceleration
    float angularVel = angularAccel * ANGULAR_VEL_COEFFICIENT;

    //clamp the angular velocity
    if (angularVel > MAX_ANGULAR_VEL) angularVel = MAX_ANGULAR_VEL;
    else if (angularVel < -MAX_ANGULAR_VEL) angularVel = -MAX_ANGULAR_VEL;
    mAngularVelocity = angularVel;

    mLastUpdateTime = SystemClock.uptimeMillis();
    mRequiresUpdate = true;

    invalidate();
}
 
Example 12
Project: letv   File: AsyncTaskLoader.java   View Source Code Vote up 5 votes
void dispatchOnCancelled(LoadTask task, D data) {
    onCanceled(data);
    if (this.mCancellingTask == task) {
        rollbackContentChanged();
        this.mLastLoadCompleteTime = SystemClock.uptimeMillis();
        this.mCancellingTask = null;
        executePendingTask();
    }
}
 
Example 13
Project: Sega   File: ProgressWheel.java   View Source Code Vote up 5 votes
@Override protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
  super.onVisibilityChanged(changedView, visibility);

  if (visibility == VISIBLE) {
    lastTimeAnimated = SystemClock.uptimeMillis();
  }
}
 
Example 14
Project: materialprogress   File: ProgressWheel.java   View Source Code Vote up 5 votes
@Override protected void onVisibilityChanged(View changedView, int visibility) {
  super.onVisibilityChanged(changedView, visibility);

  if (visibility == VISIBLE) {
    lastTimeAnimated = SystemClock.uptimeMillis();
  }
}
 
Example 15
Project: editor-sql   File: FloatingActionButton.java   View Source Code Vote up 5 votes
public synchronized void setProgress(int progress, boolean animate) {
    if (mProgressIndeterminate) return;

    mProgress = progress;
    mAnimateProgress = animate;

    if (!mButtonPositionSaved) {
        mShouldSetProgress = true;
        return;
    }

    mProgressBarEnabled = true;
    mShouldUpdateButtonPosition = true;
    setupProgressBounds();
    saveButtonOriginalPosition();
    updateBackground();

    if (progress < 0) {
        progress = 0;
    } else if (progress > mProgressMax) {
        progress = mProgressMax;
    }

    if (progress == mTargetProgress) {
        return;
    }

    mTargetProgress = mProgressMax > 0 ? (progress / (float) mProgressMax) * 360 : 0;
    mLastTimeAnimated = SystemClock.uptimeMillis();

    if (!animate) {
        mCurrentProgress = mTargetProgress;
    }

    invalidate();
}
 
Example 16
Project: Remindy   File: RecordAudioDialogFragment.java   View Source Code Vote up 5 votes
private void startPlaying() {
    //Reset time
    startTime = SystemClock.uptimeMillis();

    TransitionManager.beginDelayedTransition(mContainer);
    mFab.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.icon_check_fab_mini));
    mFab.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(), R.color.fab_accept_green)));
    mRecIcon.setVisibility(View.INVISIBLE);
    mPlayIcon.setVisibility(View.VISIBLE);

    mPlayer = new MediaPlayer();
    try {


        mPlayer.setDataSource(mAudioFilePath);
        mPlayer.prepare();
        mPlayer.start();
        mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                handleDismissDialog();

            }
        });
    } catch (IOException e) {
        Log.e(TAG, "prepare() failed");
    }
}
 
Example 17
Project: bombsquad-remote-android   File: GamePadActivity.java   View Source Code Vote up 4 votes
void _doStateChangeV2(boolean force) {

		//Log.v(TAG,"S "+_dPadStateH+" "+_dPadStateV);
		
		// compile our state value
		int s = _buttonStateV2; // buttons
		int hVal = (int)(256.0f*(0.5f+_dPadStateH*0.5f));
		if (hVal < 0) hVal = 0;
		else if (hVal > 255) hVal = 255;
		
		int vVal = (int)(256.0f*(0.5f+_dPadStateV*0.5f));
		if (vVal < 0) vVal = 0;
		else if (vVal > 255) vVal = 255;

		//Log.v("SDL","H "+hVal+" V "+vVal);
		//Log.v("SDL","H "+hVal);
		
		s |= hVal << 8;
		s |= vVal << 16;
//		s |= (_dPadStateH > 0 ? 1 : 0) << 5; // sign bit
//		s |= ((int) (Math.round(Math.min(1.0, Math.abs(_dPadStateH)) * 15.0))) << 6; // mag
//		s |= (_dPadStateV > 0 ? 1 : 0) << 10; // sign bit
//		s |= ((int) (Math.round(Math.min(1.0, Math.abs(_dPadStateV)) * 15.0))) << 11; // mag

		// if our compiled state value hasn't changed, don't send.
		// (analog joystick noise can send a bunch of redundant states through
		// here)
		// The exception is if forced is true, which is the case with packets
		// that
		// double as keepalives.
		if ((s == _lastSentState) && (!force))
			return;

		_stateBirthTimes[_nextState] = SystemClock.uptimeMillis();
		_stateLastSentTimes[_nextState] = 0;

		if (debug) Log.v(TAG, "STORING NEXT STATE: " + _nextState);
		_statesV2[_nextState] = s;
		_nextState = (_nextState + 1) % 256;
		_lastSentState = s;

		// if we're pretty up to date as far as state acks, lets go ahead
		// and send out this state immediately..
		// (keeps us nice and responsive on low latency networks)
		int unackedCount = (_nextState - _requestedState) & 0xFF; // upcast to
																	// get
																	// unsigned
		if (unackedCount < 0) throw new AssertionError();
		if (unackedCount < 3) {
			_shipUnAckedStatesV2();
		}
	}
 
Example 18
Project: android-dev-challenge   File: VisualizerView.java   View Source Code Vote up 4 votes
/**
 * Calculates, based on the current time, the angle all of the shapes should be at
 *
 * @return The current angle, in radians, that all shapes should be at
 */
private double calcCurrentAngle() {
    long elapsedTime = SystemClock.uptimeMillis() - mStartTime;
    float revolutions = elapsedTime * REVOLUTIONS_PER_SECOND / 1000;
    return revolutions * 2 * Math.PI;
}
 
Example 19
Project: caffe_android_demo   File: MainActivity.java   View Source Code Vote up 4 votes
@Override
protected Integer doInBackground(String... strings) {
    startTime = SystemClock.uptimeMillis();
    return caffeMobile.predictImage(strings[0])[0];
}
 
Example 20
Project: MNImageBrowser   File: ProgressWheel.java   View Source Code Vote up 4 votes
/**
 * Puts the view on spin mode
 */
public void spin() {
  lastTimeAnimated = SystemClock.uptimeMillis();
  isSpinning = true;
  invalidate();
}