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

@Override
public boolean updateProgress(long total, long current, boolean forceUpdateUI) {
    if (mStop) {/*  w w  w.  j  a  v  a2 s. co m*/
        return !mStop;
    }
    if (callback != null && callback.isProgress()) {
        if (forceUpdateUI) {
            publishProgress(UPDATE_LOADING, total, current);
        } else {
            long currTime = SystemClock.uptimeMillis();
            if (currTime - lastUpdateTime >= callback.getRate()) {
                lastUpdateTime = currTime;
                publishProgress(UPDATE_LOADING, total, current);
            }
        }
    }
    return !mStop;
}

From source file:com.tencent.wetest.fragment.LogPageFragment.java

public void updateLoglist() {

    try {//from   w  ww  . j  a va2s  .  c  o m

        new Thread(new Runnable() {

            public void run() {
                try {

                    items = ReportUtil.readReportList();
                    //applist = ReportUtil.readReportAppnameList(mUin);

                    Calendar cal = Calendar.getInstance();
                    cal.add(Calendar.DATE, -1);
                    Date lastday = cal.getTime();

                    Date today = new Date();

                    if (((WTApplication) WTApplication.getContext()).getReport().getBaseTime() != -1) {

                        today = new Date(((WTApplication) WTApplication.getContext()).getReport().getBaseTime()
                                + SystemClock.uptimeMillis()
                                - ((WTApplication) WTApplication.getContext()).getReport().getBaseColock());

                    }

                    SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd");

                    groups = new ArrayList<LogGroup>();
                    LogGroup logGroup_today = new LogGroup();
                    logGroup_today.setGroupName(getResources().getString(R.string.today));
                    LogGroup logGroup_lastday = new LogGroup();
                    logGroup_lastday.setGroupName(getResources().getString(R.string.yesterday));
                    LogGroup logGroup_other = new LogGroup();
                    logGroup_other.setGroupName(getResources().getString(R.string.otherday));

                    logitems_today = new ArrayList<LogItem>();
                    logitems_lastday = new ArrayList<LogItem>();
                    logitems_other = new ArrayList<LogItem>();

                    if (items != null) {

                        for (HashMap<String, Object> item : items) {

                            LogItem temp = new LogItem();
                            temp.setImg((Drawable) item.get("icon"));
                            temp.setTime(((CharSequence) item.get("appName")).toString());
                            temp.setFilename((String) item.get("filename"));
                            temp.setAppname((String) item.get("packageName"));

                            if (temp.getTime().split(" ")[0].equals(sp.format(today)))
                                logitems_today.add(temp);
                            else if (temp.getTime().split(" ")[0].equals(sp.format(lastday)))
                                logitems_lastday.add(temp);
                            else
                                logitems_other.add(temp);
                        }

                    }

                    Collections.reverse(logitems_today);
                    logGroup_today.setGroupChild(logitems_today);
                    groups.add(logGroup_today);

                    Collections.reverse(logitems_lastday);
                    logGroup_lastday.setGroupChild(logitems_lastday);
                    groups.add(logGroup_lastday);

                    Collections.reverse(logitems_other);
                    logGroup_other.setGroupChild(logitems_other);
                    groups.add(logGroup_other);

                    loadMoreLogList();

                } catch (Exception e) {

                    Logger.error("read logexception" + e.toString());

                    String cmd = "logcat -d -v time > /data/data/com.tencent.wefpmonitor/files/crash.log";
                    SuUtil.executeCommand(1, cmd);

                    e.printStackTrace();
                }

            }
        }).start();

    } catch (Exception e) {

        e.printStackTrace();
    }

}

From source file:com.android.tv.settings.about.AboutFragment.java

