Java Code Examples for android.view.KeyEvent#KEYCODE_SEARCH
The following examples show how to use
android.view.KeyEvent#KEYCODE_SEARCH .
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: Settings.java From Slide with GNU General Public License v3.0 | 6 votes |
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_SEARCH && event.getAction() == KeyEvent.ACTION_DOWN) { onOptionsItemSelected(mToolbar.getMenu().findItem(R.id.search)); // (findViewById(R.id.settings_search)).requestFocus(); MotionEvent motionEventDown = MotionEvent.obtain( SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 0, 0, 0 ); MotionEvent motionEventUp = MotionEvent.obtain( SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 0, 0, 0 ); (findViewById(R.id.settings_search)).dispatchTouchEvent(motionEventDown); (findViewById(R.id.settings_search)).dispatchTouchEvent(motionEventUp); return true; } return super.dispatchKeyEvent(event); }
Example 2
Source File: TextFrag.java From PowerFileExplorer with GNU General Public License v3.0 | 6 votes |
public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_SEARCH) { mProcSearch.run(); return true; } if (keyCode == KeyEvent.KEYCODE_BACK && mBackkeyDown) { mBackkeyDown = false; if (mLlSearch.getVisibility() == View.VISIBLE) { mBtnClose.performClick(); return true; } // if (confirmSave(mProcQuit)) { if (fragActivity instanceof TextEditorActivity) { ((TextEditorActivity)fragActivity).quit(); return true; } } //return super.onKeyUp(keyCode, event); return false; }
Example 3
Source File: MarkerListActivity.java From mytracks with Apache License 2.0 | 5 votes |
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_SEARCH && searchMenuItem != null) { if (ApiAdapterFactory.getApiAdapter().handleSearchKey(searchMenuItem)) { return true; } } return super.onKeyUp(keyCode, event); }
Example 4
Source File: CommentPage.java From Slide with GNU General Public License v3.0 | 5 votes |
public boolean onKeyDown(int keyCode, KeyEvent event) { //This is the filter if (event.getAction() != KeyEvent.ACTION_DOWN) return true; if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { goDown(); return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { goUp(); return true; } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { return onMenuItemClick(toolbar.getMenu().findItem(R.id.search)); } return false; }
Example 5
Source File: AppList.java From CustomText with Apache License 2.0 | 5 votes |
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_SEARCH && (event.getFlags() & KeyEvent.FLAG_CANCELED) == 0) { SearchView searchV = (SearchView) findViewById(R.id.searchApp); if (searchV.isShown()) { searchV.setIconified(false); return true; } } return super.onKeyUp(keyCode, event); }
Example 6
Source File: SearchView.java From CSipSimple with GNU General Public License v3.0 | 4 votes |
/** * React to the user typing while in the suggestions list. First, check for * action keys. If not handled, try refocusing regular characters into the * EditText. */ private boolean onSuggestionsKey(View v, int keyCode, KeyEvent event) { // guard against possible race conditions (late arrival after dismiss) if (mSearchable == null) { return false; } if (mSuggestionsAdapter == null) { return false; } if (event.getAction() == KeyEvent.ACTION_DOWN && KeyEventCompat.hasNoModifiers(event)) { // First, check for enter or search (both of which we'll treat as a // "click") if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_TAB) { int position = mQueryTextView.getListSelection(); return onItemClicked(position, KeyEvent.KEYCODE_UNKNOWN, null); } // Next, check for left/right moves, which we use to "return" the // user to the edit view if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { // give "focus" to text editor, with cursor at the beginning if // left key, at end if right key // TODO: Reverse left/right for right-to-left languages, e.g. // Arabic int selPoint = (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) ? 0 : mQueryTextView .length(); mQueryTextView.setSelection(selPoint); mQueryTextView.setListSelection(0); mQueryTextView.clearListSelection(); ensureImeVisible(mQueryTextView, true); return true; } // Next, check for an "up and out" move if (keyCode == KeyEvent.KEYCODE_DPAD_UP && 0 == mQueryTextView.getListSelection()) { // TODO: restoreUserQuery(); // let ACTV complete the move return false; } // Next, check for an "action key" // TODO SearchableInfo.ActionKeyInfo actionKey = mSearchable.findActionKey(keyCode); // TODO if ((actionKey != null) // TODO && ((actionKey.getSuggestActionMsg() != null) || (actionKey // TODO .getSuggestActionMsgColumn() != null))) { // TODO // launch suggestion using action key column // TODO int position = mQueryTextView.getListSelection(); // TODO if (position != ListView.INVALID_POSITION) { // TODO Cursor c = mSuggestionsAdapter.getCursor(); // TODO if (c.moveToPosition(position)) { // TODO final String actionMsg = getActionKeyMessage(c, actionKey); // TODO if (actionMsg != null && (actionMsg.length() > 0)) { // TODO return onItemClicked(position, keyCode, actionMsg); // TODO } // TODO } // TODO } // TODO } } return false; }
Example 7
Source File: TelevisionNavigationController.java From talkback with Apache License 2.0 | 4 votes |
@Override public boolean onKeyEvent(KeyEvent event, EventId eventId) { service.getInputModeManager().setInputMode(InputModeManager.INPUT_MODE_TV_REMOTE); WindowManager windowManager = new WindowManager(service); // Let the system handle keyboards. The keys are input-focusable so this works fine. // Note: on Android TV, it looks like the on-screen IME always appears, even when a physical // keyboard is connected, so this check will allow the system to handle all typing on // physical keyboards as well. This behavior is current as of Nougat. if (windowManager.isInputWindowOnScreen()) { return false; } // Note: we getCursorOrInputCursor because we want to avoid getting the root if there // is no cursor; getCursor is defined as getting the root if there is no a11y focus. AccessibilityNodeInfoCompat cursor = accessibilityFocusMonitor.getAccessibilityFocus(/* useInputFocusIfEmpty= */ true); try { if (shouldIgnore(cursor, event)) { return false; } // TalkBack should always consume up/down/left/right on the d-pad. Otherwise, strange // things will happen when TalkBack cannot navigate further. // For example, TalkBack cannot control the gray-highlighted item in a ListView; the // view itself controls the highlighted item. So if the key event gets propagated to the // list view at the end of the list, the scrolling will jump to the highlighted item. if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_DOWN: // Directional navigation takes a non-trivial amount of time, so we should // post to the handler and return true immediately. handler.postDirectionalKeyEvent(event, cursor, eventId); return true; case KeyEvent.KEYCODE_DPAD_CENTER: // Can't post to handler because the return value might vary. boolean handledCenter = onCenterKey(cursor, eventId); handledKeyDown.put(KeyEvent.KEYCODE_DPAD_CENTER, handledCenter); return handledCenter; case KeyEvent.KEYCODE_ENTER: // Note: handling the Enter key won't interfere with typing because // we skip key event handling above if the IME is visible. (See above: // this will also skip handling the Enter key if using a physical keyboard.) // Can't post to handler because the return value might vary. boolean handledEnter = onCenterKey(cursor, eventId); handledKeyDown.put(KeyEvent.KEYCODE_ENTER, handledEnter); return handledEnter; case KeyEvent.KEYCODE_SEARCH: if (treeDebugEnabled) { TreeDebug.logNodeTrees(AccessibilityServiceCompatUtils.getWindows(service)); return true; } break; default: // fall out } } else { // We need to cancel the corresponding up key action if we consumed the down action. switch (event.getKeyCode()) { case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_DOWN: return true; case KeyEvent.KEYCODE_DPAD_CENTER: if (handledKeyDown.get(KeyEvent.KEYCODE_DPAD_CENTER)) { handledKeyDown.delete(KeyEvent.KEYCODE_DPAD_CENTER); return true; } break; case KeyEvent.KEYCODE_ENTER: if (handledKeyDown.get(KeyEvent.KEYCODE_ENTER)) { handledKeyDown.delete(KeyEvent.KEYCODE_ENTER); return true; } break; case KeyEvent.KEYCODE_SEARCH: if (treeDebugEnabled) { return true; } break; default: // fall out } } } finally { AccessibilityNodeInfoUtils.recycleNodes(cursor); } return false; }
Example 8
Source File: VolumeAccessibilityService.java From Noyze with Apache License 2.0 | 4 votes |
@Override protected boolean onKeyEvent(KeyEvent event) { if (null == event) return true; // WTF?? // Make sure we're not in the middle of a phone call. if (null != mVolumePanel && mVolumePanel.getCallState() != TelephonyManager.CALL_STATE_IDLE) return super.onKeyEvent(event); final int flags = event.getFlags(); final int code = event.getKeyCode(); final boolean system = ((flags & KeyEvent.FLAG_FROM_SYSTEM) == KeyEvent.FLAG_FROM_SYSTEM); // Specifically avoid software keys or "fake" hardware buttons. if (((flags & KeyEvent.FLAG_SOFT_KEYBOARD) == KeyEvent.FLAG_SOFT_KEYBOARD) || ((flags & KeyEvent.FLAG_VIRTUAL_HARD_KEY) == KeyEvent.FLAG_VIRTUAL_HARD_KEY)) { return super.onKeyEvent(event); } else { // Specifically avoid handling certain keys. We never want to interfere // with them or harm performance in any way. switch (code) { case KeyEvent.KEYCODE_BACK: case KeyEvent.KEYCODE_HOME: case KeyEvent.KEYCODE_MENU: case KeyEvent.KEYCODE_POWER: case KeyEvent.KEYCODE_SEARCH: return super.onKeyEvent(event); } } if (!system) return super.onKeyEvent(event); LOGI(TAG, "--onKeyEvent(code=" + event.getKeyCode() + ", action=" + event.getAction() + ", topPackage=" + mCurrentActivityPackage + ", disabledButtons=" + disabledButtons + ')'); // Check if we're supposed to disable Noyze for a Blacklisted app. if (blacklist.contains(mCurrentActivityPackage)) { if (null != mVolumePanel) mVolumePanel.setEnabled(false); return super.onKeyEvent(event); } else { // NOTE: we need a "safe" way to enable the volume panel that // takes into consideration its previous state. if (null != mVolumePanel) mVolumePanel.enable(); } // If we're told to disable one or more of the volume buttons, do so (returning true consumes the event). if (disabledButtons == code) return true; // NOTE: KeyEvent#KEYCODE_VOLUME_DOWN + KeyEvent#KEYCODE_VOLUME_UP == KeyEvent_KEYCODE_U final int upAndDown = (KeyEvent.KEYCODE_VOLUME_DOWN + KeyEvent.KEYCODE_VOLUME_UP); // 49 final int upSquared = KeyEvent.KEYCODE_VOLUME_UP * KeyEvent.KEYCODE_VOLUME_UP; // 576 if (disabledButtons == upAndDown && Utils.isVolumeKeyCode(upAndDown - code)) return true; if (disabledButtons == upSquared && mVolumePanel != null && mVolumePanel.isLocked()) return true; if (disabledButtons == upSquared && KEYGUARD.equals(mCurrentActivityPackage)) return true; // Check if the volume panel has been disabled, or shouldn't handle this event (e.g. "safe volume"). if (null != mVolumePanel && mVolumePanel.isEnabled()) { if (Utils.isVolumeKeyCode(code)) { Message.obtain(mHandler, MESSAGE_KEY_EVENT, event).sendToTarget(); // Run asynchronously return true; } } return super.onKeyEvent(event); }
Example 9
Source File: CordovaWebViewImpl.java From pychat with MIT License | 4 votes |
@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 10
Source File: CordovaWebViewImpl.java From app-icon with MIT License | 4 votes |
@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 11
Source File: YoukuBasePlayerManager.java From Dota2Helper with Apache License 2.0 | 4 votes |
public boolean onKeyDown(int keyCode, KeyEvent event) { shouldCallSuperKeyDown = false; try { switch (keyCode) { case KeyEvent.KEYCODE_MENU: // 取消长按menu键弹出键盘事�? if (event.getRepeatCount() > 0) { return true; } return mediaPlayerDelegate.isFullScreen; case KeyEvent.KEYCODE_BACK: // 点击过快的取消操�? if (event.getRepeatCount() > 0) { return true; } if (!mediaPlayerDelegate.isDLNA) { if (mediaPlayerDelegate.isFullScreen && !isFromLocal() && (mediaPlayerDelegate.videoInfo != null && !mediaPlayerDelegate.videoInfo.isHLS)) { goSmall(); return true; } else { onkeyback(); return true; } } else { return true; } case KeyEvent.KEYCODE_VOLUME_DOWN: return volumeDown(); case KeyEvent.KEYCODE_VOLUME_UP: return volumeUp(); case KeyEvent.KEYCODE_SEARCH: return mediaPlayerDelegate.isFullScreen; case 125: /** 有些手机载入中弹出popupwindow */ return true; } } catch (Exception e) { e.printStackTrace(); } shouldCallSuperKeyDown = true; return false; }
Example 12
Source File: CordovaWebView.java From cordova-android-chromeview with Apache License 2.0 | 4 votes |
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { // If back key if (keyCode == KeyEvent.KEYCODE_BACK) { // A custom view is currently displayed (e.g. playing a video) if(mCustomView != null) { this.hideCustomView(); } else { // The webview is currently displayed // If back key is bound, then send event to JavaScript if (this.bound) { this.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');"); return true; } else { // If not bound // Go to previous page in webview if it is possible to go back if (this.backHistory()) { return true; } // If not, then invoke default behaviour else { //this.activityState = ACTIVITY_EXITING; //return false; // If they hit back button when app is initializing, app should exit instead of hang until initilazation (CB2-458) this.cordova.getActivity().finish(); } } } } // Legacy else if (keyCode == KeyEvent.KEYCODE_MENU) { if (this.lastMenuEventTime < event.getEventTime()) { this.loadUrl("javascript:cordova.fireDocumentEvent('menubutton');"); } this.lastMenuEventTime = event.getEventTime(); return super.onKeyUp(keyCode, event); } // If search key else if (keyCode == KeyEvent.KEYCODE_SEARCH) { this.loadUrl("javascript:cordova.fireDocumentEvent('searchbutton');"); return true; } else if(keyUpCodes.contains(keyCode)) { //What the hell should this do? return super.onKeyUp(keyCode, event); } //Does webkit change this behavior? return super.onKeyUp(keyCode, event); }
Example 13
Source File: CordovaWebViewImpl.java From BigDataPlatform with GNU General Public License v3.0 | 4 votes |
@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 14
Source File: VolumeAccessibilityService.java From Noyze with Apache License 2.0 | 4 votes |
@Override protected boolean onKeyEvent(KeyEvent event) { if (null == event) return true; // WTF?? // Make sure we're not in the middle of a phone call. if (null != mVolumePanel && mVolumePanel.getCallState() != TelephonyManager.CALL_STATE_IDLE) return super.onKeyEvent(event); final int flags = event.getFlags(); final int code = event.getKeyCode(); final boolean system = ((flags & KeyEvent.FLAG_FROM_SYSTEM) == KeyEvent.FLAG_FROM_SYSTEM); // Specifically avoid software keys or "fake" hardware buttons. if (((flags & KeyEvent.FLAG_SOFT_KEYBOARD) == KeyEvent.FLAG_SOFT_KEYBOARD) || ((flags & KeyEvent.FLAG_VIRTUAL_HARD_KEY) == KeyEvent.FLAG_VIRTUAL_HARD_KEY)) { return super.onKeyEvent(event); } else { // Specifically avoid handling certain keys. We never want to interfere // with them or harm performance in any way. switch (code) { case KeyEvent.KEYCODE_BACK: case KeyEvent.KEYCODE_HOME: case KeyEvent.KEYCODE_MENU: case KeyEvent.KEYCODE_POWER: case KeyEvent.KEYCODE_SEARCH: return super.onKeyEvent(event); } } if (!system) return super.onKeyEvent(event); LOGI(TAG, "--onKeyEvent(code=" + event.getKeyCode() + ", action=" + event.getAction() + ", topPackage=" + mCurrentActivityPackage + ", disabledButtons=" + disabledButtons + ')'); // Check if we're supposed to disable Noyze for a Blacklisted app. if (blacklist.contains(mCurrentActivityPackage)) { if (null != mVolumePanel) mVolumePanel.setEnabled(false); return super.onKeyEvent(event); } else { // NOTE: we need a "safe" way to enable the volume panel that // takes into consideration its previous state. if (null != mVolumePanel) mVolumePanel.enable(); } // If we're told to disable one or more of the volume buttons, do so (returning true consumes the event). if (disabledButtons == code) return true; // NOTE: KeyEvent#KEYCODE_VOLUME_DOWN + KeyEvent#KEYCODE_VOLUME_UP == KeyEvent_KEYCODE_U final int upAndDown = (KeyEvent.KEYCODE_VOLUME_DOWN + KeyEvent.KEYCODE_VOLUME_UP); // 49 final int upSquared = KeyEvent.KEYCODE_VOLUME_UP * KeyEvent.KEYCODE_VOLUME_UP; // 576 if (disabledButtons == upAndDown && Utils.isVolumeKeyCode(upAndDown - code)) return true; if (disabledButtons == upSquared && mVolumePanel != null && mVolumePanel.isLocked()) return true; if (disabledButtons == upSquared && KEYGUARD.equals(mCurrentActivityPackage)) return true; // Check if the volume panel has been disabled, or shouldn't handle this event (e.g. "safe volume"). if (null != mVolumePanel && mVolumePanel.isEnabled()) { if (Utils.isVolumeKeyCode(code)) { Message.obtain(mHandler, MESSAGE_KEY_EVENT, event).sendToTarget(); // Run asynchronously return true; } } return super.onKeyEvent(event); }
Example 15
Source File: InCallActivity.java From CSipSimple with GNU General Public License v3.0 | 4 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { Log.d(THIS_FILE, "Key down : " + keyCode); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_UP: // // Volume has been adjusted by the user. // Log.d(THIS_FILE, "onKeyDown: Volume button pressed"); int action = AudioManager.ADJUST_RAISE; if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { action = AudioManager.ADJUST_LOWER; } // Detect if ringing SipCallSession currentCallInfo = getActiveCallInfo(); // If not any active call active if (currentCallInfo == null && serviceConnected) { break; } if (service != null) { try { service.adjustVolume(currentCallInfo, action, AudioManager.FLAG_SHOW_UI); } catch (RemoteException e) { Log.e(THIS_FILE, "Can't adjust volume", e); } } return true; case KeyEvent.KEYCODE_CALL: case KeyEvent.KEYCODE_ENDCALL: return inCallAnswerControls.onKeyDown(keyCode, event); case KeyEvent.KEYCODE_SEARCH: // Prevent search return true; default: // Nothing to do } return super.onKeyDown(keyCode, event); }
Example 16
Source File: CordovaWebView.java From bluemix-parking-meter with MIT License | 4 votes |
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { // If back key if (keyCode == KeyEvent.KEYCODE_BACK) { // A custom view is currently displayed (e.g. playing a video) if(mCustomView != null) { this.hideCustomView(); return true; } else { // The webview is currently displayed // If back key is bound, then send event to JavaScript if (isButtonPlumbedToJs(KeyEvent.KEYCODE_BACK)) { sendJavascriptEvent("backbutton"); return true; } else { // If not bound // Go to previous page in webview if it is possible to go back if (this.backHistory()) { return true; } // If not, then invoke default behavior } } } // Legacy else if (keyCode == KeyEvent.KEYCODE_MENU) { if (this.lastMenuEventTime < event.getEventTime()) { sendJavascriptEvent("menubutton"); } this.lastMenuEventTime = event.getEventTime(); return super.onKeyUp(keyCode, event); } // If search key else if (keyCode == KeyEvent.KEYCODE_SEARCH) { sendJavascriptEvent("searchbutton"); return true; } //Does webkit change this behavior? return super.onKeyUp(keyCode, event); }
Example 17
Source File: KeyboardShortcuts.java From 365browser with Apache License 2.0 | 4 votes |
/** * This should be called from the Activity's dispatchKeyEvent() to handle keyboard shortcuts. * * Note: dispatchKeyEvent() is called before the active view or web page gets a chance to handle * the key event. So the keys handled here cannot be overridden by any view or web page. * * @param event The KeyEvent to handle. * @param activity The ChromeActivity in which the key was pressed. * @param uiInitialized Whether the UI has been initialized. If this is false, most keys will * not be handled. * @return True if the event was handled. False if the event was ignored. Null if the event * should be handled by the activity's parent class. */ @SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL") public static Boolean dispatchKeyEvent(KeyEvent event, ChromeActivity activity, boolean uiInitialized) { int keyCode = event.getKeyCode(); if (!uiInitialized) { if (keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_MENU) return true; return null; } switch (keyCode) { case KeyEvent.KEYCODE_SEARCH: if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { activity.onMenuOrKeyboardAction(R.id.focus_url_bar, false); } // Always consume the SEARCH key events to prevent android from showing // the default app search UI, which locks up Chrome. return true; case KeyEvent.KEYCODE_MENU: if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { activity.onMenuOrKeyboardAction(R.id.show_menu, false); } return true; case KeyEvent.KEYCODE_ESCAPE: if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { if (activity.exitFullscreenIfShowing()) return true; } break; case KeyEvent.KEYCODE_TV: case KeyEvent.KEYCODE_GUIDE: case KeyEvent.KEYCODE_DVR: case KeyEvent.KEYCODE_AVR_INPUT: case KeyEvent.KEYCODE_AVR_POWER: case KeyEvent.KEYCODE_STB_INPUT: case KeyEvent.KEYCODE_STB_POWER: case KeyEvent.KEYCODE_TV_INPUT: case KeyEvent.KEYCODE_TV_POWER: case KeyEvent.KEYCODE_WINDOW: // Do not consume the AV device-related keys so that the system will take // an appropriate action, such as switching to TV mode. return false; } return null; }
Example 18
Source File: CordovaWebViewImpl.java From countly-sdk-cordova with MIT License | 4 votes |
@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: CordovaWebView.java From CordovaYoutubeVideoPlayer with MIT License | 4 votes |
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { // If back key if (keyCode == KeyEvent.KEYCODE_BACK) { // A custom view is currently displayed (e.g. playing a video) if(mCustomView != null) { this.hideCustomView(); } else { // The webview is currently displayed // If back key is bound, then send event to JavaScript if (this.bound) { this.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');"); return true; } else { // If not bound // Go to previous page in webview if it is possible to go back if (this.backHistory()) { return true; } // If not, then invoke default behavior else { //this.activityState = ACTIVITY_EXITING; //return false; // If they hit back button when app is initializing, app should exit instead of hang until initialization (CB2-458) this.cordova.getActivity().finish(); } } } } // Legacy else if (keyCode == KeyEvent.KEYCODE_MENU) { if (this.lastMenuEventTime < event.getEventTime()) { this.loadUrl("javascript:cordova.fireDocumentEvent('menubutton');"); } this.lastMenuEventTime = event.getEventTime(); return super.onKeyUp(keyCode, event); } // If search key else if (keyCode == KeyEvent.KEYCODE_SEARCH) { this.loadUrl("javascript:cordova.fireDocumentEvent('searchbutton');"); return true; } else if(keyUpCodes.contains(keyCode)) { //What the hell should this do? return super.onKeyUp(keyCode, event); } //Does webkit change this behavior? return super.onKeyUp(keyCode, event); }
Example 20
Source File: CordovaWebView.java From cordova-amazon-fireos with Apache License 2.0 | 4 votes |
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { // If back key if (keyCode == KeyEvent.KEYCODE_BACK) { // A custom view is currently displayed (e.g. playing a video) if(mCustomView != null) { this.hideCustomView(); return true; } else { // The webview is currently displayed // If back key is bound, then send event to JavaScript if (isButtonPlumbedToJs(KeyEvent.KEYCODE_BACK)) { this.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');"); return true; } else { // If not bound // Go to previous page in webview if it is possible to go back if (this.backHistory()) { return true; } // If not, then invoke default behavior } } } // Legacy if (keyCode == KeyEvent.KEYCODE_MENU) { if (this.lastMenuEventTime < event.getEventTime()) { this.loadUrl("javascript:cordova.fireDocumentEvent('menubutton');"); } this.lastMenuEventTime = event.getEventTime(); return super.onKeyUp(keyCode, event); } // If search key else if (keyCode == KeyEvent.KEYCODE_SEARCH) { this.loadUrl("javascript:cordova.fireDocumentEvent('searchbutton');"); return true; } //Does webkit change this behavior? return super.onKeyUp(keyCode, event); }