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:cc.echonet.coolmicapp.MainActivity.java

@SuppressWarnings("unused")
private void callbackHandler(int what) {
    Log.d("Handler", String.valueOf(what));

    final int what_final = what;
    MainActivity.this.runOnUiThread(new Runnable() {
        public void run() {
            switch (what_final) {
            case 1:
                timeInMilliseconds = 0L;
                timeSwapBuff = 0L;/*from   w  w  w  . j  ava2 s .  c o  m*/
                updatedTime = 0L;
                timeSwapBuff += timeInMilliseconds;
                customHandler.removeCallbacks(updateTimerThread);
                startTime = SystemClock.uptimeMillis();
                customHandler.postDelayed(updateTimerThread, 0);
                break;
            case 2:
                //code to stop timer starts here
                timeSwapBuff += timeInMilliseconds;
                customHandler.removeCallbacks(updateTimerThread);
                //code to stop timer starts here
                start_button.clearAnimation();
                start_button.setBackground(buttonColor);
                start_button.setText(R.string.start_broadcast);

                ClearLED();
                //logMessage("Stopping the broadcasting");
                break;
            case 3:
                //code to stop timer starts here
                timeSwapBuff += timeInMilliseconds;
                customHandler.removeCallbacks(updateTimerThread);
                //code to stop timer starts here
                start_button.clearAnimation();
                start_button.setBackground(buttonColor);
                start_button.setText(R.string.start_broadcast);

                ClearLED();

                isThreadOn = false;

                Toast.makeText(MainActivity.this, "there was an error!", Toast.LENGTH_LONG).show();

                break;
            }
        }
    });
}

From source file:com.oceansky.yellow.service.PlaybackService.java

/**
 * Starts playing the current playback queue
 *//*from   w w  w . ja  va 2s  .  c  om*/
