List of usage examples for android.view KeyEvent getKeyCode
public final int getKeyCode()
From source file:android.support.v7ox.app.AppCompatActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { final int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.KEYCODE_DPAD_UP) { final int action = event.getAction(); if (action == KeyEvent.ACTION_DOWN) { if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { final ActionBar actionBar = getSupportActionBar(); if (actionBar != null && actionBar.isShowing() && actionBar.requestFocus()) { mEatKeyUpEvent = true; return true; }/* www. j ava2 s . c o m*/ } } else if (action == KeyEvent.ACTION_UP && mEatKeyUpEvent) { mEatKeyUpEvent = false; return true; } } return super.dispatchKeyEvent(event); }
From source file:net.olejon.mdapp.NasjonaleRetningslinjerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Input manager mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Layout/* w w w. j a v a2 s.com*/ setContentView(R.layout.activity_nasjonale_retningslinjer); // Toolbar final Toolbar toolbar = (Toolbar) findViewById(R.id.nasjonale_retningslinjer_toolbar); toolbar.setTitle(getString(R.string.nasjonale_retningslinjer_title)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolbarSearchLayout = (LinearLayout) findViewById(R.id.nasjonale_retningslinjer_toolbar_search_layout); mToolbarSearchEditText = (EditText) findViewById(R.id.nasjonale_retningslinjer_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.nasjonale_retningslinjer_toolbar_clear_search); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mToolbarSearchEditText.setText(""); } }); // Progress bar mProgressBar = (ProgressBar) findViewById(R.id.nasjonale_retningslinjer_toolbar_progressbar); // Floating action button mFloatingActionButton = (FloatingActionButton) findViewById(R.id.nasjonale_retningslinjer_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.nasjonale_retningslinjer_list); View listViewEmpty = findViewById(R.id.nasjonale_retningslinjer_list_empty); mListView.setEmptyView(listViewEmpty); View listViewHeader = getLayoutInflater().inflate(R.layout.activity_nasjonale_retningslinjer_list_subheader, mListView, false); mListView.addHeaderView(listViewHeader, null, false); }
From source file:com.ekeitho.sound.MainActivity.java
public boolean dispatchKeyEvent(KeyEvent event) { double VOLUME_INCREMENT = 0.05; int action = event.getAction(); int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_DOWN) { if (mRemoteMediaPlayer != null) { double currentVolume = Cast.CastApi.getVolume(mApiClient); if (currentVolume < 1.0) { try { Cast.CastApi.setVolume(mApiClient, Math.min(currentVolume + VOLUME_INCREMENT, 1.0)); } catch (Exception e) { Log.e(TAG, "unable to set volume", e); }//from w w w .j av a 2 s . c om } } else { Log.e(TAG, "dispatchKeyEvent - volume up"); } } return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { if (mRemoteMediaPlayer != null) { double currentVolume = Cast.CastApi.getVolume(mApiClient); if (currentVolume > 0.0) { try { Cast.CastApi.setVolume(mApiClient, Math.max(currentVolume - VOLUME_INCREMENT, 0.0)); } catch (Exception e) { Log.e(TAG, "unable to set volume", e); } } } else { Log.e(TAG, "dispatchKeyEvent - volume down"); } } return true; default: return super.dispatchKeyEvent(event); } }
From source file:io.syng.activity.BaseActivity.java
private void initSearch() { mSearchTextView.addTextChangedListener(new TextWatcher() { @Override//w ww . jav a 2s . co m public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { String searchValue = editable.toString(); updateDAppList(searchValue); } }); mSearchTextView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View view, int i, KeyEvent keyEvent) { if (keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) { GeneralUtil.hideKeyBoard(mSearchTextView, BaseActivity.this); return true; } return false; } }); }
From source file:de.vanita5.twittnuker.activity.support.QuickSearchBarActivity.java
@Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (event == null) return false; switch (event.getKeyCode()) { case KeyEvent.KEYCODE_ENTER: { doSearch();/*from ww w .j av a 2 s .c o m*/ return true; } } return false; }
From source file:org.alfresco.mobile.android.application.fragments.site.search.SearchSitesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) { return null; }/*from w ww.ja v a2s. c o m*/ setRootView(inflater.inflate(R.layout.fr_site_search, container, false)); init(getRootView(), emptyListMessageId); searchText = (MaterialAutoCompleteTextView) viewById(R.id.search_query); searchAdapter = new HistorySearchInlineCursorAdapter(this, null, R.layout.row_two_lines_search); getLoaderManager().initLoader(0, null, this); searchText.setAdapter(searchAdapter); searchText.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TwoLinesViewHolder vh = (TwoLinesViewHolder) view.getTag(); HistorySearch tmphistorySearchItem = HistorySearchManager.retrieveHistorySearch(getActivity(), (Long) vh.choose.getTag()); searchText.setText(tmphistorySearchItem.getQuery()); historySearchItem = tmphistorySearchItem; search(); } }); bAdd = (ImageButton) viewById(R.id.search_action); bAdd.setEnabled(false); activateSend(); bAdd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { search(); } }); searchText.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { historySearchItem = null; activateSend(); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); searchText.setImeOptions(EditorInfo.IME_ACTION_SEARCH); searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (event != null && (event.getAction() == KeyEvent.ACTION_DOWN) && ((actionId == EditorInfo.IME_ACTION_SEARCH) || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) { search(); return true; } return false; } }); return getRootView(); }
From source file:com.fatelon.partyphotobooth.kiosk.KioskActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { final int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1 || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3 || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5 || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7 || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9) { return super.dispatchKeyEvent(event); }/*from w ww . j a va 2 s . co m*/ final KeyEventHandler handler = mKeyEventHandler.get(); if (handler != null) { handler.onKeyEvent(event); } // Block event. return false; }
From source file:com.nextgis.rehacompdemo.RoutingActivity.java
@Override public boolean dispatchKeyEvent(@NonNull KeyEvent event) { int position; int action = event.getAction(); int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_DOWN) { position = mSteps.getSelectedItemPosition(); if (position == AdapterView.INVALID_POSITION) position = 0;/* w w w . ja v a2 s .co m*/ else position--; mSteps.requestFocusFromTouch(); mSteps.setSelection(position); break; } else return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { position = mSteps.getSelectedItemPosition(); if (position == AdapterView.INVALID_POSITION) position = 0; else position++; mSteps.requestFocusFromTouch(); mSteps.setSelection(position); break; } else return true; default: return super.dispatchKeyEvent(event); } return true; }
From source file:org.retroshare.android.ConversationFragment.java
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { boolean enterPressed = (event.getAction() == KeyEvent.ACTION_DOWN) & (event.getKeyCode() == KeyEvent.KEYCODE_ENTER); if (enterPressed) sendChatMsg(null);/* ww w . j a va 2s . com*/ return enterPressed; }
From source file:com.jlabs.peepaid.searchviewlay.SearchViewLayout.java
@Override public boolean dispatchKeyEventPreIme(KeyEvent event) { if (mSearchEditTextLayoutListener != null) { if (mSearchEditTextLayoutListener.onKey(this, event.getKeyCode(), event)) { return true; }//from w ww. ja v a 2 s . com } return super.dispatchKeyEventPreIme(event); }