List of usage examples for android.view KeyEvent KEYCODE_BACK
int KEYCODE_BACK
To view the source code for android.view KeyEvent KEYCODE_BACK.
Click Source Link
From source file:com.app.blockydemo.ui.ScriptActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { FragmentManager fragmentManager = getSupportFragmentManager(); for (String tag : FormulaEditorListFragment.TAGS) { FormulaEditorListFragment fragment = (FormulaEditorListFragment) fragmentManager.findFragmentByTag(tag); if (fragment != null) { if (fragment.isVisible()) { return fragment.onKey(null, keyCode, event); }// w w w . ja va 2s. c o m } } FormulaEditorVariableListFragment formulaEditorVariableListFragment = (FormulaEditorVariableListFragment) getSupportFragmentManager() .findFragmentByTag(FormulaEditorVariableListFragment.VARIABLE_TAG); if (formulaEditorVariableListFragment != null) { if (formulaEditorVariableListFragment.isVisible()) { return formulaEditorVariableListFragment.onKey(null, keyCode, event); } } FormulaEditorFragment formulaEditor = (FormulaEditorFragment) getSupportFragmentManager() .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG); if (formulaEditor != null) { if (formulaEditor.isVisible()) { scriptFragment.getAdapter().updateProjectBrickList(); return formulaEditor.onKey(null, keyCode, event); } } int backStackEntryCount = fragmentManager.getBackStackEntryCount(); for (int i = backStackEntryCount; i > 0; --i) { String backStackEntryName = fragmentManager.getBackStackEntryAt(i - 1).getName(); if (backStackEntryName != null) { fragmentManager.popBackStack(); } else { break; } } if (keyCode == KeyEvent.KEYCODE_BACK) { if (currentFragmentPosition == FRAGMENT_SCRIPTS) { DragAndDropListView listView = scriptFragment.getListView(); if (listView.isCurrentlyDragging()) { listView.resetDraggingScreen(); BrickAdapter adapter = scriptFragment.getAdapter(); adapter.removeDraggedBrick(); return true; } } } return super.onKeyDown(keyCode, event); }
From source file:com.hyechon.etrackermv.FaceTrackerActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) { mWebView.goBack();/* ww w. j ava 2s . c om*/ return true; } 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 .ja v a 2s .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; }
From source file:br.org.funcate.dynamicforms.FormActivity.java
public boolean onKeyDown(int keyCode, KeyEvent event) { // force to exit through the exit button, in order to avoid losing info switch (keyCode) { case KeyEvent.KEYCODE_BACK: finish();/*from www . j a va2 s.com*/ return true; } return super.onKeyDown(keyCode, event); }
From source file:com.cloudant.todo.TodoActivity.java
public Dialog createProgressDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); final View v = this.getLayoutInflater().inflate(R.layout.dialog_loading, null); DialogInterface.OnClickListener negativeClick = new DialogInterface.OnClickListener() { @Override//from www . ja v a 2 s .c o m public void onClick(DialogInterface dialog, int which) { stopReplication(); } }; DialogInterface.OnKeyListener keyListener = new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { Toast.makeText(getApplicationContext(), R.string.replication_running, Toast.LENGTH_LONG).show(); return true; } return false; } }; builder.setView(v).setNegativeButton("Stop", negativeClick).setOnKeyListener(keyListener); return builder.create(); }
From source file:com.example.android.LevelChooserActivity.java
/** * onKeyDown overrides onKeyDown and allows code to be executed when the * back button is pushed in the simulator / on the mobile phone Since * pushing "back" won't necessarily call the destroy method as far as I * understand it.//from ww w. j ava2s . c o m * * @param keyCode * : code of the key pressed * @param event * : the event for the key pressed */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == zero) { //This code cannot be in onStop in LevelChooserActivity because //it also kills the ticking noise as Game begins //cancel any noises and abandon focus SoundPlayer.stop(); if (focusHelper != null) { focusHelper.abandonFocus(); } // continue backwards (kills current activity calling onDestroy) finish(); return true; } return super.onKeyDown(keyCode, event); }
From source file:com.mercandalli.android.apps.files.file.image.FileImageActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { supportFinishAfterTransition();/* www . ja v a2 s . c om*/ } return super.onKeyDown(keyCode, event); }
From source file:net.evecom.androidecssp.activity.event.ETypeListActivity.java
/** * //from w w w .j a va 2 s . c om * * * @author Stark Zhou * @created 2015-12-30 2:23:38 * @param view */ public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK)) { Intent intent = new Intent(); setResult(4, intent); finish(); return true; } return super.onKeyDown(keyCode, event); }
From source file:com.muzima.view.forms.FormWebViewActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { AlertDialog.Builder builder = new AlertDialog.Builder(FormWebViewActivity.this); builder.setCancelable(true).setIcon(getResources().getDrawable(R.drawable.ic_warning)) .setTitle(getResources().getString(R.string.caution)) .setMessage(getResources().getString(R.string.exit_form_message)) .setPositiveButton("Yes", positiveClickListener()).setNegativeButton("No", null).create() .show();//from w ww. ja v a2 s.c om return false; } return super.onKeyDown(keyCode, event); }
From source file:ch.teamuit.android.soundplusplus.LibraryActivity.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: Limiter limiter = mPagerAdapter.getCurrentLimiter(); if (mSlidingView.isHidden() == false) { mSlidingView.hideSlide();// ww w . j av a 2 s . c om break; } if (mBottomBarControls.showSearch(false)) { break; } if (limiter != null) { int pos = -1; switch (limiter.type) { case MediaUtils.TYPE_ALBUM: setLimiter(MediaUtils.TYPE_ARTIST, limiter.data.toString()); pos = mPagerAdapter.mAlbumsPosition; break; case MediaUtils.TYPE_ARTIST: mPagerAdapter.clearLimiter(MediaUtils.TYPE_ARTIST); pos = mPagerAdapter.mArtistsPosition; break; case MediaUtils.TYPE_GENRE: mPagerAdapter.clearLimiter(MediaUtils.TYPE_GENRE); pos = mPagerAdapter.mGenresPosition; break; case MediaUtils.TYPE_FILE: if (limiter.names.length > 1) { File parentFile = ((File) limiter.data).getParentFile(); mPagerAdapter.setLimiter(FileSystemAdapter.buildLimiter(parentFile)); } else { mPagerAdapter.clearLimiter(MediaUtils.TYPE_FILE); } break; } if (pos == -1) { updateLimiterViews(); } else { mViewPager.setCurrentItem(pos); } } else { finish(); } break; case KeyEvent.KEYCODE_MENU: // We intercept these to avoid showing the activity-default menu mBottomBarControls.openMenu(); break; default: return false; } return true; }