private void startPlayingQueue() {
    // Check sleep timer
    if (mSleepTimerUptime > 0 && SystemClock.uptimeMillis() >= mSleepTimerUptime) {
        Log.d(TAG, "Stopping playback because of sleep timer");
        mSleepTimerUptime = -1;
        stopImpl();
        return;
    }

    if (mPlaybackQueue.size() > 0) {
        // mCurrentTrack in this context is the track that is going to be played
        if (mCurrentTrack < 0) {
            mCurrentTrack = 0;
        } else if (mCurrentTrack >= mPlaybackQueue.size()) {
            mCurrentTrack = mPlaybackQueue.size() - 1;
        }

        final Song next = mPlaybackQueue.get(mCurrentTrack);
        if (next == null) {
            // Song got unavailable, retry the next one
            boolean shouldFlush = mShouldFlushBuffers;
            nextImpl();

            // Keep the flush status
            mShouldFlushBuffers = shouldFlush;
            return;
        }

        final ProviderIdentifier providerId = next.getProvider();

        if (mCurrentPlayingProvider != null && !next.getProvider().equals(mCurrentPlayingProvider)) {
            // Pause the previously playing track to avoid overlap if it's not the same provider
            ProviderConnection prevConn = PluginsLookup.getDefault().getProvider(mCurrentPlayingProvider);
            if (prevConn != null) {
                IMusicProvider prevProv = prevConn.getBinder();
                if (prevProv != null) {
                    try {
                        prevProv.pause();
                    } catch (RemoteException e) {
                        Log.e(TAG, "Unable to pause previously playing provider", e);
                    }
                }
            }
            mCurrentPlayingProvider = null;
        }

        // Clear up the sink buffers if we were paused (otherwise we'll cut the end of the
        // previous song)
        if (mState == STATE_PAUSED || mState == STATE_PAUSING || mState == STATE_STOPPED) {
            mCommandsHandler.sendEmptyMessage(CommandHandler.MSG_FLUSH_BUFFERS);
        }

        if (providerId != null) {
            ProviderConnection connection = PluginsLookup.getDefault().getProvider(providerId);
            if (connection != null) {
                // Reset playbar status
                getSharedPreferences(SettingsKeys.PREF_SETTINGS, 0).edit()
                        .putBoolean(SettingsKeys.KEY_PLAYBAR_HIDDEN, false).apply();

                // Start playback
                IMusicProvider provider = connection.getBinder();
                if (provider != null) {
                    mState = STATE_BUFFERING;

                    for (IPlaybackCallback cb : mCallbacks) {
                        try {
                            cb.onSongStarted(true, next);
                        } catch (RemoteException e) {
                            Log.e(TAG, "Cannot call playback callback for song start event", e);
                        }
                    }

                    Log.d(TAG, "onSongStarted: Buffering...");

                    if (!next.isLoaded()) {
                        // Track not loaded yet, delay until track info arrived
                        mCurrentTrackWaitLoading = true;
                        mCurrentTrackLoaded = false;
                        Log.w(TAG, "Track not yet loaded: " + next.getRef() + ", delaying");
                    } else if (!next.isAvailable()) {
                        // Track is not available, skip to the next one
                        boolean shouldFlush = mShouldFlushBuffers;
                        nextImpl();

                        // Keep the flush status
                        mShouldFlushBuffers = shouldFlush;
                    } else {
                        mCurrentTrackWaitLoading = false;
                        mCurrentPlayingProvider = providerId;

                        requestAudioFocus();

                        try {
                            provider.playSong(next.getRef());
                        } catch (RemoteException e) {
                            Log.e(TAG, "Unable to play song", e);
                        } catch (NullPointerException e) {
                            Log.e(TAG, "No provider attached", e);
                        } catch (IllegalStateException e) {
                            Log.e(TAG, "Illegal State from provider", e);
                        }

                        mCurrentTrackLoaded = true;

                        mListenLogger.addEntry(next);

                        // The notification system takes care of calling startForeground
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                mNotification.setCurrentSong(next);
                            }
                        });

                        mRemoteMetadata.setCurrentSong(next, getNextTrack() != null);
                        mRemoteMetadata.notifyBuffering();
                    }
                }
            }
        } else {
            Log.e(TAG, "Cannot play the first song of the queue because the Song's "
                    + "ProviderIdentifier is null!");
        }
    }
}

