List of usage examples for java.lang CharSequence length
int length();
From source file:br.msf.commons.util.CharSequenceUtils.java
/** * Removes accents and graphical symbols from words, like tilde, cute, and so on. * * @param sequence Sequence witch the its accents must be removed. * @return The sequence without accents. *//*w w w . java2 s . co m*/ protected static StringBuilder reverseInternal(final CharSequence sequence) { if (sequence == null) { return null; } final StringBuilder builder = new StringBuilder(sequence.length()); for (int i = indexOfLastChar(sequence); i >= 0; i--) { builder.append(sequence.charAt(i)); } return builder; }
From source file:Main.java
/** * Recursive binary search to find the best size for the text. *//* ww w . j av a2s. co m*/ private static float getAutofitTextSize(CharSequence text, TextPaint paint, float targetWidth, int maxLines, float low, float high, float precision, DisplayMetrics displayMetrics) { float mid = (low + high) / 2.0f; int lineCount = 1; StaticLayout layout = null; paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, mid, displayMetrics)); if (maxLines != 1) { layout = new StaticLayout(text, paint, (int) targetWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true); lineCount = layout.getLineCount(); } if (SPEW) Log.d(TAG, "low=" + low + " high=" + high + " mid=" + mid + " target=" + targetWidth + " maxLines=" + maxLines + " lineCount=" + lineCount); if (lineCount > maxLines) { // For the case that `text` has more newline characters than `maxLines`. if ((high - low) < precision) { return low; } return getAutofitTextSize(text, paint, targetWidth, maxLines, low, mid, precision, displayMetrics); } else if (lineCount < maxLines) { return getAutofitTextSize(text, paint, targetWidth, maxLines, mid, high, precision, displayMetrics); } else { float maxLineWidth = 0; if (maxLines == 1) { maxLineWidth = paint.measureText(text, 0, text.length()); } else { for (int i = 0; i < lineCount; i++) { if (layout.getLineWidth(i) > maxLineWidth) { maxLineWidth = layout.getLineWidth(i); } } } if ((high - low) < precision) { return low; } else if (maxLineWidth > targetWidth) { return getAutofitTextSize(text, paint, targetWidth, maxLines, low, mid, precision, displayMetrics); } else if (maxLineWidth < targetWidth) { return getAutofitTextSize(text, paint, targetWidth, maxLines, mid, high, precision, displayMetrics); } else { return mid; } } }
From source file:cc.softwarefactory.lokki.android.fragments.AddContactsFragment.java
private void enableSearchFilter() { inputSearch.addTextChangedListener(new TextWatcher() { @Override// ww w .j a va2s . c o m public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) { // When user changed the Text if (adapter != null) { adapter.getFilter().filter(cs); } clearFilter.setVisibility(cs.length() == 0 ? View.INVISIBLE : View.VISIBLE); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable arg0) { // TODO Auto-generated method stub } }); clearFilter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { inputSearch.setText(""); } }); }
From source file:com.moto.miletus.application.DeviceListAdapter.java
@Override public Filter getFilter() { return new Filter() { @Override//from w w w. j a v a 2 s .c o m protected FilterResults performFiltering(final CharSequence constraint) { final FilterResults results = new FilterResults(); final List<DeviceWrapper> dataSetFilter = new ArrayList<>(); if (constraint.length() == 0) { dataSetFilter.addAll(getDataSetOriginal()); } else { for (final DeviceWrapper device : getDataSetOriginal()) { if (StringUtils.containsIgnoreCase(device.getDevice().getName(), constraint.toString())) { dataSetFilter.add(device); } } } results.values = dataSetFilter; results.count = dataSetFilter.size(); return results; } @Override protected void publishResults(final CharSequence constraint, final FilterResults results) { if (results.values instanceof List) { getDataSetFilter().clear(); setDataSetFilter((List<DeviceWrapper>) results.values); sort(); } } }; }
From source file:edu.cornell.med.icb.goby.util.SimulateBisulfiteReads.java
protected void process(DoubleList methylationRates, CharSequence segmentBases, int from, Writer writer) throws IOException { readLength = Math.min(segmentBases.length(), readLength); final String trueRateFilename = FilenameUtils.removeExtension(outputFilename) + "-true-methylation.tsv"; final PrintWriter trueRateWriter = new PrintWriter(new FileWriter(trueRateFilename)); if (bisulfiteTreatment) { writeTrueRatesBisulfite(methylationRates, segmentBases, from, trueRateWriter); } else {//from www . j ava 2s. c om writeTrueRatesMutations(methylationRates, segmentBases, from, trueRateWriter); } process(segmentBases, from, writer); writer.close(); }
From source file:edu.cornell.med.icb.goby.util.SimulateBisulfiteReads.java
private CharSequence reverseComplement(CharSequence selectedReadRegion) { MutableString s = new MutableString(); s.setLength(selectedReadRegion.length()); int j = 0;// w w w . j a v a 2 s . c o m for (int i = s.length() - 1; i >= 0; i--) { char base = selectedReadRegion.charAt(i); switch (base) { case 'A': base = 'T'; break; case 'C': base = 'G'; break; case '>': base = '<'; break; case '<': base = '>'; break; case 'T': base = 'A'; break; case 'G': base = 'C'; break; default: base = 'N'; break; } s.charAt(j++, base); } return s; }
From source file:com.silentcircle.silenttext.activity.AccountCreationActivity.java
@Override public void onError(final CharSequence message) { runOnUiThread(new Runnable() { @Override/*from w w w .ja va2 s. c o m*/ public void run() { TextView error = (TextView) findViewById(R.id.error); error.setText( message == null || message.length() <= 0 ? getString(R.string.error_unknown) : message); error.setVisibility(View.VISIBLE); error.startAnimation(AnimationUtils.loadAnimation(error.getContext(), R.anim.slide_down)); handler.removeCallbacks(hideError); handler.postDelayed(hideError, 5000); } }); }
From source file:br.msf.commons.util.CharSequenceUtils.java
public static int countAscendingChain(final CharSequence sequence) { if (length(sequence) < 2) { return length(sequence); }//from w ww.j av a 2 s . com int max = 1; int count = 1; for (int i = 1; i < sequence.length(); i++) { if (sequence.charAt(i) == (sequence.charAt(i - 1) + 1)) { count++; } else { if (count > max) { max = count; } count = 1; } } if (count > max) { max = count; } return max; }
From source file:br.msf.commons.util.CharSequenceUtils.java
public static int countDescendingChain(final CharSequence sequence) { if (length(sequence) < 2) { return length(sequence); }//from w w w.j av a 2s. c om int max = 1; int count = 1; for (int i = 1; i < sequence.length(); i++) { if (sequence.charAt(i) == (sequence.charAt(i - 1) - 1)) { count++; } else { if (count > max) { max = count; } count = 1; } } if (count > max) { max = count; } return max; }