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.android.idtt.http.HttpHandler.java

private Object handleResponse(HttpResponse response) throws HttpException, IOException {
    if (response == null) {
        throw new HttpException("response is null");
    }//w  ww. j a v a  2  s.  c  o m
    StatusLine status = response.getStatusLine();
    int statusCode = status.getStatusCode();
    if (statusCode < 300) {
        HttpEntity entity = response.getEntity();
        Object responseBody = null;
        if (entity != null) {
            lastUpdateTime = SystemClock.uptimeMillis();
            if (isDownloadingFile) {
                String responseFileName = autoRename ? OtherUtils.getFileNameFromHttpResponse(response) : null;
                responseBody = mFileDownloadHandler.handleEntity(entity, this, fileSavePath, autoResume,
                        responseFileName);
            } else {

                // charset
                String responseCharset = OtherUtils.getCharsetFromHttpResponse(response);
                charset = TextUtils.isEmpty(responseCharset) ? charset : responseCharset;

                responseBody = mStringDownloadHandler.handleEntity(entity, this, charset);
                HttpUtils.sHttpGetCache.put(_getRequestUrl, (String) responseBody, expiry);
            }
        }
        return responseBody;
    } else if (statusCode == 301 || statusCode == 302) {
        if (downloadRedirectHandler == null) {
            downloadRedirectHandler = new DefaultDownloadRedirectHandler();
        }
        HttpRequestBase request = downloadRedirectHandler.getDirectRequest(response);
        if (request != null) {
            return this.sendRequest(request);
        }
    } else if (statusCode == 416) {
        throw new HttpException(statusCode, "maybe the file has downloaded completely");
    } else {
        throw new HttpException(statusCode, status.getReasonPhrase());
    }
    return null;
}

From source file:com.phonemetra.turbo.keyboard.accessibility.AccessibilityUtils.java

/**
 * Sends the specified text to the {@link AccessibilityManager} to be
 * spoken.// ww w. ja  v  a 2 s  .  c  o m
 *
 * @param view The source view.
 * @param text The text to speak.
 */
public void announceForAccessibility(final View view, final CharSequence text) {
    if (!mAccessibilityManager.isEnabled()) {
        return;
    }

    // The following is a hack to avoid using the heavy-weight TextToSpeech
    // class. Instead, we're just forcing a fake AccessibilityEvent into
    // the screen reader to make it speak.
    final AccessibilityEvent event = AccessibilityEvent.obtain();

    event.setPackageName(PACKAGE);
    event.setClassName(CLASS);
    event.setEventTime(SystemClock.uptimeMillis());
    event.setEnabled(true);
    event.getText().add(text);

    // Platforms starting at SDK version 16 (Build.VERSION_CODES.JELLY_BEAN) should use
    // announce events.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
    } else {
        event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    }

    final ViewParent viewParent = view.getParent();
    if ((viewParent == null) || !(viewParent instanceof ViewGroup)) {
        return;
    }

    viewParent.requestSendAccessibilityEvent(view, event);
}

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

void executePendingTask() {
    if (mCancellingTask == null && mTask != null) {
        if (mTask.waiting) {
            mTask.waiting = false;/*  w  w w.j a v  a  2 s. c  o  m*/
            mHandler.removeCallbacks(mTask);
        }
        if (mUpdateThrottle > 0) {
            long now = SystemClock.uptimeMillis();
            if (now < (mLastLoadCompleteTime + mUpdateThrottle)) {
                // Not yet time to do another load.
                if (DEBUG)
                    Log.v(TAG, "Waiting until " + (mLastLoadCompleteTime + mUpdateThrottle) + " to execute: "
                            + mTask);
                mTask.waiting = true;
                mHandler.postAtTime(mTask, mLastLoadCompleteTime + mUpdateThrottle);
                return;
            }
        }
        if (DEBUG)
            Log.v(TAG, "Executing: " + mTask);
        mTask.executeOnExecutor(mExecutor, (Void[]) null);
    }
}

From source file:com.kentdisplays.synccardboarddemo.Page.java

/**
 * Encapsulates the OpenGL ES instructions for drawing this page.
 *
 * @param perspective/*  w w w.j  a  v a 2  s.  c om*/
 * @param view
 */
