Example usage for android.os SystemClock uptimeMillis

List of usage examples for android.os SystemClock uptimeMillis

Introduction

In this page you can find the example usage for android.os SystemClock uptimeMillis.

Prototype

@CriticalNative
native public static long uptimeMillis();

Source Link

Document

Returns milliseconds since boot, not counting time spent in deep sleep.

Usage

From source file:com.onyx.latinime.accessibility.AccessibilityEntityProvider.java

/**
 * Simulates a key press by injecting touch events into the keyboard view.
 * This avoids the complexity of trackers and listeners within the keyboard.
 *
 * @param key The key to press.//from  w ww  . j  av a 2s  .  c  o  m
 */
void simulateKeyPress(final Key key) {
    final int x = key.getHitBox().centerX();
    final int y = key.getHitBox().centerY();
    final long downTime = SystemClock.uptimeMillis();
    final MotionEvent downEvent = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_DOWN, x, y, 0);
    final MotionEvent upEvent = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP,
            x, y, 0);

    mKeyboardView.onTouchEvent(downEvent);
    mKeyboardView.onTouchEvent(upEvent);
    downEvent.recycle();
    upEvent.recycle();
}

From source file:com.near.chimerarevo.activities.MainActivity.java

@Override
public void onDestroy() {
    super.onDestroy();
    if (ImageLoader.getInstance().isInited()) {
        ImageLoader.getInstance().clearDiskCache();
        ImageLoader.getInstance().clearMemoryCache();
    }/*from  ww w.j  a va2 s. c  o  m*/
    if (mHelper != null)
        mHelper.dispose();

    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("news_search_pref", true)) {
        Intent intent = new Intent(getApplicationContext(), NewsService.class);
        PendingIntent pintent = PendingIntent.getService(getApplicationContext(), 0, intent, 0);
        AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

        alarm.cancel(pintent);

        long delay;
        int sel = Integer.parseInt(
                PreferenceManager.getDefaultSharedPreferences(this).getString("notification_delay_pref", "0"));

        switch (sel) {
        case 0:
            delay = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
            break;
        case 1:
            delay = AlarmManager.INTERVAL_HALF_HOUR;
            break;
        case 2:
            delay = AlarmManager.INTERVAL_HOUR;
            break;
        case 3:
            delay = 2 * AlarmManager.INTERVAL_HOUR;
            break;
        case 4:
            delay = 3 * AlarmManager.INTERVAL_HOUR;
            break;
        case 5:
            delay = 6 * AlarmManager.INTERVAL_HOUR;
            break;
        case 6:
            delay = AlarmManager.INTERVAL_HALF_DAY;
            break;
        case 7:
            delay = AlarmManager.INTERVAL_DAY;
            break;
        default:
            delay = AlarmManager.INTERVAL_HOUR;
            break;
        }

        alarm.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.uptimeMillis(), delay, pintent);
    }
}

From source file:io.selendroid.server.model.AndroidWebElement.java

@Override
public void click() {
    String tagName = getTagName();
    if ((tagName != null && "OPTION".equals(tagName.toUpperCase())) || driver.isInFrame()) {
        driver.resetPageIsLoading();/* w w w. j  ava  2s  .  c  o m*/
        driver.executeAtom(AndroidAtoms.CLICK, null, this);
        driver.waitForPageToLoad();
        if (driver.isInFrame()) {
            return;
        }
    }

    Point center = getCenterCoordinates();
    long downTime = SystemClock.uptimeMillis();
    final List<MotionEvent> events = new ArrayList<MotionEvent>();

    MotionEvent downEvent = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN,
            center.x, center.y, 0);
    events.add(downEvent);
    MotionEvent upEvent = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP,
            center.x, center.y, 0);

    events.add(upEvent);

    driver.resetPageIsLoading();
    driver.getMotionSender().send(events);

    // If the page started loading we should wait
    // until the page is done loading.
    driver.waitForPageToLoad();
}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewWithMiniKeyboard.java

protected void setPopupStickinessValues(boolean isSticky, boolean requiresSlideInMotionEvent, int touchX,
        int touchY) {
    mChildKeyboardActionListener.setInOneShot(!isSticky);
    if (requiresSlideInMotionEvent) {
        // Inject down event on the key to mini keyboard.
        long eventTime = SystemClock.uptimeMillis();
        mMiniKeyboardPopupTime = eventTime;
        MotionEvent downEvent = generateMiniKeyboardMotionEvent(MotionEvent.ACTION_DOWN, touchX, touchY,
                eventTime);//w w  w . java2  s  .  c  om
        mMiniKeyboard.onTouchEvent(downEvent);
        downEvent.recycle();
    }

}

From source file:com.ryan.sample.FMAsyncTaskLoader.java

void dispatchOnCancelled(LoadTask task, D data) {
    onCanceled(data);//  w w w.  j  a v  a2  s. c o m
    if (mCancellingTask == task) {
        if (DEBUG)
            Log.v(TAG, "Cancelled task is now canceled!");
        rollbackContentChanged();
        mLastLoadCompleteTime = SystemClock.uptimeMillis();
        mCancellingTask = null;
        if (DEBUG)
            Log.v(TAG, "Delivering cancellation");
        deliverCancellation();
        executePendingTask();
    }
}

