List of usage examples for android.os SystemClock uptimeMillis
@CriticalNative native public static long uptimeMillis();
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String GetUptimeMillis() { return Long.toString(SystemClock.uptimeMillis()); }
From source file:dev.dworks.libs.widget.ViewPager.java
public void fakeDragByVertically(float yOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); }// w w w . ja va 2 s . c o m mLastMotionY += yOffset; float oldScrollY = getScrollY(); float scrollY = oldScrollY - yOffset; final int height = getHeight(); float topBound = height * mFirstOffset; float bottomBound = height * mLastOffset; final ItemInfo firstItem = mItems.get(0); final ItemInfo lastItem = mItems.get(mItems.size() - 1); if (firstItem.position != 0) { topBound = firstItem.offset * height; } if (lastItem.position != mAdapter.getCount() - 1) { bottomBound = lastItem.offset * height; } if (scrollY < topBound) { scrollY = topBound; } else if (scrollY > bottomBound) { scrollY = bottomBound; } // Don't lose the rounded component mLastMotionY += scrollY - (int) scrollY; scrollTo(getScrollX(), (int) scrollY); pageScrolledY((int) scrollY); // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, 0, mLastMotionY, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:org.chromium.android_webview.test.AwSettingsTest.java
private void simulateDoubleTapCenterOfWebViewOnUiThread(final AwTestContainerView webView) throws Throwable { final int x = (webView.getRight() - webView.getLeft()) / 2; final int y = (webView.getBottom() - webView.getTop()) / 2; final AwContents awContents = webView.getAwContents(); runTestOnUiThread(new Runnable() { @Override//from w w w .jav a 2 s . co m public void run() { awContents.getContentViewCore().sendDoubleTapForTest(SystemClock.uptimeMillis(), x, y); } }); }
From source file:com.android.launcher2.Launcher.java
/** * Add the views for a widget to the workspace. * * Implementation of the method from LauncherModel.Callbacks. *//*from w w w. ja va2s . co m*/ public void bindAppWidget(LauncherAppWidgetInfo item) { setLoadOnResume(); final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; if (DEBUG_WIDGETS) { Log.d(TAG, "bindAppWidget: " + item); } final Workspace workspace = mWorkspace; final int appWidgetId = item.appWidgetId; final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); if (DEBUG_WIDGETS) { Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); } item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); item.hostView.setTag(item); item.onBindAppWidget(this); workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX, item.cellY, item.spanX, item.spanY, false); addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); workspace.requestLayout(); if (DEBUG_WIDGETS) { Log.d(TAG, "bound widget id=" + item.appWidgetId + " in " + (SystemClock.uptimeMillis() - start) + "ms"); } }
From source file:com.android.soma.Launcher.java
/** * Add the views for a widget to the workspace. * * Implementation of the method from LauncherModel.Callbacks. *//* w ww . j av a 2s. c om*/ public void bindAppWidget(final LauncherAppWidgetInfo item) { Runnable r = new Runnable() { public void run() { bindAppWidget(item); } }; if (waitUntilResume(r)) { return; } final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; if (DEBUG_WIDGETS) { Log.d(TAG, "bindAppWidget: " + item); } final Workspace workspace = mWorkspace; final int appWidgetId = item.appWidgetId; final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); if (DEBUG_WIDGETS) { Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); } item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); item.hostView.setTag(item); item.onBindAppWidget(this); workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX, item.cellY, item.spanX, item.spanY, false); addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); workspace.requestLayout(); if (DEBUG_WIDGETS) { Log.d(TAG, "bound widget id=" + item.appWidgetId + " in " + (SystemClock.uptimeMillis() - start) + "ms"); } }
From source file:com.klinker.android.launcher.launcher3.Launcher.java
/** * Add the views for a widget to the workspace. * * Implementation of the method from LauncherModel.Callbacks. *///w w w. j ava 2 s. c o m public void bindAppWidget(final LauncherAppWidgetInfo item) { Runnable r = new Runnable() { public void run() { bindAppWidget(item); } }; if (waitUntilResume(r)) { return; } final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; if (DEBUG_WIDGETS) { Log.d(TAG, "bindAppWidget: " + item); } final Workspace workspace = mWorkspace; LauncherAppWidgetProviderInfo appWidgetInfo = LauncherModel.getProviderInfo(this, item.providerName, item.user); if (!mIsSafeModeEnabled && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) && ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) { if (appWidgetInfo == null) { if (DEBUG_WIDGETS) { Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId + " belongs to component " + item.providerName + ", as the povider is null"); } LauncherModel.deleteItemFromDatabase(this, item); return; } // Note: This assumes that the id remap broadcast is received before this step. // If that is not the case, the id remap will be ignored and user may see the // click to setup view. PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(this, appWidgetInfo, null); pendingInfo.spanX = item.spanX; pendingInfo.spanY = item.spanY; pendingInfo.minSpanX = item.minSpanX; pendingInfo.minSpanY = item.minSpanY; Bundle options = null; WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo); int newWidgetId = mAppWidgetHost.allocateAppWidgetId(); boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId, appWidgetInfo, options); // TODO consider showing a permission dialog when the widget is clicked. if (!success) { mAppWidgetHost.deleteAppWidgetId(newWidgetId); if (DEBUG_WIDGETS) { Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId + " belongs to component " + item.providerName + ", as the launcher is unable to bing a new widget id"); } LauncherModel.deleteItemFromDatabase(this, item); return; } item.appWidgetId = newWidgetId; // If the widget has a configure activity, it is still needs to set it up, otherwise // the widget is ready to go. item.restoreStatus = (appWidgetInfo.configure == null) ? LauncherAppWidgetInfo.RESTORE_COMPLETED : LauncherAppWidgetInfo.FLAG_UI_NOT_READY; LauncherModel.updateItemInDatabase(this, item); } if (!mIsSafeModeEnabled && item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { final int appWidgetId = item.appWidgetId; if (DEBUG_WIDGETS) { Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); } item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); } else { appWidgetInfo = null; PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, mIsSafeModeEnabled); view.updateIcon(mIconCache); item.hostView = view; item.hostView.updateAppWidget(null); item.hostView.setOnClickListener(this); } item.hostView.setTag(item); item.onBindAppWidget(this); workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX, item.cellY, item.spanX, item.spanY, false); if (!item.isCustomWidget()) { addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); } workspace.requestLayout(); if (DEBUG_WIDGETS) { Log.d(TAG, "bound widget id=" + item.appWidgetId + " in " + (SystemClock.uptimeMillis() - start) + "ms"); } }
From source file:xyz.klinker.blur.launcher3.Launcher.java
/** * Add the views for a widget to the workspace. * * Implementation of the method from LauncherModel.Callbacks. *//*from w w w . ja va 2 s . c o m*/ public void bindAppWidget(final LauncherAppWidgetInfo item) { Runnable r = new Runnable() { public void run() { bindAppWidget(item); } }; if (waitUntilResume(r)) { return; } if (mIsSafeModeEnabled) { bindSafeModeWidget(item); return; } final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; if (DEBUG_WIDGETS) { Log.d(TAG, "bindAppWidget: " + item); } final LauncherAppWidgetProviderInfo appWidgetInfo; if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) { // If the provider is not ready, bind as a pending widget. appWidgetInfo = null; } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) { // The widget id is not valid. Try to find the widget based on the provider info. appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user); } else { appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId); } // If the provider is ready, but the width is not yet restored, try to restore it. if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) && (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) { if (appWidgetInfo == null) { if (DEBUG_WIDGETS) { Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId + " belongs to component " + item.providerName + ", as the povider is null"); } LauncherModel.deleteItemFromDatabase(this, item); return; } // If we do not have a valid id, try to bind an id. if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) { // Note: This assumes that the id remap broadcast is received before this step. // If that is not the case, the id remap will be ignored and user may see the // click to setup view. PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(this, appWidgetInfo, null); pendingInfo.spanX = item.spanX; pendingInfo.spanY = item.spanY; pendingInfo.minSpanX = item.minSpanX; pendingInfo.minSpanY = item.minSpanY; Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo); int newWidgetId = mAppWidgetHost.allocateAppWidgetId(); boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(newWidgetId, appWidgetInfo, options); // TODO consider showing a permission dialog when the widget is clicked. if (!success) { mAppWidgetHost.deleteAppWidgetId(newWidgetId); if (DEBUG_WIDGETS) { Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId + " belongs to component " + item.providerName + ", as the launcher is unable to bing a new widget id"); } LauncherModel.deleteItemFromDatabase(this, item); return; } item.appWidgetId = newWidgetId; // If the widget has a configure activity, it is still needs to set it up, otherwise // the widget is ready to go. item.restoreStatus = (appWidgetInfo.configure == null) ? LauncherAppWidgetInfo.RESTORE_COMPLETED : LauncherAppWidgetInfo.FLAG_UI_NOT_READY; LauncherModel.updateItemInDatabase(this, item); } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY) && (appWidgetInfo.configure == null)) { // The widget was marked as UI not ready, but there is no configure activity to // update the UI. item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED; LauncherModel.updateItemInDatabase(this, item); } } if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { if (DEBUG_WIDGETS) { Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); } // Verify that we own the widget if (appWidgetInfo == null) { Log.e(TAG, "Removing invalid widget: id=" + item.appWidgetId); deleteWidgetInfo(item); return; } item.hostView = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo); item.minSpanX = appWidgetInfo.minSpanX; item.minSpanY = appWidgetInfo.minSpanY; addAppWidgetToWorkspace(item, appWidgetInfo, false); } else { PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, mIsSafeModeEnabled); view.updateIcon(mIconCache); item.hostView = view; item.hostView.updateAppWidget(null); item.hostView.setOnClickListener(this); addAppWidgetToWorkspace(item, null, false); } mWorkspace.requestLayout(); if (DEBUG_WIDGETS) { Log.d(TAG, "bound widget id=" + item.appWidgetId + " in " + (SystemClock.uptimeMillis() - start) + "ms"); } }
From source file:com.android.launcher3.Launcher.java
/** * Add the views for a widget to the workspace. * * Implementation of the method from LauncherModel.Callbacks. *///from ww w . j ava 2 s .c o m public void bindAppWidget(final LauncherAppWidgetInfo item) { Runnable r = new Runnable() { public void run() { bindAppWidget(item); } }; if (waitUntilResume(r)) { return; } if (mIsSafeModeEnabled) { bindSafeModeWidget(item); return; } final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; if (DEBUG_WIDGETS) { Log.d(TAG, "bindAppWidget: " + item); } final LauncherAppWidgetProviderInfo appWidgetInfo; if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)) { // If the provider is not ready, bind as a pending widget. appWidgetInfo = null; } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) { // The widget id is not valid. Try to find the widget based on the provider info. appWidgetInfo = mAppWidgetManager.findProvider(item.providerName, item.user); } else { appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(item.appWidgetId); } // If the provider is ready, but the width is not yet restored, try to restore it. if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) && (item.restoreStatus != LauncherAppWidgetInfo.RESTORE_COMPLETED)) { if (appWidgetInfo == null) { if (DEBUG_WIDGETS) { Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId + " belongs to component " + item.providerName + ", as the povider is null"); } LauncherModel.deleteItemFromDatabase(this, item); return; } // If we do not have a valid id, try to bind an id. if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) { if (!item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) { // Id has not been allocated yet. Allocate a new id. item.appWidgetId = mAppWidgetHost.allocateAppWidgetId(); item.restoreStatus |= LauncherAppWidgetInfo.FLAG_ID_ALLOCATED; // Also try to bind the widget. If the bind fails, the user will be shown // a click to setup UI, which will ask for the bind permission. PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(this, appWidgetInfo); pendingInfo.spanX = item.spanX; pendingInfo.spanY = item.spanY; pendingInfo.minSpanX = item.minSpanX; pendingInfo.minSpanY = item.minSpanY; Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo); boolean isDirectConfig = item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG); if (isDirectConfig && item.bindOptions != null) { Bundle newOptions = item.bindOptions.getExtras(); if (options != null) { newOptions.putAll(options); } options = newOptions; } boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(item.appWidgetId, appWidgetInfo, options); // We tried to bind once. If we were not able to bind, we would need to // go through the permission dialog, which means we cannot skip the config // activity. item.bindOptions = null; item.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG; // Bind succeeded if (success) { // If the widget has a configure activity, it is still needs to set it up, // otherwise the widget is ready to go. item.restoreStatus = (appWidgetInfo.configure == null) || isDirectConfig ? LauncherAppWidgetInfo.RESTORE_COMPLETED : LauncherAppWidgetInfo.FLAG_UI_NOT_READY; } LauncherModel.updateItemInDatabase(this, item); } } else if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_UI_NOT_READY) && (appWidgetInfo.configure == null)) { // The widget was marked as UI not ready, but there is no configure activity to // update the UI. item.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED; LauncherModel.updateItemInDatabase(this, item); } } if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) { if (DEBUG_WIDGETS) { Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); } // Verify that we own the widget if (appWidgetInfo == null) { FileLog.e(TAG, "Removing invalid widget: id=" + item.appWidgetId); deleteWidgetInfo(item); return; } item.minSpanX = appWidgetInfo.minSpanX; item.minSpanY = appWidgetInfo.minSpanY; addAppWidgetToWorkspace(mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo), item, appWidgetInfo, false); } else { PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, false); view.updateIcon(mIconCache); view.updateAppWidget(null); view.setOnClickListener(this); addAppWidgetToWorkspace(view, item, null, false); } mWorkspace.requestLayout(); if (DEBUG_WIDGETS) { Log.d(TAG, "bound widget id=" + item.appWidgetId + " in " + (SystemClock.uptimeMillis() - start) + "ms"); } }
From source file:com.datarita.ultimatecamera.turu.views.TwoWayView.java
private int findSyncPosition() { int itemCount = mItemCount; if (itemCount == 0) { return INVALID_POSITION; }/*w ww . ja v a 2s . com*/ final long idToMatch = mSyncRowId; // If there isn't a selection don't hunt for it if (idToMatch == INVALID_ROW_ID) { return INVALID_POSITION; } // Pin seed to reasonable values int seed = mSyncPosition; seed = Math.max(0, seed); seed = Math.min(itemCount - 1, seed); long endTime = SystemClock.uptimeMillis() + SYNC_MAX_DURATION_MILLIS; long rowId; // first position scanned so far int first = seed; // last position scanned so far int last = seed; // True if we should move down on the next iteration boolean next = false; // True when we have looked at the first item in the data boolean hitFirst; // True when we have looked at the last item in the data boolean hitLast; // Get the item ID locally (instead of getItemIdAtPosition), so // we need the mAdapter final ListAdapter adapter = mAdapter; if (adapter == null) { return INVALID_POSITION; } while (SystemClock.uptimeMillis() <= endTime) { rowId = adapter.getItemId(seed); if (rowId == idToMatch) { // Found it! return seed; } hitLast = (last == itemCount - 1); hitFirst = (first == 0); if (hitLast && hitFirst) { // Looked at everything break; } if (hitFirst || (next && !hitLast)) { // Either we hit the top, or we are trying to move down last++; seed = last; // Try going up next time next = false; } else if (hitLast || (!next && !hitFirst)) { // Either we hit the bottom, or we are trying to move up first--; seed = first; // Try going down next time next = true; } } return INVALID_POSITION; }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
private int findSyncPosition() { int itemCount = mItemCount; if (itemCount == 0) { return INVALID_POSITION; }//from www . ja v a 2s. co m final long idToMatch = mSyncRowId; // If there isn't a selection don't hunt for it if (idToMatch == INVALID_ROW_ID) { return INVALID_POSITION; } // Pin seed to reasonable values int seed = mSyncPosition; seed = Math.max(0, seed); seed = Math.min(itemCount - 1, seed); long endTime = SystemClock.uptimeMillis() + SYNC_MAX_DURATION_MILLIS; long rowId; // first position scanned so far int first = seed; // last position scanned so far int last = seed; // True if we should move down on the next iteration boolean next = false; // True when we have looked at the first item in the data boolean hitFirst; // True when we have looked at the last item in the data boolean hitLast; // Get the item ID locally (instead of getItemIdAtPosition), so // we need the adapter final ListAdapter adapter = mAdapter; if (adapter == null) { return INVALID_POSITION; } while (SystemClock.uptimeMillis() <= endTime) { rowId = adapter.getItemId(seed); if (rowId == idToMatch) { // Found it! return seed; } hitLast = (last == itemCount - 1); hitFirst = (first == 0); if (hitLast && hitFirst) { // Looked at everything break; } if (hitFirst || (next && !hitLast)) { // Either we hit the top, or we are trying to move down last++; seed = last; // Try going up next time next = false; } else if (hitLast || (!next && !hitFirst)) { // Either we hit the bottom, or we are trying to move up first--; seed = first; // Try going down next time next = true; } } return INVALID_POSITION; }