android.view.KeyEvent Java Examples

The following examples show how to use android.view.KeyEvent. 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: SuperTools.java    From AndroidAnimationExercise with Apache License 2.0 7 votes vote down vote up
/**
 * 获取导航栏高度
 *
 * @param context
 * @return
 */
public static int getNavigationBarHeight(Context context) {

    boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    if (!hasMenuKey && !hasBackKey) {
        //没有物理按钮(虚拟导航栏)
        print("没有物理按钮(虚拟导航栏)");
        Resources resources = context.getResources();
        int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
        //获取NavigationBar的高度
        int height = resources.getDimensionPixelSize(resourceId);
        return height;
    } else {
        print("有物理导航栏,小米非全面屏");
        //有物理导航栏,小米非全面屏
        return 0;
    }
}
 
Example #2
Source File: ViewPagerEx.java    From AndroidImageSlider with MIT 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 #3
Source File: MainActivity.java    From Upchain-wallet with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN
            && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
        if (System.currentTimeMillis() - currentBackPressedTime > BACK_PRESSED_INTERVAL) {
            currentBackPressedTime = System.currentTimeMillis();
            ToastUtils.showToast(getString(R.string.exit_tips));
            return true;
        } else {
            finish(); // 退出
        }
    } else if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
        return true;
    }
    return super.dispatchKeyEvent(event);
}
 
Example #4
Source File: QGallery.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
//		int position = MyGallery.this.getSelectedItemPosition();
//		int minV = ViewConfiguration.get(context).getScaledMinimumFlingVelocity();	
//         
//		if(velocityX > minV){			
//			if(position > 0)
//				MyGallery.this.setSelection(position-1);
//		}else if(velocityX < -minV){
//			if(position < MyGallery.this.getCount()-1)
//				MyGallery.this.setSelection(position+1);
//		}
		if (e2.getX() > e1.getX()) {
			// 往左边滑动
			super.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, null);
		} else {
			// 往右边滑动
			super.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
		}
		return false;
	}
 
Example #5
Source File: SignUpActivity.java    From A-week-to-develop-android-app-plan with Apache License 2.0 6 votes vote down vote up
private void initViews() {

        getVerifiCodeButton = getView(R.id.btn_send_verifi_code);
        getVerifiCodeButton.setOnClickListener(this);
        phoneEdit = getView(R.id.et_phone);
        phoneEdit.setImeOptions(EditorInfo.IME_ACTION_NEXT);// 下一步
        verifyCodeEdit = getView(R.id.et_verifiCode);
        verifyCodeEdit.setImeOptions(EditorInfo.IME_ACTION_NEXT);// 下一步
        passwordEdit = getView(R.id.et_password);
        passwordEdit.setImeOptions(EditorInfo.IME_ACTION_DONE);
        passwordEdit.setImeOptions(EditorInfo.IME_ACTION_GO);
        passwordEdit.setOnEditorActionListener(new OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView v, int actionId,
                                          KeyEvent event) {
                // 点击虚拟键盘的done
                if (actionId == EditorInfo.IME_ACTION_DONE
                        || actionId == EditorInfo.IME_ACTION_GO) {
                    commit();
                }
                return false;
            }
        });
    }
 
Example #6
Source File: CaptureModule.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    switch (keyCode)
    {
        case KeyEvent.KEYCODE_CAMERA:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            if (mUI.isCountingDown())
            {
                cancelCountDown();
            } else if (event.getRepeatCount() == 0)
            {
                onShutterButtonClick();
            }
            return true;
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            // Prevent default.
            return true;
    }
    return false;
}
 
Example #7
Source File: InputMethodService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
void reportExtractedMovement(int keyCode, int count) {
    int dx = 0, dy = 0;
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            dx = -count;
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            dx = count;
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            dy = -count;
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            dy = count;
            break;
    }
    onExtractedCursorMovement(dx, dy);
}
 
Example #8
Source File: MainActivity.java    From cloud-cup-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Firebase.setAndroidContext(this);
    setContentView(R.layout.activity_main);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_LOGIN)
            .build();

    firebase = new Firebase(Consts.FIREBASE_URL);
    username = (TextView) findViewById(R.id.username);
    userImage = (ImageView) findViewById(R.id.user_image);
    code = (EditText) findViewById(R.id.code);
    code.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            join();
            return true;
        }
    });
    code.requestFocus();
}
 
