List of usage examples for android.view KeyEvent ACTION_UP
int ACTION_UP
To view the source code for android.view KeyEvent ACTION_UP.
Click Source Link
From source file:com.hellofyc.base.app.activity.BaseActivity.java
@Override public boolean dispatchKeyEvent(@NonNull KeyEvent event) { final int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.KEYCODE_BACK) { if (mPressTwoExit && mIsHighPriority) { final int action = event.getAction(); if (action == KeyEvent.ACTION_UP) { pressBackToExit();/*ww w .j av a 2s .c o m*/ return true; } } } return super.dispatchKeyEvent(event); }
From source file:org.puder.trs80.EmulatorActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (gameController.dispatchKeyEvent(event)) { return true; }/* w ww . ja v a 2 s .co m*/ boolean consumed = false; if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { consumed = keyboardManager.keyDown(event); } if (event.getAction() == KeyEvent.ACTION_UP && event.getRepeatCount() == 0) { consumed = keyboardManager.keyUp(event); } return consumed || super.dispatchKeyEvent(event); }
From source file:es.farfuteam.vncpp.controller.CanvasActivity.java
/** * @param event The event//from w w w . ja v a 2s . com * @brief Captures the keys of the keyboard * @details Capture the keys of the keyboard. If the character has to be pressed with a combination of the shift key * and other key then adds 100 to the modKeyCount attribute to applies the offset */ @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN || event.getAction() == KeyEvent.ACTION_UP || event.getAction() == KeyEvent.ACTION_MULTIPLE) { int keyunicode = event.getUnicodeChar(event.getMetaState()); char character = (char) keyunicode; int key = event.getKeyCode(); if (key == 59) { if (modKeyCount == 0) { modKeyCount = 100; } else { modKeyCount = 0; } } else if (key >= 7) { boolean down = event.getAction() == KeyEvent.ACTION_DOWN; vnc.sendKey(modKeyCount + key, down); } Log.e(DEBUG_TAG, String.valueOf(event.getKeyCode())); } return super.dispatchKeyEvent(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 ww w. j a va 2 s .c om*/ 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.example.android.home.Home.java
@SuppressLint({ "NewApi", "NewApi" }) @Override/*from w w w . j a va2 s .com*/ 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.actionbarsherlock.internal.ActionBarSherlockCompat.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (DEBUG)//from ww w.j a v a 2 s . c om 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; }
From source file:org.runnerup.export.SyncManager.java
private void askUsernamePassword(final Synchronizer sync, boolean showPassword) { AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setTitle(sync.getName());/*from w w w. ja v a 2s .c o m*/ final View view = View.inflate(mActivity, R.layout.userpass, null); final CheckBox cb = (CheckBox) view.findViewById(R.id.showpass); final TextView tv1 = (TextView) view.findViewById(R.id.username); final TextView tv2 = (TextView) view.findViewById(R.id.password_input); final TextView tvAuthNotice = (TextView) view.findViewById(R.id.textViewAuthNotice); String authConfigStr = sync.getAuthConfig(); final JSONObject authConfig = newObj(authConfigStr); String username = authConfig.optString("username", ""); String password = authConfig.optString("password", ""); tv1.setText(username); tv2.setText(password); cb.setChecked(showPassword); tv2.setInputType(InputType.TYPE_CLASS_TEXT | (showPassword ? 0 : InputType.TYPE_TEXT_VARIATION_PASSWORD)); cb.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { tv2.setInputType( InputType.TYPE_CLASS_TEXT | (isChecked ? 0 : InputType.TYPE_TEXT_VARIATION_PASSWORD)); } }); if (sync.getAuthNotice() != null) { tvAuthNotice.setVisibility(View.VISIBLE); tvAuthNotice.setText(sync.getAuthNotice()); } else { tvAuthNotice.setVisibility(View.GONE); } // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout builder.setView(view); builder.setPositiveButton(getResources().getString(R.string.OK), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { authConfig.put("username", tv1.getText()); authConfig.put("password", tv2.getText()); } catch (JSONException e) { e.printStackTrace(); } testUserPass(sync, authConfig, cb.isChecked()); } }); builder.setNeutralButton("Skip", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handleAuthComplete(sync, Status.SKIP); } }); builder.setNegativeButton(getResources().getString(R.string.Cancel), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handleAuthComplete(sync, Status.SKIP); } }); builder.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) { if (i == KeyEvent.KEYCODE_BACK && keyEvent.getAction() == KeyEvent.ACTION_UP) { handleAuthComplete(sync, Status.CANCEL); } return false; } }); final AlertDialog dialog = builder.create(); dialog.show(); }
From source file:com.android.tv.settings.accessories.AddAccessoryActivity.java
private void sendKeyEvent(int keyCode, boolean down) { InputManager iMgr = (InputManager) getSystemService(INPUT_SERVICE); if (iMgr != null) { long time = SystemClock.uptimeMillis(); KeyEvent evt = new KeyEvent(time, time, down ? KeyEvent.ACTION_DOWN : KeyEvent.ACTION_UP, keyCode, 0); iMgr.injectInputEvent(evt, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); }/*from w ww . ja va2 s. co m*/ }
From source file:android.support.v17.leanback.app.PlaybackSupportFragment.java
private boolean onInterceptInputEvent(InputEvent event) { final boolean controlsHidden = !mControlVisible; if (DEBUG)//from ww w .j a va2s. co m Log.v(TAG, "onInterceptInputEvent hidden " + controlsHidden + " " + event); boolean consumeEvent = false; int keyCode = KeyEvent.KEYCODE_UNKNOWN; int keyAction = 0; if (event instanceof KeyEvent) { keyCode = ((KeyEvent) event).getKeyCode(); keyAction = ((KeyEvent) event).getAction(); if (mInputEventHandler != null) { consumeEvent = mInputEventHandler.onKey(getView(), keyCode, (KeyEvent) event); } } switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: // Event may be consumed; regardless, if controls are hidden then these keys will // bring up the controls. if (controlsHidden) { consumeEvent = true; } if (keyAction == KeyEvent.ACTION_DOWN) { tickle(); } break; case KeyEvent.KEYCODE_BACK: case KeyEvent.KEYCODE_ESCAPE: if (mInSeek) { // when in seek, the SeekUi will handle the BACK. return false; } // If controls are not hidden, back will be consumed to fade // them out (even if the key was consumed by the handler). if (!controlsHidden) { consumeEvent = true; if (((KeyEvent) event).getAction() == KeyEvent.ACTION_UP) { hideControlsOverlay(true); } } break; default: if (consumeEvent) { if (keyAction == KeyEvent.ACTION_DOWN) { tickle(); } } } return consumeEvent; }
From source file:org.catrobat.catroid.ui.ScriptActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { //Dismiss ActionMode without effecting checked items FormulaEditorDataFragment formulaEditorDataFragment = (FormulaEditorDataFragment) getSupportFragmentManager() .findFragmentByTag(FormulaEditorDataFragment.USER_DATA_TAG); if (formulaEditorDataFragment != null && formulaEditorDataFragment.isVisible()) { ListAdapter adapter = formulaEditorDataFragment.getListAdapter(); ((ScriptActivityAdapterInterface) adapter).clearCheckedItems(); return super.dispatchKeyEvent(event); }// w w w . ja v a 2 s . c om if (currentFragment != null && currentFragment.getActionModeActive() && event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { ListAdapter adapter = null; if (currentFragment instanceof ScriptFragment) { adapter = ((ScriptFragment) currentFragment).getAdapter(); } else { adapter = currentFragment.getListAdapter(); } ((ScriptActivityAdapterInterface) adapter).clearCheckedItems(); } return super.dispatchKeyEvent(event); }