本文整理汇总了Java中android.inputmethodservice.Keyboard.Key类的典型用法代码示例。如果您正苦于以下问题:Java Key类的具体用法?Java Key怎么用?Java Key使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Key类属于android.inputmethodservice.Keyboard包,在下文中一共展示了Key类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openPopupIfRequired
import android.inputmethodservice.Keyboard.Key; //导入依赖的package包/类
private boolean openPopupIfRequired(int keyIndex, PointerTracker tracker) {
// Check if we have a popup layout specified first.
if (mPopupLayout == 0) {
return false;
}
Key popupKey = tracker.getKey(keyIndex);
if (popupKey == null)
return false;
boolean result = onLongPress(popupKey);
if (result) {
dismissKeyPreview();
mMiniKeyboardTrackerId = tracker.mPointerId;
// Mark this tracker "already processed" and remove it from the pointer queue
tracker.setAlreadyProcessed();
mPointerQueue.remove(tracker);
}
return result;
}
示例2: getPointerTracker
import android.inputmethodservice.Keyboard.Key; //导入依赖的package包/类
private PointerTracker getPointerTracker(final int id) {
final ArrayList<PointerTracker> pointers = mPointerTrackers;
final Key[] keys = mKeys;
final OnKeyboardActionListener listener = mKeyboardActionListener;
// Create pointer trackers until we can get 'id+1'-th tracker, if needed.
for (int i = pointers.size(); i <= id; i++) {
final PointerTracker tracker =
new PointerTracker(i, mHandler, mKeyDetector, this, getResources());
if (keys != null)
tracker.setKeyboard(keys, mKeyHysteresisDistance);
if (listener != null)
tracker.setOnKeyboardActionListener(listener);
pointers.add(tracker);
}
return pointers.get(id);
}
示例3: keyPressedAt
import android.inputmethodservice.Keyboard.Key; //导入依赖的package包/类
public static void keyPressedAt(Key key, int x, int y) {
if (LOGGING && sKeyLocationFile != null && key.codes[0] >= 32) {
String out =
"KEY: " + (char) key.codes[0]
+ " X: " + x
+ " Y: " + y
+ " MX: " + (key.x + key.width / 2)
+ " MY: " + (key.y + key.height / 2)
+ "\n";
try {
sKeyLocationFile.write(out.getBytes());
} catch (IOException ioe) {
// TODO: May run out of space
}
}
}
示例4: checkMultiTap
import android.inputmethodservice.Keyboard.Key; //导入依赖的package包/类
private void checkMultiTap(long eventTime, int keyIndex) {
Key key = getKey(keyIndex);
if (key == null)
return;
final boolean isMultiTap =
(eventTime < mLastTapTime + mMultiTapKeyTimeout && keyIndex == mLastSentIndex);
if (key.codes.length > 1) {
mInMultiTap = true;
if (isMultiTap) {
mTapCount = (mTapCount + 1) % key.codes.length;
return;
} else {
mTapCount = -1;
return;
}
}
if (!isMultiTap) {
resetMultiTap();
}
}
示例5: getKeyIndexAndNearbyCodes
import android.inputmethodservice.Keyboard.Key; //导入依赖的package包/类
@Override
public int getKeyIndexAndNearbyCodes(int x, int y, int[] allKeys) {
final Key[] keys = getKeys();
final int touchX = getTouchX(x);
final int touchY = getTouchY(y);
int closestKeyIndex = LatinKeyboardBaseView.NOT_A_KEY;
int closestKeyDist = (y < 0) ? mSlideAllowanceSquareTop : mSlideAllowanceSquare;
final int keyCount = keys.length;
for (int i = 0; i < keyCount; i++) {
final Key key = keys[i];
int dist = key.squaredDistanceFrom(touchX, touchY);
if (dist < closestKeyDist) {
closestKeyIndex = i;
closestKeyDist = dist;
}
}
if (allKeys != null && closestKeyIndex != LatinKeyboardBaseView.NOT_A_KEY)
allKeys[0] = keys[closestKeyIndex].codes[0];
return closestKeyIndex;
}
示例6: onLongPress
import android.inputmethodservice.Keyboard.Key; //导入依赖的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);
}
示例7: setKeyboard
import android.inputmethodservice.Keyboard.Key; //导入依赖的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
}
示例8: openPopupIfRequired
import android.inputmethodservice.Keyboard.Key; //导入依赖的package包/类
private boolean openPopupIfRequired(MotionEvent me) {
// Check if we have a popup layout specified first.
if (mPopupLayout == 0) {
return false;
}
if (mCurrentKey < 0 || mCurrentKey >= mKeys.length) {
return false;
}
Key popupKey = mKeys[mCurrentKey];
boolean result = onLongPress(popupKey);
if (result) {
mAbortKey = true;
showPreview(NOT_A_KEY);
}
return result;
}
示例9: checkMultiTap
import android.inputmethodservice.Keyboard.Key; //导入依赖的package包/类
private void checkMultiTap(long eventTime, int keyIndex) {
if (keyIndex == NOT_A_KEY) return;
Key key = mKeys[keyIndex];
if (key.codes.length > 1) {
mInMultiTap = true;
if (eventTime < mLastTapTime + MULTITAP_INTERVAL
&& keyIndex == mLastSentIndex) {
mTapCount = (mTapCount + 1) % key.codes.length;
return;
} else {
mTapCount = -1;
return;
}
}
if (eventTime > mLastTapTime + MULTITAP_INTERVAL || keyIndex != mLastSentIndex) {
resetMultiTap();
}
}
示例10: onDraw
import android.inputmethodservice.Keyboard.Key; //导入依赖的package包/类
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
List<Key> keys = getKeyboard().getKeys();
Paint paint = new Paint();
paint.setTextAlign(Paint.Align.CENTER);
paint.setTextSize((float) getResources().getDimension(R.dimen.double_tap_key_size));
paint.setAntiAlias(true);
paint.setColor(getResources().getColor(R.color.text_color));
for (Key key : keys) {
if (key.label != null) {
if (key.popupCharacters != null) {
String popKeyLabel = "";
int xPos = key.x + (key.width / 4) * 3;
int yPos = key.y + key.height / 3;
popKeyLabel = key.popupCharacters.toString();
canvas.drawText(popKeyLabel, xPos, yPos, paint);
}
}
}
}
示例11: randomNumKey
import android.inputmethodservice.Keyboard.Key; //导入依赖的package包/类
/**
* 数字随机
*/
private void randomNumKey() {
// 随机数
int[] num = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Random random = new Random();
for (int i = 0; i < num.length; i++) {
int m = random.nextInt(10);
int n = random.nextInt(10);
int z = num[m];
num[m] = num[n];
num[n] = z;
}
List<Key> list = numKeyboard.getKeys();
int data = 0;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).codes[0] >= 48 && list.get(i).codes[0] <= 57) {
list.get(i).label = String.valueOf(num[data]);
list.get(i).codes[0] = num[data] + 48;
data++;
}
}
}
示例12: setupKeys
import android.inputmethodservice.Keyboard.Key; //导入依赖的package包/类
private void setupKeys()
{
Iterator<Key> itKeys = getKeyboard().getKeys().iterator();
Key key;
while (itKeys.hasNext())
{
key = itKeys.next();
if (key.codes[0] > 2000)
{
String keyCode = ((char)key.codes[0])+"";
boolean hasMult = key.popupCharacters != null && key.popupCharacters.length() > 0;
key.label = null;
key.icon = new DynaDrawable (getContext(), key, mTypeface, keyCode, Color.WHITE, -8, 20, 1.8f, hasMult);
key.iconPreview = new DynaDrawable (getContext(), key, mTypeface, keyCode, Color.BLACK, -10, -25, 1.5f,false);
}
}
}
示例13: DynaDrawable
import android.inputmethodservice.Keyboard.Key; //导入依赖的package包/类
public DynaDrawable (Context context, Key key, Typeface typeface, String text, int textColor, int xOffset, int yOffset, float heightMod, boolean hasMult)
{
mTypeface = typeface;
mText = text;
mKey = key;
mTextSize = (int)(key.height/heightMod);
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setTextSize(mTextSize);
mPaint.setColor(textColor);
mPaint.setTypeface(mTypeface);
mXOffset = xOffset;
mYOffset = yOffset;
mHasMult = hasMult;
}
示例14: onLongPress
import android.inputmethodservice.Keyboard.Key; //导入依赖的package包/类
@Override
protected boolean onLongPress(Key key) {
if (key.codes[0] == Keyboard.KEYCODE_CANCEL) {
getOnKeyboardActionListener().onKey(KEYCODE_OPTIONS, null);
return true;
} else if (key.codes[0] == KEYCODE_LANGUAGE_SWITCH) {
getOnKeyboardActionListener().onKey(KEYCODE_INPUT_METHOD_SWITCH, null);
return true;
} else if (key.codes[0] == Keyboard.KEYCODE_DELETE) {
// turn off server predictions during long pressing backspace key
mLastPredictionEnabled = ((SoftKeyboard)getOnKeyboardActionListener()).turnOffPredictionsIfNeeded();
mLongPressedDelete = true;
return false;
} else {
return super.onLongPress(key);
}
}
示例15: onDraw
import android.inputmethodservice.Keyboard.Key; //导入依赖的package包/类
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
List<Key> keys = getKeyboard().getKeys();
for (Key key : keys) {
if (key.codes[0] == 32) {
canvas.drawRect(
key.x + spaceKeyMargin,
key.y + key.height / 2,
key.x + key.width - spaceKeyMargin,
key.y + key.height - key.height / 4,
foregroundPaint);
return;
}
}
}