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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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);
}