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.anysoftkeyboard.AnySoftKeyboard.java

private void setSpaceTimeStamp(boolean isSpace) {
    if (isSpace) {
        mLastSpaceTimeStamp = SystemClock.uptimeMillis();
    } else {//from   w  w w . j av a2  s.  c  o  m
        mLastSpaceTimeStamp = NEVER_TIME_STAMP;
    }
}

From source file:com.chenglong.muscle.ui.LazyViewPager.java

/**
 * Fake drag by an offset in pixels. You must have called
 * {@link #beginFakeDrag()} first.//  w  w  w  .  jav a  2s.com
 *
 * @param xOffset Offset in pixels to drag by.
 * @see #beginFakeDrag()
 * @see #endFakeDrag()
 */
public void fakeDragBy(float xOffset) {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }
    mLastMotionX += xOffset;
    float scrollX = getScrollX() - xOffset;
    final int width = getWidth();
    final int widthWithMargin = width + mPageMargin;
    final float leftBound = Math.max(0, (mCurItem - 1) * widthWithMargin);
    final float rightBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * widthWithMargin;
    if (scrollX < leftBound) {
        scrollX = leftBound;
    } else if (scrollX > rightBound) {
        scrollX = rightBound;
    }
    // Don't lose the rounded component
    mLastMotionX += scrollX - (int) scrollX;
    scrollTo((int) scrollX, getScrollY());
    pageScrolled((int) scrollX);
    // Synthesize an event for the VelocityTracker.
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX,
            0, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
}

From source file:org.mozilla.gecko.GeckoApp.java

/** Called when the activity is first created. */
@Override//from  w  ww . jav  a  2 s .  c o m
public void onCreate(Bundle savedInstanceState) {
    mAppContext = this;

    // StrictMode is set by defaults resource flag |enableStrictMode|.
    if (getResources().getBoolean(R.bool.enableStrictMode)) {
        enableStrictMode();
    }

    System.loadLibrary("mozglue");
    mMainHandler = new GeckoAppHandler();
    Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onCreate");
    if (savedInstanceState != null) {
        mLastTitle = savedInstanceState.getString(SAVED_STATE_TITLE);
        mLastViewport = savedInstanceState.getString(SAVED_STATE_VIEWPORT);
        mLastScreen = savedInstanceState.getByteArray(SAVED_STATE_SCREEN);
        mRestoreSession = savedInstanceState.getBoolean(SAVED_STATE_SESSION);
    }

    super.onCreate(savedInstanceState);

    mOrientation = getResources().getConfiguration().orientation;

    setContentView(R.layout.gecko_app);

    if (Build.VERSION.SDK_INT >= 11) {
        mBrowserToolbar = (BrowserToolbar) GeckoActionBar.getCustomView(this);
    } else {
        mBrowserToolbar = (BrowserToolbar) findViewById(R.id.browser_toolbar);
    }

    // setup gecko layout
    mGeckoLayout = (RelativeLayout) findViewById(R.id.gecko_layout);
    mMainLayout = (LinearLayout) findViewById(R.id.main_layout);

    mConnectivityFilter = new IntentFilter();
    mConnectivityFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    mConnectivityReceiver = new GeckoConnectivityReceiver();
}

From source file:org.vshgap.android.NotificationsController.java

