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:dev.datvt.cloudtracks.sound_cloud.LocalTracksFragment.java
private void addEvent() { search_et.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { ToolsHelper.hideKeyBoard(getActivity()); String query = search_et.getText().toString(); if (query != null) { if (query.length() > 1 && baseLocal.size() > 0) { ArrayList<Track> tmp = new ArrayList<>(); for (int z = 0; z < baseLocal.size(); z++) { if (baseLocal.get(z).title.toLowerCase().contains(query.toLowerCase())) { tmp.add(baseLocal.get(z)); }// w ww .ja v a 2 s.c om } if (tmp.size() > 0) { localTracks = tmp; setUpList(localTracks); } else { ToolsHelper.toast(ctx, getString(R.string.nothing_found)); } } } return true; } return false; } }); search_et.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) { final StringBuilder sb = new StringBuilder(charSequence.length()); sb.append(charSequence); String query = sb.toString(); if (query != null && baseLocal != null) { if (query.length() > 0 && baseLocal.size() > 0) { ArrayList<Track> tmp = new ArrayList<Track>(); for (int z = 0; z < baseLocal.size(); z++) { if (baseLocal.get(z).title.toLowerCase().contains(query.toLowerCase())) { tmp.add(baseLocal.get(z)); } } if (tmp.size() > 0) { localTracks = tmp; setUpList(localTracks); } // else { // ToolsHelper.toast(ctx, getString(R.string.nothing_found)); // } } } } @Override public void afterTextChanged(Editable editable) { } }); ref.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { try { getAllSongs(); setUpList(localTracks); } catch (Exception e) { e.printStackTrace(); } } }); back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ref.setVisibility(View.GONE); lnBack.setVisibility(View.GONE); mm.setVisibility(View.VISIBLE); showMenus(); } }); }
From source file:org.catrobat.catroid.ui.dialogs.OverwriteRenameDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_overwrite_project, null); replaceButton = (RadioButton) dialogView.findViewById(R.id.dialog_overwrite_project_radio_replace); replaceButton.setOnClickListener(this); renameButton = (RadioButton) dialogView.findViewById(R.id.dialog_overwrite_project_radio_rename); renameButton.setOnClickListener(this); projectText = (EditText) dialogView.findViewById(R.id.dialog_overwrite_project_edit); projectText.setText(programName);/*from ww w .ja v a 2 s . c o m*/ projectTextView = (TextView) dialogView.findViewById(R.id.dialog_overwrite_project_edit_text); projectTextLine = dialogView.findViewById(R.id.dialog_overwrite_project_edit_line); Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(R.string.overwrite_text) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ToastUtil.showError(context, R.string.notification_download_project_cancel); } }).create(); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); dialog.setOnShowListener(new OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); positiveButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { handleOkButton(); } }); } }); dialog.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { boolean okButtonResult = handleOkButton(); if (okButtonResult) { dismiss(); } return okButtonResult; } else if (keyCode == KeyEvent.KEYCODE_BACK) { ToastUtil.showError(context, R.string.notification_download_project_cancel); return true; } return false; } }); return dialog; }
From source file:com.manueldeveloper.VolumeButtonsListener.java
/** * Overwritten method to receive the Android key events * * @param view: View object who emit the signal (CordovaWebView) * @param keyCode: int with the identifier of the pressed key * @param keyEvent: KeyEvent object with the information of the event * * @return "boolean" which indicates if the listener has consumed the event (true) or not (false) [Always false to allow that the event spreading] * * @date 27/02/2014/* w w w . j ava 2s . c o m*/ * @version 0.0.1 * @author ManuelDeveloper(manueldeveloper@gmail.com) */ public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { // Check if the event is equal to KEY_DOWN if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) { // Check what button has been pressed if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { // Create a new JSONObject with the information and send it JSONObject info = new JSONObject(); try { info.put("signal", new String("volume-up")); sendSignal(info, true); } catch (JSONException ex) { Log.e(VolumeButtonsListener_LOG, ex.getMessage()); } } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { // Create a new JSONObject with the information and send it JSONObject info = new JSONObject(); try { info.put("signal", new String("volume-down")); sendSignal(info, true); } catch (JSONException ex) { Log.e(VolumeButtonsListener_LOG, ex.getMessage()); } } } return false; }
From source file:org.catrobat.catroid.ui.fragment.FormulaEditorVariableListFragment.java
@Override public void onListItemClick(int position) { if (!inContextMode) { formulaEditorEditText.handleKeyEvent(0, "" + adapter.getItem(position).getName()); KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK); onKey(null, keyEvent.getKeyCode(), keyEvent); }//w ww . jav a 2 s . c o m }
From source file:com.app.blockydemo.ui.fragment.FormulaEditorListFragment.java
@Override public void onListItemClick(ListView listView, View view, int position, long id) { FormulaEditorFragment formulaEditor = (FormulaEditorFragment) getActivity().getSupportFragmentManager() .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG); if (formulaEditor != null) { formulaEditor.addResourceToActiveFormula(itemsIds[position]); formulaEditor.updateButtonViewOnKeyboard(); }//from w w w . ja va 2 s. c o m KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK); onKey(null, keyEvent.getKeyCode(), keyEvent); }
From source file:org.xbmc.kore.ui.SendTextDialogFragment.java
/** * Create the dialog// ww w . j av a 2 s. com * @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:android.car.cluster.sample.MainClusterActivity.java
@Override public void onKeyEvent(KeyEvent event) { Log.i(TAG, "onKeyEvent, event: " + event); dispatchKeyEvent(event); // TODO: dispatch event doesn't work for some reason. if (event.getAction() == KeyEvent.ACTION_DOWN) { if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) { int nextItem = (mPager.getCurrentItem() + 1) % mButtonToFacet.size(); mOrderToFacet.get(nextItem).button.requestFocus(); } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) { int nextItem = (mPager.getCurrentItem() - 1); if (nextItem < 0) nextItem = mButtonToFacet.size() - 1; mOrderToFacet.get(nextItem).button.requestFocus(); }/*from w w w . ja v a2 s .c om*/ } }
From source file:org.xbmc.kore.ui.generic.SendTextDialogFragment.java
/** * Create the dialog// w ww .ja va 2 s . c om * @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.glanznig.beepme.view.MainActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { int action = event.getAction(); int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: if (action == KeyEvent.ACTION_UP) { audioManager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND); }/*from ww w. j a v a 2 s . co m*/ return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { audioManager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND); } return true; default: return super.dispatchKeyEvent(event); } }
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. ja va 2s. c om*/ 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()); }