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.koma.music.service.MusicService.java
private void setUpMediaSession() { mSession = new MediaSession(this, "KomaMusic"); mSession.setCallback(new MediaSession.Callback() { @Override/*from ww w . j a va 2 s .c om*/ public void onPause() { pause(); mPausedByTransientLossOfFocus = false; } @Override public void onPlay() { play(); } @Override public void onSeekTo(long pos) { seek(pos); } @Override public void onSkipToNext() { gotoNext(true); } @Override public void onSkipToPrevious() { prev(false); } @Override public void onStop() { pause(); mPausedByTransientLossOfFocus = false; seek(0); releaseServiceUiAndStop(); } @Override public void onSkipToQueueItem(long id) { setQueuePosition((int) id); } @Override public boolean onMediaButtonEvent(@NonNull Intent mediaButtonIntent) { if (Intent.ACTION_MEDIA_BUTTON.equals(mediaButtonIntent.getAction())) { KeyEvent ke = mediaButtonIntent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (ke != null && ke.getKeyCode() == KeyEvent.KEYCODE_HEADSETHOOK) { if (ke.getAction() == KeyEvent.ACTION_UP) { handleHeadsetHookClick(ke.getEventTime()); } return true; } } return super.onMediaButtonEvent(mediaButtonIntent); } }); PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(this, MediaButtonIntentReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT); mSession.setMediaButtonReceiver(pi); mSession.setFlags(MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSession.FLAG_HANDLES_MEDIA_BUTTONS); }
From source file:org.telegram.ui.ActionBar.ActionBarMenuItem.java
public ActionBarMenuItem setIsSearchField(boolean value) { if (parentMenu == null) { return this; }//from w w w.jav a 2s . c o m 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:hku.fyp14017.blencode.ui.ScriptActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { //Dismiss ActionMode without effecting checked items FormulaEditorVariableListFragment formulaEditorVariableListFragment = (FormulaEditorVariableListFragment) getSupportFragmentManager() .findFragmentByTag(FormulaEditorVariableListFragment.VARIABLE_TAG); if (formulaEditorVariableListFragment != null && formulaEditorVariableListFragment.isVisible()) { ListAdapter adapter = formulaEditorVariableListFragment.getListAdapter(); ((ScriptActivityAdapterInterface) adapter).clearCheckedItems(); return super.dispatchKeyEvent(event); }//from ww w.ja va 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); }
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();//from www . j a va 2 s. c om 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:com.googlecode.eyesfree.brailleback.BrailleIME.java
private boolean sendAndroidKeyInternal(int keyCode) { LogUtils.log(this, Log.VERBOSE, "sendAndroidKey: %d", keyCode); InputConnection ic = getCurrentInputConnection(); if (ic == null) { return false; }/*from w ww . j av a 2 s . com*/ long eventTime = SystemClock.uptimeMillis(); if (!ic.sendKeyEvent(new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, keyCode, 0 /*repeat*/))) { return false; } return ic.sendKeyEvent(new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_UP, keyCode, 0 /*repeat*/)); }
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 a2s . 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:lewa.support.v7.app.ActionBarActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() != KeyEvent.ACTION_UP) { if (getDelegate().onBackPressed()) { return true; }//from w w w.j a v a 2s. c o m } return super.dispatchKeyEvent(event); }
From source file:com.aretha.slidemenu.SlideMenu.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (KeyEvent.ACTION_UP == event.getAction()) { final boolean isOpen = isOpen(); switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: if (isOpen) { close(true);/*from w w w. j a v a 2 s .co m*/ return true; } break; case KeyEvent.KEYCODE_DPAD_LEFT: if (STATE_OPEN_LEFT == mCurrentState) { close(true); return true; } else if (!isOpen) { open(true, true); return true; } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (STATE_OPEN_RIGHT == mCurrentState) { close(true); return true; } else if (!isOpen) { open(false, true); return true; } break; } } return super.dispatchKeyEvent(event); }
From source file:org.connectbot.ConsoleActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { StrictModeSetup.run();// w w w . j a va 2 s.co m } hardKeyboard = getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY; clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); prefs = PreferenceManager.getDefaultSharedPreferences(this); titleBarHide = prefs.getBoolean(PreferenceConstants.TITLEBARHIDE, false); if (titleBarHide && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // This is a separate method because Gradle does not uniformly respect the conditional // Build check. See: https://code.google.com/p/android/issues/detail?id=137195 requestActionBar(); } this.setContentView(R.layout.act_console); // hide status bar if requested by user if (prefs.getBoolean(PreferenceConstants.FULLSCREEN, false)) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } // TODO find proper way to disable volume key beep if it exists. setVolumeControlStream(AudioManager.STREAM_MUSIC); // handle requested console from incoming intent if (icicle == null) { requested = getIntent().getData(); } else { String uri = icicle.getString(STATE_SELECTED_URI); if (uri != null) { requested = Uri.parse(uri); } } inflater = LayoutInflater.from(this); toolbar = (Toolbar) findViewById(R.id.toolbar); pager = (TerminalViewPager) findViewById(R.id.console_flip); pager.addOnPageChangeListener(new TerminalViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { setTitle(adapter.getPageTitle(position)); onTerminalChanged(); } }); adapter = new TerminalPagerAdapter(); pager.setAdapter(adapter); empty = (TextView) findViewById(android.R.id.empty); stringPromptGroup = (RelativeLayout) findViewById(R.id.console_password_group); stringPromptInstructions = (TextView) findViewById(R.id.console_password_instructions); stringPrompt = (EditText) findViewById(R.id.console_password); stringPrompt.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP) return false; if (keyCode != KeyEvent.KEYCODE_ENTER) return false; // pass collected password down to current terminal String value = stringPrompt.getText().toString(); PromptHelper helper = getCurrentPromptHelper(); if (helper == null) return false; helper.setResponse(value); // finally clear password for next user stringPrompt.setText(""); updatePromptVisible(); return true; } }); booleanPromptGroup = (RelativeLayout) findViewById(R.id.console_boolean_group); booleanPrompt = (TextView) findViewById(R.id.console_prompt); booleanYes = (Button) findViewById(R.id.console_prompt_yes); booleanYes.setOnClickListener(new OnClickListener() { public void onClick(View v) { PromptHelper helper = getCurrentPromptHelper(); if (helper == null) return; helper.setResponse(Boolean.TRUE); updatePromptVisible(); } }); Button booleanNo = (Button) findViewById(R.id.console_prompt_no); booleanNo.setOnClickListener(new OnClickListener() { public void onClick(View v) { PromptHelper helper = getCurrentPromptHelper(); if (helper == null) return; helper.setResponse(Boolean.FALSE); updatePromptVisible(); } }); fade_out_delayed = AnimationUtils.loadAnimation(this, R.anim.fade_out_delayed); // Preload animation for keyboard button keyboard_fade_in = AnimationUtils.loadAnimation(this, R.anim.keyboard_fade_in); keyboard_fade_out = AnimationUtils.loadAnimation(this, R.anim.keyboard_fade_out); keyboardGroup = (LinearLayout) findViewById(R.id.keyboard_group); keyboardAlwaysVisible = prefs.getBoolean(PreferenceConstants.KEY_ALWAYS_VISIVLE, false); if (keyboardAlwaysVisible) { // equivalent to android:layout_above=keyboard_group RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); layoutParams.addRule(RelativeLayout.ABOVE, R.id.keyboard_group); pager.setLayoutParams(layoutParams); // Show virtual keyboard keyboardGroup.setVisibility(View.VISIBLE); } mKeyboardButton = (ImageView) findViewById(R.id.button_keyboard); mKeyboardButton.setOnClickListener(new OnClickListener() { public void onClick(View view) { View terminal = adapter.getCurrentTerminalView(); if (terminal == null) return; InputMethodManager inputMethodManager = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); inputMethodManager.toggleSoftInputFromWindow(terminal.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0); terminal.requestFocus(); hideEmulatedKeys(); } }); findViewById(R.id.button_ctrl).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_esc).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_tab).setOnClickListener(emulatedKeysListener); addKeyRepeater(findViewById(R.id.button_up)); addKeyRepeater(findViewById(R.id.button_up)); addKeyRepeater(findViewById(R.id.button_down)); addKeyRepeater(findViewById(R.id.button_left)); addKeyRepeater(findViewById(R.id.button_right)); findViewById(R.id.button_home).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_end).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_pgup).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_pgdn).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_f1).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_f2).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_f3).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_f4).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_f5).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_f6).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_f7).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_f8).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_f9).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_f10).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_f11).setOnClickListener(emulatedKeysListener); findViewById(R.id.button_f12).setOnClickListener(emulatedKeysListener); actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); if (titleBarHide) { actionBar.hide(); } actionBar.addOnMenuVisibilityListener(new ActionBar.OnMenuVisibilityListener() { public void onMenuVisibilityChanged(boolean isVisible) { inActionBarMenu = isVisible; if (!isVisible) { hideEmulatedKeys(); } } }); } final HorizontalScrollView keyboardScroll = (HorizontalScrollView) findViewById(R.id.keyboard_hscroll); if (!hardKeyboard) { // Show virtual keyboard and scroll back and forth showEmulatedKeys(false); keyboardScroll.postDelayed(new Runnable() { @Override public void run() { final int xscroll = findViewById(R.id.button_f12).getRight(); if (BuildConfig.DEBUG) { Log.d(TAG, "smoothScrollBy(toEnd[" + xscroll + "])"); } keyboardScroll.smoothScrollBy(xscroll, 0); keyboardScroll.postDelayed(new Runnable() { @Override public void run() { if (BuildConfig.DEBUG) { Log.d(TAG, "smoothScrollBy(toStart[" + (-xscroll) + "])"); } keyboardScroll.smoothScrollBy(-xscroll, 0); } }, 500); } }, 500); } // Reset keyboard auto-hide timer when scrolling keyboardScroll.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_MOVE: autoHideEmulatedKeys(); break; case MotionEvent.ACTION_UP: v.performClick(); return (true); } return (false); } }); tabs = (TabLayout) findViewById(R.id.tabs); if (tabs != null) setupTabLayoutWithViewPager(); pager.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showEmulatedKeys(true); } }); // Change keyboard button image according to soft keyboard visibility // How to detect keyboard visibility: http://stackoverflow.com/q/4745988 contentView = findViewById(android.R.id.content); contentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect r = new Rect(); contentView.getWindowVisibleDisplayFrame(r); int screenHeight = contentView.getRootView().getHeight(); int keypadHeight = screenHeight - r.bottom; if (keypadHeight > screenHeight * 0.15) { // keyboard is opened mKeyboardButton.setImageResource(R.drawable.ic_keyboard_hide); mKeyboardButton.setContentDescription( getResources().getText(R.string.image_description_hide_keyboard)); } else { // keyboard is closed mKeyboardButton.setImageResource(R.drawable.ic_keyboard); mKeyboardButton.setContentDescription( getResources().getText(R.string.image_description_show_keyboard)); } } }); }
From source file:com.android.kalite27.ScriptActivity.java
/** * Check if the path contains a data and a content folder * @param path/*from ww w .j a v a2 s. c o m*/ * @return */ private boolean check_directory(String path) { File content_file = new File(path + "/content"); // if the directory doesn't contain data or content folder, alert if (!content_file.exists()) { new AlertDialog.Builder(this).setTitle("Invalid Directory") .setMessage("The selected directory doesn't contain the content folder") .setPositiveButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { isFileBrowserClosed = true; openWebViewIfAllConditionsMeet(); } }).setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { isFileBrowserClosed = true; openWebViewIfAllConditionsMeet(); } }).setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) { dialog.cancel(); isFileBrowserClosed = true; openWebViewIfAllConditionsMeet(); return true; } return false; } }).show(); return false; } else { return true; } }