Example usage for java.lang CharSequence charAt

List of usage examples for java.lang CharSequence charAt

Introduction

In this page you can find the example usage for java.lang CharSequence charAt.

Prototype

char charAt(int index);

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:org.noise_planet.noisecapture.CommentActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_comment);

    View mainView = findViewById(R.id.mainLayout);
    if (mainView != null) {
        mainView.setOnTouchListener(new MainOnTouchListener(this));
    }/*from   w ww.j  a  va  2 s.  c  om*/

    // Read record activity parameter
    // Use last record of no parameter provided
    this.measurementManager = new MeasurementManager(this);
    Intent intent = getIntent();
    // Read the last stored record
    List<Storage.Record> recordList = measurementManager.getRecords();
    if (intent != null && intent.hasExtra(COMMENT_RECORD_ID)) {
        record = measurementManager.getRecord(intent.getIntExtra(COMMENT_RECORD_ID, -1));
    } else {
        if (!recordList.isEmpty()) {
            record = recordList.get(0);
        } else {
            // Message for starting a record
            Toast.makeText(getApplicationContext(), getString(R.string.no_results), Toast.LENGTH_LONG).show();
            return;
        }
    }
    if (record != null) {
        View addPhoto = findViewById(R.id.btn_add_photo);
        addPhoto.setOnClickListener(new OnAddPhotoClickListener(this));
        View resultsBtn = findViewById(R.id.resultsBtn);
        resultsBtn.setOnClickListener(new OnGoToResultPage(this));
        View deleteBts = findViewById(R.id.deleteBtn);
        deleteBts.setOnClickListener(new OnDeleteMeasurement(this));
        TextView noisePartyTag = (TextView) findViewById(R.id.edit_noiseparty_tag);
        noisePartyTag.setEnabled(record.getUploadId().isEmpty());
        noisePartyTag.setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter() {
            @Override
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                    int dend) {
                // [^A-Za-z0-9_]
                StringBuilder stringBuilder = new StringBuilder();
                for (int i = start; i < end; i++) {
                    char c = source.charAt(i);
                    if (Character.isLetterOrDigit(c) || c == '_') {
                        stringBuilder.append(c);
                    }
                }

                // keep original if unchanged or return swapped chars
                boolean modified = (stringBuilder.length() == end - start);
                return modified ? null : stringBuilder.toString();
            }
        } });
        if (record.getNoisePartyTag() == null) {
            // Read last stored NoiseParty id
            for (Storage.Record recordItem : recordList) {
                if (recordItem.getId() != record.getId()) {
                    if (recordItem.getNoisePartyTag() != null) {
                        noisePartyTag.setText(recordItem.getNoisePartyTag());
                    }
                    break;
                }
            }
        } else {
            noisePartyTag.setText(record.getNoisePartyTag());
        }
    }
    initDrawer(record != null ? record.getId() : null);
    SeekBar seekBar = (SeekBar) findViewById(R.id.pleasantness_slider);

    // Load stored user comment
    // Pleasantness and tags are read only if the record has been uploaded
    Map<String, Storage.TagInfo> tagToIndex = new HashMap<>(Storage.TAGS_INFO.length);
    for (Storage.TagInfo sysTag : Storage.TAGS_INFO) {
        tagToIndex.put(sysTag.name, sysTag);
    }

    View thumbnail = findViewById(R.id.image_thumbnail);
    thumbnail.setOnClickListener(new OnImageClickListener(this));
    if (record != null) {
        // Load selected tags
        for (String sysTag : measurementManager.getTags(record.getId())) {
            Storage.TagInfo tagInfo = tagToIndex.get(sysTag);
            if (tagInfo != null) {
                checkedTags.add(tagInfo.id);
            }
        }
        // Load description
        if (record.getDescription() != null) {
            TextView description = (TextView) findViewById(R.id.edit_description);
            description.setText(record.getDescription());
        }
        Integer pleasantness = record.getPleasantness();
        if (pleasantness != null) {
            seekBar.setProgress((int) (Math.round((pleasantness / 100.0) * seekBar.getMax())));
            seekBar.setThumb(
                    seekBar.getResources().getDrawable(R.drawable.seekguess_scrubber_control_normal_holo));
            userInputSeekBar.set(true);
        } else {
            seekBar.setThumb(
                    seekBar.getResources().getDrawable(R.drawable.seekguess_scrubber_control_disabled_holo));
        }
        photo_uri = record.getPhotoUri();
        // User can only update not uploaded data
        seekBar.setEnabled(record.getUploadId().isEmpty());
    } else {
        // Message for starting a record
        Toast.makeText(getApplicationContext(), getString(R.string.no_results), Toast.LENGTH_LONG).show();
    }
    thumbnailImageLayoutDoneObserver = new OnThumbnailImageLayoutDoneObserver(this);
    thumbnail.getViewTreeObserver().addOnGlobalLayoutListener(thumbnailImageLayoutDoneObserver);

    seekBar.setOnSeekBarChangeListener(new OnSeekBarUserInput(userInputSeekBar));
    // Fill tags grid
    Resources r = getResources();
    String[] tags = r.getStringArray(R.array.tags);
    // Append tags items
    for (Storage.TagInfo tagInfo : Storage.TAGS_INFO) {
        ViewGroup tagContainer = (ViewGroup) findViewById(tagInfo.location);
        if (tagContainer != null && tagInfo.id < tags.length) {
            addTag(tags[tagInfo.id], tagInfo.id, tagContainer,
                    tagInfo.color != -1 ? r.getColor(tagInfo.color) : -1);
        }
    }
}

