Java Code Examples for android.view.KeyEvent#KEYCODE_BACK

The following examples show how to use android.view.KeyEvent#KEYCODE_BACK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From WanAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {

        if (mDrawerLayout.isDrawerOpen(Gravity.START)) {
            mDrawerLayout.closeDrawer(Gravity.START);
            return true;
        }

        if (System.currentTimeMillis() - mExitTime < 2000) {
            finish();
        } else {
            mExitTime = System.currentTimeMillis();
            ToastUtils.showToast(AppContext.getContext(), "请再按一次退出程序");
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 2
Source File: MainActivity.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
/**
 * 是当某个按键被按下是触发。所以也有人在点击返回键的时候去执行该方法来做判断
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    LogUtils.e("触摸监听", "onKeyDown");
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (mPlayFragment != null && isPlayFragmentShow) {
            hidePlayingFragment();
        }else {
            //双击返回桌面
            if ((System.currentTimeMillis() - time > 1000)) {
                ToastUtils.showRoundRectToast("再按一次返回桌面");
                time = System.currentTimeMillis();
            } else {
                moveTaskToBack(true);
            }
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 3
Source File: FindToolbar.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
            // Tell the framework to start tracking this event.
            getKeyDispatcherState().startTracking(event, this);
            return true;
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            getKeyDispatcherState().handleUpEvent(event);
            if (event.isTracking() && !event.isCanceled()) {
                mFindToolbar.deactivate();
                return true;
            }
        }
    }
    return false;
}
 
Example 4
Source File: GankWebActivity.java    From Gank-Veaer with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                if (mWebView.canGoBack()) {
                    mWebView.goBack();
                }
                else {
                    finish();
                }
                return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 5
Source File: TopicContentActivity.java    From diycode with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        finish();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 6
Source File: BasePickerView.java    From Android-PickerView with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == MotionEvent.ACTION_DOWN && isShowing()) {
        dismiss();
        return true;
    }
    return false;
}
 
Example 7
Source File: MainActivity.java    From Os-FileUp with MIT License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event){
    if(event.getAction() == KeyEvent.ACTION_DOWN){
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (webView.canGoBack()) {
                webView.goBack();
            } else {
                finish();
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 8
Source File: IjkVideoView.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK &&
            keyCode != KeyEvent.KEYCODE_VOLUME_UP &&
            keyCode != KeyEvent.KEYCODE_VOLUME_DOWN &&
            keyCode != KeyEvent.KEYCODE_VOLUME_MUTE &&
            keyCode != KeyEvent.KEYCODE_MENU &&
            keyCode != KeyEvent.KEYCODE_CALL &&
            keyCode != KeyEvent.KEYCODE_ENDCALL;
    if (isInPlaybackState() && isKeyCodeSupported && mMediaController != null) {
        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK ||
                keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();
                mMediaController.show();
            } else {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
            if (!mMediaPlayer.isPlaying()) {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP
                || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();
                mMediaController.show();
            }
            return true;
        } else {
            toggleMediaControlsVisiblity();
        }
    }

    return super.onKeyDown(keyCode, event);
}
 
Example 9
Source File: MainActivity.java    From Modularity with Apache License 2.0 5 votes vote down vote up
private boolean handleExitTip(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (isOnKeyBacking) {
            mMainLoopHandler.removeCallbacks(onBackTimeRunnable);
            isOnKeyBacking = false;
            finish();
        } else {
            isOnKeyBacking = true;
            showExitTip();
            mMainLoopHandler.postDelayed(onBackTimeRunnable, 2000);
        }
        return true;
    }
    return false;
}
 
Example 10
Source File: GameActivity.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        ResourcesManager.getInstance().storyService.getCurrentScene().onBackKeyPressed();
    }

    return false;
}
 
Example 11
Source File: WelcomeActivity.java    From GifAssistant with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	// TODO Auto-generated method stub
	if(keyCode == KeyEvent.KEYCODE_BACK) {
		return false;
	}
	return false;
}
 
Example 12
Source File: SearchViewLayout.java    From Search-View-Layout with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
            isExpanded()) {
        boolean keyboardHidden = Utils.hideInputMethod(v);
        if (keyboardHidden) return true;
        collapse();
        return true;
    }
    return false;
}
 
Example 13
Source File: UnlockGesturePasswordActivity.java    From quickmark with MIT License 5 votes vote down vote up
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK) { // ���/����/���η��ؼ�
		if ((flag == "clear") || (flag == "md") || (flag == "enable")) {
			finish();
		} else {
			dialogShowUtil.dialogShow("shake", "quit", "", "");
		}
		return true;
	}
	return super.onKeyDown(keyCode, event);
}
 
Example 14
Source File: Cocos2dxEditText.java    From Earlybird with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) {
	super.onKeyDown(keyCode, keyEvent);

	/* Let GlSurfaceView get focus if back key is input. */
	if (keyCode == KeyEvent.KEYCODE_BACK) {
		//Cocos2dxHelper.nativeRequestFocus();
	}

	return true;
}
 
Example 15
Source File: GosDeviceReadyActivity.java    From GOpenSource_AppKit_Android_AS with MIT License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK) {
		quitAlert(this);
		return true;
	}
	return false;
}
 
Example 16
Source File: CordovaActivity.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    //Determine if the focus is on the current view or not
    if (appView != null && appView.getFocusedChild() != null && (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU)) {
                return appView.onKeyDown(keyCode, event);
    }
    else
        return super.onKeyDown(keyCode, event);
}
 
Example 17
Source File: RegistrationActivity.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK) {
		Intent i = new Intent();
		i.setAction(Intent.ACTION_MAIN);
		i.addCategory(Intent.CATEGORY_HOME);
		this.startActivity(i);
		finish();
		return true;
	} else if (keyCode == KeyEvent.KEYCODE_HOME) {
		finish();
		return true;
	}
	return super.onKeyDown(keyCode, event);
}
 