From source file:com.a.mirko.android.datetimepicker.time.RadialPickerLayout.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    final float eventX = event.getX();
    final float eventY = event.getY();
    int degrees;//from   w w  w . j  av  a 2  s.  co  m
    int value;
    final Boolean[] isInnerCircle = new Boolean[1];
    isInnerCircle[0] = false;

    long millis = SystemClock.uptimeMillis();

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (!mInputEnabled) {
            return true;
        }

        mDownX = eventX;
        mDownY = eventY;

        mLastValueSelected = -1;
        mDoingMove = false;
        mDoingTouch = true;
        // If we're showing the AM/PM, check to see if the user is touching it.
        if (!mHideAmPm) {
            mIsTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
        } else {
            mIsTouchingAmOrPm = -1;
        }
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            // If the touch is on AM or PM, set it as "touched" after the TAP_TIMEOUT
            // in case the user moves their finger quickly.
            tryVibrate();
            mDownDegrees = -1;
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mAmPmCirclesView.setAmOrPmPressed(mIsTouchingAmOrPm);
                    mAmPmCirclesView.invalidate();
                }
            }, TAP_TIMEOUT);
        } else {
            // If we're in accessibility mode, force the touch to be legal. Otherwise,
            // it will only register within the given touch target zone.
            boolean forceLegal = AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager);
            // Calculate the degrees that is currently being touched.
            mDownDegrees = getDegreesFromCoords(eventX, eventY, forceLegal, isInnerCircle);
            if (mDownDegrees != -1) {
                // If it's a legal touch, set that number as "selected" after the
                // TAP_TIMEOUT in case the user moves their finger quickly.
                tryVibrate();
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mDoingMove = true;
                        int value = reselectSelector(mDownDegrees, isInnerCircle[0], false, true);
                        mLastValueSelected = value;
                        mListener.onValueSelected(getCurrentItemShowing(), value, false);
                    }
                }, TAP_TIMEOUT);
            }
        }
        return true;
    case MotionEvent.ACTION_MOVE:
        if (!mInputEnabled) {
            // We shouldn't be in this state, because input is disabled.
            Log.e(TAG, "Input was disabled, but received ACTION_MOVE.");
            return true;
        }

        float dY = Math.abs(eventY - mDownY);
        float dX = Math.abs(eventX - mDownX);

        if (!mDoingMove && dX <= TOUCH_SLOP && dY <= TOUCH_SLOP) {
            // Hasn't registered down yet, just slight, accidental movement of finger.
            break;
        }

        // If we're in the middle of touching down on AM or PM, check if we still are.
        // If so, no-op. If not, remove its pressed state. Either way, no need to check
        // for touches on the other circle.
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            mHandler.removeCallbacksAndMessages(null);
            int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
            if (isTouchingAmOrPm != mIsTouchingAmOrPm) {
                mAmPmCirclesView.setAmOrPmPressed(-1);
                mAmPmCirclesView.invalidate();
                mIsTouchingAmOrPm = -1;
            }
            break;
        }

        if (mDownDegrees == -1) {
            // Original down was illegal, so no movement will register.
            break;
        }

        // We're doing a move along the circle, so move the selection as appropriate.
        mDoingMove = true;
        mHandler.removeCallbacksAndMessages(null);
        degrees = getDegreesFromCoords(eventX, eventY, true, isInnerCircle);
        if (degrees != -1) {
            value = reselectSelector(degrees, isInnerCircle[0], false, true);
            if (value != mLastValueSelected) {
                tryVibrate();
                mLastValueSelected = value;
                mListener.onValueSelected(getCurrentItemShowing(), value, false);
            }
        }
        return true;
    case MotionEvent.ACTION_UP:
        if (!mInputEnabled) {
            // If our touch input was disabled, tell the listener to re-enable us.
            Log.d(TAG, "Input was disabled, but received ACTION_UP.");
            mListener.onValueSelected(ENABLE_PICKER_INDEX, 1, false);
            return true;
        }

        mHandler.removeCallbacksAndMessages(null);
        mDoingTouch = false;

        // If we're touching AM or PM, set it as selected, and tell the listener.
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
            mAmPmCirclesView.setAmOrPmPressed(-1);
            mAmPmCirclesView.invalidate();

            if (isTouchingAmOrPm == mIsTouchingAmOrPm) {
                mAmPmCirclesView.setAmOrPm(isTouchingAmOrPm);
                if (getIsCurrentlyAmOrPm() != isTouchingAmOrPm) {
                    mListener.onValueSelected(AMPM_INDEX, mIsTouchingAmOrPm, false);
                    setValueForItem(AMPM_INDEX, isTouchingAmOrPm);
                }
            }
            mIsTouchingAmOrPm = -1;
            break;
        }

        // If we have a legal degrees selected, set the value and tell the listener.
        if (mDownDegrees != -1) {
            degrees = getDegreesFromCoords(eventX, eventY, mDoingMove, isInnerCircle);
            if (degrees != -1) {
                value = reselectSelector(degrees, isInnerCircle[0], !mDoingMove, false);
                if (getCurrentItemShowing() == HOUR_INDEX && !mIs24HourMode) {
                    int amOrPm = getIsCurrentlyAmOrPm();
                    if (amOrPm == AM && value == 12) {
                        value = 0;
                    } else if (amOrPm == PM && value != 12) {
                        value += 12;
                    }
                }
                setValueForItem(getCurrentItemShowing(), value);
                mListener.onValueSelected(getCurrentItemShowing(), value, true);
            }
        }
        mDoingMove = false;
        return true;
    default:
        break;
    }
    return false;
}

