Example usage for android.os SystemClock elapsedRealtime

List of usage examples for android.os SystemClock elapsedRealtime

Introduction

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

Prototype

@CriticalNative
native public static long elapsedRealtime();

Source Link

Document

Returns milliseconds since boot, including time spent in sleep.

Usage

From source file:cn.jmessage.android.uikit.pickerimage.view.BaseZoomableImageView.java

protected void center(boolean vertical, boolean horizontal, boolean animate) {
    if (mBitmap == null)
        return;/*from w  w  w .ja  va2 s .  co m*/

    Matrix m = getImageViewMatrix();

    float[] topLeft = new float[] { 0, 0 };
    float[] botRight = new float[] { mBitmap.getWidth(), mBitmap.getHeight() };

    translatePoint(m, topLeft);
    translatePoint(m, botRight);

    float height = botRight[1] - topLeft[1];
    float width = botRight[0] - topLeft[0];

    float deltaX = 0, deltaY = 0;

    if (vertical) {
        int viewHeight = getHeight();
        if (height < viewHeight) {
            deltaY = (viewHeight - height) / 2 - topLeft[1];
        } else if (topLeft[1] > 0) {
            deltaY = -topLeft[1];
        } else if (botRight[1] < viewHeight) {
            deltaY = getHeight() - botRight[1];
        }
    }

    if (horizontal) {
        int viewWidth = getWidth();
        if (width < viewWidth) {
            deltaX = (viewWidth - width) / 2 - topLeft[0];
        } else if (topLeft[0] > 0) {
            deltaX = -topLeft[0];
        } else if (botRight[0] < viewWidth) {
            deltaX = viewWidth - botRight[0];
        }
    }

    postTranslate(deltaX, deltaY);
    if (animate) {
        Animation a = new TranslateAnimation(-deltaX, 0, -deltaY, 0);
        a.setStartTime(SystemClock.elapsedRealtime());
        a.setDuration(250);
        setAnimation(a);
    }
    setImageMatrix(getImageViewMatrix());
}

From source file:com.chauthai.overscroll.BouncyAdapter.java

private void initTouchListener() {
    mRecyclerView.addOnItemTouchListener(new RecyclerView.SimpleOnItemTouchListener() {
        @Override/*w w w. ja va2  s.  c  o m*/
        public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
            switch (e.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mPrevTime = SystemClock.elapsedRealtime();
                mShouldUseSpring = false;

                mSpringScroller.stopScroll();
                mIsScrollBack = false;
                rv.stopScroll();
                break;

            case MotionEvent.ACTION_MOVE:
                break;

            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                onActionUp();
                break;
            }

            mGestureOnIntercept = true;
            mGestureDetector.onTouchEvent(e);

            // return true so that RecyclerView won't scroll when the user scroll.
            // We scroll it using scrollBy().
            return shouldInterceptTouch();
        }

        @Override
        public void onTouchEvent(RecyclerView rv, MotionEvent e) {
            mGestureOnIntercept = false;
            mGestureDetector.onTouchEvent(e);

            switch (e.getAction()) {
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                mGestureOnIntercept = true;
                onActionUp();
                break;
            }
        }
    });
}

From source file:com.sublimis.urgentcallfilter.Magic.java

private RingData calculateRingScore() {
    RingData retVal = new RingData();
    // we count this current ring as one
    retVal.mRingCount = 1;//w  ww .j  a  v a  2  s .c  o m

    long firstRingTimestamp = 0;
    long currentTime = SystemClock.elapsedRealtime();

    if (mData != null && mData.length() > 0) {
        for (int i = mData.length() - 1; i >= 0; i--) {
            if (retVal.mRingCount >= getUrgencyLevelRingCount()) {
                break;
            } else {
                JSONObject flame = jsonGetObject(mData, i);

                if (flame != null) {
                    String number = jsonGetString(flame, jsonNumberKey, null);
                    long timestamp = jsonGetLong(flame, jsonTimestampKey, 0);
                    long ringDuration = jsonGetLong(flame, jsonRingDurationKey, 0);

                    if (strEqual(number, mNumber)) {
                        if (firstRingTimestamp <= 0 || timestamp < firstRingTimestamp) {
                            firstRingTimestamp = timestamp;
                        }

                        retVal.mRingCount += 1;
                        retVal.mRingDurationCumulative += ringDuration;
                    }
                }
            }
        }

        retVal.mRingTimePeriod = currentTime - firstRingTimestamp;

        if (retVal.mRingTimePeriod > 0 && firstRingTimestamp > 0)
            retVal.mRingTimeRatio = (double) retVal.mRingDurationCumulative / retVal.mRingTimePeriod;
        else
            retVal.mRingTimeRatio = 0;
    }

    return retVal;
}

From source file:com.granita.tasks.notification.NotificationActionUtils.java

