List of usage examples for android.view KeyEvent getAction
public final int getAction()
From source file:com.ruesga.rview.SearchActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_MENU: mBinding.searchView.openMenu(true); return true; }// ww w .j av a 2 s.co m } return super.dispatchKeyEvent(event); }
From source file:paulscode.android.mupen64plusae.game.GameActivity.java
@Override public boolean onKey(View view, int keyCode, KeyEvent event) { final boolean keyDown = event.getAction() == KeyEvent.ACTION_DOWN; // Attempt to reconnect any disconnected devices mGamePrefs.playerMap.reconnectDevice(AbstractProvider.getHardwareId(event)); if (keyDown && keyCode == KeyEvent.KEYCODE_MENU) { if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) mDrawerLayout.closeDrawer(GravityCompat.START); else//w ww . j ava 2 s . c o m mDrawerLayout.openDrawer(GravityCompat.START); return true; } else if (keyDown && keyCode == KeyEvent.KEYCODE_BACK) { if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { mDrawerLayout.closeDrawer(GravityCompat.START); } else { mWaitingOnConfirmation = true; CoreInterface.exit(); } return true; } // Let the PeripheralControllers and Android handle everything else else { 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) return mKeyProvider.onKey(view, keyCode, event); } return false; } }
From source file:com.google.fpl.voltair.VoltAirActivity.java
/** * @brief Called to process (and possibly intercept) key events. * @param event @c KeyEvent to handle/*from w ww . j a va 2s . c o m*/ * @returns @c true if @p event was handled */ @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { // Since QtActivity does not handle volume (throwing the events on the floor) and we // cannot call super.super, we must handle managing of the volume here // TODO: Figure out how to get the volume Ui slide to show up without permanently // breaking immersive mode. switch (event.getKeyCode()) { case KeyEvent.KEYCODE_VOLUME_UP: mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, 0 /* No flags */); break; case KeyEvent.KEYCODE_VOLUME_DOWN: mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, 0 /* No flags */); break; } } // QtActivity (i.e. super) will convert all key events to QKeyEvents and *always* return // true saying it accepted the event -- even on Gamepad key events it doesn't understand. // This is annoying, and unfortunately means that we must always let controllers take a look // at the event even if QtActivity understood it and accepted it for use (e.g. in the UI). // However, we must be careful with events that are successfully translated (e.g. Keyboard // key events) so as to not spawn two separate controllers (one here with the Android // KeyEvent, and the other one in "InputArea" with the translated QKeyEvent). if (isGamepadEvent(event)) { if (onGamepadKeyEvent(event)) { return true; } } else if (isTouchNavigationEvent(event)) { if (onTouchNavigationKeyEvent(event)) { return true; } } else if (isKeyboardEvent(event)) { if (onKeyboardKeyEvent(event)) { return true; } } return super.dispatchKeyEvent(event); }
From source file:com.lemon.lime.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getBatteryPercentage();/*w ww .ja v a2s . c om*/ setContentView(R.layout.activity_main); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(false); mWebView = (ObservableWebView) findViewById(R.id.activity_main_webview); mWebView.setScrollViewCallbacks(this); LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflator.inflate(R.layout.bar, null); getSupportActionBar().setCustomView(v); WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath()); swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipeToRefresh); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mWebView.reload(); } }); swipeLayout.setColorSchemeResources(R.color.lili, R.color.colorPrimary, R.color.red); window = getWindow(); favicon = (ImageView) findViewById(R.id.favicon); editurl = (EditText) findViewById(R.id.editurl); mWebView.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Uri uri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } }); favicon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (lili == 5) { lilimode(); lili = 0; lilimode = true; } else { lili = lili + 1; } } }); editurl.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) { if (event.getAction() == KeyEvent.ACTION_UP) { if (editurl.getText().toString().contains("file:///")) { filemgr(); } else if (editurl.getText().toString().contains("gaymode")) { gaymode(); } else if (editurl.getText().toString().contains("exitapp")) { finish(); } else if (editurl.getText().toString().contains("light")) { flash(); } if (isconnected()) { if (editurl.getText().toString().contains("http://") || editurl.getText().toString().contains("https://")) { mWebView.loadUrl(editurl.getText().toString()); } else if (editurl.getText().toString().contains(".com") || editurl.getText().toString().contains(".net") || editurl.getText().toString().contains(".org") || editurl.getText().toString().contains(".gov") || editurl.getText().toString().contains(".hu") || editurl.getText().toString().contains(".sk") || editurl.getText().toString().contains(".co.uk") || editurl.getText().toString().contains(".co.in") || editurl.getText().toString().contains(".cn") || editurl.getText().toString().contains(".it") || editurl.getText().toString().contains(".de") || editurl.getText().toString().contains(".aus") || editurl.getText().toString().contains(".hr") || editurl.getText().toString().contains(".cz") || editurl.getText().toString().contains(".xyz") || editurl.getText().toString().contains(".pl") || editurl.getText().toString().contains(".io")) { mWebView.loadUrl("http://" + editurl.getText().toString()); InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editurl.getWindowToken(), 0); } else { mWebView.loadUrl("https://www.google.com/search?q=" + editurl.getText().toString()); InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editurl.getWindowToken(), 0); } } return true; } return false; } return true; } }); // Enable Javascript WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); webSettings.setSupportMultipleWindows(true); if (isconnected()) { mWebView.loadUrl("http://google.com"); } else { final View coordinatorLayoutView = findViewById(R.id.snackbarPosition); mWebView.loadUrl("file:///android_asset/nonet.html"); Snackbar snackbar = Snackbar.make(coordinatorLayoutView, R.string.offline, Snackbar.LENGTH_LONG); snackbar.show(); } mWebView.setWebChromeClient(new WebChromeClient() { @Override public void onReceivedIcon(WebView mWebView, Bitmap icon) { super.onReceivedIcon(mWebView, icon); favicon.setImageBitmap(icon); } public void onProgressChanged(WebView view, int progress) { activity.setProgress(progress * 100); int a = progress; if (lilimode) { editurl.setText("Liling: " + Integer.toString(a) + "?"); } else editurl.setText("Liming: " + Integer.toString(a) + "%"); if (progress == 100) { editurl.setHint(view.getTitle()); activity.setTitle(view.getTitle()); editurl.setText(view.getUrl()); fav(); //battery if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (level <= 20) { window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setNavigationBarColor(Color.RED); window.setStatusBarColor(Color.RED); getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.RED)); } } } } }); mWebView.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView mWebView, String url) { swipeLayout.setRefreshing(false); } }); }
From source file:com.grass.caishi.cc.activity.SettingUserActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { // ?/*from w w w .j av a 2s .c om*/ if (isRefresh) { Intent it = new Intent(); it.putExtra("info", userInfo); setResult(888, it); finish(); } } return super.onKeyDown(keyCode, event); }
From source file:com.cse3310.phms.ui.activities.BaseActivity.java
private void setUpAutoCompleteTextView() { mAutoCompTextView.setAdapter(mSuggestionAdapter); // listener for close/open of search field mAutoCompTextView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() { @Override/*from w ww.j a v a 2 s .c om*/ public void onViewAttachedToWindow(View v) { v.requestFocus(); Keyboard.show(mInputManager, mAutoCompTextView); } @Override public void onViewDetachedFromWindow(View v) { Keyboard.hide(mInputManager, mAutoCompTextView); } }); // listener for when a suggestion is click mAutoCompTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Keyboard.hide(mInputManager, mAutoCompTextView); doSearch(); } }); // listener for when the search key on the keyboard is pressed mAutoCompTextView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) { Keyboard.hide(mInputManager, mAutoCompTextView); mAutoCompTextView.dismissDropDown(); // hide suggestion doSearch(); return true; } return false; } }); // handler for the clear input button to the right of the search text view. mAutoCompTextView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_RIGHT = 2; if (event.getAction() == MotionEvent.ACTION_UP) { // some magic... :| to get the delete text icon to work if (event.getX() >= (mAutoCompTextView.getRight() - mAutoCompTextView.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { mAutoCompTextView.setText(""); // set search text view to empty string. return true; } } return false; } }); }
From source file:com.trellmor.berrytubechat.ChatActivity.java
@SuppressLint("NewApi") @Override/*from w w w . j av a 2 s .c om*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { getActionBar().setDisplayHomeAsUpEnabled(false); } mEditChatMsg = (EditText) findViewById(R.id.edit_chat_msg); TextView.OnEditorActionListener chatMsgListener = new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEND) { sendChatMsg(); } else if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { sendChatMsg(); } return true; } }; mEditChatMsg.setOnEditorActionListener(chatMsgListener); mTextDrinks = (TextView) findViewById(R.id.text_drinks); registerForContextMenu(mTextDrinks); mCurrentVideo = (TextView) findViewById(R.id.text_video); mCurrentVideo.setMovementMethod(LinkMovementMethod.getInstance()); mTextNick = (TextView) findViewById(R.id.text_nick); mTextNick.setText("Anonymous"); mListChat = (ListView) findViewById(R.id.list_chat); Intent intent = getIntent(); mUsername = intent.getStringExtra(MainActivity.KEY_USERNAME); mPassword = intent.getStringExtra(MainActivity.KEY_PASSWORD); if (savedInstanceState != null) { mDrinkCount = savedInstanceState.getInt(KEY_DRINKCOUT); mMyDrinkCount = savedInstanceState.getInt(KEY_MYDRINKCOUNT); if (mUsername == null) mUsername = savedInstanceState.getString(MainActivity.KEY_USERNAME); if (mPassword == null) mPassword = savedInstanceState.getString(MainActivity.KEY_PASSWORD); } startService(new Intent(this, BerryTube.class)); bindService(new Intent(this, BerryTube.class), mService, BIND_ABOVE_CLIENT); }
From source file:org.petero.droidfish.activities.EditBoard.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case EDIT_DIALOG: { final int SIDE_TO_MOVE = 0; final int CLEAR_BOARD = 1; final int INITIAL_POS = 2; final int CASTLING_FLAGS = 3; final int EN_PASSANT_FILE = 4; final int MOVE_COUNTERS = 5; final int COPY_POSITION = 6; final int PASTE_POSITION = 7; final int GET_FEN = 8; List<CharSequence> lst = new ArrayList<CharSequence>(); List<Integer> actions = new ArrayList<Integer>(); lst.add(getString(R.string.side_to_move)); actions.add(SIDE_TO_MOVE);/*www . jav a2 s .c o m*/ lst.add(getString(R.string.clear_board)); actions.add(CLEAR_BOARD); lst.add(getString(R.string.initial_position)); actions.add(INITIAL_POS); lst.add(getString(R.string.castling_flags)); actions.add(CASTLING_FLAGS); lst.add(getString(R.string.en_passant_file)); actions.add(EN_PASSANT_FILE); lst.add(getString(R.string.move_counters)); actions.add(MOVE_COUNTERS); lst.add(getString(R.string.copy_position)); actions.add(COPY_POSITION); lst.add(getString(R.string.paste_position)); actions.add(PASTE_POSITION); if (DroidFish.hasFenProvider(getPackageManager())) { lst.add(getString(R.string.get_fen)); actions.add(GET_FEN); } final List<Integer> finalActions = actions; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.edit_board); builder.setItems(lst.toArray(new CharSequence[lst.size()]), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { switch (finalActions.get(item)) { case SIDE_TO_MOVE: showDialog(SIDE_DIALOG); setSelection(-1); checkValidAndUpdateMaterialDiff(); break; case CLEAR_BOARD: { Position pos = new Position(); cb.setPosition(pos); setSelection(-1); checkValidAndUpdateMaterialDiff(); break; } case INITIAL_POS: { try { Position pos = TextIO.readFEN(TextIO.startPosFEN); cb.setPosition(pos); setSelection(-1); checkValidAndUpdateMaterialDiff(); } catch (ChessParseError e) { } break; } case CASTLING_FLAGS: removeDialog(CASTLE_DIALOG); showDialog(CASTLE_DIALOG); setSelection(-1); checkValidAndUpdateMaterialDiff(); break; case EN_PASSANT_FILE: removeDialog(EP_DIALOG); showDialog(EP_DIALOG); setSelection(-1); checkValidAndUpdateMaterialDiff(); break; case MOVE_COUNTERS: removeDialog(MOVCNT_DIALOG); showDialog(MOVCNT_DIALOG); setSelection(-1); checkValidAndUpdateMaterialDiff(); break; case COPY_POSITION: { setPosFields(); String fen = TextIO.toFEN(cb.pos) + "\n"; ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(fen); setSelection(-1); break; } case PASTE_POSITION: { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (clipboard.hasText()) { String fen = clipboard.getText().toString(); setFEN(fen); } break; } case GET_FEN: Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.setType("application/x-chess-fen"); try { startActivityForResult(i, RESULT_GET_FEN); } catch (ActivityNotFoundException e) { Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show(); } } } }); AlertDialog alert = builder.create(); return alert; } case SIDE_DIALOG: { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.select_side_to_move_first); final int selectedItem = (cb.pos.whiteMove) ? 0 : 1; builder.setSingleChoiceItems(new String[] { getString(R.string.white), getString(R.string.black) }, selectedItem, new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (id == 0) { // white to move cb.pos.setWhiteMove(true); checkValidAndUpdateMaterialDiff(); dialog.cancel(); } else { cb.pos.setWhiteMove(false); checkValidAndUpdateMaterialDiff(); dialog.cancel(); } } }); AlertDialog alert = builder.create(); return alert; } case CASTLE_DIALOG: { final CharSequence[] items = { getString(R.string.white_king_castle), getString(R.string.white_queen_castle), getString(R.string.black_king_castle), getString(R.string.black_queen_castle) }; boolean[] checkedItems = { cb.pos.h1Castle(), cb.pos.a1Castle(), cb.pos.h8Castle(), cb.pos.a8Castle() }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.castling_flags); builder.setMultiChoiceItems(items, checkedItems, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { Position pos = new Position(cb.pos); boolean a1Castle = pos.a1Castle(); boolean h1Castle = pos.h1Castle(); boolean a8Castle = pos.a8Castle(); boolean h8Castle = pos.h8Castle(); switch (which) { case 0: h1Castle = isChecked; break; case 1: a1Castle = isChecked; break; case 2: h8Castle = isChecked; break; case 3: a8Castle = isChecked; break; } int castleMask = 0; if (a1Castle) castleMask |= 1 << Position.A1_CASTLE; if (h1Castle) castleMask |= 1 << Position.H1_CASTLE; if (a8Castle) castleMask |= 1 << Position.A8_CASTLE; if (h8Castle) castleMask |= 1 << Position.H8_CASTLE; pos.setCastleMask(castleMask); cb.setPosition(pos); checkValidAndUpdateMaterialDiff(); } }); AlertDialog alert = builder.create(); return alert; } case EP_DIALOG: { final CharSequence[] items = { "A", "B", "C", "D", "E", "F", "G", "H", getString(R.string.none) }; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.select_en_passant_file); builder.setSingleChoiceItems(items, getEPFile(), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { setEPFile(item); dialog.cancel(); } }); AlertDialog alert = builder.create(); return alert; } case MOVCNT_DIALOG: { View content = View.inflate(this, R.layout.edit_move_counters, null); final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(content); builder.setTitle(R.string.edit_move_counters); final EditText halfMoveClock = (EditText) content.findViewById(R.id.ed_cnt_halfmove); final EditText fullMoveCounter = (EditText) content.findViewById(R.id.ed_cnt_fullmove); halfMoveClock.setText(String.format(Locale.US, "%d", cb.pos.halfMoveClock)); fullMoveCounter.setText(String.format(Locale.US, "%d", cb.pos.fullMoveCounter)); final Runnable setCounters = new Runnable() { public void run() { try { int halfClock = Integer.parseInt(halfMoveClock.getText().toString()); int fullCount = Integer.parseInt(fullMoveCounter.getText().toString()); cb.pos.halfMoveClock = halfClock; cb.pos.fullMoveCounter = fullCount; } catch (NumberFormatException nfe) { Toast.makeText(getApplicationContext(), R.string.invalid_number_format, Toast.LENGTH_SHORT) .show(); } } }; builder.setPositiveButton("Ok", new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { setCounters.run(); } }); builder.setNegativeButton("Cancel", null); final Dialog dialog = builder.create(); fullMoveCounter.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { setCounters.run(); dialog.cancel(); return true; } return false; } }); return dialog; } } return null; }
From source file:com.waz.zclient.ui.cursor.CursorLayout.java
/** * EditText callback when user sent text. *///from ww w. j a va 2 s . c o m @Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEND || (actionId != EditorInfo.IME_ACTION_UNSPECIFIED && event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN)) { if (isEditingMessage()) { onApproveEditMessage(); return true; } String sendText = textView.getText().toString(); if (TextUtils.isEmpty(sendText)) { return false; } if (cursorCallback != null) { cursorCallback.onMessageSubmitted(sendText); } return true; } return false; }
From source file:com.farmerbb.notepad.activity.MainActivity.java
@Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { super.dispatchKeyShortcutEvent(event); if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) { if (getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) instanceof NoteListFragment) { NoteListFragment fragment = (NoteListFragment) getSupportFragmentManager() .findFragmentByTag("NoteListFragment"); fragment.dispatchKeyShortcutEvent(event.getKeyCode()); } else if (getSupportFragmentManager() .findFragmentById(R.id.noteViewEdit) instanceof NoteViewFragment) { NoteViewFragment fragment = (NoteViewFragment) getSupportFragmentManager() .findFragmentByTag("NoteViewFragment"); fragment.dispatchKeyShortcutEvent(event.getKeyCode()); } else if (getSupportFragmentManager() .findFragmentById(R.id.noteViewEdit) instanceof NoteEditFragment) { NoteEditFragment fragment = (NoteEditFragment) getSupportFragmentManager() .findFragmentByTag("NoteEditFragment"); fragment.dispatchKeyShortcutEvent(event.getKeyCode()); } else if (getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) instanceof WelcomeFragment) { WelcomeFragment fragment = (WelcomeFragment) getSupportFragmentManager() .findFragmentByTag("NoteListFragment"); fragment.dispatchKeyShortcutEvent(event.getKeyCode()); }//from w ww. j a v a 2s . com return true; } return super.dispatchKeyShortcutEvent(event); }