List of usage examples for android.view KeyEvent getAction
public final int getAction()
From source file:com.oonhee.oojs.inappbrowser.InAppBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject/*from w w w . j a v a 2 s . co m*/ */ public String showWebPage(final String url, HashMap<String, Boolean> features) { // Determine if we should hide the location bar. showLocationBar = true; openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } Boolean hidden = features.get(HIDDEN); if (hidden != null) { openWindowHidden = hidden.booleanValue(); } Boolean cache = features.get(CLEAR_ALL_CACHE); if (cache != null) { clearAllCache = cache.booleanValue(); } else { cache = features.get(CLEAR_SESSION_CACHE); if (cache != null) { clearSessionCache = cache.booleanValue(); } } } final CordovaWebView thatWebView = this.webView; // Create dialog in new thread Runnable runnable = new Runnable() { /** * Convert our DIP units to Pixels * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, cordova.getActivity().getResources().getDisplayMetrics()); return value; } public void run() { // Let's create the main dialog dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { closeDialog(); } }); // Main container layout LinearLayout main = new LinearLayout(cordova.getActivity()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); //Please, no more black! toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.TOP); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); actionButtonContainer.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button Button back = new Button(cordova.getActivity()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); back.setText("<"); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button Button forward = new Button(cordova.getActivity()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); forward.setText(">"); forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // Edit Text Box edittext = new EditText(cordova.getActivity()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setId(4); edittext.setSingleLine(true); edittext.setText(url); edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); edittext.setImeOptions(EditorInfo.IME_ACTION_GO); edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); // Close button Button close = new Button(cordova.getActivity()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); close.setText(buttonLabel); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView inAppWebView = new AmazonWebView(cordova.getActivity()); CordovaActivity app = (CordovaActivity) cordova.getActivity(); cordova.getFactory().initializeWebView(inAppWebView, 0x00FF00, false, null); inAppWebView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); AmazonWebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); AmazonWebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginState(com.amazon.android.webkit.AmazonWebSettings.PluginState.ON); //Toggle whether this is enabled or not! Bundle appSettings = cordova.getActivity().getIntent().getExtras(); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); if (enableDatabase) { String databasePath = cordova.getActivity().getApplicationContext() .getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setDatabaseEnabled(true); } settings.setDomStorageEnabled(true); if (clearAllCache) { AmazonCookieManager.getInstance().removeAllCookie(); } else if (clearSessionCache) { AmazonCookieManager.getInstance().removeSessionCookie(); } inAppWebView.loadUrl(url); inAppWebView.setId(6); inAppWebView.getSettings().setLoadWithOverviewMode(true); inAppWebView.getSettings().setUseWideViewPort(true); inAppWebView.requestFocus(); inAppWebView.requestFocusFromTouch(); // Add the back and forward buttons to our action button container layout actionButtonContainer.addView(back); actionButtonContainer.addView(forward); // Add the views to our toolbar toolbar.addView(actionButtonContainer); toolbar.addView(edittext); toolbar.addView(close); // Don't add the toolbar if its been disabled if (getShowLocationBar()) { // Add our toolbar to our main view/layout main.addView(toolbar); } // Add our webview to our main view/layout main.addView(inAppWebView); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); // the goal of openhidden is to load the url and not display it // Show() needs to be called to cause the URL to be loaded if (openWindowHidden) { dialog.hide(); } } }; this.cordova.getActivity().runOnUiThread(runnable); return ""; }
From source file:com.example.angel.parkpanda.MainActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { switch (event.getAction()) { case KeyEvent.ACTION_DOWN: if (event.getDownTime() - lastPressedTime < PERIOD) { System.exit(0);/*from ww w . j ava 2 s .co m*/ finish(); } else { Toast.makeText(getApplicationContext(), "Press again to exit.", Toast.LENGTH_SHORT).show(); lastPressedTime = event.getEventTime(); } return true; } } return false; }
From source file:org.uoyabause.android.YabauseHandler.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { int action = event.getAction(); int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.KEYCODE_BACK) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { Fragment fg = getSupportFragmentManager().findFragmentByTag(StateListFragment.TAG); if (fg != null) { this.cancelStateLoad(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.remove(fg);//w ww . j av a2 s . co m transaction.commit(); View mainv = findViewById(R.id.yabause_view); mainv.setActivated(true); mainv.requestFocus(); waiting_reault = false; YabauseRunnable.resume(); audio.unmute(audio.SYSTEM); return true; } fg = getSupportFragmentManager().findFragmentByTag(TabBackupFragment.TAG); if (fg != null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.remove(fg); transaction.commit(); View mainv = findViewById(R.id.yabause_view); mainv.setActivated(true); mainv.requestFocus(); waiting_reault = false; YabauseRunnable.resume(); audio.unmute(audio.SYSTEM); return true; } showBottomMenu(); } return true; } if (menu_showing) { return super.dispatchKeyEvent(event); } if (this.waiting_reault) { return super.dispatchKeyEvent(event); } //Log.d("dispatchKeyEvent","device:" + event.getDeviceId() + ",action:" + action +",keyCoe:" + keyCode ); if (action == KeyEvent.ACTION_UP) { int rtn = padm.onKeyUp(keyCode, event); if (rtn != 0) { return true; } } else if (action == KeyEvent.ACTION_MULTIPLE) { } else if (action == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { int rtn = padm.onKeyDown(keyCode, event); if (rtn != 0) { return true; } } 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);/* w ww .j av a2 s . c o 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:com.gelakinetic.mtgfam.activities.MainActivity.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { /*/*w w w .java2s . c o m*/ * This is for ForceOverflow */ if (DEVICE_VERSION < DEVICE_HONEYCOMB) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_MENU) { openOptionsMenu(); return true; } } return super.onKeyUp(keyCode, event); }
From source file:com.owen.tvrecyclerview.widget.TvRecyclerView.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { boolean result = super.dispatchKeyEvent(event); if (!result) { switch (event.getAction()) { case KeyEvent.ACTION_DOWN: result = onKeyDown(event.getKeyCode(), event); break; case KeyEvent.ACTION_UP: result = onKeyUp(event.getKeyCode(), event); break; }/*ww w . j a v a2 s . c o m*/ } return result; }
From source file:su.comp.bk.ui.BkEmuActivity.java
@Override public void onBackPressed() { KeyboardController keyboardController = this.computer.getKeyboardController(); if (keyboardController.isOnScreenKeyboardVisible()) { keyboardController.setOnScreenKeyboardVisibility(false); } else {//ww w. ja v a 2s. co m this.computer.pause(); new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert) .setTitle(R.string.exit_confirm_title).setMessage(R.string.exit_confirm_message) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { BkEmuActivity.this.computer.resume(); } }).setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) { BkEmuActivity.this.computer.resume(); } return false; } }).show(); } }
From source file:paulscode.android.mupen64plusae.game.GameFragment.java
/** * Handle view onKey callbacks//from w w w . jav a 2 s . c o m * @param view If view is NULL then this keycode will not be handled by the key provider. This is to avoid * the situation where user maps the menu key to the menu command. * @param keyCode key code * @param event key event * @return True if handled */ @Override public boolean onKey(View view, int keyCode, KeyEvent event) { final boolean keyDown = event.getAction() == KeyEvent.ACTION_DOWN; boolean handled = false; // Attempt to reconnect any disconnected devices mGamePrefs.playerMap.reconnectDevice(AbstractProvider.getHardwareId(event)); if (!mDrawerLayout.isDrawerOpen(GravityCompat.START)) { // If PeripheralControllers exist and handle the event, // they return true. Else they return false, signaling // Android to handle the event (menu button, vol keys). if (mKeyProvider != null && view != null) { handled = mKeyProvider.onKey(view, keyCode, event); //Don't use built in keys in the device to hide the touch controls if (handled && keyCode != KeyEvent.KEYCODE_MENU && keyCode != KeyEvent.KEYCODE_BACK && keyCode != KeyEvent.KEYCODE_VOLUME_UP && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE && mGlobalPrefs.touchscreenAutoHideEnabled) { mOverlay.onTouchControlsHide(); } } } if (!handled) { if (keyDown && keyCode == KeyEvent.KEYCODE_MENU) { if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { mDrawerLayout.closeDrawer(GravityCompat.START); mOverlay.requestFocus(); } else { mCoreFragment.pauseEmulator(); mDrawerLayout.openDrawer(GravityCompat.START); mDrawerOpenState = true; mGameSidebar.requestFocus(); mGameSidebar.smoothScrollToPosition(0); } return true; } else if (keyDown && keyCode == KeyEvent.KEYCODE_BACK) { if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { mDrawerLayout.closeDrawer(GravityCompat.START); mOverlay.requestFocus(); } else { //We are using the slide gesture for the menu, so the back key can be used to exit if (mGlobalPrefs.inGameMenuIsSwipGesture) { mWaitingOnConfirmation = true; mCoreFragment.exit(); } //Else the back key bring up the in-game menu else { mCoreFragment.pauseEmulator(); mDrawerLayout.openDrawer(GravityCompat.START); mDrawerOpenState = true; mGameSidebar.requestFocus(); mGameSidebar.smoothScrollToPosition(0); } } return true; } } return handled; }
From source file:com.undatech.opaque.RemoteCanvasActivity.java
@Override public boolean onKey(View v, int keyCode, KeyEvent evt) { boolean consumed = false; if (keyCode == KeyEvent.KEYCODE_MENU) { if (evt.getAction() == KeyEvent.ACTION_DOWN) return super.onKeyDown(keyCode, evt); else return super.onKeyUp(keyCode, evt); }/*from www.java2s .com*/ try { if (evt.getAction() == KeyEvent.ACTION_DOWN || evt.getAction() == KeyEvent.ACTION_MULTIPLE) { consumed = inputHandler.onKeyDown(keyCode, evt); } else if (evt.getAction() == KeyEvent.ACTION_UP) { consumed = inputHandler.onKeyUp(keyCode, evt); } resetOnScreenKeys(keyCode); } catch (NullPointerException e) { } return consumed; }
From source file:com.scooter1556.sms.android.fragment.tv.TvVideoPlayerFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { view.setOnKeyListener(new View.OnKeyListener() { @Override/*from w w w . j a v a 2 s. c o m*/ public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) { if (playbackState == PlaybackStateCompat.STATE_PLAYING) { pause(); } else { play(currentMedia); } return true; } } return false; } }); }