Java Code Examples for android.view.KeyEvent

The following are top voted examples for showing how to use android.view.KeyEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: buildAPKsApps   File: CalibrateActivity.java   Source Code and License 7 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_DOWN:
      // Don't allow this value to go to 0. It shuts the screen off.
      if (minBrightness > 1) {
        minBrightness -= 1;
        updateDisplay();
        Util.setActivityBrightness(getWindow(), minBrightness);
      }
      return true;
    case KeyEvent.KEYCODE_VOLUME_UP:
      if (minBrightness < 255) {
        minBrightness += 1;
        updateDisplay();
        Util.setActivityBrightness(getWindow(), minBrightness);
      }
      return true;
    default:
      return super.onKeyDown(keyCode, event);
  }
}
 
Example 2
Project: FreeStreams-TVLauncher   File: MainActivity.java   Source Code and License 7 votes vote down vote up
/**
 * 顶部焦点获取
 *
 * @param keyCode
 * @param event
 * @return
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean focusFlag = false;
    for (View v : mViews) {
        if (v.isFocused()) {
            focusFlag = true;
        }
    }
    Log.d(TAG, "code:" + keyCode + " flag:" + focusFlag);
    if (focusFlag) {
        if (KeyEvent.KEYCODE_DPAD_LEFT == keyCode) {
            if (mCurrentIndex > 0) {
                mViews[--mCurrentIndex].requestFocus();
            }
            return true;
        } else if (KeyEvent.KEYCODE_DPAD_RIGHT == keyCode) {
            if (mCurrentIndex < 2) {
                mViews[++mCurrentIndex].requestFocus();
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 3
Project: airboard   File: AirBoard.java   Source Code and License 6 votes vote down vote up
@Override
  public void onKey(int primaryCode, int[] keyCodes) {
      InputConnection ic = getCurrentInputConnection() ;
      playclick(primaryCode);
      switch (primaryCode) {
          case Keyboard.KEYCODE_DELETE:
              ic.deleteSurroundingText(1, 0);
              break;
          case Keyboard.KEYCODE_SHIFT:
              caps = !caps;
              keyboard.setShifted(caps);
              kv.invalidateAllKeys();
              break;
          case Keyboard.KEYCODE_DONE:
              ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
              break;
          default:
              char code = (char) primaryCode;
              if(Character.isLetter(code) && caps) {
                  code = Character.toUpperCase(code);
              }

              ic.commitText(String.valueOf(code), 1);
break;
      }
  }
 
Example 4
Project: Bigbang   File: KeyPressedTipViewController.java   Source Code and License 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
        String reason = intent.getStringExtra(SYSTEM_REASON);
        if (TextUtils.equals(reason, SYSTEM_HOME_KEY)) {
            //表示按了home键,程序到了后台
            if (currentKeyCode==KeyEvent.KEYCODE_HOME && isLongPressedHome){
                isLongPressedHome=false;
                return;
            }
        }else if(TextUtils.equals(reason, SYSTEM_HOME_KEY_LONG)){
            //表示长按home键,显示最近使用的程序列表
            if (currentKeyCode==KeyEvent.KEYCODE_APP_SWITCH && isLongPressedRecent){
                isLongPressedRecent=false;
                return;
            }
        }else {
            return;
        }
        refreshViewState(false);
    }
}
 
Example 5
Project: keemob   File: CordovaWebViewImpl.java   Source Code and License 6 votes vote down vote up
@Override
public void setButtonPlumbedToJs(int keyCode, boolean override) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_DOWN:
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_BACK:
        case KeyEvent.KEYCODE_MENU:
            // TODO: Why are search and menu buttons handled separately?
            if (override) {
                boundKeyCodes.add(keyCode);
            } else {
                boundKeyCodes.remove(keyCode);
            }
            return;
        default:
            throw new IllegalArgumentException("Unsupported keycode: " + keyCode);
    }
}
 
Example 6
Project: mpr121-androidthings   File: Mpr121InputDriver.java   Source Code and License 6 votes vote down vote up
@Override
public void run() {
    try {
        int data = peripheralDevice.getTouched();

        for (int i = 0; i < Mpr121.NB_ELECTRODES; i++) {
            if ((data & (1 << i)) != 0) {
                if (!inputStatus[i]) {
                    Log.d(TAG, "#" + i + " touched");
                    inputStatus[i] = true;
                    emitInputEvents(keycodes[i], KeyEvent.ACTION_DOWN);
                }
            } else {
                if (inputStatus[i]) {
                    Log.d(TAG, "#" + i + " released");
                    inputStatus[i] = false;
                    emitInputEvents(keycodes[i], KeyEvent.ACTION_UP);
                }
            }
        }
    } catch (IOException e) {
        Log.e(TAG, "Error getting data from peripheral device", e);
    } finally {
        inputHandler.postDelayed(this, SOFTWAREPOLL_DELAY_MS);
    }
}
 
Example 7
Project: Runnest   File: ChallengeTest.java   Source Code and License 6 votes vote down vote up
@Test
public void challengePressBackAndQuit() {
    onView(withId(R.id.search)).perform(click());
    onView(isRoot()).perform(waitForMatch(withId(R.id.empty_layout), UI_TEST_TIMEOUT));
    onView(isAssignableFrom(EditText.class)).perform(typeText("R"), pressKey(KeyEvent.KEYCODE_ENTER));

    tryIsDisplayed(withText("Runnest IHL"), UI_TEST_TIMEOUT);
    onView(withText("Runnest IHL")).perform(click());

    //Create challenge
    onView(isRoot()).perform(waitForMatch(withId(R.id.main_layout), UI_TEST_TIMEOUT));
    onView(withText(R.string.challenge)).perform(click());
    tryIsDisplayed(withId(R.id.define_challenge), UI_TEST_TIMEOUT);
    onView(withId(R.id.customize_positive_btn)).perform(click());

    //Wait
    Espresso.pressBack();
    tryIsDisplayed(withId(android.R.id.button1), UI_TEST_TIMEOUT);
    onView(withText(R.string.quit)).perform(click());
}
 
Example 8
Project: cleaninsights-android-sdk   File: PlaybackOverlayActivity.java   Source Code and License 6 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    PlaybackOverlayFragment playbackOverlayFragment = (PlaybackOverlayFragment) getFragmentManager().findFragmentById(R.id.playback_controls_fragment);
    switch (keyCode) {
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            playbackOverlayFragment.togglePlayback(false);
            return true;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            playbackOverlayFragment.togglePlayback(false);
            return true;
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            if (mPlaybackState == LeanbackPlaybackState.PLAYING) {
                playbackOverlayFragment.togglePlayback(false);
            } else {
                playbackOverlayFragment.togglePlayback(true);
            }
            return true;
        default:
            return super.onKeyUp(keyCode, event);
    }
}
 
Example 9
Project: keemob   File: CordovaWebViewImpl.java   Source Code and License 6 votes vote down vote up
@Override
public void setButtonPlumbedToJs(int keyCode, boolean override) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_DOWN:
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_BACK:
        case KeyEvent.KEYCODE_MENU:
            // TODO: Why are search and menu buttons handled separately?
            if (override) {
                boundKeyCodes.add(keyCode);
            } else {
                boundKeyCodes.remove(keyCode);
            }
            return;
        default:
            throw new IllegalArgumentException("Unsupported keycode: " + keyCode);
    }
}
 
Example 10
Project: Sega   File: ViewPagerEx.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 11
Project: yyox   File: EmoticonsKeyBoard.java   Source Code and License 6 votes vote down vote up
public boolean dispatchKeyEventInFullScreen(KeyEvent event) {

        if (event == null) return false;
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_BACK:
                if (EmoticonsKeyboardUtils.isFullScreen((Activity) getContext()) && mLayoutKVML.isShown()) {
                    reset();
                    return true;
                }
            default:
                if (event.getAction() == KeyEvent.ACTION_DOWN) {
                    boolean isFocused;
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        isFocused = mIMLayout.getETChat().getShowSoftInputOnFocus();
                    } else {
                        isFocused = mIMLayout.getETChat().isFocused();
                    }
                    if (isFocused)
                        mIMLayout.getETChat().onKeyDown(event.getKeyCode(), event);
                }
        }
        return false;
    }
 
Example 12
Project: AliZhiBoHao   File: WebActivity.java   Source Code and License 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
        if (mWebView.getUrl().equals(INDEXURL)) {
            if (System.currentTimeMillis() - exitTime > 2000) {
                CommonUtils.showToast(this, getString(R.string.w_exit_app));
                exitTime = System.currentTimeMillis();
            } else {
                for (int i = 0; i < MyApplication.list.size(); i++) {
                    MyApplication.list.get(i).finish();
                }
            }
        } else {
            mWebView.goBack();
        }
    }
    return true;
}
 
Example 13
Project: aos-Video   File: Browser.java   Source Code and License 6 votes vote down vote up
public boolean onKeyUp(int keyCode, KeyEvent event) {
    boolean ret = false;
    switch (keyCode) {
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
        case KeyEvent.KEYCODE_MEDIA_NEXT:
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            // if (isChild() == true) {
            // final VideoBrowserActivity parent = (VideoBrowserActivity)
            // getParent();
            // parent.launchGlobalResume();
            // }
            ret = true;
    }

    // if (!ret)
    // ret = super.onKeyUp(keyCode, event);

    return ret;
}
 
Example 14
Project: IdealMedia   File: DiscreteSeekBar.java   Source Code and License 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    //TODO: Should we reverse the keys for RTL? The framework's SeekBar does NOT....
    boolean handled = false;
    if (isEnabled()) {
        int progress = getAnimatedProgress();
        switch (keyCode) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                handled = true;
                if (progress <= mMin) break;
                animateSetProgress(progress - mKeyProgressIncrement);
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                handled = true;
                if (progress >= mMax) break;
                animateSetProgress(progress + mKeyProgressIncrement);
                break;
        }
    }

    return handled || super.onKeyDown(keyCode, event);
}
 
Example 15
Project: AndroidOpen   File: BottomPopup.java   Source Code and License 5 votes vote down vote up
@Override
public final boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        return onKeyDown(keyCode, event);
    }
    return false;
}
 
Example 16
Project: OSchina_resources_android   File: TopicTweetActivity.java   Source Code and License 5 votes vote down vote up
@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
//                if (!mDelegation.onTurnBack()) return true;
                break;
        }
        return super.onKeyDown(keyCode, event);
    }
 
Example 17
Project: COB   File: SystemWebView.java   Source Code and License 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    Boolean ret = parentEngine.client.onDispatchKeyEvent(event);
    if (ret != null) {
        return ret.booleanValue();
    }
    return super.dispatchKeyEvent(event);
}
 
Example 18
Project: GitHub   File: TechDetailActivity.java   Source Code and License 5 votes vote down vote up
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && wvTechContent.canGoBack()) {
        wvTechContent.goBack();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 19
Project: aos-Video   File: ListingActivity.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {

    // Quit file browsing on BACK long press
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        MultiBackHintManager.getInstance(this).onBackLongPressed();
        finish();
        return true;
    }
    else return super.onKeyLongPress(keyCode, event);
}
 
Example 20
Project: BLPlayer   File: IjkVideoView.java   Source Code and License 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 21
Project: yyox   File: OrderPaySuccessActivity.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK
            && event.getRepeatCount() == 0) {
        setResult(CodeDefine.ORDER_PAY_RESULT);
        this.finish();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 22
Project: boohee_v5.6   File: MenuPopupHelper.java   Source Code and License 5 votes vote down vote up
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (event.getAction() != 1 || keyCode != 82) {
        return false;
    }
    dismiss();
    return true;
}
 
Example 23
Project: android-image-classification   File: MainActivity.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        debug = !debug;
        requestRender();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 24
Project: CSipSimple   File: ActionBarSherlockCompat.java   Source Code and License 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (ActionBarSherlock.DEBUG) Log.d(TAG, "[dispatchKeyEvent] event: " + event);

    final int keyCode = event.getKeyCode();

    // Not handled by the view hierarchy, does the action bar want it
    // to cancel out of something special?
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        final int action = event.getAction();
        // Back cancels action modes first.
        if (mActionMode != null) {
            if (action == KeyEvent.ACTION_UP) {
                mActionMode.finish();
            }
            if (ActionBarSherlock.DEBUG) Log.d(TAG, "[dispatchKeyEvent] returning true");
            return true;
        }

        // Next collapse any expanded action views.
        if (wActionBar != null && wActionBar.hasExpandedActionView()) {
            if (action == KeyEvent.ACTION_UP) {
                wActionBar.collapseActionView();
            }
            if (ActionBarSherlock.DEBUG) Log.d(TAG, "[dispatchKeyEvent] returning true");
            return true;
        }
    }

    if (ActionBarSherlock.DEBUG) Log.d(TAG, "[dispatchKeyEvent] returning false");
    return false;
}
 
Example 25
Project: cordova-vuetify   File: SystemWebView.java   Source Code and License 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    Boolean ret = parentEngine.client.onDispatchKeyEvent(event);
    if (ret != null) {
        return ret.booleanValue();
    }
    return super.dispatchKeyEvent(event);
}
 
Example 26
Project: androidtv-sample   File: SearchActivity.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // If there are no results found, press the left key to reselect the microphone
    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT && !mFragment.hasResults()) {
        mFragment.focusOnSearch();
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 27
Project: Underlined   File: PopUpActivity.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)  {
    if (keyCode == KeyEvent.KEYCODE_BACK ) {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
    }

    return false;
}
 
Example 28
Project: GearVRf-template   File: Gvr.java   Source Code and License 5 votes vote down vote up
@Override
                public void onEvent(GVRCursorController gvrCursorController) {
                    KeyEvent keyEvent = gvrCursorController.getKeyEvent();
                    if(keyEvent != null){
//                        mPickHandler.setClicked(keyEvent.getAction() == KeyEvent.ACTION_DOWN);
                    }
                }
 
Example 29
Project: ceji_android   File: ReadingFragment.java   Source Code and License 5 votes vote down vote up
private boolean simulateButtonPress(int action, int idToSend, ImageButton buttonToClick ) {
    if ( action == KeyEvent.ACTION_DOWN ) {
        buttonToClick.setPressed(true);
    } else {
        buttonToClick.setPressed(false);
    }

    buttonToClick.invalidate();
    return true;
}
 
Example 30
Project: VRPlayer   File: PlayerView.java   Source Code and License 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 31
Project: LaunchEnr   File: PagedView.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL: {
                // Handle mouse (or ext. device) by shifting the page depending on the scroll
                final float vscroll;
                final float hscroll;
                if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                    vscroll = 0;
                    hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                } else {
                    vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                }
                if (hscroll != 0 || vscroll != 0) {
                    boolean isForwardScroll = mIsRtl ? (hscroll < 0 || vscroll < 0)
                                                     : (hscroll > 0 || vscroll > 0);
                    if (isForwardScroll) {
                        scrollRight();
                    } else {
                        scrollLeft();
                    }
                    return true;
                }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
 
Example 32
Project: eyeRS   File: LoginActivity.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR
            && keyCode == KeyEvent.KEYCODE_BACK
            && event.getRepeatCount() == 0) {
        onBackPressed();
    }

    return super.onKeyDown(keyCode, event);
}
 
Example 33
Project: TakeRest   File: WebActivity.java   Source Code and License 5 votes vote down vote up
public boolean onKeyDown(int keyCoder, KeyEvent event) {
    if (webview.canGoBack() && keyCoder == KeyEvent.KEYCODE_BACK) {
        webview.goBack();
        return true;
    } else if (!webview.canGoBack() && keyCoder == KeyEvent.KEYCODE_BACK) {
        onBackPressed();
    }
    return false;
}
 
Example 34
Project: ChatExchange-old   File: SpotlightView.java   Source Code and License 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (dismissOnBackPress && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
        if (event.getAction() == KeyEvent.ACTION_UP) {
            dismiss();
        }
        return true;
    }
    return super.dispatchKeyEvent(event);
}
 
Example 35
Project: HiBangClient   File: FriendActivity.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK) {
		if ((System.currentTimeMillis() - mExitTime) > 2000) {
			Toast.makeText(getApplicationContext(), "再按一次退出程序",
					Toast.LENGTH_SHORT).show();
			mExitTime = System.currentTimeMillis();
		} else {
			this.finish();
		}
		return true;
	}
	return super.onKeyDown(keyCode, event);
}
 
Example 36
Project: decoy   File: InputPanel.java   Source Code and License 5 votes vote down vote up
/**
 * *************** IEmojiSelectedListener ***************
 */