@Override
public boolean onPreferenceTreeClick(Preference preference) {
    switch (preference.getKey()) {
    case KEY_FIRMWARE_VERSION:
        System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
        mHits[mHits.length - 1] = SystemClock.uptimeMillis();
        if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
            if (mUm.hasUserRestriction(UserManager.DISALLOW_FUN)) {
                Log.d(TAG, "Sorry, no fun for you!");
                return false;
            }/*  www. ja v a 2 s . co  m*/

            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClassName("android", com.android.internal.app.PlatLogoActivity.class.getName());
            try {
                startActivity(intent);
            } catch (Exception e) {
                Log.e(TAG, "Unable to start activity " + intent.toString());
            }
        }
        break;
    case KEY_BUILD_NUMBER:
        // Don't enable developer options for secondary users.
        if (!mUm.isAdminUser())
            return true;

        if (mUm.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES))
            return true;

        if (mDevHitCountdown > 0) {
            mDevHitCountdown--;
            if (mDevHitCountdown == 0) {
                Settings.Global.putInt(getActivity().getContentResolver(),
                        Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
                if (mDevHitToast != null) {
                    mDevHitToast.cancel();
                }
                mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_on, Toast.LENGTH_LONG);
                mDevHitToast.show();
                // This is good time to index the Developer Options
                //                    Index.getInstance(
                //                            getActivity().getApplicationContext()).updateFromClassNameResource(
                //                            DevelopmentSettings.class.getName(), true, true);

            } else if (mDevHitCountdown > 0 && mDevHitCountdown < (TAPS_TO_BE_A_DEVELOPER - 2)) {
                if (mDevHitToast != null) {
                    mDevHitToast.cancel();
                }
                mDevHitToast = Toast.makeText(getActivity(), getResources().getQuantityString(
                        R.plurals.show_dev_countdown, mDevHitCountdown, mDevHitCountdown), Toast.LENGTH_SHORT);
                mDevHitToast.show();
            }
        } else if (mDevHitCountdown < 0) {
            if (mDevHitToast != null) {
                mDevHitToast.cancel();
            }
            mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_already, Toast.LENGTH_LONG);
            mDevHitToast.show();
        }
        break;
    case KEY_DEVICE_FEEDBACK:
        sendFeedback();
        break;
    case KEY_SYSTEM_UPDATE_SETTINGS:
        CarrierConfigManager configManager = (CarrierConfigManager) getActivity()
                .getSystemService(Context.CARRIER_CONFIG_SERVICE);
        PersistableBundle b = configManager.getConfig();
        if (b != null && b.getBoolean(CarrierConfigManager.KEY_CI_ACTION_ON_SYS_UPDATE_BOOL)) {
            ciActionOnSysUpdate(b);
        }
        break;
    }
    return super.onPreferenceTreeClick(preference);
}

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

private void handleResponse(HttpResponse response) {
    StatusLine status = response.getStatusLine();
    if (status.getStatusCode() >= 300) {
        String errorMsg = "response status error code:" + status.getStatusCode();
        if (status.getStatusCode() == 416 && isResume) {
            errorMsg += " \n maybe you have download complete.";
        }/*from ww  w  .  jav a  2s .  c  o m*/
        publishProgress(UPDATE_FAILURE,
                new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()),
                status.getStatusCode(), errorMsg);
    } else {
        try {
            HttpEntity entity = response.getEntity();
            Object responseBody = null;
            if (entity != null) {
                time = SystemClock.uptimeMillis();
                if (targetUrl != null) {
                    responseBody = mFileEntityHandler.handleEntity(entity, getDownloadProgressListener(),
                            config.savePath, isResume);
                }
            }
            publishProgress(UPDATE_SUCCESS, responseBody);
        } catch (Exception e) {
            publishProgress(UPDATE_FAILURE, e, 0, e.getMessage());
        }

    }
}

From source file:com.video.search.recyclerview.adapter.helper.ViewAnimator.java

/**
 * Returns the delay in milliseconds after which animation for View with position mLastAnimatedPosition + 1 should start.
 *//*  w  w w  . j a  v a2 s  . c  o  m*/
@SuppressLint("NewApi")
private int calculateAnimationDelay(final int position) {
    int delay;

    int lastVisiblePosition = ((LinearLayoutManager) mRecyclerView.getLayoutManager())
            .findLastCompletelyVisibleItemPosition();
    int firstVisiblePosition = ((LinearLayoutManager) mRecyclerView.getLayoutManager())
            .findFirstCompletelyVisibleItemPosition();

    if (mLastAnimatedPosition > lastVisiblePosition)
        lastVisiblePosition = mLastAnimatedPosition;

    int numberOfItemsOnScreen = lastVisiblePosition - firstVisiblePosition;
    int numberOfAnimatedItems = position - 1 - mFirstAnimatedPosition;

    if (numberOfItemsOnScreen + 1 < numberOfAnimatedItems) {
        delay = mAnimationDelayMillis;

        if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) {
            int numColumns = ((GridLayoutManager) mRecyclerView.getLayoutManager()).getSpanCount();
            delay += mAnimationDelayMillis * (position % numColumns);
            //Log.d("GAB", "Delay[" + position + "]=*"+lastVisiblePosition+"|"+firstVisiblePosition+"|");
        }
    } else {
        int delaySinceStart = (position - mFirstAnimatedPosition) * mAnimationDelayMillis;
        delay = Math.max(0, (int) (-SystemClock.uptimeMillis() + mAnimationStartMillis + mInitialDelayMillis
                + delaySinceStart));
    }
    //Log.d("GAB", "Delay[" + position + "]=" + delay+"|"+lastVisiblePosition+"|"+firstVisiblePosition+"|");
    return delay;
}

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

/**
 * Returns the delay in milliseconds after which animation for View with position mLastAnimatedPosition + 1 should start.
 *//*from w w w . j  a va2  s  .c o  m*/
