Example usage for android.os SystemClock elapsedRealtime

List of usage examples for android.os SystemClock elapsedRealtime

Introduction

In this page you can find the example usage for android.os SystemClock elapsedRealtime.

Prototype

@CriticalNative
native public static long elapsedRealtime();

Source Link

Document

Returns milliseconds since boot, including time spent in sleep.

Usage

From source file:com.rexmtorres.android.patternlock.PatternLockView.java

@Override
protected void onDraw(Canvas canvas) {
    final ArrayList<Cell> pattern = mPattern;
    final int count = pattern.size();
    final boolean[][] drawLookup = mPatternDrawLookup;
    if (mPatternDisplayMode == DisplayMode.Animate) {
        // figure out which circles to draw
        // + 1 so we pause on complete pattern
        final int oneCycle = (count + 1) * MILLIS_PER_CIRCLE_ANIMATING;
        final int spotInCycle = (int) (SystemClock.elapsedRealtime() - mAnimatingPeriodStart) % oneCycle;
        final int numCircles = spotInCycle / MILLIS_PER_CIRCLE_ANIMATING;
        clearPatternDrawLookup();//from   ww  w  . jav  a  2s . c  o  m
        for (int i = 0; i < numCircles; i++) {
            final Cell cell = pattern.get(i);
            drawLookup[cell.getRow()][cell.getColumn()] = true;
        }
        // figure out in progress portion of ghosting line
        final boolean needToUpdateInProgressPoint = numCircles > 0 && numCircles < count;
        if (needToUpdateInProgressPoint) {
            final float percentageOfNextCircle = ((float) (spotInCycle % MILLIS_PER_CIRCLE_ANIMATING))
                    / MILLIS_PER_CIRCLE_ANIMATING;
            final Cell currentCell = pattern.get(numCircles - 1);
            final float centerX = getCenterXForColumn(currentCell.column);
            final float centerY = getCenterYForRow(currentCell.row);
            final Cell nextCell = pattern.get(numCircles);
            final float dx = percentageOfNextCircle * (getCenterXForColumn(nextCell.column) - centerX);
            final float dy = percentageOfNextCircle * (getCenterYForRow(nextCell.row) - centerY);
            mInProgressX = centerX + dx;
            mInProgressY = centerY + dy;
        }
        // TODO: Infinite loop here...
        invalidate();
    }
    final Path currentPath = mCurrentPath;
    currentPath.rewind();
    // draw the circles
    for (int i = 0; i < 3; i++) {
        float centerY = getCenterYForRow(i);
        for (int j = 0; j < 3; j++) {
            CellState cellState = mCellStates[i][j];
            float centerX = getCenterXForColumn(j);
            float translationY = cellState.translationY;
            drawDot(canvas, (int) centerX, (int) centerY + translationY, cellState.radius, drawLookup[i][j],
                    cellState.alpha, cellState.bitmapDot);
        }
    }

    // TODO: the path should be created and cached every time we hit-detect a cell
    // only the last segment of the path should be computed here
    // draw the path of the pattern (unless we are in stealth mode)
    final boolean drawPath = !mInStealthMode;
    if (drawPath) {
        mPathPaint.setColor(getCurrentColor(true /* partOfPattern */));
        boolean anyCircles = false;
        float lastX = 0f;
        float lastY = 0f;
        for (int i = 0; i < count; i++) {
            Cell cell = pattern.get(i);
            // only draw the part of the pattern stored in
            // the lookup table (this is only different in the case
            // of animation).
            if (!drawLookup[cell.row][cell.column]) {
                break;
            }
            anyCircles = true;
            float centerX = getCenterXForColumn(cell.column);
            float centerY = getCenterYForRow(cell.row);
            if (i != 0) {
                CellState state = mCellStates[cell.row][cell.column];
                currentPath.rewind();
                currentPath.moveTo(lastX, lastY);
                if (state.lineEndX != Float.MIN_VALUE && state.lineEndY != Float.MIN_VALUE) {
                    currentPath.lineTo(state.lineEndX, state.lineEndY);
                } else {
                    currentPath.lineTo(centerX, centerY);
                }
                canvas.drawPath(currentPath, mPathPaint);
            }
            lastX = centerX;
            lastY = centerY;
        }
        // draw last in progress section
        if ((mPatternInProgress || mPatternDisplayMode == DisplayMode.Animate) && anyCircles) {
            currentPath.rewind();
            currentPath.moveTo(lastX, lastY);
            currentPath.lineTo(mInProgressX, mInProgressY);
            mPathPaint.setAlpha(
                    (int) (calculateLastSegmentAlpha(mInProgressX, mInProgressY, lastX, lastY) * 255f));
            canvas.drawPath(currentPath, mPathPaint);
        }
    }
}

