當前位置: 首頁>>代碼示例>>Java>>正文


Java KeyEvent.getKeyCode方法代碼示例

本文整理匯總了Java中android.view.KeyEvent.getKeyCode方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyEvent.getKeyCode方法的具體用法?Java KeyEvent.getKeyCode怎麽用?Java KeyEvent.getKeyCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.KeyEvent的用法示例。


在下文中一共展示了KeyEvent.getKeyCode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: executeKeyEvent

import android.view.KeyEvent; //導入方法依賴的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;
}
 
開發者ID:ruiqiao2017,項目名稱:Renrentou,代碼行數:34,代碼來源:XCCycleViewPager.java

示例2: onKey

import android.view.KeyEvent; //導入方法依賴的package包/類
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (mPopup == null || mPopup.getListView() == null) return false;

    if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
            event.startTracking();
            v.getKeyDispatcherState().startTracking(event, this);
            return true;
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            v.getKeyDispatcherState().handleUpEvent(event);
            if (event.isTracking() && !event.isCanceled()) {
                dismiss();
                return true;
            }
        }
    }
    return false;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:20,代碼來源:AppMenu.java

示例3: dispatchKeyEvent

import android.view.KeyEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
  int keyCode = event.getKeyCode();
  if (event.getRepeatCount() == 0 && (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_SPACE)) {
    doPauseResume();
    show(sDefaultTimeout);
    if (mPauseButton != null)
      mPauseButton.requestFocus();
    return true;
  } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP) {
    if (mPlayer.isPlaying()) {
      mPlayer.pause();
      updatePausePlay();
    }
    return true;
  } else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) {
    hide();
    return true;
  } else {
    show(sDefaultTimeout);
  }
  return super.dispatchKeyEvent(event);
}
 
開發者ID:Leavessilent,項目名稱:QuanMinTV,代碼行數:24,代碼來源:MediaController.java

示例4: dispatchKeyEvent

import android.view.KeyEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
	// 監測音量變化
	if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN
			|| event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {

		int volume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
		if (currentVolume != volume) {
			currentVolume = volume;
			volumeSeekBar.setProgress(currentVolume);
		}

		if (isPrepared) {
			setLayoutVisibility(View.VISIBLE, true);
		}
	}
	return super.dispatchKeyEvent(event);
}
 
開發者ID:lbbniu,項目名稱:CCDownload,代碼行數:19,代碼來源:ADMediaPlayActivity.java

示例5: executeKeyEvent

import android.view.KeyEvent; //導入方法依賴的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;
}
 
開發者ID:ChenTianSaber,項目名稱:DailyZhiHu,代碼行數:34,代碼來源:CustomViewAbove.java

示例6: sendKeyEvent

import android.view.KeyEvent; //導入方法依賴的package包/類
@Override
public boolean sendKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        if (event.getKeyCode() >= KeyEvent.KEYCODE_0
                && event.getKeyCode() <= KeyEvent.KEYCODE_9) {
            char c = event.getKeyCharacterMap().getNumber(event.getKeyCode());
            commitText(String.valueOf(c), 1);
        } else if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
            deleteSurroundingText(1, 0);
        }
    }
    return super.sendKeyEvent(event);
}
 
開發者ID:Onum,項目名稱:EditCodeView,代碼行數:14,代碼來源:EditCodeInputConnection.java

示例7: dispatchKeyEvent

import android.view.KeyEvent; //導入方法依賴的package包/類
/**
 * Called to process key events.  You can override this to intercept all
 * key events before they are dispatched to the window.  Be sure to call
 * this implementation for key events that should be handled normally.
 *
 * @param event The key event.
 *
 * @return boolean Return true if this event was consumed.
 */
public boolean dispatchKeyEvent(KeyEvent event) {
    onUserInteraction();

    // Let action bars open menus in response to the menu key prioritized over
    // the window handling it
    final int keyCode = event.getKeyCode();
    if (keyCode == KeyEvent.KEYCODE_MENU &&
            mActionBar != null && mActionBar.onMenuKeyEvent(event)) {
        return true;
    } else if (event.isCtrlPressed() &&
            event.getUnicodeChar(event.getMetaState() & ~KeyEvent.META_CTRL_MASK) == '<') {
        // Capture the Control-< and send focus to the ActionBar
        final int action = event.getAction();
        if (action == KeyEvent.ACTION_DOWN) {
            final ActionBar actionBar = getActionBar();
            if (actionBar != null && actionBar.isShowing() && actionBar.requestFocus()) {
                mEatKeyUpEvent = true;
                return true;
            }
        } else if (action == KeyEvent.ACTION_UP && mEatKeyUpEvent) {
            mEatKeyUpEvent = false;
            return true;
        }
    }

    Window win = getWindow();
    if (win.superDispatchKeyEvent(event)) {
        return true;
    }
    View decor = mDecor;
    if (decor == null) decor = win.getDecorView();
    return event.dispatch(this, decor != null
            ? decor.getKeyDispatcherState() : null, this);
}
 
開發者ID:JessYanCoding,項目名稱:ProgressManager,代碼行數:44,代碼來源:a.java

示例8: processDelKey

import android.view.KeyEvent; //導入方法依賴的package包/類
public boolean processDelKey(KeyEvent event)
{
    if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DEL
            && getText().length() == 0 && !toBeDeleted)
    {
        toBeDeleted = true;
        if (formulaChangeIf != null)
        {
            formulaChangeIf.onDelete(this);
            return true;
        }
    }
    return false;
}
 
