List of usage examples for android.view KeyEvent ACTION_DOWN
int ACTION_DOWN
To view the source code for android.view KeyEvent ACTION_DOWN.
Click Source Link
From source file:com.bluros.music.helpers.MediaButtonIntentReceiver.java
@Override public void onReceive(final Context context, final Intent intent) { final String intentAction = intent.getAction(); if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) { if (PreferencesUtility.getInstance(context).pauseEnabledOnDetach()) startService(context, MusicService.CMDPAUSE); } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event == null) { return; }/* ww w. j a v a2s .c om*/ final int keycode = event.getKeyCode(); final int action = event.getAction(); final long eventtime = event.getEventTime(); String command = null; switch (keycode) { case KeyEvent.KEYCODE_MEDIA_STOP: command = MusicService.CMDSTOP; break; case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: command = MusicService.CMDTOGGLEPAUSE; break; case KeyEvent.KEYCODE_MEDIA_NEXT: command = MusicService.CMDNEXT; break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: command = MusicService.CMDPREVIOUS; break; case KeyEvent.KEYCODE_MEDIA_PAUSE: command = MusicService.CMDPAUSE; break; case KeyEvent.KEYCODE_MEDIA_PLAY: command = MusicService.CMDPLAY; break; } if (command != null) { if (action == KeyEvent.ACTION_DOWN) { if (mDown) { if (MusicService.CMDTOGGLEPAUSE.equals(command) || MusicService.CMDPLAY.equals(command)) { if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) { acquireWakeLockAndSendMessage(context, mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0); } } } else if (event.getRepeatCount() == 0) { if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) { if (eventtime - mLastClickTime >= DOUBLE_CLICK) { mClickCounter = 0; } mClickCounter++; if (DEBUG) Log.v(TAG, "Got headset click, count = " + mClickCounter); mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT); Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0, context); long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0; if (mClickCounter >= 3) { mClickCounter = 0; } mLastClickTime = eventtime; acquireWakeLockAndSendMessage(context, msg, delay); } else { startService(context, command); } mLaunched = false; mDown = true; } } else { mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT); mDown = false; } if (isOrderedBroadcast()) { abortBroadcast(); } releaseWakeLockIfHandlerIdle(); } } }
From source file:com.kinvey.sample.kitchensink.account.LoginFragment.java
protected void addEditListeners() { login.setEnabled(validateInput());//from w ww . j a v a 2 s. co m username.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { login.setEnabled(validateInput()); } }); username.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE || (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) && username.getText().length() < MIN_USERNAME_LENGTH) { CharSequence text = "User name must contain at least " + MIN_USERNAME_LENGTH + " characters"; Toast.makeText(getSherlockActivity().getApplicationContext(), text, Toast.LENGTH_SHORT).show(); return true; } return false; } }); password.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { login.setEnabled(validateInput()); } }); password.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE || (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) && password.getText().length() < MIN_USERNAME_LENGTH) { CharSequence text = "Password must contain at least " + MIN_PASSWORD_LENGTH + " characters"; Toast.makeText(getSherlockActivity(), text, Toast.LENGTH_SHORT).show(); return true; } return false; } }); }
From source file:com.mifos.mifosxdroid.login.LoginActivity.java
@OnEditorAction(R.id.et_password) public boolean passwordSubmitted(KeyEvent keyEvent) { if (keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN) { login();/* w w w . j a va 2s . c o m*/ return true; } return false; }
From source file:org.alfresco.mobile.android.application.fragments.search.SearchFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setRetainInstance(true);/*www . j a v a 2 s. co m*/ setRootView(inflater.inflate(R.layout.app_search_history, container, false)); init(getRootView(), emptyListMessageId); // Folder path if (getArguments() != null && getArguments().containsKey(ARGUMENT_FOLDER)) { pathView = (TextView) viewById(R.id.search_path); show(R.id.search_path_panel); displayPathOption(); } else { hide(R.id.search_path_panel); } // Search Icon searchIcon = (ImageView) viewById(R.id.search_icon); // Search Input 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) { search(searchForm.getText().toString()); UIUtils.hideKeyboard(getActivity()); } 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); } return getRootView(); }
From source file:com.andrewshu.android.reddit.reddits.PickSubredditActivity.java
void resetUI(PickSubredditAdapter adapter) { findViewById(R.id.loading_light).setVisibility(View.GONE); findViewById(R.id.loading_dark).setVisibility(View.GONE); synchronized (ADAPTER_LOCK) { if (adapter == null) { // Reset the list to be empty. mSubredditsList = new ArrayList<String>(); mSubredditsAdapter = new PickSubredditAdapter(this, mSubredditsList); } else {/*from w ww.j ava 2 s . co m*/ mSubredditsAdapter = adapter; } setListAdapter(mSubredditsAdapter); mSubredditsAdapter.mLoading = false; mSubredditsAdapter.notifyDataSetChanged(); // Just in case } Common.updateListDrawables(this, mSettings.getTheme()); // Set the EditText to do same thing as onListItemClick mEt = (EditText) findViewById(R.id.pick_subreddit_input); if (mEt != null) { mEt.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { returnSubreddit(mEt.getText().toString().trim()); return true; } return false; } }); mEt.setFocusableInTouchMode(true); } Button goButton = (Button) findViewById(R.id.pick_subreddit_button); if (goButton != null) { goButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { returnSubreddit(mEt.getText().toString().trim()); } }); } getListView().requestFocus(); }
From source file:com.shenma.yueba.yangjia.activity.MainActivityForYangJia.java
public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { if ((System.currentTimeMillis() - exitTime) > 2000) { exitTime = System.currentTimeMillis(); Toast.makeText(getApplicationContext(), "??", Toast.LENGTH_SHORT).show(); } else {//w w w. j ava2 s . com MyApplication.getInstance().exit(); } return true; // true??? } return super.onKeyDown(keyCode, event); }
From source file:com.waz.zclient.pages.main.popup.QuickReplyFragment.java
@Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEND || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN)) { final String sendText = textView.getText().toString(); if (TextUtils.isEmpty(sendText)) { return false; }/* w ww .java2 s . c om*/ conversation.sendMessage(new MessageContent.Text(sendText)); TrackingUtils.onSentTextMessage(getControllerFactory().getTrackingController(), getStoreFactory().getConversationStore().getCurrentConversation()); getActivity().finish(); return true; } return false; }
From source file:in.shick.diode.reddits.PickSubredditActivity.java
void resetUI(PickSubredditAdapter adapter) { findViewById(R.id.loading_light).setVisibility(View.GONE); findViewById(R.id.loading_dark).setVisibility(View.GONE); synchronized (ADAPTER_LOCK) { if (adapter == null) { // Reset the list to be empty. mSubredditsList = new ArrayList<SubredditInfo>(); mSubredditsAdapter = new PickSubredditAdapter(this, mSubredditsList); } else {/*from w ww . j a va 2s . co m*/ mSubredditsAdapter = adapter; } setListAdapter(mSubredditsAdapter); mSubredditsAdapter.mLoading = false; mSubredditsAdapter.notifyDataSetChanged(); // Just in case } Common.updateListDrawables(this, mSettings.getTheme()); // Set the EditText to do same thing as onListItemClick mEt = (EditText) findViewById(R.id.pick_subreddit_input); if (mEt != null) { mEt.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { returnSubreddit(mEt.getText().toString().trim()); return true; } return false; } }); mEt.setFocusableInTouchMode(true); } Button goButton = (Button) findViewById(R.id.pick_subreddit_button); if (goButton != null) { goButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { returnSubreddit(mEt.getText().toString().trim()); } }); } getListView().requestFocus(); }
From source file:com.nextgis.rehacompdemo.RoutingActivity.java
@Override public boolean dispatchKeyEvent(@NonNull KeyEvent event) { int position; int action = event.getAction(); int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_DOWN) { position = mSteps.getSelectedItemPosition(); if (position == AdapterView.INVALID_POSITION) position = 0;/*from w ww. j a va 2 s . co m*/ else position--; mSteps.requestFocusFromTouch(); mSteps.setSelection(position); break; } else return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { position = mSteps.getSelectedItemPosition(); if (position == AdapterView.INVALID_POSITION) position = 0; else position++; mSteps.requestFocusFromTouch(); mSteps.setSelection(position); break; } else return true; default: return super.dispatchKeyEvent(event); } return true; }
From source file:org.mozilla.gecko.AwesomeBar.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(LOGTAG, "creating awesomebar"); mResolver = Tabs.getInstance().getContentResolver(); setContentView(R.layout.awesomebar); if (Build.VERSION.SDK_INT >= 11) { RelativeLayout actionBarLayout = (RelativeLayout) GeckoActionBar.getCustomView(this); mGoButton = (ImageButton) actionBarLayout.findViewById(R.id.awesomebar_button); mText = (AwesomeBarEditText) actionBarLayout.findViewById(R.id.awesomebar_text); } else {//from w w w . j av a 2 s.c o m mGoButton = (ImageButton) findViewById(R.id.awesomebar_button); mText = (AwesomeBarEditText) findViewById(R.id.awesomebar_text); } TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs); tabWidget.setDividerDrawable(null); mAwesomeTabs = (AwesomeBarTabs) findViewById(R.id.awesomebar_tabs); mAwesomeTabs.setOnUrlOpenListener(new AwesomeBarTabs.OnUrlOpenListener() { public void onUrlOpen(String url) { openUrlAndFinish(url); } public void onSearch(String engine) { openSearchAndFinish(mText.getText().toString(), engine); } }); mGoButton.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { openUserEnteredAndFinish(mText.getText().toString()); } }); Resources resources = getResources(); int padding[] = { mText.getPaddingLeft(), mText.getPaddingTop(), mText.getPaddingRight(), mText.getPaddingBottom() }; GeckoStateListDrawable states = new GeckoStateListDrawable(); states.initializeFilter(GeckoApp.mBrowserToolbar.getHighlightColor()); states.addState(new int[] { android.R.attr.state_focused }, resources.getDrawable(R.drawable.address_bar_url_pressed)); states.addState(new int[] { android.R.attr.state_pressed }, resources.getDrawable(R.drawable.address_bar_url_pressed)); states.addState(new int[] {}, resources.getDrawable(R.drawable.address_bar_url_default)); mText.setBackgroundDrawable(states); mText.setPadding(padding[0], padding[1], padding[2], padding[3]); Intent intent = getIntent(); String currentUrl = intent.getStringExtra(CURRENT_URL_KEY); mType = intent.getStringExtra(TYPE_KEY); if (currentUrl != null) { mText.setText(currentUrl); mText.selectAll(); } mText.setOnKeyPreImeListener(new AwesomeBarEditText.OnKeyPreImeListener() { public boolean onKeyPreIme(View v, int keyCode, KeyEvent event) { // We only want to process one event per tap if (event.getAction() != KeyEvent.ACTION_DOWN) return false; if (keyCode == KeyEvent.KEYCODE_ENTER) { openUserEnteredAndFinish(mText.getText().toString()); return true; } // If input method is in fullscreen mode, we want to dismiss // it instead of closing awesomebar straight away. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (keyCode == KeyEvent.KEYCODE_BACK && !imm.isFullscreenMode()) { // Let mAwesomeTabs try to handle the back press, since we may be in a // bookmarks sub-folder. if (mAwesomeTabs.onBackPressed()) return true; // If mAwesomeTabs.onBackPressed() returned false, we didn't move up // a folder level, so just exit the activity. cancelAndFinish(); return true; } return false; } }); mText.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { // do nothing } public void beforeTextChanged(CharSequence s, int start, int count, int after) { // do nothing } public void onTextChanged(CharSequence s, int start, int before, int count) { String text = s.toString(); mAwesomeTabs.filter(text); updateGoButton(text); } }); mText.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) { if (event.getAction() != KeyEvent.ACTION_DOWN) return true; openUserEnteredAndFinish(mText.getText().toString()); return true; } else { return false; } } }); mText.setOnFocusChangeListener(new View.OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); } } }); registerForContextMenu(mAwesomeTabs.findViewById(R.id.all_pages_list)); registerForContextMenu(mAwesomeTabs.findViewById(R.id.bookmarks_list)); registerForContextMenu(mAwesomeTabs.findViewById(R.id.history_list)); GeckoAppShell.registerGeckoEventListener("SearchEngines:Data", this); GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:Get", null)); }