List of usage examples for android.os SystemClock uptimeMillis
@CriticalNative native public static long uptimeMillis();
From source file:silent.kuasapmaterial.libs.ProgressWheel.java
protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isCircleBackground) { if (isShadow) { canvas.drawCircle(circleBounds2.centerX() + mShadowSize / 2, circleBounds2.centerY() + mShadowSize, circleBounds2.width() / 2 + mShadowSize / 2, shadowPaint); }//from ww w .j a v a 2s . co m canvas.drawCircle(circleBounds2.centerX(), circleBounds2.centerY(), circleBounds2.width() / 2, circlePaint); } canvas.drawArc(circleBounds, 360, 360, false, rimPaint); boolean mustInvalidate = false; if (isSpinning) { //Draw the spinning bar mustInvalidate = true; long deltaTime = (SystemClock.uptimeMillis() - lastTimeAnimated); float deltaNormalized = deltaTime * spinSpeed / 1000.0f; updateBarLength(deltaTime); mProgress += deltaNormalized; if (mProgress > 360) { mProgress -= 360f; // A full turn has been completed // we run the callback with -1 in case we want to // do something, like changing the color runCallback(-1.0f); } lastTimeAnimated = SystemClock.uptimeMillis(); float from = mProgress - 90; float length = barLength + barExtraLength; if (isInEditMode()) { from = 0; length = 135; } canvas.drawArc(circleBounds, from, length, false, barPaint); } else { float oldProgress = mProgress; if (mProgress != mTargetProgress) { //We smoothly increase the progress bar mustInvalidate = true; float deltaTime = (float) (SystemClock.uptimeMillis() - lastTimeAnimated) / 1000; float deltaNormalized = deltaTime * spinSpeed; mProgress = Math.min(mProgress + deltaNormalized, mTargetProgress); lastTimeAnimated = SystemClock.uptimeMillis(); } if (oldProgress != mProgress) { runCallback(); } float offset = 0.0f; float progress = mProgress; if (!linearProgress) { float factor = 2.0f; offset = (float) (1.0f - Math.pow(1.0f - mProgress / 360.0f, 2.0f * factor)) * 360.0f; progress = (float) (1.0f - Math.pow(1.0f - mProgress / 360.0f, factor)) * 360.0f; } if (isInEditMode()) { progress = 360; } canvas.drawArc(circleBounds, offset - 90, progress, false, barPaint); } if (mustInvalidate) { invalidate(); } }
From source file:crackerjack.education.Indijisites.StartUp.java
@Override public boolean onMarkerClick(final Marker marker) { // This method makes the marker bounce when you click on it. It's not really needed, but it's a neat feature. // Will expand this if offered more time. if (marker.equals(mBrisbane)) { final Handler handler = new Handler(); final long start = SystemClock.uptimeMillis(); Projection proj = mMap.getProjection(); Point startPoint = proj.toScreenLocation(BRISBANE); startPoint.offset(0, -100);// w w w .j a v a 2s. c om final LatLng startLatLng = proj.fromScreenLocation(startPoint); final long duration = 1500; final Interpolator interpolator = new BounceInterpolator(); handler.post(new Runnable() { @Override public void run() { long elapsed = SystemClock.uptimeMillis() - start; float t = interpolator.getInterpolation((float) elapsed / duration); double lng = t * BRISBANE.longitude + (1 - t) * startLatLng.longitude; // This allows the marker to pinpoint if offscreen (I think =/) double lat = t * BRISBANE.latitude + (1 - t) * startLatLng.latitude; marker.setPosition(new LatLng(lat, lng)); if (t < 1.0) { // Post again 16ms later handler.postDelayed(this, 16); } } }); } //False is returned to indicate we have not consumed the event and that we wish //for the default behaviour to occur (move to marker location). return false; }
From source file:br.com.devmix.baseapp.listener.OnSwipeableRecyclerViewTouchListener.java
private void performDismiss(final View dismissView, final int dismissPosition) { // Animate the dismissed list item to zero-height and fire the dismiss callback when // all dismissed list item animations have completed. This triggers layout on each animation // frame; in the future we may want to do something smarter and more performant. final ViewGroup.LayoutParams lp = dismissView.getLayoutParams(); final int originalLayoutParamsHeight = lp.height; final int originalHeight = dismissView.getHeight(); ValueAnimatorCompat animatorCompat = AnimatorCompatHelper.emptyValueAnimator(); animatorCompat.setDuration(mAnimationTime); animatorCompat.addListener(new AnimatorListenerCompat() { @Override//from w w w. j a v a 2 s .co m public void onAnimationStart(ValueAnimatorCompat animation) { } @Override public void onAnimationEnd(ValueAnimatorCompat animation) { --mDismissAnimationRefCount; if (mDismissAnimationRefCount == 0) { // No active animations, process all pending dismisses. // Sort by descending position Collections.sort(mPendingDismisses); int[] dismissPositions = new int[mPendingDismisses.size()]; for (int i = mPendingDismisses.size() - 1; i >= 0; i--) { dismissPositions[i] = mPendingDismisses.get(i).position; } if (mFinalDelta > 0) { mSwipeListener.onDismissedBySwipeRight(mRecyclerView, dismissPositions); } else { mSwipeListener.onDismissedBySwipeLeft(mRecyclerView, dismissPositions); } // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss // animation with a stale position mDownPosition = ListView.INVALID_POSITION; ViewGroup.LayoutParams lp; for (PendingDismissData pendingDismiss : mPendingDismisses) { // Reset view presentation ViewCompat.setAlpha(pendingDismiss.view, mAlpha); ViewCompat.setTranslationX(pendingDismiss.view, 0); lp = pendingDismiss.view.getLayoutParams(); lp.height = originalLayoutParamsHeight; pendingDismiss.view.setLayoutParams(lp); } // Send a cancel event long time = SystemClock.uptimeMillis(); MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0); mRecyclerView.dispatchTouchEvent(cancelEvent); mPendingDismisses.clear(); mAnimatingPosition = ListView.INVALID_POSITION; } } @Override public void onAnimationCancel(ValueAnimatorCompat animation) { } @Override public void onAnimationRepeat(ValueAnimatorCompat animation) { } }); animatorCompat.addUpdateListener(new AnimatorUpdateListenerCompat() { @Override public void onAnimationUpdate(ValueAnimatorCompat animation) { float fraction = animation.getAnimatedFraction(); lp.height = (int) (originalHeight * (1 - fraction)); dismissView.setLayoutParams(lp); } }); mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView)); animatorCompat.start(); }
From source file:org.addhen.smssync.presentation.view.ui.listener.OnSwipeableRecyclerViewTouchListener.java
private void performDismiss(final View dismissView, final int dismissPosition) { // Animate the dismissed list item to zero-height and fire the dismiss callback when // all dismissed list item animations have completed. This triggers layout on each animation // frame; in the future we may want to do something smarter and more performant. final ViewGroup.LayoutParams lp = dismissView.getLayoutParams(); final int originalLayoutParamsHeight = lp.height; final int originalHeight = dismissView.getHeight(); ValueAnimatorCompat animatorCompat = AnimatorCompatHelper.emptyValueAnimator(); animatorCompat.setDuration(mAnimationTime); animatorCompat.addListener(new AnimatorListenerCompat() { @Override//from www.java 2 s . c om public void onAnimationStart(ValueAnimatorCompat animation) { } @Override public void onAnimationEnd(ValueAnimatorCompat animation) { --mDismissAnimationRefCount; if (mDismissAnimationRefCount == 0) { // No active animations, process all pending dismisses. // Sort by descending position Collections.sort(mPendingDismisses); int[] dismissPositions = new int[mPendingDismisses.size()]; for (int i = mPendingDismisses.size() - 1; i >= 0; i--) { dismissPositions[i] = mPendingDismisses.get(i).position; } if (mFinalDelta > 0) { mSwipeListener.onDismissedBySwipeRight(mRecyclerView, dismissPositions); } else { mSwipeListener.onDismissedBySwipeLeft(mRecyclerView, dismissPositions); } // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss // animation with a stale position mDownPosition = ListView.INVALID_POSITION; ViewGroup.LayoutParams lp; for (PendingDismissData pendingDismiss : mPendingDismisses) { // Reset view presentation ViewCompat.setAlpha(pendingDismiss.view, mAlpha); ViewCompat.setTranslationX(pendingDismiss.view, 0); lp = pendingDismiss.view.getLayoutParams(); lp.height = originalLayoutParamsHeight; pendingDismiss.view.setLayoutParams(lp); } // Send a cancel event long time = SystemClock.uptimeMillis(); MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0); mRecyclerView.dispatchTouchEvent(cancelEvent); mPendingDismisses.clear(); mAnimatingPosition = ListView.INVALID_POSITION; } } @Override public void onAnimationCancel(ValueAnimatorCompat animation) { } @Override public void onAnimationRepeat(ValueAnimatorCompat animation) { } }); animatorCompat.addUpdateListener(animation -> { float fraction = animation.getAnimatedFraction(); lp.height = (int) (originalHeight * (1 - fraction)); dismissView.setLayoutParams(lp); }); mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView)); animatorCompat.start(); }
From source file:se.kth.csc.stayawhile.swipe.QueueTouchListener.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void performDismiss(final View dismissView, final int dismissPosition) { // Animate the dismissed list item to zero-height and fire the dismiss callback when // all dismissed list item animations have completed. This triggers layout on each animation // frame; in the future we may want to do something smarter and more performant. final ViewGroup.LayoutParams lp = dismissView.getLayoutParams(); final int originalLayoutParamsHeight = lp.height; final int originalHeight = dismissView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime); animator.addListener(new AnimatorListenerAdapter() { @Override//from w w w. j ava 2 s. c o m public void onAnimationEnd(Animator animation) { --mDismissAnimationRefCount; if (mDismissAnimationRefCount == 0) { // No active animations, process all pending dismisses. // Sort by descending position Collections.sort(mPendingDismisses); int[] dismissPositions = new int[mPendingDismisses.size()]; for (int i = mPendingDismisses.size() - 1; i >= 0; i--) { dismissPositions[i] = mPendingDismisses.get(i).position; } mQueueSwipeListener.onDismiss(mRecyclerView, dismissPositions); // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss // animation with a stale position mDownPosition = ListView.INVALID_POSITION; ViewGroup.LayoutParams lp; for (PendingActionData pendingDismiss : mPendingDismisses) { // Reset view presentation pendingDismiss.view.setAlpha(mAlpha); pendingDismiss.view.setTranslationX(0); lp = pendingDismiss.view.getLayoutParams(); lp.height = originalLayoutParamsHeight; pendingDismiss.view.setLayoutParams(lp); } // Send a cancel event long time = SystemClock.uptimeMillis(); MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0); mRecyclerView.dispatchTouchEvent(cancelEvent); mPendingDismisses.clear(); mAnimatingPosition = ListView.INVALID_POSITION; } } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); dismissView.setLayoutParams(lp); } }); mPendingDismisses.add(new PendingActionData(dismissPosition, dismissView)); animator.start(); }
From source file:com.googlecode.eyesfree.testing.BaseAccessibilityInstrumentationTestCase.java
/** * Ensures that {@link #NO_EVENTS_DURATION} milliseconds have passed since * the last accessibility event.//from w w w. j a v a2 s.c om */ protected void waitForAccessibilityIdleSync() { boolean hasIdleSync = false; final long startTime = SystemClock.uptimeMillis(); synchronized (mAccessibilityEventLock) { try { // Reset the event time to now so that we catch queued events. mLastEventTime = SystemClock.uptimeMillis(); while (true) { final long eventTimeElapsed = (SystemClock.uptimeMillis() - mLastEventTime); final long eventTimeLeft = (NO_EVENTS_DURATION - eventTimeElapsed); if (eventTimeLeft <= 0) { hasIdleSync = true; break; } final long timeElapsed = (SystemClock.uptimeMillis() - startTime); final long timeLeft = (NO_EVENTS_TIMEOUT - timeElapsed); if (timeLeft <= 0) { break; } final long timeToWait = Math.min(timeLeft, eventTimeLeft); mAccessibilityEventLock.wait(timeToWait); } } catch (InterruptedException e) { // Do nothing. } assertTrue("Accessibility events idle for " + NO_EVENTS_DURATION + " ms", hasIdleSync); } LogUtils.log(this, Log.VERBOSE, "Took %d ms to sync accessibility idle state", (SystemClock.uptimeMillis() - startTime)); }
From source file:org.mozilla.gecko.gfx.GeckoSoftwareLayerClient.java
public void endDrawing(int x, int y, int width, int height) { synchronized (getLayerController()) { try {/*ww w.j a v a2 s . c o m*/ updateViewport(!mUpdateViewportOnEndDraw); mUpdateViewportOnEndDraw = false; if (mTileLayer instanceof MultiTileLayer) { Rect rect = new Rect(x, y, x + width, y + height); ((MultiTileLayer) mTileLayer).invalidate(rect); } } finally { endTransaction(mTileLayer); } } Log.i(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - endDrawing"); /* Used by robocop for testing purposes */ if (mDrawListener != null) { mDrawListener.drawFinished(x, y, width, height); } }
From source file:org.tensorflow.demo.Camera2BasicFragment.java
private void classifyImage(Image image) { try {/*from ww w. j a v a2s . c o m*/ Log.d("predict_class", "1"); if (image == null) { return; } if (computing) { image.close(); return; } Log.d("predict_class", "2"); computing = true; Trace.beginSection("imageAvailable"); Log.d("predict_class", image.getHeight() + ""); Log.d("predict_class", image.getWidth() + ""); final Image.Plane[] planes = image.getPlanes(); fillBytes(planes, yuvBytes); final int yRowStride = planes[0].getRowStride(); final int uvRowStride = planes[1].getRowStride(); final int uvPixelStride = planes[1].getPixelStride(); ImageUtils.convertYUV420ToARGB8888(yuvBytes[0], yuvBytes[1], yuvBytes[2], rgbBytes, previewWidth, previewHeight, yRowStride, uvRowStride, uvPixelStride, false); image.close(); } catch (final Exception e) { Log.d("predict_class", "error: " + e.getMessage()); if (image != null) { image.close(); } LOGGER.e(e, "Exception!"); Trace.endSection(); return; } rgbFrameBitmap.setPixels(rgbBytes, 0, previewWidth, 0, 0, previewWidth, previewHeight); final Canvas canvas = new Canvas(croppedBitmap); canvas.drawBitmap(rgbFrameBitmap, frameToCropTransform, null); // For examining the actual TF input. if (SAVE_PREVIEW_BITMAP) { ImageUtils.saveBitmap(croppedBitmap); } runInBackground(new Runnable() { @Override public void run() { final long startTime = SystemClock.uptimeMillis(); final List<Classifier.Recognition> results = classifier.recognizeImage(croppedBitmap); lastProcessingTimeMs = SystemClock.uptimeMillis() - startTime; String toastString = ""; Log.d("predict_class", results.toString()); for (Classifier.Recognition cr : results) { toastString = toastString + " " + cr.getTitle() + ": " + cr.getConfidence() + ";"; } Log.d("predict_class", toastString); //showToast(toastString); Intent intent = new Intent(getActivity(), ClassifierResultActivity.class); Gson gs = new Gson(); String resultString = gs.toJson(results); intent.putExtra("result", resultString); startActivity(intent); cropCopyBitmap = Bitmap.createBitmap(croppedBitmap); computing = false; } }); Trace.endSection(); }
From source file:org.akop.crosswords.fragment.CrosswordFragment.java
private void resetPuzzle() { AlertDialog dialog = new AlertDialog.Builder(getActivity()).setMessage(R.string.clear_puzzle_contents) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override/*w w w . ja v a 2 s.com*/ public void onClick(DialogInterface dialog, int which) { mPlayStartTime = SystemClock.uptimeMillis(); mLastState = null; mCrosswordView.reset(); } }).setNegativeButton(R.string.no, null).create(); dialog.show(); }
From source file:com.googlecode.talkingrssreader.talkingrss.ReaderHttp.java
private void doApiPost(String url, ArrayList<NameValuePair> params) throws ReaderException { long startTime = SystemClock.uptimeMillis(); boolean do_retry = true; if (apiToken == null) { fetchApiToken();/* w ww . jav a 2s .c o m*/ do_retry = false; } try { checkApiOk(doPost(url, params, true)); } catch (HttpException e) { if (do_retry && (e.code == HttpStatus.SC_BAD_REQUEST || e.code == HttpStatus.SC_UNAUTHORIZED)) { // Get a fresh token fetchApiToken(); checkApiOk(doPost(url, params, true)); } else { throw e; } } long now = SystemClock.uptimeMillis(); if (Config.LOGD) Log.d(TAG, String.format("API request took %dms", now - startTime)); }