Example usage for android.view KeyEvent getDownTime

List of usage examples for android.view KeyEvent getDownTime

Introduction

In this page you can find the example usage for android.view KeyEvent getDownTime.

Prototype

public final long getDownTime() 

Source Link

Document

Retrieve the time of the most recent key down event, in the android.os.SystemClock#uptimeMillis time base.

Usage

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

@Override
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
    Logger.d(TAG, "onKeyUp keycode=%d", keyCode);
    switch (keyCode) {
    // Issue 248//from   w ww.jav a 2s . co  m
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (!isInputViewShown()) {
            return super.onKeyUp(keyCode, event);
        }
        if (mAskPrefs.useVolumeKeyForLeftRight()) {
            // no need of vol up/down sound
            return true;
        }
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (getInputView() != null && getInputView().isShown() && getInputView().isShifted()) {
            event = new KeyEvent(event.getDownTime(), event.getEventTime(), event.getAction(),
                    event.getKeyCode(), event.getRepeatCount(), event.getDeviceId(), event.getScanCode(),
                    KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON);
            InputConnection ic = getCurrentInputConnection();
            if (ic != null)
                ic.sendKeyEvent(event);

            return true;
        }
        break;
    case KeyEvent.KEYCODE_ALT_LEFT:
    case KeyEvent.KEYCODE_ALT_RIGHT:
    case KeyEvent.KEYCODE_SHIFT_LEFT:
    case KeyEvent.KEYCODE_SHIFT_RIGHT:
    case KeyEvent.KEYCODE_SYM:
        mMetaState = MyMetaKeyKeyListener.handleKeyUp(mMetaState, keyCode, event);
        Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyUp"));
        setInputConnectionMetaStateAsCurrentMetaKeyKeyListenerState();
        break;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:org.pocketworkstation.pckeyboard.LatinIME.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
        // Enable shift key and DPAD to do selections
        if (inputView != null && inputView.isShown() && inputView.getShiftState() == Keyboard.SHIFT_ON) {
            event = new KeyEvent(event.getDownTime(), event.getEventTime(), event.getAction(),
                    event.getKeyCode(), event.getRepeatCount(), event.getDeviceId(), event.getScanCode(),
                    KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON);
            InputConnection ic = getCurrentInputConnection();
            if (ic != null)
                ic.sendKeyEvent(event);//from ww w. java2 s  .  com
            return true;
        }
        break;
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (!mVolUpAction.equals("none") && isKeyboardVisible()) {
            return doSwipeAction(mVolUpAction);
        }
        break;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (!mVolDownAction.equals("none") && isKeyboardVisible()) {
            return doSwipeAction(mVolDownAction);
        }
        break;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:org.distantshoresmedia.keyboard.LatinIME.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        // If tutorial is visible, don't allow dpad to work
        if (mTutorial != null) {
            return true;
        }//from   w w w  .j a v a  2  s  . c  om
        TKKeyboardView inputView = mKeyboardSwitcher.getInputView();
        // Enable shift key and DPAD to do selections
        if (inputView != null && inputView.isShown() && inputView.getShiftState() == Keyboard.SHIFT_ON) {
            event = new KeyEvent(event.getDownTime(), event.getEventTime(), event.getAction(),
                    event.getKeyCode(), event.getRepeatCount(), event.getDeviceId(), event.getScanCode(),
                    KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON);
            InputConnection ic = getCurrentInputConnection();
            if (ic != null)
                ic.sendKeyEvent(event);
            return true;
        }
        break;
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (!mVolUpAction.equals("none") && isKeyboardVisible()) {
            return doSwipeAction(mVolUpAction);
        }
        break;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (!mVolDownAction.equals("none") && isKeyboardVisible()) {
            return doSwipeAction(mVolDownAction);
        }
        break;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.fishstix.dosboxfree.DBGLSurfaceView.java

private boolean handleKey(int keyCode, final KeyEvent event) {
    if (mDebug)//from  w w  w .  java2  s  .  com
        Log.d("DosBoxTurbo", "handleKey keyCode=" + keyCode);
    int tKeyCode = 0;

    // check for xperia play back case
    if (keyCode == KeyEvent.KEYCODE_BACK && event.isAltPressed()) {
        int backval = customMap.get(DosBoxPreferences.XPERIA_BACK_BUTTON);
        if (backval > 0) {
            // Special Sony XPeria Play case
            if (mEnableDpad) {
                // FIRE2
                if ((mInputMode == INPUT_MODE_MOUSE) || (mInputMode == INPUT_MODE_REAL_MOUSE)) {
                    DosBoxControl.nativeMouse(0, 0, 0, 0, (event.getAction() == KeyEvent.ACTION_DOWN) ? 0 : 1,
                            BTN_B);
                } else if ((mInputMode == INPUT_MODE_JOYSTICK) || (mInputMode == INPUT_MODE_REAL_JOYSTICK)) {
                    DosBoxControl.nativeJoystick(0, 0, (event.getAction() == KeyEvent.ACTION_DOWN) ? 0 : 1,
                            BTN_B);
                }
            } else {
                // sony xperia play O (circle) button
                DosBoxControl.sendNativeKey(backval, (event.getAction() == KeyEvent.ACTION_DOWN), mModifierCtrl,
                        mModifierAlt, mModifierShift);
                return true; // consume event
            }
        }
        return true; // consume event
    }

    // Handle all other keyevents
    int value = customMap.get(keyCode);

    if (value > 0) {
        // found a valid mapping
        tKeyCode = getMappedKeyCode(value, event);
        if (tKeyCode > MAP_NONE) {
            DosBoxControl.sendNativeKey(tKeyCode, (event.getAction() == KeyEvent.ACTION_DOWN), mModifierCtrl,
                    mModifierAlt, mModifierShift);
            return true; // consume KeyEvent
        } else if (tKeyCode == MAP_EVENT_CONSUMED) {
            return true;
        }
    }

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // fishstix, allow remap of Android back button
        // catch no mapping
        if (event.getAction() == KeyEvent.ACTION_UP) {
            DBMenuSystem.doConfirmQuit(mParent);
        }
        return true;
    }

    switch (keyCode) {
    case KeyEvent.KEYCODE_UNKNOWN:
        break;

    default:
        boolean down = (event.getAction() == KeyEvent.ACTION_DOWN);
        if (mDebug)
            Log.d("DosBoxTurbo", "handleKey (default) keyCode=" + keyCode + " down=" + down);

        if (!down || (event.getRepeatCount() == 0)) {
            int unicode = event.getUnicodeChar();

            // filter system generated keys, but not hardware keypresses
            if ((event.isAltPressed() || event.isShiftPressed()) && (unicode == 0)
                    && ((event.getFlags() & KeyEvent.FLAG_FROM_SYSTEM) == 0))
                break;

            //fixed alt key problem for physical keyboard with only left alt
            if ((!mUseLeftAltOn) && (keyCode == KeyEvent.KEYCODE_ALT_LEFT)) {
                break;
            }

            if ((!mUseLeftAltOn) && (keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT)) {
                break;
            }

            if ((keyCode > 255) || (unicode > 255)) {
                //unknown keys
                break;
            }

            keyCode = keyCode | (unicode << 8);

            long diff = event.getEventTime() - event.getDownTime();

            if (!down && (diff < 50)) {
                //simulate as long press
                if (mDebug)
                    Log.d("DosBoxTurbo", "LongPress consumed keyCode=" + keyCode + " down=" + down);
                mKeyHandler.removeMessages(keyCode);
                mKeyHandler.sendEmptyMessageDelayed(keyCode, BUTTON_REPEAT_DELAY - diff);
            } else if (down && mKeyHandler.hasMessages(keyCode)) {
                if (mDebug)
                    Log.d("DosBoxTurbo", "KeyUp consumed keyCode=" + keyCode + " down=" + down);
                //there is an key up in queue, should be repeated event
            } else {
                boolean result = DosBoxControl.sendNativeKey(keyCode, down, mModifierCtrl, mModifierAlt,
                        mModifierShift);
                if (!down) {
                    mModifierCtrl = false;
                    mModifierAlt = false;
                    mModifierShift = false;
                }
                return result;
            }
        }
    }

    return false;
}