@Override
public void onEmojiSelected(String key) {
    Editable mEditable = messageEditText.getText();
    if (key.equals("/DEL")) {
        messageEditText.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
    } else {
        int start = messageEditText.getSelectionStart();
        int end = messageEditText.getSelectionEnd();
        start = (start < 0 ? 0 : start);
        end = (start < 0 ? 0 : end);
        mEditable.replace(start, end, key);
    }
}
 
Example 37
Project: PlusGram   File: ChatAttachAlert.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (cameraOpened && (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
        shutterButton.getDelegate().shutterReleased();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 38
Project: EpisodeListView   File: EpisodeListView.java   Source Code and License 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_DPAD_UP:
                if (mParentView.hasFocus()) {
                    mChildrenView.requestFocus();
                    return true;
                }
                break;
            case KeyEvent.KEYCODE_DPAD_DOWN:
                if (mChildrenView.hasFocus()) {
                    mParentView.requestFocus();
                    return true;
                }
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                if (mChildrenView.hasFocus()
                        && mChildrenAdapter.getCurrentPosition() >= mChildrenAdapter.getData().size() - 1) {
                    return true;
                }
                if (mParentView.hasFocus()
                        && mParentAdapter.getCurrentPosition() >= mParentAdapter.getDatas().size() - 1) {
                    return true;
                }
        }
    }
    return super.dispatchKeyEvent(event);
}
 