From source file:com.lgallardo.qbittorrentclient.RefreshListener.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get preferences
    getSettings();//  w ww .j  a v  a  2  s .  c  o m

    // Set alarm for checking completed torrents, if not set
    if (PendingIntent.getBroadcast(getApplication(), 0, new Intent(getApplication(), NotifierService.class),
            PendingIntent.FLAG_NO_CREATE) == null) {

        // Set Alarm for checking completed torrents
        alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(getApplication(), NotifierService.class);
        alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0);

        alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000,
                notification_period, alarmIntent);
    }

    // Set alarm for RSS checking, if not set
    if (PendingIntent.getBroadcast(getApplication(), 0, new Intent(getApplication(), RSSService.class),
            PendingIntent.FLAG_NO_CREATE) == null) {

        // Set Alarm for checking completed torrents
        alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(getApplication(), RSSService.class);
        alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0);

        alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000,
                AlarmManager.INTERVAL_DAY, alarmIntent);
    }

    // Set Theme (It must be fore inflating or setContentView)
    if (dark_ui) {
        this.setTheme(R.style.Theme_Dark);

        if (Build.VERSION.SDK_INT >= 21) {
            getWindow().setNavigationBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground));
            getWindow().setStatusBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground));
        }
    } else {
        this.setTheme(R.style.Theme_Light);

        if (Build.VERSION.SDK_INT >= 21) {
            getWindow().setNavigationBarColor(getResources().getColor(R.color.primary));
        }

    }

    setContentView(R.layout.activity_main);

    toolbar = (Toolbar) findViewById(R.id.app_bar);

    if (dark_ui) {
        toolbar.setBackgroundColor(getResources().getColor(R.color.Theme_Dark_primary));
    }

    setSupportActionBar(toolbar);

    // Set App title
    setTitle(R.string.app_shortname);

    // Drawer menu
    navigationDrawerServerItems = getResources().getStringArray(R.array.qBittorrentServers);
    navigationDrawerItemTitles = getResources().getStringArray(R.array.navigation_drawer_items_array);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    //        drawerList = (ListView) findViewById(R.id.left_drawer);

    mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View
    mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are

    ArrayList<DrawerItem> serverItems = new ArrayList<DrawerItem>();
    ArrayList<DrawerItem> actionItems = new ArrayList<DrawerItem>();
    //        ArrayList<ObjectDrawerItem> labelItems = new ArrayList<ObjectDrawerItem>();
    ArrayList<DrawerItem> settingsItems = new ArrayList<DrawerItem>();

    // Add server category
    serverItems.add(new DrawerItem(R.drawable.ic_drawer_servers,
            getResources().getString(R.string.drawer_servers_category), DRAWER_CATEGORY, false, null));

    // Server items
    int currentServerValue = 1;

    try {
        currentServerValue = Integer.parseInt(MainActivity.currentServer);
    } catch (NumberFormatException e) {

    }

    for (int i = 0; i < navigationDrawerServerItems.length; i++) {
        serverItems.add(new DrawerItem(R.drawable.ic_drawer_subitem, navigationDrawerServerItems[i],
                DRAWER_ITEM_SERVERS, ((i + 1) == currentServerValue), "changeCurrentServer"));

    }

    // Add actions
    actionItems.add(new DrawerItem(R.drawable.ic_drawer_all, navigationDrawerItemTitles[0], DRAWER_ITEM_ACTIONS,
            lastState.equals("all"), "refreshAll"));
    actionItems.add(new DrawerItem(R.drawable.ic_drawer_downloading, navigationDrawerItemTitles[1],
            DRAWER_ITEM_ACTIONS, lastState.equals("downloading"), "refreshDownloading"));
    actionItems.add(new DrawerItem(R.drawable.ic_drawer_completed, navigationDrawerItemTitles[2],
            DRAWER_ITEM_ACTIONS, lastState.equals("completed"), "refreshCompleted"));
    actionItems.add(new DrawerItem(R.drawable.ic_drawer_seeding, navigationDrawerItemTitles[3],
            DRAWER_ITEM_ACTIONS, lastState.equals("seeding"), "refreshSeeding"));
    actionItems.add(new DrawerItem(R.drawable.ic_drawer_paused, navigationDrawerItemTitles[4],
            DRAWER_ITEM_ACTIONS, lastState.equals("pause"), "refreshPaused"));
    actionItems.add(new DrawerItem(R.drawable.ic_drawer_active, navigationDrawerItemTitles[5],
            DRAWER_ITEM_ACTIONS, lastState.equals("active"), "refreshActive"));
    actionItems.add(new DrawerItem(R.drawable.ic_drawer_inactive, navigationDrawerItemTitles[6],
            DRAWER_ITEM_ACTIONS, lastState.equals("inactive"), "refreshInactive"));

    // Add labels

    // Add settings actions
    settingsItems.add(new DrawerItem(R.drawable.ic_action_options, navigationDrawerItemTitles[7],
            DRAWER_ITEM_ACTIONS, false, "openOptions"));
    settingsItems.add(new DrawerItem(R.drawable.ic_drawer_settings, navigationDrawerItemTitles[8],
            DRAWER_ITEM_ACTIONS, false, "openSettings"));

    if (packageName.equals("com.lgallardo.qbittorrentclient")) {
        settingsItems.add(new DrawerItem(R.drawable.ic_drawer_pro, navigationDrawerItemTitles[9],
                DRAWER_ITEM_ACTIONS, false, "getPro"));
        settingsItems.add(new DrawerItem(R.drawable.ic_drawer_help, navigationDrawerItemTitles[10],
                DRAWER_ITEM_ACTIONS, false, "openHelp"));
    } else {
        settingsItems.add(new DrawerItem(R.drawable.ic_drawer_help, navigationDrawerItemTitles[9],
                DRAWER_ITEM_ACTIONS, false, "openHelp"));
    }

    rAdapter = new DrawerItemRecyclerViewAdapter(getApplicationContext(), this, serverItems, actionItems,
            settingsItems, null);
    rAdapter.notifyDataSetChanged();

    //        drawerList.setAdapter(adapter);
    mRecyclerView.setAdapter(rAdapter);

    mLayoutManager = new LinearLayoutManager(this); // Creating a layout Manager
    mRecyclerView.setLayoutManager(mLayoutManager); // Setting the layout Manager

    // Set selection according to last state
    setSelectionAndTitle(lastState);

    // Get drawer title
    title = drawerTitle = getTitle();

    // Add the application icon control code inside MainActivity onCreate

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    // New ActionBarDrawerToggle for Google Material Desing (v7)
    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open,
            R.string.drawer_close) {

        /**
         * Called when a drawer has settled in a completely closed state.
         */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            // getSupportActionBar().setTitle(title);
        }

        /**
         * Called when a drawer has settled in a completely open state.
         */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            // getSupportActionBar().setTitle(drawerTitle);
            // setTitle(R.string.app_shortname);

        }
    };

    drawerLayout.setDrawerListener(drawerToggle);

    getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    getSupportActionBar().setHomeButtonEnabled(false);

    // Get options and save them as shared preferences
    qBittorrentOptions qso = new qBittorrentOptions();
    qso.execute(new String[] { qbQueryString + "/preferences", "getSettings" });

    // If it was awoken from an intent-filter,
    // get intent from the intent filter and Add URL torrent
    addTorrentByIntent(getIntent());

    // Fragments

    // Check whether the activity is using the layout version with
    // the fragment_container FrameLayout. If so, we must add the first
    // fragment
    if (findViewById(R.id.fragment_container) != null) {

        // However, if we're being restored from a previous state,
        // then we don't need to do anything and should return or else
        // we could end up with overlapping fragments.
        // if (savedInstanceState != null) {
        // return;
        // }

        // This fragment will hold the list of torrents
        if (firstFragment == null) {
            firstFragment = new com.lgallardo.qbittorrentclient.ItemstFragment();
        }

        // This fragment will hold the list of torrents
        helpTabletFragment = new HelpFragment();

        // Set the second fragments container
        firstFragment.setSecondFragmentContainer(R.id.content_frame);

        // This i the second fragment, holding a default message at the
        // beginning
        secondFragment = new AboutFragment();

        // Add the fragment to the 'list_frame' FrameLayout
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        if (fragmentManager.findFragmentByTag("firstFragment") == null) {
            fragmentTransaction.add(R.id.list_frame, helpTabletFragment, "firstFragment");
        } else {
            fragmentTransaction.replace(R.id.list_frame, helpTabletFragment, "firstFragment");
        }

        if (fragmentManager.findFragmentByTag("secondFragment") == null) {
            fragmentTransaction.add(R.id.content_frame, secondFragment, "secondFragment");
        } else {
            fragmentTransaction.replace(R.id.content_frame, secondFragment, "secondFragment");
        }

        fragmentTransaction.commit();

        // Second fragment will be added in ItemsFragment's onListItemClick method

    } else {

        // Phones handle just one fragment

        // Create an instance of ItemsFragments
        if (firstFragment == null) {
            firstFragment = new com.lgallardo.qbittorrentclient.ItemstFragment();
        }
        firstFragment.setSecondFragmentContainer(R.id.one_frame);

        // This is the about fragment, holding a default message at the
        // beginning
        secondFragment = new AboutFragment();

        // If we're being restored from a previous state,
        // then we don't need to do anything and should return or else
        // we could end up with overlapping fragments.
        //            if (savedInstanceState != null) {
        //
        //                // Handle Item list empty due to Fragment stack
        //                try {
        //                    FragmentManager fm = getFragmentManager();
        //
        //                    if (fm.getBackStackEntryCount() == 1 && fm.findFragmentById(R.id.one_frame) instanceof com.lgallardo.qbittorrentclient.TorrentDetailsFragment) {
        //
        //                        refreshCurrent();
        //
        //                    }
        //                }
        //                catch (Exception e) {
        //                }
        //
        //                return;
        //            }

        // Add the fragment to the 'list_frame' FrameLayout
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        if (fragmentManager.findFragmentByTag("firstFragment") == null) {
            fragmentTransaction.add(R.id.one_frame, secondFragment, "firstFragment");
        } else {
            fragmentTransaction.replace(R.id.one_frame, secondFragment, "firstFragment");
        }

        // if torrent details was loaded reset back button stack
        for (int i = 0; i < fragmentManager.getBackStackEntryCount(); ++i) {
            fragmentManager.popBackStack();
        }

        fragmentTransaction.commit();
    }

    // Activity is visible
    activityIsVisible = true;

    // First refresh
    refreshCurrent();

    handler = new Handler();
    handler.postDelayed(m_Runnable, refresh_period);

    // Load banner
    loadBanner();

}