From source file:com.fastbootmobile.encore.service.PlaybackService.java

/**
 * Starts playing the current playback queue
 *//*from ww  w  .  j a v  a 2 s .  c om*/
private void startPlayingQueue() {
    // Check sleep timer
    if (mSleepTimerUptime > 0 && SystemClock.uptimeMillis() >= mSleepTimerUptime) {
        Log.d(TAG, "Stopping playback because of sleep timer");
        mSleepTimerUptime = -1;
        stopImpl();
        return;
    }

    if (mPlaybackQueue.size() > 0) {
        // mCurrentTrack in this context is the track that is going to be played
        if (mCurrentTrack < 0) {
            mCurrentTrack = 0;
        }

        final Song next = mPlaybackQueue.get(mCurrentTrack);
        if (next == null) {
            // Song got unavailable, retry the next one
            boolean shouldFlush = mShouldFlushBuffers;
            nextImpl();

            // Keep the flush status
            mShouldFlushBuffers = shouldFlush;
            return;
        }

        final ProviderIdentifier providerId = next.getProvider();

        if (mCurrentPlayingProvider != null && !next.getProvider().equals(mCurrentPlayingProvider)) {
            // Pause the previously playing track to avoid overlap if it's not the same provider
            ProviderConnection prevConn = PluginsLookup.getDefault().getProvider(mCurrentPlayingProvider);
            if (prevConn != null) {
                IMusicProvider prevProv = prevConn.getBinder();
                if (prevProv != null) {
                    try {
                        prevProv.pause();
                    } catch (RemoteException e) {
                        Log.e(TAG, "Unable to pause previously playing provider", e);
                    }
                }
            }
            mCurrentPlayingProvider = null;
        }

        // Clear up the sink buffers if we were paused (otherwise we'll cut the end of the
        // previous song)
        if (mState == STATE_PAUSED || mState == STATE_PAUSING || mState == STATE_STOPPED) {
            mCommandsHandler.sendEmptyMessage(CommandHandler.MSG_FLUSH_BUFFERS);
        }

        if (providerId != null) {
            ProviderConnection connection = PluginsLookup.getDefault().getProvider(providerId);
            if (connection != null) {
                // Reset playbar status
                getSharedPreferences(SettingsKeys.PREF_SETTINGS, 0).edit()
                        .putBoolean(SettingsKeys.KEY_PLAYBAR_HIDDEN, false).apply();

                // Start playback
                IMusicProvider provider = connection.getBinder();
                if (provider != null) {
                    mState = STATE_BUFFERING;

                    for (IPlaybackCallback cb : mCallbacks) {
                        try {
                            cb.onSongStarted(true, next);
                        } catch (RemoteException e) {
                            Log.e(TAG, "Cannot call playback callback for song start event", e);
                        }
                    }

                    Log.d(TAG, "onSongStarted: Buffering...");

                    if (!next.isLoaded()) {
                        // Track not loaded yet, delay until track info arrived
                        mCurrentTrackWaitLoading = true;
                        mCurrentTrackLoaded = false;
                        Log.w(TAG, "Track not yet loaded: " + next.getRef() + ", delaying");
                    } else if (!next.isAvailable()) {
                        // Track is not available, skip to the next one
                        boolean shouldFlush = mShouldFlushBuffers;
                        nextImpl();

                        // Keep the flush status
                        mShouldFlushBuffers = shouldFlush;
                    } else {
                        mCurrentTrackWaitLoading = false;
                        mCurrentPlayingProvider = providerId;

                        requestAudioFocus();

                        try {
                            provider.playSong(next.getRef());
                        } catch (RemoteException e) {
                            Log.e(TAG, "Unable to play song", e);
                        } catch (NullPointerException e) {
                            Log.e(TAG, "No provider attached", e);
                        } catch (IllegalStateException e) {
                            Log.e(TAG, "Illegal State from provider", e);
                        }

                        mCurrentTrackLoaded = true;

                        mListenLogger.addEntry(next);

                        // The notification system takes care of calling startForeground
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                mNotification.setCurrentSong(next);
                            }
                        });

                        mRemoteMetadata.setCurrentSong(next, getNextTrack() != null);
                        mRemoteMetadata.notifyBuffering();
                    }
                }
            }
        } else {
            Log.e(TAG, "Cannot play the first song of the queue because the Song's "
                    + "ProviderIdentifier is null!");
        }
    }
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

