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.lchtime.safetyexpress.ui.chat.hx.activity.ContactActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { //exit(); finish();// www . j av a 2s . co m return true; } if (keyCode == KeyEvent.KEYCODE_BACK) { //moveTaskToBack(false); return true; } return super.onKeyDown(keyCode, event); }
From source file:com.ichi2.anki.FilteredDeckOptions.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { Timber.i("DeckOptions - onBackPressed()"); closeDeckOptions();/*from w ww .j av a2s . co m*/ return true; } return super.onKeyDown(keyCode, event); }
From source file:com.example.android.home.Home.java
@SuppressLint({ "NewApi", "NewApi" }) @Override/*from w w w . j a v a 2 s . c o m*/ public boolean dispatchKeyEvent(KeyEvent event) { Toast.makeText(getApplicationContext(), "dispatchKeyEvent", Toast.LENGTH_SHORT).show(); if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: mBackDown = true; Toast.makeText(getApplicationContext(), "BACK 1", Toast.LENGTH_SHORT).show(); myPager.setCurrentItem(HomePagerAdapter.SCREEN_CENTER); return true; case KeyEvent.KEYCODE_HOME: mHomeDown = true; //myPager.setCurrentItem(HomePagerAdapter.SCREEN_CENTER); //myPager.invalidate(); Toast.makeText(getApplicationContext(), "HOME", Toast.LENGTH_SHORT).show(); Log.e("PUSH", "Home 2"); return true; } } else if (event.getAction() == KeyEvent.ACTION_UP) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: if (!event.isCanceled()) { // Do BACK behavior. Toast.makeText(getApplicationContext(), "BACK 2", Toast.LENGTH_SHORT).show(); } mBackDown = true; return true; case KeyEvent.KEYCODE_HOME: Toast.makeText(getApplicationContext(), "HOME", Toast.LENGTH_SHORT).show(); Log.e("PUSH", "Home 2"); if (!event.isCanceled()) { // Do HOME behavior. //myPager.setCurrentItem(HomePagerAdapter.SCREEN_CENTER); Toast.makeText(getApplicationContext(), "HOME", Toast.LENGTH_SHORT).show(); Log.e("PUSH", "Home 2"); } mHomeDown = true; return true; } } return super.dispatchKeyEvent(event); }
From source file:com.njlabs.amrita.aid.gpms.ui.GpmsActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitGpms();//from w w w.ja v a 2s. c o m return true; } return super.onKeyDown(keyCode, event); }
From source file:com.speedtong.example.ui.chatting.ChattingActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { LogUtil.d(TAG, "keycode back , chatfooter mode: " + mChattingFooter.getMode()); if (!mChattingFooter.isButtomPanelNotVisibility()) { hideBottom();/*from ww w . jav a 2s.c o m*/ return true; } } return super.onKeyDown(keyCode, event); }
From source file:com.hitesh_sahu.retailapp.view.fragment.ProductDetailsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.frag_product_detail, container, false); scrollView = (ScrollView) rootView;//from w w w . j av a 2s .co m mToolbar = (Toolbar) rootView.findViewById(R.id.htab_toolbar); if (mToolbar != null) { ((ECartHomeActivity) getActivity()).setSupportActionBar(mToolbar); } if (mToolbar != null) { ((ECartHomeActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolbar.setNavigationIcon(R.drawable.ic_drawer); } mToolbar.setTitleTextColor(Color.WHITE); mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((ECartHomeActivity) getActivity()).getmDrawerLayout().openDrawer(GravityCompat.START); } }); ((ECartHomeActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); similarProductsPager = (ClickableViewPager) rootView.findViewById(R.id.similar_products_pager); topSellingPager = (ClickableViewPager) rootView.findViewById(R.id.top_selleing_pager); itemSellPrice = ((TextView) rootView.findViewById(R.id.category_discount)); quanitity = ((TextView) rootView.findViewById(R.id.iteam_amount)); itemName = ((TextView) rootView.findViewById(R.id.product_name)); itemdescription = ((TextView) rootView.findViewById(R.id.product_description)); itemImage = (ImageView) rootView.findViewById(R.id.product_image); fillProductData(); TextView addItem = (TextView) rootView.findViewById(R.id.add_item); FocusPin.with(getContext()).into(addItem).scrollView(scrollView).create(); addItem.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { FocusPin.with(getContext()).destroy(); /*if (null != mFrameLayout && mFrameLayout.isActivated()) { mWindowManager.removeViewImmediate(mFrameLayout); mFrameLayout.setActivated(false); ViewTreeObserver observer = scrollView.getViewTreeObserver(); observer.removeOnScrollChangedListener(onScrollChangedListener); }*/ if (isFromCart) { //Update Quantity on shopping List CenterRepository.getCenterRepository().getListOfProductsInShoppingList().get(productListNumber) .setQuantity(String.valueOf( Integer.valueOf(CenterRepository.getCenterRepository() .getListOfProductsInShoppingList().get(productListNumber).getQuantity()) + 1)); //Update Ui quanitity.setText(CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .get(productListNumber).getQuantity()); Utils.vibrate(getActivity()); //Update checkout amount on screen ((ECartHomeActivity) getActivity()).updateCheckOutAmount( BigDecimal.valueOf(Long.valueOf(CenterRepository.getCenterRepository() .getListOfProductsInShoppingList().get(productListNumber).getSellMRP())), true); } else { // current object Product tempObj = CenterRepository.getCenterRepository().getMapOfProductsInCategory() .get(subcategoryKey).get(productListNumber); // if current object is lready in shopping list if (CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .contains(tempObj)) { // get position of current item in shopping list int indexOfTempInShopingList = CenterRepository.getCenterRepository() .getListOfProductsInShoppingList().indexOf(tempObj); // increase quantity of current item in shopping // list if (Integer.parseInt(tempObj.getQuantity()) == 0) { ((ECartHomeActivity) getContext()).updateItemCount(true); } // update quanity in shopping list CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .get(indexOfTempInShopingList) .setQuantity(String.valueOf(Integer.valueOf(tempObj.getQuantity()) + 1)); // update checkout amount ((ECartHomeActivity) getContext()) .updateCheckOutAmount( BigDecimal.valueOf(Long.valueOf( CenterRepository.getCenterRepository().getMapOfProductsInCategory() .get(subcategoryKey).get(productListNumber).getSellMRP())), true); // update current item quanitity quanitity.setText(tempObj.getQuantity()); } else { ((ECartHomeActivity) getContext()).updateItemCount(true); tempObj.setQuantity(String.valueOf(1)); quanitity.setText(tempObj.getQuantity()); CenterRepository.getCenterRepository().getListOfProductsInShoppingList().add(tempObj); ((ECartHomeActivity) getContext()).getCheckOutView(); ((ECartHomeActivity) getContext()) .updateCheckOutAmount( BigDecimal.valueOf(Long.valueOf( CenterRepository.getCenterRepository().getMapOfProductsInCategory() .get(subcategoryKey).get(productListNumber).getSellMRP())), true); } Utils.vibrate(getContext()); } } }); rootView.findViewById(R.id.remove_item).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (isFromCart) { if (Integer.valueOf(CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .get(productListNumber).getQuantity()) > 2) { CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .get(productListNumber).setQuantity(String.valueOf( Integer.valueOf(CenterRepository.getCenterRepository() .getListOfProductsInShoppingList().get(productListNumber) .getQuantity()) - 1)); quanitity.setText(CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .get(productListNumber).getQuantity()); ((ECartHomeActivity) getActivity()).updateCheckOutAmount( BigDecimal.valueOf(Long.valueOf(CenterRepository.getCenterRepository() .getListOfProductsInShoppingList().get(productListNumber).getSellMRP())), false); Utils.vibrate(getActivity()); } else if (Integer.valueOf(CenterRepository.getCenterRepository() .getListOfProductsInShoppingList().get(productListNumber).getQuantity()) == 1) { ((ECartHomeActivity) getActivity()).updateItemCount(false); ((ECartHomeActivity) getActivity()).updateCheckOutAmount( BigDecimal.valueOf(Long.valueOf(CenterRepository.getCenterRepository() .getListOfProductsInShoppingList().get(productListNumber).getSellMRP())), false); CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .remove(productListNumber); if (Integer.valueOf(((ECartHomeActivity) getActivity()).getItemCount()) == 0) { MyCartFragment.updateMyCartFragment(false); } Utils.vibrate(getActivity()); } } else { Product tempObj = CenterRepository.getCenterRepository().getMapOfProductsInCategory() .get(subcategoryKey).get(productListNumber); if (CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .contains(tempObj)) { int indexOfTempInShopingList = CenterRepository.getCenterRepository() .getListOfProductsInShoppingList().indexOf(tempObj); if (Integer.valueOf(tempObj.getQuantity()) != 0) { CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .get(indexOfTempInShopingList) .setQuantity(String.valueOf(Integer.valueOf(tempObj.getQuantity()) - 1)); ((ECartHomeActivity) getContext()).updateCheckOutAmount( BigDecimal.valueOf(Long.valueOf( CenterRepository.getCenterRepository().getMapOfProductsInCategory() .get(subcategoryKey).get(productListNumber).getSellMRP())), false); quanitity.setText(CenterRepository.getCenterRepository() .getListOfProductsInShoppingList().get(indexOfTempInShopingList).getQuantity()); Utils.vibrate(getContext()); if (Integer.valueOf( CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .get(indexOfTempInShopingList).getQuantity()) == 0) { CenterRepository.getCenterRepository().getListOfProductsInShoppingList() .remove(indexOfTempInShopingList); ((ECartHomeActivity) getContext()).updateItemCount(false); } } } else { } } } }); 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) { if (isFromCart) { Utils.switchContent(R.id.frag_container, Utils.SHOPPING_LIST_TAG, ((ECartHomeActivity) (getActivity())), AnimationType.SLIDE_UP); } else { Utils.switchContent(R.id.frag_container, Utils.PRODUCT_OVERVIEW_FRAGMENT_TAG, ((ECartHomeActivity) (getActivity())), AnimationType.SLIDE_RIGHT); } } return true; } }); if (isFromCart) { similarProductsPager.setVisibility(View.GONE); topSellingPager.setVisibility(View.GONE); } else { showRecomondation(); } return rootView; }
From source file:com.lepin.activity.MyLoveCarActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (from_info.equals("from_perinfo")) { this.finish(); } else {/* w ww. j a v a 2 s. co m*/ if (isEidting && !isPublishAddCar) { isEidting = false; setEnable(isEidting); setVisible(isEidting); loadCarInfo(); } else { this.finish(); } } } return false; }
From source file:in.shick.diode.threads.ThreadsListActivity.java
/** * http://stackoverflow.com/questions/2257963/android-how-to-show-dialog-to-confirm-user-wishes-to-exit-activity */// w w w . j a va 2 s .co m @Override public boolean onKeyDown(int keyCode, KeyEvent event) { //Handle the back button if (mSettings.isConfirmQuitOrLogout() && keyCode == KeyEvent.KEYCODE_BACK && isTaskRoot()) { //Ask the user if they want to quit new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme())) .setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.quit) .setMessage(R.string.really_quit) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //Stop the activity finish(); } }).setNegativeButton(R.string.no, null).show(); return true; } //if the search button is pressed else if (keyCode == KeyEvent.KEYCODE_SEARCH) { //start activity startActivityForResult(new Intent(this, RedditSearchActivity.class), Constants.ACTIVITY_SEARCH_REDDIT); return true; } else { return super.onKeyDown(keyCode, event); } }
From source file:com.ichi2.anki.CramDeckOptions.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { Log.i(AnkiDroidApp.TAG, "DeckOptions - onBackPressed()"); finish();/*from w w w. j av a 2s. c om*/ if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.FADE); } return true; } return super.onKeyDown(keyCode, event); }
From source file:com.actionbarsherlock.internal.ActionBarSherlockCompat.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (DEBUG)//from w w w .java2s .c o m Log.d(TAG, "[dispatchKeyEvent] event: " + event); final int keyCode = event.getKeyCode(); // Not handled by the view hierarchy, does the action bar want it // to cancel out of something special? if (keyCode == KeyEvent.KEYCODE_BACK) { final int action = event.getAction(); // Back cancels action modes first. if (mActionMode != null) { if (action == KeyEvent.ACTION_UP) { mActionMode.finish(); } if (DEBUG) Log.d(TAG, "[dispatchKeyEvent] returning true"); return true; } // Next collapse any expanded action views. if (wActionBar != null && wActionBar.hasExpandedActionView()) { if (action == KeyEvent.ACTION_UP) { wActionBar.collapseActionView(); } if (DEBUG) Log.d(TAG, "[dispatchKeyEvent] returning true"); return true; } } boolean result = false; if (keyCode == KeyEvent.KEYCODE_MENU && isReservingOverflow()) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.isLongPress()) { mMenuKeyIsLongPress = true; } else if (event.getAction() == KeyEvent.ACTION_UP) { if (!mMenuKeyIsLongPress) { if (mActionMode == null && wActionBar != null) { if (wActionBar.isOverflowMenuShowing()) { wActionBar.hideOverflowMenu(); } else { wActionBar.showOverflowMenu(); } } result = true; } mMenuKeyIsLongPress = false; } } if (DEBUG) Log.d(TAG, "[dispatchKeyEvent] returning " + result); return result; }