本文整理匯總了Java中android.inputmethodservice.Keyboard類的典型用法代碼示例。如果您正苦於以下問題:Java Keyboard類的具體用法?Java Keyboard怎麽用?Java Keyboard使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Keyboard類屬於android.inputmethodservice包,在下文中一共展示了Keyboard類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: NumberKeyboard
import android.inputmethodservice.Keyboard; //導入依賴的package包/類
public NumberKeyboard(final Context context, OnKeyActionListener keyActionListener) {
super(context, keyActionListener);
final View contentView = setContentView(R.layout.keyboard_plate);
mKeyboard = new Keyboard(context, R.xml.keyboardnumber);
mKeyboardView = (KeyboardView) contentView.findViewById(R.id.keyboard_view);
mKeyboardView.setOnKeyboardActionListener(new OnKeyboardActionHandler() {
@Override
public void onKey(int charCode, int[] keyCodes) {
if (charCode == Keyboard.KEYCODE_DONE) {
dismiss();
return;
}
mOnKeyActionListener.onProcess(charCode);
}
});
mKeyboardView.setPreviewEnabled(false);// !!! Must be false
mKeyboardView.setKeyboard(mKeyboard);
}
示例2: invalidateAllKeys
import android.inputmethodservice.Keyboard; //導入依賴的package包/類
@Override
public void invalidateAllKeys() {
if (getKeyboard() != null) {
boolean isDark = ColorUtils.isColorDark(color);
for (Keyboard.Key key : getKeyboard().getKeys()) {
if (key.label != null) {
key.icon = new TextDrawable(getContext(), getShiftedLabel(key.label.toString()), isDark ? Color.WHITE : Color.BLACK);
key.label = null;
} else if (key.icon != null) {
if (key.icon instanceof TextDrawable) {
key.icon = new TextDrawable(getContext(), getShiftedLabel(((TextDrawable) key.icon).getText()), isDark ? Color.WHITE : Color.BLACK);
} else {
DrawableCompat.setTint(key.icon, isDark ? Color.WHITE : Color.BLACK);
if (key.icon instanceof AnimatedVectorDrawableCompat)
((AnimatedVectorDrawableCompat) key.icon).start();
}
}
}
}
super.invalidateAllKeys();
}
示例3: playClick
import android.inputmethodservice.Keyboard; //導入依賴的package包/類
private void playClick(int keyCode) {
AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
switch (keyCode) {
case 0x20:
am.playSoundEffect(AudioManager.FX_KEYPRESS_SPACEBAR);
break;
case Keyboard.KEYCODE_DONE:
case 0x0a:
am.playSoundEffect(AudioManager.FX_KEYPRESS_RETURN);
break;
case Keyboard.KEYCODE_DELETE:
am.playSoundEffect(AudioManager.FX_KEYPRESS_DELETE);
break;
case 0x38:
if (prefs.getBoolean("pref_eight_enable", false)) {
// Play random "eight" sound
MediaPlayer mPlayer = mediaEight[rand.nextInt(mediaEight.length)];
mPlayer.seekTo(0);
mPlayer.start();
}
break;
default:
am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD);
}
}
示例4: onPress
import android.inputmethodservice.Keyboard; //導入依賴的package包/類
public void onPress(int primaryCode) {
if (mKeyboardSwitcher.isVibrateAndSoundFeedbackRequired()) {
vibrate();
playKeyClick(primaryCode);
}
final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch();
if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_SHIFT) {
mShiftKeyState.onPress();
handleShift();
} else if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_MODE_CHANGE) {
changeKeyboardMode();
mSymbolKeyState.onPress();
mKeyboardSwitcher.setAutoModeSwitchStateMomentary();
} else {
mShiftKeyState.onOtherKeyPressed();
mSymbolKeyState.onOtherKeyPressed();
}
}
示例5: onRelease
import android.inputmethodservice.Keyboard; //導入依賴的package包/類
public void onRelease(int primaryCode) {
// Reset any drag flags in the keyboard
((LatinKeyboard) mKeyboardSwitcher.getInputView().getKeyboard()).keyReleased();
//vibrate();
final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch();
if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_SHIFT) {
if (mShiftKeyState.isMomentary())
resetShift();
mShiftKeyState.onRelease();
} else if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_MODE_CHANGE) {
// Snap back to the previous keyboard mode if the user chords the mode change key and
// other key, then released the mode change key.
if (mKeyboardSwitcher.isInChordingAutoModeSwitchState())
changeKeyboardMode();
mSymbolKeyState.onRelease();
}
}
示例6: playKeyClick
import android.inputmethodservice.Keyboard; //導入依賴的package包/類
private void playKeyClick(int primaryCode) {
// if mAudioManager is null, we don't have the ringer state yet
// mAudioManager will be set by updateRingerMode
if (mAudioManager == null) {
if (mKeyboardSwitcher.getInputView() != null) {
updateRingerMode();
}
}
if (mSoundOn && !mSilentMode) {
// FIXME: Volume and enable should come from UI settings
// FIXME: These should be triggered after auto-repeat logic
int sound = AudioManager.FX_KEYPRESS_STANDARD;
switch (primaryCode) {
case Keyboard.KEYCODE_DELETE:
sound = AudioManager.FX_KEYPRESS_DELETE;
break;
case KEYCODE_ENTER:
sound = AudioManager.FX_KEYPRESS_RETURN;
break;
case KEYCODE_SPACE:
sound = AudioManager.FX_KEYPRESS_SPACEBAR;
break;
}
mAudioManager.playSoundEffect(sound, FX_VOLUME);
}
}
示例7: setKeyboard
import android.inputmethodservice.Keyboard; //導入依賴的package包/類
/**
* Attaches a keyboard to this view. The keyboard can be switched at any time and the
* view will re-layout itself to accommodate the keyboard.
* @see Keyboard
* @see #getKeyboard()
* @param keyboard the keyboard to display in this view
*/
public void setKeyboard(Keyboard keyboard) {
if (mKeyboard != null) {
dismissKeyPreview();
}
// Remove any pending messages, except dismissing preview
mHandler.cancelKeyTimers();
mHandler.cancelPopupPreview();
mKeyboard = keyboard;
LatinImeLogger.onSetKeyboard(keyboard);
mKeys = mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(),
-getPaddingTop() + mVerticalCorrection);
mKeyboardVerticalGap = (int)getResources().getDimension(R.dimen.key_bottom_gap);
for (PointerTracker tracker : mPointerTrackers) {
tracker.setKeyboard(mKeys, mKeyHysteresisDistance);
}
requestLayout();
// Hint to reallocate the buffer if the size changed
mKeyboardChanged = true;
invalidateAllKeys();
computeProximityThreshold(keyboard);
mMiniKeyboardCache.clear();
}
示例8: createKeyFromXml
import android.inputmethodservice.Keyboard; //導入依賴的package包/類
@Override
protected Key createKeyFromXml(Resources res, Row parent, int x, int y,
XmlResourceParser parser) {
Key key = new LatinKey(res, parent, x, y, parser);
if (key.codes[0] == 10) {
mEnterKey = key;
} else if (key.codes[0] == ' ') {
mSpaceKey = key;
} else if (key.codes[0] == Keyboard.KEYCODE_MODE_CHANGE) {
mModeChangeKey = key;
mSavedModeChangeKey = new LatinKey(res, parent, x, y, parser);
} else if (key.codes[0] == LatinKeyboard.KEYCODE_LAYUOUT_SWITCH) {
mLanguageSwitchKey = key;
mSavedLanguageSwitchKey = new LatinKey(res, parent, x, y, parser);
}
return key;
}
示例9: onLongPress
import android.inputmethodservice.Keyboard; //導入依賴的package包/類
@Override
protected boolean onLongPress(Key key) {
if (key.codes[0] == Keyboard.KEYCODE_CANCEL) {
getOnKeyboardActionListener().onKey(LatinKeyboard.KEYCODE_OPTIONS, null);
return true;
}
if(key.codes[0] == -113) {
Variables.setCtrlOn();
draw(new Canvas());
return true;
}
if(key.codes[0] == -114) {
Variables.setAltOn();
draw(new Canvas());
return true;
}
return super.onLongPress(key);
}
示例10: playclick
import android.inputmethodservice.Keyboard; //導入依賴的package包/類
private void playclick(int keyCode){
AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
switch (keyCode) {
case 32:
am.playSoundEffect(AudioManager.FX_KEYPRESS_SPACEBAR);
break;
case 10:
am.playSoundEffect(AudioManager.FX_KEYPRESS_RETURN);
break;
case Keyboard.KEYCODE_DELETE:
am.playSoundEffect(AudioManager.FX_KEYPRESS_DELETE);
break;
default:
am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD);
break;
}
}
示例11: onKey
import android.inputmethodservice.Keyboard; //導入依賴的package包/類
@Override
public void onKey(int primaryCode, int[] keyCodes) {
InputConnection ic = getCurrentInputConnection() ;
playclick(primaryCode);
switch (primaryCode) {
case Keyboard.KEYCODE_DELETE:
ic.deleteSurroundingText(1, 0);
break;
case Keyboard.KEYCODE_SHIFT:
caps = !caps;
keyboard.setShifted(caps);
kv.invalidateAllKeys();
break;
case Keyboard.KEYCODE_DONE:
ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
break;
default:
char code = (char) primaryCode;
if(Character.isLetter(code) && caps) {
code = Character.toUpperCase(code);
}
ic.commitText(String.valueOf(code), 1);
break;
}
}
示例12: setKeyboard
import android.inputmethodservice.Keyboard; //導入依賴的package包/類
/**
* Attaches a keyboard to this view. The keyboard can be switched at any time and the
* view will re-layout itself to accommodate the keyboard.
*
* @param keyboard the keyboard to display in this view
* @see Keyboard
* @see #getKeyboard()
*/
public void setKeyboard(Keyboard keyboard) {
if (mKeyboard != null) {
showPreview(NOT_A_KEY);
}
// Remove any pending messages
removeMessages();
mKeyboard = keyboard;
List<Key> keys = mKeyboard.getKeys();
mKeys = keys.toArray(new Key[keys.size()]);
requestLayout();
// Hint to reallocate the buffer if the size changed
mKeyboardChanged = true;
invalidateAllKeys();
computeProximityThreshold(keyboard);
mMiniKeyboardCache.clear(); // Not really necessary to do every time, but will free up views
// Switching to a different keyboard should abort any pending keys so that the key up
// doesn't get delivered to the old or new keyboard
mAbortKey = true; // Until the next ACTION_DOWN
}
示例13: VinKeyboardUtil
import android.inputmethodservice.Keyboard; //導入依賴的package包/類
public VinKeyboardUtil(Context ctx, View view, EditText edit) {
this.ctx = ctx;
this.edit = edit;
this.editString = edit.getText().toString();
this.edit.setSelection(editString.length());
k2 = new Keyboard(ctx, R.xml.lettersanddigit_keyboard);
keyboardView = (KeyboardView) view.findViewById(R.id.keyboard_view);
keyboardView.setKeyboard(k2);
keyboardView.setEnabled(true);
//設置為true時,當按下一個按鍵時會有一個popup來顯示<key>元素設置的android:popupCharacters=""
keyboardView.setPreviewEnabled(false);
//設置鍵盤按鍵監聽器
keyboardView.setOnKeyboardActionListener(listener);
letterAndDigit = new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"
, "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"
, "A", "S", "D", "F", "G", "H", "J", "K", "L"
, "Z", "X", "C", "V", "B", "N", "M"};
}
示例14: onKey
import android.inputmethodservice.Keyboard; //導入依賴的package包/類
@Override
public void onKey(int primaryCode, int[] keyCodes) {
if (primaryCode == 0) // Tasto vuoto
return;
if (primaryCode != Keyboard.KEYCODE_DELETE)
pin = pin + Character.toString((char) primaryCode);
else if (pin.length() > 0)
pin = pin.substring(0, pin.length() - 1);
pinCodeView.setPinLength(pin.length());
if (pin.length() == 4) {
pinCodeView.postDelayed(new Runnable() {
@Override
public void run() {
checkPin();
}
}, 250);
}
}
示例15: playClick
import android.inputmethodservice.Keyboard; //導入依賴的package包/類
/**
* Play sound on key press
*
* @param keyCode of pressed key
*/
private void playClick(int keyCode) {
AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
switch (keyCode) {
case Constants.KeyCode.SPACE:
am.playSoundEffect(AudioManager.FX_KEYPRESS_SPACEBAR);
break;
case Keyboard.KEYCODE_DONE:
am.playSoundEffect(AudioManager.FX_KEYPRESS_RETURN);
break;
case Constants.KeyCode.RETURN:
am.playSoundEffect(AudioManager.FX_KEYPRESS_RETURN);
break;
case Keyboard.KEYCODE_DELETE:
am.playSoundEffect(AudioManager.FX_KEYPRESS_DELETE);
break;
default:
am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD);
break;
}
}