@Override
public void onUpdateSelection(int oldSelStart, int oldSelEnd, int newSelStart, int newSelEnd,
        int candidatesStart, int candidatesEnd) {
    super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd);

    if (BuildConfig.DEBUG)
        Logger.d(TAG, "onUpdateSelection: oss=%d, ose=%d, nss=%d, nse=%d, cs=%d, ce=%d", oldSelStart, oldSelEnd,
                newSelStart, newSelEnd, candidatesStart, candidatesEnd);

    mGlobalCursorPosition = newSelEnd;/* w  w  w .  j av  a  2s.  c  om*/
    mGlobalSelectionStartPosition = newSelStart;
    if (mUndoCommitCursorPosition == UNDO_COMMIT_WAITING_TO_RECORD_POSITION) {
        Logger.d(TAG,
                "onUpdateSelection: I am in ACCEPTED_DEFAULT state, time to store the position - I can only undo-commit from here.");
        mUndoCommitCursorPosition = newSelStart;
    }
    updateShiftStateNow();

    final boolean isExpectedEvent = SystemClock.uptimeMillis() < mExpectingSelectionUpdateBy;
    mExpectingSelectionUpdateBy = NEVER_TIME_STAMP;

    if (isExpectedEvent) {
        Logger.v(TAG, "onUpdateSelection: Expected event. Discarding.");
        return;
    }

    if (!isPredictionOn()) {
        return;// not relevant if no prediction is needed.
    }

    final InputConnection ic = getCurrentInputConnection();
    if (ic == null)
        return;// well, I can't do anything without this connection

    Logger.d(TAG, "onUpdateSelection: ok, let's see what can be done");

    if (newSelStart != newSelEnd) {
        // text selection. can't predict in this mode
        Logger.d(TAG, "onUpdateSelection: text selection.");
        abortCorrectionAndResetPredictionState(false);
    } else {
        // we have the following options (we are in an input which requires
        // predicting (mPredictionOn == true):
        // 1) predicting and moved inside the word
        // 2) predicting and moved outside the word
        // 2.1) to a new word
        // 2.2) to no word land
        // 3) not predicting
        // 3.1) to a new word
        // 3.2) to no word land

        // so, 1 and 2 requires that predicting is currently done, and the
        // cursor moved
        if (TextEntryState.isPredicting()) {
            if (newSelStart >= candidatesStart && newSelStart <= candidatesEnd) {
                // 1) predicting and moved inside the word - just update the
                // cursor position and shift state
                // inside the currently selected word
                int cursorPosition = newSelEnd - candidatesStart;
                if (mWord.setCursorPosition(cursorPosition)) {
                    Logger.d(TAG, "onUpdateSelection: cursor moving inside the predicting word");
                }
            } else {
                Logger.d(TAG, "onUpdateSelection: cursor moving outside the currently predicting word");
                abortCorrectionAndResetPredictionState(false);
                // ask user whether to restart
                postRestartWordSuggestion();
            }
        } else {
            Logger.d(TAG,
                    "onUpdateSelection: not predicting at this moment, maybe the cursor is now at a new word?");
            if (TextEntryState.willUndoCommitOnBackspace()) {
                if (mUndoCommitCursorPosition == oldSelStart && mUndoCommitCursorPosition != newSelStart) {
                    Logger.d(TAG,
                            "onUpdateSelection: I am in a state that is position sensitive but the user moved the cursor, so it is not possible to undo_commit now.");
                    abortCorrectionAndResetPredictionState(false);
                }
            }
            postRestartWordSuggestion();
        }
    }
}

