List of usage examples for android.view KeyEvent getAction
public final int getAction()
From source file:com.gigaset.home.Home.java
/** * Catch keys to avoid back through HOME in Back Stack */// w w w . j av a 2s . co m @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: return true; case KeyEvent.KEYCODE_HOME: return true; } } else if (event.getAction() == KeyEvent.ACTION_UP) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: if (!event.isCanceled()) { // Do BACK behavior. } return true; case KeyEvent.KEYCODE_HOME: if (!event.isCanceled()) { // Do HOME behavior. myPager.setCurrentItem(HomePagerAdapter.SCREEN_CENTER); } return true; } } return super.dispatchKeyEvent(event); }
From source file:io.github.hidroh.materialistic.KeyDelegate.java
/** * Calls from {@link Activity#onKeyDown(int, KeyEvent)} to delegate * @param keyCode event key code/* w ww. ja v a2s . com*/ * @param event key event * @return true if is intercepted as navigation, false otherwise */ public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { return mBackInterceptor != null && mBackInterceptor.onBackPressed(); } if (!mEnabled) { return false; } if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { event.startTracking(); return true; } return false; }
From source file:org.deviceconnect.android.localoauth.fragment.ConfirmAuthFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { Intent intent = getActivity().getIntent(); if (intent == null) { getActivity().finish();/* w w w .ja v a 2 s . c om*/ return null; } mThreadId = intent.getLongExtra(ConfirmAuthActivity.EXTRA_THREAD_ID, -1); if (mThreadId == -1) { getActivity().finish(); return null; } String applicationName = intent.getStringExtra(ConfirmAuthActivity.EXTRA_APPLICATION_NAME); String packageName = intent.getStringExtra(ConfirmAuthActivity.EXTRA_PACKAGE_NAME); String keyword = intent.getStringExtra(ConfirmAuthActivity.EXTRA_KEYWORD); String[] displayScopes = intent.getStringArrayExtra(ConfirmAuthActivity.EXTRA_DISPLAY_SCOPES); String expirePeriod = toStringExpiredPeriod(); boolean isForPlugin = intent.getBooleanExtra(ConfirmAuthActivity.EXTRA_IS_FOR_DEVICEPLUGIN, true); boolean isAutoFlag = intent.getBooleanExtra(ConfirmAuthActivity.EXTRA_AUTO_FLAG, false); long requestTime = intent.getLongExtra(ConfirmAuthActivity.EXTRA_REQUEST_TIME, System.currentTimeMillis()); long timeout = DEFAULT_TIMEOUT - (System.currentTimeMillis() - requestTime); int layoutId; if (isForPlugin) { layoutId = R.layout.confirm_auth_activity_plugin; } else { layoutId = R.layout.confirm_auth_activity_manager; } View view = inflater.inflate(layoutId, container, false); view.setFocusableInTouchMode(true); view.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(final View v, final int keyCode, final KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { notApprovalProc(); return true; } return false; } }); // ? TextView textViewExpirePeriod = (TextView) view.findViewById(R.id.textViewExpirePeriod); textViewExpirePeriod.setText(expirePeriod); // ?? TextView textViewApplicationName = (TextView) view.findViewById(R.id.textViewAccessToken); textViewApplicationName.setText(applicationName); // ListView listViewScopes = (ListView) view.findViewById(R.id.listViewScopes); listViewScopes.setAdapter(new ArrayAdapter<>(getActivity(), R.layout.confirm_auth_scopes_list_item, R.id.textViewScope, displayScopes)); // ? Button buttonApproval = (Button) view.findViewById(R.id.buttonApproval); buttonApproval.setOnClickListener(mOnButtonApprovalClickListener); // ? Button buttonReject = (Button) view.findViewById(R.id.buttonReject); buttonReject.setOnClickListener(mOnButtonApprovalClickListener); if (!isForPlugin) { // ?(=?)??? TextView textViewPackageName = (TextView) view.findViewById(R.id.textPackageName); textViewPackageName.setText(packageName); // TextView textViewKeyword = (TextView) view.findViewById(R.id.textKeyword); textViewKeyword.setText(keyword); } if (timeout > 0) { startTimeoutTimer(timeout); } else { // ????????Activity? getActivity().finish(); } if (isAutoFlag) { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { approvalProc(); } }); } return view; }
From source file:com.jxlc.tajiproject.ui.MainActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() != KeyEvent.ACTION_UP) { finish();/* w w w. j ava2 s. c o m*/ return true; } if (event.getAction() == KeyEvent.ACTION_MULTIPLE) { return mUnityPlayer.injectEvent(event); } return super.dispatchKeyEvent(event); }
From source file:fr.ippon.android.opendata.android.AbstractParkingListFragment.java
private void configureSearchField(RelativeLayout r) { final AbstractParkingListFragment loaderCallBack = this; searchField = (EditText) r.findViewById(R.id.searchField); if (TextUtils.isEmpty(searchField.getText())) searchField.setText(searchHint); searchField.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // hide the keyboard InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(searchField.getWindowToken(), 0); // Perform action on key press boolean okSearch = !TextUtils.isEmpty(searchField.getText()) && !searchHint.equals(searchField.getText()); queryText = okSearch ? searchField.getText().toString() : null; Log.d(TAG, "query: " + queryText); hasSearched = true;//from w ww . ja v a2 s. c o m getLoaderManager().restartLoader(0, null, loaderCallBack); if (queryText == null) { searchField.setText(searchHint); } return true; } return false; } }); // afichage d'une croix dans l'edit text pour effacer le texte saisie final Drawable x = getResources().getDrawable(R.drawable.ic_cancel); x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight()); searchField.setCompoundDrawables(null, null, x, null); searchField.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && searchHint.equals(searchField.getText().toString())) { searchField.setText(""); } if (searchField.getCompoundDrawables()[2] == null) { // cross is not being shown so no need to handle return false; } if (event.getAction() != MotionEvent.ACTION_DOWN) { // only respond to the down type return false; } if (event.getX() > searchField.getMeasuredWidth() - searchField.getPaddingRight() - x.getIntrinsicWidth()) { searchField.setText(""); return true; } else { return false; } } }); }
From source file:com.actionbarsherlock.internal.view.menu.MenuPopupHelper.java
public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_MENU) { dismiss();/*from w w w. j av a 2s .co m*/ return true; } return false; }
From source file:org.interactiverobotics.headset_launcher.MediaButtonMonitorService.java
@Override public void onCreate() { Log.d(TAG, "Create"); // ? /*from www . ja v a 2s. c o m*/ mMediaButtonReceiver = new ComponentName(this, MediaButtonReceiver.class); // , ? API 18+ // // final Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); // // mediaButtonIntent.setComponent(mMediaButtonReceiver); // // mPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0); mMediaSession = new MediaSessionCompat(this, TAG, mMediaButtonReceiver, /* pendingIntent */ null); mMediaSession.setCallback(new MediaSessionCompat.Callback() { @Override public boolean onMediaButtonEvent(Intent mediaButtonEvent) { if (Intent.ACTION_MEDIA_BUTTON.equals(mediaButtonEvent.getAction())) { final KeyEvent keyEvent = (KeyEvent) mediaButtonEvent .getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (KeyEvent.KEYCODE_HEADSETHOOK == keyEvent.getKeyCode()) { if (KeyEvent.ACTION_DOWN == keyEvent.getAction()) { Log.d(TAG, "Media button down!"); // ? startService(new Intent(MediaButtonMonitorService.this, LauncherService.class)); } } else { Log.e(TAG, "Unknown keycode: " + keyEvent.getKeyCode()); } } else { Log.e(TAG, "Unknown intent: " + mediaButtonEvent.getAction()); } return true; } }); mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS); mMediaSession.setActive(true); }
From source file:org.tanrabad.team.ChatFragment.java
private void initUiComponents(View rootView) { mListView = (ListView) rootView.findViewById(R.id.list); turnOffListViewDecoration(mListView); mListView.setAdapter(mAdapter);//from ww w. ja v a2s. c o m mBtnChannel = (ImageButton) rootView.findViewById(R.id.btn_channel); mBtnSend = (Button) rootView.findViewById(R.id.btn_send); mBtnUpload = (ImageButton) rootView.findViewById(R.id.btn_upload); mProgressBtnUpload = (ProgressBar) rootView.findViewById(R.id.progress_btn_upload); mEtxtMessage = (EditText) rootView.findViewById(R.id.etxt_message); mBtnSend.setEnabled(false); mBtnSend.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { send(); } }); mBtnChannel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mHandler != null) { mHandler.onChannelListClicked(); } } }); mBtnUpload.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"), REQUEST_PICK_IMAGE); } }); mEtxtMessage.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) { if (event.getAction() == KeyEvent.ACTION_DOWN) { send(); } return true; // Do not hide keyboard. } return false; } }); mEtxtMessage.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); mEtxtMessage.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { mBtnSend.setEnabled(s.length() > 0); } }); mListView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { SoftKeyboard.hide(getActivity()); return false; } }); mListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState == SCROLL_STATE_IDLE) { if (view.getFirstVisiblePosition() == 0 && view.getChildCount() > 0 && view.getChildAt(0).getTop() == 0) { resultHandler = new MessageListQuery.MessageListQueryResult() { @Override public void onResult(List<MessageModel> messageModels) { for (MessageModel model : messageModels) { mAdapter.addMessageModel(model); } mAdapter.notifyDataSetChanged(); mListView.setSelection(messageModels.size()); } @Override public void onError(Exception e) { } }; SendBird.queryMessageList(SendBird.getChannelUrl()).prev(mAdapter.getMinMessageTimestamp(), 30, resultHandler); } } } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }); }
From source file:eu.geekgasm.kintrol.DeviceControlActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { int action = event.getAction(); int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_DOWN) { kontrollerThread.increaseVolume(); }/*from w w w . j a va2s .c o m*/ return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { kontrollerThread.decreaseVolume(); } return true; default: return super.dispatchKeyEvent(event); } }
From source file:hku.fyp14017.blencode.ui.BackPackActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { //Dismiss ActionMode without effecting checked items if (currentFragment != null && currentFragment.getActionModeActive() && event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { ListAdapter adapter = null;//from w w w . j a v a 2 s . co m if (currentFragment instanceof BackPackScriptFragment) { adapter = ((BackPackScriptFragment) currentFragment).getAdapter(); } else { adapter = currentFragment.getListAdapter(); } ((ScriptActivityAdapterInterface) adapter).clearCheckedItems(); } return super.dispatchKeyEvent(event); }