Example #9
Source File: MaterialIntroActivity.java    From youqu_master with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_CENTER:
            if (messageButtonBehaviours.get(viewPager.getCurrentItem()) != null) {
                messageButton.performClick();
            }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            int position = viewPager.getCurrentItem();
            if (adapter.isLastSlide(position) && adapter.getItem(position).canMoveFurther()) {
                performFinish();
            } else if (adapter.shouldLockSlide(position)) {
                errorOccurred(adapter.getItem(position));
            } else {
                viewPager.moveToNextPage();
            }
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            moveBack();
            break;
        default:
            return super.onKeyDown(keyCode, event);
    }
    return super.onKeyDown(keyCode, event);
}
 
Example #10
Source File: TwoWayAbsListView.java    From recent-images with MIT License 6 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
		if (!isEnabled()) {
			return true;
		}
		if (isClickable() && isPressed() &&
				mSelectedPosition >= 0 && mAdapter != null &&
				mSelectedPosition < mAdapter.getCount()) {

			final View view = getChildAt(mSelectedPosition - mFirstPosition);
			if (view != null) {
				performItemClick(view, mSelectedPosition, mSelectedRowId);
				view.setPressed(false);
			}
			setPressed(false);
			return true;
		}
	}
	return super.onKeyUp(keyCode, event);
}
 
Example #11
Source File: TransportMediator.java    From android-recipes-app with Apache License 2.0 6 votes vote down vote up
static boolean isMediaKey(int keyCode) {
    switch (keyCode) {
        case KEYCODE_MEDIA_PLAY:
        case KEYCODE_MEDIA_PAUSE:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
        case KeyEvent.KEYCODE_MUTE:
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_STOP:
        case KeyEvent.KEYCODE_MEDIA_NEXT:
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
        case KeyEvent.KEYCODE_MEDIA_REWIND:
        case KEYCODE_MEDIA_RECORD:
        case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: {
            return true;
        }
    }
    return false;
}
 
Example #12
Source File: DelegatingEditText.java    From android-test with Apache License 2.0 6 votes vote down vote up
public DelegatingEditText(Context context, AttributeSet attrs) {
  super(context, attrs);
  setOrientation(VERTICAL);
  mContext = context;
  LayoutInflater inflater = LayoutInflater.from(context);
  inflater.inflate(R.layout.delegating_edit_text, this, /* attachToRoot */ true);
  messageView = (TextView) findViewById(R.id.edit_text_message);
  delegateEditText = (EditText) findViewById(R.id.delegate_edit_text);
  delegateEditText.setOnEditorActionListener(new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionCode, KeyEvent event) {
      messageView.setText("typed: " + delegateEditText.getText());
      messageView.setVisibility(View.VISIBLE);
      InputMethodManager imm =
          (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(delegateEditText.getWindowToken(), 0);
      return true;
    }
  });
}
 
Example #13
Source File: MediaVideoView.java    From Slide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK
            && keyCode != KeyEvent.KEYCODE_VOLUME_UP
            && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN
            && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE
            && keyCode != KeyEvent.KEYCODE_MENU
            && keyCode != KeyEvent.KEYCODE_CALL
            && keyCode != KeyEvent.KEYCODE_ENDCALL;
    if (isPlaying() && isKeyCodeSupported) {
        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK
                || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
            if (isPlaying()) {
                pause();
                getVideoControls().show();
            } else {
                start();
                getVideoControls().hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
            if (!isPlaying()) {
                start();
                getVideoControls().hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP
                || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
            if (isPlaying()) {
                pause();
                getVideoControls().show();
            }
            return true;
        } else {
            toggleMediaControlsVisiblity();
        }
    }

    return super.onKeyDown(keyCode, event);
}
 
Example #14
Source File: LiveActivityRel.java    From TvPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean isCtrl = leftMenuCtrl.getVisibility() == View.GONE;
    //确认键弹出频道列表界面
    if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
        if (isCtrl) {
            leftMenuCtrl.setVisibility(View.VISIBLE);
            leftMenuCtrl.requestFocus();
        } else
            leftMenuCtrl.setVisibility(View.GONE);
    }
    //左右切换频道列表
    if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        turnRight(null);
    }
    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
        turnLeft(null);
    }
    int size = PlayListCache.channelInfoList.size() - 1;
    //上下换台
    if (keyCode == KeyEvent.KEYCODE_DPAD_UP && isCtrl) {
        PlayListCache.currChannel--;
        if (PlayListCache.currChannel < 0)
            PlayListCache.currChannel = size;
        LiveActivityRel.activityStart(LiveActivityRel.this, PlayListCache.channelInfoList.get(PlayListCache.currChannel));
        //结束当前播放
        LiveActivityRel.this.finish();
    }
    if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && isCtrl) {
        PlayListCache.currChannel++;
        if (PlayListCache.currChannel > size)
            PlayListCache.currChannel = 0;
        LiveActivityRel.activityStart(LiveActivityRel.this, PlayListCache.channelInfoList.get(PlayListCache.currChannel));
        //结束当前播放
        LiveActivityRel.this.finish();
    }
    return super.onKeyDown(keyCode, event);
}
 
