List of usage examples for android.os SystemClock uptimeMillis
@CriticalNative native public static long uptimeMillis();
From source file:Main.java
public static long getTimeSecs() { return SystemClock.uptimeMillis() / 1000; }
From source file:Main.java
public static long getTimeMillis() { return SystemClock.uptimeMillis(); }
From source file:Main.java
public static void dispatchCancelEvent(View view) { view.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_CANCEL, 0, 0, 0)); }
From source file:Main.java
public static void recordForegroundStartTime() { sForegroundStartTimeMs = SystemClock.uptimeMillis(); }
From source file:Main.java
private static long dragStart(View view, float x, float y) { long downTime = SystemClock.uptimeMillis(); sendAction(view, MotionEvent.ACTION_DOWN, downTime, x, y); return downTime; }
From source file:Main.java
/** * Record the time at which Chrome was sent to background. */ public static void recordBackgroundTime() { sBackgroundTimeMs = SystemClock.uptimeMillis(); }
From source file:Main.java
public static void setKeyboardFocus(final EditText mEditText) { (new Handler()).postDelayed(new Runnable() { public void run() { mEditText.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 0, 0, 0)); mEditText.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 0, 0, 0)); }// www . j av a 2 s .c o m }, 100); }
From source file:Main.java
public static void dispatchTouch(final View view, final long duration) { final long downTime = SystemClock.uptimeMillis(); final long eventTime = SystemClock.uptimeMillis(); final float x = view.getWidth() / 3;//0.0f; final float y = view.getHeight() / 3;//0.0f; // List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState() final int metaState = 0; MotionEvent motionEvent = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, x, y, metaState); // Dispatch touch event to view view.dispatchTouchEvent(motionEvent); new Handler().postDelayed(new Runnable() { @Override/*ww w.j ava 2 s. c om*/ public void run() { MotionEvent motionEvent = MotionEvent.obtain(downTime + duration, eventTime + duration, MotionEvent.ACTION_UP, x, y, metaState); view.dispatchTouchEvent(motionEvent); } }, duration); }
From source file:Main.java
private static void sendAction(View view, int action, long downTime, float x, float y) { long eventTime = SystemClock.uptimeMillis(); MotionEvent event = MotionEvent.obtain(downTime, eventTime, action, x, y, 0); view.onTouchEvent(event);/*from ww w .j av a 2 s. co m*/ }
From source file:Main.java
public static MotionEvent CreateMotionEventFromJSonObject(JSONObject jObj) throws JSONException { long uptime = SystemClock.uptimeMillis(); //get pointer infos JSONArray array = jObj.optJSONArray("pointers"); int arrlen = array != null ? array.length() : 1; PointerProperties[] props = new PointerProperties[arrlen]; PointerCoords[] coords = new PointerCoords[arrlen]; if (array != null) { for (int i = 0; i < array.length(); i++) { PointerProperties prop = new PointerProperties(); PointerCoords coord = new PointerCoords(); PointerValuesFromJSonObj(prop, coord, array.getJSONObject(i)); props[i] = prop;//from w w w. j ava 2 s. com coords[i] = coord; } } else { JSONObject pointer = jObj.optJSONObject("pointers"); if (pointer != null) { PointerProperties prop = new PointerProperties(); PointerCoords coord = new PointerCoords(); PointerValuesFromJSonObj(prop, coord, pointer); props[0] = prop; coords[0] = coord; } } long downTimeOffset = jObj.getLong("eventTime") - jObj.getLong("downTime"); /* TODO calculating the time offset is not a goog solution. the downtime should be the same of all events in a row. * for an optimal use the events should be traced. then at the first occurency both down and event time * are set from uptime. and then in the follow up events the uptime is used for event time and the stored downtime * for the downtime. but for this some identification of events is needed. * first events can be identified with (eventTime == downTime) * */ MotionEvent event = MotionEvent.obtain(uptime - downTimeOffset, uptime, jObj.getInt("action"), jObj.getInt("pointerCount"), props, coords, jObj.getInt("metaState"), jObj.getInt("buttonState"), (float) jObj.getDouble("xPrecision"), (float) jObj.getDouble("yPrecision"), jObj.getInt("deviceId"), jObj.getInt("edgeFlags"), jObj.getInt("source"), jObj.getInt("flags")); return event; }