From source file:com.jecelyin.editor.v2.core.text.TextUtils.java

public static int getOffsetAfter(CharSequence text, int offset) {
    int len = text.length();

    if (offset == len)
        return len;
    if (offset == len - 1)
        return len;

    char c = text.charAt(offset);

    if (c >= '\uD800' && c <= '\uDBFF') {
        char c1 = text.charAt(offset + 1);

        if (c1 >= '\uDC00' && c1 <= '\uDFFF')
            offset += 2;// ww w.ja  va  2 s.  c o m
        else
            offset += 1;
    } else {
        offset += 1;
    }

    if (text instanceof Spanned) {
        ReplacementSpan[] spans = ((Spanned) text).getSpans(offset, offset, ReplacementSpan.class);

        for (int i = 0; i < spans.length; i++) {
            int start = ((Spanned) text).getSpanStart(spans[i]);
            int end = ((Spanned) text).getSpanEnd(spans[i]);

            if (start < offset && end > offset)
                offset = end;
        }
    }

    return offset;
}

From source file:me.philio.pinentry.PinEntryView.java

/**
 * Create views and add them to the view group
 *//*from   www  . ja v a2 s . c o  m*/
@TargetApi(21)
private void addViews() {
    // Add a digit view for each digit
    for (int i = 0; i < mDigits; i++) {
        DigitView digitView = new DigitView(getContext());
        digitView.setWidth(mDigitWidth);
        digitView.setHeight(mDigitHeight);
        digitView.setBackgroundResource(mDigitBackground);
        digitView.setTextColor(mDigitTextColor);
        digitView.setTextSize(mDigitTextSize);
        digitView.setGravity(Gravity.CENTER);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            digitView.setElevation(mDigitElevation);
        }
        addView(digitView);
    }

    // Add an "invisible" edit text to handle input
    mEditText = new EditText(getContext());
    mEditText.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
    mEditText.setTextColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
    mEditText.setCursorVisible(false);
    mEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mDigits) });
    mEditText.setInputType(InputType.TYPE_CLASS_NUMBER);
    mEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    mEditText.setPadding(mEditText.getPaddingLeft(), mEditText.getPaddingTop(), mEditText.getPaddingRight(),
            100);
    mEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            // Update the selected state of the views
            int length = mEditText.getText().length();
            for (int i = 0; i < mDigits; i++) {
                getChildAt(i)
                        .setSelected(hasFocus && (mAccentType == ACCENT_ALL || (mAccentType == ACCENT_CHARACTER
                                && (i == length || (i == mDigits - 1 && length == mDigits)))));
            }

            // Make sure the cursor is at the end
            mEditText.setSelection(length);

            // Provide focus change events to any listener
            if (mOnFocusChangeListener != null) {
                mOnFocusChangeListener.onFocusChange(PinEntryView.this, hasFocus);
            }
        }
    });
    mEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            int length = s.length();
            for (int i = 0; i < mDigits; i++) {
                if (s.length() > i) {
                    String mask = mMask == null || mMask.length() == 0 ? String.valueOf(s.charAt(i)) : mMask;
                    ((TextView) getChildAt(i)).setText(mask);
                } else {
                    ((TextView) getChildAt(i)).setText("");
                }
                if (mEditText.hasFocus()) {
                    getChildAt(i).setSelected(mAccentType == ACCENT_ALL || (mAccentType == ACCENT_CHARACTER
                            && (i == length || (i == mDigits - 1 && length == mDigits))));
                }
            }

            if (length == mDigits && mPinEnteredListener != null) {
                mPinEnteredListener.pinEntered(s.toString());
            }
        }
    });
    addView(mEditText);
}

From source file:eu.stratosphere.types.StringValue.java

@Override
public Appendable append(CharSequence csq, int start, int end) {
    final int otherLen = end - start;
    grow(this.len + otherLen);
    for (int pos = start; pos < end; pos++) {
        this.value[this.len + pos] = csq.charAt(pos);
    }/*  w  ww. j a v  a 2 s  .  c o  m*/
    this.len += otherLen;
    return this;
}