Example 39
Project: anyRTC-RTCP-Android   File: LiveActivity.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (!isPublish){
            rtcpKit.unSubscribe(strPeerId);
        }else {
            rtcpKit.unPublish();
        }
        finishAnimActivity();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 40
Project: xlight_android_native   File: SoftKeyboardVisibilityDetectingLinearLayout.java   Source Code and License 5 votes vote down vote up
@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
        // Keyboard is hidden
        if (isKeyboardShown) {
            isKeyboardShown = false;
            listener.onSoftKeyboardHidden();
        }
    }
    return super.dispatchKeyEventPreIme(event);
}
 
Example 41
Project: phonk   File: AppRunnerActivity.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (onKeyListener != null) {
        onKeyListener.onKeyUp(event);
        onKeyListener.onKeyEvent(event);
    }

    // check if back key or volume keys are disabled
    if (checkBackKey(keyCode) || checkVolumeKeys(keyCode)) return true;

    return super.onKeyUp(keyCode, event);
}
 
Example 42
Project: GitHub   File: TimePickerDialog.java   Source Code and License 5 votes vote down vote up
private boolean addKeyIfLegal(int keyCode) {
    // If we're in 24hour mode, we'll need to check if the input is full. If in AM/PM mode,
    // we'll need to see if AM/PM have been typed.
    if ((mIs24HourMode && mTypedTimes.size() == 4) ||
            (!mIs24HourMode && isTypedTimeFullyLegal())) {
        return false;
    }

    mTypedTimes.add(keyCode);
    if (!isTypedTimeLegalSoFar()) {
        deleteLastTypedKey();
        return false;
    }

    int val = getValFromKeyCode(keyCode);
    Utils.tryAccessibilityAnnounce(mTimePicker, String.format("%d", val));
    // Automatically fill in 0's if AM or PM was legally entered.
    if (isTypedTimeFullyLegal()) {
        if (!mIs24HourMode && mTypedTimes.size() <= 3) {
            mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0);
            mTypedTimes.add(mTypedTimes.size() - 1, KeyEvent.KEYCODE_0);
        }
        mDoneButton.setEnabled(true);
    }

    return true;
}
 
