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:cn.isif.util_plus.http.HttpHandler.java

@Override
protected Void doInBackground(Object... params) {
    if (this.state == State.CANCELLED || params == null || params.length == 0)
        return null;

    if (params.length > 3) {
        fileSavePath = String.valueOf(params[1]);
        isDownloadingFile = fileSavePath != null;
        autoResume = (Boolean) params[2];
        autoRename = (Boolean) params[3];
    }/*  w ww  .ja  va2  s. co  m*/

    try {
        if (this.state == State.CANCELLED)
            return null;
        // init request & requestUrl
        request = (HttpRequestBase) params[0];
        requestUrl = request.getURI().toString();
        if (callback != null) {
            callback.setRequestUrl(requestUrl);
        }

        this.publishProgress(UPDATE_START);

        lastUpdateTime = SystemClock.uptimeMillis();

        ResponseInfo<T> responseInfo = sendRequest(request);
        if (responseInfo != null) {
            this.publishProgress(UPDATE_SUCCESS, responseInfo);
            return null;
        }
    } catch (HttpException e) {
        this.publishProgress(UPDATE_FAILURE, e, e.getMessage());
    }

    return null;
}

From source file:org.adw.library.widgets.discreteseekbar.internal.drawable.AlmostRippleDrawable.java

public void animateToNormal() {
    unscheduleSelf(mUpdater);//from   www. j ava 2 s .c  o  m
    if (mCurrentScale > INACTIVE_SCALE) {
        mReverse = true;
        mRunning = true;
        mAnimationInitialValue = mCurrentScale;
        float durationFactor = 1f - ((mAnimationInitialValue - ACTIVE_SCALE) / (INACTIVE_SCALE - ACTIVE_SCALE));
        mDuration = (int) (ANIMATION_DURATION * durationFactor);
        mStartTime = SystemClock.uptimeMillis();
        scheduleSelf(mUpdater, mStartTime + FRAME_DURATION);
    }
}

From source file:com.louding.frame.http.download.SimpleDownloader.java

@Override
protected void onProgressUpdate(Object... values) {
    int update = Integer.valueOf(String.valueOf(values[0]));
    switch (update) {
    case UPDATE_START:
        if (callback != null) {
            callback.onPreStart();//from w  w w.  ja  va2s  .c  o m
        }
        break;
    case UPDATE_LOADING:
        if (callback != null && SystemClock.uptimeMillis() - time >= 1000) {
            time = SystemClock.uptimeMillis();
            callback.onLoading(Long.valueOf(String.valueOf(values[1])),
                    Long.valueOf(String.valueOf(values[2])));
        }
        break;
    case UPDATE_FAILURE:
        if (callback != null) {
            callback.onFailure((Throwable) values[1], (Integer) values[2], (String) values[3]);
        }
        break;
    case UPDATE_SUCCESS:
        if (callback != null) {
            callback.onSuccess((File) values[1]);
        }
        break;
    }
    super.onProgressUpdate(values);
}

From source file:com.drive.student.xutils.http.HttpHandler.java

@Override
protected Void doInBackground(Object... params) {
    if (this.state == State.CANCELLED || params == null || params.length == 0)
        return null;

    if (params.length > 3) {
        fileSavePath = String.valueOf(params[1]);
        isDownloadingFile = fileSavePath != null;
        autoResume = (Boolean) params[2];
        autoRename = (Boolean) params[3];
    }/*from   w w w  . jav a  2s . co m*/

    try {
        if (this.state == State.CANCELLED)
            return null;
        // init request & requestUrl
        request = (HttpRequestBase) params[0];
        requestUrl = request.getURI().toString();
        if (callback != null) {
            callback.setRequestUrl(requestUrl);
        }

        this.publishProgress(UPDATE_START);

        lastUpdateTime = SystemClock.uptimeMillis();

        com.drive.student.xutils.http.ResponseInfo<T> responseInfo = sendRequest(request);
        if (responseInfo != null) {
            this.publishProgress(UPDATE_SUCCESS, responseInfo);
            return null;
        }
    } catch (HttpException e) {
        this.publishProgress(UPDATE_FAILURE, e, e.getMessage());
    }

    return null;
}

From source file:pt.bappy.domsebastiao.activities.MapSearchActivity.java

