List of usage examples for android.view KeyEvent getAction
public final int getAction()
From source file:org.noorganization.instalist.view.fragment.ShoppingListOverviewFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // set the title in "main" activity so that the current list name is shown on the actionbar //mBaseActivityInterface.setToolbarTitle(mCurrentShoppingList.mName); mRootView = getView();/*from w w w . j av a 2 s .c om*/ if (mRootView == null) { throw new NullPointerException("Root view is null. Probably some initialization went wrong."); } mRootView.setFocusableInTouchMode(true); // set focus to this view to get key events. mRootView.requestFocus(); mRootView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View _View, int _KeyCode, KeyEvent _Event) { // onKey gets 2 calls when key was pressed ( up and down) only use the up action. if (_Event.getAction() == MotionEvent.ACTION_UP) { // only call back button when back button was released if (_KeyCode == KeyEvent.KEYCODE_BACK) { if (mActionMode != null) { mActionMode.finish(); return true; } } } return false; } }); }
From source file:io.github.yavski.fabspeeddial.FabSpeedDial.java
@Override public boolean dispatchKeyEventPreIme(KeyEvent event) { if (isMenuOpen() && event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP && event.getRepeatCount() == 0) { closeMenu();/*from www. ja v a2 s . c o m*/ return true; } return super.dispatchKeyEventPreIme(event); }
From source file:com.amsterdam.marktbureau.makkelijkemarkt.DagvergunningFragmentKoopman.java
/** * Trigger the autocomplete on enter on the erkennings- en sollicitatenummer search textviews * @param view the autocomplete textview * @param actionId the type of action//from w w w . j ava 2 s . c om * @param event the type of keyevent */ @OnEditorAction({ R.id.search_erkenningsnummer, R.id.search_sollicitatienummer }) public boolean onAutoCompleteEnter(AutoCompleteTextView view, int actionId, KeyEvent event) { if (((event != null) && (event.getAction() == KeyEvent.ACTION_DOWN) && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) { showDropdown(view); } return true; }
From source file:mobi.monaca.framework.plugin.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject//www. j av a 2s .co m */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); } // Create dialog in new thread Runnable runnable = new Runnable() { /** * Convert our DIP units to Pixels * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics()); return value; } public void run() { // Let's create the main dialog dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.TOP); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); actionButtonContainer.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button ImageButton back = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); back.setImageResource(R.drawable.childbroswer_icon_arrow_left); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button ImageButton forward = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); forward.setImageResource(R.drawable.childbroswer_icon_arrow_right); forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // Edit Text Box edittext = new EditText(cordova.getActivity()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setId(4); edittext.setSingleLine(true); edittext.setText(url); edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); edittext.setImeOptions(EditorInfo.IME_ACTION_GO); edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); // Close button ImageButton close = new ImageButton(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); close.setImageResource(R.drawable.childbroswer_icon_close); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView webview = new WebView(cordova.getActivity()); webview.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); webview.setWebChromeClient(new WebChromeClient()); WebViewClient client = new ChildBrowserClient(edittext); webview.setWebViewClient(client); WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginsEnabled(true); settings.setDomStorageEnabled(true); webview.loadUrl(url); webview.setId(6); webview.getSettings().setLoadWithOverviewMode(true); webview.getSettings().setUseWideViewPort(true); webview.requestFocus(); webview.requestFocusFromTouch(); // Add the back and forward buttons to our action button container layout actionButtonContainer.addView(back); actionButtonContainer.addView(forward); // Add the views to our toolbar toolbar.addView(actionButtonContainer); toolbar.addView(edittext); toolbar.addView(close); // Don't add the toolbar if its been disabled if (getShowLocationBar()) { // Add our toolbar to our main view/layout main.addView(toolbar); } // Add our webview to our main view/layout main.addView(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { //TODO check LocalFileBootloader InputStream input = cordova.getActivity().getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:android.support.v7.view.menu.CascadingMenuPopup.java
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_MENU) { dismiss();/* w w w .j a v a 2 s . c o m*/ return true; } return false; }
From source file:org.alfresco.mobile.android.application.fragments.search.SearchFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setRetainInstance(true);/*from w w w .j a v a 2 s. c o m*/ setRootView(inflater.inflate(R.layout.app_search_history, container, false)); init(getRootView(), emptyListMessageId); // Folder path if (getArguments() != null && getArguments().containsKey(ARGUMENT_FOLDER)) { pathView = (TextView) viewById(R.id.search_path); show(R.id.search_path_panel); displayPathOption(); } else { hide(R.id.search_path_panel); } // Search Icon searchIcon = (ImageView) viewById(R.id.search_icon); // Search Input 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) { search(searchForm.getText().toString()); UIUtils.hideKeyboard(getActivity()); } 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); } return getRootView(); }
From source file:jp.gr.java_conf.ya.shiobeforandroid3.UpdateTweetDrive.java
@Override public final boolean dispatchKeyEvent(final KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { //true???? return true; }//from w w w . ja va2s . c o m } return super.dispatchKeyEvent(event); }
From source file:com.syncedsynapse.kore2.ui.RemoteActivity.java
/** * Override hardware volume keys and send to Kodi *///from w ww . j a va 2 s . co m @Override public boolean dispatchKeyEvent(KeyEvent event) { // Check whether we should intercept this boolean useVolumeKeys = PreferenceManager.getDefaultSharedPreferences(this).getBoolean( Settings.KEY_PREF_USE_HARDWARE_VOLUME_KEYS, Settings.DEFAULT_PREF_USE_HARDWARE_VOLUME_KEYS); if (useVolumeKeys) { int action = event.getAction(); int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_DOWN) { new Application.SetVolume(GlobalType.IncrementDecrement.INCREMENT) .execute(hostManager.getConnection(), null, null); } return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { new Application.SetVolume(GlobalType.IncrementDecrement.DECREMENT) .execute(hostManager.getConnection(), null, null); } return true; } } return super.dispatchKeyEvent(event); }
From source file:com.miz.mizuu.fragments.IdentifyTvShowEpisodeFragment.java
public void onViewCreated(View v, Bundle savedInstanceState) { super.onViewCreated(v, savedInstanceState); mToolbar = (Toolbar) v.findViewById(R.id.toolbar); ((MizActivity) getActivity()).setSupportActionBar(mToolbar); mListView = (ListView) v.findViewById(R.id.listView1); mQuery = (EditText) v.findViewById(R.id.editText1); mSpinner = (Spinner) v.findViewById(R.id.spinner1); mProgress = (ProgressBar) v.findViewById(R.id.progressBar1); mListView.setOnItemClickListener(new OnItemClickListener() { @Override// w ww . ja va 2s . c om public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { updateShow(arg2); } }); mListView.setEmptyView(v.findViewById(R.id.no_results)); v.findViewById(R.id.no_results).setVisibility(View.GONE); // Manually make it gone to begin with mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { mLocale = mSpinnerAdapter.getItem(position).getLanguage(); searchForShows(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); mSpinnerAdapter = new LanguageAdapter(); mSpinner.setAdapter(mSpinnerAdapter); String language = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getString(LANGUAGE_PREFERENCE, "en"); mSpinner.setSelection(mSpinnerAdapter.getIndexForLocale(language)); mQuery.setText(mShowTitle); mQuery.setSelection(mQuery.length()); mQuery.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (s.toString().length() > 0) searchForShows(); else { mTvShowSearch.cancel(true); mAdapter.clearItems(); mAdapter.notifyDataSetChanged(); } } }); mQuery.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN || actionId == EditorInfo.IME_ACTION_SEARCH) searchForShows(); return true; } }); if (mTvShowSearch == null) { if (MizLib.isOnline(getActivity())) { mTvShowSearch = new TvShowSearch(getActivity(), mQuery.getText().toString()); } else { Toast.makeText(getActivity(), getString(R.string.noInternet), Toast.LENGTH_SHORT).show(); } } }
From source file:com.example.android.mediarouter.player.MainActivity.java
public boolean handleMediaKey(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: { Log.d(TAG, "Received Play/Pause event from RemoteControlClient"); mPaused = !mPaused;//from ww w.j av a 2 s . c o m if (mPaused) { mSessionManager.pause(); } else { mSessionManager.resume(); } return true; } case KeyEvent.KEYCODE_MEDIA_PLAY: { Log.d(TAG, "Received Play event from RemoteControlClient"); if (mPaused) { mPaused = false; mSessionManager.resume(); } return true; } case KeyEvent.KEYCODE_MEDIA_PAUSE: { Log.d(TAG, "Received Pause event from RemoteControlClient"); if (!mPaused) { mPaused = true; mSessionManager.pause(); } return true; } case KeyEvent.KEYCODE_MEDIA_STOP: { Log.d(TAG, "Received Stop event from RemoteControlClient"); mPaused = false; mSessionManager.stop(); return true; } default: break; } } return false; }