From source file:com.google.io.accessibility.util.IncrementalAsyncTaskLoader.java

void dispatchOnLoadComplete(LoadTask task, D data) {
    if (mTask != task) {
        if (DEBUG)
            Log.v(TAG, "Load complete of old task, trying to cancel");
        dispatchOnCancelled(task, data);
    } else {//from  ww w. ja  v  a 2 s. c  o m
        if (isAbandoned()) {
            // This cursor has been abandoned; just cancel the new data.
            onCanceled(data);
        } else {
            mLastLoadCompleteTime = SystemClock.uptimeMillis();
            mTask = null;
            if (DEBUG)
                Log.v(TAG, "Delivering result");
            deliverResult(data);
        }
    }
}

From source file:com.android.inputmethod.accessibility.KeyboardAccessibilityDelegate.java

/**
 * Simulating a touch event by injecting a synthesized touch event into {@link KeyboardView}.
 *
 * @param touchAction The action of the synthesizing touch event.
 * @param key The key that a synthesized touch event is on.
 *///from   w w w  . j  a  va2  s  .c  o m
private void simulateTouchEvent(final int touchAction, final Key key) {
    final int x = key.getHitBox().centerX();
    final int y = key.getHitBox().centerY();
    final long eventTime = SystemClock.uptimeMillis();
    final MotionEvent touchEvent = MotionEvent.obtain(eventTime, eventTime, touchAction, x, y,
            0 /* metaState */);
    mKeyboardView.onTouchEvent(touchEvent);
    touchEvent.recycle();
}

From source file:jp.morihirosoft.twwb.TwwbService.java

private void blockScreen() {
    if (DEBUG)/* w w  w .j ava  2 s  . co m*/
        Log.d(TAG, "blockScreen");
    if (mBlockScreen == null) {
        if (mIsCalling) {
            return;
        }
        if (SystemClock.uptimeMillis() - mStartTime < mSettings.getPending() * 1000) {
            return;
        }
        mBlockScreen = LayoutInflater.from(this).inflate(R.layout.view_block, null);
        int alpha = 255 * mSettings.getAlpha() / 100;
        mBlockScreen.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
        ((ImageView) mBlockScreen.findViewById(R.id.img_logo)).setAlpha(alpha);
        ((Button) mBlockScreen.findViewById(R.id.btn_unblock)).setOnClickListener(this);

        WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.MATCH_PARENT;
        params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
        params.flags = 0;
        params.format = PixelFormat.TRANSLUCENT;

        WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
        wm.addView(mBlockScreen, params);
    }
}

From source file:com.android.gallery3d2.ingest.IngestService.java

@Override
public void onObjectIndexed(MtpObjectInfo object, int numVisited) {
    mNeedRelaunchNotification = false;/* w w  w. j a v a2s .co  m*/
    if (mClientActivity != null) {
        mClientActivity.onObjectIndexed(object, numVisited);
    } else {
        // Throttle the updates to one every PROGRESS_UPDATE_INTERVAL_MS milliseconds
        long currentTime = SystemClock.uptimeMillis();
        if (currentTime > mLastProgressIndexTime + PROGRESS_UPDATE_INTERVAL_MS) {
            mLastProgressIndexTime = currentTime;
            mNotificationBuilder.setProgress(0, numVisited, true)
                    .setContentText(getResources().getText(R.string.ingest_scanning));
            mNotificationManager.notify(NotificationIds.INGEST_NOTIFICATION_SCANNING,
                    mNotificationBuilder.build());
        }
    }
}

From source file:com.github.michalbednarski.intentslab.editor.IntentEditorActivity.java

@Override
protected void onDestroy() {
    // System is destroying activity for no apparent reason...
    // Since we haven't saved state nor called finish we'll restart ourselves
    // https://android.googlesource.com/platform/frameworks/base/+/f83c555d8a153662d067702c0df5761b5e71b1bf%5E%21/services/java/com/android/server/am/ActivityManagerService.java
    if (!mDestroyExpected && getCallingActivity() == null && // Not started for result
            sLastForceFinish + 3000 < SystemClock.uptimeMillis() // Last crash more than 3 s ago
    ) {/*w  ww .  j a  v a  2 s.  co m*/
        // Save crash time
        sLastForceFinish = SystemClock.uptimeMillis();

        // Restart activity
        updateIntent();
        Intent intent = new Intent(this, IntentEditorActivity.class);
        intent.putExtra(EXTRA_INTENT, mEditedIntent);
        intent.putExtra(EXTRA_COMPONENT_TYPE, mComponentType);
        intent.putExtra(EXTRA_METHOD_ID, mMethodId);
        intent.putExtra(EXTRA_INTENT_FILTERS, mAttachedIntentFilters);
        if (mLocalState != null) {
            Bundle extra = new Bundle(1);
            RunAsInitReceiver.putBinderInBundle(extra, EXTRA_LOCAL_STATE, mLocalState);
            intent.putExtras(extra);
        }

        startActivity(intent);
    }

    super.onDestroy();
}