開發者ID:mkulesh,項目名稱:microMathematics,代碼行數:15,代碼來源:CustomEditText.java

示例9: dispatchKeyEvent

import android.view.KeyEvent; //導入方法依賴的package包/類
public boolean dispatchKeyEvent(KeyEvent keyEvent) {
    f.b("SecureWebView", "-->dispatchKeyEvent, is device support: " + a);
    if (!a) {
        return super.dispatchKeyEvent(keyEvent);
    }
    if (keyEvent.getAction() != 0) {
        return super.dispatchKeyEvent(keyEvent);
    }
    switch (keyEvent.getKeyCode()) {
        case 4:
            return super.dispatchKeyEvent(keyEvent);
        case 66:
            return super.dispatchKeyEvent(keyEvent);
        case 67:
            a.b = true;
            return super.dispatchKeyEvent(keyEvent);
        default:
            if (keyEvent.getUnicodeChar() == 0) {
                return super.dispatchKeyEvent(keyEvent);
            }
            if (SecureJsInterface.isPWDEdit) {
                int unicodeChar = keyEvent.getUnicodeChar();
                if ((unicodeChar >= 33 && unicodeChar <= 95) || (unicodeChar >= 97 && unicodeChar <= 125)) {
                    this.b = new KeyEvent(0, 17);
                    return super.dispatchKeyEvent(this.b);
                }
            }
            return super.dispatchKeyEvent(keyEvent);
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:31,代碼來源:c.java

示例10: dispatchKeyEvent

import android.view.KeyEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (tvCursorManager != null && tvCursorManager.isShowCursor() && !isIMEMode) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN ||
                event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP ||
                event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT ||
                event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT ||
                event.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER)
            return tvCursorManager.onDpadClicked(event);
    }
    return super.dispatchKeyEvent(event);
}
 
開發者ID:jasonhancn,項目名稱:AndroidTVCursor,代碼行數:13,代碼來源:TvCursorActivity.java

示例11: onKeyDown

import android.view.KeyEvent; //導入方法依賴的package包/類
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
        finish();
    }
    return super.onKeyDown(keyCode, event);
}
 
開發者ID:fengdongfei,項目名稱:CXJPadProject,代碼行數:8,代碼來源:FineActivity.java

示例12: executeKeyEvent

import android.view.KeyEvent; //導入方法依賴的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;
}
 
開發者ID:HueToYou,項目名稱:ChatExchange-old,代碼行數:41,代碼來源:CustomViewAbove.java

示例13: executeKeyEvent

import android.view.KeyEvent; //導入方法依賴的package包/類
public boolean executeKeyEvent(KeyEvent event) {
    this.mTempRect.setEmpty();
    if (canScroll()) {
        boolean handled = false;
        if (event.getAction() == 0) {
            switch (event.getKeyCode()) {
                case 19:
                    if (!event.isAltPressed()) {
                        handled = arrowScroll(33);
                        break;
                    }
                    handled = fullScroll(33);
                    break;
                case 20:
                    if (!event.isAltPressed()) {
                        handled = arrowScroll(130);
                        break;
                    }
                    handled = fullScroll(130);
                    break;
                case 62:
                    pageScroll(event.isShiftPressed() ? 33 : 130);
                    break;
            }
        }
        return handled;
    } else if (!isFocused() || event.getKeyCode() == 4) {
        return false;
    } else {
        View currentFocused = findFocus();
        if (currentFocused == this) {
            currentFocused = null;
        }
        View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, 130);
        if (nextFocused == null || nextFocused == this || !nextFocused.requestFocus(130)) {
            return false;
        }
        return true;
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:41,代碼來源:NestedScrollView.java

示例14: dispatchKeyEvent

import android.view.KeyEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    //判斷是否是按返回鍵
    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
        L.i("我按了BACK鍵");
        if (mView.getParent() != null) {
            wm.removeView(mView);
        }
        return true;
    }
    return false;
}
 
開發者ID:lijizhi,項目名稱:studydemo,代碼行數:13,代碼來源:SmsService.java

示例15: dispatchKeyEvent

import android.view.KeyEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    final int keyCode = event.getKeyCode();
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            removeAllCallbacks();
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_DPAD_UP:
            if (!mHasSelectorWheel) {
                break;
            }
            switch (event.getAction()) {
                case KeyEvent.ACTION_DOWN:
                    if (mWrapSelectorWheel || (keyCode == KeyEvent.KEYCODE_DPAD_DOWN)
                            ? getValue() < getMaxValue() : getValue() > getMinValue()) {
                        requestFocus();
                        mLastHandledDownDpadKeyCode = keyCode;
                        removeAllCallbacks();
                        if (mFlingScroller.isFinished()) {
                            changeValueByOne(keyCode == KeyEvent.KEYCODE_DPAD_DOWN);
                        }
                        return true;
                    }
                    break;
                case KeyEvent.ACTION_UP:
                    if (mLastHandledDownDpadKeyCode == keyCode) {
                        mLastHandledDownDpadKeyCode = -1;
                        return true;
                    }
                    break;
            }
    }
    return super.dispatchKeyEvent(event);
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:37,代碼來源:NumberPicker.java


注:本文中的android.view.KeyEvent.getKeyCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。