Example usage for twitter4j.util CharacterUtil count

List of usage examples for twitter4j.util CharacterUtil count

Introduction

In this page you can find the example usage for twitter4j.util CharacterUtil count.

Prototype

public static int count(String text) 

Source Link

Document

Counts the length of the tweet

Usage

From source file:ch.ethz.twimight.activities.ComposeTweetActivity.java

License:Open Source License

private void checkTweetLength() {
    int usedTextChars = CharacterUtil.count(mEtTweetText.getText().toString());
    int usedMediaChars = mHasMedia ? Constants.CHARACTERS_RESERVED_PER_MEDIA : 0;
    int numCharsLeft = Constants.TWEET_LENGTH - usedTextChars - usedMediaChars;

    if (numCharsLeft < 0) {
        mEtTweetText.setText(mEtTweetText.getText().subSequence(0, Constants.TWEET_LENGTH - usedMediaChars));
        mEtTweetText.setSelection(mEtTweetText.getText().length());
        usedTextChars = CharacterUtil.count(mEtTweetText.getText().toString());
        numCharsLeft = Constants.TWEET_LENGTH - usedTextChars - usedMediaChars;
    }//from w  w w .  j  av  a 2  s  .  c om

    if (numCharsLeft <= 0) {
        mTvCharacterCounter.setTextColor(Color.RED);
    } else {
        mTvCharacterCounter.setTextColor(getResources().getColor(R.color.medium_gray));
    }

    if (numCharsLeft == Constants.TWEET_LENGTH) {
        mBtnSend.setEnabled(false);
    } else {
        mBtnSend.setEnabled(true);
    }

    mTvCharacterCounter.setText(Integer.toString(numCharsLeft));
}