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:org.akop.crosswords.Storage.java

public long write(long folderId, long puzzleId, Crossword crossword) {
    long started = SystemClock.uptimeMillis();

    StorageHelper helper = getHelper();// w w  w  .j  av a  2  s .  c o  m
    SQLiteDatabase db = helper.getWritableDatabase();
    ContentValues cv;

    try {
        cv = new ContentValues();
        cv.put(Puzzle.CLASS, crossword.getClass().getName());
        cv.put(Puzzle.SOURCE_URL, crossword.getSourceUrl());
        cv.put(Puzzle.TITLE, crossword.getTitle());
        cv.put(Puzzle.AUTHOR, crossword.getAuthor());
        cv.put(Puzzle.COPYRIGHT, crossword.getCopyright());
        cv.put(Puzzle.HASH, crossword.getHash());
        cv.put(Puzzle.SOURCE_ID, crossword.getSourceId());
        cv.put(Puzzle.FOLDER_ID, folderId);
        cv.put(Puzzle.OBJECT, mGson.toJson(crossword));
        cv.put(Puzzle.OBJECT_VERSION, 1);
        cv.put(Puzzle.LAST_UPDATED, System.currentTimeMillis());

        Long millis = null;
        if (crossword.getDate() != null) {
            millis = crossword.getDate().getMillis();
        }
        cv.put(Puzzle.DATE, millis);

        if (puzzleId != ID_NOT_FOUND) {
            db.update(Puzzle.TABLE, cv, Puzzle._ID + " = " + puzzleId, null);
        } else {
            puzzleId = db.insert(Puzzle.TABLE, null, cv);
        }
    } finally {
        db.close();
    }

    Crosswords.logv("Wrote crossword %s (%dms)", crossword.getHash(), SystemClock.uptimeMillis() - started);

    Intent outgoing = new Intent(ACTION_PUZZLE_CHANGE);
    outgoing.putExtra(INTENT_PUZZLE_ID, puzzleId);
    outgoing.putExtra(INTENT_PUZZLE_URL, crossword.getSourceUrl());

    sendLocalBroadcast(outgoing);

    return puzzleId;
}

From source file:com.example.com.benasque2014.mercurio.PuntosInfoFragment.java

private void addPoint(LatLng point) {
    if (markers == null)
        markers = new ArrayList<Marker>();
    if (points == null)
        points = new ArrayList<LatLng>();
    MarkerOptions marker = new MarkerOptions().position(point).title("Parada " + markers.size() + 1);

    final Marker mMarker = mMap.addMarker(marker);

    //if (markers.size()==0)
    //   Toast.makeText(getActivity(), "Haga click en un punto para eliminarlo", Toast.LENGTH_SHORT).show();

    markers.add(mMarker);/*www  .j  ava 2s.  co  m*/

    //mPage.getData().putParcelableArrayList(PuntosInfoPage.PUNTOS_DATA_KEY, (ArrayList<? extends Parcelable>) points);
    //mPage.notifyDataChanged();

    // This causes the marker at Perth to bounce into position when it is clicked.
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    final long duration = 1500;

    final Interpolator interpolator = new BounceInterpolator();

    handler.post(new Runnable() {
        @Override
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0);
            mMarker.setAnchor(0.5f, 1.0f + 2 * t);

            if (t > 0.0) {
                // Post again 16ms later.
                handler.postDelayed(this, 16);
            }
        }
    });
    //TODO: si queremos aadir lineas entre los puntos
    //addLines();
}

From source file:com.nxt.zyl.data.volley.toolbox.BasicNetwork.java

