List of usage examples for android.os SystemClock uptimeMillis
@CriticalNative native public static long uptimeMillis();
From source file:org.akop.crosswords.Storage.java
public void write(long puzzleId, Crossword.State state) { long started = SystemClock.uptimeMillis(); ContentValues cv = new ContentValues(); cv.put(PuzzleState.PUZZLE_ID, puzzleId); cv.put(PuzzleState.CLASS, state.getClass().getName()); cv.put(PuzzleState.OBJECT, mGson.toJson(state)); cv.put(PuzzleState.OBJECT_VERSION, 1); cv.put(PuzzleState.PERCENT_SOLVED, state.getPercentSolved()); cv.put(PuzzleState.PERCENT_CHEATED, state.getPercentCheated()); cv.put(PuzzleState.PERCENT_WRONG, state.getPercentWrong()); cv.put(PuzzleState.PLAY_TIME_MILLIS, state.getPlayTimeMillis()); long lastPlayed = 0; if (state.getLastPlayed() != null) { lastPlayed = state.getLastPlayed().getMillis(); }/*from w ww . j a va2 s . c o m*/ cv.put(PuzzleState.LAST_PLAYED, lastPlayed); cv.put(PuzzleState.LAST_UPDATED, System.currentTimeMillis()); StorageHelper helper = getHelper(); SQLiteDatabase db = helper.getWritableDatabase(); try { // Delete any existing rows db.delete(PuzzleState.TABLE, PuzzleState.PUZZLE_ID + "=" + puzzleId, null); // Insert the new one db.insert(PuzzleState.TABLE, null, cv); } finally { db.close(); } Crosswords.logv("Wrote state for %d (%dms)", puzzleId, SystemClock.uptimeMillis() - started); // Add a copy to the cache mStateCache.put((int) puzzleId, new Crossword.State(state)); // Broadcast the change Intent intent = new Intent(ACTION_PUZZLE_STATE_CHANGE); intent.putExtra(INTENT_PUZZLE_ID, puzzleId); Context context = Crosswords.getInstance(); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); }
From source file:io.github.sin3hz.fastjumper.FastJumperDecoration.java
private void cancelTouch() { final long now = SystemClock.uptimeMillis(); final MotionEvent cancelEvent = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); mRecyclerView.onTouchEvent(cancelEvent); cancelEvent.recycle();/*from ww w. jav a2 s .c o m*/ mRecyclerView.requestDisallowInterceptTouchEvent(false); }
From source file:com.samebits.beacon.locator.ui.view.RadarScanView.java
/** * Turn on the sweep animation starting with the next draw *//*w w w . jav a 2 s. c o m*/ public void startSweep() { mInfoView.setText(R.string.text_scanning); mSweepTime = SystemClock.uptimeMillis(); mSweepBefore = true; }
From source file:fashiome.android.fragments.MapListFragment.java
private void dropPinEffect(final Marker marker) { // Handler allows us to repeat a code block after a specified delay final android.os.Handler handler = new android.os.Handler(); final long start = SystemClock.uptimeMillis(); final long duration = 1500; // Use the bounce interpolator final android.view.animation.Interpolator interpolator = new BounceInterpolator(); // Animate marker with a bounce updating its position every 15ms handler.post(new Runnable() { @Override/* w w w . j ava2s. co m*/ public void run() { long elapsed = SystemClock.uptimeMillis() - start; // Calculate t for bounce based on elapsed time float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0); // Set the anchor marker.setAnchor(0.5f, 1.0f + 14 * t); if (t > 0.0) { // Post this event again 15ms from now. handler.postDelayed(this, 15); } else { // done elapsing, show window marker.showInfoWindow(); } } }); }
From source file:cn.meiqu.baseproject.view.superrecyclerview.swipe.SwipeDismissRecyclerViewTouchListener.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 originalHeight = dismissView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime); animator.addListener(new AnimatorListenerAdapter() { @Override/*from w ww. j a v a 2 s . com*/ 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; } mCallbacks.onDismiss(mRecyclerView, dismissPositions); // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss // animation with a stale position mDownPosition = INVALID_POSITION; ViewGroup.LayoutParams lp; for (PendingDismissData pendingDismiss : mPendingDismisses) { // Reset view presentation setAlpha(pendingDismiss.view, 1f); setTranslationX(pendingDismiss.view, 0); lp = pendingDismiss.view.getLayoutParams(); lp.height = originalHeight; 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(); } } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); dismissView.setLayoutParams(lp); } }); mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView)); animator.start(); }
From source file:com.nxt.zyl.data.volley.toolbox.BasicNetwork.java
private byte[] handleEntity(ResponseDelivery delivery, DownloadRequest request, HttpEntity entity) throws IOException, ServerError { long time = SystemClock.uptimeMillis(); final String target = request.getTarget(); if (TextUtils.isEmpty(target) || target.trim().length() == 0) return null; File targetFile = new File(target); if (!targetFile.exists()) { targetFile.createNewFile();/* www . j a v a 2 s. com*/ } if (request.isCanceled()) { return target.getBytes(); } FileOutputStream os = null; InputStream input = null; try { long current = 0; if (request.isResume()) { current = targetFile.length(); os = new FileOutputStream(target, true); } else { os = new FileOutputStream(target); } if (request.isCanceled()) { return target.getBytes(); } input = entity.getContent(); long count = entity.getContentLength() + current; if (current >= count || request.isCanceled()) { return target.getBytes(); } int readLen = 0; byte[] buffer = new byte[1024]; Response.LoadingListener listener = request.getLoadingListener(); while (!request.isCanceled() && !(current >= count) && ((readLen = input.read(buffer, 0, 1024)) > 0)) {// os.write(buffer, 0, readLen); current += readLen; if (listener != null) { long thisTime = SystemClock.uptimeMillis(); if (thisTime - time >= request.getRate()) { time = thisTime; delivery.postLoading(request, count, current); } } } if (listener != null) { delivery.postLoading(request, count, current); } if (request.isCanceled() && current < count) { // throw new IOException("user stop download thread"); } } finally { if (input != null) { input.close(); } try { // Close the InputStream and release the resources by "consuming the content". entity.consumeContent(); } catch (IOException e) { // This can happen if there was an exception above that left the entity in // an invalid state. VolleyLog.v("Error occured when calling consumingContent"); } if (os != null) { os.close(); } } return target.getBytes(); }
From source file:de.quist.app.maps.example.MarkerDemoActivity.java
@Override public boolean onMarkerClick(final Marker marker) { if (marker.equals(mPerth)) { // This causes the marker at Perth to bounce into position when it is clicked. final Handler handler = new Handler(); final long start = SystemClock.uptimeMillis(); final long duration = 1500; final Interpolator interpolator = new BounceInterpolator(); handler.post(new Runnable() { @Override//from w w w. j a va 2 s. com public void run() { long elapsed = SystemClock.uptimeMillis() - start; float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0); marker.setAnchor(0.5f, 1.0f + 2 * t); if (t > 0.0) { // Post again 16ms later. handler.postDelayed(this, 16); } } }); } else if (marker.equals(mAdelaide)) { // This causes the marker at Adelaide to change color and alpha. marker.setIcon( BuildConfig.MAP_BINDING.bitmapDescriptorFactory().defaultMarker(mRandom.nextFloat() * 360)); marker.setAlpha(mRandom.nextFloat()); } mLastSelectedMarker = marker; // We return false to indicate that we have not consumed the event and that we wish // for the default behavior to occur (which is for the camera to move such that the // marker is centered and for the marker's info window to open, if it has one). return false; }
From source file:com.android.screenspeak.eventprocessor.AccessibilityEventProcessor.java
/** * Manages touch exploration state./* w ww . j a va2 s. c o m*/ * * @param event The current event. */ private void maintainExplorationState(AccessibilityEvent event) { final int eventType = event.getEventType(); if (eventType == AccessibilityEventCompat.TYPE_TOUCH_EXPLORATION_GESTURE_START) { mIsUserTouchExploring = true; } else if (eventType == AccessibilityEventCompat.TYPE_TOUCH_EXPLORATION_GESTURE_END) { mIsUserTouchExploring = false; } else if (eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { mLastWindowStateChanged = SystemClock.uptimeMillis(); } }
From source file:org.mariotaku.twidere.activity.DirectMessagesActivity.java
@Override public void onStart() { super.onStart(); mTickerStopped = false;//from w w w. j a v a 2 s . c om mHandler = new Handler(); mTicker = new Runnable() { @Override public void run() { if (mTickerStopped) return; if (mListView != null && !mBusy) { mAdapter.notifyDataSetChanged(); } final long now = SystemClock.uptimeMillis(); final long next = now + TICKER_DURATION - now % TICKER_DURATION; mHandler.postAtTime(mTicker, next); } }; mTicker.run(); setSupportProgressBarIndeterminateVisibility( mService.isReceivedDirectMessagesRefreshing() || mService.isSentDirectMessagesRefreshing()); final IntentFilter filter = new IntentFilter(BROADCAST_REFRESHSTATE_CHANGED); filter.addAction(BROADCAST_RECEIVED_DIRECT_MESSAGES_DATABASE_UPDATED); filter.addAction(BROADCAST_SENT_DIRECT_MESSAGES_DATABASE_UPDATED); registerReceiver(mStatusReceiver, filter); }
From source file:com.brandon.mailbox.RecyclerSwipeListener.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// w w w. j a v a 2s. 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; } if (mFinalDelta < 0) { mSwipeListener.onDismissedBySwipeLeft(mRecyclerView, dismissPositions); } else { mSwipeListener.onDismissedBySwipeRight(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 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 PendingDismissData(dismissPosition, dismissView)); animator.start(); }