Example usage for java.lang CharSequence length

List of usage examples for java.lang CharSequence length

Introduction

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

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:org.shredzone.cilla.plugin.flattr.FlattrPublicationServiceImpl.java

/**
 * Prepares a {@link CharSequence}. Strips all HTML and limits its length to the given
 * maximum length.//  ww  w. jav  a2 s. c om
 *
 * @param str
 *            {@link CharSequence} to prepare
 * @param maxlen
 *            maximum length
 * @return prepared {@link CharSequence}
 */
private CharSequence prepare(CharSequence str, int maxlen) {
    CharSequence result = textFormatter.stripHtml(str.toString().trim());
    if (result.length() > maxlen) {
        return result.subSequence(0, maxlen);
    } else {
        return result;
    }
}

From source file:net.eledge.android.europeana.gui.activity.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    NewBlogNotification.cancel(this);

    PreferenceManager.setDefaultValues(this, R.xml.settings, false);

    searchController.suggestionPageSize = getResources().getInteger(R.integer.home_suggestions_pagesize);
    isLandscape = getResources().getBoolean(R.bool.home_support_landscape);

    mSuggestionsAdaptor = new SuggestionAdapter(this, new ArrayList<Item>());
    mGridViewSuggestions.setAdapter(mSuggestionsAdaptor);
    mGridViewSuggestions.setOnItemClickListener(this);

    mEditTextQuery.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override/*from w ww  . ja va2  s .  c om*/
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((actionId == EditorInfo.IME_ACTION_SEARCH) || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                performSearch(v.getText().toString());
                return true;
            }
            return false;
        }
    });
    mEditTextQuery.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() > 2) {
                if (mGridViewSuggestions.isShown()) {
                    mSuggestionsAdaptor.clear();
                    mSuggestionsAdaptor.notifyDataSetChanged();
                }
                searchController.suggestions(HomeActivity.this, s.toString());
            } else {
                onTaskFinished(null);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // ignore
        }

        @Override
        public void afterTextChanged(Editable s) {
            // ignore
        }
    });

    mProfilesAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item);
    mSpinnerProfiles.setAdapter(mProfilesAdapter);

    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    if (mBlogFragment == null) {
        mBlogFragment = new HomeBlogFragment();
    }
    fragmentTransaction.replace(R.id.activity_home_fragment_blog, mBlogFragment);
    fragmentTransaction.commit();
}

From source file:com.androidquery.simplefeed.activity.PlaceActivity.java

public void searchChanged(CharSequence s, int start, int before, int count) {

    if (s.length() == 0) {
        searchClicked(null);/*from w  w  w.  j  a  v  a  2 s.  c  o m*/
    }

}

From source file:br.msf.commons.text.EnhancedStringBuilder.java

protected static boolean startsWith(final CharSequence prefix, final int offset, final CharSequence sequence) {
    if (CharSequenceUtils.isEmptyOrNull(prefix) || CharSequenceUtils.isEmptyOrNull(sequence)
            || prefix.length() > sequence.length()) {
        return false;
    }/*from   w w w . j a  v a 2  s. c om*/
    int i = offset, j = 0;
    int pLen = prefix.length();
    while (--pLen >= 0) {
        if (sequence.charAt(i++) != prefix.charAt(j++)) {
            return false;
        }
    }
    return true;
}

From source file:ch.algotrader.service.ib.IBNativeReferenceDataServiceImpl.java

private LocalDate parseYearMonth(final CharSequence s) {
    if (s == null || s.length() == 0) {
        return null;
    }//  ww w .  j ava2  s .c o m
    try {
        TemporalAccessor parsed = YEAR_MONTH_FORMAT.parse(s);
        int year = parsed.get(ChronoField.YEAR);
        int month = parsed.get(ChronoField.MONTH_OF_YEAR);
        return LocalDate.of(year, month, 1);
    } catch (DateTimeParseException ex) {
        throw new ServiceException("Invalid year/month format: " + s);
    }
}

From source file:com.achep.base.ui.fragments.dialogs.FeedbackDialog.java

private boolean isMessageLongEnough(@Nullable CharSequence message) {
    return message != null && message.length() >= getMinMessageLength();
}

From source file:io.selendroid.server.model.AndroidWebElement.java