/** Reads the contents of HttpEntity into a byte[]. */
private byte[] entityToBytes(ResponseDelivery delivery, Request<?> request, HttpEntity entity)
        throws IOException, ServerError {
    PoolingByteArrayOutputStream bytes = new PoolingByteArrayOutputStream(mPool,
            (int) entity.getContentLength());
    byte[] buffer = null;
    long time = SystemClock.uptimeMillis();
    try {/*ww  w . j  a  va  2  s. c o m*/
        InputStream in = entity.getContent();
        if (in == null) {
            throw new ServerError();
        }
        buffer = mPool.getBuf(1024);
        long length = entity.getContentLength();
        long current = 0;
        int count = -1;
        Response.LoadingListener listener = request.getLoadingListener();
        while ((count = in.read(buffer)) != -1) {
            bytes.write(buffer, 0, count);
            current += count;
            if (listener != null) {
                long thisTime = SystemClock.uptimeMillis();
                if (thisTime - time >= request.getRate()) {
                    time = thisTime;
                    delivery.postLoading(request, length == -1 ? current * 2 : length, current);
                }
            }
        }
        if (listener != null) {
            delivery.postLoading(request, length == -1 ? current : length, current);
        }
        return bytes.toByteArray();
    } finally {
        try {
            // Close the InputStream and release the resources by "consuming the content".
            entity.consumeContent();
        } catch (IOException e) {
            // This can happen if there was an exception above that left the entity in
            // an invalid state.
            VolleyLog.v("Error occured when calling consumingContent");
        }
        mPool.returnBuf(buffer);
        bytes.close();
    }
}

From source file:com.dongfang.net.http.HttpHandler.java

@Override
public boolean updateProgress(long total, long current, boolean forceUpdateUI) {
    if (callback != null && !mStopped) {
        if (forceUpdateUI) {
            this.publishProgress(UPDATE_LOADING, total, current);
        } else {/*w  w  w.j a  va  2  s .  c  o  m*/
            long currTime = SystemClock.uptimeMillis();
            if (currTime - lastUpdateTime >= callback.getRate()) {
                lastUpdateTime = currTime;
                this.publishProgress(UPDATE_LOADING, total, current);
            }
        }
    }
    return !mStopped;
}

From source file:org.akop.crosswords.fragment.CrosswordFragment.java

private void updateState() {
    if (mCrosswordView == null) {
        return;//w w w  . j ava  2  s . c  o  m
    }

    Crossword.State state = mCrosswordView.getState();
    state.setLastPlayed(DateTime.now());

    if (mPlayStartTime != 0) {
        long totalPlayTimeMillis = SystemClock.uptimeMillis() - mPlayStartTime;
        if (mLastState != null) {
            totalPlayTimeMillis += mLastState.getPlayTimeMillis();
        }

        state.setPlayTimeMillis(totalPlayTimeMillis);
        mPlayStartTime = 0;
    }

    mLastState = state;
}

From source file:com.malinskiy.superrecyclerview.SwipeDismissRecyclerViewTouchListener.java

private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.

    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalHeight = dismissView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(new AnimatorListenerAdapter() {
        @Override//from w ww. j av a2s  .c  o m
        public void onAnimationEnd(Animator animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
                // No active animations, process all pending dismisses.
                // Sort by descending position
                Collections.sort(mPendingDismisses);

                int[] dismissPositions = new int[mPendingDismisses.size()];
                for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                    dismissPositions[i] = mPendingDismisses.get(i).position;
                }
                mCallbacks.onDismiss(mRecyclerView, dismissPositions);

                // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
                // animation with a stale position
                mDownPosition = INVALID_POSITION;

                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    setAlpha(pendingDismiss.view, 1f);
                    setTranslationX(pendingDismiss.view, 0);
                    lp = pendingDismiss.view.getLayoutParams();
                    lp.height = originalHeight;
                    pendingDismiss.view.setLayoutParams(lp);
                }

                // Send a cancel event
                long time = SystemClock.uptimeMillis();
                MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
                mRecyclerView.dispatchTouchEvent(cancelEvent);

                mPendingDismisses.clear();
            }
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });

    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
}

From source file:com.laquysoft.droidconnl.Hunt.java

public void setStartTime() {
    finishTime = SystemClock.uptimeMillis() + 15000;
}

From source file:com.googlecode.talkingrssreader.talkingrss.ReaderHttp.java