From source file:org.connectbot.ConsoleFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.frg_console, container, false);

    this.inflater = inflater;

    flip = (ViewFlipper) v.findViewById(R.id.console_flip);
    empty = (TextView) v.findViewById(android.R.id.empty);

    stringPromptGroup = (RelativeLayout) v.findViewById(R.id.console_password_group);
    stringPromptInstructions = (TextView) v.findViewById(R.id.console_password_instructions);
    stringPrompt = (EditText) v.findViewById(R.id.console_password);
    stringPrompt.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP)
                return false;
            if (keyCode != KeyEvent.KEYCODE_ENTER)
                return false;

            // pass collected password down to current terminal
            String value = stringPrompt.getText().toString();

            PromptHelper helper = getCurrentPromptHelper();
            if (helper == null)
                return false;
            helper.setResponse(value);//from  w ww .  ja  va 2s  .c  o m

            // finally clear password for next user
            stringPrompt.setText("");
            updatePromptVisible();

            return true;
        }
    });

    booleanPromptGroup = (RelativeLayout) v.findViewById(R.id.console_boolean_group);
    booleanPrompt = (TextView) v.findViewById(R.id.console_prompt);

    booleanYes = (Button) v.findViewById(R.id.console_prompt_yes);
    booleanYes.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            PromptHelper helper = getCurrentPromptHelper();
            if (helper == null)
                return;
            helper.setResponse(Boolean.TRUE);
            updatePromptVisible();
        }
    });

    booleanNo = (Button) v.findViewById(R.id.console_prompt_no);
    booleanNo.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            PromptHelper helper = getCurrentPromptHelper();
            if (helper == null)
                return;
            helper.setResponse(Boolean.FALSE);
            updatePromptVisible();
        }
    });

    // preload animations for terminal switching
    slide_left_in = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_left_in);
    slide_left_out = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_left_out);
    slide_right_in = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_right_in);
    slide_right_out = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_right_out);

    fade_out_delayed = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_out_delayed);
    fade_stay_hidden = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_stay_hidden);

    // Preload animation for keyboard button
    keyboard_fade_in = AnimationUtils.loadAnimation(getActivity(), R.anim.keyboard_fade_in);
    keyboard_fade_out = AnimationUtils.loadAnimation(getActivity(), R.anim.keyboard_fade_out);

    inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);

    final RelativeLayout keyboardGroup = (RelativeLayout) v.findViewById(R.id.keyboard_group);

    mKeyboardButton = (ImageView) v.findViewById(R.id.button_keyboard);
    mKeyboardButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View flip = findCurrentView(R.id.console_flip);
            if (flip == null)
                return;

            inputManager.showSoftInput(flip, InputMethodManager.SHOW_FORCED);
            keyboardGroup.setVisibility(View.GONE);
        }
    });

    final ImageView ctrlButton = (ImageView) v.findViewById(R.id.button_ctrl);
    ctrlButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View flip = findCurrentView(R.id.console_flip);
            if (flip == null)
                return;
            TerminalView terminal = (TerminalView) flip;

            TerminalKeyListener handler = terminal.bridge.getKeyHandler();
            handler.metaPress(TerminalKeyListener.META_CTRL_ON);

            keyboardGroup.setVisibility(View.GONE);
        }
    });

    final ImageView escButton = (ImageView) v.findViewById(R.id.button_esc);
    escButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View flip = findCurrentView(R.id.console_flip);
            if (flip == null)
                return;
            TerminalView terminal = (TerminalView) flip;

            TerminalKeyListener handler = terminal.bridge.getKeyHandler();
            handler.sendEscape();

            keyboardGroup.setVisibility(View.GONE);
        }
    });

    // detect fling gestures to switch between terminals
    final GestureDetector detect = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
        private float totalY = 0;

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

            final float distx = e2.getRawX() - e1.getRawX();
            final float disty = e2.getRawY() - e1.getRawY();
            final int goalwidth = flip.getWidth() / 2;

            // need to slide across half of display to trigger console change
            // make sure user kept a steady hand horizontally
            if (Math.abs(disty) < (flip.getHeight() / 4)) {
                if (distx > goalwidth) {
                    shiftCurrentTerminal(SHIFT_RIGHT);
                    return true;
                }

                if (distx < -goalwidth) {
                    shiftCurrentTerminal(SHIFT_LEFT);
                    return true;
                }

            }

            return false;
        }

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

            // if copying, then ignore
            if (copySource != null && copySource.isSelectingForCopy())
                return false;

            if (e1 == null || e2 == null)
                return false;

            // if releasing then reset total scroll
            if (e2.getAction() == MotionEvent.ACTION_UP) {
                totalY = 0;
            }

            // activate consider if within x tolerance
            if (Math.abs(e1.getX() - e2.getX()) < ViewConfiguration.getTouchSlop() * 4) {

                View flip = findCurrentView(R.id.console_flip);
                if (flip == null)
                    return false;
                TerminalView terminal = (TerminalView) flip;

                // estimate how many rows we have scrolled through
                // accumulate distance that doesn't trigger immediate scroll
                totalY += distanceY;
                final int moved = (int) (totalY / terminal.bridge.charHeight);

                // consume as scrollback only if towards right half of screen
                if (e2.getX() > flip.getWidth() / 2) {
                    if (moved != 0) {
                        int base = terminal.bridge.buffer.getWindowBase();
                        terminal.bridge.buffer.setWindowBase(base + moved);
                        totalY = 0;
                        return true;
                    }
                } else {
                    // otherwise consume as pgup/pgdown for every 5 lines
                    if (moved > 5) {
                        ((vt320) terminal.bridge.buffer).keyPressed(vt320.KEY_PAGE_DOWN, ' ', 0);
                        terminal.bridge.tryKeyVibrate();
                        totalY = 0;
                        return true;
                    } else if (moved < -5) {
                        ((vt320) terminal.bridge.buffer).keyPressed(vt320.KEY_PAGE_UP, ' ', 0);
                        terminal.bridge.tryKeyVibrate();
                        totalY = 0;
                        return true;
                    }

                }

            }

            return false;
        }

    });

    flip.setLongClickable(true);
    flip.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {

            // when copying, highlight the area
            if (copySource != null && copySource.isSelectingForCopy()) {
                int row = (int) Math.floor(event.getY() / copySource.charHeight);
                int col = (int) Math.floor(event.getX() / copySource.charWidth);

                SelectionArea area = copySource.getSelectionArea();

                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    // recording starting area
                    if (area.isSelectingOrigin()) {
                        area.setRow(row);
                        area.setColumn(col);
                        lastTouchRow = row;
                        lastTouchCol = col;
                        copySource.redraw();
                    }
                    return true;
                case MotionEvent.ACTION_MOVE:
                    /* ignore when user hasn't moved since last time so
                     * we can fine-tune with directional pad
                     */
                    if (row == lastTouchRow && col == lastTouchCol)
                        return true;

                    // if the user moves, start the selection for other corner
                    area.finishSelectingOrigin();

                    // update selected area
                    area.setRow(row);
                    area.setColumn(col);
                    lastTouchRow = row;
                    lastTouchCol = col;
                    copySource.redraw();
                    return true;
                case MotionEvent.ACTION_UP:
                    /* If they didn't move their finger, maybe they meant to
                     * select the rest of the text with the directional pad.
                     */
                    if (area.getLeft() == area.getRight() && area.getTop() == area.getBottom()) {
                        return true;
                    }

                    // copy selected area to clipboard
                    String copiedText = area.copyFrom(copySource.buffer);

                    clipboard.setText(copiedText);
                    Toast.makeText(getActivity(), getString(R.string.console_copy_done, copiedText.length()),
                            Toast.LENGTH_LONG).show();
                    // fall through to clear state

                case MotionEvent.ACTION_CANCEL:
                    // make sure we clear any highlighted area
                    area.reset();
                    copySource.setSelectingForCopy(false);
                    copySource.redraw();
                    return true;
                }
            }

            Configuration config = getResources().getConfiguration();

            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                lastX = event.getX();
                lastY = event.getY();
            } else if (event.getAction() == MotionEvent.ACTION_UP && keyboardGroup.getVisibility() == View.GONE
                    && event.getEventTime() - event.getDownTime() < CLICK_TIME
                    && Math.abs(event.getX() - lastX) < MAX_CLICK_DISTANCE
                    && Math.abs(event.getY() - lastY) < MAX_CLICK_DISTANCE) {
                keyboardGroup.startAnimation(keyboard_fade_in);
                keyboardGroup.setVisibility(View.VISIBLE);

                mUIHandler.postDelayed(new Runnable() {
                    public void run() {
                        if (keyboardGroup.getVisibility() == View.GONE)
                            return;

                        keyboardGroup.startAnimation(keyboard_fade_out);
                        keyboardGroup.setVisibility(View.GONE);
                    }
                }, KEYBOARD_DISPLAY_TIME);
            }

            // pass any touch events back to detector
            return detect.onTouchEvent(event);
        }

    });

    return v;
}

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

public void run() {
    podCommand pCommand = null;/* w  w w .  j av  a  2  s.  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;
            }

        }
    }
}