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.fishstix.dosboxfree.DBGLSurfaceView.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override/*from   w ww .  ja v a  2s.  co m*/
public boolean onGenericMotionEvent(MotionEvent event) {
    if (event.getEventTime() + EVENT_THRESHOLD_DECAY < SystemClock.uptimeMillis()) {
        //Log.i("DosBoxTurbo","eventtime: "+event.getEventTime() + " systemtime: "+SystemClock.uptimeMillis());
        return true; // get rid of old events
    }
    final int pointerIndex = MotionEventCompat.getActionIndex(event);
    final int pointerId = MotionEventCompat.getPointerId(event, pointerIndex);

    if ((MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_MOVE) && ((mWrap.getSource(event)
            & TouchEventWrapper.SOURCE_CLASS_MASK) == TouchEventWrapper.SOURCE_CLASS_JOYSTICK)) {
        if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) && (mAnalogStickPref < 3)) {
            // use new 3.1 API to handle joystick movements
            int historySize = event.getHistorySize();
            for (int i = 0; i < historySize; i++) {
                processJoystickInput(event, i);
            }

            processJoystickInput(event, -1);
            return true;
        } else {
            // use older 2.2+ API to handle joystick movements
            if (mInputMode == INPUT_MODE_REAL_JOYSTICK) {
                x[pointerId] = mWrap.getX(event, pointerId);
                y[pointerId] = mWrap.getY(event, pointerId);
                DosBoxControl.nativeJoystick((int) ((x[pointerId] * 256f) + mJoyCenterX),
                        (int) ((y[pointerId] * 256f) + mJoyCenterY), ACTION_MOVE, -1);
                return true;
            }
        }
    } else if ((MotionEventCompat.getActionMasked(event) == MotionEventCompat.ACTION_HOVER_MOVE)
            && ((mWrap.getSource(event)
                    & TouchEventWrapper.SOURCE_CLASS_MASK) == TouchEventWrapper.SOURCE_CLASS_POINTER)) {
        if (mInputMode == INPUT_MODE_REAL_MOUSE) {
            x_last[pointerId] = x[pointerId];
            y_last[pointerId] = y[pointerId];
            x[pointerId] = mWrap.getX(event, pointerId);
            y[pointerId] = mWrap.getY(event, pointerId);
            if (mAbsolute) {
                DosBoxControl.nativeMouseWarp(x[pointerId], y[pointerId], mRenderer.x, mRenderer.y,
                        mRenderer.width, mRenderer.height);
            } else {
                DosBoxControl.nativeMouse((int) (x[pointerId] * mMouseSensitivityX),
                        (int) (y[pointerId] * mMouseSensitivityY),
                        (int) (x_last[pointerId] * mMouseSensitivityX),
                        (int) (y_last[pointerId] * mMouseSensitivityY), 2, -1);
            }

            int buttonState = mWrap.getButtonState(event);
            if (((buttonState & TouchEventWrapper.BUTTON_SECONDARY) != 0) && !mSPenButton) {
                // Handle Samsung SPen Button (RMB) - DOWN
                DosBoxControl.nativeMouse(0, 0, 0, 0, ACTION_DOWN, BTN_B);
                mSPenButton = true;
            } else if (((buttonState & TouchEventWrapper.BUTTON_SECONDARY) == 0) && mSPenButton) {
                // Handle Samsung SPen Button (RMB) - UP
                DosBoxControl.nativeMouse(0, 0, 0, 0, ACTION_UP, BTN_B);
                mSPenButton = false;
            }

            if (mDebug)
                Log.d("DosBoxTurbo", "onGenericMotionEvent() INPUT_MODE_REAL_MOUSE x: " + x[pointerId] + "  y: "
                        + y[pointerId] + "  |  xL: " + x_last[pointerId] + "  yL: " + y_last[pointerId]);
            try {
                if (!mInputLowLatency)
                    Thread.sleep(95);
                else
                    Thread.sleep(65);
            } catch (InterruptedException e) {
            }
            return true;
        }
    } else if (MotionEventCompat.getActionMasked(event) == MotionEventCompat.ACTION_HOVER_EXIT) {
        if (mInputMode == INPUT_MODE_REAL_MOUSE) {
            // hover exit
            int buttonState = mWrap.getButtonState(event);
            if (((buttonState & TouchEventWrapper.BUTTON_SECONDARY) == 0) && mSPenButton) {
                // Handle Samsung SPen Button (RMB) - UP
                DosBoxControl.nativeMouse(0, 0, 0, 0, ACTION_UP, BTN_B);
                mSPenButton = false;
                return true;
            }
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        return super.onGenericMotionEvent(event);
    } else {
        return false;
    }
}

