List of usage examples for java.lang CharSequence subSequence
CharSequence subSequence(int start, int end);
From source file:com.amazon.android.ui.widget.EllipsizedTextView.java
/** * Sets the text please note that text must be a normal CharSequence. * The text will be truncated if goes beyond max_characters_allowed characters *///w w w . j a v a 2 s. co m @Override public void setText(final CharSequence text, final BufferType type) { int maxCharactersAllowed = getContext().getResources() .getInteger(R.integer.ellipsized_text_view_max_characters); if (text.length() > maxCharactersAllowed) { mCharSequence = text.subSequence(0, maxCharactersAllowed); } else { mCharSequence = text; } mSetText = mCharSequence.toString(); super.setText(mCharSequence, type); }
From source file:netbeanstypescript.TSCodeCompletion.java
@Override public String getPrefix(ParserResult info, int caretOffset, boolean upToOffset) { CharSequence seq = info.getSnapshot().getText(); int i = caretOffset, j = i; while (i > 0 && Character.isJavaIdentifierPart(seq.charAt(i - 1))) { i--;//ww w .j a v a 2 s. c om } while (!upToOffset && j < seq.length() && Character.isJavaIdentifierPart(seq.charAt(j))) { j++; } return seq.subSequence(i, j).toString(); }
From source file:org.solovyev.android.calculator.widget.CalculatorWidget.java
private void updateEditorState(@Nonnull Context context, @Nonnull RemoteViews views, @Nonnull EditorState state, @Nonnull SimpleTheme theme) {/* w w w .j a va 2 s. c o m*/ final boolean unspan = App.getTheme().light != theme.light; final CharSequence text = state.text; final int selection = state.selection; if (selection < 0 || selection > text.length()) { views.setTextViewText(R.id.calculator_editor, unspan ? App.unspan(text) : text); return; } final SpannableStringBuilder result; // inject cursor if (unspan) { final CharSequence beforeCursor = text.subSequence(0, selection); final CharSequence afterCursor = text.subSequence(selection, text.length()); result = new SpannableStringBuilder(); result.append(App.unspan(beforeCursor)); result.append(getCursorString(context)); result.append(App.unspan(afterCursor)); } else { result = new SpannableStringBuilder(text); result.insert(selection, getCursorString(context)); } views.setTextViewText(R.id.calculator_editor, result); }
From source file:org.mariotaku.commons.emojione.AbsShortnameToUnicodeTranslator.java
/** * {@inheritDoc}/* www . jav a 2 s.com*/ */ @Override public int translate(final CharSequence input, final int index, final Writer out) throws IOException { final int inputLength = input.length(); if (index + 1 >= inputLength) return 0; // check if translation exists for the input at position index if (':' == input.charAt(index) && prefixSet.contains(input.charAt(index + 1))) { int max = longest; if (index + longest > inputLength) { max = inputLength - index; } // implement greedy algorithm by trying maximum match first for (int i = max; i >= shortest; i--) { final CharSequence subSeq = input.subSequence(index, index + i); final String result = lookupMap.get(subSeq); if (result != null) { out.write(result); return i; } } } return 0; }
From source file:com.jins_meme.bridge.OSCConfigFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); handler = new Handler(); layout = (LinearLayout) view.findViewById(R.id.osc_layout); layout.setOnTouchListener(new OnTouchListener() { @Override/*from w ww. ja v a 2s .c o m*/ public boolean onTouch(View view, MotionEvent motionEvent) { Log.d("DEBUG", "view touch."); layout.requestFocus(); return false; } }); InputFilter[] filters = new InputFilter[1]; filters[0] = new InputFilter() { @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { if (end > start) { String destTxt = dest.toString(); String resultingTxt = destTxt.substring(0, dstart) + source.subSequence(start, end) + destTxt.substring(dend); if (!resultingTxt .matches("^\\d{1,3}(\\." + "(\\d{1,3}(\\.(\\d{1,3}(\\.(\\d{1,3})?)?)?)?)?)?")) { return ""; } else { String[] splits = resultingTxt.split("\\."); for (String split : splits) { if (Integer.valueOf(split) > 255) { return ""; } } } } return null; } }; etRemoteIP = (EditText) view.findViewById(R.id.remote_ip); String savedRemoteIP = ((MainActivity) getActivity()).getSavedValue("REMOTE_IP", "255.255.255.255"); if (savedRemoteIP.equals("255.255.255.255")) { etRemoteIP.setText(MemeOSC.getRemoteIPv4Address()); } else { etRemoteIP.setText(savedRemoteIP); } etRemoteIP.setFilters(filters); etRemoteIP.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean b) { if (!b) { InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } }); etRemoteIP.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { Log.d("DEBUG", "after text changed " + editable.toString()); ((MainActivity) getActivity()).autoSaveValue("REMOTE_IP", editable.toString()); testOSC.setRemoteIP(etRemoteIP.getText().toString()); testOSC.initSocket(); } }); etRemotePort = (EditText) view.findViewById(R.id.remote_port); etRemotePort.setText(String.valueOf(((MainActivity) getActivity()).getSavedValue("REMOTE_PORT", 10316))); etRemotePort.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean b) { if (!b) { InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } }); etRemotePort.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { Log.d("DEBUG", "after text changed " + editable.toString()); if (editable.toString().length() > 0) { ((MainActivity) getActivity()).autoSaveValue("REMOTE_PORT", Integer.valueOf(editable.toString())); testOSC.setRemotePort(Integer.parseInt(editable.toString())); testOSC.initSocket(); } } }); etHostIP = (EditText) view.findViewById(R.id.host_ip); etHostIP.setText(MemeOSC.getHostIPv4Address()); etHostIP.setEnabled(false); etHostPort = (EditText) view.findViewById(R.id.host_port); etHostPort.setText(String.valueOf(((MainActivity) getActivity()).getSavedValue("HOST_PORT", 11316))); etHostPort.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean b) { if (!b) { InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } }); etHostPort.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { Log.d("DEBUG", "after text changed " + editable.toString()); if (editable.toString().length() > 0) { ((MainActivity) getActivity()).autoSaveValue("HOST_PORT", Integer.valueOf(editable.toString())); testOSC.setHostPort(Integer.parseInt(editable.toString())); testOSC.initSocket(); } } }); btnTest = (Button) view.findViewById(R.id.remote_test); btnTest.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { layout.requestFocus(); testOSC.setAddress("/meme/bridge", "/test"); testOSC.setTypeTag("si"); testOSC.addArgument(etRemoteIP.getText().toString()); testOSC.addArgument(Integer.parseInt(etRemotePort.getText().toString())); testOSC.flushMessage(); } }); testOSC = new MemeOSC(); testOSC.setRemoteIP(etRemoteIP.getText().toString()); testOSC.setRemotePort(Integer.parseInt(etRemotePort.getText().toString())); testOSC.setHostPort(Integer.parseInt(etHostPort.getText().toString())); testOSC.initSocket(); isShown = true; Thread rcvTestThread = new Thread(new ReceiveTestTRunnable()); rcvTestThread.start(); }
From source file:org.mariotaku.twidere.adapter.ComposeAutoCompleteAdapter.java
@Override public Cursor runQueryOnBackgroundThread(final CharSequence constraint) { if (TextUtils.isEmpty(constraint)) return null; char token = constraint.charAt(0); if (getNormalizedSymbol(token) == getNormalizedSymbol(mToken)) { final FilterQueryProvider filter = getFilterQueryProvider(); if (filter != null) return filter.runQuery(constraint); }//from w ww . j a v a 2 s.co m mToken = token; final Uri.Builder builder = Suggestions.AutoComplete.CONTENT_URI.buildUpon(); builder.appendQueryParameter(QUERY_PARAM_QUERY, String.valueOf(constraint.subSequence(1, constraint.length()))); switch (getNormalizedSymbol(token)) { case '#': { builder.appendQueryParameter(QUERY_PARAM_TYPE, Suggestions.AutoComplete.TYPE_HASHTAGS); break; } case '@': { builder.appendQueryParameter(QUERY_PARAM_TYPE, Suggestions.AutoComplete.TYPE_USERS); break; } default: { return null; } } builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, String.valueOf(accountKey)); return mContext.getContentResolver().query(builder.build(), Suggestions.AutoComplete.COLUMNS, null, null, null); }
From source file:org.archive.extractor.RegexHTMLLinkExtractor.java
protected void processMeta(CharSequence cs) { Matcher attr = TextUtils.getMatcher(EACH_ATTRIBUTE_EXTRACTOR, cs); String name = null;// ww w .j av a 2 s . c om String httpEquiv = null; String content = null; while (attr.find()) { int valueGroup = (attr.start(12) > -1) ? 12 : (attr.start(13) > -1) ? 13 : 14; CharSequence value = cs.subSequence(attr.start(valueGroup), attr.end(valueGroup)); if (attr.group(1).equalsIgnoreCase("name")) { name = value.toString(); } else if (attr.group(1).equalsIgnoreCase("http-equiv")) { httpEquiv = value.toString(); } else if (attr.group(1).equalsIgnoreCase("content")) { content = value.toString(); } // TODO: handle other stuff } TextUtils.recycleMatcher(attr); // Look for the 'robots' meta-tag if ("robots".equalsIgnoreCase(name) && content != null) { if (getHonorRobots()) { String contentLower = content.toLowerCase(); if ((contentLower.indexOf("nofollow") >= 0 || contentLower.indexOf("none") >= 0)) { // if 'nofollow' or 'none' is specified and we // are honoring robots, end html extraction logger.fine("HTML extraction skipped due to robots meta-tag for: " + source); cancelFurtherExtraction(); return; } } } else if ("refresh".equalsIgnoreCase(httpEquiv) && content != null) { String refreshUri = content.substring(content.indexOf("=") + 1); try { Link refreshLink = new Link(source, UURIFactory.getInstance(base, refreshUri), new HTMLLinkContext("meta", httpEquiv), Hop.REFER); next.addLast(refreshLink); } catch (URIException e) { extractErrorListener.noteExtractError(e, source, refreshUri); } } }
From source file:com.cyberway.issue.extractor.RegexpHTMLLinkExtractor.java
protected void processMeta(CharSequence cs) { Matcher attr = TextUtils.getMatcher(EACH_ATTRIBUTE_EXTRACTOR, cs); String name = null;//from www . j ava2s.co m String httpEquiv = null; String content = null; while (attr.find()) { int valueGroup = (attr.start(12) > -1) ? 12 : (attr.start(13) > -1) ? 13 : 14; CharSequence value = cs.subSequence(attr.start(valueGroup), attr.end(valueGroup)); if (attr.group(1).equalsIgnoreCase("name")) { name = value.toString(); } else if (attr.group(1).equalsIgnoreCase("http-equiv")) { httpEquiv = value.toString(); } else if (attr.group(1).equalsIgnoreCase("content")) { content = value.toString(); } // TODO: handle other stuff } TextUtils.recycleMatcher(attr); // Look for the 'robots' meta-tag if ("robots".equalsIgnoreCase(name) && content != null) { if (getHonorRobots()) { String contentLower = content.toLowerCase(); if ((contentLower.indexOf("nofollow") >= 0 || contentLower.indexOf("none") >= 0)) { // if 'nofollow' or 'none' is specified and we // are honoring robots, end html extraction logger.fine("HTML extraction skipped due to robots meta-tag for: " + source); cancelFurtherExtraction(); return; } } } else if ("refresh".equalsIgnoreCase(httpEquiv) && content != null) { String refreshUri = content.substring(content.indexOf("=") + 1); try { Link refreshLink = new Link(source, UURIFactory.getInstance(base, refreshUri), Link.elementContext("meta", httpEquiv), Link.REFER_HOP); next.addLast(refreshLink); } catch (URIException e) { extractErrorListener.noteExtractError(e, source, refreshUri); } } }
From source file:org.apache.abdera.util.AbstractStreamWriter.java
public Appendable append(CharSequence csq, int start, int end) throws IOException { return append(csq.subSequence(start, end)); }
From source file:com.cyberway.issue.crawler.extractor.ExtractorHTML.java
/** * Process style text.// ww w . j a va2 s. c o m * @param curi CrawlURI we're processing. * @param sequence Sequence from underlying ReplayCharSequence. This * is TRANSIENT data. Make a copy if you want the data to live outside * of this extractors' lifetime. * @param endOfOpenTag */ protected void processStyle(CrawlURI curi, CharSequence sequence, int endOfOpenTag) { // First, get attributes of script-open tag as per any other tag. processGeneralTag(curi, sequence.subSequence(0, 6), sequence.subSequence(0, endOfOpenTag)); // then, parse for URIs this.numberOfLinksExtracted += ExtractorCSS.processStyleCode(curi, sequence.subSequence(endOfOpenTag, sequence.length()), getController()); }