List of usage examples for android.text.method TextKeyListener clear
public static void clear(Editable e)
From source file:com.sir_m2x.messenger.activities.ChatWindowFragment.java
private void sendIM() { String sender = MessengerService.getSession().getLoginID().getId(); String message = this.txtMessage.getText().toString(); Date timeStamp = Calendar.getInstance().getTime(); IM im = new IM(sender, message, timeStamp); if (im.getMessage().equals("") || MessengerService.getSession().getSessionStatus() != SessionState.LOGGED_ON) return;/* ww w . j ava2 s. c o m*/ try { MessengerService.getSession().sendMessage(this.friendId, im.getMessage()); MessengerService.addIm(this.getActivity(), this.friendId, im); this.listAdapter.notifyDataSetChanged(); TextKeyListener.clear(this.txtMessage.getText()); // to prevent the Android's bug. // if we use setText(""), the EditText will not show typed characters after a while! // strange bug, I confess } catch (Exception e) { e.printStackTrace(); } }
From source file:org.sandholm.max.juttele.activity.ConversationActivity.java
/** * On create/*ww w . ja v a 2 s . c o m*/ */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); serverId = getIntent().getExtras().getInt("serverId"); server = Yaaic.getInstance().getServerById(serverId); Settings settings = new Settings(this); // Finish activity if server does not exist anymore - See #55 if (server == null) { this.finish(); } ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); setTitle(server.getTitle()); setContentView(R.layout.conversations); boolean isLandscape = (getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE); EditText input = (EditText) findViewById(R.id.input); input.setOnKeyListener(inputKeyListener); input.setOnEditorActionListener(new TextView.OnEditorActionListener() { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEND) { sendMessage(v.getText().toString()); // Workaround for a race condition in EditText // Instead of calling input.setText(""); // See: // - https://github.com/pocmo/Yaaic/issues/67 // - http://code.google.com/p/android/issues/detail?id=17508 TextKeyListener.clear(v.getEditableText()); return true; } else { return false; } } }); input.setHint(server.getIdentity().getNickname()); pager = (ViewPager) findViewById(R.id.pager); pagerAdapter = new ConversationPagerAdapter(this, server); pager.setAdapter(pagerAdapter); final float density = getResources().getDisplayMetrics().density; indicator = (ConversationIndicator) findViewById(R.id.titleIndicator); indicator.setServer(server); //indicator.setTypeface(Typeface.MONOSPACE); indicator.setViewPager(pager); //indicator.setFooterColor(0xFF31B6E7); indicator.setFooterLineHeight(1 * density); indicator.setFooterIndicatorHeight(3 * density); indicator.setFooterIndicatorStyle(IndicatorStyle.Underline); indicator.setSelectedColor(0xFFFFFFFF); indicator.setSelectedBold(true); //indicator.setBackgroundColor(0xFF181818); historySize = settings.getHistorySize(); if (server.getStatus() == Status.PRE_CONNECTING) { server.clearConversations(); pagerAdapter.clearConversations(); server.getConversation(ServerInfo.DEFAULT_NAME).setHistorySize(historySize); } float fontSize = settings.getFontSize(); indicator.setTextSize(fontSize * density); input.setTextSize(settings.getFontSize()); //input.setTypeface(Typeface.MONOSPACE); // Optimization : cache field lookups Collection<Conversation> mConversations = server.getConversations(); for (Conversation conversation : mConversations) { // Only scroll to new conversation if it was selected before if (conversation.getStatus() == Conversation.STATUS_SELECTED) { onNewConversation(conversation.getName()); } else { createNewConversation(conversation.getName()); } } int setInputTypeFlags = 0; setInputTypeFlags |= InputType.TYPE_TEXT_FLAG_AUTO_CORRECT; if (settings.autoCapSentences()) { setInputTypeFlags |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; } if (isLandscape && settings.imeExtract()) { setInputTypeFlags |= InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE; } if (!settings.imeExtract()) { input.setImeOptions(input.getImeOptions() | EditorInfo.IME_FLAG_NO_EXTRACT_UI); } input.setInputType(input.getInputType() | setInputTypeFlags); // Create a new scrollback history scrollback = new Scrollback(); }
From source file:com.limewoodmedia.nsdroid.fragments.RMBFragment.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.rmb_post_close: closeMessageBox();/* ww w . jav a 2 s. co m*/ break; case R.id.rmb_post_send: if (messageBox.getText().length() == 0) { Toast.makeText(context, R.string.rmb_post_no_text, Toast.LENGTH_SHORT).show(); break; } dimmer.getForeground().setAlpha(150); startLoading(R.string.loading_on_rmb_post); messageBox.setEnabled(false); postClose.setEnabled(false); postSend.setEnabled(false); new AsyncTask<String, Void, Boolean>() { @Override protected Boolean doInBackground(String... params) { try { if (API.getInstance(context).checkLogin(getActivity())) { return API.getInstance(context).postToRMB(region, params[0]); } } catch (IOException e) { e.printStackTrace(); } return false; } protected void onPostExecute(Boolean result) { LoadingHelper.stopLoading(loadingView); dimmer.getForeground().setAlpha(0); messageBox.setEnabled(true); postClose.setEnabled(true); postSend.setEnabled(true); if (result) { Toast.makeText(context, R.string.message_posted, Toast.LENGTH_SHORT).show(); closeMessageBox(); TextKeyListener.clear(messageBox.getText()); // Update RMB messages loadMessages(); } else { Toast.makeText(context, R.string.message_error, Toast.LENGTH_SHORT).show(); } } }.execute(messageBox.getText().toString()); break; } }
From source file:org.yaaic.fragment.ConversationFragment.java
private void sendCurrentMessage() { sendMessage(input.getText().toString()); // Workaround for a race condition in EditText // Instead of calling input.setText(""); // See:/*ww w. java 2s. com*/ // - https://github.com/pocmo/Yaaic/issues/67 // - http://code.google.com/p/android/issues/detail?id=17508 TextKeyListener.clear(input.getText()); }
From source file:com.android.mms.ui.ComposeMessageActivity.java
private void resetMessage() { if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { log("resetMessage"); }/*from w ww .j a v a 2 s . c om*/ // Make the attachment editor hide its view. mAttachmentEditor.hideView(); mAttachmentEditorScrollView.setVisibility(View.GONE); // Hide the subject editor. showSubjectEditor(false); // Focus to the text editor. mTextEditor.requestFocus(); // We have to remove the text change listener while the text editor gets cleared and // we subsequently turn the message back into SMS. When the listener is listening while // doing the clearing, it's fighting to update its counts and itself try and turn // the message one way or the other. mTextEditor.removeTextChangedListener(mTextEditorWatcher); // Clear the text box. TextKeyListener.clear(mTextEditor.getText()); mWorkingMessage.clearConversation(mConversation, false); mWorkingMessage = WorkingMessage.createEmpty(this); mWorkingMessage.setConversation(mConversation); hideRecipientEditor(); drawBottomPanel(); // "Or not", in this case. updateSendButtonState(); // Our changes are done. Let the listener respond to text changes once again. mTextEditor.addTextChangedListener(mTextEditorWatcher); // Close the soft on-screen keyboard if we're in landscape mode so the user can see the // conversation. if (mIsLandscape) { hideKeyboard(); } mLastRecipientCount = 0; mSendingMessage = false; invalidateOptionsMenu(); }