From source file:at.alladin.rmbt.android.test.RMBTLoopService.java

private void setNotificationText(NotificationCompat.Builder builder) {
    final Resources res = getResources();

    final long now = SystemClock.elapsedRealtime();
    final long lastTestDelta = loopModeResults.getLastTestTime() == 0 ? 0
            : now - loopModeResults.getLastTestTime();

    final String elapsedTimeString = LoopModeTriggerItem.formatSeconds(Math.round(lastTestDelta / 1000), 1);

    final CharSequence textTemplate = res.getText(R.string.loop_notification_text_without_stop);
    final CharSequence text = MessageFormat.format(textTemplate.toString(), loopModeResults.getNumberOfTests(),
            elapsedTimeString, Math.round(loopModeResults.getLastDistance()));
    builder.setContentText(text);/*from   w  w w. j  a  v a2s.  c  o  m*/

    if (bigTextStyle == null) {
        bigTextStyle = (new NotificationCompat.BigTextStyle());
        builder.setStyle(bigTextStyle);
    }

    bigTextStyle.bigText(text);
}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardView.java

public void revertPopTextOutOfKey() {
    if (TextUtils.isEmpty(mPopOutText))
        return;/*from   w  w w. j  a v a2s  .c  o m*/

    if (!mPopOutTextReverting) {
        mPopOutTextReverting = true;
        //re-setting the mPopOutTime to reflect the time required to revert back
        final long currentAnimationTime = SystemClock.elapsedRealtime() - mPopOutTime;
        final long animationTimeLeft = TEXT_POP_OUT_ANIMATION_DURATION - currentAnimationTime;
        mPopOutTime = SystemClock.elapsedRealtime() - animationTimeLeft;
    }
}

