当前位置: 首页>>代码示例>>Java>>正文


Java KeyEvent.getAction方法代码示例

本文整理汇总了Java中android.view.KeyEvent.getAction方法的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.getAction方法的具体用法?Java KeyEvent.getAction怎么用?Java KeyEvent.getAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.KeyEvent的用法示例。


在下文中一共展示了KeyEvent.getAction方法的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:sega4revenge,项目名称:Sega,代码行数:34,代码来源:ViewPagerEx.java

示例2: 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:QuixomTech,项目名称:WeatherStream,代码行数:34,代码来源:CustomViewAbove.java

示例3: onKeyUp

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean onKeyUp(int keyCode, KeyEvent event)
{
	if (event.getAction() == KeyEvent.ACTION_UP)
	{
		switch (keyCode)
		{
			case KeyEvent.KEYCODE_MENU:
			{
				if (getSupportActionBar().isShowing() && menuMore != null && menuMore.findItem(MENU_MORE) != null)
				{
					menuMore.performIdentifierAction(MENU_MORE, 0);

					return true;
				}
			}
		}
	}
	
	return super.onKeyUp(keyCode, event);
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:22,代码来源:ImageViewerActivity.java

示例4: onKeyDown

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (DebugConstant.DOUBLECLICK_EXIT) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            if (System.currentTimeMillis() - firstTime > 2000) {
                Toast.makeText(MainActivity.this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
                firstTime = System.currentTimeMillis();
            } else {
                finish();
                System.exit(0);
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
开发者ID:HurTeng,项目名称:StormPlane,代码行数:17,代码来源:MainActivity.java

示例5: dispatchKeyEvent

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
            this.exitApp();
        }
        return true;
    }
    return super.dispatchKeyEvent(event);
}
 
开发者ID:ligongzai,项目名称:QianXun,代码行数:11,代码来源:MainActivity.java

示例6: sendKeyEvent

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean sendKeyEvent(KeyEvent event) {
    if (keyboardListener != null) {
        if (event.getAction() == KeyEvent.ACTION_DOWN
                && event.getKeyCode() == KeyEvent.KEYCODE_DEL) { // Backspace key
            keyboardListener.onKeyboardBackspace();
        }
    }
    return super.sendKeyEvent(event);
}
 
开发者ID:tylersuehr7,项目名称:chips-input-layout,代码行数:11,代码来源:ChipEditText.java

示例7: onKeyDown

import android.view.KeyEvent; //导入方法依赖的package包/类
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        completeRoute = true;
        finish();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
开发者ID:yiwent,项目名称:Mobike,代码行数:9,代码来源:RouteDetailActivity.java

示例8: onKeyDown

import android.view.KeyEvent; //导入方法依赖的package包/类
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() != 4) {
        return super.onKeyDown(keyCode, event);
    }
    if (!this.canBack) {
        return true;
    }
    setResult(258);
    finish();
    return true;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:12,代码来源:VipOrderDetailActivity.java

示例9: onKeyDown

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN)
    {
        pressAgainExit();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
开发者ID:dufangyu1990,项目名称:JKApp,代码行数:10,代码来源:FragmentActivityPresentImpl.java

示例10: 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

示例11: 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:
            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:h6ah4i,项目名称:android-numberpickercompat,代码行数:34,代码来源:NumberPicker.java

示例12: onKeyDown

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (wvWeb.canGoBack()) {
                wvWeb.goBack();
            } else {
                finish();
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
开发者ID:lueans,项目名称:LueansRead,代码行数:15,代码来源:WebActivity.java

示例13: onKeyPreIme

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
	if (event.getKeyCode() == KeyEvent.KEYCODE_BACK &&
				event.getAction() == KeyEvent.ACTION_UP) {
		if (mOnImeBack != null)
			mOnImeBack.onImeBack(this, this.getText().toString());
	}
	return super.dispatchKeyEvent(event);
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:10,代码来源:EditTextBackEvent.java

示例14: onKey

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    switch (event.getAction()){
        case KeyEvent.ACTION_DOWN:
            return handleKeyActionDown(v, keyCode, event);

        case KeyEvent.ACTION_UP:
            return handleKeyActionUp(v, keyCode, event);
    }
    return false;
}
 
开发者ID:jiajunhui,项目名称:PlayerBase,代码行数:12,代码来源:BaseFocusCover.java

示例15: onKey

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        finishActivity();
    }
    return false;
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:8,代码来源:UnsupportedFragment.java


注:本文中的android.view.KeyEvent.getAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。