Example usage for android.view KeyEvent getUnicodeChar

List of usage examples for android.view KeyEvent getUnicodeChar

Introduction

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

Prototype

public int getUnicodeChar() 

Source Link

Document

Gets the Unicode character generated by the specified key and meta key state combination.

Usage

From source file:website.openeng.anki.Reviewer.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    char keyPressed = (char) event.getUnicodeChar();
    if (mAnswerField != null && !mAnswerField.isFocused()) {
        if (sDisplayAnswer) {
            if (keyPressed == '1') {
                answerCard(EASE_1);//w  w  w  .j  a v  a2s . c o  m
                return true;
            }
            if (keyPressed == '2') {
                answerCard(EASE_2);
                return true;
            }
            if (keyPressed == '3') {
                answerCard(EASE_3);
                return true;
            }
            if (keyPressed == '4') {
                answerCard(EASE_4);
                return true;
            }
            if (keyCode == KeyEvent.KEYCODE_SPACE || keyCode == KeyEvent.KEYCODE_ENTER
                    || keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER) {
                answerCard(getDefaultEase());
                return true;
            }
        }
        if (keyPressed == 'e') {
            editCard();
            return true;
        }
        if (keyPressed == '*') {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_MARK_CARD, mMarkCardHandler,
                    new DeckTask.TaskData(mCurrentCard, 0));
            return true;
        }
        if (keyPressed == '-') {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler,
                    new DeckTask.TaskData(mCurrentCard, 4));
            return true;
        }
        if (keyPressed == '=') {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler,
                    new DeckTask.TaskData(mCurrentCard, 0));
            return true;
        }
        if (keyPressed == '@') {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler,
                    new DeckTask.TaskData(mCurrentCard, 1));
            return true;
        }
        if (keyPressed == '!') {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler,
                    new DeckTask.TaskData(mCurrentCard, 2));
            return true;
        }
        if (keyPressed == 'r' || keyCode == KeyEvent.KEYCODE_F5) {
            playSounds(true);
            return true;
        }
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.ichi2.anki.Reviewer.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    char keyPressed = (char) event.getUnicodeChar();
    if (mAnswerField != null && !mAnswerField.isFocused()) {
        if (sDisplayAnswer) {
            if (keyPressed == '1') {
                answerCard(EASE_1);//from w  w w. java  2s.  co m
                return true;
            }
            if (keyPressed == '2') {
                answerCard(EASE_2);
                return true;
            }
            if (keyPressed == '3') {
                answerCard(EASE_3);
                return true;
            }
            if (keyPressed == '4') {
                answerCard(EASE_4);
                return true;
            }
            if (keyCode == KeyEvent.KEYCODE_SPACE || keyCode == KeyEvent.KEYCODE_ENTER
                    || keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER) {
                answerCard(getDefaultEase());
                return true;
            }
        }
        if (keyPressed == 'e') {
            editCard();
            return true;
        }
        if (keyPressed == '*') {
            onMark(mCurrentCard);
            refreshActionBar();
            return true;
        }
        if (keyPressed == '-') {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler,
                    new DeckTask.TaskData(mCurrentCard, 4));
            return true;
        }
        if (keyPressed == '=') {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler,
                    new DeckTask.TaskData(mCurrentCard, 0));
            return true;
        }
        if (keyPressed == '@') {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler,
                    new DeckTask.TaskData(mCurrentCard, 1));
            return true;
        }
        if (keyPressed == '!') {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler,
                    new DeckTask.TaskData(mCurrentCard, 2));
            return true;
        }
        if (keyPressed == 'r' || keyCode == KeyEvent.KEYCODE_F5) {
            playSounds(true);
            return true;
        }

        // different from Anki Desktop
        if (keyPressed == 'z') {
            undo();
            return true;
        }
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.cybrosys.basic.EventListener.java

@Override
public boolean onKey(View vwView, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT);
        return eat;
    }/*from  ww  w  . jav  a 2 s. co  m*/
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true;
    }
    if (keyEvent.getUnicodeChar() == '=') {
        if (action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }
    if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP
            && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) {
        return false;
    }
    if (action == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}

From source file:com.android.calculator2.EventListener.java

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    // Work-around for spurious key event from IME, bug #1639445
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }//from   w  w  w  .j  ava2  s .c  om

    if (keyEvent.getUnicodeChar() == '=') {
        if (action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }

    if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP
            && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) {
        if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) {
            // Tell the handler that text was updated.
            mHandler.onTextChanged();
        }
        return false;
    }

    /*
     * We should act on KeyEvent.ACTION_DOWN, but strangely sometimes the
     * DOWN event isn't received, only the UP. So the workaround is to act
     * on UP... http://b/issue?id=1022478
     */

    if (action == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}

From source file:com.android2.calculator3.EventListener.java

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    // Work-around for spurious key event from IME, bug #1639445
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }/*from   ww  w  . j a v a2 s. com*/

    if (keyEvent.getUnicodeChar() == '=') {
        if (action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }

    if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP
            && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) {
        if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) {
            // Tell the handler that text was updated.
            mHandler.onTextChanged();
        }
        return false;
    }

    /*
     * We should act on KeyEvent.ACTION_DOWN, but strangely sometimes the DOWN event isn't received, only the UP. So the workaround is to act on UP... http://b/issue?id=1022478
     */

    if (action == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}

