List of usage examples for android.os SystemClock uptimeMillis
@CriticalNative native public static long uptimeMillis();
From source file:com.android.yijiang.kzx.widget.betterpickers.calendardatepicker.CalendarDatePickerDialog.java
/** * Try to vibrate. To prevent this becoming a single continuous vibration, nothing will happen if we have vibrated * very recently.// w w w .j a v a2 s .c om */ @Override public void tryVibrate() { if (mVibrator != null) { long now = SystemClock.uptimeMillis(); // We want to try to vibrate each individual tick discretely. if (now - mLastVibrate >= 125) { mVibrator.vibrate(5); mLastVibrate = now; } } }
From source file:com.googlecode.eyesfree.testing.BaseAccessibilityInstrumentationTestCase.java
/** * Attempts to obtain a null instance of {@link TestAccessibilityService}. * <p>// w w w . j a v a 2 s.c om * May block for up to {@link #OBTAIN_SERVICE_TIMEOUT} seconds, and may * return {@code null} if the service is not running. */ private boolean obtainNullTargetServiceSync() { boolean success = false; final long startTime = SystemClock.uptimeMillis(); try { while (true) { final AccessibilityService service = getService(); if (service == null) { break; } final long timeElapsed = (SystemClock.uptimeMillis() - startTime); final long timeLeft = (OBTAIN_SERVICE_TIMEOUT - timeElapsed); if (timeLeft <= 0) { break; } final long timeToWait = Math.min(OBTAIN_SERVICE_RETRY, timeLeft); Thread.sleep(timeToWait); } } catch (InterruptedException e) { // Do nothing. } LogUtils.log(this, Log.VERBOSE, "Took %d ms to obtain null service", (SystemClock.uptimeMillis() - startTime)); return success; }
From source file:rs.pedjaapps.KernelTuner.compatibility.helpers.IOHelper.java
public static String deepSleep() { String deepSleep;//from w w w .j a va2s . c om int time = (int) (SystemClock.elapsedRealtime() - SystemClock.uptimeMillis()); String s = String.valueOf((int) ((time / 1000) % 60)); String m = String.valueOf((int) ((time / (1000 * 60)) % 60)); String h = String.valueOf((int) ((time / (1000 * 3600)) % 24)); String d = String.valueOf((int) (time / (1000 * 60 * 60 * 24))); StringBuilder builder = new StringBuilder(); if (!d.equals("0")) { builder.append(d + "d:"); } if (!h.equals("0")) { builder.append(h + "h:"); } if (!m.equals("0")) { builder.append(m + "m:"); } builder.append(s + "s"); deepSleep = builder.toString(); return deepSleep; }
From source file:com.android.gallery3d.app.PhotoPage.java
@Override public void onCreate(Bundle data, Bundle restoreState) { super.onCreate(data, restoreState); mActionBar = mActivity.getGalleryActionBar(); mSelectionManager = new SelectionManager(mActivity, false); mMenuExecutor = new MenuExecutor(mActivity, mSelectionManager); mPhotoView = new PhotoView(mActivity); mPhotoView.setListener(this); mRootPane.addComponent(mPhotoView);// w ww . j a v a 2s .co m mApplication = (GalleryApp) ((Activity) mActivity).getApplication(); mOrientationManager = mActivity.getOrientationManager(); mActivity.getGLRoot().setOrientationSource(mOrientationManager); mHandler = new SynchronizedHandler(mActivity.getGLRoot()) { @Override public void handleMessage(Message message) { switch (message.what) { case MSG_HIDE_BARS: { /// M: [BUG.MODIFY] @{ /* hideBars(); */ if (mIsActive) { hideBars(); } else { Log.i(TAG, "<mHandler.MSG_HIDE_BARS> mIsActive = " + mIsActive + ", not hideBars"); } /// @} break; } case MSG_REFRESH_BOTTOM_CONTROLS: { if (mCurrentPhoto == message.obj && mBottomControls != null) { mIsPanorama = message.arg1 == 1; mIsPanorama360 = message.arg2 == 1; mBottomControls.refresh(); fresh(mBottomControls.getContainerVisibility()); } break; } case MSG_ON_FULL_SCREEN_CHANGED: { if (mAppBridge != null) { mAppBridge.onFullScreenChanged(message.arg1 == 1); } break; } case MSG_UPDATE_ACTION_BAR: { updateBars(); break; } case MSG_WANT_BARS: { wantBars(); break; } case MSG_UNFREEZE_GLROOT: { mActivity.getGLRoot().unfreeze(); break; } case MSG_UPDATE_DEFERRED: { long nextUpdate = mDeferUpdateUntil - SystemClock.uptimeMillis(); if (nextUpdate <= 0) { mDeferredUpdateWaiting = false; updateUIForCurrentPhoto(); } else { mHandler.sendEmptyMessageDelayed(MSG_UPDATE_DEFERRED, nextUpdate); } break; } case MSG_ON_CAMERA_CENTER: { mSkipUpdateCurrentPhoto = false; boolean stayedOnCamera = false; if (!mPhotoView.getFilmMode()) { stayedOnCamera = true; } else if (SystemClock.uptimeMillis() < mCameraSwitchCutoff && mMediaSet.getMediaItemCount() > 1) { mPhotoView.switchToImage(1); } else { if (mAppBridge != null) mPhotoView.setFilmMode(false); stayedOnCamera = true; } if (stayedOnCamera) { if (mAppBridge == null && mMediaSet.getTotalMediaItemCount() > 1) { launchCamera(); /// M: [FEATURE.ADD] @{ mPhotoView.stopUpdateEngineData(); /// @} /* We got here by swiping from photo 1 to the placeholder, so make it be the thing that is in focus when the user presses back from the camera app */ mPhotoView.switchToImage(1); } else { updateBars(); /// M: [BUG.MODIFY] getMediaItem(0) may be null, fix JE @{ /*updateCurrentPhoto(mModel.getMediaItem(0));*/ MediaItem photo = mModel.getMediaItem(0); if (photo != null) { updateCurrentPhoto(photo); } /// @} } } break; } case MSG_ON_PICTURE_CENTER: { if (!mPhotoView.getFilmMode() && mCurrentPhoto != null && (mCurrentPhoto.getSupportedOperations() & MediaObject.SUPPORT_ACTION) != 0) { /// M: [BUG.MODIFY] @{ /*mPhotoView.setFilmMode(true);*/ showEmptyAlbumToast(Toast.LENGTH_SHORT); /// @} } break; } case MSG_REFRESH_IMAGE: { final MediaItem photo = mCurrentPhoto; mCurrentPhoto = null; updateCurrentPhoto(photo); break; } case MSG_UPDATE_PHOTO_UI: { updateUIForCurrentPhoto(); break; } case MSG_UPDATE_SHARE_URI: { /// M: [BUG.ADD] @{ // never update share uri when PhotoPage is not active if (!mIsActive) { break; } /// @} /// M: [BUG.MARK] @{ // No matter what message.obj is, we update share intent for current photo /* if (mCurrentPhoto == message.obj) {*/ /// @} boolean isPanorama360 = message.arg1 != 0; Uri contentUri = mCurrentPhoto.getContentUri(); Intent panoramaIntent = null; if (isPanorama360) { panoramaIntent = createSharePanoramaIntent(contentUri); } Intent shareIntent = createShareIntent(mCurrentPhoto); mActionBar.setShareIntents(panoramaIntent, shareIntent, PhotoPage.this); setNfcBeamPushUri(contentUri); /// M: [BUG.MARK] @{ // } /// @} break; } case MSG_UPDATE_PANORAMA_UI: { if (mCurrentPhoto == message.obj) { boolean isPanorama360 = message.arg1 != 0; updatePanoramaUI(isPanorama360); } break; } default: throw new AssertionError(message.what); } } }; mSetPathString = data.getString(KEY_MEDIA_SET_PATH); /// M: [FEATURE.ADD] [Camera independent from Gallery] @{ mLaunchFromCamera = data.getBoolean(KEY_LAUNCH_FROM_CAMERA, false); /// @} /// M: [BUG.MODIFY] @{ // if there is mSetPathString, view is not read only, enable edit /*mReadOnlyView = data.getBoolean(KEY_READONLY);*/ mReadOnlyView = data.getBoolean(KEY_READONLY) && (mSetPathString == null || mSetPathString.equals("")); Log.i(TAG, "<onCreate> mSetPathString = " + mSetPathString + ", mReadOnlyView = " + mReadOnlyView); /// @} mOriginalSetPathString = mSetPathString; setupNfcBeamPush(); String itemPathString = data.getString(KEY_MEDIA_ITEM_PATH); Path itemPath = itemPathString != null ? Path.fromString(data.getString(KEY_MEDIA_ITEM_PATH)) : null; mTreatBackAsUp = data.getBoolean(KEY_TREAT_BACK_AS_UP, false); mStartInFilmstrip = data.getBoolean(KEY_START_IN_FILMSTRIP, false); boolean inCameraRoll = data.getBoolean(KEY_IN_CAMERA_ROLL, false); mCurrentIndex = data.getInt(KEY_INDEX_HINT, 0); if (mSetPathString != null) { mShowSpinner = true; /// M: [FEATURE.ADD] [Camera independent from Gallery] @{ // Launch from secure camera if (!mSetPathString.equals("/local/all/0") && SecureSource.isSecurePath(mSetPathString)) { Log.d(TAG, "<onCreate> secure album"); mFlags |= FLAG_SHOW_WHEN_LOCKED; mSecureAlbum = (SecureAlbum) mActivity.getDataManager().getMediaSet(mSetPathString); mSecureAlbum.clearAll(); ArrayList<String> secureAlbum = (ArrayList<String>) data.getSerializable(SECURE_ALBUM); if (secureAlbum != null) { int albumCount = secureAlbum.size(); Log.d(TAG, "<onCreate> albumCount " + albumCount); for (int i = 0; i < albumCount; i++) { try { String[] albumItem = secureAlbum.get(i).split("\\+"); int albumItemSize = albumItem.length; Log.d(TAG, "<onCreate> albumItemSize " + albumItemSize); if (albumItemSize == 2) { int id = Integer.parseInt(albumItem[0].trim()); boolean isVideo = Boolean.parseBoolean(albumItem[1].trim()); Log.d(TAG, "<onCreate> secure item : id " + id + ", isVideo " + isVideo); mSecureAlbum.addMediaItem(isVideo, id); } } catch (NullPointerException ex) { Log.e(TAG, "<onCreate> exception " + ex); } catch (PatternSyntaxException ex) { Log.e(TAG, "<onCreate> exception " + ex); } catch (NumberFormatException ex) { Log.e(TAG, "<onCreate> exception " + ex); } } } mShowSpinner = false; mSetPathString = "/filter/empty/{" + mSetPathString + "}"; mSetPathString = "/combo/item/{" + mSetPathString + "}"; } /// @} mAppBridge = (AppBridge) data.getParcelable(KEY_APP_BRIDGE); if (mAppBridge != null) { mShowBars = false; mHasCameraScreennailOrPlaceholder = true; mAppBridge.setServer(this); // Get the ScreenNail from AppBridge and register it. int id = SnailSource.newId(); Path screenNailSetPath = SnailSource.getSetPath(id); Path screenNailItemPath = SnailSource.getItemPath(id); mScreenNailSet = (SnailAlbum) mActivity.getDataManager().getMediaObject(screenNailSetPath); mScreenNailItem = (SnailItem) mActivity.getDataManager().getMediaObject(screenNailItemPath); mScreenNailItem.setScreenNail(mAppBridge.attachScreenNail()); if (data.getBoolean(KEY_SHOW_WHEN_LOCKED, false)) { // Set the flag to be on top of the lock screen. mFlags |= FLAG_SHOW_WHEN_LOCKED; } // Don't display "empty album" action item for capture intents. if (!mSetPathString.equals("/local/all/0")) { // Check if the path is a secure album. if (SecureSource.isSecurePath(mSetPathString)) { mSecureAlbum = (SecureAlbum) mActivity.getDataManager().getMediaSet(mSetPathString); mShowSpinner = false; } mSetPathString = "/filter/empty/{" + mSetPathString + "}"; } // Combine the original MediaSet with the one for ScreenNail // from AppBridge. mSetPathString = "/combo/item/{" + screenNailSetPath + "," + mSetPathString + "}"; // Start from the screen nail. itemPath = screenNailItemPath; /// M: [FEATURE.MARK] [Camera independent from Gallery] @{ // After camera is removed from gallery, modify the behavior as below: // When view the first image in camera folder, slide to left, // there is no place holder of camera, and it can not launch camera too. /*} else if (inCameraRoll && GalleryUtils.isCameraAvailable(mActivity)) { mSetPathString = "/combo/item/{" + FilterSource.FILTER_CAMERA_SHORTCUT + "," + mSetPathString + "}"; mCurrentIndex++; mHasCameraScreennailOrPlaceholder = true;*/ /// @} /// M: [FEATURE.ADD] [Camera independent from Gallery] @{ // When launch from camera, and not from secure camera, we show empty item // after delete all images. } else if (mLaunchFromCamera && mSecureAlbum == null) { mSetPathString = "/filter/empty/{" + mSetPathString + "}"; Log.i(TAG, "<onCreate> launch from camera, not secure, mSetPathString = " + mSetPathString); /// @} } MediaSet originalSet = mActivity.getDataManager().getMediaSet(mSetPathString); if (mHasCameraScreennailOrPlaceholder && originalSet instanceof ComboAlbum) { // Use the name of the camera album rather than the default // ComboAlbum behavior ((ComboAlbum) originalSet).useNameOfChild(1); } /// M: [BUG.ADD] @{ // tell PhotoView whether this album is cluster if (originalSet != null && originalSet instanceof ClusterAlbum) { mPhotoView.setIsCluster(true); } else { mPhotoView.setIsCluster(false); } /// @} mSelectionManager.setSourceMediaSet(originalSet); mSetPathString = "/filter/delete/{" + mSetPathString + "}"; mMediaSet = (FilterDeleteSet) mActivity.getDataManager().getMediaSet(mSetPathString); if (mMediaSet == null) { Log.w(TAG, "failed to restore " + mSetPathString); } if (itemPath == null) { int mediaItemCount = mMediaSet.getMediaItemCount(); if (mediaItemCount > 0) { if (mCurrentIndex >= mediaItemCount) mCurrentIndex = 0; itemPath = mMediaSet.getMediaItem(mCurrentIndex, 1).get(0).getPath(); } else { // Bail out, PhotoPage can't load on an empty album return; } } PhotoDataAdapter pda = new PhotoDataAdapter(mActivity, mPhotoView, mMediaSet, itemPath, mCurrentIndex, mAppBridge == null ? -1 : 0, mAppBridge == null ? false : mAppBridge.isPanorama(), mAppBridge == null ? false : mAppBridge.isStaticCamera()); mModel = pda; mPhotoView.setModel(mModel); pda.setDataListener(new PhotoDataAdapter.DataListener() { @Override public void onPhotoChanged(int index, Path item) { int oldIndex = mCurrentIndex; mCurrentIndex = index; if (mHasCameraScreennailOrPlaceholder) { if (mCurrentIndex > 0) { mSkipUpdateCurrentPhoto = false; } /// M: [FEATURE.MODIFY] @{ /*if (oldIndex == 0 && mCurrentIndex > 0 && !mPhotoView.getFilmMode()) { mPhotoView.setFilmMode(true);*/ if (oldIndex == 0 && mCurrentIndex > 0) { onActionBarAllowed(true); mPhotoView.setFilmMode(false); /// @} if (mAppBridge != null) { UsageStatistics.onEvent("CameraToFilmstrip", UsageStatistics.TRANSITION_SWIPE, null); } } else if (oldIndex == 2 && mCurrentIndex == 1) { mCameraSwitchCutoff = SystemClock.uptimeMillis() + CAMERA_SWITCH_CUTOFF_THRESHOLD_MS; mPhotoView.stopScrolling(); } else if (oldIndex >= 1 && mCurrentIndex == 0) { mPhotoView.setWantPictureCenterCallbacks(true); mSkipUpdateCurrentPhoto = true; } } if (!mSkipUpdateCurrentPhoto) { if (item != null) { MediaItem photo = mModel.getMediaItem(0); if (photo != null) updateCurrentPhoto(photo); } updateBars(); } // Reset the timeout for the bars after a swipe /// M: [DEBUG.ADD] @{ Log.i(TAG, "<onPhotoChanged> refreshHidingMessage"); /// @} refreshHidingMessage(); } @Override public void onLoadingFinished(boolean loadingFailed) { /// M: [BUG.ADD] @{ mLoadingFinished = true; // Refresh bottom controls when data loading done refreshBottomControlsWhenReady(); /// @} if (!mModel.isEmpty()) { MediaItem photo = mModel.getMediaItem(0); if (photo != null) updateCurrentPhoto(photo); } else if (mIsActive) { // We only want to finish the PhotoPage if there is no // deletion that the user can undo. if (mMediaSet.getNumberOfDeletions() == 0) { /// M: [BUG.ADD] pause PhotoView before finish PhotoPage @{ mPhotoView.pause(); /// @} mActivity.getStateManager().finishState(PhotoPage.this); } } } @Override public void onLoadingStarted() { /// M: [BUG.ADD] @{ mLoadingFinished = false; /// @} } }); } else { // Get default media set by the URI MediaItem mediaItem = (MediaItem) mActivity.getDataManager().getMediaObject(itemPath); /// M: [BUG.ADD] fix JE when mediaItem is deleted@{ if (mediaItem == null) { Toast.makeText(((Activity) mActivity), R.string.no_such_item, Toast.LENGTH_LONG).show(); mPhotoView.pause(); mActivity.getStateManager().finishState(this); return; } /// @} /// M: [BUG.ADD] @{ // no PhotoDataAdapter style loading in SinglePhotoDataAdapter mLoadingFinished = true; /// @} mModel = new SinglePhotoDataAdapter(mActivity, mPhotoView, mediaItem); mPhotoView.setModel(mModel); updateCurrentPhoto(mediaItem); mShowSpinner = false; } mPhotoView.setFilmMode(mStartInFilmstrip && mMediaSet.getMediaItemCount() > 1); RelativeLayout galleryRoot = (RelativeLayout) ((Activity) mActivity) .findViewById(mAppBridge != null ? R.id.content : R.id.gallery_root); if (galleryRoot != null) { if (mSecureAlbum == null) { mBottomControls = new PhotoPageBottomControls(this, mActivity, galleryRoot); } } /// M: [BUG.MODIFY] set change listener to current GLRootView @{ // onResume also need to set this listener, so modify it. /*((GLRootView) mActivity.getGLRoot()).setOnSystemUiVisibilityChangeListener( new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { int diff = mLastSystemUiVis ^ visibility; mLastSystemUiVis = visibility; if ((diff & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0 && (visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { /// M: [BUG.MODIFY] Don't need show bars in camera preview. @{ /*showBars();*/ /*wantBars(); /// @} } } });*/ setOnSystemUiVisibilityChangeListener(); /// @} /// M: [FEATURE.ADD] VTSP: share as video @{ initAnimatedContentSharer(); /// @} /// M: [FEATURE.ADD] add backward controller for layer @{ mPhotoView.setBackwardControllerForLayerManager(mBackwardContollerForLayer); /// @} }
From source file:org.chromium.chrome.browser.tabmodel.TabPersistentStore.java
/** * Merge the tabs of the other Chrome instance into this instance by reading its tab metadata * file and tab state files.//from ww w . j a v a 2 s . co m * * This method should be called after a change in activity state indicates that a merge is * necessary. #loadState() will take care of merging states on application cold start if needed. * * If there is currently a merge or load in progress then this method will return early. */ public void mergeState() { if (mLoadInProgress || mPersistencePolicy.isMergeInProgress() || !mTabsToRestore.isEmpty()) { Log.e(TAG, "Tab load still in progress when merge was attempted."); return; } // Initialize variables. mCancelNormalTabLoads = false; mCancelIncognitoTabLoads = false; mNormalTabsRestored = new SparseIntArray(); mIncognitoTabsRestored = new SparseIntArray(); try { long time = SystemClock.uptimeMillis(); // Read the tab state metadata file. DataInputStream stream = startFetchTabListTask(AsyncTask.SERIAL_EXECUTOR, mPersistencePolicy.getStateToBeMergedFileName()).get(); // Return early if the stream is null, which indicates there isn't a second instance // to merge. if (stream == null) return; logExecutionTime("MergeStateInternalFetchTime", time); mPersistencePolicy.setMergeInProgress(true); readSavedStateFile(stream, createOnTabStateReadCallback(mTabModelSelector.isIncognitoSelected(), true), null, true); logExecutionTime("MergeStateInternalTime", time); } catch (Exception e) { // Catch generic exception to prevent a corrupted state from crashing app. Log.d(TAG, "meregeState exception: " + e.toString(), e); } // Restore the tabs from the second activity asynchronously. new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... voids) { mMergeTabCount = mTabsToRestore.size(); mRestoreMergedTabsStartTime = SystemClock.uptimeMillis(); restoreTabs(false); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.taobao.weex.utils.WXUtils.java
public static long getFixUnixTime() { return sInterval + SystemClock.uptimeMillis(); }
From source file:org.creativecommons.thelist.swipedismiss.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(); com.nineoldandroids.animation.ValueAnimator animator = com.nineoldandroids.animation.ValueAnimator .ofInt(originalHeight, 1).setDuration(mAnimationTime); animator.addListener(new com.nineoldandroids.animation.AnimatorListenerAdapter() { @Override//from ww w. j a va2s. c o m public void onAnimationEnd(com.nineoldandroids.animation.Animator animation) { --mDismissAnimationRefCount; if (mDismissAnimationRefCount == 0) { // boolean noAnimationLeft; // synchronized (mAnimationLock) { // Log.d("ANIMATIONLOCK", "hello"); // --mDismissAnimationRefCount; // mAnimatedViews.remove(dismissView); // noAnimationLeft = mDismissAnimationRefCount == 0; // } // // if(noAnimationLeft){ // 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 = ListView.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 = ViewGroup.LayoutParams.WRAP_CONTENT; 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); //Log.v("THESE ARE DISMISSES: ", mPendingDismisses.toString()); mPendingDismisses.clear(); } } }); animator.addUpdateListener(new com.nineoldandroids.animation.ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(com.nineoldandroids.animation.ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); dismissView.setLayoutParams(lp); } }); mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView)); animator.start(); }
From source file:rs.pedjaapps.kerneltuner.utility.IOHelper.java
public static String deepSleep() { String deepSleep;//from w w w . j a v a2 s . co m int time = (int) (SystemClock.elapsedRealtime() - SystemClock.uptimeMillis()); String s = (time / 1000) % 60 + ""; String m = (time / (1000 * 60)) % 60 + ""; String h = (time / (1000 * 3600)) % 24 + ""; String d = time / (1000 * 60 * 60 * 24) + ""; StringBuilder builder = new StringBuilder(); if (!d.equals("0")) { builder.append(d).append("d:"); } if (!h.equals("0")) { builder.append(h).append("h:"); } if (!m.equals("0")) { builder.append(m).append("m:"); } builder.append(s).append("s"); deepSleep = builder.toString(); return deepSleep; }
From source file:android.support.design.widget.CoordinatorLayout.java
private boolean performIntercept(MotionEvent ev, final int type) { boolean intercepted = false; boolean newBlock = false; MotionEvent cancelEvent = null;/*ww w .j a v a 2s . c o m*/ final int action = MotionEventCompat.getActionMasked(ev); final List<View> topmostChildList = mTempList1; getTopSortedChildren(topmostChildList); // Let topmost child views inspect first final int childCount = topmostChildList.size(); for (int i = 0; i < childCount; i++) { final View child = topmostChildList.get(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final Behavior b = lp.getBehavior(); if ((intercepted || newBlock) && action != MotionEvent.ACTION_DOWN) { // Cancel all behaviors beneath the one that intercepted. // If the event is "down" then we don't have anything to cancel yet. if (b != null) { if (cancelEvent == null) { final long now = SystemClock.uptimeMillis(); cancelEvent = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); } switch (type) { case TYPE_ON_INTERCEPT: b.onInterceptTouchEvent(this, child, cancelEvent); break; case TYPE_ON_TOUCH: b.onTouchEvent(this, child, cancelEvent); break; } } continue; } if (!intercepted && b != null) { switch (type) { case TYPE_ON_INTERCEPT: intercepted = b.onInterceptTouchEvent(this, child, ev); break; case TYPE_ON_TOUCH: intercepted = b.onTouchEvent(this, child, ev); break; } if (intercepted) { mBehaviorTouchView = child; } } // Don't keep going if we're not allowing interaction below this. // Setting newBlock will make sure we cancel the rest of the behaviors. final boolean wasBlocking = lp.didBlockInteraction(); final boolean isBlocking = lp.isBlockingInteractionBelow(this, child); newBlock = isBlocking && !wasBlocking; if (isBlocking && !newBlock) { // Stop here since we don't have anything more to cancel - we already did // when the behavior first started blocking things below this point. break; } } topmostChildList.clear(); return intercepted; }
From source file:com.googlecode.eyesfree.testing.BaseAccessibilityInstrumentationTestCase.java
/** * Attempts to obtain an instance of {@link TestAccessibilityService}. * <p>//from ww w .j a v a2s.c om * May block for up to {@link #OBTAIN_SERVICE_TIMEOUT} seconds, and may * return {@code null} if the service is not running. */ private boolean obtainTargetServiceSync() { boolean success = false; final long startTime = SystemClock.uptimeMillis(); try { while (true) { final AccessibilityService service = getService(); if (service != null) { break; } final long timeElapsed = (SystemClock.uptimeMillis() - startTime); final long timeLeft = (OBTAIN_SERVICE_TIMEOUT - timeElapsed); if (timeLeft <= 0) { break; } final long timeToWait = Math.min(OBTAIN_SERVICE_RETRY, timeLeft); Thread.sleep(timeToWait); } } catch (InterruptedException e) { // Do nothing. } LogUtils.log(this, Log.VERBOSE, "Took %d ms to obtain service", (SystemClock.uptimeMillis() - startTime)); return success; }