Example 43
Project: homunculus   File: ActivityEventDispatcher.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onActivityKeyMultiple(T activity, int keyCode, int repeatCount, KeyEvent event) {
    for (ActivityEventCallback<T> cb : getCallbacks()) {
        if (cb.onActivityKeyMultiple(activity, keyCode, repeatCount, event)) {
            return true;
        }
    }
    return false;
}
 
Example 44
Project: homescreenarcade   File: FieldViewManager.java   Source Code and License 5 votes vote down vote up
public boolean handleKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
        synchronized(field) {
            // Don't let a pressed flipper key start a game, but do launch a ball if needed.
            if (!field.getGameState().isGameInProgress() || field.getGameState().isPaused()) {
                return false;
            }
            boolean isActionKey = updateFlippersForKeyCode(keyCode, true);
            if (isActionKey) launchBallIfNeeded();
            return isActionKey;
        }
    }
    return false;
}
 
Example 45
Project: microMathematics   File: CustomEditText.java   Source Code and License 5 votes vote down vote up
@Override
public boolean deleteSurroundingText(int beforeLength, int afterLength)
{
    if (beforeLength != 0 && afterLength == 0 && CustomEditText.this.getText().length() == 0)
    {
        final KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL);
        if (CustomEditText.this.processDelKey(event))
        {
            return true;
        }
    }
    return super.deleteSurroundingText(beforeLength, afterLength);
}
 
