List of usage examples for android.view View onKeyDown
public boolean onKeyDown(int keyCode, KeyEvent event)
From source file:org.mozilla.gecko.home.BrowserSearch.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mList.setTag(HomePager.LIST_TAG_BROWSER_SEARCH); mList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from ww w . j ava2s .co m public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Perform the user-entered search if the user clicks on a search engine row. // This row will be disabled if suggestions (in addition to the user-entered term) are showing. if (view instanceof SearchEngineRow) { ((SearchEngineRow) view).performUserEnteredSearch(); return; } // Account for the search engine rows. position -= getPrimaryEngineCount(); final Cursor c = mAdapter.getCursor(position); final String url = c.getString(c.getColumnIndexOrThrow(URLColumns.URL)); // The "urlbar" and "frecency" sessions can be open at the same time. Use the LIST_ITEM // method to set this LOAD_URL event apart from the case where the user commits what's in // the url bar. Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.LIST_ITEM); // This item is a TwoLinePageRow, so we allow switch-to-tab. mUrlOpenListener.onUrlOpen(url, EnumSet.of(OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB)); } }); mList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { // Don't do anything when the user long-clicks on a search engine row. if (view instanceof SearchEngineRow) { return true; } // Account for the search engine rows. position -= getPrimaryEngineCount(); return mList.onItemLongClick(parent, view, position, id); } }); final ListSelectionListener listener = new ListSelectionListener(); mList.setOnItemSelectedListener(listener); mList.setOnFocusChangeListener(listener); mList.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, android.view.KeyEvent event) { final View selected = mList.getSelectedView(); if (selected instanceof SearchEngineRow) { return selected.onKeyDown(keyCode, event); } return false; } }); registerForContextMenu(mList); EventDispatcher.getInstance().registerGeckoThreadListener(this, "SearchEngines:Data"); mSearchEngineBar.setOnSearchBarClickListener(this); }