From source file:com.onesignal.OneSignal.java

static void onAppLostFocus(boolean onlySave) {
    foreground = false;//from   w w w  . j  a va 2  s . co  m

    if (!initDone)
        return;

    if (trackAmazonPurchase != null)
        trackAmazonPurchase.checkListener();

    if (lastTrackedTime == -1)
        return;

    long time_elapsed = (long) (((SystemClock.elapsedRealtime() - lastTrackedTime) / 1000d) + 0.5d);
    lastTrackedTime = SystemClock.elapsedRealtime();
    if (time_elapsed < 0 || time_elapsed > 604800)
        return;
    if (appContext == null) {
        Log(LOG_LEVEL.ERROR, "Android Context not found, please call OneSignal.init when your app starts.");
        return;
    }

    long unSentActiveTime = GetUnsentActiveTime();
    long totalTimeActive = unSentActiveTime + time_elapsed;

    if (onlySave || totalTimeActive < MIN_ON_FOCUS_TIME || getUserId() == null) {
        SaveUnsentActiveTime(totalTimeActive);
        return;
    }

    sendOnFocus(totalTimeActive, true);
}

From source file:com.heightechllc.breakify.MainActivity.java

/**
 * Starts the work or break timer//from  w w w  .  j  a va2s.  c  om
 * @param duration The number of milliseconds to run the timer for. If currently paused, this
 *                 is the remaining time.
 */
