List of usage examples for android.view KeyEvent getRepeatCount
public final int getRepeatCount()
From source file:com.abc.driver.MainActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { if (menu_display) { menuWindow.dismiss();/*from ww w . j ava 2 s.c o m*/ menu_display = false; } else { onBackPressed(); } } else if (keyCode == KeyEvent.KEYCODE_MENU) { if (!menu_display) { inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); layout = inflater.inflate(R.layout.main_menu, null); menuWindow = new PopupWindow(layout, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); menuWindow.showAtLocation(this.findViewById(R.id.mainweixin), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); mClose = (LinearLayout) layout.findViewById(R.id.menu_close); mCloseBtn = (LinearLayout) layout.findViewById(R.id.menu_close_btn); mCloseBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(); menuWindow.dismiss(); } }); menu_display = true; } else { menuWindow.dismiss(); menu_display = false; } return false; } return false; }
From source file:com.ichi2.anki.CardEditor.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { Log.i(AnkiDroidApp.TAG, "CardEditor - onBackPressed()"); closeCardEditor();/*from ww w.j av a2 s . c om*/ return true; } return super.onKeyDown(keyCode, event); }
From source file:android.support.v7.app.AppCompatDelegateImplV7.java
private boolean onKeyDownPanel(int featureId, KeyEvent event) { if (event.getRepeatCount() == 0) { PanelFeatureState st = getPanelState(featureId, true); if (!st.isOpen) { return preparePanel(st, event); }//w w w . j av a 2 s. c o m } return false; }
From source file:give_me_coins.dashboard.MainScreen.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub switch (keyCode) { case KeyEvent.KEYCODE_HOME: BackKeyExit = 0;//from www . ja v a 2 s.co m onPause(); return true; case KeyEvent.KEYCODE_BACK: if (event.getRepeatCount() == 0) { if (BackKeyExit == 0) { Toast.makeText(this, "Press BACK twice to fully exit", Toast.LENGTH_LONG).show(); BackKeyExit = 1; } else { if (DEBUG) Log.d(TAG, "Back pressed twice - EXITING"); BackKeyExit = 0; finish(); } } if (event.getRepeatCount() == 1) { if (DEBUG) Log.d(TAG, "Back pressed twice - EXITING"); finish(); } return true; default: BackKeyExit = 0; } if (DEBUG) Log.d(TAG, "Pressed: " + keyCode); return super.onKeyDown(keyCode, event); }
From source file:website.openeng.anki.DeckPicker.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { Timber.i("DeckPicker:: onBackPressed()"); automaticSync();/*from www . ja va 2 s .c om*/ finishWithAnimation(); return true; } else { return super.onKeyDown(keyCode, event); } }
From source file:com.rks.musicx.services.MediaButtonReceiver.java
@Override public void onReceive(Context context, Intent intent) { String intentAction = intent.getAction(); String command = null;// w ww . j a v a 2 s . co m if (intent.getAction() != null) { if (intentAction.equals(Intent.ACTION_MEDIA_BUTTON)) { KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event == null) { return; } int keycode = event.getKeyCode(); final int action = event.getAction(); final long eventTime = event.getEventTime(); switch (keycode) { case KeyEvent.KEYCODE_MEDIA_STOP: Log.d(TAG, "stop"); command = Constants.ACTION_STOP; break; case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: Log.d(TAG, "toggle"); command = Constants.ACTION_TOGGLE; break; case KeyEvent.KEYCODE_MEDIA_NEXT: Log.d(TAG, "next"); command = Constants.ACTION_NEXT; break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: Log.d(TAG, "prev"); command = Constants.ACTION_PREVIOUS; break; case KeyEvent.KEYCODE_MEDIA_PAUSE: Log.d(TAG, "pause"); command = Constants.ACTION_PAUSE; break; case KeyEvent.KEYCODE_MEDIA_PLAY: Log.d(TAG, "play"); command = Constants.ACTION_PLAY; break; } // startServices(context, command); if (command != null) { if (action == KeyEvent.ACTION_DOWN) { if (event.getRepeatCount() == 0) { if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) { if (eventTime - mLastClickTime >= DOUBLE_CLICK) { mClickCounter = 0; } mClickCounter++; Log.e("MediaButton", "Got headset click, count = " + mClickCounter); mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT); Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0, context); long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0; if (mClickCounter >= 3) { mClickCounter = 0; } mLastClickTime = eventTime; acquireWakeLockAndSendMessage(context, msg, delay); } else { startServices(context, command); } } } } } } }
From source file:com.ubuntuone.android.files.activity.FilesActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // Was the Back button pressed? if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { if (!mPathTracker.isAtRoot()) { mAdapter.cd(this); getListView().setSelectionFromTop(mTopPosition, mTop); mTopPosition = mTop = 0;//w ww . j a v a2 s . c o m return true; } } return super.onKeyDown(keyCode, event); }
From source file:research.sg.edu.edapp.kb.KbSoftKeyboard.java
/** * Use this to monitor key events being delivered to the application. * We get first crack at them, and can either resume them or let them * continue to the app.// w w w .j ava 2 s. c o m */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { String s = "" + event.getUnicodeChar(); Log.d("CAME HERE", "CAME HERE"); switch (keyCode) { case KeyEvent.KEYCODE_BACK: // The InputMethodService already takes care of the back // key for us, to dismiss the input method if it is shown. // However, our keyboard could be showing a pop-up window // that back should dismiss, so we first allow it to do that. if (event.getRepeatCount() == 0 && mInputView != null) { if (mInputView.handleBack()) { return true; } } break; case KeyEvent.KEYCODE_DEL: // Special handling of the delete key: if we currently are // composing text for the user, we want to modify that instead // of let the application to the delete itself. if (mComposing.length() > 0) { onKey(Keyboard.KEYCODE_DELETE, null); return true; } break; case KeyEvent.KEYCODE_ENTER: // Let the underlying text editor always handle these. return false; default: // For all other keys, if we want to do transformations on // text being entered with a hard keyboard, we need to process // it and do the appropriate action. if (PROCESS_HARD_KEYS) { //*********added changes here if (event.getAction() == KeyEvent.ACTION_DOWN) { swipe += (char) event.getUnicodeChar(); Log.d("msg", swipe); System.out.println(swipe); // keyDownUp(keyCode); // return true; } //*********done if (keyCode == KeyEvent.KEYCODE_SPACE && (event.getMetaState() & KeyEvent.META_ALT_ON) != 0) { // A silly example: in our input method, Alt+Space // is a shortcut for 'android' in lower case. InputConnection ic = getCurrentInputConnection(); if (ic != null) { // First, tell the editor that it is no longer in the // shift state, since we are consuming this. ic.clearMetaKeyStates(KeyEvent.META_ALT_ON); keyDownUp(KeyEvent.KEYCODE_A); keyDownUp(KeyEvent.KEYCODE_N); keyDownUp(KeyEvent.KEYCODE_D); keyDownUp(KeyEvent.KEYCODE_R); keyDownUp(KeyEvent.KEYCODE_O); keyDownUp(KeyEvent.KEYCODE_I); keyDownUp(KeyEvent.KEYCODE_D); // And we consume this event. return true; } } if (mPredictionOn && translateKeyDown(keyCode, event)) { return true; } } } return super.onKeyDown(keyCode, event); }
From source file:singh.amandeep.musicplayer.MediaButtonIntentReceiver.java
/** * {@inheritDoc}// w ww. j a va 2s . co m */ @Override public void onReceive(final Context context, final Intent intent) { final String intentAction = intent.getAction(); if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) { startService(context, MusicService.CMDPAUSE); } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event == null) { return; } final int keycode = event.getKeyCode(); final int action = event.getAction(); final long eventtime = event.getEventTime(); String command = null; switch (keycode) { case KeyEvent.KEYCODE_MEDIA_STOP: command = MusicService.CMDSTOP; break; case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: command = MusicService.CMDTOGGLEPAUSE; break; case KeyEvent.KEYCODE_MEDIA_NEXT: command = MusicService.CMDNEXT; break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: command = MusicService.CMDPREVIOUS; break; case KeyEvent.KEYCODE_MEDIA_PAUSE: command = MusicService.CMDPAUSE; break; case KeyEvent.KEYCODE_MEDIA_PLAY: command = MusicService.CMDPLAY; break; } if (command != null) { if (action == KeyEvent.ACTION_DOWN) { if (mDown) { if (MusicService.CMDTOGGLEPAUSE.equals(command) || MusicService.CMDPLAY.equals(command)) { if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) { acquireWakeLockAndSendMessage(context, mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0); } } } else if (event.getRepeatCount() == 0) { // Only consider the first event in a sequence, not the repeat events, // so that we don't trigger in cases where the first event went to // a different app (e.g. when the user ends a phone call by // long pressing the headset button) // The service may or may not be running, but we need to send it // a command. if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) { if (eventtime - mLastClickTime >= DOUBLE_CLICK) { mClickCounter = 0; } mClickCounter++; mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT); Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0, context); long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0; if (mClickCounter >= 3) { mClickCounter = 0; } mLastClickTime = eventtime; acquireWakeLockAndSendMessage(context, msg, delay); } else { startService(context, command); } mLaunched = false; mDown = true; } } else { mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT); mDown = false; } if (isOrderedBroadcast()) { abortBroadcast(); } releaseWakeLockIfHandlerIdle(); } } }
From source file:com.av.remusic.receiver.MediaButtonIntentReceiver.java
@Override public void onReceive(final Context context, final Intent intent) { final String intentAction = intent.getAction(); if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) { if (true) startService(context, MediaService.CMDPAUSE); } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event == null) { return; }// w ww. jav a 2s.c o m final int keycode = event.getKeyCode(); final int action = event.getAction(); final long eventtime = event.getEventTime(); String command = null; switch (keycode) { case KeyEvent.KEYCODE_MEDIA_STOP: command = MediaService.CMDSTOP; break; case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: command = MediaService.CMDTOGGLEPAUSE; break; case KeyEvent.KEYCODE_MEDIA_NEXT: command = MediaService.CMDNEXT; break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: command = MediaService.CMDPREVIOUS; break; case KeyEvent.KEYCODE_MEDIA_PAUSE: command = MediaService.CMDPAUSE; break; case KeyEvent.KEYCODE_MEDIA_PLAY: command = MediaService.CMDPLAY; break; } if (command != null) { if (action == KeyEvent.ACTION_DOWN) { if (mDown) { if (MediaService.CMDTOGGLEPAUSE.equals(command) || MediaService.CMDPLAY.equals(command)) { if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) { acquireWakeLockAndSendMessage(context, mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0); } } } else if (event.getRepeatCount() == 0) { if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) { if (eventtime - mLastClickTime >= DOUBLE_CLICK) { mClickCounter = 0; } mClickCounter++; if (DEBUG) Log.v(TAG, "Got headset click, count = " + mClickCounter); mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT); Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0, context); long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0; if (mClickCounter >= 3) { mClickCounter = 0; } mLastClickTime = eventtime; acquireWakeLockAndSendMessage(context, msg, delay); } else { startService(context, command); } mLaunched = false; mDown = true; } } else { mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT); mDown = false; } if (isOrderedBroadcast()) { abortBroadcast(); } releaseWakeLockIfHandlerIdle(); } } }