public void sendKeys(final CharSequence value) {
    if (value == null || value.length() == 0) {
        return;/*from w ww . ja  va 2 s.c o m*/
    }
    // focus on the element
    this.click();
    driver.waitUntilEditAreaHasFocus();
    // Move the cursor to the end of the test input.
    // The trick is to set the value after the cursor
    String originalText = (String) driver.executeScript(
            "arguments[0].focus();" + "arguments[0].value=arguments[0].value;return arguments[0].value", this,
            null);

    driver.getKeySender().send(value);

    // wait for keys to have been sent to the element
    long timeout = System.currentTimeMillis() + SENDKEYS_TIMEOUT;
    while (timeout < System.currentTimeMillis()) {
        String newValue = (String) driver.executeScript("return arguments[0].value;");
        if (newValue.length() > originalText.length())
            break;
        try {
            Thread.sleep(POLLING_INTERVAL);
        } catch (InterruptedException e) {
            // being kind to the system, if system is interrupting just break out.
            break;
        }
    }
}

From source file:com.harrywu.springweb.common.PropertyPlaceholderHelper.java

private int findPlaceholderEndIndex(CharSequence buf, int startIndex) {
    int index = startIndex + this.placeholderPrefix.length();
    int withinNestedPlaceholder = 0;
    while (index < buf.length()) {
        if (StringUtils.substringMatch(buf, index, this.placeholderSuffix)) {
            if (withinNestedPlaceholder > 0) {
                withinNestedPlaceholder--;
                index = index + this.placeholderPrefix.length() - 1;
            } else {
                return index;
            }//  w  ww. j a va  2 s .co m
        } else if (StringUtils.substringMatch(buf, index, this.placeholderPrefix)) {
            withinNestedPlaceholder++;
            index = index + this.placeholderPrefix.length();
        } else {
            index++;
        }
    }
    return -1;
}

From source file:de.greenrobot.daoexample.NoteActivity.java

protected void addUiListeners() {
    editText.setOnEditorActionListener(new OnEditorActionListener() {

        @Override/*from   ww  w  . j  a v  a  2s  .  c  o  m*/
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                addNote();
                return true;
            }
            return false;
        }
    });

    final View button = findViewById(R.id.buttonAdd);
    button.setEnabled(false);
    editText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            boolean enable = s.length() != 0;
            button.setEnabled(enable);
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    mBtnAddAll.setOnClickListener(this);
    mBtnDeleteAll.setOnClickListener(this);
    mBtnDeleteByCount.setOnClickListener(this);
    mBtnQueryCount.setOnClickListener(this);
    mBtnQueryAll.setOnClickListener(this);
    mBtnQueryWithParam.setOnClickListener(this);
}

From source file:org.shredzone.cilla.plugin.flattr.FlattrPublicationServiceImpl.java

/**
 * Creates a {@link Submission} object for the {@link Page}.
 *
 * @param page/*from  w  w w  .ja  v a2  s  . c o m*/
 *            {@link Page} to create a {@link Submission} for
 * @return generated {@link Submission}, or {@code null} if a {@link Submission} could
 *         not be generated because of lacking information or other problems.
 */
private Submission createSubmissionForPage(Page page) {
    Submission thing = new Submission();
    thing.setCategory(org.shredzone.flattr4j.model.Category.withId(category));

    CharSequence title = prepare(page.getTitle(), 100);
    if (title.length() < 5) {
        // Title would be too short...
        return null;
    }
    thing.setTitle(title.toString());

    CharSequence description = textFormatter.format(page.getTeaser());
    description = prepare(description, 1000);
    if (description.length() < 5) {
        // Description would be too short...
        return null;
    }
    thing.setDescription(description.toString());

    LanguageId language = flattrLanguage.findLanguageId(page.getLanguage().getLocale());
    if (language == null) {
        // No matching language was found...
        return null;
    }
    thing.setLanguage(language);

    page.getCategories().stream().map(Category::getName).forEach(thing::addTag);
    page.getTags().stream().map(Tag::getName).forEach(thing::addTag);

    if (flattrAutotags != null && !flattrAutotags.isEmpty()) {
        Arrays.stream(flattrAutotags.split(",")).map(String::trim).forEach(thing::addTag);
    }

    thing.setHidden(flattrHidden);
    thing.setUrl(linkService.linkTo().page(page).external().toString());

    return thing;
}