Example 46
Project: AgentWeb   File: WrapperWebViewClient.java   Source Code and License 5 votes vote down vote up
public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
    if(mWebViewClient!=null){
       return mWebViewClient.shouldOverrideKeyEvent(view,event);

    }

    return super.shouldOverrideKeyEvent(view,event);
}
 
Example 47
Project: iroha-demo-android   File: AccountRegisterPresenter.java   Source Code and License 5 votes vote down vote up
public View.OnKeyListener onKeyEventOnUserName() {
    return new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                InputMethodManager inputMethodManager =
                        (InputMethodManager) accountRegisterView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
                return true;
            }
            return false;
        }
    };
}
 
Example 48
Project: WechatChatroomHelper   File: HookLogic.java   Source Code and License 5 votes vote down vote up
private void hookDispatchKeyEvent(XC_MethodHook.MethodHookParam param) {
    KeyEvent keyEvent = (KeyEvent) param.args[0];

    //手指离开返回键的事件
    if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK
            && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {

        //不在聊天界面
        if (!isInChatting) {
            //群消息助手在屏幕上显示
            if (chatRoomViewPresenter.isShowing()) {
                XposedBridge.log("dispatchKeyEvent, chatRoomViewPresenter.isShowing");
                chatRoomViewPresenter.dismiss();
                param.setResult(true);
            }

            //公众号助手在屏幕上显示
            if (officialViewPresenter.isShowing()) {
                XposedBridge.log("dispatchKeyEvent, officialViewPresenter.isShowing");
                officialViewPresenter.dismiss();
                param.setResult(true);
            }
        } else {
            XposedBridge.log("dispatchKeyEvent, isInChatting");
        }
    }
}
 
