List of usage examples for android.view KeyEvent getAction
public final int getAction()
From source file:android.support.v7ox.app.AppCompatActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { final int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.KEYCODE_DPAD_UP) { final int action = event.getAction(); if (action == KeyEvent.ACTION_DOWN) { if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { final ActionBar actionBar = getSupportActionBar(); if (actionBar != null && actionBar.isShowing() && actionBar.requestFocus()) { mEatKeyUpEvent = true; return true; }/* w w w . j ava 2 s .c om*/ } } else if (action == KeyEvent.ACTION_UP && mEatKeyUpEvent) { mEatKeyUpEvent = false; return true; } } return super.dispatchKeyEvent(event); }
From source file:com.nttec.everychan.ui.BoardsListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (isFailInstance) { Toast.makeText(activity, R.string.error_unknown, Toast.LENGTH_LONG).show(); return new View(activity); }/*from ww w. j a v a 2 s . c om*/ startItem = tabModel.startItemNumber; startItemTop = tabModel.startItemTop; rootView = inflater.inflate(R.layout.boardslist_fragment, container, false); loadingView = rootView.findViewById(R.id.boardslist_loading); errorView = rootView.findViewById(R.id.boardslist_error); errorTextView = (TextView) errorView.findViewById(R.id.frame_error_text); listView = (ListView) rootView.findViewById(android.R.id.list); listView.setOnItemClickListener(this); registerForContextMenu(listView); boardField = (EditText) rootView.findViewById(R.id.boardslist_board_field); boardField.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { onClick(v); return true; } return false; } }); buttonGo = (Button) rootView.findViewById(R.id.boardslist_btn_go); buttonGo.setOnClickListener(this); activity.setTitle(chan.getDisplayingName()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) CompatibilityImpl.setActionBarCustomFavicon(activity, chan.getChanFavicon()); update(false); return rootView; }
From source file:com.company.millenium.iwannask.MainActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: // if (myWebView.canGoBack()) { // myWebView.goBack(); // } else { // finish(); // } return true; }//ww w . j a v a 2s . c o m } return super.onKeyDown(keyCode, event); }
From source file:com.scooter1556.sms.android.fragment.tv.TvAudioPlayerFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { view.setOnKeyListener(new View.OnKeyListener() { @Override//from ww w.j a v a2 s. c om public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) { if (lastPlaybackState != null) { if (lastPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING) { mediaController.getTransportControls().pause(); } else { mediaController.getTransportControls().play(); } } return true; } } return false; } }); }
From source file:com.qiusheng.cast.CastActivity.java
/** * Processes volume up and volume down actions upon receiving them as key * events./*w w w. jav a2 s .c o m*/ */ @Override public boolean dispatchKeyEvent(KeyEvent event) { int action = event.getAction(); int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_DOWN) { double currentVolume; if (mMessageStream != null) { currentVolume = mMessageStream.getVolume(); logVIfEnabled(TAG, "Volume up from " + currentVolume); if (currentVolume < 1.0) { logVIfEnabled(TAG, "New volume: " + (currentVolume + VOLUME_INCREMENT)); onSetVolume(currentVolume + VOLUME_INCREMENT); } } else { Log.e(TAG, "dispatchKeyEvent - volume up - mMessageStream==null"); } } return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { double currentVolume; if (mMessageStream != null) { currentVolume = mMessageStream.getVolume(); logVIfEnabled(TAG, "Volume down from: " + currentVolume); if (currentVolume > 0.0) { logVIfEnabled(TAG, "New volume: " + (currentVolume - VOLUME_INCREMENT)); onSetVolume(currentVolume - VOLUME_INCREMENT); } } else { Log.e(TAG, "dispatchKeyEvent - volume down - mMessageStream==null"); } } return true; default: return super.dispatchKeyEvent(event); } }
From source file:com.alivenet.dmvtaxi.fragment.FragmentArriveDriver.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (view != null) { ViewGroup parent = (ViewGroup) view.getParent(); if (parent != null) parent.removeView(view);//www . j a v a 2s . com } try { view = inflater.inflate(R.layout.fragment_time_estemet, container, false); } catch (InflateException e) { } if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } mPref = getActivity().getSharedPreferences(MYPREF, Context.MODE_PRIVATE); mUserId = mPref.getString("userId", null); gps = new GPSTracker(getActivity()); MyApplication.arrivedrivermarker = true; progressDialog = new ProgressDialog(getActivity()); progressDialog.setMessage("Please wait..."); progressDialog.setCancelable(false); mlinerlayoutbottom = (LinearLayout) view.findViewById(R.id.ll_bottom); mphone = (ImageView) view.findViewById(R.id.iv_phone); mphonenumber = (TextView) view.findViewById(R.id.tv_phonenumber); marrivaltime = (TextView) view.findViewById(R.id.tv_textarrival); mname = (TextView) view.findViewById(R.id.tv_name); mlicence = (TextView) view.findViewById(R.id.tv_licence); mtaximodel = (TextView) view.findViewById(R.id.tv_model); muserImage = (ImageView) view.findViewById(R.id.imageView_close); getLatLong(); btnSplite = (Button) view.findViewById(R.id.btn_splite_rides); btnSplite.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent in = new Intent(getActivity(), SplitAddFrnd.class); startActivity(in); } }); mphone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String uri = "tel:" + mphonenumber.getText().toString().trim(); Intent intent = new Intent(Intent.ACTION_CALL); intent.setData(Uri.parse(uri)); startActivity(intent); } }); System.out.println("userId>>>>>>>>>>>>>>>>>>>>>" + mUserId); mname.setText(MyApplication.driverName); mlicence.setText(MyApplication.licenseId); mtaximodel.setText(MyApplication.vehicle); mphonenumber.setText(MyApplication.mobileNO); Picasso.with(getActivity()).load(MyApplication.imageUrl).error(R.mipmap.avtar).placeholder(R.mipmap.avtar) .into(muserImage); System.out.println("driverImageurl" + "chceck=" + MyApplication.imageUrl); mphonenumber.setText("Call To" + " " + MyApplication.driverName); final SinchClient sinchClient = Sinch.getSinchClientBuilder().context(getActivity()).userId(mUserId) .applicationKey("3b013f09-db1f-422e-ac7b-c6498e119612") .applicationSecret("LMhelEFYtUqms55VX1C7MQ==").environmentHost("sandbox.sinch.com").build(); sinchClient.setSupportCalling(true); sinchClient.start(); mphone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (call == null) { if (MyApplication.mobileNO != null && !MyApplication.mobileNO.equals("")) { call = sinchClient.getCallClient().callPhoneNumber("+" + MyApplication.mobileNO); System.out.println("mobile_number" + MyApplication.mobileNO); //call = sinchClient.getCallClient().callPhoneNumber("+918510834641"); try { call.addCallListener(new SinchCallListener()); } catch (Exception e) { e.printStackTrace(); } mphonenumber.setText("Hang Up"); } } else { call.hangup(); } } }); view.setFocusableInTouchMode(true); view.requestFocus(); view.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { // handle back button's click listener if (keyCode == KeyEvent.KEYCODE_BACK) { Fragment homeFragment = new FragmentMainScreen(); FragmentManager frgManager; frgManager = getFragmentManager(); frgManager.beginTransaction().replace(R.id.fragment_switch, homeFragment).commit(); return true; } return true; } return false; } }); return view; }
From source file:com.phonegap.plugins.childBrowser.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load./* www.ja v a 2 s . c o m*/ * @param jsonObject */ 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() { public void run() { dialog = new Dialog(ctx.getContext()); 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"); } } }); LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f); LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); LinearLayout main = new LinearLayout(ctx.getContext()); main.setOrientation(LinearLayout.VERTICAL); LinearLayout toolbar = new LinearLayout(ctx.getContext()); toolbar.setOrientation(LinearLayout.HORIZONTAL); ImageButton back = new ImageButton(ctx.getContext()); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); back.setId(1); try { back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setLayoutParams(backParams); ImageButton forward = new ImageButton(ctx.getContext()); forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); forward.setId(2); try { forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } forward.setLayoutParams(forwardParams); edittext = new EditText(ctx.getContext()); 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; } }); edittext.setId(3); edittext.setSingleLine(true); edittext.setText(url); edittext.setLayoutParams(editParams); ImageButton close = new ImageButton((Context) ctx); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); close.setId(4); try { close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setLayoutParams(closeParams); webview = new WebView(ctx.getContext()); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setBuiltInZoomControls(true); // dda: intercept calls to console.log webview.setWebChromeClient(new WebChromeClient() { public boolean onConsoleMessage(ConsoleMessage cmsg) { // check secret prefix if (cmsg.message().startsWith("MAGIC")) { String msg = cmsg.message().substring(5); // strip off prefix /* process HTML */ try { JSONObject obj = new JSONObject(); obj.put("type", PAGE_LOADED); obj.put("html", msg); sendUpdate(obj, true); } catch (JSONException e) { Log.d("ChildBrowser", "This should never happen"); } return true; } return false; } }); // dda: inject the JavaScript on page load webview.setWebViewClient(new ChildBrowserClient(edittext) { public void onPageFinished(WebView view, String address) { // have the page spill its guts, with a secret prefix Log.d("ChildBrowser", "\n\nInjecting javascript\n\n"); view.loadUrl( "javascript:console.log('MAGIC'+document.getElementsByTagName('html')[0].innerHTML);"); } }); // webview.setWebViewClient(client); webview.loadUrl(url); webview.setId(5); webview.setInitialScale(0); webview.setLayoutParams(wvParams); webview.requestFocus(); webview.requestFocusFromTouch(); toolbar.addView(back); toolbar.addView(forward); toolbar.addView(edittext); toolbar.addView(close); if (getShowLocationBar()) { main.addView(toolbar); } 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 { InputStream input = ctx.getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.ctx.runOnUiThread(runnable); return ""; }
From source file:com.gao.im.ui.ECLauncherUI.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { LogUtil.d(LogUtil.getLogUtilsTag(ECLauncherUI.class), " onKeyDown"); if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK) && event.getAction() == KeyEvent.ACTION_UP) { // dismiss PlusSubMenuHelper if (mOverflowHelper != null && mOverflowHelper.isOverflowShowing()) { mOverflowHelper.dismiss();//w w w. ja va2 s .co m return true; } } // ?menu?? if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK) && event.getAction() == KeyEvent.ACTION_DOWN) { doTaskToBackEvent(); } try { return super.dispatchKeyEvent(event); } catch (Exception e) { LogUtil.e(LogUtil.getLogUtilsTag(ECLauncherUI.class), "dispatch key event catch exception " + e.getMessage()); } return false; }
From source file:com.miz.mizuu.fragments.IdentifyMovieFragment.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/*from www . j a v a2s .c o m*/ public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { updateMovie(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(); searchForMovies(); } @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(mMovieStructure.getDecryptedFilename()); 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) searchForMovies(); else { mMovieSearch.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) searchForMovies(); return true; } }); if (mMovieSearch == null) { if (MizLib.isOnline(getActivity())) { mMovieSearch = new MovieSearch(getActivity(), mQuery.getText().toString()); } else { Toast.makeText(getActivity(), getString(R.string.noInternet), Toast.LENGTH_SHORT).show(); } } }
From source file:com.mobicage.rogerthat.plugins.friends.ServiceSearchActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.service_search); mSearchCategoryLabels = (LinearLayout) findViewById(R.id.search_category); mSearchCategoryViewFlipper = (SafeViewFlipper) findViewById(R.id.search_result_lists); mSearchInfoByCategory = new HashMap<String, ServiceSearchActivity.SearchInfo>(); mSearchInfoByListView = new HashMap<AbsListView, ServiceSearchActivity.SearchInfo>(); mGestureScanner = new GestureDetector(new ViewFlipperSlider(mOnSwipeLeft, mOnSwipeRight)); final Context ctx = this; final EditText editText = (EditText) findViewById(R.id.search_text); editText.setOnEditorActionListener(new OnEditorActionListener() { @Override/*www. ja va2 s. co m*/ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN)) { if (!TextUtils.isEmptyOrWhitespace(mSearchString)) { UIUtils.hideKeyboard(ServiceSearchActivity.this, v); launchFindServiceCall(); return true; } } return false; } }); editText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { mSearchString = s.toString(); clearSearches(); } }); findViewById(R.id.search_button).setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { if (TextUtils.isEmptyOrWhitespace(mSearchString)) { mSearchString = ""; } UIUtils.hideKeyboard(ctx, editText); clearSearches(); launchFindServiceCall(); } }); }