Example 18
Source File: CordovaWebViewImpl.java    From cordova-plugin-app-update-demo with MIT License 4 votes vote down vote up
@Override
public Boolean onDispatchKeyEvent(KeyEvent event) {
    int keyCode = event.getKeyCode();
    boolean isBackButton = keyCode == KeyEvent.KEYCODE_BACK;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        if (isBackButton && mCustomView != null) {
            return true;
        } else if (boundKeyCodes.contains(keyCode)) {
            return true;
        } else if (isBackButton) {
            return engine.canGoBack();
        }
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
        if (isBackButton && mCustomView != null) {
            hideCustomView();
            return true;
        } else if (boundKeyCodes.contains(keyCode)) {
            String eventName = null;
            switch (keyCode) {
                case KeyEvent.KEYCODE_VOLUME_DOWN:
                    eventName = "volumedownbutton";
                    break;
                case KeyEvent.KEYCODE_VOLUME_UP:
                    eventName = "volumeupbutton";
                    break;
                case KeyEvent.KEYCODE_SEARCH:
                    eventName = "searchbutton";
                    break;
                case KeyEvent.KEYCODE_MENU:
                    eventName = "menubutton";
                    break;
                case KeyEvent.KEYCODE_BACK:
                    eventName = "backbutton";
                    break;
            }
            if (eventName != null) {
                sendJavascriptEvent(eventName);
                return true;
            }
        } else if (isBackButton) {
            return engine.goBack();
        }
    }
    return null;
}
 
Example 19
Source File: AndroidControllers.java    From gdx-controllerutils with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onKey (View view, int keyCode, KeyEvent keyEvent) {
	if (ignoreNoGamepadButtons && !keyEvent.isGamepadButton(keyCode)) {
		return false;
	}
	AndroidController controller = controllerMap.get(keyEvent.getDeviceId());
	if(controller != null) {
		if(controller.getButton(keyCode) && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
			return true;
		}
		synchronized(eventQueue) {
			AndroidControllerEvent event = eventPool.obtain();
			event.controller = controller;
			if(keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
				if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
					event.type = AndroidControllerEvent.POV;
					controller.pov |= 0x00000001;
					event.povDirection = controller.getPov(0);
				} else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
					event.type = AndroidControllerEvent.POV;
					controller.pov |= 0x00000010;
					event.povDirection = controller.getPov(0);
				} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
					event.type = AndroidControllerEvent.POV;
					controller.pov |= 0x00000100;
					event.povDirection = controller.getPov(0);
				} else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
					event.type = AndroidControllerEvent.POV;
					controller.pov |= 0x00001000;
					event.povDirection = controller.getPov(0);
				} else {
					event.type = AndroidControllerEvent.BUTTON_DOWN;
					event.code = keyCode;
				}
			} else {
				if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
					event.type = AndroidControllerEvent.POV;
					controller.pov &= 0x00001110;
					event.povDirection = controller.getPov(0);
				} else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
					event.type = AndroidControllerEvent.POV;
					controller.pov &= 0x00001101;
					event.povDirection = controller.getPov(0);
				} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
					event.type = AndroidControllerEvent.POV;
					controller.pov &= 0x00001011;
					event.povDirection = controller.getPov(0);
				} else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
					event.type = AndroidControllerEvent.POV;
					controller.pov &= 0x00000111;
					event.povDirection = controller.getPov(0);
				} else {
					event.type = AndroidControllerEvent.BUTTON_UP;
					event.code = keyCode;
				}
			}
			eventQueue.add(event);
		}
		if (keyCode == KeyEvent.KEYCODE_BACK && !Gdx.input.isCatchBackKey()) {
			return false;
		}
		return true;
	} else {
		return false;
	}
}
 
Example 20
Source File: MediaController.java    From BambooPlayer with Apache License 2.0 4 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
	int keyCode = event.getKeyCode();
	int keyMode = event.getAction();

	if (keyMode == KeyEvent.ACTION_DOWN) {
		switch (keyCode) {
		case KeyEvent.KEYCODE_VOLUME_MUTE:
			return super.dispatchKeyEvent(event);
		case KeyEvent.KEYCODE_VOLUME_UP:
		case KeyEvent.KEYCODE_VOLUME_DOWN:
			mVolume = mAM.getStreamVolume(AudioManager.STREAM_MUSIC);
			int step = keyCode == KeyEvent.KEYCODE_VOLUME_UP ? 1 : -1;
			setVolume(mVolume + step);
			mHandler.removeMessages(MSG_HIDE_OPERATION_VOLLUM);
			mHandler.sendEmptyMessageDelayed(MSG_HIDE_OPERATION_VOLLUM, 500);
			return true;
		}

		if (isLocked() && keyCode != KeyEvent.KEYCODE_BACK) {
			show();
			return true;
		}

		if (event.getRepeatCount() == 0
				&& (keyCode == KeyEvent.KEYCODE_HEADSETHOOK
						|| keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_SPACE)) {
			doPauseResume();
			show(DEFAULT_TIME_OUT);
			return true;
		} else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP) {
			if (mPlayer.isPlaying()) {
				mPlayer.pause();
				updatePausePlay();
			}
			return true;
		} else if (keyCode == KeyEvent.KEYCODE_BACK) {
			pressbacktime++;
			if (pressbacktime > 1) {
				release();
			}
			mPlayer.stop(pressbacktime);
			return true;
		} else {
			show(DEFAULT_TIME_OUT);
		}
		return super.dispatchKeyEvent(event);
	} else {
		return super.dispatchKeyEvent(event);
	}
}