public void draw(float[] perspective, float[] view) {
    mPositionParam = GLES20.glGetAttribLocation(mGlProgram, "a_Position");
    mNormalParam = GLES20.glGetAttribLocation(mGlProgram, "a_Normal");
    mColorParam = GLES20.glGetAttribLocation(mGlProgram, "a_Color");
    mModelViewProjectionParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVP");
    mIsFloorParam = GLES20.glGetUniformLocation(mGlProgram, "u_IsFloor");
    mModelParam = GLES20.glGetUniformLocation(mGlProgram, "u_Model");
    mModelViewParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVMatrix");

    // This is not the floor!
    GLES20.glUniform1f(mIsFloorParam, 0f);

    // Set the Model in the shader, used to calculate lighting
    GLES20.glUniformMatrix4fv(mModelParam, 1, false, mModel, 0);

    // Build the ModelView and ModelViewProjection matrices
    // for calculating cube position and light.
    float[] modelView = new float[16];
    float[] modelViewProjection = new float[16];
    Matrix.multiplyMM(modelView, 0, view, 0, mModel, 0);
    Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0);

    // Set the ModelView in the shader, used to calculate lighting
    GLES20.glUniformMatrix4fv(mModelViewParam, 1, false, modelView, 0);

    // Set the position of the cube
    GLES20.glVertexAttribPointer(mPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mPageVertices);

    // Set the ModelViewProjection matrix in the shader.
    GLES20.glUniformMatrix4fv(mModelViewProjectionParam, 1, false, modelViewProjection, 0);

    // Set the normal positions of the cube, again for shading
    GLES20.glVertexAttribPointer(mNormalParam, 3, GLES20.GL_FLOAT, false, 0, mPageNormals);

    GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false, 0, mPageColors);

    // Animate over all the paths every 30 seconds.
    long time = SystemClock.uptimeMillis() % 30000L;
    int numberOfPathsToDraw = Math.round(mNumberOfPaths / 30000.0f * time);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, numberOfPathsToDraw * 6);
}

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

/**
 * Sends the specified text to the {@link AccessibilityManager} to be
 * spoken.//from   w ww  .java  2 s  .co m
 *
 * @param view The source view.
 * @param text The text to speak.
 */
public void announceForAccessibility(final View view, final CharSequence text) {
    if (!mAccessibilityManager.isEnabled()) {
        Log.e(TAG, "Attempted to speak when accessibility was disabled!");
        return;
    }

    // The following is a hack to avoid using the heavy-weight TextToSpeech
    // class. Instead, we're just forcing a fake AccessibilityEvent into
    // the screen reader to make it speak.
    final AccessibilityEvent event = AccessibilityEvent.obtain();

    event.setPackageName(PACKAGE);
    event.setClassName(CLASS);
    event.setEventTime(SystemClock.uptimeMillis());
    event.setEnabled(true);
    event.getText().add(text);

    // Platforms starting at SDK version 16 (Build.VERSION_CODES.JELLY_BEAN) should use
    // announce events.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
    } else {
        event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    }

    final ViewParent viewParent = view.getParent();
    if ((viewParent == null) || !(viewParent instanceof ViewGroup)) {
        Log.e(TAG, "Failed to obtain ViewParent in announceForAccessibility");
        return;
    }

    viewParent.requestSendAccessibilityEvent(view, event);
}

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

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

    Crossword.State state = mStateCache.get((int) puzzleId);
    if (state == null) {
        StorageHelper helper = getHelper();
        SQLiteDatabase db = helper.getReadableDatabase();

        try {/*from www . ja va  2s  .  c  om*/
            Cursor cursor = db.query(PuzzleState.TABLE, new String[] { PuzzleState.CLASS, PuzzleState.OBJECT, },
                    PuzzleState.PUZZLE_ID + "=" + puzzleId, null, null, null, null);

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

    if (state != null) {
        Crosswords.logv("Loaded state for %d (%dms)", puzzleId, SystemClock.uptimeMillis() - started);
    }

    return state;
}

From source file:ac.robinson.mediaphone.MediaPhoneActivity.java

@Override
protected void onResume() {
    super.onResume();
    mResumeTime = SystemClock.uptimeMillis();
    if (MediaPhone.DEBUG) {
        ViewServer.get(this).setFocusedWindow(this);
    }/*from   ww  w . ja  v a  2s. c o m*/
    ((MediaPhoneApplication) getApplication()).registerActivityHandle(this);
}

From source file:org.openqa.selendroid.server.model.AndroidWebElement.java

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

    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();
    Activity current = ServerInstrumentation.getInstance().getCurrentActivity();
    EventSender.sendMotion(events, webview, current);

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

From source file:com.dalingge.gankio.common.widgets.recyclerview.anim.adapter.helper.ViewAnimator.java

/**
 * Animates given View.//from   www .ja  v a2 s  .c  om
 *
 * @param view the View that should be animated.
 */
private void animateView(final int position, @NonNull final View view, @NonNull final Animator[] animators) {
    if (mAnimationStartMillis == -1) {
        mAnimationStartMillis = SystemClock.uptimeMillis();
    }

    ViewCompat.setAlpha(view, 0);

    AnimatorSet set = new AnimatorSet();
    set.playTogether(animators);
    set.setStartDelay(calculateAnimationDelay(position));
    set.setDuration(mAnimationDurationMillis);
    set.start();

    mAnimators.put(view.hashCode(), set);
}

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

void dispatchOnCancelled(LoadTask task, D data) {
    onCanceled(data);/*from   w  w  w  .ja  v a2 s.  com*/
    if (mCancellingTask == task) {
        if (DEBUG)
            Log.v(TAG, "Cancelled task is now canceled!");
        mLastLoadCompleteTime = SystemClock.uptimeMillis();
        mCancellingTask = null;
        executePendingTask();
    }
}