本文整理匯總了Java中android.inputmethodservice.Keyboard.Key方法的典型用法代碼示例。如果您正苦於以下問題:Java Keyboard.Key方法的具體用法?Java Keyboard.Key怎麽用?Java Keyboard.Key使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.inputmethodservice.Keyboard
的用法示例。
在下文中一共展示了Keyboard.Key方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: shiftEnglish
import android.inputmethodservice.Keyboard; //導入方法依賴的package包/類
/**
* 英文鍵盤大小寫切換
*/
private void shiftEnglish() {
List<Keyboard.Key> keyList = keyboardEnglish.getKeys();
for (Keyboard.Key key : keyList) {
if (key.label != null && isKey(key.label.toString())) {
if (isCapital) {
key.label = key.label.toString().toLowerCase();
key.codes[0] = key.codes[0] + 32;
} else {
key.label = key.label.toString().toUpperCase();
key.codes[0] = key.codes[0] - 32;
}
}
}
isCapital = !isCapital;
}
示例3: drawKeyboardEnglish
import android.inputmethodservice.Keyboard; //導入方法依賴的package包/類
/**
* 繪製英文鍵盤
*
* @param keys
* @param canvas
*/
private void drawKeyboardEnglish(List<Keyboard.Key> keys, Canvas canvas) {
for (Keyboard.Key key : keys) {
if (key.codes[0] == -5) {//刪除鍵
drawKeyBackground(R.drawable.img_edit_clear, canvas, key);
}
if (key.codes[0] == -1) {//大小寫切換
drawKeyBackground(R.drawable.img_edit_clear, canvas, key);
}
if (key.codes[0] == 32) {//space
}
if (key.codes[0] == -4) {//完成
}
}
}
示例4: onDraw
import android.inputmethodservice.Keyboard; //導入方法依賴的package包/類
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
// 遍曆所有的按鍵
List<Keyboard.Key> keys = getKeyboard().getKeys();
for (Keyboard.Key key : keys) {
// 如果是左下角空白的按鍵,重畫按鍵的背景
if (key.codes[0] == KEYCODE_EMPTY) {
drawKeyBackground(key, canvas, mDeleteBackgroundColor);
}
// 如果是右下角的刪除按鍵,重畫按鍵的背景,並且繪製刪除圖標
else if (key.codes[0] == Keyboard.KEYCODE_DELETE) {
drawKeyBackground(key, canvas, mDeleteBackgroundColor);
drawDeleteButton(key, canvas);
}
}
}
示例5: shuffleKeyboard
import android.inputmethodservice.Keyboard; //導入方法依賴的package包/類
/**
* 隨機打亂數字鍵盤上鍵位的排列順序。
*/
public void shuffleKeyboard() {
Keyboard keyboard = getKeyboard();
if (keyboard != null && keyboard.getKeys() != null && keyboard.getKeys().size() > 0) {
Collections.shuffle(keyCodes); // 隨機排序數字
// 遍曆所有的按鍵
List<Keyboard.Key> keys = getKeyboard().getKeys();
int index = 0;
for (Keyboard.Key key : keys) {
// 如果按鍵是數字
if (key.codes[0] != KEYCODE_EMPTY && key.codes[0] != Keyboard.KEYCODE_DELETE) {
char code = keyCodes.get(index++);
key.codes[0] = code;
key.label = Character.toString(code);
}
}
setKeyboard(keyboard);
}
}
示例6: initType
import android.inputmethodservice.Keyboard; //導入方法依賴的package包/類
/**
* 判斷為何種鍵盤, 通過某一個按鍵的code值
* TODO 注意,這種方法有弊端:如果xml中的最上麵一排的按鍵數目發生變化,這裏應該改變
*
* @param keys
*/
private void initType(List<Keyboard.Key> keys) {
switch (keys.get(5).codes[0]) {
case 113:
currentType = TYPE_ABC;
break;
case 81:
currentType = TYPE_ABC_SHIFT;
break;
case 49:
currentType = TYPE_SYMBOL;
break;
case 126:
currentType = TYPE_SYMBOL_MORE;
break;
}
}
示例7: controlKeyToggle
import android.inputmethodservice.Keyboard; //導入方法依賴的package包/類
public void controlKeyToggle() {
keyboard = kv.getKeyboard();
int i;
List<Keyboard.Key> keys = keyboard.getKeys();
for (i = 0; i < keys.size(); i++) {
if (ctrl) {
if (keys.get(i).label != null && keys.get(i).label.equals("Ctrl")) {
keys.get(i).label = "CTRL";
break;
}
} else {
if (keys.get(i).label != null && keys.get(i).label.equals("CTRL")) {
keys.get(i).label = "Ctrl";
break;
}
}
}
kv.invalidateKey(i);
}
示例8: shiftKeyToggle
import android.inputmethodservice.Keyboard; //導入方法依賴的package包/類
public void shiftKeyToggle() {
keyboard = kv.getKeyboard();
List<Keyboard.Key> keys = keyboard.getKeys();
for (int i = 0; i < keys.size(); i++) {
if (shift) {
if (keys.get(i).label != null && keys.get(i).label.equals("Shft")) {
keys.get(i).label = "SHFT";
break;
}
} else {
if (keys.get(i).label != null && keys.get(i).label.equals("SHFT")) {
keys.get(i).label = "Shft";
break;
}
}
}
keyboard.setShifted(shift);
kv.invalidateAllKeys();
}
示例9: onInitializeInterface
import android.inputmethodservice.Keyboard; //導入方法依賴的package包/類
@Override
public void onInitializeInterface() {
// TODO Auto-generated method stub
super.onInitializeInterface();
this.setupUtilityKeyboard();
dotDashKeyboard = new DotDashKeyboard(this, R.xml.dotdash);
dotDashKeyboard.setupDotDashKeys(this.prefs.getBoolean(DotDashPrefs.DASHKEYONLEFT, false));
spaceKey = dotDashKeyboard.spaceKey;
capsLockKey = dotDashKeyboard.capsLockKey;
List<Keyboard.Key> keys = dotDashKeyboard.getKeys();
spaceKeyIndex = keys.indexOf(spaceKey);
capsLockKeyIndex = keys.indexOf(capsLockKey);
if (isAudio()) {
loadSoundPool();
}
}
示例10: createKeyFromXml
import android.inputmethodservice.Keyboard; //導入方法依賴的package包/類
@Override
protected Keyboard.Key createKeyFromXml(Resources res, Keyboard.Row parent, int x, int y,
XmlResourceParser parser) {
LatinKey key = new LatinKey(res, parent, x, y, parser);
final int code = key.codes[0];
if (code >= 0 && code != '\n' && (code < 32 || code > 127)) {
key.label = " ";
key.setEnabled(false);
}
switch (key.codes[0]) {
case KEYCODE_ENTER:
mEnterKey = key;
break;
}
return key;
}
示例11: syncStateKeys
import android.inputmethodservice.Keyboard; //導入方法依賴的package包/類
private void syncStateKeys(Keyboard k) {
for (Keyboard.Key key : k.getKeys()) {
if (key.sticky) {
switch (key.codes[0]) {
case VirtualKeyCode.ALT:
key.on = altState;
break;
case VirtualKeyCode.CAPS:
key.on = capsState;
break;
case VirtualKeyCode.CTRL:
key.on = ctrlState;
break;
case VirtualKeyCode.WIN:
key.on = winState;
break;
case VirtualKeyCode.MAC_COMMAND:
key.on = commandState;
break;
}
}
}
}
示例12: swapKeys
import android.inputmethodservice.Keyboard; //導入方法依賴的package包/類
private void swapKeys(Keyboard.Key k1, Keyboard.Key k2) {
int[] codes = k1.codes;
Drawable icon = k1.icon;
Drawable iconPreview = k1.iconPreview;
CharSequence label = k1.label;
boolean modifier = k1.modifier;
boolean on = k1.on;
CharSequence popupCharacters = k1.popupCharacters;
int popupResId = k1.popupResId;
boolean pressed = k1.pressed;
boolean repeatable = k1.repeatable;
boolean sticky = k1.sticky;
CharSequence text = k1.text;
k1.codes = k2.codes;
k1.icon = k2.icon;
k1.iconPreview = k2.iconPreview;
k1.label = k2.label;
k1.modifier = k2.modifier;
k1.on = k2.on;
k1.popupCharacters = k2.popupCharacters;
k1.popupResId = k2.popupResId;
k1.pressed = k2.pressed;
k1.repeatable = k2.repeatable;
k1.sticky = k2.sticky;
k1.text = k2.text;
k2.codes = codes;
k2.icon = icon;
k2.iconPreview = iconPreview;
k2.label = label;
k2.modifier = modifier;
k2.on = on;
k2.popupCharacters = popupCharacters;
k2.popupResId = popupResId;
k2.pressed = pressed;
k2.repeatable = repeatable;
k2.sticky = sticky;
k2.text = text;
}
示例13: shuffleKeyboard
import android.inputmethodservice.Keyboard; //導入方法依賴的package包/類
private void shuffleKeyboard(Keyboard keyboard) {
List<Keyboard.Key> keys = keyboard.getKeys();
int nKeys = keys.size();
int swappiness = Integer.parseInt(prefs.getString("pref_swap_swappiness", "1"));
for (int i = 0; i < swappiness; i++) {
Keyboard.Key k1 = keys.get(rand.nextInt(nKeys));
Keyboard.Key k2 = keys.get(rand.nextInt(nKeys));
swapKeys(k1, k2);
}
kv.invalidateAllKeys();
}
示例14: changeKeyHeight
import android.inputmethodservice.Keyboard; //導入方法依賴的package包/類
public void changeKeyHeight(double height_modifier){
int height = 0;
for(Keyboard.Key key : getKeys()) {
key.height *= height_modifier;
key.y *= height_modifier;
height = key.height;
}
setKeyHeight(height);
getNearestKeys(0, 0); //somehow adding this fixed a weird bug where bottom row keys could not be pressed if keyboard height is too tall.. from the Keyboard source code seems like calling this will recalculate some values used in keypress detection calculation
}
示例15: drawKeyboardNumber
import android.inputmethodservice.Keyboard; //導入方法依賴的package包/類
/**
* 繪製數字鍵盤
*
* @param keys
* @param canvas
*/
private void drawKeyboardNumber(List<Keyboard.Key> keys, Canvas canvas) {
for (Keyboard.Key key : keys) {
if (key.codes[0] == -5) {//刪除鍵
drawKeyBackground(R.drawable.img_edit_clear, canvas, key);
}
}
}