Example 49
Project: boohee_v5.6   File: NestedScrollView.java   Source Code and License 5 votes vote down vote up
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;
    }
}
 
Example 50
Project: FlickLauncher   File: PagedView.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL: {
                // Handle mouse (or ext. device) by shifting the page depending on the scroll
                final float vscroll;
                final float hscroll;
                if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                    vscroll = 0;
                    hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                } else {
                    vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                }
                if (hscroll != 0 || vscroll != 0) {
                    boolean isForwardScroll = mIsRtl ? (hscroll < 0 || vscroll < 0)
                                                     : (hscroll > 0 || vscroll > 0);
                    if (isForwardScroll) {
                        scrollRight();
                    } else {
                        scrollLeft();
                    }
                    return true;
                }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
 
Example 51
Project: KrGallery   File: ActionBarLayout.java   Source Code and License 5 votes vote down vote up
@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
    if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK
            && event.getAction() == KeyEvent.ACTION_UP) {
        return delegate != null && delegate.onPreIme() || super.dispatchKeyEventPreIme(event);
    }
    return super.dispatchKeyEventPreIme(event);
}
 
Example 52
Project: android-mrz-reader   File: HelpActivity.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  if (keyCode == KeyEvent.KEYCODE_BACK) {
    if (webView.canGoBack()) {
      webView.goBack();
      return true;
    }
  }
  return super.onKeyDown(keyCode, event);
}
 