From source file:com.llf.android.launcher3.Folder.java

@Override
public void onDragOver(DragObject d) {
    final DragView dragView = d.dragView;
    final int scrollOffset = mScrollView.getScrollY();
    final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null);
    r[0] -= getPaddingLeft();/*from   ww  w  . j  a v a  2s.  c om*/
    r[1] -= getPaddingTop();

    final long downTime = SystemClock.uptimeMillis();
    final MotionEvent translatedEv = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y,
            0);

    if (!mAutoScrollHelper.isEnabled()) {
        mAutoScrollHelper.setEnabled(true);
    }

    final boolean handled = mAutoScrollHelper.onTouch(this, translatedEv);
    translatedEv.recycle();

    if (handled) {
        mReorderAlarm.cancelAlarm();
    } else {
        mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell);
        if (isLayoutRtl()) {
            mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
        }
        if (mTargetCell[0] != mPreviousTargetCell[0] || mTargetCell[1] != mPreviousTargetCell[1]) {
            mReorderAlarm.cancelAlarm();
            mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
            mReorderAlarm.setAlarm(REORDER_DELAY);
            mPreviousTargetCell[0] = mTargetCell[0];
            mPreviousTargetCell[1] = mTargetCell[1];
            mDragMode = DRAG_MODE_REORDER;
        } else {
            mDragMode = DRAG_MODE_NONE;
        }
    }
}

From source file:com.zologic.tardis.app.MainActivity.java

private void startScan(final UUID[] servicesToScan, final String deviceNameToScanFor) {
    Log.d(TAG, "startScan");

    // Stop current scanning (if needed)
    stopScanning();//from  w w w .j a  va 2 s .c  om

    // Configure scanning
    BluetoothAdapter bluetoothAdapter = BleUtils.getBluetoothAdapter(getApplicationContext());
    if (BleUtils.getBleStatus(this) != BleUtils.STATUS_BLE_ENABLED) {
        Log.w(TAG, "startScan: BluetoothAdapter not initialized or unspecified address.");
    } else {
        mScanner = new BleDevicesScanner(bluetoothAdapter, servicesToScan,
                new BluetoothAdapter.LeScanCallback() {
                    @Override
                    public void onLeScan(final BluetoothDevice device, final int rssi, byte[] scanRecord) {
                        final String deviceName = device.getName();
                        //Log.d(TAG, "Discovered device: " + (deviceName != null ? deviceName : "<unknown>"));

                        BluetoothDeviceData previouslyScannedDeviceData = null;
                        if (deviceNameToScanFor == null
                                || (deviceName != null && deviceName.equalsIgnoreCase(deviceNameToScanFor))) { // Workaround for bug in service discovery. Discovery filtered by service uuid is not working on Android 4.3, 4.4
                            if (mScannedDevices == null)
                                mScannedDevices = new ArrayList<>(); // Safeguard

                            // Check that the device was not previously found
                            for (BluetoothDeviceData deviceData : mScannedDevices) {
                                if (deviceData.device.getAddress().equals(device.getAddress())) {
                                    previouslyScannedDeviceData = deviceData;
                                    break;
                                }
                            }

                            BluetoothDeviceData deviceData;
                            if (previouslyScannedDeviceData == null) {
                                // Add it to the mScannedDevice list
                                deviceData = new BluetoothDeviceData();
                                mScannedDevices.add(deviceData);
                            } else {
                                deviceData = previouslyScannedDeviceData;
                            }

                            deviceData.device = device;
                            deviceData.rssi = rssi;
                            deviceData.scanRecord = scanRecord;
                            decodeScanRecords(deviceData);

                            // Update device data
                            long currentMillis = SystemClock.uptimeMillis();
                            if (previouslyScannedDeviceData == null
                                    || currentMillis - mLastUpdateMillis > kMinDelayToUpdateUI) { // Avoid updating when not a new device has been found and the time from the last update is really short to avoid updating UI so fast that it will become unresponsive
                                mLastUpdateMillis = currentMillis;

                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        updateUI();
                                    }
                                });
                            }
                        }
                    }
                });

        // Start scanning
        mScanner.start();
    }

    // Update UI
    updateUI();
}