public void processLoadedUnreadMessages(HashMap<Long, Integer> dialogs, ArrayList<TLRPC.Message> messages,
        ArrayList<TLRPC.User> users, ArrayList<TLRPC.Chat> chats,
        ArrayList<TLRPC.EncryptedChat> encryptedChats) {
    MessagesController.getInstance().putUsers(users, true);
    MessagesController.getInstance().putChats(chats, true);
    MessagesController.getInstance().putEncryptedChats(encryptedChats, true);

    pushDialogs.clear();//from  w  ww. j av  a  2  s  .  co m
    pushMessages.clear();
    pushMessagesDict.clear();
    total_unread_count = 0;
    personal_count = 0;
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications",
            Context.MODE_PRIVATE);
    HashMap<Long, Boolean> settingsCache = new HashMap<>();

    if (messages != null) {
        for (TLRPC.Message message : messages) {
            if (pushMessagesDict.containsKey(message.id)) {
                continue;
            }
            MessageObject messageObject = new MessageObject(message, null, false);
            if (isPersonalMessage(messageObject)) {
                personal_count++;
            }
            long dialog_id = messageObject.getDialogId();
            long original_dialog_id = dialog_id;
            if ((messageObject.messageOwner.flags & TLRPC.MESSAGE_FLAG_MENTION) != 0) {
                dialog_id = messageObject.messageOwner.from_id;
            }
            Boolean value = settingsCache.get(dialog_id);
            if (value == null) {
                int notifyOverride = getNotifyOverride(preferences, dialog_id);
                value = !(notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true)
                        || ((int) dialog_id < 0) && !preferences.getBoolean("EnableGroup", true))
                        && notifyOverride == 0);
                settingsCache.put(dialog_id, value);
            }
            if (!value || dialog_id == openned_dialog_id && ApplicationLoader.isScreenOn) {
                continue;
            }
            pushMessagesDict.put(messageObject.getId(), messageObject);
            pushMessages.add(0, messageObject);
            if (original_dialog_id != dialog_id) {
                pushDialogsOverrideMention.put(original_dialog_id, 1);
            }
        }
    }
    for (HashMap.Entry<Long, Integer> entry : dialogs.entrySet()) {
        long dialog_id = entry.getKey();
        Boolean value = settingsCache.get(dialog_id);
        if (value == null) {
            int notifyOverride = getNotifyOverride(preferences, dialog_id);
            Integer override = pushDialogsOverrideMention.get(dialog_id);
            if (override != null && override == 1) {
                pushDialogsOverrideMention.put(dialog_id, 0);
                notifyOverride = 1;
            }
            value = !(notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true)
                    || ((int) dialog_id < 0) && !preferences.getBoolean("EnableGroup", true))
                    && notifyOverride == 0);
            settingsCache.put(dialog_id, value);
        }
        if (!value) {
            continue;
        }
        int count = entry.getValue();
        pushDialogs.put(dialog_id, count);
        total_unread_count += count;
    }
    if (total_unread_count == 0) {
        popupMessages.clear();
        NotificationCenter.getInstance().postNotificationName(NotificationCenter.pushMessagesUpdated);
    }
    showOrUpdateNotification(SystemClock.uptimeMillis() / 1000 < 60);

    if (preferences.getBoolean("badgeNumber", true)) {
        setBadge(ApplicationLoader.applicationContext, total_unread_count);
    }
}

From source file:beichen.douban.ui.view.LazyViewPager.java

/**
 * Fake drag by an offset in pixels. You must have called
 * {@link #beginFakeDrag()} first./*from  w w w . ja va 2s. co  m*/
 * 
 * @param xOffset
 *            Offset in pixels to drag by.
 * @see #beginFakeDrag()
 * @see #endFakeDrag()
 */
public void fakeDragBy(float xOffset) {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }

    mLastMotionX += xOffset;
    float scrollX = getScrollX() - xOffset;
    final int width = getWidth();
    final int widthWithMargin = width + mPageMargin;

    final float leftBound = Math.max(0, (mCurItem - 1) * widthWithMargin);
    final float rightBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * widthWithMargin;
    if (scrollX < leftBound) {
        scrollX = leftBound;
    } else if (scrollX > rightBound) {
        scrollX = rightBound;
    }
    // Don't lose the rounded component
    mLastMotionX += scrollX - (int) scrollX;
    scrollTo((int) scrollX, getScrollY());
    pageScrolled((int) scrollX);

    // Synthesize an event for the VelocityTracker.
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX,
            0, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
}

From source file:org.immopoly.android.widget.ViewPager.java

/**
 * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first.
 *
 * @param xOffset Offset in pixels to drag by.
 * @see #beginFakeDrag()/*  ww w .j  a va2  s  .  c om*/
 * @see #endFakeDrag()
 */
