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:org.kde.kdeconnect.Plugins.RemoteKeyboardPlugin.RemoteKeyboardPlugin.java
private boolean handleSpecialKey(int key, boolean shift, boolean ctrl, boolean alt) { int keyEvent = specialKeyMap.get(key, 0); if (keyEvent == 0) return false; InputConnection inputConn = RemoteKeyboardService.instance.getCurrentInputConnection(); // Log.d("RemoteKeyboardPlugin", "Handling special key " + key + " translated to " + keyEvent + " shift=" + shift + " ctrl=" + ctrl + " alt=" + alt); // special sequences: if (ctrl && (keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT)) { // Ctrl + right -> next word ExtractedText extractedText = inputConn.getExtractedText(new ExtractedTextRequest(), 0); int pos = getCharPos(extractedText, ' ', keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT); if (pos == -1) pos = currentTextLength(extractedText); else//from w w w. j a va 2s .co m pos++; int startPos = pos; int endPos = pos; if (shift) { // Shift -> select word (otherwise jump) Pair<Integer, Integer> sel = currentSelection(extractedText); int cursor = currentCursorPos(extractedText); // Log.d("RemoteKeyboardPlugin", "Selection (to right): " + sel.first + " / " + sel.second + " cursor: " + cursor); startPos = cursor; if (sel.first < cursor || // active selection from left to right -> grow sel.first > sel.second) // active selection from right to left -> shrink startPos = sel.first; } inputConn.setSelection(startPos, endPos); } else if (ctrl && keyEvent == KeyEvent.KEYCODE_DPAD_LEFT) { // Ctrl + left -> previous word ExtractedText extractedText = inputConn.getExtractedText(new ExtractedTextRequest(), 0); int pos = getCharPos(extractedText, ' ', keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT); if (pos == -1) pos = 0; else pos++; int startPos = pos; int endPos = pos; if (shift) { Pair<Integer, Integer> sel = currentSelection(extractedText); int cursor = currentCursorPos(extractedText); // Log.d("RemoteKeyboardPlugin", "Selection (to left): " + sel.first + " / " + sel.second + " cursor: " + cursor); startPos = cursor; if (cursor < sel.first || // active selection from right to left -> grow sel.first < sel.second) // active selection from right to left -> shrink startPos = sel.first; } inputConn.setSelection(startPos, endPos); } else if (shift && (keyEvent == KeyEvent.KEYCODE_DPAD_LEFT || keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT || keyEvent == KeyEvent.KEYCODE_DPAD_UP || keyEvent == KeyEvent.KEYCODE_DPAD_DOWN || keyEvent == KeyEvent.KEYCODE_MOVE_HOME || keyEvent == KeyEvent.KEYCODE_MOVE_END)) { // Shift + up/down/left/right/home/end long now = SystemClock.uptimeMillis(); inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0)); inputConn.sendKeyEvent( new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyEvent, 0, KeyEvent.META_SHIFT_LEFT_ON)); inputConn.sendKeyEvent( new KeyEvent(now, now, KeyEvent.ACTION_UP, keyEvent, 0, KeyEvent.META_SHIFT_LEFT_ON)); inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0)); } else if (keyEvent == KeyEvent.KEYCODE_NUMPAD_ENTER || keyEvent == KeyEvent.KEYCODE_ENTER) { // Enter key EditorInfo editorInfo = RemoteKeyboardService.instance.getCurrentInputEditorInfo(); // Log.d("RemoteKeyboardPlugin", "Enter: " + editorInfo.imeOptions); if (editorInfo != null && (((editorInfo.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0) || ctrl)) { // Ctrl+Return overrides IME_FLAG_NO_ENTER_ACTION (FIXME: make configurable?) // check for special DONE/GO/etc actions first: int[] actions = { EditorInfo.IME_ACTION_GO, EditorInfo.IME_ACTION_NEXT, EditorInfo.IME_ACTION_SEND, EditorInfo.IME_ACTION_SEARCH, EditorInfo.IME_ACTION_DONE }; // note: DONE should be last or we might hide the ime instead of "go" for (int i = 0; i < actions.length; i++) { if ((editorInfo.imeOptions & actions[i]) == actions[i]) { // Log.d("RemoteKeyboardPlugin", "Enter-action: " + actions[i]); inputConn.performEditorAction(actions[i]); return true; } } } else { // else: fall back to regular Enter-event: // Log.d("RemoteKeyboardPlugin", "Enter: normal keypress"); inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent)); inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyEvent)); } } else { // default handling: inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent)); inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyEvent)); } return true; }
From source file:android.webkit.AccessibilityInjector.java
/** * Attempts to handle key events when accessibility is turned on. * * @param event The key event to handle. * @return {@code true} if the event was handled. *///from w w w .j a v a2s. c o m public boolean handleKeyEventIfNecessary(KeyEvent event) { if (!isAccessibilityEnabled()) { mAccessibilityScriptInjected = false; toggleFallbackAccessibilityInjector(false); return false; } if (mAccessibilityScriptInjected) { // if an accessibility script is injected we delegate to it the key // handling. this script is a screen reader which is a fully fledged // solution for blind users to navigate in and interact with web // pages. if (event.getAction() == KeyEvent.ACTION_UP) { mWebViewClassic.sendBatchableInputMessage(EventHub.KEY_UP, 0, 0, event); } else if (event.getAction() == KeyEvent.ACTION_DOWN) { mWebViewClassic.sendBatchableInputMessage(EventHub.KEY_DOWN, 0, 0, event); } else { return false; } return true; } if (mAccessibilityInjectorFallback != null) { // if an accessibility injector is present (no JavaScript enabled or // the site opts out injecting our JavaScript screen reader) we let // it decide whether to act on and consume the event. return mAccessibilityInjectorFallback.onKeyEvent(event); } return false; }
From source file:org.tigase.messenger.phone.pro.conversations.chat.ChatItemFragment.java
@Override public void onEmojiDelete() { String text = this.message.getText().toString(); if (text.isEmpty()) { return;//from w w w . j a v a 2s.c o m } if ("]".equals(text.substring(text.length() - 1, text.length()))) { int index = text.lastIndexOf("["); if (index == -1) { int action = KeyEvent.ACTION_DOWN; int code = KeyEvent.KEYCODE_DEL; KeyEvent event = new KeyEvent(action, code); this.message.onKeyDown(KeyEvent.KEYCODE_DEL, event); displayTextView(); return; } Editable s = message.getText().delete(index, text.length()); displayTextView(); return; } int action = KeyEvent.ACTION_DOWN; int code = KeyEvent.KEYCODE_DEL; KeyEvent event = new KeyEvent(action, code); this.message.onKeyDown(KeyEvent.KEYCODE_DEL, event); displayTextView(); }
From source file:com.qiusheng.cast.CastActivity.java
/** * Processes volume up and volume down actions upon receiving them as key * events./*w w w . j a v a 2s. com*/ */ @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_DOWN) { double currentVolume; if (mMessageStream != null) { currentVolume = mMessageStream.getVolume(); logVIfEnabled(TAG, "Volume up from " + currentVolume); if (currentVolume < 1.0) { logVIfEnabled(TAG, "New volume: " + (currentVolume + VOLUME_INCREMENT)); onSetVolume(currentVolume + VOLUME_INCREMENT); } } else { Log.e(TAG, "dispatchKeyEvent - volume up - mMessageStream==null"); } } return true; case KeyEvent.KEYCODE_VOLUME_DOWN: if (action == KeyEvent.ACTION_DOWN) { double currentVolume; if (mMessageStream != null) { currentVolume = mMessageStream.getVolume(); logVIfEnabled(TAG, "Volume down from: " + currentVolume); if (currentVolume > 0.0) { logVIfEnabled(TAG, "New volume: " + (currentVolume - VOLUME_INCREMENT)); onSetVolume(currentVolume - VOLUME_INCREMENT); } } else { Log.e(TAG, "dispatchKeyEvent - volume down - mMessageStream==null"); } } return true; default: return super.dispatchKeyEvent(event); } }
From source file:dev.memento.MainActivity.java
private void initUI() { mDateChosenButton = (Button) findViewById(R.id.dateChosen); mDateDisplayedView = (TextView) findViewById(R.id.dateDisplayed); mNowButton = (Button) findViewById(R.id.nowButton); mNowButton.setEnabled(false);// w ww.j ava 2 s . c om mPageLoadingProgressBar = (ProgressBar) findViewById(R.id.pageLoadProgressBar); mPageLoadingProgressBar.setVisibility(View.GONE); mMementoProgressBar = (ProgressBar) findViewById(R.id.loadMementosProgressBar); mMementoProgressBar.setVisibility(View.GONE); mLocation = (AutoCompleteTextView) findViewById(R.id.locationEditText); // Load list of popular URLs so they are easier to enter String[] defaultSites = getResources().getStringArray(R.array.defaultWebsites); if (mLocationAdapter == null) mLocationAdapter = new LocationAutoCompleteAdapter(this, android.R.layout.simple_dropdown_item_1line, defaultSites); mLocation.setAdapter(mLocationAdapter); mLocation.setFocusableInTouchMode(true); mLocation.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { // Go to URL if user presses enter if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { String url = Utilities.fixUrl(mLocation.getText().toString()); if (Utilities.isArchiveUrl(url)) { // Don't do anything but load the URL if (Log.LOG) Log.d(LOG_TAG, "Loading archive URL " + url); } else if (Utilities.isValidUrl(url)) { // Always bounce to the present when the user types a URL mOriginalUrl = url; if (Log.LOG) Log.d(LOG_TAG, "Browsing to NOW " + url); mLocationAdapter.add(url); resetMementoButtons(); mCurrentMemento = null; // Clear since we are visiting a different page in the present mMementos.clear(); surfToUrl(mOriginalUrl); // Hide the virtual keyboard ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mLocation.getWindowToken(), 0); mWebview.requestFocus(); return true; } else { MainActivity.this.showToast("Please enter a valid URL."); // Put focus back in text box mHandler.postDelayed(new Runnable() { @Override public void run() { mLocation.requestFocus(); // Select all text mLocation.setSelection(0, mLocation.getText().length()); } }, 200); return true; } } return false; } }); mNextButton = (ImageButton) findViewById(R.id.next); setImageButtonEnabled(false, mNextButton, R.drawable.next_item); mNextButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Advance to next Memento Memento nextMemento = null; // This could happen if the index has not been set yet if (mMementos.getCurrentIndex() < 0) { int index = mMementos.getIndexByDate(mDateDisplayed); if (index < 0) { if (Log.LOG) Log.d(LOG_TAG, "Could not find Memento with date " + mDateDisplayed + " (" + mMementos.size() + " mementos). Try to find next another way."); // Try alternative way of getting the next memento nextMemento = mMementos.getNext(mDateDisplayed); } else { mMementos.setCurrentIndex(index); nextMemento = mMementos.getNext(); } } else { // Locate the next Memento in the list nextMemento = mMementos.getNext(); } if (nextMemento == null) { // This could happen if we got redirected to the memento and didn't know // it was the last memento, so the Next button was not disabled if (Log.LOG) Log.d(LOG_TAG, "Still could not find next Memento."); if (Log.LOG) Log.d(LOG_TAG, "Current index is " + mMementos.getCurrentIndex()); setImageButtonEnabled(false, mNextButton, R.drawable.next_item); } else { SimpleDateTime date = nextMemento.getDateTime(); //setChosenDate(nextMemento.getDateTime()); showToast("Time traveling to next Memento on " + date.dateFormatted()); if (Log.LOG) Log.d(LOG_TAG, "Going to next Memento on " + date); mDateDisplayed = date; mCurrentMemento = nextMemento; String redirectUrl = nextMemento.getUrl(); surfToUrl(redirectUrl); // Just in case it wasn't already enabled //mPreviousButton.setEnabled(true); MainActivity.this.setImageButtonEnabled(true, mPreviousButton, R.drawable.previous_item); // If this is the last memento, disable button if (mMementos.isLast(date)) setImageButtonEnabled(false, mNextButton, R.drawable.next_item); } } }); mPreviousButton = (ImageButton) findViewById(R.id.previous); setImageButtonEnabled(false, mPreviousButton, R.drawable.previous_item); mPreviousButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Advance to previous Memento Memento prevMemento = null; // This could happen if the index has not been set yet if (mMementos.getCurrentIndex() < 0) { int index = mMementos.getIndexByDate(mDateDisplayed); if (index < 0) { if (Log.LOG) Log.d(LOG_TAG, "Could not find Memento with date " + mDateDisplayed + " (" + mMementos.size() + " mementos). Try to find previous" + " another way."); // Try alternative way of getting the pervious memento prevMemento = mMementos.getPrevious(mDateDisplayed); } else { mMementos.setCurrentIndex(index); prevMemento = mMementos.getPrevious(); } } else { // Locate the prev Memento in the list prevMemento = mMementos.getPrevious(); } if (prevMemento == null) { if (Log.LOG) Log.d(LOG_TAG, "Still could not find previous Memento!"); if (Log.LOG) Log.d(LOG_TAG, "Current index is " + mMementos.getCurrentIndex()); setImageButtonEnabled(false, mPreviousButton, R.drawable.previous_item); } else { SimpleDateTime date = prevMemento.getDateTime(); showToast("Time traveling to previous Memento on " + date.dateFormatted()); if (Log.LOG) Log.d(LOG_TAG, "Going to previous Memento on " + date); mDateDisplayed = date; mCurrentMemento = prevMemento; String redirectUrl = prevMemento.getUrl(); surfToUrl(redirectUrl); // Just in case it wasn't already enabled setImageButtonEnabled(true, mNextButton, R.drawable.next_item); // If this is the first memento, disable button if (mMementos.isFirst(date)) setImageButtonEnabled(false, mPreviousButton, R.drawable.previous_item); } } }); // Idea to use placeholder and handle orientation changes ourself is from here: // http://www.devahead.com/blog/2012/01/preserving-the-state-of-an-android-webview-on-screen-orientation-change/ webViewPlaceholder = ((FrameLayout) findViewById(R.id.webViewPlaceholder)); if (mWebview == null) { mWebview = new WebView(this); mWebview.setLayoutParams( new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); mWebview.getSettings().setSupportZoom(true); mWebview.getSettings().setBuiltInZoomControls(true); mWebview.getSettings().setLoadWithOverviewMode(true); // Setting to true allows the zoom-in to work, but problems moving around. // Sometimes the underlying webview library also set faults and crashes the app // http://stackoverflow.com/questions/17187338/android-fatal-signal-11-sigsegv-in-webviewcorethre // Safer to leave off although zoom won't work. //mWebview.getSettings().setUseWideViewPort(true); mWebview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); mWebview.setScrollbarFadingEnabled(true); mWebview.getSettings().setLoadsImagesAutomatically(true); mWebview.getSettings().setJavaScriptEnabled(true); mWebview.setWebViewClient(new MementoWebViewClient()); mWebview.setWebChromeClient(new MementoWebChromClient()); mWebview.getSettings().setUserAgentString(mUserAgent); // Must be declared before favicons will be received // http://stackoverflow.com/questions/3462582/display-the-android-webviews-favicon WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath()); surfToUrl(mCurrentUrl); // Get focus away from location field mWebview.requestFocus(); } webViewPlaceholder.addView(mWebview); mWebview.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // Hide the virtual keyboard ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mLocation.getWindowToken(), 0); return false; } }); }
From source file:com.irccloud.android.activity.BaseActivity.java
public void onIRCEvent(int what, Object obj) { String message = ""; final IRCCloudJSONObject o; switch (what) { case NetworkConnection.EVENT_BADCHANNELKEY: o = (IRCCloudJSONObject) obj;/* w w w. j a v a 2 s.co m*/ runOnUiThread(new Runnable() { @Override public void run() { Server server = ServersList.getInstance().getServer(o.cid()); AlertDialog.Builder builder = new AlertDialog.Builder(BaseActivity.this); View view = getDialogTextPrompt(); TextView prompt = view.findViewById(R.id.prompt); final EditText keyinput = view.findViewById(R.id.textInput); keyinput.setText(""); keyinput.setOnEditorActionListener(new OnEditorActionListener() { public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN) { try { if (keyinput.getText() != null) conn.join(o.cid(), o.getString("chan"), keyinput.getText().toString()); } catch (Exception e) { // TODO Auto-generated catch block NetworkConnection.printStackTraceToCrashlytics(e); } ((AlertDialog) keyinput.getTag()).dismiss(); } return true; } }); try { prompt.setText("Password for " + o.getString("chan")); } catch (Exception e) { // TODO Auto-generated catch block NetworkConnection.printStackTraceToCrashlytics(e); } builder.setTitle( server.getName() + " (" + server.getHostname() + ":" + (server.getPort()) + ")"); builder.setView(view); builder.setPositiveButton("Join", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { conn.join(o.cid(), o.getString("chan"), keyinput.getText().toString()); } catch (Exception e) { // TODO Auto-generated catch block NetworkConnection.printStackTraceToCrashlytics(e); } dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog dialog = builder.create(); keyinput.setTag(dialog); dialog.setOwnerActivity(BaseActivity.this); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); dialog.show(); } }); break; case NetworkConnection.EVENT_INVALIDNICK: o = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { Server server = ServersList.getInstance().getServer(o.cid()); AlertDialog.Builder builder = new AlertDialog.Builder(BaseActivity.this); View view = getDialogTextPrompt(); TextView prompt = view.findViewById(R.id.prompt); final EditText nickinput = view.findViewById(R.id.textInput); nickinput.setText(""); nickinput.setOnEditorActionListener(new OnEditorActionListener() { public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN) { try { conn.say(o.cid(), null, "/nick " + nickinput.getText().toString()); } catch (Exception e) { // TODO Auto-generated catch block NetworkConnection.printStackTraceToCrashlytics(e); } ((AlertDialog) nickinput.getTag()).dismiss(); } return true; } }); try { String message = o.getString("invalid_nick") + " is not a valid nickname, try again"; if (server.isupport != null && server.isupport.has("NICKLEN")) message += "\n(" + server.isupport.get("NICKLEN").asText() + " chars)"; message += "."; prompt.setText(message); } catch (Exception e) { // TODO Auto-generated catch block NetworkConnection.printStackTraceToCrashlytics(e); } builder.setTitle( server.getName() + " (" + server.getHostname() + ":" + (server.getPort()) + ")"); builder.setView(view); builder.setPositiveButton("Change Nickname", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { conn.say(o.cid(), null, "/nick " + nickinput.getText().toString()); } catch (Exception e) { // TODO Auto-generated catch block NetworkConnection.printStackTraceToCrashlytics(e); } dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog dialog = builder.create(); nickinput.setTag(dialog); dialog.setOwnerActivity(BaseActivity.this); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); dialog.show(); } }); break; case NetworkConnection.EVENT_ALERT: try { o = (IRCCloudJSONObject) obj; String type = o.type(); if (type.equalsIgnoreCase("invite_only_chan")) showAlert(o.cid(), "You need an invitation to join " + o.getString("chan")); else if (type.equalsIgnoreCase("channel_full")) showAlert(o.cid(), o.getString("chan") + " isn't allowing any more members to join."); else if (type.equalsIgnoreCase("banned_from_channel")) showAlert(o.cid(), "You've been banned from " + o.getString("chan")); else if (type.equalsIgnoreCase("invalid_nickchange")) showAlert(o.cid(), o.getString("ban_channel") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("no_messages_from_non_registered")) { if (o.has("nick") && o.getString("nick").length() > 0) showAlert(o.cid(), o.getString("nick") + ": " + o.getString("msg")); else showAlert(o.cid(), o.getString("msg")); } else if (type.equalsIgnoreCase("not_registered")) { String first = o.getString("first"); if (o.has("rest")) first += " " + o.getString("rest"); showAlert(o.cid(), first + ": " + o.getString("msg")); } else if (type.equalsIgnoreCase("too_many_channels")) showAlert(o.cid(), "Couldn't join " + o.getString("chan") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("too_many_targets")) showAlert(o.cid(), o.getString("description") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("no_such_server")) showAlert(o.cid(), o.getString("server") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("unknown_command")) showAlert(o.cid(), "Unknown command: " + o.getString("command")); else if (type.equalsIgnoreCase("help_not_found")) showAlert(o.cid(), o.getString("topic") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("accept_exists")) showAlert(o.cid(), o.getString("nick") + " " + o.getString("msg")); else if (type.equalsIgnoreCase("accept_not")) showAlert(o.cid(), o.getString("nick") + " " + o.getString("msg")); else if (type.equalsIgnoreCase("nick_collision")) showAlert(o.cid(), o.getString("collision") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("nick_too_fast")) showAlert(o.cid(), o.getString("nick") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("save_nick")) showAlert(o.cid(), o.getString("nick") + ": " + o.getString("msg") + ": " + o.getString("new_nick")); else if (type.equalsIgnoreCase("unknown_mode")) showAlert(o.cid(), "Missing mode: " + o.getString("params")); else if (type.equalsIgnoreCase("user_not_in_channel")) showAlert(o.cid(), o.getString("nick") + " is not in " + o.getString("channel")); else if (type.equalsIgnoreCase("need_more_params")) showAlert(o.cid(), "Missing parameters for command: " + o.getString("command")); else if (type.equalsIgnoreCase("chan_privs_needed")) showAlert(o.cid(), o.getString("chan") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("not_on_channel")) showAlert(o.cid(), o.getString("channel") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("ban_on_chan")) showAlert(o.cid(), "You cannot change your nick to " + o.getString("proposed_nick") + " while banned on " + o.getString("channel")); else if (type.equalsIgnoreCase("cannot_send_to_chan")) showAlert(o.cid(), o.getString("channel") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("user_on_channel")) showAlert(o.cid(), o.getString("nick") + " is already a member of " + o.getString("channel")); else if (type.equalsIgnoreCase("no_nick_given")) showAlert(o.cid(), "No nickname given"); else if (type.equalsIgnoreCase("nickname_in_use")) showAlert(o.cid(), o.getString("nick") + " is already in use"); else if (type.equalsIgnoreCase("silence")) { String mask = o.getString("usermask"); if (mask.startsWith("-")) message = mask.substring(1) + " removed from silence list"; else if (mask.startsWith("+")) message = mask.substring(1) + " added to silence list"; else message = "Silence list change: " + mask; showAlert(o.cid(), message); } else if (type.equalsIgnoreCase("no_channel_topic")) showAlert(o.cid(), o.getString("channel") + ": " + o.getString("msg")); else if (type.equalsIgnoreCase("time")) { message = o.getString("time_string"); if (o.has("time_stamp") && o.getString("time_stamp").length() > 0) message += " (" + o.getString("time_stamp") + ")"; message += " " + o.getString("time_server"); showAlert(o.cid(), message); } else showAlert(o.cid(), o.getString("msg")); } catch (Exception e1) { NetworkConnection.printStackTraceToCrashlytics(e1); } break; default: break; } }
From source file:com.kaku.weac.activities.MainActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { if ((System.currentTimeMillis() - mExitTime) > 2000) { ToastUtil.showShortToast(this, getString(R.string.press_again_exit)); mExitTime = System.currentTimeMillis(); } else {/*from w ww . ja va2s . co m*/ MobclickAgent.onKillProcess(this); finish(); System.exit(0); } return true; } return super.onKeyDown(keyCode, event); }
From source file:com.amsterdam.marktbureau.makkelijkemarkt.DagvergunningFragmentKoopman.java
/** * Trigger the autocomplete on enter on the erkennings- en sollicitatenummer search textviews * @param view the autocomplete textview * @param actionId the type of action/*from w w w .j a v a 2 s . c o m*/ * @param event the type of keyevent */ @OnEditorAction({ R.id.search_erkenningsnummer, R.id.search_sollicitatienummer }) public boolean onAutoCompleteEnter(AutoCompleteTextView view, int actionId, KeyEvent event) { if (((event != null) && (event.getAction() == KeyEvent.ACTION_DOWN) && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) { showDropdown(view); } return true; }
From source file:org.cocos2dx.lib.Cocos2dxEditBoxDialog.java
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); getWindow().setBackgroundDrawable(new ColorDrawable(0x80000000)); LinearLayout layout = new LinearLayout(mParentActivity); layout.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); mTextViewTitle = new TextView(mParentActivity); LinearLayout.LayoutParams textviewParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); textviewParams.leftMargin = textviewParams.rightMargin = convertDipsToPixels(10); mTextViewTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); layout.addView(mTextViewTitle, textviewParams); mInputEditText = new EditText(mParentActivity); LinearLayout.LayoutParams editTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); editTextParams.leftMargin = editTextParams.rightMargin = convertDipsToPixels(10); layout.addView(mInputEditText, editTextParams); setContentView(layout, layoutParams); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); mInputMode = mMsg.inputMode;//ww w . j a va 2 s . c o m mInputFlag = mMsg.inputFlag; mReturnType = mMsg.returnType; mMaxLength = mMsg.maxLength; mTextViewTitle.setText(mMsg.title); mInputEditText.setText(mMsg.content); int oldImeOptions = mInputEditText.getImeOptions(); mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_FLAG_NO_EXTRACT_UI); oldImeOptions = mInputEditText.getImeOptions(); switch (mInputMode) { case kEditBoxInputModeAny: mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE; break; case kEditBoxInputModeEmailAddr: mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; break; case kEditBoxInputModeNumeric: mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED; break; case kEditBoxInputModePhoneNumber: mInputModeContraints = InputType.TYPE_CLASS_PHONE; break; case kEditBoxInputModeUrl: mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI; break; case kEditBoxInputModeDecimal: mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED; break; case kEditBoxInputModeSingleLine: mInputModeContraints = InputType.TYPE_CLASS_TEXT; break; default: break; } if (mIsMultiline) { mInputModeContraints |= InputType.TYPE_TEXT_FLAG_MULTI_LINE; } mInputEditText.setInputType(mInputModeContraints | mInputFlagConstraints); switch (mInputFlag) { case kEditBoxInputFlagPassword: mInputFlagConstraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD; break; case kEditBoxInputFlagSensitive: mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; break; case kEditBoxInputFlagInitialCapsWord: mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_WORDS; break; case kEditBoxInputFlagInitialCapsSentence: mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; break; case kEditBoxInputFlagInitialCapsAllCharacters: mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; break; default: break; } mInputEditText.setInputType(mInputFlagConstraints | mInputModeContraints); switch (mReturnType) { case kKeyboardReturnTypeDefault: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE); break; case kKeyboardReturnTypeDone: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_DONE); break; case kKeyboardReturnTypeSend: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEND); break; case kKeyboardReturnTypeSearch: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEARCH); break; case kKeyboardReturnTypeGo: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_GO); break; default: mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE); break; } if (mMaxLength > 0) { mInputEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mMaxLength) }); } Handler initHandler = new Handler(); initHandler.postDelayed(new Runnable() { public void run() { mInputEditText.requestFocus(); mInputEditText.setSelection(mInputEditText.length()); openKeyboard(); } }, 200); mInputEditText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // if user didn't set keyboard type, // this callback will be invoked twice with 'KeyEvent.ACTION_DOWN' and 'KeyEvent.ACTION_UP' if (actionId != EditorInfo.IME_NULL || (actionId == EditorInfo.IME_NULL && event != null && event.getAction() == KeyEvent.ACTION_DOWN)) { //Log.d("EditBox", "actionId: "+actionId +",event: "+event); mParentActivity.setEditBoxResult(mInputEditText.getText().toString()); closeKeyboard(); dismiss(); return true; } return false; } }); }