List of usage examples for android.text Editable length
int length();
From source file:com.ywesee.amiko.MainActivity.java
/** * Changes to "suggestView" - called from ExpertInfoView *///w w w . jav a 2s. co m public void setSuggestView() { // Enable flag mRestoringState = true; // Set view setCurrentView(mSuggestView, true); // Remove search hit counter mSearchHitsCntView.setVisibility(View.GONE); // Old search query if (!mSearchQuery.isEmpty()) mSearch.setText(mSearchQuery); else mSearch.getText().clear(); Editable s = mSearch.getText(); // Set cursor at the end Selection.setSelection(s, s.length()); // Restore search results showResults(mMedis); // Restore hint mSearch.setHint(getString(R.string.search) + " " + mActionName); // Show keyboard showSoftKeyboard(300); // Disable flag mRestoringState = false; }
From source file:com.sentaroh.android.TaskAutomation.Config.ActivityMain.java
final private void renameProfileGroupDlg(final String old_loc) { // ??// w ww . ja v a2s .co m final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // dialog.getWindow().setSoftInputMode( // WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); dialog.setContentView(R.layout.single_item_input_dlg); final TextView dlg_title = (TextView) dialog.findViewById(R.id.single_item_input_title); final EditText dlg_et_name = (EditText) dialog.findViewById(R.id.single_item_input_dir); // final TextView dlg_msg = (TextView) dialog.findViewById(R.id.single_item_input_msg); final Button btnCancel = (Button) dialog.findViewById(R.id.single_item_input_cancel_btn); final Button btnOK = (Button) dialog.findViewById(R.id.single_item_input_ok_btn); btnOK.setEnabled(false); dlg_title.setText(mContext.getString(R.string.msgs_profile_group_rename_profile_group)); CommonDialog.setDlgBoxSizeCompact(dialog); dlg_et_name.setText(old_loc); dlg_et_name.addTextChangedListener(new TextWatcher() { @Override final public void afterTextChanged(Editable s) { if (s.length() != 0) { // dlg_et_name.selectAll(); String newgrp = dlg_et_name.getText().toString(); if (!newgrp.startsWith("*")) { btnOK.setEnabled(true); for (int i = 0; i < mGlblParms.profileGroupAdapter.getCount(); i++) { if (mGlblParms.profileGroupAdapter.getItem(i).getProfileGroupName().equals(newgrp)) { btnOK.setEnabled(false); break; } } } else btnOK.setEnabled(false); } else btnOK.setEnabled(false); } @Override final public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override final public void onTextChanged(CharSequence s, int start, int before, int count) { } }); final NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override final public void positiveResponse(Context c, Object[] o) { dlg_et_name.selectAll(); String new_loc = dlg_et_name.getText().toString(); renameProfileGroup(true, old_loc, new_loc); } @Override final public void negativeResponse(Context c, Object[] o) { } }); // CANCEL? btnCancel.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { dialog.dismiss(); } }); // OK? btnOK.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { ntfy.notifyToListener(POSITIVE, null); dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btnCancel.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); // dialog.setCancelable(false); dialog.show(); }
From source file:com.sentaroh.android.TaskAutomation.Config.ActivityMain.java
final private void copyProfileGroupDlg(final String old_loc) { // ??//w w w. ja v a2 s . c o m final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // dialog.getWindow().setSoftInputMode( // WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); dialog.setContentView(R.layout.single_item_input_dlg); final TextView dlg_title = (TextView) dialog.findViewById(R.id.single_item_input_title); final EditText dlg_et_name = (EditText) dialog.findViewById(R.id.single_item_input_dir); // final TextView dlg_msg = (TextView) dialog.findViewById(R.id.single_item_input_msg); final Button btnCancel = (Button) dialog.findViewById(R.id.single_item_input_cancel_btn); final Button btnOK = (Button) dialog.findViewById(R.id.single_item_input_ok_btn); btnOK.setEnabled(false); dlg_title.setText(mContext.getString(R.string.msgs_profile_group_copy_profile_group)); CommonDialog.setDlgBoxSizeCompact(dialog); dlg_et_name.setText(old_loc); dlg_et_name.addTextChangedListener(new TextWatcher() { @Override final public void afterTextChanged(Editable s) { if (s.length() != 0) { // dlg_et_name.selectAll(); String newgrp = dlg_et_name.getText().toString(); if (!newgrp.startsWith("*")) { btnOK.setEnabled(true); for (int i = 0; i < mGlblParms.profileGroupAdapter.getCount(); i++) { if (mGlblParms.profileGroupAdapter.getItem(i).getProfileGroupName().equals(newgrp)) { btnOK.setEnabled(false); break; } } } else btnOK.setEnabled(false); } else btnOK.setEnabled(false); } @Override final public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override final public void onTextChanged(CharSequence s, int start, int before, int count) { } }); final NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override final public void positiveResponse(Context c, Object[] o) { dlg_et_name.selectAll(); String new_loc = dlg_et_name.getText().toString(); copyProfileGroup(true, old_loc, new_loc); } @Override final public void negativeResponse(Context c, Object[] o) { } }); // CANCEL? btnCancel.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { dialog.dismiss(); } }); // OK? btnOK.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { ntfy.notifyToListener(POSITIVE, null); dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btnCancel.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); // dialog.setCancelable(false); dialog.show(); }
From source file:com.sentaroh.android.TaskAutomation.Config.ActivityMain.java
final private void createNewProfileGroup() { // ??/*from www . j a v a 2 s . co m*/ final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // dialog.getWindow().setSoftInputMode( // WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); dialog.setContentView(R.layout.single_item_input_dlg); final TextView dlg_title = (TextView) dialog.findViewById(R.id.single_item_input_title); final EditText dlg_et_name = (EditText) dialog.findViewById(R.id.single_item_input_dir); // final TextView dlg_msg = (TextView) dialog.findViewById(R.id.single_item_input_msg); final Button btnCancel = (Button) dialog.findViewById(R.id.single_item_input_cancel_btn); final Button btnOK = (Button) dialog.findViewById(R.id.single_item_input_ok_btn); btnOK.setEnabled(false); dlg_title.setText(mContext.getString(R.string.msgs_profile_group_create_new_profile_group)); CommonDialog.setDlgBoxSizeCompact(dialog); dlg_et_name.addTextChangedListener(new TextWatcher() { @Override final public void afterTextChanged(Editable s) { if (s.length() != 0) { // dlg_et_name.selectAll(); String newgrp = dlg_et_name.getText().toString(); if (!newgrp.startsWith("*")) { btnOK.setEnabled(true); for (int i = 0; i < mGlblParms.profileGroupAdapter.getCount(); i++) { if (mGlblParms.profileGroupAdapter.getItem(i).getProfileGroupName().equals(newgrp)) { btnOK.setEnabled(false); break; } } } else btnOK.setEnabled(false); } else btnOK.setEnabled(false); } @Override final public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override final public void onTextChanged(CharSequence s, int start, int before, int count) { } }); final NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override final public void positiveResponse(Context c, Object[] o) { dlg_et_name.selectAll(); String newloc = dlg_et_name.getText().toString(); mGlblParms.profileGroupAdapter.add(new ProfileGroupListItem(newloc, false, 0, 0, 0)); mGlblParms.profileGroupAdapter.sort(); mGlblParms.profileGroupAdapter.notifyDataSetChanged(); ProfileListItem tpli = new ProfileListItem(); tpli.setTaskEntry(PROFILE_VERSION_CURRENT, newloc, false, System.currentTimeMillis(), "", mContext.getString(R.string.msgs_no_profile_entry), "", "", "", "", null, null); mGlblParms.profileAdapter.addDataListItem(tpli); mGlblParms.profileAdapter.updateShowList(); setProfileGroupSelectorListener(); } @Override final public void negativeResponse(Context c, Object[] o) { } }); // CANCEL? btnCancel.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { dialog.dismiss(); } }); // OK? btnOK.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { ntfy.notifyToListener(POSITIVE, null); dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btnCancel.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); // dialog.setCancelable(false); dialog.show(); }
From source file:com.android.ex.chips.RecipientEditTextView.java
private int putOffsetInRange(final int o) { int offset = o; final Editable text = getText(); final int length = text.length(); // Remove whitespace from end to find "real end" int realLength = length; for (int i = length - 1; i >= 0; i--) if (text.charAt(i) == ' ') realLength--;/* www . j ava 2s . c o m*/ else break; // If the offset is beyond or at the end of the text, // leave it alone. if (offset >= realLength) return offset; final Editable editable = getText(); while (offset >= 0 && findText(editable, offset) == -1 && findChip(offset) == null) // Keep walking backward! offset--; return offset; }
From source file:com.android.ex.chips.RecipientEditTextView.java
private void expand() { if (mShouldShrink) setMaxLines(Integer.MAX_VALUE); removeMoreChip();/*ww w.ja v a 2 s . co m*/ setCursorVisible(true); final Editable text = getText(); setSelection(text != null && text.length() > 0 ? text.length() : 0); // If there are any temporary chips, try replacing them now that the user // has expanded the field. if (mTemporaryRecipients != null && mTemporaryRecipients.size() > 0) { new RecipientReplacementTask().execute(); mTemporaryRecipients = null; } }
From source file:com.android.ex.chips.RecipientEditTextView.java
/** * Remove any characters after the last valid chip. *//* ww w.ja v a2 s .co m*/ // Visible for testing. /* package */void sanitizeEnd() { // Don't sanitize while we are waiting for pending chips to complete. if (mPendingChipsCount > 0) return; // Find the last chip; eliminate any commit characters after it. final DrawableRecipientChip[] chips = getSortedRecipients(); final Spannable spannable = getSpannable(); if (chips != null && chips.length > 0) { int end; mMoreChip = getMoreChip(); if (mMoreChip != null) end = spannable.getSpanEnd(mMoreChip); else end = getSpannable().getSpanEnd(getLastChip()); final Editable editable = getText(); final int length = editable.length(); if (length > end) { // See what characters occur after that and eliminate them. if (Log.isLoggable(TAG, Log.DEBUG)) Log.d(TAG, "There were extra characters after the last tokenizable entry." + editable); editable.delete(end + 1, length); } } }
From source file:com.android.ex.chips.RecipientEditTextView.java
int countTokens(final Editable text) { int tokenCount = 0; int start = 0; while (start < text.length()) { start = movePastTerminators(mTokenizer.findTokenEnd(text, start)); tokenCount++;/*www . j a v a 2 s. co m*/ if (start >= text.length()) break; } return tokenCount; }
From source file:com.android.ex.chips.RecipientEditTextView.java
void sanitizeBetween() { // Don't sanitize while we are waiting for content to chipify. if (mPendingChipsCount > 0) return;/*from w w w . j a v a2s .c om*/ // Find the last chip. final DrawableRecipientChip[] recips = getSortedRecipients(); if (recips != null && recips.length > 0) { final DrawableRecipientChip last = recips[recips.length - 1]; DrawableRecipientChip beforeLast = null; if (recips.length > 1) beforeLast = recips[recips.length - 2]; int startLooking = 0; final int end = getSpannable().getSpanStart(last); if (beforeLast != null) { startLooking = getSpannable().getSpanEnd(beforeLast); final Editable text = getText(); if (startLooking == -1 || startLooking > text.length() - 1) // There is nothing after this chip. return; if (text.charAt(startLooking) == ' ') startLooking++; } if (startLooking >= 0 && end >= 0 && startLooking < end) getText().delete(startLooking, end); } }
From source file:cgeo.geocaching.CacheDetailActivity.java
private void addWarning(final UnknownTagsHandler unknownTagsHandler, final Editable description) { if (unknownTagsHandler.isProblematicDetected()) { final int startPos = description.length(); final IConnector connector = ConnectorFactory.getConnector(cache); if (StringUtils.isNotEmpty(cache.getUrl())) { final Spanned tableNote = Html.fromHtml(res.getString(R.string.cache_description_table_note, "<a href=\"" + cache.getUrl() + "\">" + connector.getName() + "</a>")); description.append("\n\n").append(tableNote); description.setSpan(new StyleSpan(Typeface.ITALIC), startPos, description.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }// ww w . j a va2 s. c o m } }