/**
 * Registers a timeout for the undo notification such that when it expires, the undo bar will disappear, and the action will be performed.
 *//*  w ww . j  a  v  a2 s  .  co  m*/
public static void registerUndoTimeout(final Context context, final NotificationAction notificationAction) {

    if (sUndoTimeoutMillis == -1) {
        sUndoTimeoutMillis = TIMEOUT_MILLIS;
    }

    final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final long triggerAtMills = SystemClock.elapsedRealtime() + sUndoTimeoutMillis;
    final PendingIntent pendingIntent = createUndoTimeoutPendingIntent(context, notificationAction);
    alarmManager.set(AlarmManager.ELAPSED_REALTIME, triggerAtMills, pendingIntent);
}

From source file:com.android.tv.settings.accessories.AddAccessoryActivity.java

@Override
protected void onStart() {
    super.onStart();

    if (DEBUG) {/*  w ww .  j  ava2s  . co  m*/
        Log.d(TAG, "onStart() mPairingInBackground = " + mPairingInBackground);
    }

    // Only do the following if we are not coming back to this activity from
    // the Secure Pairing activity.
    if (!mPairingInBackground) {
        if (mAnimateOnStart) {
            mAnimateOnStart = false;
            ViewGroup contentView = (ViewGroup) findViewById(android.R.id.content);
            mTopLayout = (FrameLayout) contentView.getChildAt(0);

            // Fade out the old activity, and fade in the new activity.
            overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

            // Set the activity background
            int bgColor = getResources().getColor(R.color.dialog_activity_background);
            getBackgroundDrawable().setColor(bgColor);
            mTopLayout.setBackground(getBackgroundDrawable());

            // Delay the rest of the changes until the first layout event
            mTopLayout.getViewTreeObserver()
                    .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                        @Override
                        public void onGlobalLayout() {
                            mTopLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);

                            // set the Action and Content fragments to their start offsets
                            mActionView = findViewById(R.id.action_fragment);
                            mContentView = findViewById(R.id.content_fragment);
                            if (mActionView != null) {
                                mViewOffset = mActionView.getMeasuredWidth();
                                int offset = (ViewCompat
                                        .getLayoutDirection(mActionView) == View.LAYOUT_DIRECTION_RTL)
                                                ? -mViewOffset
                                                : mViewOffset;
                                mActionView.setTranslationX(offset);
                                mContentView.setTranslationX(offset / 2);
                            }
                            mAutoPairText = (TextView) findViewById(R.id.autopair_message);
                            if (mAutoPairText != null) {
                                mAutoPairText.setVisibility(View.GONE);
                            }
                            updateView();
                        }
                    });
        }

        startBluetoothPairer();

        mStartTime = SystemClock.elapsedRealtime();
    }

    mPairingInBackground = false;
}

From source file:com.snda.mymarket.providers.downloads.DownloadNotifier.java

public void dumpSpeeds() {
    synchronized (mDownloadSpeed) {
        for (int i = 0; i < mDownloadSpeed.size(); i++) {
            final long id = mDownloadSpeed.keyAt(i);
            final long delta = SystemClock.elapsedRealtime() - mDownloadTouch.get(id);
            Log.d(Constants.TAG,//from  w w  w  .  j  ava2 s. c om
                    "Download " + id + " speed " + mDownloadSpeed.valueAt(i) + "bps, " + delta + "ms ago");
        }
    }
}

From source file:com.jio.appstore.download.DownloadNotifier.java

public void dumpSpeeds() {
    synchronized (mDownloadSpeed) {
        for (int i = 0; i < mDownloadSpeed.size(); i++) {
            final long id = mDownloadSpeed.keyAt(i);
            final long delta = SystemClock.elapsedRealtime() - mDownloadTouch.get(id);
            Log.d(TAG, "Download " + id + " speed " + mDownloadSpeed.valueAt(i) + "bps, " + delta + "ms ago");
        }/*from   www. jav  a 2  s .  c  o m*/
    }
}

From source file:com.facebook.stetho.inspector.network.NetworkEventReporterImpl.java

private static long stethoNow() {
    return SystemClock.elapsedRealtime();
}

From source file:com.android.providers.downloads.DownloadNotifier.java

public void dumpSpeeds() {
    synchronized (mDownloadSpeed) {
        for (int i = 0; i < mDownloadSpeed.size(); i++) {
            final long id = mDownloadSpeed.keySet().toArray(new Long[0])[i]; // FIXME TransferManager very inefficient
            final long delta = SystemClock.elapsedRealtime() - mDownloadTouch.get(id);
            Log.d(TAG, "Download " + id + " speed " + mDownloadSpeed.get(i) + "bps, " + delta + "ms ago");
        }/*from   w  ww .j  a v  a  2s  .  c o  m*/
    }
}