List of usage examples for android.view KeyEvent getKeyCode
public final int getKeyCode()
From source file:net.olejon.mdapp.DiseasesAndTreatmentsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Input manager mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Layout/* w w w . j ava2 s . c om*/ setContentView(R.layout.activity_diseases_and_treatments); // Toolbar final Toolbar toolbar = (Toolbar) findViewById(R.id.diseases_and_treatments_toolbar); toolbar.setTitle(getString(R.string.diseases_and_treatments_title)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolbarSearchLayout = (LinearLayout) findViewById(R.id.diseases_and_treatments_toolbar_search_layout); mToolbarSearchEditText = (EditText) findViewById(R.id.diseases_and_treatments_toolbar_search); mToolbarSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) { mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0); search(mToolbarSearchEditText.getText().toString().trim()); return true; } return false; } }); final ImageButton toolbarSearchClearButton = (ImageButton) findViewById( R.id.diseases_and_treatments_toolbar_clear_search); toolbarSearchClearButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mToolbarSearchEditText.setText(""); } }); // List mListView = (ListView) findViewById(R.id.diseases_and_treatments_list); View listViewEmpty = findViewById(R.id.diseases_and_treatments_list_empty); mListView.setEmptyView(listViewEmpty); View listViewHeader = getLayoutInflater().inflate(R.layout.activity_diseases_and_treatments_list_subheader, mListView, false); mListView.addHeaderView(listViewHeader, null, false); // Floating action buttons mFloatingActionButton = (FloatingActionButton) findViewById(R.id.diseases_and_treatments_fab); mFloatingActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String string = mToolbarSearchEditText.getText().toString().trim(); if (mToolbarSearchLayout.getVisibility() == View.VISIBLE && !string.equals("")) { search(string); } else { showSearchLanguageDialog(); } } }); }
From source file:org.catrobat.catroid.ui.fragment.FormulaEditorDataFragment.java
@Override public void onListItemClick(int position) { if (!inContextMode) { FormulaEditorFragment formulaEditor = (FormulaEditorFragment) getSherlockActivity() .getSupportFragmentManager() .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG); if (formulaEditor != null) { Object itemToAdd = adapter.getItem(position); if (itemToAdd instanceof UserVariable) { formulaEditor.addUserVariableToActiveFormula(((UserVariable) itemToAdd).getName()); } else if (itemToAdd instanceof UserList) { formulaEditor.addUserListToActiveFormula(((UserList) itemToAdd).getName()); }//from w w w. j a v a2 s.c o m formulaEditor.updateButtonsOnKeyboardAndInvalidateOptionsMenu(); } KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK); onKey(null, keyEvent.getKeyCode(), keyEvent); } }
From source file:com.gecq.musicwave.player.MediaButtonIntentReceiver.java
/** * {@inheritDoc}/*w w w . ja v a2 s. com*/ */ @Override public void onReceive(final Context context, final Intent intent) { if (DEBUG) Log.v(TAG, "Received intent: " + intent); final String intentAction = intent.getAction(); if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) { startService(context, PlayerService.CMDPAUSE); } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { final KeyEvent event = (KeyEvent) 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 = PlayerService.CMDSTOP; break; case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: command = PlayerService.CMDTOGGLEPAUSE; break; case KeyEvent.KEYCODE_MEDIA_NEXT: command = PlayerService.CMDNEXT; break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: command = PlayerService.CMDPREVIOUS; break; case KeyEvent.KEYCODE_MEDIA_PAUSE: command = PlayerService.CMDPAUSE; break; case KeyEvent.KEYCODE_MEDIA_PLAY: command = PlayerService.CMDPLAY; break; } if (command != null) { if (action == KeyEvent.ACTION_DOWN) { if (mDown) { if (PlayerService.CMDTOGGLEPAUSE.equals(command) || PlayerService.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++; 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(); } } }
From source file:org.xwalk.core.xwview.shell.XWalkViewShellActivity.java
private void initializeUrlField() { mUrlTextView = (EditText) findViewById(R.id.url); mUrlTextView.setOnEditorActionListener(new OnEditorActionListener() { @Override/*from ww w . j ava2 s . co m*/ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((actionId != EditorInfo.IME_ACTION_GO) && (event == null || event.getKeyCode() != KeyEvent.KEYCODE_ENTER || event.getAction() != KeyEvent.ACTION_DOWN)) { return false; } if (mActiveView == null) return true; mActiveView.load(sanitizeUrl(mUrlTextView.getText().toString()), null); mUrlTextView.clearFocus(); setKeyboardVisibilityForUrl(false); return true; } }); mUrlTextView.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { setKeyboardVisibilityForUrl(hasFocus); mNextButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE); mPrevButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE); mStopButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE); mReloadButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE); if (!hasFocus) { if (mActiveView == null) return; mUrlTextView.setText(mActiveView.getUrl()); } } }); }
From source file:com.andrew.apollo.MediaButtonIntentReceiver.java
/** * {@inheritDoc}/* ww w .j ava 2 s .c o m*/ */ @Override public void onReceive(final Context context, final Intent intent) { if (DEBUG) Log.v(TAG, "Received intent: " + intent); final String intentAction = intent.getAction(); if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) { startService(context, MusicPlaybackService.CMDPAUSE); } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { final KeyEvent event = (KeyEvent) 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 = MusicPlaybackService.CMDSTOP; break; case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: command = MusicPlaybackService.CMDTOGGLEPAUSE; break; case KeyEvent.KEYCODE_MEDIA_NEXT: command = MusicPlaybackService.CMDNEXT; break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: command = MusicPlaybackService.CMDPREVIOUS; break; case KeyEvent.KEYCODE_MEDIA_PAUSE: command = MusicPlaybackService.CMDPAUSE; break; case KeyEvent.KEYCODE_MEDIA_PLAY: command = MusicPlaybackService.CMDPLAY; break; } if (command != null) { if (action == KeyEvent.ACTION_DOWN) { if (mDown) { if (MusicPlaybackService.CMDTOGGLEPAUSE.equals(command) || MusicPlaybackService.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++; 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(); } } }
From source file:net.olejon.mdapp.PoisoningsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Intent// w w w .j av a 2s . co m final Intent intent = getIntent(); final String searchString = intent.getStringExtra("search"); // Input manager mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Layout setContentView(R.layout.activity_poisonings); // Toolbar final Toolbar toolbar = (Toolbar) findViewById(R.id.poisonings_toolbar); toolbar.setTitle(getString(R.string.poisonings_title)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolbarSearchLayout = (LinearLayout) findViewById(R.id.poisonings_toolbar_search_layout); mToolbarSearchEditText = (EditText) findViewById(R.id.poisonings_toolbar_search); mToolbarSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) { mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0); search(mToolbarSearchEditText.getText().toString().trim()); return true; } return false; } }); ImageButton imageButton = (ImageButton) findViewById(R.id.poisonings_toolbar_clear_search); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mToolbarSearchEditText.setText(""); } }); // Floating action button mFloatingActionButton = (FloatingActionButton) findViewById(R.id.poisonings_fab); mFloatingActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mToolbarSearchLayout.getVisibility() == View.VISIBLE) { mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0); search(mToolbarSearchEditText.getText().toString().trim()); } else { mToolbarSearchLayout.setVisibility(View.VISIBLE); mToolbarSearchEditText.requestFocus(); mInputMethodManager.showSoftInput(mToolbarSearchEditText, 0); } } }); // List mListView = (ListView) findViewById(R.id.poisonings_list); View listViewEmpty = findViewById(R.id.poisonings_list_empty); mListView.setEmptyView(listViewEmpty); View listViewHeader = getLayoutInflater().inflate(R.layout.activity_poisonings_list_subheader, mListView, false); mListView.addHeaderView(listViewHeader, null, false); // Search if (searchString != null) search(searchString.split(" ")[0]); }
From source file:com.docd.purefm.ui.activities.BrowserPagerActivity.java
@Override public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) { final Intent searchIntent = new Intent(this, SearchActivity.class); searchIntent.putExtra(Extras.EXTRA_PATH, currentPath.getAbsolutePath()); startActivity(searchIntent);//from w ww. ja va 2s. com return true; } return super.onKeyUp(keyCode, event); }
From source file:com.example.android.leanback.PlaybackTransportControlGlueSample.java
@Override public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) { Action action = getControlsRow().getActionForKeyCode(keyEvent.getKeyCode()); if (shouldDispatchAction(action)) { dispatchAction(action);/* w w w. ja v a 2 s. c o m*/ return true; } } return super.onKey(view, keyCode, keyEvent); }
From source file:com.google.android.apps.tvremote.PairingActivity.java
private ProgressDialog buildProgressDialog() { ProgressDialog dialog = new ProgressDialog(this); dialog.setMessage(getString(R.string.pairing_waiting)); dialog.setOnKeyListener(new DialogInterface.OnKeyListener() { public boolean onKey(DialogInterface dialogInterface, int which, KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { cancelPairing();/* w w w . ja v a 2 s. c o m*/ return true; } return false; } }); dialog.setButton(getString(R.string.pairing_cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int which) { cancelPairing(); } }); return dialog; }
From source file:com.dwdesign.tweetings.fragment.DMConversationFragment.java
@Override public boolean onEditorAction(final TextView view, final int actionId, final KeyEvent event) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_ENTER: { send();//from w w w . j a v a2s. c om return true; } } return false; }