List of usage examples for android.view KeyEvent getAction
public final int getAction()
From source file:com.aman.stockcalculator.EventListener.java
@Override public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { int action = keyEvent.getAction(); if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT); return eat; }//from ww w . ja va 2 s .co m //Work-around for spurious key event from IME, bug #1639445 if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) { return true; // eat it } //Calculator.log("KEY " + keyCode + "; " + action); if (keyEvent.getUnicodeChar() == '=') { if (action == KeyEvent.ACTION_UP) { mHandler.onEnter(); } return true; } if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) { if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) { // Tell the handler that text was updated. mHandler.onTextChanged(); } return false; } /* We should act on KeyEvent.ACTION_DOWN, but strangely sometimes the DOWN event isn't received, only the UP. So the workaround is to act on UP... http://b/issue?id=1022478 */ if (action == KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_DPAD_CENTER: mHandler.onEnter(); break; case KeyEvent.KEYCODE_DPAD_UP: mHandler.onUp(); break; case KeyEvent.KEYCODE_DPAD_DOWN: mHandler.onDown(); break; } } return true; }
From source file:com.koma.music.service.MediaButtonIntentReceiver.java
@Override public void onReceive(final Context context, final Intent intent) { LogUtils.i(TAG, "Received intent: " + intent); final String intentAction = intent.getAction(); if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) { startService(context, MusicServiceConstants.CMDPAUSE, System.currentTimeMillis()); } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event == null || event.getAction() != KeyEvent.ACTION_UP) { return; }// w w w. j av a2 s.c o m String command = null; switch (event.getKeyCode()) { case KeyEvent.KEYCODE_HEADSETHOOK: command = MusicServiceConstants.CMDHEADSETHOOK; break; case KeyEvent.KEYCODE_MEDIA_STOP: command = MusicServiceConstants.CMDSTOP; break; case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: command = MusicServiceConstants.CMDTOGGLEPAUSE; break; case KeyEvent.KEYCODE_MEDIA_NEXT: command = MusicServiceConstants.CMDNEXT; break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: command = MusicServiceConstants.CMDPREVIOUS; break; case KeyEvent.KEYCODE_MEDIA_PAUSE: command = MusicServiceConstants.CMDPAUSE; break; case KeyEvent.KEYCODE_MEDIA_PLAY: command = MusicServiceConstants.CMDPLAY; break; } if (command != null) { startService(context, command, event.getEventTime()); if (isOrderedBroadcast()) { abortBroadcast(); } } } }
From source file:de.appetites.android.menuItemSearchAction.MenuItemSearchAction.java
/** * Listen for back button clicks, in order to close the keyboard and collapse the ActionView */// w w w .j a v a 2 s. c om @Override public boolean onKeyPreIme(int keyCode, KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { searchItem.collapseActionView(); } else if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) { searchPerformListener.performSearch(MenuItemSearchAction.this.getText().toString()); searchItem.collapseActionView(); } return super.dispatchKeyEvent(event); }
From source file:com.mobivery.greent.MVYBatteryManagerActivityFragment.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (MVYBatterySaverManager.getInstance().areConnectionsManaged()) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: m_isSendingToBackground = true; MVYBatterySaverManager.getInstance().sendAppToBackground(); break; }/*w w w . j a va 2 s .com*/ } } return super.dispatchKeyEvent(event); }
From source file:org.dmfs.oauth2.android.fragment.InteractiveGrantFragment.java
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (mWebView.canGoBack()) { // user went back a step mWebView.goBack();/* w w w .j av a 2 s .com*/ } else { // the user cancelled the authorization flow sendState(new ErrorOAuth2GrantState( new AuthorizationCancelledError("Authorization cancelled by user."))); } return true; } } if (event.getAction() == KeyEvent.ACTION_UP) { if (keyCode == KeyEvent.KEYCODE_BACK) { // also capture the up event return true; } } return false; }
From source file:com.github.yuukis.businessmap.app.MainActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: // ?//ww w . j ava 2s .c o m ContactsListFragment listFragment = (ContactsListFragment) getSupportFragmentManager() .findFragmentById(R.id.contacts_list); if (listFragment != null && listFragment.getVisibility()) { // ???????? listFragment.setVisibility(false); return true; } } } return super.dispatchKeyEvent(event); }
From source file:com.kogitune.activitytransition.fragment.ExitFragmentTransition.java
public void startExitListening(final Runnable popBackStackRunnable) { if (interpolator == null) { interpolator = new DecelerateInterpolator(); }/*from www . j ava 2 s . co m*/ final View toView = moveData.toView; toView.setFocusableInTouchMode(true); toView.requestFocus(); toView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (event.getAction() != KeyEvent.ACTION_UP) { return true; } TransitionAnimation.startExitAnimation(moveData, interpolator, new Runnable() { @Override public void run() { if (popBackStackRunnable != null) { popBackStackRunnable.run(); return; } if (fragment == null) { if (!supportFragment.isResumed()) { return; } final FragmentManager fragmentManager = supportFragment.getFragmentManager(); if (fragmentManager != null) { fragmentManager.popBackStack(); } } else { if (!fragment.isResumed()) { return; } final android.app.FragmentManager fragmentManager = fragment.getFragmentManager(); if (fragmentManager != null) { fragmentManager.popBackStack(); } } } }); return true; } return false; } }); }
From source file:com.anxpp.blog.fragment.AboutFragment.java
@SuppressLint("SetJavaScriptEnabled") private void initView() { webView = (WebView) getView().findViewById(R.id.webView); // webView.setVisibility(View.GONE); webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { Activity activity = getActivity(); /**//from w w w. j a v a 2 s .c o m * ?Fragment??? * I am not sure why are you getting this error, * i think it should be something like NullPointerException. * Try next: * Evert time you calling getActivity() on Fragment instance you should be sure, * that fragment is actually have this Activity. * Because when your webview is loading you are calling this function: * */ if (activity == null) return; activity.setTitle("Loading..." + progress + "%"); activity.setProgress(progress * 100); if (progress == 100) { activity.setTitle(R.string.app_name); webView.setVisibility(View.VISIBLE); } } }); webView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { Toast("shouldOverrideUrlLoading"); view.loadUrl(url); return true; } }); //?? WebSettings webSettings = webView.getSettings(); //? //webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); //?js webSettings.setJavaScriptEnabled(true); //? ? webSettings.setUseWideViewPort(false); //?? webSettings.setLoadWithOverviewMode(true); // ?? webView.loadUrl("http://anxpp.com"); // webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { //trueWebViewfalse?? view.loadUrl(url); return true; //false? } }); webView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) { // ? webView.goBack(); //? return true; //? } } return false; } }); }
From source file:org.videolan.vlc.gui.MRLPanelFragment.java
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == EditorInfo.IME_ACTION_DONE || keyCode == EditorInfo.IME_ACTION_GO || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { return processUri(); }/*from www.jav a 2 s .c o m*/ return false; }
From source file:com.timothy.android.api.activity.SlidingActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { if ((System.currentTimeMillis() - exitTime) > 2000) { Toast.makeText(getApplicationContext(), this.getResources().getString(R.string.msg_exit_hint), Toast.LENGTH_SHORT).show(); exitTime = System.currentTimeMillis(); } else {/* w w w . j a v a 2 s . c om*/ finish(); ActivityManage.finishProgram(); System.exit(0); } return true; } return super.onKeyDown(keyCode, event); }