Example #15
Source File: HdmiCecLocalDevice.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@ServiceThreadOnly
protected boolean handleUserControlPressed(HdmiCecMessage message) {
    assertRunOnServiceThread();
    mHandler.removeMessages(MSG_USER_CONTROL_RELEASE_TIMEOUT);
    if (mService.isPowerOnOrTransient() && isPowerOffOrToggleCommand(message)) {
        mService.standby();
        return true;
    } else if (mService.isPowerStandbyOrTransient() && isPowerOnOrToggleCommand(message)) {
        mService.wakeUp();
        return true;
    }

    final long downTime = SystemClock.uptimeMillis();
    final byte[] params = message.getParams();
    final int keycode = HdmiCecKeycode.cecKeycodeAndParamsToAndroidKey(params);
    int keyRepeatCount = 0;
    if (mLastKeycode != HdmiCecKeycode.UNSUPPORTED_KEYCODE) {
        if (keycode == mLastKeycode) {
            keyRepeatCount = mLastKeyRepeatCount + 1;
        } else {
            injectKeyEvent(downTime, KeyEvent.ACTION_UP, mLastKeycode, 0);
        }
    }
    mLastKeycode = keycode;
    mLastKeyRepeatCount = keyRepeatCount;

    if (keycode != HdmiCecKeycode.UNSUPPORTED_KEYCODE) {
        injectKeyEvent(downTime, KeyEvent.ACTION_DOWN, keycode, keyRepeatCount);
        mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_USER_CONTROL_RELEASE_TIMEOUT),
                FOLLOWER_SAFETY_TIMEOUT);
        return true;
    }
    return false;
}
 
Example #16
Source File: PolylinePointsControlFragment.java    From android-samples with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) {
    // Only handle "Done" action triggered by the user tapping "Enter" on the keyboard.
    if (actionId != EditorInfo.IME_ACTION_DONE) {
        return false;
    }

    int textViewId = textView.getId();
    if (textViewId == R.id.fps_edittext) {
        setFrameRate(textView);
    } else if (textViewId == R.id.step_edittext) {
        setStepSize(textView);
    }
    return false;
}
 
Example #17
Source File: MainActivity.java    From crazyflie-android-client with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // do not call super if key event comes from a gamepad, otherwise the buttons can quit the app
    if (isJoystickButton(event.getKeyCode()) && mController instanceof GamepadController) {
        mGamepadController.dealWithKeyEvent(event);
        // exception for OUYA controllers
        if (!Build.MODEL.toUpperCase(Locale.getDefault()).contains("OUYA")) {
            return true;
        }
    }
    return super.dispatchKeyEvent(event);
}
 
Example #18
Source File: ItemPickerButton.java    From libcommon with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyUp(final int keyCode, final KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
            || (keyCode == KeyEvent.KEYCODE_ENTER)) {
        cancelLongpress();
    }
    return super.onKeyUp(keyCode, event);
}
 
Example #19
Source File: Activity_Login.java    From FoodOrdering with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    //如果是返回键
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        ActivityCollector.finishAll();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example #20
Source File: RetroWebViewActivity.java    From retrowatch with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK) {
		if(mWebView.getWebViewInstance().canGoBack()) {
			mWebView.getWebViewInstance().goBack();
		} else {
			onBackPressed();
		}
		return true;
	}
	return false;
}
 
Example #21
Source File: IntroNewWalletWarningFragment.java    From natrium-android-wallet with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // init dependency injection
    if (getActivity() instanceof ActivityWithComponent) {
        ((ActivityWithComponent) getActivity()).getActivityComponent().inject(this);
    }

    // inflate the view
    binding = DataBindingUtil.inflate(
            inflater, R.layout.fragment_intro_new_wallet_warning, container, false);
    view = binding.getRoot();

    // subscribe to bus
    RxBus.get().register(this);

    // bind data to view
    binding.setHandlers(new ClickHandlers());

    // Override back button press
    view.setFocusableInTouchMode(true);
    view.requestFocus();
    view.setOnKeyListener((View v, int keyCode, KeyEvent event) -> {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
            goToSeed();
            return true;
        }
        return false;
    });

    return view;
}
 