public void fakeDragBy(float xOffset) {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }

    mLastMotionX += xOffset;
    float scrollX = getScrollX() - xOffset;
    final int width = forcedChildWidth > 0 ? forcedChildWidth : getWidth();
    final int widthWithMargin = width + mPageMargin;

    final float leftBound = Math.max(0, (mCurItem - 1) * widthWithMargin);
    final float rightBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * widthWithMargin;
    if (scrollX < leftBound) {
        scrollX = leftBound;
    } else if (scrollX > rightBound) {
        scrollX = rightBound;
    }
    // Don't lose the rounded component
    mLastMotionX += scrollX - (int) scrollX;
    scrollTo((int) scrollX, getScrollY());
    pageScrolled((int) scrollX);

    // Synthesize an event for the VelocityTracker.
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX,
            0, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
}

From source file:org.catrobat.catroid.uitest.util.UiTestUtils.java

public static void longClickAndDrag(final Solo solo, final float xFrom, final float yFrom, final float xTo,
        final float yTo, final int steps) {
    final Activity activity = solo.getCurrentActivity();
    Handler handler = new Handler(activity.getMainLooper());

    handler.post(new Runnable() {

        public void run() {
            MotionEvent downEvent = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
                    MotionEvent.ACTION_DOWN, xFrom, yFrom, 0);
            activity.dispatchTouchEvent(downEvent);
            downEvent.recycle();/*from   www. j ava2  s  . c om*/
        }
    });

    solo.sleep(ViewConfiguration.getLongPressTimeout() + 200);

    handler.post(new Runnable() {
        public void run() {
            double offsetX = xTo - xFrom;
            offsetX /= steps;
            double offsetY = yTo - yFrom;
            offsetY /= steps;
            for (int i = 0; i <= steps; i++) {
                float x = xFrom + (float) (offsetX * i);
                float y = yFrom + (float) (offsetY * i);
                MotionEvent moveEvent = MotionEvent.obtain(SystemClock.uptimeMillis(),
                        SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE, x, y, 0);
                activity.dispatchTouchEvent(moveEvent);

                solo.sleep(20);
                moveEvent.recycle();
            }
        }
    });

    solo.sleep(steps * 20 + 200);

    handler.post(new Runnable() {

        public void run() {
            MotionEvent upEvent = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
                    MotionEvent.ACTION_UP, xTo, yTo, 0);
            activity.dispatchTouchEvent(upEvent);
            upEvent.recycle();
            Log.d(TAG, "longClickAndDrag finished: " + (int) yTo);
        }
    });

    solo.sleep(1000);
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

private void startRecording() {
    //      Camera camera = CameraController.getCamera();
    //      if (null == camera)
    //         return;

    filesList = new ArrayList<File>();
    documentFilesList = new ArrayList<DocumentFile>();

    fileSaved = null;/*from  w ww.  j  ava2  s  .c  o m*/
    documentFileSaved = null;

    if (shutterOff)
        return;

    stopRotateAnimation();

    if (!swChecked) {
        // RotateImageView additionalButton = (RotateImageView)
        // ApplicationScreen.instance.guiManager.getMainView().findViewById(R.id.buttonShutterAdditional);
        RotateImageView buttonSelectMode = (RotateImageView) ApplicationScreen.instance.guiManager.getMainView()
                .findViewById(R.id.buttonSelectMode);

        // additionalButton.setVisibility(View.VISIBLE);
        buttonSelectMode.setVisibility(View.GONE);
    }

    modeSwitcher.setVisibility(View.GONE);
    if (this.modeDRO()) {
        shutterOff = true;
        mRecordingStartTime = SystemClock.uptimeMillis();

        ApplicationScreen.getGUIManager().lockControls = true;
        // inform the user that recording has stopped
        isRecording = true;
        onPause = false;

        showRecordingUI(isRecording);
        PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext()).edit()
                .putBoolean("videorecording", true).commit();

        this.droEngine.startRecording(getOutputMediaFile().toString(), 300);

        new CountDownTimer(1000, 1000) {
            public void onTick(long millisUntilFinished) {
            }

            public void onFinish() {
                shutterOff = false;
                // ApplicationScreen.getGUIManager().lockControls = false;
            }
        }.start();
    } else {
        this.startVideoRecording();
    }

    View mainButtonsVideo = (View) ApplicationScreen.instance.guiManager.getMainView()
            .findViewById(R.id.mainButtonsVideo);
    mainButtonsVideo.setVisibility(View.VISIBLE);

    View mainButtons = (View) ApplicationScreen.instance.guiManager.getMainView()
            .findViewById(R.id.mainButtons);
    mainButtons.setVisibility(View.INVISIBLE);

    // change shutter icon
    pauseVideoButton.setVisibility(View.VISIBLE);
    pauseVideoButton.setImageDrawable(
            ApplicationScreen.getAppResources().getDrawable(R.drawable.plugin_capture_video_pause));

    ApplicationScreen.instance.setKeepScreenOn(true);
}

