List of usage examples for android.view KeyEvent getAction
public final int getAction()
From source file:com.android.kalite27.ScriptActivity.java
/** * Check if the path contains a data and a content folder * @param path/*from w ww . j av a 2 s.c o m*/ * @return */ private boolean check_directory(String path) { File content_file = new File(path + "/content"); // if the directory doesn't contain data or content folder, alert if (!content_file.exists()) { new AlertDialog.Builder(this).setTitle("Invalid Directory") .setMessage("The selected directory doesn't contain the content folder") .setPositiveButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { isFileBrowserClosed = true; openWebViewIfAllConditionsMeet(); } }).setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { isFileBrowserClosed = true; openWebViewIfAllConditionsMeet(); } }).setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) { dialog.cancel(); isFileBrowserClosed = true; openWebViewIfAllConditionsMeet(); return true; } return false; } }).show(); return false; } else { return true; } }
From source file:org.profeda.dictionary.SearchActivity.java
/** * Called when the activity is first created. *///w w w .j a va2 s . com @Override public void onCreate(Bundle savedInstanceState) { final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(SearchActivity.this); if (pref.getBoolean("show_changelog", true) == true) { MessageBox.showChangeLog(this); } loadDictionaries(pref); if (pref.getBoolean("p_invert_colors", false) == true) { setTheme(R.style.Light); } else { setTheme(R.style.Dark); } super.onCreate(savedInstanceState); setContentView(R.layout.main); dict = new Dict(this, pref.getString("dictFile", null)); updateTitleBar(); readMRU(); final EditText searchbox = (EditText) findViewById(R.id.searchbox); final Button dictselectbutton = (Button) findViewById(R.id.dictselectbutton); final ListView listview = (ListView) findViewById(R.id.contentlist); listview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView l, View v, int position, long id) { ListAdapter la = ((ListView) l).getAdapter(); if (la instanceof GenericStringAdapter) { final String data = (String) la.getItem(position); if (data.startsWith("> ")) { searchbox.setText(data.substring(2)); doSearch(true); } } else if (la instanceof DictListAdapter) { final String[] data = (String[]) la.getItem(position); final List<Dict> langs = Dict.searchForLanguage(SearchActivity.this, dict.toLang, null); String[] menu = new String[langs.size() + 1]; menu[0] = getString(R.string.copy_translation_to_clipboard); for (int i = 1; i < menu.length; i++) menu[i] = String.format(getString(R.string.search_translation_in_language), langs.get(i - 1).toLang); Matcher m = Pattern.compile("<b>(.*)<\\/b>.*").matcher(data[1]); if (!m.matches()) return; final String translation = m.group(1).trim(); new AlertDialog.Builder(SearchActivity.this).setIcon(android.R.drawable.ic_dialog_info) .setTitle(translation).setItems(menu, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { switch (arg1) { case 0: ClipboardManager cm = (ClipboardManager) getSystemService( CLIPBOARD_SERVICE); cm.setText(translation); break; default: dict = langs.get(arg1 - 1); readMRU(); updateTitleBar(); searchbox.setText(translation); doSearch(true); } } }).show(); } } }); searchbox.setOnEditorActionListener(new EditText.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) { doSearch(true); return true; } else { return false; } } }); final Drawable deleteIcon = getResources().getDrawable(R.drawable.textbox_clear); //deleteIcon.setBounds(0, 0, deleteIcon.getIntrinsicWidth(), deleteIcon.getIntrinsicHeight()); deleteIcon.setBounds(0, 0, 51, 30); // wtf??? die Zahlen sind empirisch ermittelt... ab right>=52 springt die hhe des editText searchbox.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { searchbox.setCompoundDrawables(null, null, s.toString().equals("") ? null : deleteIcon, null); //searchbox.setCompoundDrawablesWithIntrinsicBounds(null, null, s.toString().equals("") ? null : deleteIcon, null); searchbox.setCompoundDrawablePadding(0); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { if (enableLivesearch && s.length() > 1 && dict.filePrefix != null && dictSearchInAction == false) { DictionarySearcher ds = new DictionarySearcher(); ds.targetList = (ListView) findViewById(R.id.contentlist); ds.execute(dict.filePrefix, s.toString()); } if (s.length() == 0) { displayMRU(); } } }); //searchbox.setCompoundDrawables(null, null, deleteIcon, null); searchbox.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (searchbox.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > searchbox.getWidth() - searchbox.getPaddingRight() - deleteIcon.getIntrinsicWidth()) { searchbox.setText(""); searchbox.setCompoundDrawables(null, null, null, null); } return false; } }); dictselectbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { selectDictionary(); } }); ((Button) findViewById(R.id.dictswapbutton)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final List<Dict> langs = Dict.searchForLanguage(SearchActivity.this, dict.toLang, dict.fromLang); if (langs.size() > 0) { dict = langs.get(0); readMRU(); updateTitleBar(); searchbox.setText(""); } else { MessageBox.alert(SearchActivity.this, getString(R.string.no_reverse_dict_found)); } } }); }
From source file:com.mozilla.simplepush.simplepushdemoapp.MainActivity.java
/** Initialize the app from the saved state * * @param savedInstanceState The previously stored instance *//*from www .ja v a 2 s . c o m*/ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Properties config; try { config = loadProperties(); SENDER_ID = config.getProperty("sender_id"); if (SENDER_ID == null) { Log.e(TAG, "sender_id not definied in configuration file. Aborting"); return; } } catch (IOException x) { Log.e(TAG, "Could not load properties"); return; } setContentView(R.layout.activity_main); // Set the convenience globals. mDisplay = (TextView) findViewById(R.id.display); hostUrl = (EditText) findViewById(R.id.host_edit); pingData = (EditText) findViewById(R.id.message); sendButton = (Button) findViewById(R.id.send); connectButton = (Button) findViewById(R.id.connect); context = getApplicationContext(); // Check that GCM is available on this device. if (checkPlayServices()) { gcm = GoogleCloudMessaging.getInstance(this); regid = getRegistrationId(context); } else { Log.i(TAG, "No valid Google Play Services APK found"); } // detect the "enter/submit" key for the editor views. hostUrl.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { boolean handled = false; // yes, be very careful about this, else you can send multiple actions. if (actionId == EditorInfo.IME_ACTION_SEND || (actionId == EditorInfo.IME_ACTION_UNSPECIFIED && event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN)) { registerInBackground(); handled = true; } return handled; } }); pingData.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { boolean handled = false; if (actionId == EditorInfo.IME_ACTION_SEND || (actionId == EditorInfo.IME_ACTION_UNSPECIFIED && event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN)) { SendNotification(getMessage()); handled = true; } return handled; } }); }
From source file:com.holo.fileexplorer.MainActivity.java
/** * Since Dialogs are (almost always) attached to an activity, they are all * defined here to provide simple, combined access. Courtesy of OpenIntents: * <p>// w w w . j a v a 2 s. c o m * http://code.google.com/p/openintents/source/browse/#svn/trunk/samples/ * TestFileManager * <p> * *Note: commented code is straight from OI, and uncommented has been * modified to work with HFE * * @param id * id code of the desired dialog. Defined as a set of constants * within MainActivity * @param bundle * the bundle containing any parameters to be used by the dialog * @return a reference to the open dialog */ // @Override protected Dialog onCreateDialog(int id, Bundle bundle) { switch (id) { case DIALOG_NEW_FOLDER: LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.dialog_new_folder, null); final EditText et = (EditText) view.findViewById(R.id.foldername); et.setText(""); // accept "return" key TextView.OnEditorActionListener returnListener = new TextView.OnEditorActionListener() { public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN) { // match this behavior to your OK button // createNewFolder(et.getText().toString()); dismissDialog(DIALOG_NEW_FOLDER); } return true; } }; // et.setOnEditorActionListener(returnListener); // // end of code regarding "return key" // // return new AlertDialog.Builder(this) // .setIcon(android.R.drawable.ic_dialog_alert) // .setTitle(R.string.create_new_folder) // .setView(view) // .setPositiveButton(android.R.string.ok, // new OnClickListener() { // // public void onClick(DialogInterface dialog, // int which) { // createNewFolder(et.getText().toString()); // } // // }) // .setNegativeButton(android.R.string.cancel, // new OnClickListener() { // // public void onClick(DialogInterface dialog, // int which) { // // Cancel should not do anything. // } // // }).create(); // case DIALOG_RENAME: // inflater = LayoutInflater.from(this); // view = inflater.inflate(R.layout.dialog_new_folder, null); // final EditText et2 = (EditText) // view.findViewById(R.id.foldername); // // accept "return" key // TextView.OnEditorActionListener returnListener2 = new // TextView.OnEditorActionListener() { // public boolean onEditorAction(TextView exampleView, // int actionId, KeyEvent event) { // if (actionId == EditorInfo.IME_NULL // && event.getAction() == KeyEvent.ACTION_DOWN) { // renameFileOrFolder(mContextFile, et2.getText() // .toString()); // match this behavior to your OK // // button // dismissDialog(DIALOG_RENAME); // } // return true; // } // // }; // et2.setOnEditorActionListener(returnListener2); // // end of code regarding "return key" // return new AlertDialog.Builder(this) // .setTitle(R.string.menu_rename) // .setView(view) // .setPositiveButton(android.R.string.ok, // new OnClickListener() { // // public void onClick(DialogInterface dialog, // int which) { // // renameFileOrFolder(mContextFile, et2 // .getText().toString()); // } // // }) // .setNegativeButton(android.R.string.cancel, // new OnClickListener() { // // public void onClick(DialogInterface dialog, // int which) { // // Cancel should not do anything. // } // // }).create(); case DIALOG_ZIP: inflater = LayoutInflater.from(this); view = inflater.inflate(R.layout.dialog_new_folder, null); final EditText editText = (EditText) view.findViewById(R.id.foldername); // accept "return" key TextView.OnEditorActionListener returnListener3 = new TextView.OnEditorActionListener() { public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN) { mViewPager.getFragment(mPager, mPager.getCurrentItem()) .zipInit(editText.getText().toString()); // if (new File(mContextFile.getParent() + // File.separator // + editText.getText().toString()).exists()) { // mDialogArgument = editText.getText().toString(); // showDialog(DIALOG_WARNING_EXISTS); // } else { // new CompressManager(FileManagerActivity.this) // .compress(mContextFile, editText.getText() // .toString()); // } // match this behavior to your OK button dismissDialog(DIALOG_ZIP); } return true; } }; editText.setOnEditorActionListener(returnListener3); // end of code regarding "return key" return new AlertDialog.Builder(this).setTitle(R.string.zip_dialog).setView(view) .setPositiveButton(android.R.string.ok, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { mViewPager.getFragment(mPager, mPager.getCurrentItem()) .zipInit(editText.getText().toString()); // if (new File(mContextFile.getParent() // + File.separator // + editText.getText().toString()) // .exists()) { // mDialogArgument = editText.getText() // .toString(); // showDialog(DIALOG_WARNING_EXISTS); // } else { // new CompressManager( // FileManagerActivity.this) // .compress(mContextFile, // editText.getText() // .toString()); // } } }).setNegativeButton(android.R.string.cancel, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Cancel should not do anything. } }).create(); } return super.onCreateDialog(id, bundle); }
From source file:com.android.tv.settings.accessories.AddAccessoryActivity.java
@Override public void onNewIntent(Intent intent) { if (ACTION_CONNECT_INPUT.equals(intent.getAction()) && (intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) == 0) { // We were the front most app and we got a new intent. // If screen saver is going, stop it. try {/*from w w w .ja v a2 s. co m*/ if (mDreamManager != null && mDreamManager.isDreaming()) { mDreamManager.awaken(); } } catch (RemoteException e) { // Do nothing. } KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_PAIRING) { if (event.getAction() == KeyEvent.ACTION_UP) { onHwKeyEvent(false); } else if (event.getAction() == KeyEvent.ACTION_DOWN) { onHwKeyEvent(true); } } } else { setIntent(intent); } }
From source file:com.irccloud.android.activity.BaseActivity.java
public void onIRCEvent(int what, Object obj) { String message = ""; final IRCCloudJSONObject o; switch (what) { case NetworkConnection.EVENT_BADCHANNELKEY: o = (IRCCloudJSONObject) obj;/*from w w w . jav a2 s . co m*/ runOnUiThread(new Runnable() { @Override public void run() { Server server = ServersList.getInstance().getServer(o.cid()); AlertDialog.Builder builder = new AlertDialog.Builder(BaseActivity.this); View view = getDialogTextPrompt(); TextView prompt = view.findViewById(R.id.prompt); final EditText keyinput = view.findViewById(R.id.textInput); keyinput.setText(""); keyinput.setOnEditorActionListener(new OnEditorActionListener() { public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN) { try { if (keyinput.getText() != null) conn.join(o.cid(), o.getString("chan"), keyinput.getText().toString()); } catch (Exception e) { // TODO Auto-generated catch block NetworkConnection.printStackTraceToCrashlytics(e); } ((AlertDialog) keyinput.getTag()).dismiss(); } return true; } }); try { prompt.setText("Password for " + o.getString("chan")); } catch (Exception e) { // TODO Auto-generated catch block NetworkConnection.printStackTraceToCrashlytics(e); } builder.setTitle( server.getName() + " (" + server.getHostname() + ":" + (server.getPort()) + ")"); builder.setView(view); builder.setPositiveButton("Join", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { conn.join(o.cid(), o.getString("chan"), keyinput.getText().toString()); } catch (Exception e) { // TODO Auto-generated catch block NetworkConnection.printStackTraceToCrashlytics(e); } dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog dialog = builder.create(); keyinput.setTag(dialog); dialog.setOwnerActivity(BaseActivity.this); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); dialog.show(); } }); break; case NetworkConnection.EVENT_INVALIDNICK: o = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { Server server = ServersList.getInstance().getServer(o.cid()); AlertDialog.Builder builder = new AlertDialog.Builder(BaseActivity.this); View view = getDialogTextPrompt(); TextView prompt = view.findViewById(R.id.prompt); final EditText nickinput = view.findViewById(R.id.textInput); nickinput.setText(""); nickinput.setOnEditorActionListener(new OnEditorActionListener() { public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN) { try { conn.say(o.cid(), null, "/nick " + nickinput.getText().toString()); } catch (Exception e) { // TODO Auto-generated catch block NetworkConnection.printStackTraceToCrashlytics(e); } ((AlertDialog) nickinput.getTag()).dismiss(); } return true; } }); try { String message = o.getString("invalid_nick") + " is not a valid nickname, try again"; if (server.isupport != null && server.isupport.has("NICKLEN")) message += "\n(" + server.isupport.get("NICKLEN").asText() + " chars)"; message += "."; prompt.setText(message); } catch (Exception e) { // TODO Auto-generated catch block NetworkConnection.printStackTraceToCrashlytics(e); } builder.setTitle( server.getName() + " (" + server.getHostname() + ":" + (server.getPort()) + ")"); builder.setView(view); builder.setPositiveButton("Change Nickname", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { conn.say(o.cid(), null, "/nick " + nickinput.getText().toString()); } catch (Exception e) { // TODO Auto-generated catch block NetworkConnection.printStackTraceToCrashlytics(e); } dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog dialog = builder.create(); nickinput.setTag(dialog); dialog.setOwnerActivity(BaseActivity.this); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); dialog.show(); } }); break; case NetworkConnection.EVENT_ALERT: try { o = (IRCCloudJSONObject) obj; String type = o.type(); if (type.equalsIgnoreCase("invite_only_chan")) showAlert(o.cid(), "You need an invitation to join " + o.getString("chan")); else if (type.equalsIgnoreCase("channel_full")) showAlert(o.cid(), o.getString("chan") + " isn't allowing any more members to join."); else if (type.equalsIgnoreCase("banned_from_channel")) showAlert(o.cid(), "You've been banned from " + o.getString("chan")); else if (type.equalsIgnoreCase("invalid_nickchange")) showAlert(o.cid(), o.getString("ban_channel") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("no_messages_from_non_registered")) { if (o.has("nick") && o.getString("nick").length() > 0) showAlert(o.cid(), o.getString("nick") + ": " + o.getString("msg")); else showAlert(o.cid(), o.getString("msg")); } else if (type.equalsIgnoreCase("not_registered")) { String first = o.getString("first"); if (o.has("rest")) first += " " + o.getString("rest"); showAlert(o.cid(), first + ": " + o.getString("msg")); } else if (type.equalsIgnoreCase("too_many_channels")) showAlert(o.cid(), "Couldn't join " + o.getString("chan") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("too_many_targets")) showAlert(o.cid(), o.getString("description") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("no_such_server")) showAlert(o.cid(), o.getString("server") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("unknown_command")) showAlert(o.cid(), "Unknown command: " + o.getString("command")); else if (type.equalsIgnoreCase("help_not_found")) showAlert(o.cid(), o.getString("topic") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("accept_exists")) showAlert(o.cid(), o.getString("nick") + " " + o.getString("msg")); else if (type.equalsIgnoreCase("accept_not")) showAlert(o.cid(), o.getString("nick") + " " + o.getString("msg")); else if (type.equalsIgnoreCase("nick_collision")) showAlert(o.cid(), o.getString("collision") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("nick_too_fast")) showAlert(o.cid(), o.getString("nick") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("save_nick")) showAlert(o.cid(), o.getString("nick") + ": " + o.getString("msg") + ": " + o.getString("new_nick")); else if (type.equalsIgnoreCase("unknown_mode")) showAlert(o.cid(), "Missing mode: " + o.getString("params")); else if (type.equalsIgnoreCase("user_not_in_channel")) showAlert(o.cid(), o.getString("nick") + " is not in " + o.getString("channel")); else if (type.equalsIgnoreCase("need_more_params")) showAlert(o.cid(), "Missing parameters for command: " + o.getString("command")); else if (type.equalsIgnoreCase("chan_privs_needed")) showAlert(o.cid(), o.getString("chan") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("not_on_channel")) showAlert(o.cid(), o.getString("channel") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("ban_on_chan")) showAlert(o.cid(), "You cannot change your nick to " + o.getString("proposed_nick") + " while banned on " + o.getString("channel")); else if (type.equalsIgnoreCase("cannot_send_to_chan")) showAlert(o.cid(), o.getString("channel") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("user_on_channel")) showAlert(o.cid(), o.getString("nick") + " is already a member of " + o.getString("channel")); else if (type.equalsIgnoreCase("no_nick_given")) showAlert(o.cid(), "No nickname given"); else if (type.equalsIgnoreCase("nickname_in_use")) showAlert(o.cid(), o.getString("nick") + " is already in use"); else if (type.equalsIgnoreCase("silence")) { String mask = o.getString("usermask"); if (mask.startsWith("-")) message = mask.substring(1) + " removed from silence list"; else if (mask.startsWith("+")) message = mask.substring(1) + " added to silence list"; else message = "Silence list change: " + mask; showAlert(o.cid(), message); } else if (type.equalsIgnoreCase("no_channel_topic")) showAlert(o.cid(), o.getString("channel") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("time")) { message = o.getString("time_string"); if (o.has("time_stamp") && o.getString("time_stamp").length() > 0) message += " (" + o.getString("time_stamp") + ")"; message += " " + o.getString("time_server"); showAlert(o.cid(), message); } else showAlert(o.cid(), o.getString("msg")); } catch (Exception e1) { NetworkConnection.printStackTraceToCrashlytics(e1); } break; default: break; } }
From source file:de.azapps.mirakel.new_ui.fragments.TaskFragment.java
private void initTaskNameEdit() { taskNameEdit.setText(task.getName()); // Show Keyboard if stub if (task.isStub()) { taskNameViewSwitcher.showNext(); taskNameEdit.selectAll();/*w w w.j a va 2s.c o m*/ taskNameEdit.requestFocus(); toggleKeyboard(); } taskNameEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(final View v, final boolean hasFocus) { if (hasFocus) { toggleKeyboard(); } } }); taskNameEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) { switch (actionId) { case EditorInfo.IME_ACTION_DONE: case EditorInfo.IME_ACTION_SEND: updateName(); return true; } return false; } }); taskNameEdit.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(final View v, final int keyCode, final KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { updateName(); return true; } return false; } }); }
From source file:com.android.launcher3.allapps.FullMergeAlgorithm.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { // Determine if the key event was actual text, if so, focus the search bar and then dispatch // the key normally so that it can process this key event if (!mSearchBarController.isSearchFieldFocused() && event.getAction() == KeyEvent.ACTION_DOWN) { final int unicodeChar = event.getUnicodeChar(); final boolean isKeyNotWhitespace = unicodeChar > 0 && !Character.isWhitespace(unicodeChar) && !Character.isSpaceChar(unicodeChar); if (isKeyNotWhitespace) { boolean gotKey = TextKeyListener.getInstance().onKeyDown(this, mSearchQueryBuilder, event.getKeyCode(), event); if (gotKey && mSearchQueryBuilder.length() > 0) { mSearchBarController.focusSearchField(); }//w w w. jav a2s. c om } } return super.dispatchKeyEvent(event); }
From source file:fr.plnech.igem.game.AbstractGameActivity.java
@Override public boolean onKeyDown(final int pKeyCode, @NonNull final KeyEvent pEvent) { if (gameScene != null && pauseScene != null && pKeyCode == KeyEvent.KEYCODE_MENU && pEvent.getAction() == KeyEvent.ACTION_DOWN) { if (gameScene.hasChildScene()) { // The game is paused music.play();//from ww w .j av a 2 s . co m pauseScene.back(); updateNextStatus(); } else { music.pause(); gameScene.setChildScene(pauseScene, false, true, true); } return true; } else { return super.onKeyDown(pKeyCode, pEvent); } }