Java Code Examples for android.text.Editable#toString()
The following examples show how to use
android.text.Editable#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PublishFragment.java From Sparkplug with Eclipse Public License 1.0 | 6 votes |
private void handleAnalog(Editable s, String metricName) { synchronized (connection.getSeqLock()) { String analog = s.toString(); if (analog == null || analog.trim().isEmpty()) { return; } try { if ((double) connection.getSparkplugMetrics().get(metricName).getValue() != Double.parseDouble(s.toString())) { Log.d(TAG, "Handling analog: " + analog); Metric metric = new Metric.MetricBuilder(metricName, MetricDataType.Double, Double.parseDouble(analog)).createMetric(); queuedMetrics.put(metricName, metric); ioSubmitButton.getBackground().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY); } } catch (Exception e) { Log.d(TAG, "Failed to publish ", e); } } }
Example 2
Source File: ConversationFragment.java From Pix-Art-Messenger with GNU General Public License v3.0 | 6 votes |
public void appendText(String text, final boolean doNotAppend) { if (text == null) { return; } final Editable editable = this.binding.textinput.getText(); String previous = editable == null ? "" : editable.toString(); if (doNotAppend && !TextUtils.isEmpty(previous)) { ToastCompat.makeText(getActivity(), R.string.already_drafting_message, Toast.LENGTH_LONG).show(); return; } if (UIHelper.isLastLineQuote(previous)) { text = '\n' + text; } else if (previous.length() != 0 && !Character.isWhitespace(previous.charAt(previous.length() - 1))) { text = " " + text; } this.binding.textinput.append(text); }
Example 3
Source File: AbstractWidgetConfigActivity.java From GeometricWeather with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { setBottomSheetState(subtitleDataValues[i].equals("custom")); if (!subtitleDataValueNow.equals(subtitleDataValues[i])) { if (subtitleDataValues[i].equals("custom")) { Editable editable = subtitleInputter.getText(); if (editable != null) { subtitleDataValueNow = editable.toString(); } else { subtitleDataValueNow = ""; } } else { subtitleDataValueNow = subtitleDataValues[i]; } updateHostView(); } }
Example 4
Source File: MentionEditText.java From TikTok with Apache License 2.0 | 5 votes |
private void colorMentionString() { //reset state mIsSelected = false; if (mRangeArrayList != null) { mRangeArrayList.clear(); } Editable spannableText = getText(); if (spannableText == null || TextUtils.isEmpty(spannableText.toString())) { return; } //remove previous spans ForegroundColorSpan[] oldSpans = spannableText.getSpans(0, spannableText.length(), ForegroundColorSpan.class); for (ForegroundColorSpan oldSpan : oldSpans) { spannableText.removeSpan(oldSpan); } //find mention string and color it int lastMentionIndex = -1; String text = spannableText.toString(); Matcher matcher = mPattern.matcher(text); while (matcher.find()) { String mentionText = matcher.group(); int start; if (lastMentionIndex != -1) { start = text.indexOf(mentionText, lastMentionIndex); } else { start = text.indexOf(mentionText); } int end = start + mentionText.length(); spannableText.setSpan(new ForegroundColorSpan(mMentionTextColor), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); lastMentionIndex = end; //record all mention-string's position mRangeArrayList.add(new Range(start, end+1));//+1 because \t } }
Example 5
Source File: DeviceActivity.java From syncthing-android with Mozilla Public License 2.0 | 5 votes |
@Override public void afterTextChanged(Editable s) { if (!s.toString().equals(mDevice.name)) { mDeviceNeedsToUpdate = true; mDevice.name = s.toString(); } }
Example 6
Source File: MetInputConnection.java From mongol-library with MIT License | 5 votes |
@Override public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) { if (request == null) return null; Editable editable = getEditable(); if (editable == null) { return null; } int selStart = Selection.getSelectionStart(editable); int selEnd = Selection.getSelectionEnd(editable); ExtractedText extract = new ExtractedText(); extract.flags = 0; extract.partialStartOffset = -1; extract.partialEndOffset = -1; extract.selectionStart = selStart; extract.selectionEnd = selEnd; extract.startOffset = 0; if ((request.flags & GET_TEXT_WITH_STYLES) != 0) { extract.text = new SpannableString(editable); } else { extract.text = editable.toString(); } mMongolEditText.setExtractedTextToken(request.token); return extract; }
Example 7
Source File: ProcessFragment.java From PowerFileExplorer with GNU General Public License v3.0 | 5 votes |
public void afterTextChanged(final Editable text) { final String filesearch = text.toString(); Log.d("quicksearch", "filesearch " + filesearch); if (filesearch.length() > 0) { if (searchTask != null && searchTask.getStatus() == AsyncTask.Status.RUNNING) { searchTask.cancel(true); } searchTask = new SearchFileNameTask(); searchTask.execute(filesearch); } }
Example 8
Source File: Main.java From JotaTextEditor with Apache License 2.0 | 5 votes |
public void run() { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); int startsel = mEditor.getSelectionStart(); int endsel = mEditor.getSelectionEnd(); Editable text = mEditor.getText(); String substr = null; if (startsel != endsel) { if (endsel < startsel) { int temp = startsel; startsel = endsel; endsel = temp; } if (endsel - startsel > jp.sblo.pandora.jota.text.TextView.MAX_PARCELABLE) { Toast.makeText(Main.this, R.string.toast_overflow_of_limit, Toast.LENGTH_LONG) .show(); return; } substr = text.subSequence(startsel, endsel).toString(); } if (substr == null) { if (text.length() <= jp.sblo.pandora.jota.text.TextView.MAX_PARCELABLE) { substr = text.toString(); } } if (substr != null) { intent.putExtra(Intent.EXTRA_TEXT, substr); try { startActivity(intent); } catch (ActivityNotFoundException e) { } } }
Example 9
Source File: GroupMemberSelectorTextWatcher.java From YiBo with Apache License 2.0 | 5 votes |
@Override public void afterTextChanged(Editable s) { String filterName = s.toString(); if (StringUtil.isEmpty(filterName)) { filterName = " "; } listAdapter.getFilter().filter(filterName); listAdapter.notifyDataSetChanged(); }
Example 10
Source File: EditSpinner.java From EditSpinner with Apache License 2.0 | 5 votes |
@Override public final void afterTextChanged(Editable s) { String key = s.toString(); editText.setSelection(key.length()); if (!TextUtils.isEmpty(key)) { showFilterData(key); } else { popupWindow.dismiss(); } }
Example 11
Source File: AdapterInputConnection.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * @see BaseInputConnection#getExtractedText(android.view.inputmethod.ExtractedTextRequest, * int) */ @Override public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) { if (DEBUG) Log.w(TAG, "getExtractedText"); ExtractedText et = new ExtractedText(); Editable editable = getEditable(); et.text = editable.toString(); et.partialEndOffset = editable.length(); et.selectionStart = Selection.getSelectionStart(editable); et.selectionEnd = Selection.getSelectionEnd(editable); et.flags = mSingleLine ? ExtractedText.FLAG_SINGLE_LINE : 0; return et; }
Example 12
Source File: ViewerActivityController.java From document-viewer with GNU General Public License v3.0 | 5 votes |
@ActionMethod(ids = R.id.actions_addBookmark) public void addBookmark(final ActionEx action) { final Editable value = action.getParameter("input"); final String name = value.toString(); final Page page = documentModel.getCurrentPageObject(); if (page != null) { final ViewState state = ViewState.get(getDocumentController()); final PointF pos = state.getPositionOnPage(page); bookSettings.bookmarks.add(new Bookmark(name, documentModel.getCurrentIndex(), pos.x, pos.y)); Collections.sort(bookSettings.bookmarks); SettingsManager.storeBookSettings(bookSettings); UIManagerAppCompat.invalidateOptionsMenu(getManagedComponent()); state.release(); } }
Example 13
Source File: IpInputEditText.java From v9porn with MIT License | 5 votes |
private void pressTextChange(Editable s, AppCompatEditText currenAppCompatEditText, AppCompatEditText preFouceAppCompatEditText, AppCompatEditText nextFouceAppCompatEditText) { String text = s.toString(); //回退上一个 if (TextUtils.isEmpty(s)) { focusEditViewAndMoveSelection(preFouceAppCompatEditText); return; } if (!text.startsWith(ZERO_WIDTH_SPACE)) { text = text.replace(ZERO_WIDTH_SPACE, ""); text = ZERO_WIDTH_SPACE + text; currenAppCompatEditText.setText(text); moveSelectionToLast(currenAppCompatEditText); } //输入未达到最大,但包含点,则说明当前输入完成 if (text.contains(POINT_STR)) { //替换掉点,重新设置文本 text = text.replace(POINT_STR, ""); currenAppCompatEditText.setText(text); if (!TextUtils.isEmpty(text.replace(ZERO_WIDTH_SPACE, ""))) { //聚焦到下一个控件 focusEditViewAndMoveSelection(nextFouceAppCompatEditText); } //达到最大,输入完成 } else if (text.length() >= SUB_MAX_LENGTH) { int subIp = Integer.parseInt(text.replace(ZERO_WIDTH_SPACE, "")); //检查ip断合法性 if (subIp >= MAX_IP_NUM) { //清空重新输入 currenAppCompatEditText.setText(ZERO_WIDTH_SPACE); } else { //验证通过,聚焦到下一个控件 focusEditViewAndMoveSelection(nextFouceAppCompatEditText); } } }
Example 14
Source File: Register.java From MagicPrint-ECommerce-App-Android with MIT License | 5 votes |
@Override public void afterTextChanged(Editable s) { check = s.toString(); if (check.length() < 4 || check.length() > 40) { edtemail.setError("Email Must consist of 4 to 20 characters"); } else if (!check.matches("^[A-za-z0-9.@]+")) { edtemail.setError("Only . and @ characters allowed"); } else if (!check.contains("@") || !check.contains(".")) { edtemail.setError("Enter Valid Email"); } }
Example 15
Source File: ViewUtils.java From SlyceMessaging with MIT License | 5 votes |
public static String getStringFromEditText(EditText editText) { String string = null; if (editText != null) { Editable editable = editText.getText(); if ((!TextUtils.isEmpty(editable))) { string = editable.toString(); } } return string; }
Example 16
Source File: AllAppsSearchBarController.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
@Override public void afterTextChanged(final Editable s) { mQuery = s.toString(); if (mQuery.isEmpty()) { mSearchAlgorithm.cancel(true); mCb.clearSearchResult(); } else { mSearchAlgorithm.cancel(false); mSearchAlgorithm.doSearch(mQuery, mCb); } }
Example 17
Source File: CommentEditor.java From Dashchan with Apache License 2.0 | 5 votes |
@Override public FormatResult formatSelectedText(Editable editable, int what, int start, int end) { if (what == ChanMarkup.TAG_STRIKE && super.getTag(what, false) == null) { String text = editable.toString(); String textAfterSelection = text.substring(end, text.length()); Matcher matcher = MULTIPLE_STRIKES.matcher(textAfterSelection); if (matcher.find()) { String strikes = matcher.group(1); editable.replace(end, end + strikes.length(), ""); return new FormatResult(start, end); } else { StringBuilder builder = new StringBuilder(); int count = end - start; if (count > 0) { for (int i = 0; i < count; i++) { builder.append("^H"); } editable.insert(end, builder.toString()); return new FormatResult(start, end); } else { editable.insert(end, "^H"); return new FormatResult(end + 2, end + 2); } } } else { return super.formatSelectedText(editable, what, start, end); } }
Example 18
Source File: UsersView.java From android-data-binding-recyclerview with Apache License 2.0 | 4 votes |
@Nullable private static String getStringFromEditText(EditText editText) { Editable editable = editText.getText(); return editable == null ? null : editable.toString(); }
Example 19
Source File: MentionsEditText.java From Spyglass with Apache License 2.0 | 4 votes |
/** * Ensures that the text within each {@link MentionSpan} in the {@link Editable} correctly * matches what it should be outputting. If not, replace it with the correct value. * * @param text the {@link Editable} to examine */ private void ensureMentionSpanIntegrity(Editable text) { if (text == null) { return; } MentionSpan[] spans = text.getSpans(0, text.length(), MentionSpan.class); boolean spanAltered = false; for (MentionSpan span : spans) { int start = text.getSpanStart(span); int end = text.getSpanEnd(span); CharSequence spanText = text.subSequence(start, end).toString(); Mentionable.MentionDisplayMode displayMode = span.getDisplayMode(); switch (displayMode) { case PARTIAL: case FULL: String name = span.getDisplayString(); if (!name.contentEquals(spanText) && start >= 0 && start < end && end <= text.length()) { // Mention display name does not match what is being shown, // replace text in span with proper display name int cursor = getSelectionStart(); int diff = cursor - end; text.removeSpan(span); text.replace(start, end, name); if (diff > 0 && start + end + diff < text.length()) { text.replace(start + end, start + end + diff, ""); } if (name.length() > 0) { text.setSpan(span, start, start + name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } // Notify for partially deleted mentions. if (mMentionWatchers.size() > 0 && displayMode == Mentionable.MentionDisplayMode.PARTIAL) { notifyMentionPartiallyDeletedWatchers(span.getMention(), name, start, end); } spanAltered = true; } break; case NONE: default: // Mention with DisplayMode == NONE should be deleted from the text boolean hasListeners = mMentionWatchers.size() > 0; final String textBeforeDelete = hasListeners ? text.toString() : null; text.delete(start, end); setSelection(start); if (hasListeners) { notifyMentionDeletedWatchers(span.getMention(), textBeforeDelete, start, end); } spanAltered = true; break; } } // Reset input method if spans have been changed (updates suggestions) if (spanAltered) { restartInput(); } }
Example 20
Source File: TxtChapterRuleDialog.java From a with GNU General Public License v3.0 | 4 votes |
private String getEditableText(Editable editable) { if (editable == null) { return ""; } return editable.toString(); }