From source file:tinkercoder.stockcalculator.calculator.EventListener.java

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT);
        return eat;
    }/*from  w w w  . j  av a 2 s.c  o  m*/

    //Work-around for spurious key event from IME, bug #1639445
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }

    //Calculator.log("KEY " + keyCode + "; " + action);

    if (keyEvent.getUnicodeChar() == '=') {
        if (action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }

    if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP
            && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) {
        return false;
    }

    /*
       We should act on KeyEvent.ACTION_DOWN, but strangely
       sometimes the DOWN event isn't received, only the UP.
       So the workaround is to act on UP...
       http://b/issue?id=1022478
     */

    if (action == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}

From source file:com.oda.calculator.EventListener.java

public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT);
        return eat;
    }/* ww  w  . j a v  a 2  s .c om*/

    //Work-around for spurious key event from IME, bug #1639445
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }

    //Calculator.log("KEY " + keyCode + "; " + action);

    if (keyEvent.getUnicodeChar() == '=') {
        if (action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }

    if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP
            && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) {
        if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) {
            // Tell the handler that text was updated.
            mHandler.onTextChanged();
        }
        return false;
    }

    /*
       We should act on KeyEvent.ACTION_DOWN, but strangely
       sometimes the DOWN event isn't received, only the UP.
       So the workaround is to act on UP...
       http://b/issue?id=1022478
     */

    if (action == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}

From source file:com.aman.stockcalculator.EventListener.java

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT);
        return eat;
    }//w  ww  . ja  v  a 2  s .c  o  m

    //Work-around for spurious key event from IME, bug #1639445
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }

    //Calculator.log("KEY " + keyCode + "; " + action);

    if (keyEvent.getUnicodeChar() == '=') {
        if (action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }

    if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP
            && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) {
        if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) {
            // Tell the handler that text was updated.
            mHandler.onTextChanged();
        }
        return false;
    }

    /*
       We should act on KeyEvent.ACTION_DOWN, but strangely
       sometimes the DOWN event isn't received, only the UP.
       So the workaround is to act on UP...
       http://b/issue?id=1022478
     */

    if (action == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}

From source file:org.peterbaldwin.vlcremote.app.PlaybackActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    int c = event.getUnicodeChar();
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        if (mVolumeLevel != VOLUME_LEVEL_UNKNOWN) {
            setVolume(mVolumeLevel + 20);
        } else {//from w  ww. j  a  v a 2 s .c o m
            mMediaServer.status().command.volumeUp();
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        if (mVolumeLevel != VOLUME_LEVEL_UNKNOWN) {
            setVolume(mVolumeLevel - 20);
        } else {
            mMediaServer.status().command.volumeDown();
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
        if (event.isAltPressed()) {
            mMediaServer.status().command.seek(Uri.encode("-".concat(Preferences.get(this).getSeekTime())));
            return true;
        } else if (event.isShiftPressed()) {
            mMediaServer.status().command.seek(Uri.encode("-3"));
            return true;
        } else {
            mMediaServer.status().command.key("nav-left");
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        if (event.isAltPressed()) {
            mMediaServer.status().command.seek(Uri.encode("+".concat(Preferences.get(this).getSeekTime())));
            return true;
        } else if (event.isShiftPressed()) {
            mMediaServer.status().command.seek(Uri.encode("+3"));
            return true;
        } else {
            mMediaServer.status().command.key("nav-right");
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
        mMediaServer.status().command.key("nav-up");
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
        mMediaServer.status().command.key("nav-down");
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
        mMediaServer.status().command.key("nav-activate");
        return true;
    } else if (c == ' ') {
        mMediaServer.status().command.playback.pause();
        return true;
    } else if (c == 's') {
        mMediaServer.status().command.playback.stop();
        return true;
    } else if (c == 'p') {
        mMediaServer.status().command.playback.previous();
        return true;
    } else if (c == 'n') {
        mMediaServer.status().command.playback.next();
        return true;
    } else if (c == '+') {
        // TODO: Play faster
        return super.onKeyDown(keyCode, event);
    } else if (c == '-') {
        // TODO: Play slower
        return super.onKeyDown(keyCode, event);
    } else if (c == 'f') {
        mMediaServer.status().command.fullscreen();
        return true;
    } else if (c == 'm') {
        mute();
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}

From source file:com.android.launcher3.allapps.FullMergeAlgorithm.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // Determine if the key event was actual text, if so, focus the search bar and then dispatch
    // the key normally so that it can process this key event
    if (!mSearchBarController.isSearchFieldFocused() && event.getAction() == KeyEvent.ACTION_DOWN) {
        final int unicodeChar = event.getUnicodeChar();
        final boolean isKeyNotWhitespace = unicodeChar > 0 && !Character.isWhitespace(unicodeChar)
                && !Character.isSpaceChar(unicodeChar);
        if (isKeyNotWhitespace) {
            boolean gotKey = TextKeyListener.getInstance().onKeyDown(this, mSearchQueryBuilder,
                    event.getKeyCode(), event);
            if (gotKey && mSearchQueryBuilder.length() > 0) {
                mSearchBarController.focusSearchField();
            }/*from   w  w w  .  ja  va 2s  .  c  om*/
        }
    }

    return super.dispatchKeyEvent(event);
}