本文整理匯總了Java中android.support.v4.view.KeyEventCompat類的典型用法代碼示例。如果您正苦於以下問題:Java KeyEventCompat類的具體用法?Java KeyEventCompat怎麽用?Java KeyEventCompat使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
KeyEventCompat類屬於android.support.v4.view包,在下文中一共展示了KeyEventCompat類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: executeKeyEvent
import android.support.v4.view.KeyEventCompat; //導入依賴的package包/類
/**
* You can call this function yourself to have the scroll view perform
* scrolling from a key event, just as if the event had been dispatched to
* it by the view hierarchy.
*
* @param event The key event to execute.
* @return Return true if the event was handled, else false.
*/
public boolean executeKeyEvent(KeyEvent event) {
boolean handled = false;
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_DPAD_LEFT:
handled = arrowScroll(FOCUS_LEFT);
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
handled = arrowScroll(FOCUS_RIGHT);
break;
case KeyEvent.KEYCODE_TAB:
if (Build.VERSION.SDK_INT >= 11) {
// The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
// before Android 3.0. Ignore the tab key on those devices.
if (KeyEventCompat.hasNoModifiers(event)) {
handled = arrowScroll(FOCUS_FORWARD);
} else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
handled = arrowScroll(FOCUS_BACKWARD);
}
}
break;
}
}
return handled;
}
示例2: executeKeyEvent
import android.support.v4.view.KeyEventCompat; //導入依賴的package包/類
/**
* 執行按鍵響應事件
*/
public boolean executeKeyEvent(KeyEvent event) {
boolean handled = false;
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_DPAD_LEFT:
handled = arrowScroll(FOCUS_LEFT);
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
handled = arrowScroll(FOCUS_RIGHT);
break;
case KeyEvent.KEYCODE_TAB:
if (Build.VERSION.SDK_INT >= 11) {
// The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
// before Android 3.0. Ignore the tab key on those devices.
if (KeyEventCompat.hasNoModifiers(event)) {
handled = arrowScroll(FOCUS_FORWARD);
} else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
handled = arrowScroll(FOCUS_BACKWARD);
}
}
break;
}
}
return handled;
}
示例3: executeKeyEvent
import android.support.v4.view.KeyEventCompat; //導入依賴的package包/類
/**
* You can call this function yourself to have the scroll view perform
* scrolling from a key event, just as if the event had been dispatched to
* it by the view hierarchy.
*
* @param event The key event to execute.
* @return Return true if the event was handled, else false.
*/
public boolean executeKeyEvent(KeyEvent event) {
boolean handled = false;
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_DPAD_LEFT:
handled = arrowScroll(FOCUS_LEFT);
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
handled = arrowScroll(FOCUS_RIGHT);
break;
case KeyEvent.KEYCODE_TAB:
if (Build.VERSION.SDK_INT >= 11) {
// The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
// before Android 3.0. Ignore the tab key on those devices.
if (KeyEventCompat.hasNoModifiers(event)) {
handled = arrowScroll(FOCUS_FORWARD);
} else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
handled = arrowScroll(FOCUS_BACKWARD);
}
}
break;
}
}
return handled;
}
示例4: dispatchKeyEvent
import android.support.v4.view.KeyEventCompat; //導入依賴的package包/類
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == 19) {
int action = event.getAction();
if (action == 0) {
if (KeyEventCompat.hasModifiers(event, 2)) {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null && actionBar.isShowing() && actionBar.requestFocus()) {
this.mEatKeyUpEvent = true;
return true;
}
}
} else if (action == 1 && this.mEatKeyUpEvent) {
this.mEatKeyUpEvent = false;
return true;
}
}
return super.dispatchKeyEvent(event);
}
示例5: onSuggestionsKey
import android.support.v4.view.KeyEventCompat; //導入依賴的package包/類
private boolean onSuggestionsKey(View v, int keyCode, KeyEvent event) {
if (this.mSearchable == null || this.mSuggestionsAdapter == null || event.getAction() != 0 || !KeyEventCompat.hasNoModifiers(event)) {
return false;
}
if (keyCode == 66 || keyCode == 84 || keyCode == 61) {
return onItemClicked(this.mSearchSrcTextView.getListSelection(), 0, null);
}
if (keyCode != 21 && keyCode != 22) {
return (keyCode == 19 && this.mSearchSrcTextView.getListSelection() == 0) ? false : false;
} else {
int selPoint;
if (keyCode == 21) {
selPoint = 0;
} else {
selPoint = this.mSearchSrcTextView.length();
}
this.mSearchSrcTextView.setSelection(selPoint);
this.mSearchSrcTextView.setListSelection(0);
this.mSearchSrcTextView.clearListSelection();
HIDDEN_METHOD_INVOKER.ensureImeVisible(this.mSearchSrcTextView, true);
return true;
}
}
示例6: executeKeyEvent
import android.support.v4.view.KeyEventCompat; //導入依賴的package包/類
/**
* You can call this function yourself to have the scroll view perform
* scrolling from a key event, just as if the event had been dispatched to
* it by the view hierarchy.
*
* @param event The key event to execute.
* @return Return true if the event was handled, else false.
*/
public boolean executeKeyEvent(KeyEvent event) {
boolean handled = false;
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_DPAD_LEFT:
handled = arrowScroll(FOCUS_LEFT);
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
handled = arrowScroll(FOCUS_RIGHT);
break;
case KeyEvent.KEYCODE_TAB:
if (Build.VERSION.SDK_INT >= 11) {
// The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
// before Android 3.0. Ignore the tab key on those devices.
if (KeyEventCompat.hasNoModifiers(event)) {
handled = arrowScroll(FOCUS_FORWARD);
} else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
handled = arrowScroll(FOCUS_BACKWARD);
}
}
break;
}
}
return handled;
}