From source file:edu.cornell.med.icb.goby.util.SimulateBisulfiteReads.java

protected void writeTrueRatesMutations(DoubleList methylationRates, CharSequence segmentBases, int from,
        Writer writer) throws IOException {

    PrintWriter trueRateWriter = new PrintWriter(writer);
    writeTrueRatesBisulfite(methylationRates, segmentBases, from, new StringWriter());
    trueRateWriter.printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s%n", "index", "methylationRate", "strand",
            "chromosome", "position", "fromBase", "toBase", "context");
    DoubleIterator it = methylationRates.iterator();

    for (int i = 0; i < segmentBases.length(); i++) {
        char fromBaseForward = segmentBases.charAt(i);

        if (fromBaseForward == 'C') {
            final int genomicPosition = i + from;
            if (!it.hasNext()) {
                it = methylationRates.iterator();
            }/*  w  ww. jav a2s .  c  o  m*/
            char toBase = '.';
            final double value = it.nextDouble();
            if (value == 1) {
                toBase = 'C';
            } else if (value == 0) {
                toBase = 'G';
            }

            methylationForward.put(genomicPosition, value);
            final double getterValue = getMethylationRateAtPosition(false, genomicPosition);
            assert getterValue == value;
            trueRateWriter.printf("%d\t%g\t+1\t%s\t%d\t%c\t%c\t%s%n", i, value, refChoice, genomicPosition + 1,
                    fromBaseForward, toBase, context(i, segmentBases));
        }
    }
    trueRateWriter.close();
}

From source file:StringUtil.java

/**
 * Converts char sequence into byte array. Chars are truncated to byte size.
 *//*from  ww  w.  ja v  a2  s.  co m*/
public static byte[] toByteArray(CharSequence charSequence) {
    if (charSequence == null) {
        return null;
    }
    byte[] barr = new byte[charSequence.length()];
    for (int i = 0; i < barr.length; i++) {
        barr[i] = (byte) charSequence.charAt(i);
    }
    return barr;
}

From source file:StringUtil.java

/**
 * Converts char sequence into ASCII array.
 *//*from  w w w  .  jav a2s  . c o m*/
public static byte[] toAsciiArray(CharSequence charSequence) {
    if (charSequence == null) {
        return null;
    }
    byte[] barr = new byte[charSequence.length()];
    for (int i = 0; i < barr.length; i++) {
        barr[i] = (byte) toAscii(charSequence.charAt(i));
    }
    return barr;
}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewBase.java

private static boolean isLabelOfPictographic(CharSequence label) {
    if (label.length() == 0)
        return false;
    final char hs = label.charAt(0);

    if (0xd800 <= hs && hs <= 0xdbff) {
        return true;
    } else if (Character.isHighSurrogate(hs)) {
        return true;
    }/*from  w w  w.j a  v a2 s .  c om*/
    return false;
}

From source file:github.daneren2005.dsub.util.Util.java

public static int getStringDistance(CharSequence s, CharSequence t) {
    if (s == null || t == null) {
        throw new IllegalArgumentException("Strings must not be null");
    }/*from   w  w w.  j av a  2s  .  co m*/

    int n = s.length();
    int m = t.length();

    if (n == 0) {
        return m;
    } else if (m == 0) {
        return n;
    }

    if (n > m) {
        final CharSequence tmp = s;
        s = t;
        t = tmp;
        n = m;
        m = t.length();
    }

    int p[] = new int[n + 1];
    int d[] = new int[n + 1];
    int _d[];

    int i;
    int j;
    char t_j;
    int cost;

    for (i = 0; i <= n; i++) {
        p[i] = i;
    }

    for (j = 1; j <= m; j++) {
        t_j = t.charAt(j - 1);
        d[0] = j;

        for (i = 1; i <= n; i++) {
            cost = s.charAt(i - 1) == t_j ? 0 : 1;
            d[i] = Math.min(Math.min(d[i - 1] + 1, p[i] + 1), p[i - 1] + cost);
        }

        _d = p;
        p = d;
        d = _d;
    }

    return p[n];
}

From source file:com.googlecode.eyesfree.brailleback.DisplayManager.java

private void calculateSplitPoints() {
    mSplitPoints.clear();/* www. j a v a  2  s .  c  om*/
    if (!mCurrentContent.isSplitParagraphs()) {
        return;
    }
    CharSequence text = mCurrentContent.mText;
    for (int i = 0; i < text.length() - 1; ++i) {
        if (text.charAt(i) == '\n') {
            mSplitPoints.append(textToDisplayPosition(mTranslationResult, mCursorPosition, i + 1), 1);
        }
    }
}