List of usage examples for android.view KeyEvent KEYCODE_ENTER
int KEYCODE_ENTER
To view the source code for android.view KeyEvent KEYCODE_ENTER.
Click Source Link
From source file:com.redinput.datetimepickercompat.time.TimePickerDialog.java
/** * For keyboard mode, processes key events. * //ww w .j av a 2 s. c o m * @param keyCode * the pressed key. * @return true if the key was successfully processed, false otherwise. */ private boolean processKeyUp(int keyCode) { if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) { dismiss(); return true; } else if (keyCode == KeyEvent.KEYCODE_TAB) { if (mInKbMode) { if (isTypedTimeFullyLegal()) { finishKbMode(true); } return true; } } else if (keyCode == KeyEvent.KEYCODE_ENTER) { if (mInKbMode) { if (!isTypedTimeFullyLegal()) { return true; } finishKbMode(false); } if (mCallback != null) { mCallback.onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes()); } dismiss(); return true; } else if (keyCode == KeyEvent.KEYCODE_DEL) { if (mInKbMode) { if (!mTypedTimes.isEmpty()) { int deleted = deleteLastTypedKey(); String deletedKeyStr; if (deleted == getAmOrPmKeyCode(AM)) { deletedKeyStr = mAmText; } else if (deleted == getAmOrPmKeyCode(PM)) { deletedKeyStr = mPmText; } else { deletedKeyStr = String.format(Locale.getDefault(), "%d", getValFromKeyCode(deleted)); } Utils.tryAccessibilityAnnounce(mTimePicker, String.format(mDeletedKeyFormat, deletedKeyStr)); updateDisplay(true); } } } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1 || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3 || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5 || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7 || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9 || (!mIs24HourMode && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) { if (!mInKbMode) { if (mTimePicker == null) { // Something's wrong, because time picker should definitely not be null. Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null."); return true; } mTypedTimes.clear(); tryStartingKbMode(keyCode); return true; } // We're already in keyboard mode. if (addKeyIfLegal(keyCode)) { updateDisplay(false); } return true; } return false; }
From source file:org.telegram.ui.Components.NumberPicker.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { final int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: removeAllCallbacks();/* ww w. j a v a2s .c o m*/ break; case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_UP: switch (event.getAction()) { case KeyEvent.ACTION_DOWN: if (mWrapSelectorWheel || (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) ? getValue() < getMaxValue() : getValue() > getMinValue()) { requestFocus(); mLastHandledDownDpadKeyCode = keyCode; removeAllCallbacks(); if (mFlingScroller.isFinished()) { changeValueByOne(keyCode == KeyEvent.KEYCODE_DPAD_DOWN); } return true; } break; case KeyEvent.ACTION_UP: if (mLastHandledDownDpadKeyCode == keyCode) { mLastHandledDownDpadKeyCode = -1; return true; } break; } } return super.dispatchKeyEvent(event); }
From source file:org.ulteo.ovd.MainWindow.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) { if (!Settings.getHideSm(this)) { if (!loginTxtField.equals("") && !passwdTxtField.equals("") && sessionmTxtField.isFocused()) startBtn.performClick(); } else {//w ww . ja v a 2s .com if (!loginTxtField.equals("") && !passwdTxtField.equals("") && passwdTxtField.isFocused()) startBtn.performClick(); } return true; } return super.onKeyUp(keyCode, event); }
From source file:de.vanita5.twittnuker.activity.support.ComposeActivity.java
@Override public boolean onEditorAction(final TextView view, final int actionId, final KeyEvent event) { if (event == null) return false; switch (event.getKeyCode()) { case KeyEvent.KEYCODE_ENTER: { updateStatus();//w w w. jav a 2 s. c o m return true; } } return false; }
From source file:org.telegram.ui.ActionBar.ActionBarMenuItem.java
public ActionBarMenuItem setIsSearchField(boolean value) { if (parentMenu == null) { return this; }/*w w w . j a va 2s . c om*/ if (value && searchContainer == null) { searchContainer = new FrameLayout(getContext()); parentMenu.addView(searchContainer, 0); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) searchContainer.getLayoutParams(); layoutParams.weight = 1; layoutParams.width = 0; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.leftMargin = AndroidUtilities.dp(6); searchContainer.setLayoutParams(layoutParams); searchContainer.setVisibility(GONE); searchField = new EditText(getContext()); searchField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); searchField.setHintTextColor(0x88ffffff); searchField.setTextColor(0xffffffff); searchField.setSingleLine(true); searchField.setBackgroundResource(0); searchField.setPadding(0, 0, 0, 0); int inputType = searchField.getInputType() | EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS; searchField.setInputType(inputType); searchField.setCustomSelectionActionModeCallback(new ActionMode.Callback() { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } public void onDestroyActionMode(ActionMode mode) { } public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } }); searchField.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (/*actionId == EditorInfo.IME_ACTION_SEARCH || */event != null && (event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { AndroidUtilities.hideKeyboard(searchField); if (listener != null) { listener.onSearchPressed(searchField); } } return false; } }); searchField.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) { if (listener != null) { listener.onTextChanged(searchField); } if (clearButton != null) { clearButton.setAlpha(s == null || s.length() == 0 ? 0.6f : 1.0f); } } @Override public void afterTextChanged(Editable s) { } }); try { Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes"); mCursorDrawableRes.setAccessible(true); mCursorDrawableRes.set(searchField, R.drawable.search_carret); } catch (Exception e) { //nothing to do } searchField.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_ACTION_SEARCH); searchField.setTextIsSelectable(false); searchContainer.addView(searchField); FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) searchField.getLayoutParams(); layoutParams2.width = LayoutHelper.MATCH_PARENT; layoutParams2.gravity = Gravity.CENTER_VERTICAL; layoutParams2.height = AndroidUtilities.dp(36); layoutParams2.rightMargin = AndroidUtilities.dp(48); searchField.setLayoutParams(layoutParams2); clearButton = new ImageView(getContext()); clearButton.setImageResource(R.drawable.ic_close_white); clearButton.setScaleType(ImageView.ScaleType.CENTER); clearButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { searchField.setText(""); searchField.requestFocus(); AndroidUtilities.showKeyboard(searchField); } }); searchContainer.addView(clearButton); layoutParams2 = (FrameLayout.LayoutParams) clearButton.getLayoutParams(); layoutParams2.width = AndroidUtilities.dp(48); layoutParams2.gravity = Gravity.CENTER_VERTICAL | Gravity.RIGHT; layoutParams2.height = LayoutHelper.MATCH_PARENT; clearButton.setLayoutParams(layoutParams2); } isSearchField = value; return this; }
From source file:mirko.android.datetimepicker.time.TimePickerDialogSupport.java
/** * For keyboard mode, processes key events. * @param keyCode the pressed key.//from ww w . j a va 2s . co m * @return true if the key was successfully processed, false otherwise. */ private boolean processKeyUp(int keyCode) { if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) { dismiss(); return true; } else if (keyCode == KeyEvent.KEYCODE_TAB) { if (mInKbMode) { if (isTypedTimeFullyLegal()) { finishKbMode(true); } return true; } } else if (keyCode == KeyEvent.KEYCODE_ENTER) { if (mInKbMode) { if (!isTypedTimeFullyLegal()) { return true; } finishKbMode(false); } if (mCallback != null) { mCallback.onTimeSet(this, mTimePicker.getHours(), mTimePicker.getMinutes()); } dismiss(); return true; } else if (keyCode == KeyEvent.KEYCODE_DEL) { if (mInKbMode) { if (!mTypedTimes.isEmpty()) { int deleted = deleteLastTypedKey(); String deletedKeyStr; if (deleted == getAmOrPmKeyCode(AM)) { deletedKeyStr = mAmText; } else if (deleted == getAmOrPmKeyCode(PM)) { deletedKeyStr = mPmText; } else { deletedKeyStr = String.format("%d", getValFromKeyCode(deleted)); } Utils.tryAccessibilityAnnounce(mTimePicker, String.format(mDeletedKeyFormat, deletedKeyStr)); updateDisplay(true); } } } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1 || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3 || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5 || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7 || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9 || (!mIs24HourMode && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) { if (!mInKbMode) { if (mTimePicker == null) { // Something's wrong, because time picker should definitely not be null. Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null."); return true; } mTypedTimes.clear(); tryStartingKbMode(keyCode); return true; } // We're already in keyboard mode. if (addKeyIfLegal(keyCode)) { updateDisplay(false); } return true; } return false; }
From source file:org.ednovo.goorusearchwidget.SearchResults_resource.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search_results_resource); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); Bundle extra = getIntent().getExtras(); if (extra != null) { searchKeyword = extra.getString("keyWord").trim(); }//ww w.j av a2 s .co m prefsPrivate = getSharedPreferences(PREFS_PRIVATE, Context.MODE_PRIVATE); token = prefsPrivate.getString("token", ""); imageViewClose = (ImageView) findViewById(R.id.imageViewClose); imageViewSearch = (ImageView) findViewById(R.id.imageViewSearch); editTextSearchResults = (EditText) findViewById(R.id.textViewSearch); switchResColl = (Switch) findViewById(R.id.switchResColl); dialog1 = new Dialog(this); editTextSearchResults.setText(searchKeyword); imm = (InputMethodManager) this.getSystemService(Service.INPUT_METHOD_SERVICE); dialog = new ProgressDialog(this); dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); if (checkInternetConnection()) { new getResources().execute(); } else { showDialog("Please Check Internet connection"); new getResources().execute(); } // scroll views videoScroll = (HorizontalScrollView) findViewById(R.id.videoScroll); interactiveScroll = (HorizontalScrollView) findViewById(R.id.interactiveScroll); websiteScroll = (HorizontalScrollView) findViewById(R.id.websiteScroll); textbookScroll = (HorizontalScrollView) findViewById(R.id.textbookScroll); examScroll = (HorizontalScrollView) findViewById(R.id.examScroll); handoutScroll = (HorizontalScrollView) findViewById(R.id.handoutScroll); slideScroll = (HorizontalScrollView) findViewById(R.id.slideScroll); lessonScroll = (HorizontalScrollView) findViewById(R.id.lessonScroll); // category image load more resources videoRight = (ImageView) findViewById(R.id.videoRight); interactiveRight = (ImageView) findViewById(R.id.interactiveRight); websiteRight = (ImageView) findViewById(R.id.websiteRight); textbookRight = (ImageView) findViewById(R.id.textbookRight); examRight = (ImageView) findViewById(R.id.examRight); handoutRight = (ImageView) findViewById(R.id.handoutRight); slideRight = (ImageView) findViewById(R.id.slideRight); lessonRight = (ImageView) findViewById(R.id.lessonRight); videoRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (checkInternetConnection()) { videoCount++; dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); new getNext5Videos().execute(); } else { showDialog("Please Check Internet connection"); } } }); interactiveRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (checkInternetConnection()) { interactiveCount++; dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); new getNext5interactive().execute(); } else { showDialog("Please Check Internet connection"); } } }); imageViewSearch.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String searchKeyword = editTextSearchResults.getText().toString().trim(); if (searchKeyword.length() > 0) { Intent intentResResults = new Intent(getBaseContext(), SearchResults_resource.class); searchKeyword = editTextSearchResults.getText().toString().trim(); Log.i("Search :", searchKeyword); Bundle extras = new Bundle(); extras.putString("keyWord", searchKeyword); intentResResults.putExtras(extras); startActivity(intentResResults); finish(); } else { dialog1.setTitle("Please enter a Search keyword"); dialog1.show(); } } }); websiteRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (checkInternetConnection()) { websiteCount++; dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); new getNext5website().execute(); } else { showDialog("Please Check Internet connection"); } } }); textbookRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (checkInternetConnection()) { textbookCount++; dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); new getNext5textbook().execute(); } else { showDialog("Please Check Internet connection"); } } }); examRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (checkInternetConnection()) { examCount++; dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); new getNext5exam().execute(); } else { showDialog("Please Check Internet connection"); } } }); handoutRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (checkInternetConnection()) { handoutCount++; dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); new getNext5handout().execute(); } else { showDialog("Please Check Internet connection"); } } }); slideRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (checkInternetConnection()) { slideCount++; dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); new getNext5slide().execute(); } else { showDialog("Please Check Internet connection"); } } }); lessonRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (checkInternetConnection()) { lessonCount++; dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); new getNext5lesson().execute(); } else { showDialog("Please Check Internet connection"); } } }); editTextSearchResults.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: String searchKeyword = editTextSearchResults.getText().toString().trim(); if (searchKeyword.length() > 0) { Log.i("Resources", searchKeyword); Intent intentResResults = new Intent(getBaseContext(), SearchResults_resource.class); Bundle extras = new Bundle(); extras.putString("keyWord", searchKeyword); intentResResults.putExtras(extras); startActivity(intentResResults); finish(); } else { dialog1.setTitle("Please enter a Search keyword"); dialog1.show(); } return true; default: break; } } return false; } }); imageViewClose.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { finish(); } }); }
From source file:com.concavenp.artistrymuse.MainActivity.java
/** * Intercept the signal of when keyboard presses are released. We are specifically checking for * when the Enter key is hit. If this is the case then we want to check if we are in the * Search fragment and signal it of the Enter press if it is. *///from w w w. j a v a 2 s . c o m @Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_ENTER: { Class result = mFragmentAdapter.getClassFromPosition(tabPosition); if (result == SearchFragment.class) { SearchFragment searchFragment = (SearchFragment) mFragmentAdapter.getItem(tabPosition); searchFragment.onKeyUp(); } return true; } default: { return super.onKeyUp(keyCode, event); } } }
From source file:com.albedinsky.android.ui.widget.SearchView.java
/** * Called to inflate a view hierarchy of this view. * * @param context Context used to obtain an instance of LayoutInflater used to inflate a desired * layout resource as view hierarchy for this view. * @param resource Resource id of the layout which should represent a view hierarchy of this view. *//*from ww w .j a v a 2s .c o m*/ private void inflateHierarchy(Context context, int resource) { LayoutInflater.from(context).inflate(resource, this); this.mEditText = (AutoCompleteTextViewWidget) findViewById(R.id.ui_search_input); this.mButtonIcon = (ImageButtonWidget) findViewById(R.id.ui_search_icon); this.mProgressBar = (CircularProgressBar) findViewById(R.id.ui_search_progress); this.mButtonClear = (ImageButtonWidget) findViewById(R.id.ui_search_clear); this.mButtonVoiceSearch = (ImageButtonWidget) findViewById(R.id.ui_search_mic); // fixme: remove this when voice search is implemented mButtonVoiceSearch.setVisibility(View.GONE); mEditText.addTextChangedListener(new TextWatcher() { /** */ @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Ignored. } /** */ @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // Ignored. } /** */ @Override public void afterTextChanged(Editable s) { onQueryTextChange(s != null && s.length() > 0 ? new SpannableStringBuilder(s) : ""); } }); mEditText.setOnKeyListener(new View.OnKeyListener() { /** */ @Override public boolean onKey(View view, int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_ENTER: if (event.getAction() == KeyEvent.ACTION_UP) { onTextConfirmed(); } return true; } return false; } }); mButtonClear.setOnClickListener(CLICK_LISTENER); mButtonVoiceSearch.setOnClickListener(CLICK_LISTENER); }
From source file:com.gcloud.gaadi.ui.sleepbot.datetimepicker.time.TimePickerDialog.java
/** * For keyboard mode, processes key events. * * @param keyCode the pressed key./*from w w w . ja va 2s. c o m*/ * @return true if the key was successfully processed, false otherwise. */ private boolean processKeyUp(int keyCode) { if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) { dismiss(); return true; } else if (keyCode == KeyEvent.KEYCODE_TAB) { if (mInKbMode) { if (isTypedTimeFullyLegal()) { finishKbMode(true); } return true; } } else if (keyCode == KeyEvent.KEYCODE_ENTER) { if (mInKbMode) { if (!isTypedTimeFullyLegal()) { return true; } finishKbMode(false); } if (mCallback != null) { mCallback.onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes()); } dismiss(); return true; } else if (keyCode == KeyEvent.KEYCODE_DEL) { if (mInKbMode) { if (!mTypedTimes.isEmpty()) { int deleted = deleteLastTypedKey(); String deletedKeyStr; if (deleted == getAmOrPmKeyCode(AM)) { deletedKeyStr = mAmText; } else if (deleted == getAmOrPmKeyCode(PM)) { deletedKeyStr = mPmText; } else { deletedKeyStr = String.format("%d", getValFromKeyCode(deleted)); } Utils.tryAccessibilityAnnounce(mTimePicker, String.format(mDeletedKeyFormat, deletedKeyStr)); updateDisplay(true); } } } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1 || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3 || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5 || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7 || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9 || (!mIs24HourMode && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) { if (!mInKbMode) { if (mTimePicker == null) { // Something's wrong, because time picker should definitely not be null. GCLog.e("Unable to initiate keyboard mode, TimePicker was null."); return true; } mTypedTimes.clear(); tryStartingKbMode(keyCode); return true; } // We're already in keyboard mode. if (addKeyIfLegal(keyCode)) { updateDisplay(false); } return true; } return false; }