public String getList(String list) throws ReaderException {
    String url = API_URL + list;
    ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("output", "xml"));
    //all=true/*from   w  w w .j a v  a2s  .  c  o  m*/
    long startTime = SystemClock.uptimeMillis();
    InputStream is = doGet(url, params);
    long readTime = SystemClock.uptimeMillis();
    String out = readAll(is);
    long now = SystemClock.uptimeMillis();
    if (Config.LOGD)
        Log.d(TAG, String.format("list fetch: request took %dms, transferred %dbytes in %dms",
                readTime - startTime, out.length(), now - readTime));
    return out;
}

From source file:com.laquysoft.droidconnl.Hunt.java

public int getSecondsLeft() {
    long t = SystemClock.uptimeMillis();

    return (int) Math.ceil((finishTime - t) / 1000.0);
}

From source file:org.mariotaku.gallery3d.app.ImageViewerGLActivity.java

private void startViewAction(final Intent intent) {
    if (intent == null) {
        finish();// ww  w.  jav a 2  s  .  com
        return;
    }
    final Bundle data = new Bundle();
    final DataManager dm = getDataManager();
    final Uri uri = intent.getData();
    final String contentType = getContentType(intent);
    if (contentType == null) {
        // Toast.makeText(this, R.string.no_such_item,
        // Toast.LENGTH_LONG).show();
        // finish();
        // return;
    }
    if (uri == null) {
        finish();
    } else {
        final Path itemPath = dm.findPathByUri(uri, contentType);
        data.putString(KEY_MEDIA_ITEM_PATH, itemPath.toString());
        mData = data;

        mPhotoView = new PhotoView(this);
        mPhotoView.setListener(this);
        mRootPane.addComponent(mPhotoView);

        mHandler = new SynchronizedHandler(getGLRoot()) {
            @Override
            public void handleMessage(final Message message) {
                switch (message.what) {
                case MSG_HIDE_BARS: {
                    hideBars();
                    break;
                }
                case MSG_REFRESH_BOTTOM_CONTROLS: {
                    break;
                }
                case MSG_ON_FULL_SCREEN_CHANGED: {
                    break;
                }
                case MSG_UPDATE_ACTION_BAR: {
                    updateBars();
                    break;
                }
                case MSG_WANT_BARS: {
                    wantBars();
                    break;
                }
                case MSG_UNFREEZE_GLROOT: {
                    getGLRoot().unfreeze();
                    break;
                }
                case MSG_UPDATE_DEFERRED: {
                    final long nextUpdate = mDeferUpdateUntil - SystemClock.uptimeMillis();
                    if (nextUpdate <= 0) {
                        updateUIForCurrentPhoto();
                    } else {
                        mHandler.sendEmptyMessageDelayed(MSG_UPDATE_DEFERRED, nextUpdate);
                    }
                    break;
                }
                case MSG_ON_CAMERA_CENTER: {
                    boolean stayedOnCamera = false;
                    stayedOnCamera = true;

                    if (stayedOnCamera) {
                        if (null == null) {
                            /*
                             * We got here by swiping from photo 1 to
                             * the placeholder, so make it be the thing
                             * that is in focus when the user presses
                             * back from the camera app
                             */
                        } else {
                            updateBars();
                            updateCurrentPhoto(mModel.getMediaItem());
                        }
                    }
                    break;
                }
                case MSG_ON_PICTURE_CENTER: {
                    break;
                }
                case MSG_REFRESH_IMAGE: {
                    final MediaItem photo = mCurrentPhoto;
                    mCurrentPhoto = null;
                    updateCurrentPhoto(photo);
                    break;
                }
                case MSG_UPDATE_PHOTO_UI: {
                    updateUIForCurrentPhoto();
                    break;
                }
                case MSG_UPDATE_SHARE_URI: {
                    if (mCurrentPhoto == message.obj) {
                        mCurrentPhoto.getContentUri();
                        createShareIntent(mCurrentPhoto);
                    }
                    break;
                }
                }
            }
        };

        // Get default media set by the URI
        final MediaItem mediaItem = getDataManager().getMediaItem(itemPath);
        mModel = new PhotoViewAdapter(this, mPhotoView, mediaItem);
        mPhotoView.setModel(mModel);
        updateCurrentPhoto(mediaItem);
    }
}