Example 53
Project: OpenHub   File: PagerActivity.java   Source Code and License 5 votes vote down vote up
@Override
@Deprecated
public boolean onKeyDown(int keyCode, KeyEvent event) {
    Fragment fragment = pagerAdapter.getCurFragment();
    if(fragment != null
            && fragment instanceof IFragmentKeyListener
            && ((IFragmentKeyListener)fragment).onKeyDown(keyCode, event)){
        return true;
    }
    return onMainKeyDown(keyCode, event);
}
 
Example 54
Project: EsperantoRadio   File: FjernbetjeningReciever.java   Source Code and License 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
  KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
  Log.d("MediabuttonReciever " + event);

  if (!Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction()) || event == null || event.getAction() != KeyEvent.ACTION_DOWN) {
    return;
  }

  switch (event.getKeyCode()) {
    case KeyEvent.KEYCODE_HEADSETHOOK:
    case KeyEvent.KEYCODE_MEDIA_STOP:
    case KeyEvent.KEYCODE_MEDIA_PAUSE:
      if (App.afspiller.getAfspillerstatus() != Status.STOPPET) {
        App.afspiller.pauseAfspilning();
      }
      break;
    case KeyEvent.KEYCODE_MEDIA_PLAY:
    case KeyEvent.KEYCODE_MEDIA_REWIND:
    case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
      if (App.afspiller.getAfspillerstatus() == Status.STOPPET) {
        App.afspiller.startAfspilning();
      }
      break;
    case KeyEvent.KEYCODE_MEDIA_NEXT:
      App.afspiller.næste();
      break;
    case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
      App.afspiller.forrige();
      break;
    case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
    default:
      if (App.afspiller.getAfspillerstatus() == Status.STOPPET) {
        App.afspiller.startAfspilning();
      } else {
        App.afspiller.pauseAfspilning();
        if (App.afspiller.afspillerlyde) App.afspiller.afspillerlyd.stop.start();
      }
  }
}
 
Example 55
Project: XERUNG   File: ImageViewTouchBase.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        event.startTracking();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 56
Project: Hotspot-master-devp   File: LoadingProgressDialog.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
    if(keyCode == KeyEvent.KEYCODE_BACK) {
        if(mOnBackKeyDownListener!=null) {
            mOnBackKeyDownListener.onBackKeyDown();
            return true;
        }
    }
    return false;
}
 
Example 57
Project: featurea   File: FeatureaSurfaceView.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent keyEvent) {
    InputSource inputSource = AndroidInputUtil.retrieveInputSourceFromKeyEvent(keyEvent);
    KeyInputEvent keyInputEvent = new KeyInputEvent(inputSource, InputType.up, false);
    keyInputEvent.keyChar = (char) keyEvent.getUnicodeChar();
    input.events.add(keyInputEvent);
    return false;
}
 
Example 58
Project: GitHub   File: IjkPlayerView.java   Source Code and License 5 votes vote down vote up
/**
 * 处理音量键,避免外部按音量键后导航栏和状态栏显示出来退不回去的状态
 *
 * @param keyCode
 * @return
 */
public boolean handleVolumeKey(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        _setVolume(true);
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        _setVolume(false);
        return true;
    } else {
        return false;
    }
}
 
Example 59
Project: GCSApp   File: WebActivity.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // 判断是否可以返回操作
    if (viewDelegate.getmWebContent().canGoBack() && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
        viewDelegate.getmWebContent().goBack();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 60
Project: Hotspot-master-devp   File: HelpActivity.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK && mCustomWebView.canGoBack()) {
		mCustomWebView.goBack();// 返回前一个页面
		return true;
	}
	return super.onKeyDown(keyCode, event);
}