From source file:com.goftagram.telegram.messenger.NotificationsController.java

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

    notificationsQueue.postRunnable(new Runnable() {
        @Override/*from   www .j  ava  2 s  .  c  om*/
        public void run() {
            pushDialogs.clear();
            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) {
                    long mid = message.id;
                    if (message.to_id.channel_id != 0) {
                        mid |= ((long) message.to_id.channel_id) << 32;
                    }
                    if (pushMessagesDict.containsKey(mid)) {
                        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.mentioned) {
                        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(mid, 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) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        popupMessages.clear();
                        NotificationCenter.getInstance()
                                .postNotificationName(NotificationCenter.pushMessagesUpdated);
                    }
                });
            }
            showOrUpdateNotification(SystemClock.uptimeMillis() / 1000 < 60);

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

From source file:ir.besteveryeverapp.telegram.NotificationsController.java

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

    notificationsQueue.postRunnable(new Runnable() {
        @Override//from   w  ww. j  a va 2 s . c o m
        public void run() {
            pushDialogs.clear();
            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) {
                    long mid = message.id;
                    if (message.to_id.channel_id != 0) {
                        mid |= ((long) message.to_id.channel_id) << 32;
                    }
                    if (pushMessagesDict.containsKey(mid)) {
                        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.mentioned) {
                        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 == opened_dialog_id && ApplicationLoader.isScreenOn) {
                        continue;
                    }
                    pushMessagesDict.put(mid, 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) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        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.androzic.MapFragment.java

private void updatePanels() {
    long now = SystemClock.uptimeMillis();
    boolean changed = false;

    if ((now < map.lastDragTime + mapInfoHideDelay)) {
        if (mapInfo.getVisibility() != View.VISIBLE) {
            mapInfo.setVisibility(View.VISIBLE);
            if (mapButtonsVisible)
                mapButtons.setVisibility(View.VISIBLE);
            changed = true;/*from  w  w  w . j a v  a 2 s . co  m*/
        }
    } else {
        if (mapInfo.getVisibility() != View.GONE) {
            mapInfo.setVisibility(View.GONE);
            mapButtons.setVisibility(View.GONE);
            changed = true;
        }
    }
    if ((now < map.lastDragTime + satInfoHideDelay)) {
        if (satInfo.getVisibility() != View.VISIBLE) {
            satInfo.setVisibility(View.VISIBLE);
            changed = true;
        }
    } else {
        if (satInfo.getVisibility() != View.GONE) {
            satInfo.setVisibility(View.GONE);
            changed = true;
        }
    }
    if ((now < map.lastDragTime + navInfoHideDelay)) {
        if (navInfo.getVisibility() != View.VISIBLE) {
            navInfo.setVisibility(View.VISIBLE);
            changed = true;
        }
    } else {
        if (navInfo.getVisibility() != View.GONE) {
            navInfo.setVisibility(View.GONE);
            changed = true;
        }
    }

    if (changed)
        updateMapViewArea();
}

From source file:me.spadival.podmode.PodModeService.java

public void run() {
    podCommand pCommand = null;/*from  w  w w.j a  va2s  .co  m*/
    podResponse pResponse = null;
    byte[] respBytes = null;

    long eventtime;
    Intent downIntent = null;
    KeyEvent downEvent = null;
    Intent upIntent = null;
    KeyEvent upEvent = null;

    // serialWrite(new byte[] { (byte) 0xFF, 0x55, 0x02, 0x00, 0x00,
    // (byte) 0xFE });

    while (mPodRunning) {
        pCommand = readCommand();
        if (pCommand == null)
            continue;

        if (pCommand.mode == 0x03)
            mPodStatus = podStat.DISPLAYREMOTE;

        if (mAccessoryName != null
                && (mPodStatus == podStat.SIMPLEREMOTE || mPodStatus == podStat.DISPLAYREMOTE
                        || mPodStatus == podStat.ADVANCEDREMOTE || mPodStatus == podStat.ADVANCEDHACK)
                && mHTTPsend) {
            mHTTPsend = false;
            mHttpThread.start();
        }

        if (mLaunchFirstTime
                && (pCommand.mode == 02 || (pCommand.mode == 04 && !mAdvancedRemoteApp.equals(PACKAGENAME)))) {

            String launchApp = null;

            if (pCommand.mode == 02) {
                mBanner = getString(R.string.simple_remote);
                launchApp = mSimpleRemoteApp;
            }

            if (pCommand.mode == 04) {
                mPodStatus = podStat.ADVANCEDREMOTE;
                if (!mAdvancedRemoteApp.equals(PACKAGENAME))
                    mPodStatus = podStat.ADVANCEDHACK;

                mBanner = getString(R.string.advanced_remote);
                launchApp = mAdvancedRemoteApp;
            }

            if (launchApp != null) {
                PackageManager pm = getPackageManager();
                Intent LaunchIntent = pm.getLaunchIntentForPackage(launchApp);

                startActivity(LaunchIntent);

                ResolveInfo info = pm.resolveActivity(LaunchIntent, PackageManager.MATCH_DEFAULT_ONLY);
                mSongTitle = (String) info.loadLabel(pm);
                mElapsedTime = 0;

                if (pCommand.mode == 04)
                    mRetriever.changeApp(false, mSongTitle, getString(R.string.advanced_remote), 999);

                mAlbumArtUri = "android.resource://" + launchApp + "/" + String.valueOf(info.getIconResource());
                setUpAsForeground(mBanner);
                localBroadcast(false);
            }

            mLaunchFirstTime = false;
        }

        if (pCommand.mode == 02) {

            mPodStatus = podStat.SIMPLEREMOTE;

            switch (pCommand.command) {

            case RemoteRelease:
                respBytes = new byte[] { (byte) 0x01, 0x00, 0x00 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case RemotePlayPause:

                eventtime = SystemClock.uptimeMillis();

                downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
                downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN,
                        KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, 0);
                downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
                if (mSimpleRemoteApp != null)
                    downIntent.setPackage(mSimpleRemoteApp);

                sendOrderedBroadcast(downIntent, null);

                break;

            case RemoteJustPlay:

                eventtime = SystemClock.uptimeMillis();

                downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
                downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN,
                        KeyEvent.KEYCODE_MEDIA_PLAY, 0);
                downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
                if (mSimpleRemoteApp != null)
                    downIntent.setPackage(mSimpleRemoteApp);

                sendOrderedBroadcast(downIntent, null);

                break;

            case RemoteJustPause:

                eventtime = SystemClock.uptimeMillis();

                downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
                downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN,
                        KeyEvent.KEYCODE_MEDIA_PAUSE, 0);
                downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
                if (mSimpleRemoteApp != null)
                    downIntent.setPackage(mSimpleRemoteApp);

                sendOrderedBroadcast(downIntent, null);

                break;

            case RemoteSkipFwd:

                eventtime = SystemClock.uptimeMillis();

                if (downEvent != null) {
                    if (downEvent.getKeyCode() == KeyEvent.KEYCODE_MEDIA_NEXT
                            || downEvent.getKeyCode() == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) {
                        if ((eventtime - downEvent.getEventTime()) > 1000) {

                            downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
                            downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN,
                                    KeyEvent.KEYCODE_MEDIA_FAST_FORWARD, 0);
                            downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
                            if (mSimpleRemoteApp != null)
                                downIntent.setPackage(mSimpleRemoteApp);

                            sendOrderedBroadcast(downIntent, null);

                            upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
                            upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP,
                                    KeyEvent.KEYCODE_MEDIA_FAST_FORWARD, 0);
                            upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
                            if (mSimpleRemoteApp != null)
                                upIntent.setPackage(mSimpleRemoteApp);

                            sendOrderedBroadcast(upIntent, null);
                        }

                    }

                } else {

                    downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
                    downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN,
                            KeyEvent.KEYCODE_MEDIA_NEXT, 0);
                    downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
                    if (mSimpleRemoteApp != null)
                        downIntent.setPackage(mSimpleRemoteApp);
                }

                break;
            case RemoteSkipRwd:

                eventtime = SystemClock.uptimeMillis();

                if (downEvent != null) {
                    if (downEvent.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PREVIOUS
                            || downEvent.getKeyCode() == KeyEvent.KEYCODE_MEDIA_REWIND) {
                        if ((eventtime - downEvent.getEventTime()) > 1000) {

                            downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
                            downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN,
                                    KeyEvent.KEYCODE_MEDIA_REWIND, 0);
                            downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
                            if (mSimpleRemoteApp != null)
                                downIntent.setPackage(mSimpleRemoteApp);
                            sendOrderedBroadcast(downIntent, null);

                            upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
                            upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP,
                                    KeyEvent.KEYCODE_MEDIA_REWIND, 0);
                            upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
                            if (mSimpleRemoteApp != null)
                                upIntent.setPackage(mSimpleRemoteApp);
                            sendOrderedBroadcast(upIntent, null);
                        }

                    }

                } else {

                    downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
                    downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN,
                            KeyEvent.KEYCODE_MEDIA_PREVIOUS, 0);
                    downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
                    if (mSimpleRemoteApp != null)
                        downIntent.setPackage(mSimpleRemoteApp);
                }

                break;
            case RemoteStop:
                eventtime = SystemClock.uptimeMillis();

                downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
                downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN,
                        KeyEvent.KEYCODE_MEDIA_STOP, 0);
                downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
                if (mSimpleRemoteApp != null)
                    downIntent.setPackage(mSimpleRemoteApp);
                sendOrderedBroadcast(downIntent, null);

                break;

            case RemoteButtonRel:

                eventtime = SystemClock.uptimeMillis();

                if (downIntent != null) {
                    if (downEvent.getKeyCode() == KeyEvent.KEYCODE_MEDIA_NEXT
                            || downEvent.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PREVIOUS)
                        sendOrderedBroadcast(downIntent, null);

                    if (downEvent.getKeyCode() != KeyEvent.KEYCODE_MEDIA_FAST_FORWARD
                            && downEvent.getKeyCode() != KeyEvent.KEYCODE_MEDIA_REWIND) {
                        upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
                        upEvent = new KeyEvent(downEvent.getDownTime(), eventtime, KeyEvent.ACTION_UP,
                                downEvent.getKeyCode(), 0);
                        upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
                        if (mSimpleRemoteApp != null)
                            upIntent.setPackage(mSimpleRemoteApp);
                        sendOrderedBroadcast(upIntent, null);
                    }

                }
                downIntent = null;
                downEvent = null;
                upIntent = null;
                upEvent = null;

                break;
            default:
                break;

            }

        } else {

            switch (pCommand.command) {

            case AppCmd:
                byte[] appNameBytes = new byte[pCommand.params.length - 3];

                System.arraycopy(pCommand.params, 2, appNameBytes, 0, appNameBytes.length);

                String appName = "";

                try {
                    appName = new String(appNameBytes, "UTF8");
                    Log.d("PodMode", "AppCmd " + appName);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }

                break;

            case AppAck:
                break;

            case GetUpdateFlag:
                respBytes = new byte[] { 0x00, 0x0A, mUpdateFlag };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;
            case SetUpdateFlag:
                mUpdateFlag = pCommand.params[0];
                respBytes = new byte[] { 0x00, 0x01 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;
            case SwitchToMainPlaylist:
                if (mPodStatus == podStat.ADVANCEDHACK) {
                    mNowPlaying = 0;
                    mPrevPlaying = 0;
                } else
                    mNowPlaying = 0;

                mRetriever.switchToMainPlaylist();
                respBytes = new byte[] { 0x00, 0x01 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;
            case SwitchToItem:

                int itemNo = 0;

                itemNo = pCommand.params[4] & 0xFF;
                itemNo += ((pCommand.params[3] & 0xFF) << 8);
                itemNo += ((pCommand.params[2] & 0xFF) << 16);
                itemNo += ((pCommand.params[1] & 0xFF) << 24);

                if ((mPodStatus == podStat.ADVANCEDHACK && mNotifyHack)) {
                    mNotifyHack = false;
                } else {
                    if (mRetriever.switchToItem((int) pCommand.params[0], itemNo)) {
                        if (pCommand.params[0] == (byte) 0x05) {
                            mNowPlaying = itemNo;
                            tryToGetAudioFocus();
                            playNextSong(null);
                        }
                    }
                }

                respBytes = new byte[] { 0x00, 0x01 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case GetCountForType:
                respBytes = new byte[] { 0x00, 0x19, 0x00, 0x00, 0x00, 0x00 };
                int num = mRetriever.getCountForType((int) pCommand.params[0]);

                respBytes[5] = (byte) (num & 0xFF);
                respBytes[4] = (byte) ((num >> 8) & 0xFF);
                respBytes[3] = (byte) ((num >> 16) & 0xFF);
                respBytes[2] = (byte) ((num >> 24) & 0xFF);

                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case GetItemNames:
                int startPos = 0;
                int count = 0;

                startPos = pCommand.params[4] & 0xFF;
                startPos += ((pCommand.params[3] & 0xFF) << 8);
                startPos += ((pCommand.params[2] & 0xFF) << 16);
                startPos += ((pCommand.params[1] & 0xFF) << 24);

                count = pCommand.params[8] & 0xFF;
                count += ((pCommand.params[7] & 0xFF) << 8);
                count += ((pCommand.params[6] & 0xFF) << 16);
                count += ((pCommand.params[5] & 0xFF) << 24);

                String[] itemNames = mRetriever.GetItemNames((int) pCommand.params[0], startPos, count);

                if (itemNames != null) {
                    for (int i = 0; i < itemNames.length; i++) {
                        byte[] part1 = { (byte) 0x00, (byte) 0x1B, (byte) (startPos >>> 24),
                                (byte) (startPos >>> 16), (byte) (startPos >>> 8), (byte) startPos };

                        startPos++;

                        respBytes = new String(new String(part1) + itemNames[i] + '\0').getBytes();
                        pResponse = new podResponse(pCommand, respBytes);
                        serialWrite(pResponse.getBytes());
                    }
                }
                break;

            case GetTimeStatus:
                respBytes = new byte[] { 0x00, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

                if (mState != State.Preparing && mState != State.Retrieving) {

                    int trackLen = 0;

                    if (mPlayer != null)
                        trackLen = mPlayer.getDuration();
                    respBytes[2] = (byte) (trackLen >>> 24);
                    respBytes[3] = (byte) (trackLen >>> 16);
                    respBytes[4] = (byte) (trackLen >>> 8);
                    respBytes[5] = (byte) trackLen;

                    int elapsedTime = 0;
                    if (mPlayer != null)
                        elapsedTime = mPlayer.getCurrentPosition();

                    respBytes[6] = (byte) (elapsedTime >>> 24);
                    respBytes[7] = (byte) (elapsedTime >>> 16);
                    respBytes[8] = (byte) (elapsedTime >>> 8);
                    respBytes[9] = (byte) elapsedTime;

                    switch (mState) {
                    case Stopped:
                        respBytes[10] = (byte) 0x00;
                        break;
                    case Playing:
                        respBytes[10] = (byte) 0x01;
                        break;
                    case Paused:
                        respBytes[10] = (byte) 0x02;
                        break;
                    case Preparing:
                        respBytes[10] = (byte) 0x01;
                        break;
                    case Retrieving:
                        respBytes[10] = (byte) 0x01;
                        break;
                    }
                }

                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case GetPlaylistPos:
                respBytes = new byte[] { 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00 };

                respBytes[2] = (byte) ((mNowPlaying) >>> 24);
                respBytes[3] = (byte) ((mNowPlaying) >>> 16);
                respBytes[4] = (byte) ((mNowPlaying) >>> 8);
                respBytes[5] = (byte) mNowPlaying;

                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case GetSongTitle:
                byte[] part1 = new byte[] { 0x00, 0x21 };
                int index;
                index = pCommand.params[3] & 0xFF;
                index += ((pCommand.params[2] & 0xFF) << 8);
                index += ((pCommand.params[1] & 0xFF) << 16);
                index += ((pCommand.params[0] & 0xFF) << 24);

                if (index == -1)
                    index = 0;

                respBytes = new String(new String(part1) + mRetriever.getTrack(index).title + '\0').getBytes();

                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case GetSongArtist:
                part1 = new byte[] { 0x00, 0x23 };
                index = pCommand.params[3] & 0xFF;
                index += ((pCommand.params[2] & 0xFF) << 8);
                index += ((pCommand.params[1] & 0xFF) << 16);
                index += ((pCommand.params[0] & 0xFF) << 24);

                if (index == -1)
                    index = 0;

                respBytes = new String(new String(part1) + mRetriever.getTrack(index).artist + '\0').getBytes();

                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case GetSongAlbum:
                part1 = new byte[] { 0x00, 0x25 };
                index = pCommand.params[3] & 0xFF;
                index += ((pCommand.params[2] & 0xFF) << 8);
                index += ((pCommand.params[1] & 0xFF) << 16);
                index += ((pCommand.params[0] & 0xFF) << 24);

                if (index == -1)
                    index = 0;

                respBytes = new String(new String(part1) + mRetriever.getTrack(index).album + '\0').getBytes();

                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case PollingMode:
                respBytes = new byte[] { 0x00, 0x01 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());

                mPollSpeed = (byte) pCommand.params[0];
                if (pCommand.params[0] == (byte) 0x01 && mUpdateFlag != (byte) 0x01) {
                    mUpdateFlag = pCommand.params[0];

                    if (mMediaChangeTimer == null)
                        mMediaChangeTimer = new Timer();

                    mMediaChangeTimer.scheduleAtFixedRate(mMediaChangeTask, 0, 500);

                } else if (pCommand.params[0] == (byte) 0x00 && mUpdateFlag != (byte) 0x00) {

                    mUpdateFlag = pCommand.params[0];
                    if (mMediaChangeTimer != null)
                        mMediaChangeTimer.cancel();
                }

                break;

            case ExecPlaylist:
                itemNo = pCommand.params[3] & 0xFF;
                itemNo += ((pCommand.params[2] & 0xFF) << 8);
                itemNo += ((pCommand.params[1] & 0xFF) << 16);
                itemNo += ((pCommand.params[0] & 0xFF) << 24);

                if (itemNo == -1)
                    itemNo = 0;

                mRetriever.ExecPlaylist();

                if (mPodShuffleMode == modeStat.Songs)
                    mRetriever.shuffleTracks();

                mNowPlaying = itemNo;
                tryToGetAudioFocus();
                playNextSong(null);

                respBytes = new byte[] { 0x00, 0x01 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case PlaybackControl:
                switch (pCommand.params[0]) {
                case 0x01:
                    // processStopRequest();
                    processTogglePlaybackRequest();
                    break;
                case 0x02:
                    processStopRequest();
                    break;
                case 0x03:
                    processPauseRequest();
                    processSkipRequest();
                    break;
                case 0x04:
                    processPauseRequest();
                    processSkipRwdRequest();
                    break;
                case 0x05:
                    // processSkipRequest();
                    break;
                case 0x06:
                    // processRewindRequest();
                    break;
                case 0x07:
                    // TODO Add Stop FF/RR function
                    break;
                }

                respBytes = new byte[] { 0x00, 0x01 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case GetPlayListSongNum:
                respBytes = new byte[] { 0x00, 0x36, 0x00, 0x00, 0x00, 0x00 };
                num = mRetriever.getCount();

                respBytes[5] = (byte) (num & 0xFF);
                respBytes[4] = (byte) ((num >> 8) & 0xFF);
                respBytes[3] = (byte) ((num >> 16) & 0xFF);
                respBytes[2] = (byte) ((num >> 24) & 0xFF);

                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case JumpToSong:
                itemNo = pCommand.params[3] & 0xFF;
                itemNo += ((pCommand.params[2] & 0xFF) << 8);
                itemNo += ((pCommand.params[1] & 0xFF) << 16);
                itemNo += ((pCommand.params[0] & 0xFF) << 24);

                mNowPlaying = itemNo;
                tryToGetAudioFocus();
                playNextSong(null);

                respBytes = new byte[] { 0x00, 0x01 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case FrankPlaylist:
                respBytes = new byte[] { 0x00, 0x4F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
                num = mRetriever.getPlaylistNum();

                if (num != -1) {
                    respBytes[5] = (byte) (num & 0xFF);
                    respBytes[4] = (byte) ((num >> 8) & 0xFF);
                    respBytes[3] = (byte) ((num >> 16) & 0xFF);
                    respBytes[2] = (byte) ((num >> 24) & 0xFF);
                }

                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case StartID:
                respBytes = new byte[] { 0x02 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case GetPodProtocols:
                // start
                respBytes = new byte[] { 0x02 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                if (pCommand.rawBytes[13] == (byte) 0x00 && pCommand.rawBytes[14] == (byte) 0x00
                        && pCommand.rawBytes[15] == (byte) 0x00 && pCommand.rawBytes[16] == (byte) 0x00) {
                    // respBytes = new byte[] { 0x00 };
                    // pResponse = new podResponse(pCommand, respBytes);
                    // serialWrite(pResponse.getBytes());

                } else {
                    respBytes = new byte[] { 0x14 };
                    pResponse = new podResponse(pCommand, respBytes);
                    serialWrite(pResponse.getBytes());
                }

                break;

            case DeviceAuthInfo:
                if (pCommand.length == 4) {
                    respBytes = new byte[] { 0x16 };
                    pResponse = new podResponse(pCommand, respBytes);
                    serialWrite(pResponse.getBytes());

                    respBytes = new byte[] { 0x17, 0x01 };
                    pResponse = new podResponse(pCommand, respBytes);
                    serialWrite(pResponse.getBytes());
                } else {

                    if (pCommand.rawBytes[7] != pCommand.rawBytes[8]) {
                        respBytes = new byte[] { 0x02 };
                        pResponse = new podResponse(pCommand, respBytes);
                        serialWrite(pResponse.getBytes());

                    } else {
                        respBytes = new byte[] { 0x16 };
                        pResponse = new podResponse(pCommand, respBytes);
                        serialWrite(pResponse.getBytes());

                        respBytes = new byte[] { 0x17, 0x02 };
                        pResponse = new podResponse(pCommand, respBytes);
                        serialWrite(pResponse.getBytes());
                    }
                }

                break;

            case DeviceAuthSig:
                respBytes = new byte[] { 0x19 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case GetPodOptions:
                // start
                if (pCommand.rawBytes[5] == 0x00)
                    respBytes = new byte[] { 0x4C };
                else
                    respBytes = new byte[] { (byte) 0x02, 0x04 };

                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case GetPodOption:
                // start
                respBytes = new byte[] { 0x25 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case SetIdTokens:
                respBytes = new byte[] { 0x3A };
                pResponse = new podResponse(pCommand, respBytes);
                if (mAccessoryName == null) {
                    mAccessoryName = pResponse.accessoryName;
                    mAccessoryMnf = pResponse.accessoryMnf;
                    mAccessoryModel = pResponse.accessoryModel;
                    mHTTPsend = true;
                }
                serialWrite(pResponse.getBytes());
                break;

            case EndID:
                respBytes = new byte[] { 0x3C };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());

                respBytes = new byte[] { 0x14 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case GetProtoVersion:
                respBytes = new byte[] { 0x0F };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case DeviceDetails:
                respBytes = new byte[] { 0x02 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case DevName:
                respBytes = new byte[] { 0x00, 0x15, 0x50, 0x6F, 0x64, 0x4D, 0x6F, 0x64, 0x65, 0x00 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case DevTypeSize:
                pResponse = new podResponse(pCommand, DEVTYPESIZE);
                serialWrite(pResponse.getBytes());
                break;

            case StateInfo:
                respBytes = new byte[] { 0x0D };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case RemoteNotify:
                respBytes = new byte[] { 0x02 };
                pResponse = new podResponse(pCommand, respBytes);

                serialWrite(pResponse.getBytes());
                break;

            case SwitchRemote:
                mPodStatus = podStat.SIMPLEREMOTE;
                break;

            case ReqAdvRemote:
                respBytes = new byte[] { 0x04, 0x00 };

                if (mPodStatus == podStat.ADVANCEDREMOTE || mPodStatus == podStat.ADVANCEDHACK)
                    respBytes[1] = 0x04;

                pResponse = new podResponse(pCommand, respBytes);

                serialWrite(pResponse.getBytes());
                break;

            case StartAdvRemote:
                mPodStatus = podStat.ADVANCEDREMOTE;
                if (!mAdvancedRemoteApp.equals(PACKAGENAME))
                    mPodStatus = podStat.ADVANCEDHACK;

                respBytes = new byte[] { 0x2 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case EndAdvRemote:
                mPodStatus = podStat.WAITING;
                respBytes = new byte[] { 0x2 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case GetSoftVersion:
                respBytes = new byte[] { 0x0A };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case GetSerialNum:
                respBytes = new byte[] { 0x0C };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case DevModel:
                respBytes = new byte[] { 0x0E };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case SwitchAdvanced:
                mPodStatus = podStat.ADVANCEDREMOTE;
                if (!mAdvancedRemoteApp.equals(PACKAGENAME))
                    mPodStatus = podStat.ADVANCEDHACK;
                break;

            case SetRepeatMode:
                if (pCommand.params[0] == (byte) 0x00)
                    mPodRepeatMode = modeStat.Off;
                else if (pCommand.params[0] == (byte) 0x01)
                    mPodRepeatMode = modeStat.Songs;
                else
                    mPodRepeatMode = modeStat.Albums;
                respBytes = new byte[] { 0x00, 0x01 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case GetRepeatMode:
                respBytes = new byte[] { 0x00, 0x30, 0x00 };
                if (mPodRepeatMode == modeStat.Songs)
                    respBytes[2] = 0x01;
                if (mPodRepeatMode == modeStat.Albums)
                    respBytes[2] = 0x02;
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case SetShuffleMode:
                if (pCommand.params[0] == (byte) 0x00)
                    mPodShuffleMode = modeStat.Off;
                else if (pCommand.params[0] == (byte) 0x01)
                    mPodShuffleMode = modeStat.Songs;
                else
                    mPodShuffleMode = modeStat.Albums;

                respBytes = new byte[] { 0x00, 0x01 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case GetShuffleMode:
                respBytes = new byte[] { 0x00, 0x2D, 0x00 };
                if (mPodShuffleMode == modeStat.Songs)
                    respBytes[2] = 0x01;
                if (mPodShuffleMode == modeStat.Albums)
                    respBytes[2] = 0x02;
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            case GetScreenSize:
                respBytes = new byte[] { 0x00, 0x34 };
                pResponse = new podResponse(pCommand, respBytes);
                serialWrite(pResponse.getBytes());
                break;

            default:
                break;
            }

        }
    }
}

From source file:com.actionbarsherlock.internal.widget.IcsAdapterView.java

/**
 * Searches the adapter for a position matching mSyncRowId. The search starts at mSyncPosition
 * and then alternates between moving up and moving down until 1) we find the right position, or
 * 2) we run out of time, or 3) we have looked at every position
 *
 * @return Position of the row that matches mSyncRowId, or {@link #INVALID_POSITION} if it can't
 *         be found//from   w w  w  .j  a  v  a  2s.  co m
 */
int findSyncPosition() {
    int count = mItemCount;

    if (count == 0) {
        return INVALID_POSITION;
    }

    long idToMatch = mSyncRowId;
    int seed = mSyncPosition;

    // If there isn't a selection don't hunt for it
    if (idToMatch == INVALID_ROW_ID) {
        return INVALID_POSITION;
    }

    // Pin seed to reasonable values
    seed = Math.max(0, seed);
    seed = Math.min(count - 1, seed);

    long endTime = SystemClock.uptimeMillis() + SYNC_MAX_DURATION_MILLIS;

    long rowId;

    // first position scanned so far
    int first = seed;

    // last position scanned so far
    int last = seed;

    // True if we should move down on the next iteration
    boolean next = false;

    // True when we have looked at the first item in the data
    boolean hitFirst;

    // True when we have looked at the last item in the data
    boolean hitLast;

    // Get the item ID locally (instead of getItemIdAtPosition), so
    // we need the adapter
    T adapter = getAdapter();
    if (adapter == null) {
        return INVALID_POSITION;
    }

    while (SystemClock.uptimeMillis() <= endTime) {
        rowId = adapter.getItemId(seed);
        if (rowId == idToMatch) {
            // Found it!
            return seed;
        }

        hitLast = last == count - 1;
        hitFirst = first == 0;

        if (hitLast && hitFirst) {
            // Looked at everything
            break;
        }

        if (hitFirst || (next && !hitLast)) {
            // Either we hit the top, or we are trying to move down
            last++;
            seed = last;
            // Try going up next time
            next = false;
        } else if (hitLast || (!next && !hitFirst)) {
            // Either we hit the bottom, or we are trying to move up
            first--;
            seed = first;
            // Try going down next time
            next = true;
        }

    }

    return INVALID_POSITION;
}

From source file:com.undatech.opaque.RemoteCanvasActivity.java

public void showKbdIcon() {
    kbdIcon.show();
    canvas.handler.removeCallbacks(kbdIconHider);
    canvas.handler.postAtTime(kbdIconHider, SystemClock.uptimeMillis() + hideKbdIconDelay);
}

From source file:com.corporatetaxi.TaxiOntheWay_Activity.java

private void animateMarker(final Marker marker, final LatLng toPosition, final boolean hideMarker) {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    Projection proj = map.getProjection();
    Point startPoint = proj.toScreenLocation(marker.getPosition());
    final LatLng startLatLng = proj.fromScreenLocation(startPoint);//marker1.getPosition();
    final long duration = 600;

    final Interpolator interpolator = new LinearInterpolator();
    handler.post(new Runnable() {
        @Override//from ww  w.j ava2  s .  co  m
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed / duration);
            double lng = t * toPosition.longitude + (1 - t) * startLatLng.longitude;
            double lat = t * toPosition.latitude + (1 - t) * startLatLng.latitude;
            marker.setPosition(new LatLng(lat, lng));

            if (t < 1.0) {
                // Post again 16ms later.
                handler.postDelayed(this, 16);
            } else {
                if (hideMarker) {
                    marker.setVisible(false);
                } else {
                    marker.setVisible(true);
                }
            }
            map.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lng)));
        }
    });

}

From source file:com.google.corp.productivity.specialprojects.android.samples.fft.AnalyzeActivity.java

public void invalidateGraphView(int viewMask) {
    if (isInvalidating) {
        return;//from ww  w  . ja v a 2  s. c  o m
    }
    isInvalidating = true;
    long frameTime; // time delay for next frame
    if (graphView.getShowMode() != 0) {
        frameTime = 1000 / 8; // use a much lower frame rate for spectrogram
    } else {
        frameTime = 1000 / 20;
    }
    long t = SystemClock.uptimeMillis();
    if (t >= timeToUpdate) { // limit frame rate
        timeToUpdate += frameTime;
        if (timeToUpdate < t) { // catch up current time
            timeToUpdate = t + frameTime;
        }
        idPaddingInvalidate = false;
        // Here graphView.isBusy() can be true because graphView.pushRawSpectrum() is running on Looper thread
        // Take care of synchronization of graphView.spectrogramColors and spectrogramColorsPt,
        // and then here just do invalidate().
        if ((viewMask & VIEW_MASK_graphView) != 0)
            graphView.invalidate();
        // RMS
        if ((viewMask & VIEW_MASK_textview_RMS) != 0)
            refreshRMSLabel();
        // peak frequency
        if ((viewMask & VIEW_MASK_textview_peak) != 0)
            refreshPeakLabel();
        if ((viewMask & VIEW_MASK_CursorLabel) != 0)
            refreshCursorLabel();
        if ((viewMask & VIEW_MASK_RecTimeLable) != 0)
            refreshRecTimeLable();
    } else {
        if (idPaddingInvalidate == false) {
            idPaddingInvalidate = true;
            paddingViewMask = viewMask;
            paddingInvalidateHandler.postDelayed(paddingInvalidateRunnable, timeToUpdate - t + 1);
        } else {
            paddingViewMask |= viewMask;
        }
    }
    isInvalidating = false;
}

From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java

@Override
protected synchronized void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Drawable d = mCurrentDrawable;//from   w  ww  .j ava2s.c om
    if (d != null) {
        // Translate canvas so a indeterminate circular progress bar with padding
        // rotates properly in its animation
        canvas.save();
        canvas.translate(getPaddingLeft() + mIndeterminateRealLeft, getPaddingTop() + mIndeterminateRealTop);
        long time = getDrawingTime();
        if (mAnimation != null) {
            mAnimation.getTransformation(time, mTransformation);
            float scale = mTransformation.getAlpha();
            try {
                mInDrawing = true;
                d.setLevel((int) (scale * MAX_LEVEL));
            } finally {
                mInDrawing = false;
            }
            if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) {
                mLastDrawTime = SystemClock.uptimeMillis();
                postInvalidateDelayed(mAnimationResolution);
            }
        }
        d.draw(canvas);
        canvas.restore();
        if (mShouldStartAnimationDrawable && d instanceof Animatable) {
            ((Animatable) d).start();
            mShouldStartAnimationDrawable = false;
        }
    }
}