@TargetApi(19)
private void startTimer(long duration) {
    // Stop blinking the time and state labels
    timeLbl.clearAnimation();
    stateLbl.clearAnimation();

    // Show the "Reset" and "Skip" btns
    resetBtn.setVisibility(View.VISIBLE);
    skipBtn.setVisibility(View.VISIBLE);

    // Update the start / stop label
    startStopLbl.setText(R.string.stop);
    startStopLbl.setVisibility(View.VISIBLE);

    if (timerState == TIMER_STATE_PAUSED && circleTimer.getTotalTime() > 0) {
        // We're resuming from a paused state, so calculate how much time is remaining, based
        //  on the total time set in the circleTimer
        circleTimer.setPassedTime(circleTimer.getTotalTime() - duration, false);
    } else {
        circleTimer.setTotalTime(duration);
        circleTimer.setPassedTime(0, false);
        circleTimer.updateTimeLbl(duration);
        // Record the total duration, so we can resume if the activity is destroyed
        sharedPref.edit().putLong("schedTotalTime", duration).apply();
    }

    circleTimer.startIntervalAnimation();

    timerState = TIMER_STATE_RUNNING;

    // Schedule the alarm to go off
    PendingIntent pi = PendingIntent.getBroadcast(this, ALARM_MANAGER_REQUEST_CODE,
            new Intent(this, AlarmReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
    long ringTime = SystemClock.elapsedRealtime() + duration;
    if (Build.VERSION.SDK_INT >= 19) {
        // API 19 needs setExact()
        alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, ringTime, pi);
    } else {
        // APIs 1-18 use set()
        alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, ringTime, pi);
    }
    // Show the persistent notification
    AlarmNotifications.showUpcomingNotification(this, ringTime, getWorkState());

    // Record when the timer will ring and remove record of time remaining for the paused timer.
    // Save the scheduled ring time using Unix / epoch time, not elapsedRealtime, b/c that is
    //  reset on each boot.
    long timeFromNow = ringTime - SystemClock.elapsedRealtime();
    long ringUnixTime = System.currentTimeMillis() + timeFromNow;
    sharedPref.edit().putLong("schedRingTime", ringUnixTime).remove("pausedTimeRemaining").apply();
}

