List of usage examples for android.os SystemClock uptimeMillis
@CriticalNative native public static long uptimeMillis();
From source file:Main.java
/** * Performs a single touch on the center of the supplied view. * This is safe to call from the instrumentation thread and will invoke the touch * asynchronously./*from w w w. ja v a 2 s .c om*/ * * @param view The view the coordinates are relative to. */ public static void simulateTouchCenterOfView(final View view) throws Throwable { view.post(new Runnable() { @Override public void run() { long eventTime = SystemClock.uptimeMillis(); float x = (float) (view.getRight() - view.getLeft()) / 2; float y = (float) (view.getBottom() - view.getTop()) / 2; view.onTouchEvent(MotionEvent.obtain(eventTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0)); view.onTouchEvent(MotionEvent.obtain(eventTime, eventTime, MotionEvent.ACTION_UP, x, y, 0)); } }); }
From source file:Main.java
/** * Record the time at which Chrome was brought to foreground. *///from w w w .j a va 2s . c o m public static void recordForegroundStartTime() { // Since this can be called from multiple places (e.g. ChromeActivitySessionTracker // and FirstRunActivity), only set the time if it hasn't been set previously or if // Chrome has been sent to background since the last foreground time. if (sForegroundStartTimeMs == 0 || sForegroundStartTimeMs < sBackgroundTimeMs) { sForegroundStartTimeMs = SystemClock.uptimeMillis(); } }
From source file:Main.java
public static List<MotionEvent> createMotionEvents(final AbsListView absListView, final float fromY, final float toY) { int x = (int) (absListView.getX() + absListView.getWidth() / 2); List<MotionEvent> results = new ArrayList<>(); results.add(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, x, fromY, 0)); float diff = (toY - fromY) / 25; float y = fromY; for (int i = 0; i < 25; i++) { y += diff;/* w ww . jav a 2 s. c o m*/ results.add(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE, x, y, 0)); } results.add(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, x, toY, 0)); return results; }
From source file:Main.java
public static MotionEvent motionEventAtPosition(View view, int action, int xPercent, int yPercent) { // NOTE: This method is not perfect. If you send touch events in a granular nature, you'll // see varying results of accuracy depending on the size of the jump. int paddingLeft = view.getPaddingLeft(); int paddingRight = view.getPaddingRight(); int paddingTop = view.getPaddingTop(); int paddingBottom = view.getPaddingBottom(); int width = view.getWidth(); int height = view.getHeight(); int[] topLeft = new int[2]; view.getLocationInWindow(topLeft);//from w ww. jav a 2 s. c om int x1 = topLeft[0] + paddingLeft; int y1 = topLeft[1] + paddingTop; int x2 = x1 + width - paddingLeft - paddingRight; int y2 = y1 + height - paddingTop - paddingBottom; float x = x1 + ((x2 - x1) * xPercent / 100f); float y = y1 + ((y2 - y1) * yPercent / 100f); long time = SystemClock.uptimeMillis(); return MotionEvent.obtain(time, time, action, x, y, 0); }
From source file:Main.java
public static MotionEvent motionEventAtPosition(View view, int action, int position) { // NOTE: This method is not perfect. If you send touch events in a granular nature, you'll // see varying results of accuracy depending on the size of the jump. int paddingLeft = view.getPaddingLeft(); int paddingRight = view.getPaddingRight(); int paddingTop = view.getPaddingTop(); int paddingBottom = view.getPaddingBottom(); int width = view.getWidth(); int height = view.getHeight(); int topLeft[] = new int[2]; view.getLocationInWindow(topLeft);//from w w w . ja va2 s. co m int x1 = topLeft[0] + paddingLeft; int y1 = topLeft[1] + paddingTop; int x2 = x1 + width - paddingLeft - paddingRight; int y2 = y1 + height - paddingTop - paddingBottom; float x = x1 + ((x2 - x1) * position / 100f); float y = y1 + ((y2 - y1) / 2f); long time = SystemClock.uptimeMillis(); return MotionEvent.obtain(time, time, action, x, y, 0); }
From source file:Main.java
/** * Returns the current animation time in milliseconds. This time should be used when invoking * {@link Animation#setStartTime(long)}. Refer to {@link android.os.SystemClock} for more * information about the different available clocks. The clock used by this method is * <em>not</em> the "wall" clock (it is not {@link System#currentTimeMillis}). * * @return the current animation time in milliseconds * * @see android.os.SystemClock/*from w w w . j a v a 2s . c o m*/ */ public static long currentAnimationTimeMillis() { return SystemClock.uptimeMillis(); }
From source file:io.trigger.forge.android.modules.keyboard.API.java
private static Runnable typeString(final EditText webTextView, final String text) { return new Runnable() { @Override/*w w w . j av a 2s.com*/ public void run() { webTextView.dispatchKeyEvent( new KeyEvent(SystemClock.uptimeMillis(), text, KeyCharacterMap.VIRTUAL_KEYBOARD, 0)); } }; }
From source file:com.prey.json.actions.Uptime.java
public HttpDataService run(Context ctx, List<ActionResult> lista, JSONObject parameters) { long uptime = SystemClock.uptimeMillis(); HttpDataService data = new HttpDataService("uptime"); String uptimeData = Long.toString(uptime); data.setSingleData(uptimeData);//from www .j a v a 2 s. co m return data; }
From source file:org.mtransit.android.ui.view.map.impl.MarkerAnimator.java
private void calculatePositions() { long now = SystemClock.uptimeMillis(); Iterator<DelegatingMarker> iterator = queue.keySet().iterator(); while (iterator.hasNext()) { DelegatingMarker marker = iterator.next(); AnimationData data = queue.get(marker); long time = now - data.start; if (time <= 0) { marker.setPositionDuringAnimation(data.from); } else if (time >= data.duration) { marker.setPositionDuringAnimation(data.to); if (data.callback != null) { data.callback.onFinish(marker); }/*from w w w .j a v a2s .c o m*/ iterator.remove(); } else { float t = ((float) time) / data.duration; t = data.interpolator.getInterpolation(t); double lat = (1.0f - t) * data.from.latitude + t * data.to.latitude; double lng = (1.0f - t) * data.from.longitude + t * data.to.longitude; marker.setPositionDuringAnimation(new LatLng(lat, lng)); } } if (queue.size() > 0) { handler.sendEmptyMessage(0); } }
From source file:Main.java
/** * Replaces an ImageView's background AnimationDrawable with the specified resource id in the * future. Calls start() on the AnimationDrawable once it has been replaced. * @param handler The Handler for the Activity in which the animation will run. * @param imageView An ImageView that has a background that can be casted to AnimationDrawable. * @param animationResourceId The animation's resource id. * @param color The color to apply to the AnimationDrawable. * @param millisFromNow The number of milliseconds to wait before replacing the animation. *///from w ww . j a v a2 s . co m public static void replaceAnimationInFuture(final Handler handler, final ImageView imageView, final int animationResourceId, final int color, long millisFromNow) { handler.postAtTime(new Runnable() { @Override public void run() { imageView.setBackgroundResource(animationResourceId); imageView.getBackground().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY); ((AnimationDrawable) (imageView.getBackground())).start(); } }, SystemClock.uptimeMillis() + millisFromNow); }