List of usage examples for android.text Editable append
public Editable append(char text);
From source file:com.ruesga.rview.widget.TagEditTextView.java
public void computeTags(OnComputedTagEndedListener cb) { mHandler.removeMessages(MESSAGE_CREATE_CHIP); Editable s = mTagEdit.getEditableText(); s = s.append(" "); performComputeChipsLocked(s);/*from w ww . ja v a 2 s.c o m*/ }
From source file:com.forrestguice.suntimeswidget.settings.ColorChooser.java
private void changeColor() { Editable editable = edit.getText(); int i = editable.toString().indexOf('#'); if (i != -1) // should start with a # {/*from w w w.j av a 2s . c om*/ editable.delete(i, i + 1); } editable.insert(0, "#"); while (editable.length() < 3) // supply an alpha value (FF) { editable.insert(1, "F"); } if (editable.length() == 7) { editable.insert(1, "FF"); } while (editable.length() < 9) // fill rest with "0" { editable.append("0"); } //Log.d("DEBUG", "color is " + editable.toString()); edit.setText(editable); setColor(editable.toString()); onColorChanged(getColor()); }
From source file:com.taobao.weex.dom.WXTextDomObject.java
/** * Truncate the source span to the specified lines. * Caller of this method must ensure that the lines of text is <strong>greater than desired lines and need truncate</strong>. * Otherwise, unexpected behavior may happen. * @param source The source span./*from www . j a v a 2 s . co m*/ * @param paint the textPaint * @param desired specified lines. * @param truncateAt truncate method, null value means clipping overflow text directly, non-null value means using ellipsis strategy to clip * @return The spans after clipped. */ private @NonNull Spanned truncate(@Nullable Editable source, @NonNull TextPaint paint, int desired, @Nullable TextUtils.TruncateAt truncateAt) { Spanned ret = new SpannedString(""); if (!TextUtils.isEmpty(source) && source.length() > 0) { if (truncateAt != null) { source.append(ELLIPSIS); Object[] spans = source.getSpans(0, source.length(), Object.class); for (Object span : spans) { int start = source.getSpanStart(span); int end = source.getSpanEnd(span); if (start == 0 && end == source.length() - 1) { source.removeSpan(span); source.setSpan(span, 0, source.length(), source.getSpanFlags(span)); } } } StaticLayout layout; int startOffset; while (source.length() > 1) { startOffset = source.length() - 1; if (truncateAt != null) { startOffset -= 1; } source.delete(startOffset, startOffset + 1); layout = new StaticLayout(source, paint, desired, Layout.Alignment.ALIGN_NORMAL, 1, 0, false); if (layout.getLineCount() <= 1) { ret = source; break; } } } return ret; }
From source file:org.eyeseetea.malariacare.network.CustomParser.java
@Override public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { if (tag.equalsIgnoreCase("ul")) { if (opening) { lists.push(tag);/*from w ww . ja va2 s .c om*/ } else { lists.pop(); } } else if (tag.equalsIgnoreCase("ol")) { if (opening) { lists.push(tag); olNextIndex.push(Integer.valueOf(1)).toString();//TODO: add support for lists starting other index than 1 } else { lists.pop(); olNextIndex.pop().toString(); } } else if (tag.equalsIgnoreCase("li")) { if (opening) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } String parentList = lists.peek(); if (parentList.equalsIgnoreCase("ol")) { start(output, new Ol()); output.append(olNextIndex.peek().toString() + ". "); olNextIndex.push(Integer.valueOf(olNextIndex.pop().intValue() + 1)); } else if (parentList.equalsIgnoreCase("ul")) { start(output, new Ul()); } } else { if (lists.peek().equalsIgnoreCase("ul")) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } // Nested BulletSpans increases distance between bullet and text, so we must prevent it. int bulletMargin = indent; if (lists.size() > 1) { bulletMargin = indent - bullet.getLeadingMargin(true); if (lists.size() > 2) { // This get's more complicated when we add a LeadingMarginSpan into the same line: // we have also counter it's effect to BulletSpan bulletMargin -= (lists.size() - 2) * listItemIndent; } } BulletSpan newBullet = new BulletSpan(bulletMargin); end(output, Ul.class, new LeadingMarginSpan.Standard(listItemIndent * (lists.size() - 1)), newBullet); } else if (lists.peek().equalsIgnoreCase("ol")) { if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') { output.append("\n"); } int numberMargin = listItemIndent * (lists.size() - 1); if (lists.size() > 2) { // Same as in ordered lists: counter the effect of nested Spans numberMargin -= (lists.size() - 2) * listItemIndent; } end(output, Ol.class, new LeadingMarginSpan.Standard(numberMargin)); } } } else { if (opening) Log.d("TagHandler", "Found an unsupported tag " + tag); } }
From source file:com.forrestguice.suntimeswidget.settings.ColorChooser.java
@Override public void afterTextChanged(Editable editable) { if (isRunning || isRemoving) return;/*from ww w .j a va 2 s. c om*/ isRunning = true; String text = editable.toString(); // should consist of [#][0-9][a-f] for (int j = text.length() - 1; j >= 0; j--) { if (!inputSet.contains(text.charAt(j))) { editable.delete(j, j + 1); } } text = editable.toString(); // should start with a # int i = text.indexOf('#'); if (i != -1) { editable.delete(i, i + 1); } editable.insert(0, "#"); if (editable.length() > 8) // should be no longer than 8 { editable.delete(9, editable.length()); } text = editable.toString(); String toCaps = text.toUpperCase(Locale.US); editable.clear(); editable.append(toCaps); isRunning = false; }
From source file:com.yeldi.yeldibazaar.AppDetails.java
private void startViews() { // Populate the list... ApkListAdapter la = (ApkListAdapter) getListAdapter(); for (DB.Apk apk : app.apks) la.addItem(apk);// ww w.j ava 2 s. com la.notifyDataSetChanged(); // Insert the 'infoView' (which contains the summary, various odds and // ends, and the description) into the appropriate place, if we're in // landscape mode. In portrait mode, we put it in the listview's // header.. infoView = View.inflate(this, R.layout.appinfo, null); LinearLayout landparent = (LinearLayout) findViewById(R.id.landleft); headerView.removeAllViews(); if (landparent != null) { landparent.addView(infoView); Log.d("FDroid", "Setting landparent infoview"); } else { headerView.addView(infoView); Log.d("FDroid", "Setting header infoview"); } // Set the icon... ImageView iv = (ImageView) findViewById(R.id.icon); File icon = new File(DB.getIconsPath(this), app.icon); if (icon.exists()) { iv.setImageDrawable(new BitmapDrawable(icon.getPath())); } else { iv.setImageResource(android.R.drawable.sym_def_app_icon); } // Set the title and other header details... TextView tv = (TextView) findViewById(R.id.title); tv.setText(app.name); tv = (TextView) findViewById(R.id.license); tv.setText(app.license); tv = (TextView) findViewById(R.id.status); tv = (TextView) infoView.findViewById(R.id.description); /* * The following is a quick solution to enable both text selection and * links. Causes glitches and crashes: * java.lang.IndexOutOfBoundsException: setSpan (-1 ... -1) starts * before 0 * * class CustomMovementMethod extends LinkMovementMethod { * * @Override public boolean canSelectArbitrarily () { return true; } } * * if (Utils.hasApi(11)) { tv.setTextIsSelectable(true); * tv.setMovementMethod(new CustomMovementMethod()); } else { * tv.setMovementMethod(LinkMovementMethod.getInstance()); } */ tv.setMovementMethod(LinkMovementMethod.getInstance()); // Need this to add the unimplemented support for ordered and unordered // lists to Html.fromHtml(). class HtmlTagHandler implements TagHandler { int listNum; @Override public void handleTag(boolean opening, String tag, Editable output, XMLReader reader) { if (opening && tag.equals("ul")) { listNum = -1; } else if (opening && tag.equals("ol")) { listNum = 1; } else if (tag.equals("li")) { if (opening) { if (listNum == -1) { output.append("\t"); } else { output.append("\t" + Integer.toString(listNum) + ". "); listNum++; } } else { output.append('\n'); } } } } tv.setText(Html.fromHtml(app.detail_description, null, new HtmlTagHandler())); tv = (TextView) infoView.findViewById(R.id.appid); tv.setText(app.id); tv = (TextView) infoView.findViewById(R.id.summary); tv.setText(app.summary); if (!app.apks.isEmpty()) { tv = (TextView) infoView.findViewById(R.id.permissions_list); CommaSeparatedList permsList = app.apks.get(0).detail_permissions; if (permsList == null) { tv.setText(getString(R.string.no_permissions) + '\n'); } else { Iterator<String> permissions = permsList.iterator(); StringBuilder sb = new StringBuilder(); while (permissions.hasNext()) { String permissionName = permissions.next(); try { Permission permission = new Permission(this, permissionName); sb.append("\t " + permission.getName() + '\n'); } catch (NameNotFoundException e) { Log.d("FDroid", "Can't find permission '" + permissionName + "'"); } } tv.setText(sb.toString()); } tv = (TextView) infoView.findViewById(R.id.permissions); tv.setText(getString(R.string.permissions_for_long, app.apks.get(0).version)); } }
From source file:com.air.mobilebrowser.BrowserActivity.java
/** Logs an onscreen message for debugging. */ public void logMessage(final TextView consoleView, String message, String value, int color) { if (mIsDebugEnabled && consoleView != null) { consoleView.setOnFocusChangeListener(new OnFocusChangeListener() { @Override/*from w ww . j a v a 2 s . co m*/ public void onFocusChange(View v, boolean hasFocus) { ViewParent parent = consoleView.getParent(); final ScrollView scroll = (ScrollView) parent; new Handler().postDelayed(new Runnable() { @Override public void run() { scroll.smoothScrollTo(0, consoleView.getMeasuredHeight() + 10); } }, 0); } }); Editable editable = consoleView.getEditableText(); SpannableString str = null; if (editable == null) { editable = new SpannableStringBuilder(); str = new SpannableString(message + ": " + value); str.setSpan(new ForegroundColorSpan(color), message.length() + 2, message.length() + 2 + value.length(), 0); } else { str = new SpannableString("\n" + message + ": " + value); str.setSpan(new ForegroundColorSpan(color), message.length() + 2, message.length() + 3 + value.length(), 0); } editable.append(str); consoleView.setText(editable, TextView.BufferType.EDITABLE); ViewParent parent = consoleView.getParent(); if (parent instanceof ScrollView) { final ScrollView scroll = (ScrollView) parent; new Handler().postDelayed(new Runnable() { @Override public void run() { scroll.smoothScrollTo(0, consoleView.getMeasuredHeight() + 10); } }, 1000); } } }
From source file:com.df.dfcarchecker.CarCheck.CarCheckBasicInfoFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Random r=new Random(); // int uniqueNumber =(r.nextInt(999) + 100); // uniqueId = Integer.toString(uniqueNumber); // ?uniqueId/*from w ww . j av a2 s. com*/ UUID uuid = UUID.randomUUID(); uniqueId = uuid.toString(); this.inflater = inflater; rootView = inflater.inflate(R.layout.fragment_car_check_basic_info, container, false); // <editor-fold defaultstate="collapsed" desc="??View?"> tableLayout = (TableLayout) rootView.findViewById(R.id.bi_content_table); contentLayout = (LinearLayout) rootView.findViewById(R.id.brand_input); Button vinButton = (Button) rootView.findViewById(R.id.bi_vin_button); vinButton.setOnClickListener(this); brandOkButton = (Button) rootView.findViewById(R.id.bi_brand_ok_button); brandOkButton.setEnabled(false); brandOkButton.setOnClickListener(this); brandSelectButton = (Button) rootView.findViewById(R.id.bi_brand_select_button); brandSelectButton.setEnabled(false); brandSelectButton.setOnClickListener(this); // ?? sketchPhotoEntities = new ArrayList<PhotoEntity>(); // Button matchButton = (Button) rootView.findViewById(R.id.ct_licencePhotoMatch_button); matchButton.setOnClickListener(this); // vin??? InputFilter alphaNumericFilter = new InputFilter() { @Override public CharSequence filter(CharSequence arg0, int arg1, int arg2, Spanned arg3, int arg4, int arg5) { for (int k = arg1; k < arg2; k++) { if (!Character.isLetterOrDigit(arg0.charAt(k))) { return ""; } } return null; } }; vin_edit = (EditText) rootView.findViewById(R.id.bi_vin_edit); vin_edit.setFilters(new InputFilter[] { alphaNumericFilter, new InputFilter.AllCaps() }); brandEdit = (EditText) rootView.findViewById(R.id.bi_brand_edit); displacementEdit = (EditText) rootView.findViewById(R.id.csi_displacement_edit); transmissionEdit = (EditText) rootView.findViewById(R.id.csi_transmission_edit); runEdit = (EditText) rootView.findViewById(R.id.bi_mileage_edit); // // transmissionSpinner = (Spinner)rootView.findViewById(R.id.csi_transmission_spinner); // transmissionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { // @Override // public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { // transmissionEdit.setText(adapterView.getSelectedItem().toString()); // } // // @Override // public void onNothingSelected(AdapterView<?> adapterView) { // // } // }); // ?????? ScrollView view = (ScrollView) rootView.findViewById(R.id.root); view.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); view.setFocusable(true); view.setFocusableInTouchMode(true); view.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { v.requestFocusFromTouch(); return false; } }); // ????????2? runEdit.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable edt) { String temp = edt.toString(); if (temp.contains(".")) { int posDot = temp.indexOf("."); if (posDot <= 0) return; if (temp.length() - posDot - 1 > 2) { edt.delete(posDot + 3, posDot + 4); } } else { if (temp.length() > 2) { edt.clear(); edt.append(temp.substring(0, 2)); } } } public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } }); licencePhotoMatchEdit = (EditText) rootView.findViewById(R.id.ct_licencePhotoMatch_edit); licencePhotoMatchEdit.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { licencePhotoMatchEdit.setError(null); } @Override public void afterTextChanged(Editable editable) { licencePhotoMatchEdit.setError(null); } }); // ?? carNumberEdit = (EditText) rootView.findViewById(R.id.ci_plateNumber_edit); carNumberEdit.setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(10) }); // ? portedProcedureRow = (TableRow) rootView.findViewById(R.id.ct_ported_procedure); // ?Spinner setRegLocationSpinner(); setCarColorSpinner(); setFirstLogTimeSpinner(); setManufactureTimeSpinner(); setTransferCountSpinner(); setLastTransferTimeSpinner(); setYearlyCheckAvailableDateSpinner(); setAvailableDateYearSpinner(); setBusinessInsuranceAvailableDateYearSpinner(); setOtherSpinners(); // </editor-fold> mCarSettings = new CarSettings(); // ??xml if (vehicleModel == null) { mProgressDialog = ProgressDialog.show(rootView.getContext(), null, "?..", false, false); Thread thread = new Thread(new Runnable() { @Override public void run() { try { ParseXml(); // jsonData?? if (!jsonData.equals("")) { modifyMode = true; letsEnterModifyMode(); } } catch (Exception e) { e.printStackTrace(); } } }); thread.start(); } return rootView; }
From source file:com.android.ex.chips.RecipientEditTextView.java
/** adds a recipient to the view. note that it should be called when the view has determined its size */ public void addRecipient(final RecipientEntry entry, final boolean alsoNotifyAboutDataChanges) { if (entry == null) return;/*from ww w. j a v a 2 s. co m*/ // clearComposingText(); final Editable editable = getText(); // QwertyKeyListener.markAsReplaced(editable, start, end, ""); final CharSequence chip = createChip(entry, false); if (!alsoNotifyAboutDataChanges) ++mPreviousChipsCount; // expand(); if (chip != null) editable.append(chip); sanitizeBetween(); // shrink(); }
From source file:com.android.ex.chips.RecipientEditTextView.java
/** * Show specified chip as selected. If the RecipientChip is just an email address, selecting the chip will take the * contents of the chip and place it at the end of the RecipientEditTextView for inline editing. If the * RecipientChip is a complete contact, then selecting the chip will change the background color of the chip, show * the delete icon, and a popup window with the address in use highlighted and any other alternate addresses for the * contact./* ww w. j av a 2 s. c o m*/ * * @param currentChip * Chip to select. * @return A RecipientChip in the selected state or null if the chip just contained an email address. */ private DrawableRecipientChip selectChip(final DrawableRecipientChip currentChip) { if (shouldShowEditableText(currentChip)) { final CharSequence text = currentChip.getValue(); final Editable editable = getText(); final Spannable spannable = getSpannable(); final int spanStart = spannable.getSpanStart(currentChip); final int spanEnd = spannable.getSpanEnd(currentChip); spannable.removeSpan(currentChip); editable.delete(spanStart, spanEnd); setCursorVisible(true); setSelection(editable.length()); editable.append(text); return constructChipSpan(RecipientEntry.constructFakeEntry((String) text, isValid(text.toString())), true, false); } else if (currentChip.getContactId() == RecipientEntry.GENERATED_CONTACT || currentChip.isGalContact()) { final int start = getChipStart(currentChip); final int end = getChipEnd(currentChip); getSpannable().removeSpan(currentChip); DrawableRecipientChip newChip; try { if (mNoChips) return null; newChip = constructChipSpan(currentChip.getEntry(), true, false); } catch (final NullPointerException e) { Log.e(TAG, e.getMessage(), e); return null; } final Editable editable = getText(); QwertyKeyListener.markAsReplaced(editable, start, end, ""); if (start == -1 || end == -1) Log.d(TAG, "The chip being selected no longer exists but should."); else editable.setSpan(newChip, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); newChip.setSelected(true); if (shouldShowEditableText(newChip)) scrollLineIntoView(getLayout().getLineForOffset(getChipStart(newChip))); //showAddress(newChip,mAddressPopup,getWidth()); setCursorVisible(false); return newChip; } else { final int start = getChipStart(currentChip); final int end = getChipEnd(currentChip); getSpannable().removeSpan(currentChip); DrawableRecipientChip newChip; try { newChip = constructChipSpan(currentChip.getEntry(), true, false); } catch (final NullPointerException e) { Log.e(TAG, e.getMessage(), e); return null; } final Editable editable = getText(); QwertyKeyListener.markAsReplaced(editable, start, end, ""); if (start == -1 || end == -1) Log.d(TAG, "The chip being selected no longer exists but should."); else editable.setSpan(newChip, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); newChip.setSelected(true); if (shouldShowEditableText(newChip)) scrollLineIntoView(getLayout().getLineForOffset(getChipStart(newChip))); //showAlternates(newChip,mAlternatesPopup,getWidth()); setCursorVisible(false); return newChip; } }