List of usage examples for android.view KeyEvent getAction
public final int getAction()
From source file:org.chromium.chrome.browser.media.remote.ExpandedControllerActivity.java
/** * Modify remote volume by handling volume keys. * * @param controller The remote controller through which the volume will be modified. * @param event The key event. Its keycode needs to be either {@code KEYCODE_VOLUME_DOWN} or * {@code KEYCODE_VOLUME_UP} otherwise this method will return false. * @return True if the event is handled. *//*ww w . ja v a 2 s . c o m*/ private boolean handleVolumeKeyEvent(MediaRouteController controller, KeyEvent event) { if (!controller.isBeingCast()) return false; int action = event.getAction(); int keyCode = event.getKeyCode(); // Intercept the volume keys to affect only remote volume. switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) controller.setRemoteVolume(-1); return true; case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_DOWN) controller.setRemoteVolume(1); return true; default: return false; } }
From source file:com.polyvi.xface.extension.inappbrowser.XInAppBrowser.java
/** * //from ww w . j a v a 2 s . c o m */ protected void buildEditText() { RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); OnKeyListener keyListener = new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(mEditText.getText().toString()); return true; } return false; } }; mEditText = createEditText(EDITTEXT_ID, textLayoutParams, true, mUrl, InputType.TYPE_TEXT_VARIATION_URI, EditorInfo.IME_ACTION_GO, keyListener); }
From source file:com.miz.mizuu.fragments.SearchWebMoviesFragment.java
@Override public void onViewCreated(View v, Bundle savedInstanceState) { super.onViewCreated(v, savedInstanceState); mToolbar = (Toolbar) v.findViewById(R.id.toolbar); ((MizActivity) getActivity()).setSupportActionBar(mToolbar); mProgressBar = (ProgressBar) v.findViewById(R.id.progressBar1); v.findViewById(R.id.spinner1).setVisibility(View.GONE); mListView = (ListView) v.findViewById(R.id.listView1); mListView.setOnItemClickListener(new OnItemClickListener() { @Override/*from w w w.ja va 2 s . c o m*/ public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { showMovie(arg2); } }); mListView.setEmptyView(v.findViewById(R.id.no_results)); v.findViewById(R.id.no_results).setVisibility(View.GONE); // Both the ProgressBar and ListView have been set, so let's hide the ProgressBar hideProgressBar(); mSearchField = (EditText) v.findViewById(R.id.editText1); mSearchField.setSelection(mSearchField.length()); mSearchField.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) { } @Override public void afterTextChanged(Editable s) { if (s.toString().length() > 0) searchForMovies(); else { mSearchTask.cancel(true); mResults.clear(); mAdapter.notifyDataSetChanged(); } } }); mSearchField.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN || actionId == EditorInfo.IME_ACTION_SEARCH) searchForMovies(); return true; } }); }
From source file:com.simas.vc.file_chooser.FileChooser.java
@Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.isLongPress()) { dismiss();//from ww w . j a v a2s . c o m return true; } else if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { navigateUp(); return true; } else { return false; } }
From source file:org.xbmc.kore.ui.SendTextDialogFragment.java
/** * Create the dialog/*from w w w.j a va 2 s.c om*/ * @param savedInstanceState Saved state * @return Created dialog */ @Override @SuppressWarnings("InflateParams") public Dialog onCreateDialog(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final String title = getArguments().getString(TITLE_KEY, getString(R.string.send_text)); View dialogView = getActivity().getLayoutInflater().inflate(R.layout.dialog_send_text, null); textToSend = (EditText) dialogView.findViewById(R.id.text_to_send); finishAfterSend = (CheckBox) dialogView.findViewById(R.id.send_text_done); builder.setTitle(title).setView(dialogView) .setPositiveButton(R.string.send, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mListener.onSendTextFinished(textToSend.getText().toString(), finishAfterSend.isChecked()); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mListener.onSendTextCancel(); } }); final Dialog dialog = builder.create(); textToSend.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); textToSend.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEND) { onSendTextFinished(); } // handles enter key on external keyboard, issue #99 else if (actionId == EditorInfo.IME_ACTION_UNSPECIFIED && (event != null && event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { onSendTextFinished(); } dialog.dismiss(); return false; } private void onSendTextFinished() { mListener.onSendTextFinished(textToSend.getText().toString(), finishAfterSend.isChecked()); } }); return dialog; }
From source file:com.orangelabs.rcs.ri.messaging.chat.ChatView.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* Set layout */ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); setContentView(R.layout.chat_view);//from w w w.j av a 2 s.c o m initialize(); HistoryUriBuilder uriBuilder = new HistoryUriBuilder(HistoryLog.CONTENT_URI); uriBuilder.appendProvider(ChatLog.Message.HISTORYLOG_MEMBER_ID); uriBuilder.appendProvider(FileTransferLog.HISTORYLOG_MEMBER_ID); mUriHistoryProvider = uriBuilder.build(); /* Set message composer callbacks */ mComposeText = (EditText) findViewById(R.id.userText); mComposeText.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (KeyEvent.ACTION_DOWN != event.getAction()) { return false; } switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: sendText(); return true; } return false; } }); mComposeText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // Check if the text is not null. // we do not wish to consider putting the edit text back to null // (like when sending message), is having activity if (!TextUtils.isEmpty(s)) { // Warn the composing manager that we have some activity if (mComposingManager != null) { mComposingManager.hasActivity(); } } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); /* Set send button listener */ Button sendBtn = (Button) findViewById(R.id.send_button); sendBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { sendText(); } }); /* Initialize the adapter. */ mAdapter = new ChatCursorAdapter(this, isSingleChat()); // Associate the list adapter with the ListView. ListView listView = (ListView) findViewById(android.R.id.list); listView.setAdapter(mAdapter); registerForContextMenu(listView); if (!isServiceConnected(RcsServiceName.CHAT, RcsServiceName.CONTACT, RcsServiceName.CAPABILITY, RcsServiceName.FILE_TRANSFER)) { showMessageThenExit(R.string.label_service_not_available); return; } startMonitorServices(RcsServiceName.CHAT, RcsServiceName.CONTACT, RcsServiceName.CAPABILITY, RcsServiceName.FILE_TRANSFER); mChatService = getChatApi(); mFileTransferService = getFileTransferApi(); processIntent(getIntent()); }
From source file:com.se.cronus.AbstractCActivity.java
/** * //w w w.ja va 2 s.c o m */ protected void setUpOnClicks() { // extract soon item.setOnClickListener(this); search.setOnClickListener(this); refresh.setOnClickListener(this); searchTextV.setClickable(true); searchTextV.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() != KeyEvent.ACTION_DOWN) return false; if (keyCode == KeyEvent.KEYCODE_ENTER) { // your necessary codes... onSearchClick(); return true; } if (keyCode == KeyEvent.KEYCODE_SEARCH) { // your necessary codes... onSearchClick(); return true; } return false; } }); searchTextV.setOnClickListener(this); }
From source file:org.xbmc.kore.ui.generic.SendTextDialogFragment.java
/** * Create the dialog/* w ww . jav a2 s .com*/ * @param savedInstanceState Saved state * @return Created dialog */ @NonNull @Override @SuppressWarnings("InflateParams") public Dialog onCreateDialog(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final String title = getArguments().getString(TITLE_KEY, getString(R.string.send_text)); View dialogView = getActivity().getLayoutInflater().inflate(R.layout.dialog_send_text, null); textToSend = (EditText) dialogView.findViewById(R.id.text_to_send); finishAfterSend = (CheckBox) dialogView.findViewById(R.id.send_text_done); builder.setTitle(title).setView(dialogView) .setPositiveButton(R.string.send, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mListener.onSendTextFinished(textToSend.getText().toString(), finishAfterSend.isChecked()); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mListener.onSendTextCancel(); } }); final Dialog dialog = builder.create(); textToSend.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); textToSend.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEND) { onSendTextFinished(); } // handles enter key on external keyboard, issue #99 else if (actionId == EditorInfo.IME_ACTION_UNSPECIFIED && (event != null && event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { onSendTextFinished(); } dialog.dismiss(); return false; } private void onSendTextFinished() { mListener.onSendTextFinished(textToSend.getText().toString(), finishAfterSend.isChecked()); } }); return dialog; }
From source file:com.vuze.android.remote.fragment.OpenOptionsFilesFragment.java
public View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, Bundle savedInstanceState) {// w w w.j a va 2 s. co m if (AndroidUtils.DEBUG) { Log.d(TAG, "onCreateview " + this); } FragmentActivity activity = getActivity(); Intent intent = activity.getIntent(); final Bundle extras = intent.getExtras(); if (extras == null) { Log.e(TAG, "No extras!"); } else { String remoteProfileID = extras.getString(SessionInfoManager.BUNDLE_KEY); if (remoteProfileID != null) { sessionInfo = SessionInfoManager.getSessionInfo(remoteProfileID, activity); } torrentID = extras.getLong("TorrentID"); } Map<?, ?> torrent = sessionInfo.getTorrent(torrentID); if (torrent == null) { // In theory TorrentOpenOptionsActivity handled this NPE already return null; } View topView = inflater.inflate(R.layout.frag_fileselection, container, false); tvScrollTitle = (TextView) topView.findViewById(R.id.files_scrolltitle); tvSummary = (TextView) topView.findViewById(R.id.files_summary); listview = (RecyclerView) topView.findViewById(R.id.files_list); listview.setLayoutManager(new PreCachingLayoutManager(getContext())); listview.setAdapter(adapter); FlexibleRecyclerSelectionListener rs = new FlexibleRecyclerSelectionListener<FilesTreeAdapter, FilesAdapterDisplayObject>() { @Override public void onItemClick(FilesTreeAdapter adapter, int position) { if (AndroidUtils.usesNavigationControl()) { FilesAdapterDisplayObject oItem = adapter.getItem(position); if (adapter.isInEditMode()) { adapter.flipWant(oItem); return; } if (oItem instanceof FilesAdapterDisplayFolder) { FilesAdapterDisplayFolder oFolder = (FilesAdapterDisplayFolder) oItem; oFolder.expand = !oFolder.expand; adapter.getFilter().filter(""); } } } @Override public boolean onItemLongClick(FilesTreeAdapter adapter, int position) { return false; } @Override public void onItemSelected(FilesTreeAdapter adapter, int position, boolean isChecked) { } @Override public void onItemCheckedChanged(FilesTreeAdapter adapter, FilesAdapterDisplayObject item, boolean isChecked) { } }; adapter = new FilesTreeAdapter(this.getActivity(), rs); adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onItemRangeChanged(int positionStart, int itemCount) { if (tvSummary != null) { tvSummary.setText(DisplayFormatters.formatByteCountToKiBEtc(adapter.getTotalSizeWanted())); } } @Override public void onChanged() { super.onChanged(); if (tvSummary != null) { tvSummary.setText(DisplayFormatters.formatByteCountToKiBEtc(adapter.getTotalSizeWanted())); } } }); adapter.setInEditMode(true); adapter.setSessionInfo(sessionInfo); adapter.setCheckOnSelectedAfterMS(0); listview.setAdapter(adapter); listview.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { { if (event.getAction() != KeyEvent.ACTION_DOWN) { return false; } switch (keyCode) { case KeyEvent.KEYCODE_DPAD_RIGHT: { // expand int i = adapter.getSelectedPosition(); FilesAdapterDisplayObject item = adapter.getItem(i); if (item instanceof FilesAdapterDisplayFolder) { if (!((FilesAdapterDisplayFolder) item).expand) { ((FilesAdapterDisplayFolder) item).expand = true; adapter.getFilter().filter(""); return true; } } break; } case KeyEvent.KEYCODE_DPAD_LEFT: { // collapse int i = adapter.getSelectedPosition(); FilesAdapterDisplayObject item = adapter.getItem(i); if (item instanceof FilesAdapterDisplayFolder) { if (((FilesAdapterDisplayFolder) item).expand) { ((FilesAdapterDisplayFolder) item).expand = false; adapter.getFilter().filter(""); return true; } } break; } } return false; } } }); listview.setOnScrollListener(new RecyclerView.OnScrollListener() { int firstVisibleItem = 0; @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); LinearLayoutManager lm = (LinearLayoutManager) listview.getLayoutManager(); int firstVisibleItem = lm.findFirstCompletelyVisibleItemPosition(); if (firstVisibleItem != this.firstVisibleItem) { this.firstVisibleItem = firstVisibleItem; FilesAdapterDisplayObject itemAtPosition = adapter.getItem(firstVisibleItem); if (itemAtPosition == null) { return; } if (itemAtPosition.parent != null) { if (tvScrollTitle != null) { tvScrollTitle.setText(itemAtPosition.parent.folder); } } else { if (tvScrollTitle != null) { tvScrollTitle.setText(""); } } } } }); if (torrent.containsKey("files")) { adapter.setTorrentID(torrentID); } else { sessionInfo.executeRpc(new RpcExecuter() { @Override public void executeRpc(TransmissionRPC rpc) { rpc.getTorrentFileInfo(TAG, torrentID, null, new TorrentListReceivedListener() { @Override public void rpcTorrentListReceived(String callID, List<?> addedTorrentMaps, List<?> removedTorrentIDs) { AndroidUtils.runOnUIThread(OpenOptionsFilesFragment.this, new Runnable() { @Override public void run() { adapter.setTorrentID(torrentID); } }); } }); } }); } if (AndroidUtils.DEBUG) { Log.d(TAG, "set " + adapter + " for " + listview + " to " + sessionInfo + "/" + torrentID); } return topView; }
From source file:com.activiti.android.ui.fragments.form.picker.IdmPickerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (getArguments() != null) { onRetrieveParameters(getArguments()); }/* w ww. j a v a 2 s .c om*/ // Create View setRootView(inflater.inflate(R.layout.fr_idm_picker, container, false)); // Init list init(getRootView(), emptyListMessageId); gv.setChoiceMode(GridView.CHOICE_MODE_SINGLE); setListShown(true); searchView = UIUtils.setActionBarCustomView(getActivity(), R.layout.person_picker_header, true); View searchBack = searchView.findViewById(R.id.search_back); searchBack.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { getActivity().getSupportFragmentManager().popBackStackImmediate(); } }); if (keywords != null && !keywords.isEmpty()) { search(keywords); } else { // Speech to Text hasTextToSpeech = FeatureUtils.hasSpeechToText(getActivity()); speechToText = (ImageButton) searchView.findViewById(R.id.search_microphone); if (hasTextToSpeech) { speechToText.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { speechToText(); } }); } else { speechToText.setVisibility(View.GONE); } searchAction = (ImageButton) searchView.findViewById(R.id.search_start); searchAction.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (searchForm.getText().length() > 0) { keywords = searchForm.getText().toString(); search(keywords); } else { // TODO Snackbar } } }); searchAction.setVisibility(View.GONE); // Init form search searchForm = (EditText) searchView.findViewById(R.id.search_query); searchForm.requestFocus(); UIUtils.showKeyboard(getActivity(), searchForm); searchForm.setImeOptions(EditorInfo.IME_ACTION_SEARCH); searchForm.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { if (s.length() == 0) { searchAction.setVisibility(View.GONE); if (hasTextToSpeech) { speechToText.setVisibility(View.VISIBLE); } } else { speechToText.setVisibility(View.GONE); searchAction.setVisibility(View.VISIBLE); } } }); 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) || (actionId == EditorInfo.IME_ACTION_DONE))) { if (searchForm.getText().length() > 0) { keywords = searchForm.getText().toString(); search(keywords); } else { // TODO Snackbar } return true; } return false; } }); } if (getMode() == MODE_PICK) { Button cancel = UIUtils.initCancel(getRootView(), R.string.general_action_cancel); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (getDialog() != null) { getDialog().dismiss(); } else { getFragmentManager().popBackStack(); } } }); } else { hide(R.id.validation_panel); } return getRootView(); }