From source file:org.telegramsecureplus.android.NotificationsController.java

public void processLoadedUnreadMessages(HashMap<Long, Integer> dialogs, ArrayList<TLRPC.Message> messages,
        ArrayList<TLRPC.User> users, ArrayList<TLRPC.Chat> chats,
        ArrayList<TLRPC.EncryptedChat> encryptedChats) {
    MessagesController.getInstance().putUsers(users, true);
    MessagesController.getInstance().putChats(chats, true);
    MessagesController.getInstance().putEncryptedChats(encryptedChats, true);

    pushDialogs.clear();//from  www  .  jav  a 2 s  .c o  m
    pushMessages.clear();
    pushMessagesDict.clear();
    total_unread_count = 0;
    personal_count = 0;
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications",
            Context.MODE_PRIVATE);
    HashMap<Long, Boolean> settingsCache = new HashMap<>();

    if (messages != null) {
        for (TLRPC.Message message : messages) {
            if (pushMessagesDict.containsKey(message.id)) {
                continue;
            }
            MessageObject messageObject = new MessageObject(message, null, false);
            if (isPersonalMessage(messageObject)) {
                personal_count++;
            }
            long dialog_id = messageObject.getDialogId();
            long original_dialog_id = dialog_id;
            if ((messageObject.messageOwner.flags & TLRPC.MESSAGE_FLAG_MENTION) != 0) {
                dialog_id = messageObject.messageOwner.from_id;
            }
            Boolean value = settingsCache.get(dialog_id);
            if (value == null) {
                int notifyOverride = getNotifyOverride(preferences, dialog_id);
                value = !(notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true)
                        || ((int) dialog_id < 0) && !preferences.getBoolean("EnableGroup", true))
                        && notifyOverride == 0);
                settingsCache.put(dialog_id, value);
            }
            if (!value || dialog_id == openned_dialog_id && ApplicationLoader.isScreenOn) {
                continue;
            }
            pushMessagesDict.put(messageObject.getId(), messageObject);
            pushMessages.add(0, messageObject);
            if (original_dialog_id != dialog_id) {
                pushDialogsOverrideMention.put(original_dialog_id, 1);
            }
        }
    }
    for (HashMap.Entry<Long, Integer> entry : dialogs.entrySet()) {
        long dialog_id = entry.getKey();
        Boolean value = settingsCache.get(dialog_id);
        if (value == null) {
            int notifyOverride = getNotifyOverride(preferences, dialog_id);
            Integer override = pushDialogsOverrideMention.get(dialog_id);
            if (override != null && override == 1) {
                pushDialogsOverrideMention.put(dialog_id, 0);
                notifyOverride = 1;
            }
            value = !(notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true)
                    || ((int) dialog_id < 0) && !preferences.getBoolean("EnableGroup", true))
                    && notifyOverride == 0);
            settingsCache.put(dialog_id, value);
        }
        if (!value) {
            continue;
        }
        int count = entry.getValue();
        pushDialogs.put(dialog_id, count);
        total_unread_count += count;
    }
    if (total_unread_count == 0) {
        popupMessages.clear();
        NotificationCenter.getInstance().postNotificationName(NotificationCenter.pushMessagesUpdated);
    }
    showOrUpdateNotification(SystemClock.uptimeMillis() / 1000 < 60);

    if (preferences.getBoolean("badgeNumber", true)) {
        setBadge(total_unread_count);
    }
}

From source file:com.cardio3g.MainActivity.java

/**
 * Go through each of the Expansion APK files and open each as a zip file.
 * Calculate the CRC for each file and return false if any fail to match.
 *
 * @return true if XAPKZipFile is successful
 *//*from   w  ww  .  j a v a 2  s  .  c  o m*/