@Override
public boolean onMarkerClick(final Marker marker) {

    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    final long duration = 1500;

    final Interpolator interpolator = new BounceInterpolator();

    handler.post(new Runnable() {
        @Override// w w w  .  ja v a 2s .  c o m
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0);
            marker.setAnchor(0.5f, 1.0f + 2 * t);

            if (t > 0.0) {
                // Post again 16ms later.
                handler.postDelayed(this, 16);
            }
        }
    });

    return false;
}

From source file:com.kohoh.AsyncTaskLoader.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 {//w w  w . j av a 2s . co  m
        if (isAbandoned()) {
            // This cursor has been abandoned; just cancel the new data.
            onCanceled(data);
        } else {
            commitContentChanged();
            mLastLoadCompleteTime = SystemClock.uptimeMillis();
            mTask = null;
            if (DEBUG)
                Log.v(TAG, "Delivering result");
            deliverResult(data);
        }
    }
}

From source file:com.near.chimerarevo.fragments.SettingsFragment.java

private void setAlarm(int sel, boolean isEnabled) {
    Intent intent = new Intent(getActivity().getApplicationContext(), NewsService.class);
    PendingIntent pintent = PendingIntent.getService(getActivity().getApplicationContext(), 0, intent, 0);
    AlarmManager alarm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);

    alarm.cancel(pintent);/*from   w w  w  . j a va  2s .c  om*/

    if (isEnabled) {
        long delay;
        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:org.mariotaku.twidere.activity.AccountSelectorActivity.java

@Override
public void onStart() {
    super.onStart();
    mTickerStopped = false;//from   w  ww  .j  ava 2 s.com
    mHandler = new Handler();

    mTicker = new Runnable() {

        @Override
        public void run() {
            if (mTickerStopped)
                return;
            if (mListView != null && !mBusy) {
                mAdapter.notifyDataSetChanged();
            }
            final long now = SystemClock.uptimeMillis();
            final long next = now + TICKER_DURATION - now % TICKER_DURATION;
            mHandler.postAtTime(mTicker, next);
        }
    };
    mTicker.run();

    final IntentFilter filter = new IntentFilter(BROADCAST_ACCOUNT_LIST_DATABASE_UPDATED);
    registerReceiver(mStateReceiver, filter);

}

From source file:org.akop.crosswords.Storage.java

public Crossword getPuzzle(long puzzleId) {
    long started = SystemClock.uptimeMillis();

    Crossword crossword = mPuzzleCache.get((int) puzzleId);
    if (crossword == null) {
        StorageHelper helper = getHelper();
        SQLiteDatabase db = helper.getReadableDatabase();

        try {//from www.j  av a  2 s  . c  o m
            Cursor cursor = db.query(Puzzle.TABLE, new String[] { Puzzle.CLASS, Puzzle.OBJECT, },
                    Puzzle._ID + " = " + puzzleId, null, null, null, null);

            if (cursor != null) {
                try {
                    if (cursor.moveToFirst()) {
                        crossword = mGson.fromJson(cursor.getString(1), Crossword.class);
                        mPuzzleCache.put((int) puzzleId, crossword);
                    }
                } finally {
                    cursor.close();
                }
            }
        } finally {
            db.close();
        }
    }

    if (crossword != null) {
        Crosswords.logv("Loaded crossword %s (%dms)", crossword.getHash(),
                SystemClock.uptimeMillis() - started);
    }

    return crossword;
}

From source file:android.support.v7.widget.ForwardingListener.java

private void onLongPress() {
    clearCallbacks();/*from  w  w w.  ja  v  a2 s. c  om*/

    final View src = mSrc;
    if (!src.isEnabled() || src.isLongClickable()) {
        // Ignore long-press if the view is disabled or has its own
        // handler.
        return;
    }

    if (!onForwardingStarted()) {
        return;
    }

    // Don't let the parent intercept our events.
    src.getParent().requestDisallowInterceptTouchEvent(true);

    // Make sure we cancel any ongoing source event stream.
    final long now = SystemClock.uptimeMillis();
    final MotionEvent e = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0, 0, 0);
    src.onTouchEvent(e);
    e.recycle();

    mForwarding = true;
}