List of usage examples for android.view KeyEvent getAction
public final int getAction()
From source file:ayushi.view.fragment.ContactUsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.frag_about, container, false); getActivity().setTitle("Contact Us"); mToolbar = (Toolbar) rootView.findViewById(R.id.htab_toolbar); if (mToolbar != null) { ((ECartHomeActivity) getActivity()).setSupportActionBar(mToolbar); }/*from ww w. j av a 2s .c om*/ if (mToolbar != null) { ((ECartHomeActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolbar.setNavigationIcon(R.drawable.ic_drawer); } mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((ECartHomeActivity) getActivity()).getmDrawerLayout().openDrawer(GravityCompat.START); } }); mToolbar.setTitleTextColor(Color.WHITE); rootView.findViewById(R.id.locations).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { } }); rootView.findViewById(R.id.contact_num).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent callIntent = new Intent(Intent.ACTION_DIAL); callIntent.setData(Uri.parse("tel:" + "8888813275")); startActivity(callIntent); } }); rootView.setFocusableInTouchMode(true); rootView.requestFocus(); rootView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { Utils.switchContent(R.id.frag_container, Utils.HOME_FRAGMENT, ((ECartHomeActivity) (getContext())), AnimationType.SLIDE_UP); } return true; } }); rootView.findViewById(R.id.site_dev).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://hiteshsahu.com/")); startActivity(browserIntent); } }); rootView.findViewById(R.id.email).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("text/plain"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "hiteshkumarsahu1990@gmail.com" }); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hello There"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Add Message here"); emailIntent.setType("message/rfc822"); try { startActivity(Intent.createChooser(emailIntent, "Send email using...")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(getActivity(), "No email clients installed.", Toast.LENGTH_SHORT).show(); } } }); return rootView; }
From source file:com.app.blockydemo.ui.dialogs.TextDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_text_dialog, null); input = (EditText) dialogView.findViewById(R.id.dialog_text_edit_text); inputTitle = (TextView) dialogView.findViewById(R.id.dialog_text_text_view); if (getHint() != null) { input.setHint(getHint());/* w w w .j a va 2 s .c o m*/ } input.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if (hasFocus) { getDialog().getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); initialize(); Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(getTitle()) .setNegativeButton(R.string.cancel_button, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dismiss(); } }).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).create(); dialog.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { boolean okButtonResult = handleOkButton(); onOkButtonHandled(); if (okButtonResult) { dismiss(); } return okButtonResult; } return false; } }); dialog.setCanceledOnTouchOutside(true); dialog.setOnShowListener(new OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button buttonPositive = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE); buttonPositive.setEnabled(getPositiveButtonEnabled()); setPositiveButtonClickCustomListener(dialog); InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT); initTextChangedListener(); } }); return dialog; }
From source file:hku.fyp14017.blencode.ui.dialogs.OverwriteRenameDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { View dialogView = LayoutInflater.from(context) .inflate(hku.fyp14017.blencode.R.layout.dialog_overwrite_project, null); replaceButton = (RadioButton) dialogView .findViewById(hku.fyp14017.blencode.R.id.dialog_overwrite_project_radio_replace); replaceButton.setOnClickListener(this); renameButton = (RadioButton) dialogView .findViewById(hku.fyp14017.blencode.R.id.dialog_overwrite_project_radio_rename); renameButton.setOnClickListener(this); projectText = (EditText) dialogView.findViewById(hku.fyp14017.blencode.R.id.dialog_overwrite_project_edit); projectText.setText(programName);/* w w w. j av a2 s. co m*/ projectTextView = (TextView) dialogView .findViewById(hku.fyp14017.blencode.R.id.dialog_overwrite_project_edit_text); projectTextLine = dialogView.findViewById(hku.fyp14017.blencode.R.id.dialog_overwrite_project_edit_line); Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView) .setTitle(hku.fyp14017.blencode.R.string.overwrite_text) .setPositiveButton(hku.fyp14017.blencode.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).setNegativeButton(hku.fyp14017.blencode.R.string.cancel_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(context, hku.fyp14017.blencode.R.string.notification_download_project_cancel, Toast.LENGTH_SHORT).show(); } }) .create(); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); dialog.setOnShowListener(new OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); positiveButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { handleOkButton(); } }); } }); dialog.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { boolean okButtonResult = handleOkButton(); if (okButtonResult) { dismiss(); } return okButtonResult; } else if (keyCode == KeyEvent.KEYCODE_BACK) { Toast.makeText(context, hku.fyp14017.blencode.R.string.notification_download_project_cancel, Toast.LENGTH_SHORT).show(); return true; } return false; } }); return dialog; }
From source file:org.catrobat.catroid.ui.dialogs.TextDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_text_dialog, null); input = (EditText) dialogView.findViewById(R.id.dialog_text_edit_text); inputTitle = (TextView) dialogView.findViewById(R.id.dialog_text_text_view); if (getHint() != null) { input.setHint(getHint());/*ww w .j a v a 2 s .c o m*/ } input.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if (hasFocus) { getDialog().getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); initialize(); Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(getTitle()) .setNegativeButton(R.string.cancel_button, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dismiss(); } }).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).create(); dialog.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { boolean okButtonResult = handleOkButton(); onOkButtonHandled(); if (okButtonResult) { dismiss(); } return okButtonResult; } return false; } }); dialog.setCanceledOnTouchOutside(true); dialog.setOnShowListener(new OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button buttonPositive = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE); buttonPositive.setEnabled(getPositiveButtonEnabled()); setPositiveButtonClickCustomListener(); InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT); initTextChangedListener(); } }); return dialog; }
From source file:com.example.nq.journalism_master.innerbrowser.InnerBrowserFragment.java
@Nullable @Override// w ww . ja v a2s . co m public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_inner_browser, container, false); initViews(view); initWebViewSettings(webView); // if not set this, click the back arrow will call nothing setHasOptionsMenu(true); webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { changeToolbarAndProgressBar(newProgress); } }); webView.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view1, WebResourceRequest request, WebResourceError error) { webView.setVisibility(View.GONE); imageView.setVisibility(View.VISIBLE); textView.setVisibility(View.VISIBLE); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (NetworkState.networkConnected(getContext())) { webView.loadUrl(url); webView.setVisibility(View.VISIBLE); imageView.setVisibility(View.GONE); textView.setVisibility(View.GONE); } } }); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); progressBar.setVisibility(View.GONE); } }); // WebView?html? webView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) { webView.goBack(); return true; } } return false; } }); webView.loadUrl(url); return view; }
From source file:com.trupti_prajapati.retailapp.view.fragment.ContactUsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.frag_contactus, container, false); getActivity().setTitle("Contact Us"); mToolbar = (Toolbar) rootView.findViewById(R.id.htab_toolbar); if (mToolbar != null) { ((ECartHomeActivity) getActivity()).setSupportActionBar(mToolbar); }//ww w .jav a 2 s . c o m if (mToolbar != null) { ((ECartHomeActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolbar.setNavigationIcon(R.drawable.ic_drawer); } mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((ECartHomeActivity) getActivity()).getmDrawerLayout().openDrawer(GravityCompat.START); } }); mToolbar.setTitleTextColor(Color.WHITE); rootView.findViewById(R.id.locations).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { } }); rootView.findViewById(R.id.contact_num).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent callIntent = new Intent(Intent.ACTION_DIAL); callIntent.setData(Uri.parse("tel:" + "8866685640")); startActivity(callIntent); } }); rootView.setFocusableInTouchMode(true); rootView.requestFocus(); rootView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { Utils.switchContent(R.id.frag_container, Utils.HOME_FRAGMENT, ((ECartHomeActivity) (getContext())), AnimationType.SLIDE_UP); } return true; } }); rootView.findViewById(R.id.site_dev).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/truptinprajapati")); startActivity(browserIntent); } }); rootView.findViewById(R.id.email).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("text/plain"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "truptiprajapati19@gmail.com" }); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hello There"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Add Message here"); emailIntent.setType("message/rfc822"); try { startActivity(Intent.createChooser(emailIntent, "Send email using...")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(getActivity(), "No email clients installed.", Toast.LENGTH_SHORT).show(); } } }); return rootView; }
From source file:hku.fyp14017.blencode.ui.dialogs.TextDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { View dialogView = LayoutInflater.from(getActivity()) .inflate(hku.fyp14017.blencode.R.layout.dialog_text_dialog, null); input = (EditText) dialogView.findViewById(hku.fyp14017.blencode.R.id.dialog_text_edit_text); inputTitle = (TextView) dialogView.findViewById(hku.fyp14017.blencode.R.id.dialog_text_text_view); if (getHint() != null) { input.setHint(getHint());// w ww . j a v a 2 s. co m } input.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if (hasFocus) { getDialog().getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); initialize(); Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(getTitle()) .setNegativeButton(hku.fyp14017.blencode.R.string.cancel_button, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dismiss(); } }).setPositiveButton(hku.fyp14017.blencode.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).create(); dialog.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { boolean okButtonResult = handleOkButton(); onOkButtonHandled(); if (okButtonResult) { dismiss(); } return okButtonResult; } return false; } }); dialog.setCanceledOnTouchOutside(true); dialog.setOnShowListener(new OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button buttonPositive = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE); buttonPositive.setEnabled(getPositiveButtonEnabled()); setPositiveButtonClickCustomListener(); InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT); initTextChangedListener(); } }); return dialog; }
From source file:ch.gianulli.trelloapi.ui.AuthenticationDialogFragment.java
@Nullable @Override/*from www . ja v a 2 s . c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (getDialog() != null) { getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE); } View v = inflater.inflate(R.layout.dialog_authentication, container, false); mProgressIndicator = (ProgressBar) v.findViewById(R.id.progress_indicator); mWebView = (WebView) v.findViewById(R.id.webview); // Catch token mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { setProgressIndicatorVisibility(true); } @Override public void onPageFinished(WebView view, String url) { setProgressIndicatorVisibility(false); if (url.equals(URL_TOKEN)) { // Get token and close dialog mWebView.loadUrl("javascript:window.HTMLOUT.parseHTML('<html>'+document" + ".getElementsByTagName('html')[0].innerHTML+'</html>');"); } else { super.onPageFinished(view, url); } } }); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); mWebView.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT"); mWebView.setVisibility(View.GONE); mWebView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: if (mWebView.canGoBack()) { mWebView.goBack(); return true; } } } return false; } }); // Load first page setProgressIndicatorVisibility(true); try { mWebView.loadUrl(URL_AUTHORIZATION + "key=" + mApi.getAppKey() + "&name=" + URLEncoder.encode(getString(R.string.app_name), "UTF-8") + "&expiration=never&response_type=token&scope=read,write"); } catch (UnsupportedEncodingException e) { // never happens } return v; }
From source file:com.manueldeveloper.VolumeButtonsListener.java
/** * Overwritten method to receive the Android key events * * @param view: View object who emit the signal (CordovaWebView) * @param keyCode: int with the identifier of the pressed key * @param keyEvent: KeyEvent object with the information of the event * * @return "boolean" which indicates if the listener has consumed the event (true) or not (false) [Always false to allow that the event spreading] * * @date 27/02/2014//from w w w. ja va2 s . c o m * @version 0.0.1 * @author ManuelDeveloper(manueldeveloper@gmail.com) */ public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { // Check if the event is equal to KEY_DOWN if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) { // Check what button has been pressed if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { // Create a new JSONObject with the information and send it JSONObject info = new JSONObject(); try { info.put("signal", new String("volume-up")); sendSignal(info, true); } catch (JSONException ex) { Log.e(VolumeButtonsListener_LOG, ex.getMessage()); } } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { // Create a new JSONObject with the information and send it JSONObject info = new JSONObject(); try { info.put("signal", new String("volume-down")); sendSignal(info, true); } catch (JSONException ex) { Log.e(VolumeButtonsListener_LOG, ex.getMessage()); } } } return false; }
From source file:com.mifos.mifosxdroid.login.LoginActivity.java
@OnEditorAction(R.id.et_password) public boolean passwordSubmitted(KeyEvent keyEvent) { if (keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN) { login();// w ww .j ava2 s . c o m return true; } return false; }