List of usage examples for android.view KeyEvent getKeyCode
public final int getKeyCode()
From source file:butter.droid.tv.fragments.TVPlaybackOverlayFragment.java
@Override public boolean handleInputEvent(@NonNull InputEvent event) { if (event instanceof KeyEvent) { KeyEvent keyEvent = (KeyEvent) event; if (keyEvent.getKeyCode() != KeyEvent.KEYCODE_DPAD_CENTER) return false; if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) { if (mFastForwardAction != null && mSelectedActionId == mFastForwardAction.getId()) { if (keyEvent.getRepeatCount() == 0) { mCurrentMode = MODE_FAST_FORWARD; invokeFastForwardAction(); }// w ww . ja va 2 s .c o m } else if (mRewindAction != null && mSelectedActionId == mRewindAction.getId()) { if (keyEvent.getRepeatCount() == 0) { mCurrentMode = MODE_REWIND; invokeRewindAction(); } } } else if (keyEvent.getAction() == KeyEvent.ACTION_UP) { mCurrentMode = MODE_NOTHING; } } return false; }
From source file:com.android.screenspeak.KeyboardSearchManager.java
@Override public boolean onKeyEvent(KeyEvent event) { // Only handle single-key events here. The KeyComboManager will pass us combos. if (event.getModifiers() != 0 || !mNodeSearch.isActive()) { return false; }/*from w ww . j a v a 2 s .co m*/ if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_ENTER: if (mHasNavigated || mNodeSearch.hasMatch()) { finishSearch(); mContext.getCursorController().clickCurrent(); } else { cancelSearch(); } return true; case KeyEvent.KEYCODE_DEL: resetHintTime(); final String queryText = mNodeSearch.getCurrentQuery(); if (queryText.isEmpty()) { cancelSearch(); } else { final String lastChar = queryText.substring(queryText.length() - 1); mNodeSearch.backspaceQueryText(); mSpeechController.speak(mContext.getString(R.string.template_text_removed, lastChar), SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null); } return true; case KeyEvent.KEYCODE_DPAD_UP: moveToEnd(NodeFocusFinder.SEARCH_BACKWARD); return true; case KeyEvent.KEYCODE_DPAD_LEFT: moveToNext(NodeFocusFinder.SEARCH_BACKWARD); return true; case KeyEvent.KEYCODE_DPAD_DOWN: moveToEnd(NodeFocusFinder.SEARCH_FORWARD); return true; case KeyEvent.KEYCODE_DPAD_RIGHT: moveToNext(NodeFocusFinder.SEARCH_FORWARD); return true; case KeyEvent.KEYCODE_SPACE: resetHintTime(); if (mNodeSearch.tryAddQueryText(" ")) { mSpeechController.speak(mContext.getString(R.string.symbol_space), SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null); } else { mContext.getFeedbackController().playAuditory(R.raw.complete); } return true; default: if (event.isPrintingKey()) { resetHintTime(); final String key = String.valueOf(event.getDisplayLabel()); if (mNodeSearch.tryAddQueryText(key)) { mSpeechController.speak(key.toLowerCase(), SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null); } else { mContext.getFeedbackController().playAuditory(R.raw.complete); } return true; } break; } } return false; }
From source file:jp.gr.java_conf.ya.shiobeforandroid3.UpdateTweetDrive.java
@Override public final boolean onKeyLongPress(final int keyCode, final KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { finish();//from www .j a v a 2 s . co m return true; } else if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) { tweet(); return true; } return super.onKeyLongPress(keyCode, event); }
From source file:com.qiusheng.cast.CastActivity.java
/** * Processes volume up and volume down actions upon receiving them as key * events.// www . jav a 2 s . com */ @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) { double currentVolume; if (mMessageStream != null) { currentVolume = mMessageStream.getVolume(); logVIfEnabled(TAG, "Volume up from " + currentVolume); if (currentVolume < 1.0) { logVIfEnabled(TAG, "New volume: " + (currentVolume + VOLUME_INCREMENT)); onSetVolume(currentVolume + VOLUME_INCREMENT); } } else { Log.e(TAG, "dispatchKeyEvent - volume up - mMessageStream==null"); } } return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { double currentVolume; if (mMessageStream != null) { currentVolume = mMessageStream.getVolume(); logVIfEnabled(TAG, "Volume down from: " + currentVolume); if (currentVolume > 0.0) { logVIfEnabled(TAG, "New volume: " + (currentVolume - VOLUME_INCREMENT)); onSetVolume(currentVolume - VOLUME_INCREMENT); } } else { Log.e(TAG, "dispatchKeyEvent - volume down - mMessageStream==null"); } } return true; default: return super.dispatchKeyEvent(event); } }
From source file:com.mobicage.rogerthat.plugins.friends.RecommendServiceActivity.java
private void configureMailView() { T.UI();// w w w. j a v a 2s . c o m final AutoCompleteTextView emailText = (AutoCompleteTextView) findViewById(R.id.recommend_email_text_field); emailText.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, new ArrayList<String>())); emailText.setThreshold(1); if (mService.isPermitted(Manifest.permission.READ_CONTACTS)) { mService.postAtFrontOfBIZZHandler(new SafeRunnable() { @SuppressWarnings("unchecked") @Override protected void safeRun() throws Exception { L.d("RecommendServiceActivity getEmailAddresses"); List<String> emailList = ContactListHelper.getEmailAddresses(RecommendServiceActivity.this); ArrayAdapter<String> a = (ArrayAdapter<String>) emailText.getAdapter(); for (int i = 0; i < emailList.size(); i++) { a.add(emailList.get(i)); } a.notifyDataSetChanged(); L.d("RecommendServiceActivity gotEmailAddresses"); } }); } final SafeViewOnClickListener onClickListener = new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { String email = emailText.getText().toString().trim(); if (RegexPatterns.EMAIL.matcher(email).matches()) { mFriendsPlugin.shareService(mServiceEmail, email); emailText.setText(null); UIUtils.hideKeyboard(RecommendServiceActivity.this, emailText); AlertDialog.Builder builder = new AlertDialog.Builder(RecommendServiceActivity.this); builder.setMessage(R.string.service_recommendation_sent); builder.setPositiveButton(R.string.rogerthat, null); builder.create().show(); } else { AlertDialog.Builder builder = new AlertDialog.Builder(RecommendServiceActivity.this); builder.setMessage(R.string.registration_email_not_valid); builder.setPositiveButton(R.string.rogerthat, null); builder.create().show(); } } }; ((Button) findViewById(R.id.recommend_email_button)).setOnClickListener(onClickListener); emailText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN)) { onClickListener.onClick(view); return true; } return false; } }); }
From source file:org.alfresco.mobile.android.application.fragments.user.UserSearchFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (getDialog() != null) { getDialog().requestWindowFeature(Window.FEATURE_LEFT_ICON); }//from w w w . j av a 2 s . c om // Retrieve session object checkSession(); if (getArguments() != null && getArguments().containsKey(ARGUMENT_MODE)) { fieldId = getArguments().getString(ARGUMENT_FIELD_ID); keywords = getArguments().getString(ARGUMENT_KEYWORD); title = getArguments().getString(ARGUMENT_TITLE); mode = getArguments().getInt(ARGUMENT_MODE); singleChoice = getArguments().getBoolean(ARGUMENT_SINGLE_CHOICE); String pickFragmentTag = getArguments().getString(ARGUMENT_FRAGMENT_TAG); fragmentPick = getFragmentManager().findFragmentByTag(pickFragmentTag); if (fragmentPick != null && fragmentPick instanceof UserPickerCallback) { selectedItems = ((UserPickerCallback) fragmentPick).retrieveSelection(); } else if (fragmentPick instanceof onPickAuthorityFragment && fieldId != null) { selectedItems = ((onPickAuthorityFragment) fragmentPick).getPersonSelected(fieldId); } } // Create View setRootView(inflater.inflate(R.layout.app_pick_person, container, false)); if (getSession() == null) { return getRootView(); } // Init list init(getRootView(), R.string.person_not_found); gv.setChoiceMode(GridView.CHOICE_MODE_SINGLE); setListShown(true); if (keywords != null && !keywords.isEmpty()) { search(keywords); hide(R.id.search_form_group); } else { // Init form search searchForm = (EditText) viewById(R.id.search_query); searchForm.setImeOptions(EditorInfo.IME_ACTION_SEARCH); searchForm.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (event != null && (event.getAction() == KeyEvent.ACTION_DOWN) && ((actionId == EditorInfo.IME_ACTION_SEARCH) || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) { if (searchForm.getText().length() > 0) { keywords = searchForm.getText().toString(); search(keywords); } else { AlfrescoNotificationManager.getInstance(getActivity()) .showLongToast(getString(R.string.search_form_hint)); } return true; } return false; } }); // Speech to Text Boolean hasTextToSpeech = ActionUtils.hasSpeechToText(getActivity()); ImageButton speechToText = (ImageButton) viewById(R.id.search_microphone); if (hasTextToSpeech) { speechToText.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { speechToText(); } }); } else { hide(R.id.search_microphone); } } if (getMode() == MODE_PICK) { show(R.id.validation_panel); validation = UIUtils.initValidation(getRootView(), R.string.done); updatePickButton(); validation.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onSelect(selectedItems); if (getDialog() != null) { getDialog().dismiss(); } else { getFragmentManager().popBackStack(); } } }); Button cancel = UIUtils.initCancel(getRootView(), R.string.cancel); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (getDialog() != null) { getDialog().dismiss(); } else { getFragmentManager().popBackStack(); } } }); } else { hide(R.id.validation_panel); } return getRootView(); }
From source file:com.groundupworks.partyphotobooth.fragments.CaptureFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final KioskActivity activity = (KioskActivity) getActivity(); final Context appContext = activity.getApplicationContext(); final Bundle args = getArguments(); final int totalFrames = args.getInt(FRAGMENT_BUNDLE_KEY_TOTAL_FRAMES); final int currentFrame = args.getInt(FRAGMENT_BUNDLE_KEY_CURRENT_FRAME); /*//from w w w .j a v a 2s. co m * Select camera from preference. */ // Get from preference. PreferencesHelper preferencesHelper = new PreferencesHelper(); PhotoBoothMode mode = preferencesHelper.getPhotoBoothMode(appContext); int cameraPreference = CameraInfo.CAMERA_FACING_FRONT; if (PhotoBoothMode.PHOTOGRAPHER.equals(mode)) { cameraPreference = CameraInfo.CAMERA_FACING_BACK; } // Default to first camera available. final int numCameras = Camera.getNumberOfCameras(); if (numCameras > 0) { mCameraId = 0; } // Select preferred camera. CameraInfo cameraInfo = new CameraInfo(); for (int cameraId = 0; cameraId < numCameras; cameraId++) { Camera.getCameraInfo(cameraId, cameraInfo); // Break on finding the preferred camera. if (cameraInfo.facing == cameraPreference) { mCameraId = cameraId; break; } } /* * Initialize and set key event handlers. */ mKeyEventHandler = new KioskActivity.KeyEventHandler() { @Override public boolean onKeyEvent(KeyEvent event) { final int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_VOLUME_UP) { mStartButton.dispatchKeyEvent(event); return true; } return false; } }; activity.setKeyEventHandler(mKeyEventHandler); /* * Functionalize views. */ // Configure start button and trigger behaviour. switch (mode) { case PHOTOGRAPHER: mStartButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { initiateCapture(); } }); mStartButton.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { initiateCapture(); return true; } }); linkStartButton(); break; case AUTOMATIC: if (currentFrame > 1) { // Auto-trigger when camera is ready and preview has started. mPreview.setOnPreviewListener(new CenteredPreview.OnPreviewListener() { @Override public void onStarted() { if (isActivityAlive()) { mPreview.post(new Runnable() { @Override public void run() { if (isActivityAlive()) { initiateCountdownCapture(); } } }); } } @Override public void onStopped() { // Do nothing. } }); break; } else { // Fall through to self-serve behaviour. Do not break. } case SELF_SERVE: default: mStartButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { initiateCountdownCapture(); } }); mStartButton.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { initiateCountdownCapture(); return true; } }); linkStartButton(); } // Show frame count only if more than one frame is to be captured. if (totalFrames > 1) { String frameCountText = getString(R.string.capture__frame_count, currentFrame, totalFrames); mFrameCount.setTypeface( Theme.from(appContext, preferencesHelper.getPhotoBoothTheme(appContext)).getFont()); mFrameCount.setText(frameCountText); mFrameCount.setVisibility(View.VISIBLE); } }
From source file:com.pukulab.puku0x.gscalendar.CalendarActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { // Back//from ww w. j a v a2 s .c o m if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { if (mDisplayedUser.usid.equals(mLoginUser.usid)) { if (!mBackKeyPressed) { // Timer //mBackKeyPressed.cancel(); // ??? mBackKeyTimer.start(); // ??, ????? mToast = Toast.makeText(CalendarActivity.this, getString(R.string.back_to_exit), Toast.LENGTH_SHORT); mToast.show(); mBackKeyPressed = true; return false; } } // pressed=true???Back??. return super.dispatchKeyEvent(event); } // Back???????????. return super.dispatchKeyEvent(event); }
From source file:info.guardianproject.otr.app.im.app.ContactListActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { int keyCode = event.getKeyCode(); boolean handled = false; if (!mIsFiltering) { handled = mFilterView.dispatchKeyEvent(event); if (!handled && (KeyEvent.KEYCODE_BACK == keyCode) && (KeyEvent.ACTION_DOWN == event.getAction())) { showFilterView();//from w w w. j a v a 2 s . c o m handled = true; } } else { handled = mContactListView.dispatchKeyEvent(event); if (!handled && KeyEvent.KEYCODE_SEARCH == keyCode && (KeyEvent.ACTION_DOWN == event.getAction())) { InputMethodManager inputMgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); inputMgr.toggleSoftInput(0, 0); if (!mIsFiltering) showFilterView(); onSearchRequested(); } else if (!handled && isReadable(keyCode, event) && (KeyEvent.ACTION_DOWN == event.getAction())) { if (!mIsFiltering) showFilterView(); handled = mFilterView.dispatchKeyEvent(event); } } if (!handled) { handled = super.dispatchKeyEvent(event); } return handled; }
From source file:com.fatelon.partyphotobooth.fragments.CaptureFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final KioskActivity activity = (KioskActivity) getActivity(); final Context appContext = activity.getApplicationContext(); final Bundle args = getArguments(); final int totalFrames = args.getInt(FRAGMENT_BUNDLE_KEY_TOTAL_FRAMES); final int currentFrame = args.getInt(FRAGMENT_BUNDLE_KEY_CURRENT_FRAME); /*/*from w ww .j a v a 2 s . c o m*/ * Select camera from preference. */ // Get from preference. PreferencesHelper preferencesHelper = new PreferencesHelper(); mPhotoBoothMode = preferencesHelper.getPhotoBoothMode(appContext); int cameraPreference = CameraInfo.CAMERA_FACING_FRONT; if (PreferencesHelper.PhotoBoothMode.PHOTOGRAPHER.equals(mPhotoBoothMode)) { cameraPreference = CameraInfo.CAMERA_FACING_BACK; } // Default to first camera available. final int numCameras = Camera.getNumberOfCameras(); if (numCameras > 0) { mCameraId = 0; } // Select preferred camera. CameraInfo cameraInfo = new CameraInfo(); for (int cameraId = 0; cameraId < numCameras; cameraId++) { Camera.getCameraInfo(cameraId, cameraInfo); // Break on finding the preferred camera. if (cameraInfo.facing == cameraPreference) { mCameraId = cameraId; break; } } /* * Initialize and set key event handlers. */ mKeyEventHandler = new KioskActivity.KeyEventHandler() { @Override public boolean onKeyEvent(KeyEvent event) { final int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_VOLUME_UP) { mStartButton.dispatchKeyEvent(event); return true; } return false; } }; activity.setKeyEventHandler(mKeyEventHandler); /* * Functionalize views. */ // Configure start button and trigger behaviour. switch (mPhotoBoothMode) { case PHOTOGRAPHER: mStartButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { initiateCapture(); } }); mStartButton.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { initiateCapture(); return true; } }); linkStartButton(); break; case AUTOMATIC: mStartButtonLong.setVisibility(View.VISIBLE); mStartButton.setVisibility(View.GONE); mStartButton = mStartButtonLong; if (currentFrame > 1) { // Auto-trigger when camera is ready and preview has started. mPreview.setOnPreviewListener(new CenteredPreview.OnPreviewListener() { @Override public void onStarted() { if (isActivityAlive()) { mPreview.post(new Runnable() { @Override public void run() { if (isActivityAlive()) { initiateCountdownCapture(); } } }); } } @Override public void onStopped() { // Do nothing. } }); break; } else { // Fall through to self-serve behaviour. Do not break. } case SELF_SERVE: default: mStartButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { initiateCountdownCapture(); } }); mStartButton.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { initiateCountdownCapture(); return true; } }); linkStartButton(); } // Show frame count only if more than one frame is to be captured. if (totalFrames > 1) { String frameCountText = getString(R.string.capture__frame_count, currentFrame, totalFrames); mFrameCount.setTypeface( Theme.from(appContext, preferencesHelper.getPhotoBoothTheme(appContext)).getFont()); mFrameCount.setText(frameCountText); mFrameCount.setVisibility(View.VISIBLE); } }