From source file:com.mycompany.myfirstindoorsapp.PagedActivity.java

public void positionUpdated(Coordinate userPosition, int accuracy) {
    /**//ww w . jav a 2s  . c  o  m
     * Is called each time the Indoors Library calculated a new position for the user
     * If Lat/Lon/Rotation of your building are set correctly you can calculate a
     * GeoCoordinate for your users current location in the building.
     */

    // if first try, itialize list of zones
    if (connected == true && firstCall == false) // if first try
    {
        this.rotation = building.getRotation();
        accel = new Accel(this, (SensorManager) getSystemService(Context.SENSOR_SERVICE), rotation);
        firstCall = true;
    }

    currentPosition = userPosition;

    if (kalman != null) {
        long time = SystemClock.uptimeMillis();
        double[] coord = new double[2];
        coord[0] = (double) userPosition.x;
        coord[1] = (double) userPosition.y;
        kalman.correct(new ArrayRealVector(coord));
        double[] estimatedState;
        estimatedState = kalman.getStateEstimationVector().toArray();
        data.addToFilter(time, new Coordinate((int) estimatedState[0], (int) estimatedState[1], FLOORLVL));

        data.addToIndoors(time, userPosition);
    }
}

From source file:com.winneredge.stockly.wcommons.floatingactionwidget.FloatingActionButton.java

@Override
public void onRestoreInstanceState(Parcelable state) {
    if (!(state instanceof ProgressSavedState)) {
        super.onRestoreInstanceState(state);
        return;/* ww  w.jav  a  2 s  . com*/
    }

    ProgressSavedState ss = (ProgressSavedState) state;
    super.onRestoreInstanceState(ss.getSuperState());

    this.mCurrentProgress = ss.mCurrentProgress;
    this.mTargetProgress = ss.mTargetProgress;
    this.mSpinSpeed = ss.mSpinSpeed;
    this.mProgressWidth = ss.mProgressWidth;
    this.mProgressColor = ss.mProgressColor;
    this.mProgressBackgroundColor = ss.mProgressBackgroundColor;
    this.mShouldProgressIndeterminate = ss.mShouldProgressIndeterminate;
    this.mShouldSetProgress = ss.mShouldSetProgress;
    this.mProgress = ss.mProgress;
    this.mAnimateProgress = ss.mAnimateProgress;
    this.mShowProgressBackground = ss.mShowProgressBackground;

    this.mLastTimeAnimated = SystemClock.uptimeMillis();
}

From source file:com.android.talkback.eventprocessor.ProcessorFocusAndSingleTap.java

private boolean attemptRefocusNode(AccessibilityNodeInfoCompat node) {
    if (!mMaybeRefocus || mSpeechController.isSpeaking()) {
        return false;
    }/*from   w  w  w .jav  a  2 s .  co  m*/

    // Never refocus legacy web content, it will just read the title again.
    if (WebInterfaceUtils.hasLegacyWebContent(node)) {
        return false;
    }

    mLastRefocusStartTime = SystemClock.uptimeMillis();
    if (mLastRefocusedNode != null) {
        mLastRefocusedNode.recycle();
    }
    mLastRefocusedNode = AccessibilityNodeInfoCompat.obtain(node);
    boolean result = PerformActionUtils.performAction(node,
            AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS) && tryFocusing(node, true /* force */);
    mLastRefocusEndTime = SystemClock.uptimeMillis();
    return result;
}