From source file:uk.bowdlerize.service.CensorCensusService.java

private void onProbeFinish() {
    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    Intent i = new Intent(CensorCensusService.this, CensorCensusService.class);
    i.putExtra(API.EXTRA_POLL, true);//from   ww  w.  j  a  v a2  s .  c  o m
    PendingIntent pi = PendingIntent.getService(CensorCensusService.this, 0, i,
            PendingIntent.FLAG_UPDATE_CURRENT);

    //If we are polling lets set our next tick
    if (getSharedPreferences(MainActivity.class.getSimpleName(), Context.MODE_PRIVATE)
            .getInt(API.SETTINGS_GCM_PREFERENCE, API.SETTINGS_GCM_FULL) == API.SETTINGS_GCM_DISABLED) {
        am.cancel(pi); // cancel any existing alarms
        //TODO Setback to 60000
        long repeat = (long) (getPreferences(CensorCensusService.this).getInt(API.SETTINGS_FREQUENCY, 1)
                * 60000);//60000 or 5000
        Log.e("onProbeFinish", Long.toString(repeat));
        Log.e("onProbeFinish", "          -         ");
        Log.e("onProbeFinish", "          -         ");
        Log.e("onProbeFinish", "          -         ");
        am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + repeat, pi);
    } else {
        Log.e("onProbeFinish", "Cancel everything!");
        Log.e("onProbeFinish", "          -         ");
        Log.e("onProbeFinish", "          -         ");
        Log.e("onProbeFinish", "          -         ");
        am.cancel(pi); // cancel any existing alarms
        stopSelf();
    }
}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardView.java

public void popTextOutOfKey(CharSequence text) {
    if (TextUtils.isEmpty(text)) {
        Logger.w(TAG, "Call for popTextOutOfKey with missing text argument!");
        return;/*from w w  w  .j a va  2s .c om*/
    }
    if (!AnyApplication.getConfig().workaround_alwaysUseDrawText())
        return;// not doing it with StaticLayout

    mPopOutTextReverting = false;
    //performing "toString" so we'll have a separate copy of the CharSequence,
    // and not the original object which I fear is a reference copy (hence may be changed).
    mPopOutText = text.toString();
    mPopOutTime = SystemClock.elapsedRealtime();
    mPopOutStartPoint.x = mFirstTouchPoint.x;
    mPopOutStartPoint.y = mFirstTouchPoint.y;
    // it is ok to wait for the next loop.
    postInvalidate();
}

From source file:com.scooter1556.sms.android.activity.FullScreenPlayerActivity.java

private void updateProgress() {
    if (lastPlaybackState == null) {
        return;//from   w  w  w  .  ja  va2s. c  om
    }

    long currentPosition = lastPlaybackState.getPosition();

    if (lastPlaybackState.getState() != PlaybackStateCompat.STATE_PAUSED) {
        // Calculate the elapsed time between the last position update and now and unless
        // paused, we can assume (delta * speed) + current position is approximately the
        // latest position. This ensures that we do not repeatedly call the getPlaybackState()
        // on MediaControllerCompat.
        long timeDelta = SystemClock.elapsedRealtime() - lastPlaybackState.getLastPositionUpdateTime();
        currentPosition += (int) timeDelta * lastPlaybackState.getPlaybackSpeed();
    }

    seekbar.setProgress((int) currentPosition);
}

From source file:com.android.development.Connectivity.java

private void scheduleAlarm(long delayMs, String eventType) {
    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(CONNECTIVITY_TEST_ALARM);

    i.putExtra(TEST_ALARM_EXTRA, eventType);
    i.putExtra(TEST_ALARM_ON_EXTRA, Long.toString(mSCOnDuration));
    i.putExtra(TEST_ALARM_OFF_EXTRA, Long.toString(mSCOffDuration));
    i.putExtra(TEST_ALARM_CYCLE_EXTRA, Integer.toString(mSCCycleCount));

    PendingIntent p = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

    am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + delayMs, p);
}