List of usage examples for android.os SystemClock uptimeMillis
@CriticalNative native public static long uptimeMillis();
From source file:org.strongswan.android.logic.VpnStateService.java
/** * Sets the retry timer/*from ww w . jav a 2 s . co m*/ */ private void setRetryTimer(ErrorState error) { mRetryTimeout = mRetryIn = mTimeoutProvider.getTimeout(error); if (mRetryTimeout <= 0) { return; } mHandler.sendMessageAtTime(mHandler.obtainMessage(RETRY_MSG), SystemClock.uptimeMillis() + RETRY_INTERVAL); }
From source file:com.quentindommerc.superlistview.SwipeDismissListViewTouchListener.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 originalHeight = dismissView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime); animator.addListener(new AnimatorListenerAdapter() { @Override/* w w w . jav a2s. 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; } mCallbacks.onDismiss(mListView, 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 if (AnimatorProxy.NEEDS_PROXY) { AnimatorProxy.wrap(pendingDismiss.view).setAlpha(1f); AnimatorProxy.wrap(pendingDismiss.view).setTranslationX(0); } else { pendingDismiss.view.setAlpha(1f); pendingDismiss.view.setTranslationX(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); mListView.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.android.strictmodetest.StrictModeActivity.java
private long settingsWrite(int mode) { Cursor c = null;/* www.j a va 2 s .c o m*/ long startTime = SystemClock.uptimeMillis(); // The database will take care of replacing duplicates. try { ContentValues values = new ContentValues(); values.put("name", "dummy_for_testing"); values.put("value", "" + startTime); Uri uri = cr.insert(SYSTEM_SETTINGS_URI, values); Log.v(TAG, "inserted uri: " + uri); } catch (SQLException e) { Log.w(TAG, "sqliteexception during write: " + e); return -1; } long duration = SystemClock.uptimeMillis() - startTime; return duration; }
From source file:com.android.tv.settings.accessories.AddAccessoryActivity.java
private void sendKeyEvent(int keyCode, boolean down) { InputManager iMgr = (InputManager) getSystemService(INPUT_SERVICE); if (iMgr != null) { long time = SystemClock.uptimeMillis(); KeyEvent evt = new KeyEvent(time, time, down ? KeyEvent.ACTION_DOWN : KeyEvent.ACTION_UP, keyCode, 0); iMgr.injectInputEvent(evt, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); }/*w w w. j a va 2 s . c om*/ }
From source file:org.mariotaku.twidere.fragment.BaseStatusesListFragment.java
@Override public void onStart() { super.onStart(); mTickerStopped = false;//ww w. java2 s. c o m 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(); final IntentFilter filter = new IntentFilter(); filter.addAction(BROADCAST_MULTI_SELECT_STATE_CHANGED); filter.addAction(BROADCAST_MULTI_SELECT_ITEM_CHANGED); registerReceiver(mStateReceiver, filter); }
From source file:android.support.design.widget.CoordinatorLayout.java
/** * Reset all Behavior-related tracking records either to clean up or in preparation * for a new event stream. This should be called when attached or detached from a window, * in response to an UP or CANCEL event, when intercept is request-disallowed * and similar cases where an event stream in progress will be aborted. *//* ww w .j ava 2 s. c o m*/ private void resetTouchBehaviors() { if (mBehaviorTouchView != null) { final Behavior b = ((LayoutParams) mBehaviorTouchView.getLayoutParams()).getBehavior(); if (b != null) { final long now = SystemClock.uptimeMillis(); final MotionEvent cancelEvent = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); b.onTouchEvent(this, mBehaviorTouchView, cancelEvent); cancelEvent.recycle(); } mBehaviorTouchView = null; } final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); lp.resetTouchBehaviorTracking(); } mDisallowInterceptReset = false; }
From source file:com.googlecode.eyesfree.testing.BaseAccessibilityInstrumentationTestCase.java
protected AccessibilityEvent stopRecordingEventsAfter(EventFilter filter) { final long startTime = SystemClock.uptimeMillis(); synchronized (mEventCache) { try {/*from www . j a v a 2s. c o m*/ int currentIndex = 0; while (true) { // Check all events starting from the current index. while (currentIndex < mEventCache.size()) { final AccessibilityEvent event = mEventCache.get(currentIndex); if (filter.accept(event)) { mRecordingEvents = false; return event; } currentIndex++; } final long elapsed = (SystemClock.uptimeMillis() - startTime); final long timeLeft = (OBTAIN_EVENT_TIMEOUT - elapsed); if (timeLeft <= 0) { break; } mEventCache.wait(timeLeft); } mRecordingEvents = false; } catch (InterruptedException e) { // Do nothing. } } return null; }
From source file:silent.kuasapmaterial.libs.ProgressWheel.java
/** * Puts the view on spin mode */ public void spin() { lastTimeAnimated = SystemClock.uptimeMillis(); isSpinning = true; invalidate(); }
From source file:net.tsz.afinal.http.HttpHandler.java
private void handleResponse(HttpResponse response) { StatusLine status = response.getStatusLine(); ZLogger.d(String.format("handleResponse:%d/%s", status.getStatusCode(), status.getReasonPhrase())); if (status.getStatusCode() >= 300) { String errorMsg = "response status error code: " + status.getStatusCode(); if (status.getStatusCode() == 416 && isResume) { errorMsg += " \n maybe you have download complete."; }// ww w . j a va2 s. c om publishProgress(UPDATE_FAILURE, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), errorMsg); } else { try { HttpEntity entity = response.getEntity(); Object responseBody = null; if (entity != null) { time = SystemClock.uptimeMillis(); if (targetUrl != null) { responseBody = mFileEntityHandler.handleEntity(entity, this, targetUrl, isResume); } else { responseBody = mStrEntityHandler.handleEntity(entity, this, charset); } } publishProgress(UPDATE_SUCCESS, responseBody); } catch (IOException e) { publishProgress(UPDATE_FAILURE, e, e.getMessage()); } } }
From source file:com.googlecode.eyesfree.brailleback.BrailleIME.java
private boolean sendAndroidKeyInternal(int keyCode) { LogUtils.log(this, Log.VERBOSE, "sendAndroidKey: %d", keyCode); InputConnection ic = getCurrentInputConnection(); if (ic == null) { return false; }/* ww w . j a v a 2 s . com*/ long eventTime = SystemClock.uptimeMillis(); if (!ic.sendKeyEvent(new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, keyCode, 0 /*repeat*/))) { return false; } return ic.sendKeyEvent(new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_UP, keyCode, 0 /*repeat*/)); }