List of usage examples for android.view KeyEvent getAction
public final int getAction()
From source file:online.privacy.SetupActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_setup); connectivityWarning = findViewById(R.id.warning_connectivity); connectivityWarningHeight = (int) getResources().getDimension(R.dimen.warning_connectivity_height); SharedPreferences preferences = getSharedPreferences(getString(R.string.privacyonline_preferences), MODE_PRIVATE);// w w w . ja v a2s .c o m defaultVPNLocationUpdate = defaultVPNLocationStart = preferences.getString("default_vpn_location", ""); final EditText usernameInput = (EditText) findViewById(R.id.input_text_username); final EditText passwordInput = (EditText) findViewById(R.id.input_password_password); usernameInput.setText(preferences.getString("username", "")); usernameInput.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { usernameInput.clearFocus(); passwordInput.requestFocus(); return true; } return false; } }); passwordInput.setText(preferences.getString("password", "")); // Ugh, apparently we can't define text on buttons to have the underlined property from // within the XML, so we'll do it here we have to set the intent chooser here anyway. Button buttonSignUp = (Button) findViewById(R.id.button_cta_signup); buttonSignUp.setPaintFlags(buttonSignUp.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); buttonSignUp.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent ctaIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.privacy_online_signup))); startActivity(ctaIntent); } }); final Button buttonSave = (Button) findViewById(R.id.button_save); buttonSave.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { EditText inputTextUsername = (EditText) findViewById(R.id.input_text_username); EditText inputTextPassword = (EditText) findViewById(R.id.input_password_password); clearErrorState(inputTextUsername); clearErrorState(inputTextPassword); setErrorInfoVisibility(View.INVISIBLE); setWorkingState(true); Intent apiIntent = new Intent(contextSetup, PrivacyOnlineAPIService.class); apiIntent.putExtra(PrivacyOnlineAPIService.PARAM_USERNAME, inputTextUsername.getText().toString()); apiIntent.putExtra(PrivacyOnlineAPIService.PARAM_PASSWORD, inputTextPassword.getText().toString()); apiIntent.setAction(PrivacyOnlineAPIService.ACTION_VERIFY_USERNAME); startService(apiIntent); } }); }
From source file:org.mklab.mikity.android.editor.AbstractObjectEditor.java
/** * {@inheritDoc}//from w w w . jav a2 s . c o m */ public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { final InputMethodManager inputMethodManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0); saveParameters(); return true; } return false; }
From source file:com.nadmm.airports.afd.BrowseAirportsFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (savedInstanceState != null && savedInstanceState.containsKey(BROWSE_MODE)) { mMode = savedInstanceState.getInt(BROWSE_MODE); if (mMode == BROWSE_AIRPORTS_MODE) { mStateCode = savedInstanceState.getString(DatabaseManager.Airports.ASSOC_STATE); mStateName = savedInstanceState.getString(DatabaseManager.States.STATE_NAME); }/*w w w . jav a2s. c o m*/ } else { mMode = BROWSE_STATE_MODE; } if (mMode == BROWSE_STATE_MODE) { setBackgroundTask(new BrowseStateTask()).execute(); } else { setBackgroundTask(new BrowseAirportsTask()).execute(mStateCode, mStateName); } View view = getView(); if (view != null) { view.setFocusableInTouchMode(true); view.requestFocus(); view.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (mMode == BROWSE_AIRPORTS_MODE && keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { // Intercept back key to go back to state mode mMode = BROWSE_STATE_MODE; setListShown(false); getListView().setAdapter(null); setBackgroundTask(new BrowseStateTask()).execute(); return true; } return false; } }); } }
From source file:com.mstar.tv.tvplayer.philips.option.OptionFirstFragment.java
@Override public void onStart() { super.onStart(); listView = getListView();/* ww w . ja v a2 s . c om*/ if (getFragmentManager().findFragmentById(R.id.first_fragment) != null) { listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); } listView.setDivider(null); listView.setDividerHeight(5); listView.setSelector(android.R.color.transparent); listView.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { settingAdapter.setSelectViewPosition(position); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); listView.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { // TODO Auto-generated method stub if (OptionKarrays.isFromLauncher) { if (!isWifiOpen() && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {//wifi has not open if (listView.getSelectedItemPosition() == 1 && keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {//??? listView.setSelection(3); return true; } else if (listView.getSelectedItemPosition() == 3 && keyCode == KeyEvent.KEYCODE_DPAD_UP) { listView.setSelection(1); return true; } } } return false; } }); }
From source file:com.darly.im.ui.CCPFragment.java
/** * ?/*from w ww . j a v a2 s .c o m*/ * @param keyCode * @param event * @return */ public boolean onKeyDown(int keyCode, KeyEvent event) { if (mBaseActivity.onKeyDown(keyCode, event)) { return true; } if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK) && event.getAction() == KeyEvent.ACTION_DOWN) { finish(); return true; } return false; }
From source file:com.kinvey.sample.kitchensink.account.LoginFragment.java
protected void addEditListeners() { login.setEnabled(validateInput());/*from w w w .j av a2 s . co m*/ username.addTextChangedListener(new TextWatcher() { @Override 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) { login.setEnabled(validateInput()); } }); username.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE || (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) && username.getText().length() < MIN_USERNAME_LENGTH) { CharSequence text = "User name must contain at least " + MIN_USERNAME_LENGTH + " characters"; Toast.makeText(getSherlockActivity().getApplicationContext(), text, Toast.LENGTH_SHORT).show(); return true; } return false; } }); password.addTextChangedListener(new TextWatcher() { @Override 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) { login.setEnabled(validateInput()); } }); password.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE || (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) && password.getText().length() < MIN_USERNAME_LENGTH) { CharSequence text = "Password must contain at least " + MIN_PASSWORD_LENGTH + " characters"; Toast.makeText(getSherlockActivity(), text, Toast.LENGTH_SHORT).show(); return true; } return false; } }); }
From source file:io.github.carlorodriguez.alarmon.MediaListView.java
public MediaListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setChoiceMode(CHOICE_MODE_SINGLE);/*from w ww . ja v a 2 s . c om*/ setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (flipper == null || flipper.getDisplayedChild() == 0) { return false; } if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { if (event.getAction() == KeyEvent.ACTION_UP) { if (mPlayer != null) { mPlayer.stop(); } flipper.setInAnimation(getContext(), R.anim.slide_in_right); flipper.setOutAnimation(getContext(), R.anim.slide_out_right); flipper.showPrevious(); } return true; } return false; } }); }
From source file:com.analysedesgeeks.android.MainActivity.java
@Override public boolean onKeyDown(final int keyCode, final KeyEvent event) { //we need to check if we can go back in the twitter fragment. Otherwise, just pass the event down final ActionBar actionBar = getSupportActionBar(); if (actionBar.getSelectedNavigationIndex() == TWITTER_FRAGMENT_INDEX) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: final WebFragment webFragment = (WebFragment) mTabsAdapter.getItem(TWITTER_FRAGMENT_INDEX); if (webFragment.goBack()) { return true; }/*from w w w. j a va 2s . c o m*/ } } } return super.onKeyDown(keyCode, event); }
From source file:com.android.calculator2.EventListener.java
@Override public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { int action = keyEvent.getAction(); // Work-around for spurious key event from IME, bug #1639445 if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) { return true; // eat it }//from www . j ava 2s. c o m if (keyEvent.getUnicodeChar() == '=') { if (action == KeyEvent.ACTION_UP) { mHandler.onEnter(); } return true; } if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) { if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) { // Tell the handler that text was updated. mHandler.onTextChanged(); } return false; } /* * We should act on KeyEvent.ACTION_DOWN, but strangely sometimes the * DOWN event isn't received, only the UP. So the workaround is to act * on UP... http://b/issue?id=1022478 */ if (action == KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_DPAD_CENTER: mHandler.onEnter(); break; case KeyEvent.KEYCODE_DPAD_UP: mHandler.onUp(); break; case KeyEvent.KEYCODE_DPAD_DOWN: mHandler.onDown(); break; } } return true; }
From source file:com.dwdesign.tweetings.activity.SearchActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { SharedPreferences mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); if (mPreferences.getBoolean(PREFERENCE_KEY_VOLUME_NAVIGATION, false)) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_VOLUME_UP: { Intent broadcast = new Intent(); broadcast.setAction(BROADCAST_VOLUME_UP); sendBroadcast(broadcast); //scrollToPrevious(); return true; }//from w ww. ja va 2 s . c om case KeyEvent.KEYCODE_VOLUME_DOWN: { Intent broadcast = new Intent(); broadcast.setAction(BROADCAST_VOLUME_DOWN); sendBroadcast(broadcast); //scrollToNext(); return true; } } } if (event.getAction() == KeyEvent.ACTION_UP && (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP || event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN)) { return true; } } return super.dispatchKeyEvent(event); }