@SuppressLint("NewApi")
private int calculateAnimationDelay(final int position) {
    int delay;

    int lastVisiblePosition = ((LinearLayoutManager) mRecyclerView.getLayoutManager())
            .findLastCompletelyVisibleItemPosition();
    int firstVisiblePosition = ((LinearLayoutManager) mRecyclerView.getLayoutManager())
            .findFirstCompletelyVisibleItemPosition();

    if (mLastAnimatedPosition > lastVisiblePosition)
        lastVisiblePosition = mLastAnimatedPosition;

    int numberOfItemsOnScreen = lastVisiblePosition - firstVisiblePosition;
    int numberOfAnimatedItems = position - 1 - mFirstAnimatedPosition;

    if (numberOfItemsOnScreen + 1 < numberOfAnimatedItems) {
        delay = mAnimationDelayMillis;

        if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) {
            int numColumns = ((GridLayoutManager) mRecyclerView.getLayoutManager()).getSpanCount();
            delay += mAnimationDelayMillis * (position % numColumns);
            Log.d("GAB", "Delay[" + position + "]=*" + lastVisiblePosition + "|" + firstVisiblePosition + "|");
        }
    } else {
        int delaySinceStart = (position - mFirstAnimatedPosition) * mAnimationDelayMillis;
        delay = Math.max(0, (int) (-SystemClock.uptimeMillis() + mAnimationStartMillis + mInitialDelayMillis
                + delaySinceStart));
    }
    Log.d("GAB",
            "Delay[" + position + "]=" + delay + "|" + lastVisiblePosition + "|" + firstVisiblePosition + "|");
    return delay;
}

From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.AmharicKeyboardView.java

private void handleChild(View child, int columnCount, LinearLayout keyContainer, int keyHeight) {
    child.setBackgroundDrawable(ContextCompat.getDrawable(getContext(), R.drawable.amharic_key_bg));
    child.setOnTouchListener(new OnTouchListener() {
        @Override/*from www.j a v a  2 s.  co m*/
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if (shouldVibrate) {
                    Vibrator vb = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
                    if (vb != null) {
                        vb.vibrate(20);
                    }
                }
                mPressedKeyView = v;
                mHandler.removeCallbacks(mKeyPressRunnable);
                mHandler.postAtTime(mKeyPressRunnable, mPressedKeyView,
                        SystemClock.uptimeMillis() + INITIAL_INTERVAL);
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_OUTSIDE:
                mHandler.removeCallbacksAndMessages(mPressedKeyView);
                mPressedKeyView = null;
                mNormalInterval = 100;
                break;
            }
            return false;
        }
    });
    child.setOnClickListener(mKeyClickListener);
    int margin = getCustomSize(1.5f);
    int tempKeyHeight = keyHeight - (margin * 2);
    LayoutParams params = new LayoutParams(0, tempKeyHeight, columnCount);
    params.setMargins(margin, margin, margin, margin);
    keyContainer.addView(child, params);
}

From source file:com.microsoft.office.integration.test.AbstractTest.java

public boolean waitForDialogToClose(long timeout) {
    final long endTime = SystemClock.uptimeMillis() + timeout;

    while (SystemClock.uptimeMillis() < endTime) {
        if (!isDialogOpen()) {
            return true;
        }//ww w  .j  a  v  a 2  s  .c  o  m
        try {
            Thread.sleep(SMALL_DELAY);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return false;
}

From source file:app.hanks.com.conquer.activity.MainActivity.java

/**
 * /*from  w w  w.ja  va 2s .c om*/
 */
@Override
public void onBackPressed() {
    System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
    mHits[mHits.length - 1] = SystemClock.uptimeMillis();
    if (mHits[0] >= SystemClock.uptimeMillis() - 1500) {
        this.finish();
        return;
    }
    T.show(this, getString(R.string.two_exit));
}

From source file:com.dwdesign.tweetings.fragment.DirectMessagesFragment.java

@Override
public void onStart() {
    super.onStart();
    mTickerStopped = false;/*  ww  w.j a  v  a  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();
    filter.addAction(BROADCAST_ACCOUNT_LIST_DATABASE_UPDATED);
    filter.addAction(BROADCAST_RECEIVED_DIRECT_MESSAGES_DATABASE_UPDATED);
    filter.addAction(BROADCAST_SENT_DIRECT_MESSAGES_DATABASE_UPDATED);
    filter.addAction(BROADCAST_REFRESHSTATE_CHANGED);
    filter.addAction(BROADCAST_RECEIVED_DIRECT_MESSAGES_REFRESHED);
    filter.addAction(BROADCAST_SENT_DIRECT_MESSAGES_REFRESHED);
    registerReceiver(mStatusReceiver, filter);
    if (mService.isReceivedDirectMessagesRefreshing() || mService.isSentDirectMessagesRefreshing()) {
        setRefreshing(false);
    } else {
        onRefreshComplete();
    }
}