void validateXAPKZipFiles() {
    AsyncTask<Object, DownloadProgressInfo, Boolean> validationTask = new AsyncTask<Object, DownloadProgressInfo, Boolean>() {

        @Override
        protected void onPreExecute() {
            mDownloadViewGroup.setVisibility(View.VISIBLE);
            super.onPreExecute();
        }

        @Override
        protected Boolean doInBackground(Object... params) {
            for (XAPKFile xf : xAPKS) {
                String fileName = Helpers.getExpansionAPKFileName(MainActivity.this, xf.mIsMain,
                        xf.mFileVersion);
                if (!Helpers.doesFileExist(MainActivity.this, fileName, xf.mFileSize, false))
                    return false;
                fileName = Helpers.generateSaveFileName(MainActivity.this, fileName);
                ZipResourceFile zrf;
                byte[] buf = new byte[1024 * 256];
                try {
                    zrf = new ZipResourceFile(fileName);
                    ZipResourceFile.ZipEntryRO[] entries = zrf.getAllEntries();
                    /**
                     * First calculate the total compressed length
                     */
                    long totalCompressedLength = 0;
                    for (ZipResourceFile.ZipEntryRO entry : entries) {
                        totalCompressedLength += entry.mCompressedLength;
                    }
                    float averageVerifySpeed = 0;
                    long totalBytesRemaining = totalCompressedLength;
                    long timeRemaining;
                    /**
                     * Then calculate a CRC for every file in the Zip file,
                     * comparing it to what is stored in the Zip directory.
                     * Note that for compressed Zip files we must extract
                     * the contents to do this comparison.
                     */
                    for (ZipResourceFile.ZipEntryRO entry : entries) {
                        if (-1 != entry.mCRC32) {
                            long length = entry.mUncompressedLength;
                            CRC32 crc = new CRC32();
                            DataInputStream dis = null;
                            try {
                                dis = new DataInputStream(zrf.getInputStream(entry.mFileName));

                                long startTime = SystemClock.uptimeMillis();
                                while (length > 0) {
                                    int seek = (int) (length > buf.length ? buf.length : length);
                                    dis.readFully(buf, 0, seek);
                                    crc.update(buf, 0, seek);
                                    length -= seek;
                                    long currentTime = SystemClock.uptimeMillis();
                                    long timePassed = currentTime - startTime;
                                    if (timePassed > 0) {
                                        float currentSpeedSample = (float) seek / (float) timePassed;
                                        if (0 != averageVerifySpeed) {
                                            averageVerifySpeed = SMOOTHING_FACTOR * currentSpeedSample
                                                    + (1 - SMOOTHING_FACTOR) * averageVerifySpeed;
                                        } else {
                                            averageVerifySpeed = currentSpeedSample;
                                        }
                                        totalBytesRemaining -= seek;
                                        timeRemaining = (long) (totalBytesRemaining / averageVerifySpeed);
                                        this.publishProgress(new DownloadProgressInfo(totalCompressedLength,
                                                totalCompressedLength - totalBytesRemaining, timeRemaining,
                                                averageVerifySpeed));
                                    }
                                    startTime = currentTime;
                                    if (mCancelValidation)
                                        return true;
                                }
                                if (crc.getValue() != entry.mCRC32) {
                                    Log.e("EXPANSION ERROR",
                                            "CRC does not match for entry: " + entry.mFileName);
                                    Log.e("EXPANSION ERROR", "In file: " + entry.getZipFileName());
                                    return false;
                                }
                            } finally {
                                if (null != dis) {
                                    dis.close();
                                }
                            }
                        }
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    return false;
                }
            }
            return true;
        }

        @Override
        protected void onProgressUpdate(DownloadProgressInfo... values) {
            onDownloadProgress(values[0]);
            super.onProgressUpdate(values);
        }

        @Override
        protected void onPostExecute(Boolean result) {
            if (result) {
                mDownloadViewGroup.setVisibility(View.GONE);
            } else {
                mDownloadViewGroup.setVisibility(View.VISIBLE);
            }
            super.onPostExecute(result);
        }

    };
    validationTask.execute(new Object());
}