List of usage examples for android.view KeyEvent getAction
public final int getAction()
From source file:com.darly.im.ui.CCPActivityBase.java
/** * * @param keyCode//from w ww . ja v a 2s. c om * @param event * @return */ public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU && event.getAction() == KeyEvent.ACTION_UP) { /*if(mOverFlowAction != null && mOverFlowAction.isEnabled()) { callMenuCallback(mOverFlowMenuItem, mOverFlowAction); return true; }*/ } return false; }
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);/*from ww w . j a v a 2 s.c o m*/ return enterPressed; }
From source file:cn.zhangls.android.weibo.ui.edit.EditActivity.java
/** * ?//from ww w.j a v a 2s. c o m */ private void setText(String text, boolean isComment) { if (isComment) { mBinding.acEditText.setText(TextUtil.convertText(this, text, ContextCompat.getColor(this, R.color.colorAccent), (int) mBinding.acEditText.getTextSize())); return; } if (mStatus.getRetweeted_status() != null) // ? mBinding.acEditText.setText(TextUtil.convertText(this, text, ContextCompat.getColor(this, R.color.colorAccent), (int) mBinding.acEditText.getTextSize())); // ??????? mTopicList = TextUtil.findRegexString(mBinding.acEditText.getText().toString(), Constants.RegularExpression.TopicRegex); mNameList = TextUtil.findRegexString(mBinding.acEditText.getText().toString(), Constants.RegularExpression.NameRegex); // ? UserName Topic mBinding.acEditText.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { // return keyCode == KeyEvent.KEYCODE_DEL && event.getAction() == KeyEvent.ACTION_DOWN && (setSelection(mBinding.acEditText, mTopicList, true) || setSelection(mBinding.acEditText, mNameList, true)); } }); // EditText ? UserName Topic ? UserName Topic ? mBinding.acEditText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // ? Topic Name boolean topic = setSelection(mBinding.acEditText, mTopicList, false); if (!topic) { setSelection(mBinding.acEditText, mNameList, false); } } }); }
From source file:com.google.android.apps.flexbox.FlexItemEditFragment.java
private void setNextFocusesOnEnterDown(final TextView... textViews) { // This can be done by setting android:nextFocus* as in // https://developer.android.com/training/keyboard-input/navigation.html // But it requires API level 11 as a minimum sdk version. To support the lower level devices, // doing it programatically. for (int i = 0; i < textViews.length; i++) { final int index = i; textViews[index].setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override// ww w . j av a2s .c om public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE || (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { if (index + 1 < textViews.length) { textViews[index + 1].requestFocus(); } else if (index == textViews.length - 1) { InputMethodManager inputMethodManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0); } } return true; } }); // Suppress the key focus change by KeyEvent.ACTION_UP of the enter key textViews[index].setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { return keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP; } }); } }
From source file:com.digium.respoke.ChatActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); getActionBar().setDisplayHomeAsUpEnabled(true); Button buttonSend = (Button) findViewById(R.id.buttonSend); EditText chatText = (EditText) findViewById(R.id.chatText); chatText = (EditText) findViewById(R.id.chatText); chatText.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { sendChatMessage();/*from w w w . j a va 2 s .c o m*/ return true; } return false; } }); buttonSend.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { sendChatMessage(); } }); String remoteEndpointID = null; boolean shouldStartDirectConnection = false; // Check whether we're recreating a previously destroyed instance if (savedInstanceState != null) { remoteEndpointID = savedInstanceState.getString(ENDPOINT_ID_KEY); shouldStartDirectConnection = savedInstanceState.getBoolean(DIRECT_CONNECTION_KEY, false); } else { Bundle extras = getIntent().getExtras(); if (extras != null) { remoteEndpointID = extras.getString(ENDPOINT_ID_KEY); shouldStartDirectConnection = extras.getBoolean(DIRECT_CONNECTION_KEY, false); } else { // The activity must have been destroyed while it was hidden to save memory. Use the most recent persistent data. SharedPreferences prefs = getSharedPreferences(ConnectActivity.RESPOKE_SETTINGS, 0); remoteEndpointID = prefs.getString(ENDPOINT_ID_KEY, ""); shouldStartDirectConnection = prefs.getBoolean(DIRECT_CONNECTION_KEY, false); } } conversation = ContactManager.sharedInstance().conversations.get(remoteEndpointID); remoteEndpoint = ContactManager.sharedInstance().sharedClient.getEndpoint(remoteEndpointID, true); setTitle(remoteEndpoint.getEndpointID()); listAdapter = new ListDataAdapter(); ListView lv = (ListView) findViewById(R.id.list); //retrieve the instance of the ListView from your main layout lv.setAdapter(listAdapter); //assign the Adapter to be used by the ListView if (shouldStartDirectConnection && (null == remoteEndpoint.directConnection())) { // If the direct connection has not been started yet, start it now remoteEndpoint.startDirectConnection(); } directConnection = remoteEndpoint.directConnection(); if (null != directConnection) { directConnection.setListener(this); RespokeCall call = directConnection.getCall(); boolean caller = false; if (null != call) { call.setListener(this); caller = call.isCaller(); } View answerView = findViewById(R.id.answer_view); View connectingView = findViewById(R.id.connecting_view); TextView callerNameView = (TextView) findViewById(R.id.caller_name_text); if (caller) { answerView.setVisibility(View.INVISIBLE); connectingView.setVisibility(View.VISIBLE); } else { answerView.setVisibility(View.VISIBLE); connectingView.setVisibility(View.INVISIBLE); } if (null != remoteEndpoint) { callerNameView.setText(remoteEndpoint.getEndpointID()); } else { callerNameView.setText("Unknown Caller"); } ActionBar actionBar = getActionBar(); actionBar.setBackgroundDrawable(new ColorDrawable(R.color.incoming_connection_bg)); actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayShowTitleEnabled(true); } }
From source file:lewa.support.v7.app.ActionBarActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() != KeyEvent.ACTION_UP) { if (getDelegate().onBackPressed()) { return true; }/*from www.j a v a 2s . c om*/ } return super.dispatchKeyEvent(event); }
From source file:org.sipdroid.sipua.ui.Sipdroid.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.sipdroid);/* w w w. j a v a 2 s . c om*/ sip_uri_box = (AutoCompleteTextView) findViewById(R.id.txt_callee); sip_uri_box2 = (AutoCompleteTextView) findViewById(R.id.txt_callee2); sip_uri_box.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { call_menu(sip_uri_box); return true; } return false; } }); sip_uri_box.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { call_menu(sip_uri_box); } }); sip_uri_box2.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { call_menu(sip_uri_box2); return true; } return false; } }); sip_uri_box2.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { call_menu(sip_uri_box2); } }); on(this, true); Button contactsButton = (Button) findViewById(R.id.contacts_button); contactsButton.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { Intent myIntent = new Intent(Intent.ACTION_DIAL); startActivity(myIntent); } }); final Context mContext = this; Button settingsButton = (Button) findViewById(R.id.settings_button); settingsButton.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { Intent myIntent = new Intent(mContext, org.sipdroid.sipua.ui.Settings.class); startActivity(myIntent); } }); final OnDismissListener listener = this; createButton = (Button) findViewById(R.id.create_button); createButton.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { CreateAccount createDialog = new CreateAccount(mContext); createDialog.setOnDismissListener(listener); createDialog.show(); } }); if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Settings.PREF_NOPORT, Settings.DEFAULT_NOPORT)) { boolean ask = false; for (int i = 0; i < SipdroidEngine.LINES; i++) { String j = (i != 0 ? "" + i : ""); if (PreferenceManager.getDefaultSharedPreferences(this) .getString(Settings.PREF_SERVER + j, Settings.DEFAULT_SERVER) .equals(Settings.DEFAULT_SERVER) && PreferenceManager.getDefaultSharedPreferences(this) .getString(Settings.PREF_USERNAME + j, Settings.DEFAULT_USERNAME).length() != 0 && PreferenceManager.getDefaultSharedPreferences(this) .getString(Settings.PREF_PORT + j, Settings.DEFAULT_PORT) .equals(Settings.DEFAULT_PORT)) ask = true; } if (ask) new AlertDialog.Builder(this).setMessage(R.string.dialog_port) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Editor edit = PreferenceManager.getDefaultSharedPreferences(mContext).edit(); for (int i = 0; i < SipdroidEngine.LINES; i++) { String j = (i != 0 ? "" + i : ""); if (PreferenceManager.getDefaultSharedPreferences(mContext) .getString(Settings.PREF_SERVER + j, Settings.DEFAULT_SERVER) .equals(Settings.DEFAULT_SERVER) && PreferenceManager.getDefaultSharedPreferences(mContext) .getString(Settings.PREF_USERNAME + j, Settings.DEFAULT_USERNAME) .length() != 0 && PreferenceManager.getDefaultSharedPreferences(mContext) .getString(Settings.PREF_PORT + j, Settings.DEFAULT_PORT) .equals(Settings.DEFAULT_PORT)) edit.putString(Settings.PREF_PORT + j, "5061"); } edit.commit(); Receiver.engine(mContext).halt(); Receiver.engine(mContext).StartEngine(); } }).setNeutralButton(R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).setNegativeButton(R.string.dontask, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Editor edit = PreferenceManager.getDefaultSharedPreferences(mContext).edit(); edit.putBoolean(Settings.PREF_NOPORT, true); edit.commit(); } }).show(); } else if (PreferenceManager.getDefaultSharedPreferences(this) .getString(Settings.PREF_PREF, Settings.DEFAULT_PREF).equals(Settings.VAL_PREF_PSTN) && !PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Settings.PREF_NODEFAULT, Settings.DEFAULT_NODEFAULT)) new AlertDialog.Builder(this).setMessage(R.string.dialog_default) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Editor edit = PreferenceManager.getDefaultSharedPreferences(mContext).edit(); edit.putString(Settings.PREF_PREF, Settings.VAL_PREF_SIP); edit.commit(); } }).setNeutralButton(R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).setNegativeButton(R.string.dontask, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Editor edit = PreferenceManager.getDefaultSharedPreferences(mContext).edit(); edit.putBoolean(Settings.PREF_NODEFAULT, true); edit.commit(); } }).show(); }
From source file:org.alfresco.mobile.android.application.fragments.user.UserSearchFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (getDialog() != null) { getDialog().requestWindowFeature(Window.FEATURE_LEFT_ICON); }/*from ww w. j a v a 2s. c om*/ // Retrieve session object checkSession(); if (getArguments() != null && getArguments().containsKey(ARGUMENT_MODE)) { fieldId = getArguments().getString(ARGUMENT_FIELD_ID); keywords = getArguments().getString(ARGUMENT_KEYWORD); title = getArguments().getString(ARGUMENT_TITLE); mode = getArguments().getInt(ARGUMENT_MODE); singleChoice = getArguments().getBoolean(ARGUMENT_SINGLE_CHOICE); String pickFragmentTag = getArguments().getString(ARGUMENT_FRAGMENT_TAG); fragmentPick = getFragmentManager().findFragmentByTag(pickFragmentTag); if (fragmentPick != null && fragmentPick instanceof UserPickerCallback) { selectedItems = ((UserPickerCallback) fragmentPick).retrieveSelection(); } else if (fragmentPick instanceof onPickAuthorityFragment && fieldId != null) { selectedItems = ((onPickAuthorityFragment) fragmentPick).getPersonSelected(fieldId); } } // Create View setRootView(inflater.inflate(R.layout.app_pick_person, container, false)); if (getSession() == null) { return getRootView(); } // Init list init(getRootView(), R.string.person_not_found); gv.setChoiceMode(GridView.CHOICE_MODE_SINGLE); setListShown(true); if (keywords != null && !keywords.isEmpty()) { search(keywords); hide(R.id.search_form_group); } else { // Init form search searchForm = (EditText) viewById(R.id.search_query); searchForm.setImeOptions(EditorInfo.IME_ACTION_SEARCH); searchForm.setOnEditorActionListener(new 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))) { if (searchForm.getText().length() > 0) { keywords = searchForm.getText().toString(); search(keywords); } else { AlfrescoNotificationManager.getInstance(getActivity()) .showLongToast(getString(R.string.search_form_hint)); } return true; } return false; } }); // Speech to Text Boolean hasTextToSpeech = ActionUtils.hasSpeechToText(getActivity()); ImageButton speechToText = (ImageButton) viewById(R.id.search_microphone); if (hasTextToSpeech) { speechToText.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { speechToText(); } }); } else { hide(R.id.search_microphone); } } if (getMode() == MODE_PICK) { show(R.id.validation_panel); validation = UIUtils.initValidation(getRootView(), R.string.done); updatePickButton(); validation.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onSelect(selectedItems); if (getDialog() != null) { getDialog().dismiss(); } else { getFragmentManager().popBackStack(); } } }); Button cancel = UIUtils.initCancel(getRootView(), R.string.cancel); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (getDialog() != null) { getDialog().dismiss(); } else { getFragmentManager().popBackStack(); } } }); } else { hide(R.id.validation_panel); } return getRootView(); }
From source file:com.example.tuicool.MainActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { if (System.currentTimeMillis() - preTime < 2000) // {/*from www . j av a 2s .com*/ finish(); } else Toast.makeText(this, "", Toast.LENGTH_SHORT).show(); // System.exit(0); preTime = System.currentTimeMillis(); // } return true;// }
From source file:com.itude.mobile.mobbl.core.controller.util.MBBasicViewController.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { _isDialogClosable = getArguments().getBoolean("closable", false); _isDialogFullscreen = getArguments().getBoolean("fullscreen", false); _isDialogCancelable = getArguments().getBoolean("cancelable", false) || _isDialogCancelable; if (_isDialogClosable) { ViewGroup view = buildInitialView(LayoutInflater.from(getActivity())); /*/* w w w.j av a 2 s . c om*/ * Add this view and a close button to a wrapper view that will be used as the content view of our AlertDialog */ // unable to use the holo light theme as pre honeycomb doesn't know AlertDialog.Builder(context, theme) AlertDialog.Builder adb = new AlertDialog.Builder(getActivity()); AlertDialog dialog = adb.create(); View content = addCloseButtonToClosableDialogView(view, dialog); dialog.setView(content); dialog.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) { return onBackKeyPressed(); } return false; } }); return dialog; } if (_isDialogFullscreen) { setStyle(STYLE_NO_TITLE, android.R.style.Theme); } return super.onCreateDialog(savedInstanceState); }