List of usage examples for android.view KeyEvent KEYCODE_ENTER
int KEYCODE_ENTER
To view the source code for android.view KeyEvent KEYCODE_ENTER.
Click Source Link
From source file:org.petero.droidfish.DroidFish.java
private final Dialog networkEngineConfigDialog() { View content = View.inflate(this, R.layout.network_engine_config, null); final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(content);/*from w w w . j a v a2 s. c o m*/ builder.setTitle(R.string.configure_network_engine); final EditText hostNameView = (EditText) content.findViewById(R.id.network_engine_host); final EditText portView = (EditText) content.findViewById(R.id.network_engine_port); String hostName = ""; String port = "0"; try { if (EngineUtil.isNetEngine(networkEngineToConfig)) { String[] lines = Util.readFile(networkEngineToConfig); if (lines.length > 1) hostName = lines[1]; if (lines.length > 2) port = lines[2]; } } catch (IOException e1) { } hostNameView.setText(hostName); portView.setText(port); final Runnable writeConfig = new Runnable() { public void run() { String hostName = hostNameView.getText().toString(); String port = portView.getText().toString(); try { FileWriter fw = new FileWriter(new File(networkEngineToConfig), false); fw.write("NETE\n"); fw.write(hostName); fw.write("\n"); fw.write(port); fw.write("\n"); fw.close(); setEngineOptions(true); } catch (IOException e) { Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show(); } } }; builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { writeConfig.run(); removeDialog(NETWORK_ENGINE_DIALOG); showDialog(NETWORK_ENGINE_DIALOG); } }); builder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { removeDialog(NETWORK_ENGINE_DIALOG); showDialog(NETWORK_ENGINE_DIALOG); } }); builder.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { removeDialog(NETWORK_ENGINE_DIALOG); showDialog(NETWORK_ENGINE_DIALOG); } }); builder.setNeutralButton(R.string.delete, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { removeDialog(DELETE_NETWORK_ENGINE_DIALOG); showDialog(DELETE_NETWORK_ENGINE_DIALOG); } }); final Dialog dialog = builder.create(); portView.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { writeConfig.run(); dialog.cancel(); removeDialog(NETWORK_ENGINE_DIALOG); showDialog(NETWORK_ENGINE_DIALOG); return true; } return false; } }); return dialog; }
From source file:edu.mit.viral.shen.DroidFish.java
private final Dialog newNetworkEngineDialog() { View content = View.inflate(this, R.layout.create_network_engine, null); final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(content);/* w w w . j ava2 s.co m*/ builder.setTitle(R.string.create_network_engine); final EditText engineNameView = (EditText) content.findViewById(R.id.create_network_engine); engineNameView.setText(""); final Runnable createEngine = new Runnable() { public void run() { String engineName = engineNameView.getText().toString(); String sep = File.separator; String pathName = Environment.getExternalStorageDirectory() + sep + engineDir + sep + engineName; File file = new File(pathName); boolean nameOk = true; int errMsg = -1; if (engineName.contains("/")) { nameOk = false; errMsg = R.string.slash_not_allowed; } else if (internalEngine(engineName) || file.exists()) { nameOk = false; errMsg = R.string.engine_name_in_use; } if (!nameOk) { Toast.makeText(getApplicationContext(), errMsg, Toast.LENGTH_LONG).show(); removeDialog(NETWORK_ENGINE_DIALOG); showDialog(NETWORK_ENGINE_DIALOG); return; } networkEngineToConfig = pathName; removeDialog(NETWORK_ENGINE_CONFIG_DIALOG); showDialog(NETWORK_ENGINE_CONFIG_DIALOG); } }; builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { createEngine.run(); } }); builder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { removeDialog(NETWORK_ENGINE_DIALOG); showDialog(NETWORK_ENGINE_DIALOG); } }); builder.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { removeDialog(NETWORK_ENGINE_DIALOG); showDialog(NETWORK_ENGINE_DIALOG); } }); final Dialog dialog = builder.create(); engineNameView.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { createEngine.run(); dialog.cancel(); return true; } return false; } }); return dialog; }
From source file:edu.mit.viral.shen.DroidFish.java
private final Dialog networkEngineConfigDialog() { View content = View.inflate(this, R.layout.network_engine_config, null); final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(content);//from w w w . j av a 2s .c o m builder.setTitle(R.string.configure_network_engine); final EditText hostNameView = (EditText) content.findViewById(R.id.network_engine_host); final EditText portView = (EditText) content.findViewById(R.id.network_engine_port); String hostName = ""; String port = "0"; try { String[] lines = Util.readFile(networkEngineToConfig); if ((lines.length >= 1) && lines[0].equals("NETE")) { if (lines.length > 1) hostName = lines[1]; if (lines.length > 2) port = lines[2]; } } catch (IOException e1) { } hostNameView.setText(hostName); portView.setText(port); final Runnable writeConfig = new Runnable() { public void run() { String hostName = hostNameView.getText().toString(); String port = portView.getText().toString(); try { FileWriter fw = new FileWriter(new File(networkEngineToConfig), false); fw.write("NETE\n"); fw.write(hostName); fw.write("\n"); fw.write(port); fw.write("\n"); fw.close(); setEngineOptions(true); } catch (IOException e) { Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show(); } } }; builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { writeConfig.run(); removeDialog(NETWORK_ENGINE_DIALOG); showDialog(NETWORK_ENGINE_DIALOG); } }); builder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { removeDialog(NETWORK_ENGINE_DIALOG); showDialog(NETWORK_ENGINE_DIALOG); } }); builder.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { removeDialog(NETWORK_ENGINE_DIALOG); showDialog(NETWORK_ENGINE_DIALOG); } }); builder.setNeutralButton(R.string.delete, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { removeDialog(DELETE_NETWORK_ENGINE_DIALOG); showDialog(DELETE_NETWORK_ENGINE_DIALOG); } }); final Dialog dialog = builder.create(); portView.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { writeConfig.run(); dialog.cancel(); removeDialog(NETWORK_ENGINE_DIALOG); showDialog(NETWORK_ENGINE_DIALOG); return true; } return false; } }); return dialog; }
From source file:com.nttec.everychan.ui.presentation.BoardFragment.java
private void initSearchBar() { if (searchBarInitialized) return;//from www. j a v a 2 s .c o m final EditText field = (EditText) searchBarView.findViewById(R.id.board_search_field); final TextView results = (TextView) searchBarView.findViewById(R.id.board_search_result); if (pageType == TYPE_POSTSLIST) { field.setHint(R.string.search_bar_in_thread_hint); } final View.OnClickListener searchOnClickListener = new View.OnClickListener() { private int lastFound = -1; @Override public void onClick(View v) { if (v != null && v.getId() == R.id.board_search_close) { searchHighlightActive = false; adapter.notifyDataSetChanged(); searchBarView.setVisibility(View.GONE); } else if (listView != null && listView.getChildCount() > 0 && adapter != null && cachedSearchResults != null) { boolean atEnd = listView.getChildAt(listView.getChildCount() - 1).getTop() + listView.getChildAt(listView.getChildCount() - 1).getHeight() == listView.getHeight(); View topView = listView.getChildAt(0); if ((v == null || v.getId() == R.id.board_search_previous) && topView.getTop() < 0 && listView.getChildCount() > 1) topView = listView.getChildAt(1); int currentListPosition = listView.getPositionForView(topView); int newResultIndex = Collections.binarySearch(cachedSearchResults, currentListPosition); if (newResultIndex >= 0) { if (v != null) { if (v.getId() == R.id.board_search_next) ++newResultIndex; else if (v.getId() == R.id.board_search_previous) --newResultIndex; } } else { newResultIndex = -newResultIndex - 1; if (v != null && v.getId() == R.id.board_search_previous) --newResultIndex; } while (newResultIndex < 0) newResultIndex += cachedSearchResults.size(); newResultIndex %= cachedSearchResults.size(); if (v != null && v.getId() == R.id.board_search_next && lastFound == newResultIndex && atEnd) newResultIndex = 0; lastFound = newResultIndex; listView.setSelection(cachedSearchResults.get(newResultIndex)); results.setText((newResultIndex + 1) + "/" + cachedSearchResults.size()); } } }; for (int id : new int[] { R.id.board_search_close, R.id.board_search_previous, R.id.board_search_next }) { searchBarView.findViewById(id).setOnClickListener(searchOnClickListener); } field.setOnKeyListener(new View.OnKeyListener() { private boolean searchUsingChan() { if (pageType != TYPE_THREADSLIST) return false; if (presentationModel != null) if (presentationModel.source != null) if (presentationModel.source.boardModel != null) if (!presentationModel.source.boardModel.searchAllowed) return false; return true; } @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { if (searchUsingChan()) { UrlPageModel model = new UrlPageModel(); model.chanName = chan.getChanName(); model.type = UrlPageModel.TYPE_SEARCHPAGE; model.boardName = tabModel.pageModel.boardName; model.searchRequest = field.getText().toString(); UrlHandler.open(model, activity); } else { int highlightColor = ThemeUtils.getThemeColor(activity.getTheme(), R.attr.searchHighlightBackground, Color.RED); String request = field.getText().toString().toLowerCase(Locale.US); if (cachedSearchRequest == null || !request.equals(cachedSearchRequest)) { cachedSearchRequest = request; cachedSearchResults = new ArrayList<Integer>(); cachedSearchHighlightedSpanables = new SparseArray<Spanned>(); List<PresentationItemModel> safePresentationList = presentationModel .getSafePresentationList(); if (safePresentationList != null) { for (int i = 0; i < safePresentationList.size(); ++i) { PresentationItemModel model = safePresentationList.get(i); if (model.hidden && !staticSettings.showHiddenItems) continue; String comment = model.spannedComment.toString().toLowerCase(Locale.US) .replace('\n', ' '); List<Integer> altFoundPositions = null; if (model.floating) { int floatingpos = FlowTextHelper.getFloatingPosition(model.spannedComment); if (floatingpos != -1 && floatingpos < model.spannedComment.length() && model.spannedComment.charAt(floatingpos) == '\n') { String altcomment = comment.substring(0, floatingpos) + comment.substring(floatingpos + 1, Math.min(model.spannedComment.length(), floatingpos + request.length())); int start = 0; int curpos; while (start < altcomment.length() && (curpos = altcomment.indexOf(request, start)) != -1) { if (altFoundPositions == null) altFoundPositions = new ArrayList<Integer>(); altFoundPositions.add(curpos); start = curpos + request.length(); } } } if (comment.contains(request) || altFoundPositions != null) { cachedSearchResults.add(Integer.valueOf(i)); SpannableStringBuilder spannedHighlited = new SpannableStringBuilder( safePresentationList.get(i).spannedComment); int start = 0; int curpos; while (start < comment.length() && (curpos = comment.indexOf(request, start)) != -1) { start = curpos + request.length(); if (altFoundPositions != null && Collections.binarySearch(altFoundPositions, curpos) >= 0) continue; spannedHighlited.setSpan(new BackgroundColorSpan(highlightColor), curpos, curpos + request.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } if (altFoundPositions != null) { for (Integer pos : altFoundPositions) { spannedHighlited.setSpan(new BackgroundColorSpan(highlightColor), pos, pos + request.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } cachedSearchHighlightedSpanables.put(i, spannedHighlited); } } } } if (cachedSearchResults.size() == 0) { Toast.makeText(activity, R.string.notification_not_found, Toast.LENGTH_LONG).show(); } else { boolean firstTime = !searchHighlightActive; searchHighlightActive = true; adapter.notifyDataSetChanged(); searchBarView.findViewById(R.id.board_search_next).setVisibility(View.VISIBLE); searchBarView.findViewById(R.id.board_search_previous).setVisibility(View.VISIBLE); searchBarView.findViewById(R.id.board_search_result).setVisibility(View.VISIBLE); searchOnClickListener .onClick(firstTime ? null : searchBarView.findViewById(R.id.board_search_next)); } } try { InputMethodManager imm = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(field.getWindowToken(), 0); } catch (Exception e) { Logger.e(TAG, e); } return true; } return false; } }); field.addTextChangedListener(new OnSearchTextChangedListener(this)); field.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); if (resources.getDimensionPixelSize(R.dimen.panel_height) < field.getMeasuredHeight()) searchBarView.getLayoutParams().height = field.getMeasuredHeight(); searchBarInitialized = true; }
From source file:com.glview.widget.AbsListView.java
/** * Sends a key to the text filter window * * @param keyCode The keycode for the event * @param event The actual key event/*w ww . j av a 2 s.c o m*/ * * @return True if the text filter handled the event, false otherwise. */ boolean sendToTextFilter(int keyCode, int count, KeyEvent event) { if (!acceptFilter()) { return false; } boolean handled = false; boolean okToSend = true; switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: okToSend = false; break; case KeyEvent.KEYCODE_BACK: okToSend = false; break; case KeyEvent.KEYCODE_SPACE: // Only send spaces once we are filtered okToSend = mFiltered; break; } if (okToSend) { KeyEvent forwardEvent = event; if (forwardEvent.getRepeatCount() > 0) { forwardEvent = KeyEvent.changeTimeRepeat(event, event.getEventTime(), 0); } int action = event.getAction(); switch (action) { case KeyEvent.ACTION_DOWN: break; case KeyEvent.ACTION_UP: break; case KeyEvent.ACTION_MULTIPLE: break; } } return handled; }
From source file:org.brandroid.openmanager.activities.OpenExplorer.java
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (v == null) return false; if (DEBUG)//from ww w . j a va2 s .c om Logger.LogDebug("OpenExplorer.onKey(" + v + "," + keyCode + "," + event + ")"); if (event.getAction() != KeyEvent.ACTION_UP) return false; if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) { if (MenuUtils.getMenuLookupID(v.getId()) > 0) if (showMenu(MenuUtils.getMenuLookupSub(v.getId()), v, false)) return true; } return false; }
From source file:com.appunite.list.AbsHorizontalListView.java
/** * Sends a key to the text filter window * * @param keyCode The keycode for the event * @param event The actual key event/*from w ww.ja va 2 s .c om*/ * * @return True if the text filter handled the event, false otherwise. */ boolean sendToTextFilter(int keyCode, int count, KeyEvent event) { if (!acceptFilter()) { return false; } boolean handled = false; boolean okToSend = true; switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: okToSend = false; break; case KeyEvent.KEYCODE_BACK: if (mFiltered && mPopup != null && mPopup.isShowing()) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { KeyEvent.DispatcherState state = getKeyDispatcherState(); if (state != null) { state.startTracking(event, this); } handled = true; } else if (event.getAction() == KeyEvent.ACTION_UP && event.isTracking() && !event.isCanceled()) { handled = true; mTextFilter.setText(""); } } okToSend = false; break; case KeyEvent.KEYCODE_SPACE: // Only send spaces once we are filtered okToSend = mFiltered; break; } if (okToSend) { createTextFilter(true); KeyEvent forwardEvent = event; if (forwardEvent.getRepeatCount() > 0) { forwardEvent = KeyEvent.changeTimeRepeat(event, event.getEventTime(), 0); } int action = event.getAction(); switch (action) { case KeyEvent.ACTION_DOWN: handled = mTextFilter.onKeyDown(keyCode, forwardEvent); break; case KeyEvent.ACTION_UP: handled = mTextFilter.onKeyUp(keyCode, forwardEvent); break; case KeyEvent.ACTION_MULTIPLE: handled = mTextFilter.onKeyMultiple(keyCode, count, event); break; } } return handled; }