Example #22
Source File: Folder.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_DONE) {
        dismissEditingName();
        return true;
    }
    return false;
}
 
Example #23
Source File: GestureLauncherService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public boolean interceptPowerKeyDown(KeyEvent event, boolean interactive,
        MutableBoolean outLaunched) {
    boolean launched = false;
    boolean intercept = false;
    long powerTapInterval;
    synchronized (this) {
        powerTapInterval = event.getEventTime() - mLastPowerDown;
        if (mCameraDoubleTapPowerEnabled
                && powerTapInterval < CAMERA_POWER_DOUBLE_TAP_MAX_TIME_MS) {
            launched = true;
            intercept = interactive;
            mPowerButtonConsecutiveTaps++;
        } else if (powerTapInterval < POWER_SHORT_TAP_SEQUENCE_MAX_INTERVAL_MS) {
            mPowerButtonConsecutiveTaps++;
        } else {
            mPowerButtonConsecutiveTaps = 1;
        }
        mLastPowerDown = event.getEventTime();
    }
    if (DBG && mPowerButtonConsecutiveTaps > 1) {
        Slog.i(TAG, Long.valueOf(mPowerButtonConsecutiveTaps) +
                " consecutive power button taps detected");
    }
    if (launched) {
        Slog.i(TAG, "Power button double tap gesture detected, launching camera. Interval="
                + powerTapInterval + "ms");
        launched = handleCameraGesture(false /* useWakelock */,
                StatusBarManager.CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP);
        if (launched) {
            mMetricsLogger.action(MetricsEvent.ACTION_DOUBLE_TAP_POWER_CAMERA_GESTURE,
                    (int) powerTapInterval);
        }
    }
    mMetricsLogger.histogram("power_consecutive_short_tap_count", mPowerButtonConsecutiveTaps);
    mMetricsLogger.histogram("power_double_tap_interval", (int) powerTapInterval);
    outLaunched.value = launched;
    return intercept && launched;
}
 
Example #24
Source File: ArticleActivity.java    From Yuan-WanAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){
        Intent intent = new Intent();
        intent.putExtra(Constant.KEY_ARTICLE_COLLECT, isCollect);
        setResult(RESULT_OK, intent);
        finish();
    }
    return mAgentWeb.handleKeyEvent(keyCode, event) || super.onKeyDown(keyCode, event);
}
 
Example #25
Source File: WelcomeFragment.java    From BLEMeshChat with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_welcome, container, false);
    ((EditText) root.findViewById(R.id.aliasEntry)).setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            mCallback.onNameChosen(textView.getText().toString());
            return false;
        }
    });
    return root;
}
 
Example #26
Source File: AllAppsSearchBarController.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    // Skip if it's not the right action
    if (actionId != EditorInfo.IME_ACTION_SEARCH) {
        return false;
    }

    // Skip if the query is empty
    String query = v.getText().toString();
    if (query.isEmpty()) {
        return false;
    }
    return mLauncher.startActivitySafely(v, createMarketSearchIntent(query), null);
}
 
Example #27
Source File: TimePickerTextInputKeyController.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKey(View view, int keyCode, KeyEvent event) {
  if (keyListenerRunning) {
    return false;
  }

  keyListenerRunning = true;
  EditText editText = (EditText) view;
  boolean ret =
      time.selection == MINUTE
          ? onMinuteKeyPress(keyCode, event, editText)
          : onHourKeyPress(keyCode, event, editText);
  keyListenerRunning = false;
  return ret;
}
 
Example #28
Source File: BaseActivity.java    From MissZzzReader with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK){
        back = true;//以便于判断是否按返回键触发界面劫持提示
    }
    return super.onKeyDown(keyCode, event);
}
 
Example #29
Source File: GosUserLoginActivity.java    From Gizwits-SmartBuld_Android with MIT License 5 votes vote down vote up
/**
 * 菜单、返回键响应
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK) {
		exitBy2Click(); // 调用双击退出函数
	}
	return false;
}
 
Example #30
Source File: ConfirmDialog.java    From AndroidLinkup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 处理返回键
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        Button btn = (Button) findViewById(R.id.dialog_button_cancel);
        btn.performClick();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}