List of usage examples for android.view KeyEvent getAction
public final int getAction()
From source file:com.ekeitho.sound.MainActivity.java
public boolean dispatchKeyEvent(KeyEvent event) { double VOLUME_INCREMENT = 0.05; int action = event.getAction(); int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_DOWN) { if (mRemoteMediaPlayer != null) { double currentVolume = Cast.CastApi.getVolume(mApiClient); if (currentVolume < 1.0) { try { Cast.CastApi.setVolume(mApiClient, Math.min(currentVolume + VOLUME_INCREMENT, 1.0)); } catch (Exception e) { Log.e(TAG, "unable to set volume", e); }/*from w w w. j av a 2 s. c o m*/ } } else { Log.e(TAG, "dispatchKeyEvent - volume up"); } } return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { if (mRemoteMediaPlayer != null) { double currentVolume = Cast.CastApi.getVolume(mApiClient); if (currentVolume > 0.0) { try { Cast.CastApi.setVolume(mApiClient, Math.max(currentVolume - VOLUME_INCREMENT, 0.0)); } catch (Exception e) { Log.e(TAG, "unable to set volume", e); } } } else { Log.e(TAG, "dispatchKeyEvent - volume down"); } } return true; default: return super.dispatchKeyEvent(event); } }
From source file:net.gaast.giggity.ChooserActivity.java
private void showAddDialog() { AlertDialog.Builder d = new AlertDialog.Builder(this); d.setTitle(R.string.add_dialog);/*from w w w.j a v a 2s . co m*/ final EditText urlBox = new EditText(this); urlBox.setHint(R.string.enter_url); urlBox.setSingleLine(); urlBox.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); d.setView(urlBox); d.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { openSchedule(urlBox.getText().toString(), false, null); } }); /* Apparently the "Go"/"Done" button still just simulates an ENTER keypress. Neat!... http://stackoverflow.com/questions/5677563/listener-for-done-button-on-edittext */ urlBox.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { openSchedule(urlBox.getText().toString(), false, null); return true; } else { return false; } } }); d.setNeutralButton(R.string.qr_scan, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { Intent intent = new Intent(BARCODE_SCANNER); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); startActivityForResult(intent, 0); } catch (ActivityNotFoundException e) { new AlertDialog.Builder(ChooserActivity.this) .setMessage("Please install the Barcode Scanner app").setTitle("Error").show(); } } }); d.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); d.show(); }
From source file:net.inbox.Pager.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Show first use help boolean show_help = false; // Init SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (!prefs.contains("initialized")) { PreferenceManager.setDefaultValues(this, R.xml.settings, false); prefs.edit().putBoolean("initialized", true).apply(); // Initial values that don't have a preference screen prefs.edit().putBoolean("imap_or_pop", true).apply(); prefs.edit().putBoolean("using_smtp", false).apply(); prefs.edit().putBoolean("enable_pw", false).apply(); show_help = true;/*ww w. j a v a 2s .c om*/ } if (show_help || !prefs.getBoolean("enable_pw", false)) { init_db("cleartext"); // Initial entry view View v = View.inflate(this, R.layout.pager, null); v.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in)); setContentView(v); rv_main = (RelativeLayout) findViewById(R.id.app_main); rv_main.setVisibility(View.VISIBLE); rv_main.setAlpha(0.01f); rv_main.animate().alpha(1f).setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); activity_load(); } }); } else { // Initial entry view View v = View.inflate(this, R.layout.pager, null); v.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in)); setContentView(v); // Entry text edit llay_pw = (LinearLayout) findViewById(R.id.llay_pw); llay_pw.setVisibility(View.VISIBLE); rv_main = (RelativeLayout) findViewById(R.id.app_main); et_pw = (EditText) findViewById(R.id.pw); et_pw.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int key, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && key == KeyEvent.KEYCODE_ENTER) { init_db(et_pw.getText().toString()); et_pw.setText(""); if (unlocked) { activity_load(); fade_in_ui(); } else { if (++over >= 3) finish(); } return true; } return false; } }); } // Helper dialog if (show_help) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCancelable(true); builder.setTitle(getString(R.string.helper_title)); builder.setMessage(getString(R.string.helper_msg)); builder.setPositiveButton(getString(android.R.string.ok), null); builder.setNegativeButton(getString(R.string.btn_pw), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(getApplicationContext(), Settings.class)); overridePendingTransition(R.anim.right_in, R.anim.right_out); } }); builder.show(); } }
From source file:org.chromium.content_shell.Shell.java
private void initializeUrlField() { mUrlTextView = (EditText) findViewById(R.id.url); mUrlTextView.setOnEditorActionListener(new OnEditorActionListener() { @Override/*w ww . j a v a 2 s.c o m*/ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((actionId != EditorInfo.IME_ACTION_GO) && (event == null || event.getKeyCode() != KeyEvent.KEYCODE_ENTER || event.getAction() != KeyEvent.ACTION_DOWN)) { return false; } loadUrl(mUrlTextView.getText().toString()); setKeyboardVisibilityForUrl(false); mContentView.requestFocus(); return true; } }); mUrlTextView.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { setKeyboardVisibilityForUrl(hasFocus); mNextButton.setVisibility(hasFocus ? GONE : VISIBLE); mPrevButton.setVisibility(hasFocus ? GONE : VISIBLE); if (!hasFocus) { mUrlTextView.setText(mContentView.getUrl()); } } }); }
From source file:bbct.android.common.activity.BaseballCardDetails.java
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.card_details, container, false); ButterKnife.bind(this, view); final Activity activity = Objects.requireNonNull(getActivity()); String cardDetailsTitle = this.getString(R.string.card_details_title); String title = this.getString(R.string.bbct_title, cardDetailsTitle); activity.setTitle(title);//from w ww.ja v a2 s . com brandText.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { Log.d(TAG, "onKey() in Brand TextView"); Log.d(TAG, "keyCode = " + keyCode); if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_ENTER) { Log.d(TAG, "focus on Year"); yearText.requestFocus(); return true; } return false; } }); playerNameText.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { Log.d(TAG, "onKey() in Player Name TextView"); Log.d(TAG, "keyCode = " + keyCode); if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_ENTER) { Log.d(TAG, "focus on Team"); teamText.requestFocus(); return true; } return false; } }); teamText.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { Log.d(TAG, "onKey() in Team TextView"); Log.d(TAG, "keyCode = " + keyCode); if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_ENTER) { Log.d(TAG, "hide keyboard"); InputMethodManager imm = Objects.requireNonNull( (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)); imm.hideSoftInputFromWindow(teamText.getWindowToken(), 0); playerPositionSpinner.requestFocus(); return true; } return false; } }); createAdapters(activity); populateTextEdits(); return view; }
From source file:org.xwalk.core.xwview.shell.XWalkViewShellActivity.java
private void initializeUrlField() { mUrlTextView = (EditText) findViewById(R.id.url); mUrlTextView.setOnEditorActionListener(new OnEditorActionListener() { @Override//from w w w. ja va 2s. c om public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((actionId != EditorInfo.IME_ACTION_GO) && (event == null || event.getKeyCode() != KeyEvent.KEYCODE_ENTER || event.getAction() != KeyEvent.ACTION_DOWN)) { return false; } if (mActiveView == null) return true; mActiveView.load(sanitizeUrl(mUrlTextView.getText().toString()), null); mUrlTextView.clearFocus(); setKeyboardVisibilityForUrl(false); return true; } }); mUrlTextView.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { setKeyboardVisibilityForUrl(hasFocus); mNextButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE); mPrevButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE); mStopButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE); mReloadButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE); if (!hasFocus) { if (mActiveView == null) return; mUrlTextView.setText(mActiveView.getUrl()); } } }); }
From source file:com.nextgis.rehacompdemo.RoutingActivity.java
@Override public boolean dispatchKeyEvent(@NonNull KeyEvent event) { int position; int action = event.getAction(); int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_DOWN) { position = mSteps.getSelectedItemPosition(); if (position == AdapterView.INVALID_POSITION) position = 0;// www . ja va2 s . c o m else position--; mSteps.requestFocusFromTouch(); mSteps.setSelection(position); break; } else return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { position = mSteps.getSelectedItemPosition(); if (position == AdapterView.INVALID_POSITION) position = 0; else position++; mSteps.requestFocusFromTouch(); mSteps.setSelection(position); break; } else return true; default: return super.dispatchKeyEvent(event); } return true; }
From source file:com.scooter1556.sms.androidtv.fragment.VideoPlayerFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { view.setOnKeyListener(new View.OnKeyListener() { @Override/*from w w w .j av a2 s . co m*/ public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) { if (player != null) { if (player.isPlaying()) { player.pause(); } else { player.start(); } } return true; } } return false; } }); }
From source file:com.android.view.leg.ImageDetailActivityLeg.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { }//ww w . java 2 s.c o m // TODO Auto-generated method stub return super.onKeyDown(keyCode, event); }
From source file:com.alivenet.dmvtaxi.fragment.FragmentRateYourRide.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.trip_completed, container, false); ratingBar = (RatingBar) view.findViewById(R.id.ratingbar); Text_tripcomplete_pickuplocation = (TextView) view.findViewById(R.id.tripcomplete_pickuplocation); Text_tripcomplete_dropoff_location = (TextView) view.findViewById(R.id.tripcomplete_dropoff_location); mname = (TextView) view.findViewById(R.id.tv_name); Text_tripcharged = (TextView) view.findViewById(R.id.tripcharged); mlicenceplate = (TextView) view.findViewById(R.id.tv_licenceplate); mtaname = (TextView) view.findViewById(R.id.tv_taname); mcommentbox = (EditText) view.findViewById(R.id.et_commentbox); btntip = (Button) view.findViewById(R.id.btntip); btnsubmit = (Button) view.findViewById(R.id.btnsubmit); icon = (ImageView) view.findViewById(R.id.tripcompltd_icons); mPref = getActivity().getSharedPreferences(MYPREF, Context.MODE_PRIVATE); mUserId = mPref.getString("userId", null); prgDialog = new ProgressDialog(getActivity()); prgDialog.setMessage("Please wait..."); prgDialog.setCancelable(false);// w w w . j ava2s . c o m btntip.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (MyApplication.RateyourRide == false) { LayoutInflater li = LayoutInflater.from(getContext()); View promptsView = li.inflate(R.layout.prompts, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); alertDialogBuilder.setView(promptsView); tipValue = (EditText) promptsView.findViewById(R.id.edittip_value); // set dialog message alertDialogBuilder.setCancelable(false) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // get user input and set it to result // edit text if (tipValue.getText().toString().trim().length() == 0) { } else { btntip.setText(String.format("Tip: $ %.2f", Double.valueOf(tipValue.getText().toString()))); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); getToken(mUserId); } } }); rideDriverComplete = sharedPreference.getDriverRidercompleate(getActivity()); String rideId = MyApplication.RideId; if (rideDriverComplete == null && rideId != null) { ValidateRidecomplet(mUserId, rideId); } if (MyApplication.RateyourRide == true) { btnsubmit.setVisibility(View.GONE); mcommentbox.setVisibility(View.GONE); } if (rideDriverComplete != null) { if (rideDriverComplete.getPickupaddress() != null && rideDriverComplete.getPickupaddress() != " " && rideDriverComplete.getDestinationaddress() != null && rideDriverComplete.getDestinationaddress() != " ") { Text_tripcomplete_pickuplocation.setText(rideDriverComplete.getPickupaddress()); Text_tripcomplete_dropoff_location.setText(rideDriverComplete.getDestinationaddress()); } try { Picasso.with(getActivity()).load(MyPreferences.getActiveInstance(getActivity()).getImageUrl()) .error(R.mipmap.avtar).placeholder(R.mipmap.avtar).into(icon); } catch (Exception e) { e.printStackTrace(); } mname.setText(rideDriverComplete.driverNameride); mlicenceplate.setText(rideDriverComplete.licenseId); mtaname.setText(rideDriverComplete.vehicle); Text_tripcharged .setText("$" + rideDriverComplete.getTotalfare() + " HAS BEEN CHARGED TO YOUR CREDIT CARD"); btnsubmit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String totalStars = "Total Stars:: " + ratingBar.getNumStars(); String rating = "Rating :: " + ratingBar.getRating(); String tip = ""; if (rideDriverComplete != null) { String driverid = rideDriverComplete.getDriverIdride(); String rideId = rideDriverComplete.getRideId(); if (tipValue != null) tip = tipValue.getText().toString(); String comment = mcommentbox.getText().toString(); if (driverid != null && rideId != null && totalStars != null && tip != null) { validateRideRating(mUserId, driverid, rideId, totalStars, tip, comment); } } } }); } 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; }