List of usage examples for android.view KeyEvent getKeyCode
public final int getKeyCode()
From source file:net.olejon.mdapp.InteractionsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Intent/*from w w w . j a va 2s. c o m*/ final Intent intent = getIntent(); final String searchString = (intent.getStringExtra("search") == null) ? "" : intent.getStringExtra("search").split(" ")[0]; // Input manager mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Layout setContentView(R.layout.activity_interactions); // Toolbar final Toolbar toolbar = (Toolbar) findViewById(R.id.interactions_toolbar); toolbar.setTitle(getString(R.string.interactions_title)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolbarSearchLayout = (LinearLayout) findViewById(R.id.interactions_toolbar_search_layout); mToolbarSearchEditText = (EditText) findViewById(R.id.interactions_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()); return true; } return false; } }); ImageButton imageButton = (ImageButton) findViewById(R.id.interactions_toolbar_clear_search); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mToolbarSearchEditText.setText(""); } }); if (!searchString.equals("")) { mToolbarSearchLayout.setVisibility(View.VISIBLE); mToolbarSearchEditText.setText(searchString + " "); mToolbarSearchEditText.setSelection(mToolbarSearchEditText.getText().length()); mTools.showToast(getString(R.string.interactions_search_other_medications_or_substances), 1); } // List mListView = (ListView) findViewById(R.id.interactions_list); View listViewEmpty = findViewById(R.id.interactions_list_empty); mListView.setEmptyView(listViewEmpty); View listViewHeader = getLayoutInflater().inflate(R.layout.activity_interactions_list_subheader, mListView, false); mListView.addHeaderView(listViewHeader, null, false); // Floating action button mFloatingActionButton = (FloatingActionButton) findViewById(R.id.interactions_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()); } else { mToolbarSearchLayout.setVisibility(View.VISIBLE); mToolbarSearchEditText.requestFocus(); mInputMethodManager.showSoftInput(mToolbarSearchEditText, 0); } } }); }
From source file:com.bluros.music.helpers.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 (PreferencesUtility.getInstance(context).pauseEnabledOnDetach()) 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; }//from w w w . j av a 2 s . c om 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) { 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:com.example.photoremark.MainActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { onExit();/*from www.j a v a2 s. c o m*/ } } return true; }
From source file:com.ruesga.rview.EditorActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG); if (fragment != null && fragment instanceof KeyEventBindable) { if (((KeyEventBindable) fragment).onKeyDown(event.getKeyCode(), event)) { return true; }// w w w . j a v a 2 s .c o m } } return super.dispatchKeyEvent(event); }
From source file:org.protocoder.MainActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) { int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_R: MLog.d(TAG, "run app"); break; default:// w w w . j a v a2s. co m break; } } return super.dispatchKeyEvent(event); }
From source file:com.mobirix.battlefieldcommander.activity.BillingNativeActivity.java
public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_MULTIPLE) return mUnityPlayer.onKeyMultiple(event.getKeyCode(), event.getRepeatCount(), event); return super.dispatchKeyEvent(event); }
From source file:com.gigaset.home.Home.java
/** * Catch keys to avoid back through HOME in Back Stack *///from w w w . j a v a 2 s.c o m @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: return true; case KeyEvent.KEYCODE_HOME: return true; } } else if (event.getAction() == KeyEvent.ACTION_UP) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: if (!event.isCanceled()) { // Do BACK behavior. } return true; case KeyEvent.KEYCODE_HOME: if (!event.isCanceled()) { // Do HOME behavior. myPager.setCurrentItem(HomePagerAdapter.SCREEN_CENTER); } return true; } } return super.dispatchKeyEvent(event); }
From source file:net.thetabx.gcd.activity.ChatActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); header = (TextView) findViewById(R.id.txt_chat_header); listView = (ListView) findViewById(R.id.lview_chat); swipe = (SwipeRefreshLayout) findViewById(R.id.swipe_chat); swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override/*from w w w . j a v a 2 s . co m*/ public void onRefresh() { fetchFreshData(); } }); edit = (EditText) findViewById(R.id.etxt_chat_send); edit.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { header.setText(String.format("Sent %s", v.getText())); sendChatMessage(v); //v.setText(""); fetchFreshData(); } return false; } }); header.setText("Start"); if (messages == null) { fetchFreshData(); } else fillActivity(); }
From source file:eu.geekgasm.kintrol.DeviceControlActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { int action = event.getAction(); int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_DOWN) { kontrollerThread.increaseVolume(); }// ww w. j a va 2 s.com return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { kontrollerThread.decreaseVolume(); } return true; default: return super.dispatchKeyEvent(event); } }
From source file:org.chromium.content_shell.Shell.java
private void initializeUrlField() { mUrlTextView = (EditText) findViewById(R.id.url); mUrlTextView.setOnEditorActionListener(new OnEditorActionListener() { @Override//from w ww.java2 s. c o 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; } loadUrl(mUrlTextView.getText().toString()); setKeyboardVisibilityForUrl(false); mContentView.requestFocus(); return true; } }); mUrlTextView.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { setKeyboardVisibilityForUrl(hasFocus); mNextButton.setVisibility(hasFocus ? GONE : VISIBLE); mPrevButton.setVisibility(hasFocus ? GONE : VISIBLE); if (!hasFocus) { mUrlTextView.setText(mContentView.getUrl()); } } }); }