List of usage examples for android.text SpannableStringBuilder length
public int length()
From source file:net.sf.fakenames.fddemo.PermissionActivity.java
private CharSequence toLabel(int uid, String[] packages) { final SpannableStringBuilder ssb = new SpannableStringBuilder(); if (packages != null) { try {//from w w w . jav a2 s . c o m final PackageManager pm = getPackageManager(); if (packages.length == 1) { final ApplicationInfo soleInfo = pm.getApplicationInfo(packages[0], 0); if (soleInfo != null) { final CharSequence label = soleInfo.loadLabel(pm); if (!TextUtils.isEmpty(label)) { ssb.append(label); setBold(ssb, 0, ssb.length()); return ssb; } } ssb.append(packages[0]); setBold(ssb, 0, ssb.length()); return ssb; } else { Arrays.sort(packages); int named = 0; ssb.append("UID ").append(String.valueOf(uid)).append(" ("); final ApplicationInfo firstInfo = pm.getApplicationInfo(packages[0], 0); if (firstInfo != null) { final CharSequence label = firstInfo.loadLabel(pm); if (!TextUtils.isEmpty(label)) { ++named; int old = ssb.length(); ssb.append(label); setBold(ssb, old, ssb.length()); } } final int maxSummary = Math.min(packages.length, 3); int i; for (i = 1; i < maxSummary; ++i) { final ApplicationInfo appInfo = pm.getApplicationInfo(packages[i], 0); if (appInfo != null) { final CharSequence label = appInfo.loadLabel(pm); if (!TextUtils.isEmpty(label)) { ++named; ssb.append(", "); int old = ssb.length(); ssb.append(label); setBold(ssb, old, ssb.length()); } } } if (named == 0) { ssb.append(String.valueOf(packages.length)).append(" packages)"); setBold(ssb, 0, ssb.length()); } else { if (packages.length <= 4) { ssb.append(")"); } else { ssb.append(" and "); ssb.append(String.valueOf(packages.length - named)); ssb.append(" others)"); } } return ssb; } } catch (PackageManager.NameNotFoundException ignored) { } } ssb.append("UID ").append(String.valueOf(uid)); setBold(ssb, 0, ssb.length()); return ssb; }
From source file:org.androidtitlan.estoesgoogle.ui.SessionDetailFragment.java
/** * Handle {@link SessionsQuery} {@link Cursor}. *///from w w w .ja v a 2 s. co m private void onSessionQueryComplete(Cursor cursor) { try { mSessionCursor = true; if (!cursor.moveToFirst()) { return; } // Format time block this session occupies final long blockStart = cursor.getLong(SessionsQuery.BLOCK_START); final long blockEnd = cursor.getLong(SessionsQuery.BLOCK_END); final String roomName = cursor.getString(SessionsQuery.ROOM_NAME); final String subtitle = UIUtils.formatSessionSubtitle(blockStart, blockEnd, roomName, getActivity()); mTitleString = cursor.getString(SessionsQuery.TITLE); mTitle.setText(mTitleString); mSubtitle.setText(subtitle); mUrl = cursor.getString(SessionsQuery.URL); if (TextUtils.isEmpty(mUrl)) { mUrl = ""; } mHashtag = cursor.getString(SessionsQuery.HASHTAG); mTagDisplay = (TextView) mRootView.findViewById(R.id.session_tags_button); if (!TextUtils.isEmpty(mHashtag)) { // Create the button text SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(getString(R.string.tag_stream) + " "); int boldStart = sb.length(); sb.append(getHashtagsString()); sb.setSpan(sBoldSpan, boldStart, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); mTagDisplay.setText(sb); mTagDisplay.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(getActivity(), TagStreamActivity.class); intent.putExtra(TagStreamFragment.EXTRA_QUERY, getHashtagsString()); startActivity(intent); } }); } else { mTagDisplay.setVisibility(View.GONE); } mRoomId = cursor.getString(SessionsQuery.ROOM_ID); // Unregister around setting checked state to avoid triggering // listener since change isn't user generated. mStarred.setOnCheckedChangeListener(null); mStarred.setChecked(cursor.getInt(SessionsQuery.STARRED) != 0); mStarred.setOnCheckedChangeListener(this); final String sessionAbstract = cursor.getString(SessionsQuery.ABSTRACT); if (!TextUtils.isEmpty(sessionAbstract)) { UIUtils.setTextMaybeHtml(mAbstract, sessionAbstract); mAbstract.setVisibility(View.VISIBLE); mHasSummaryContent = true; } else { mAbstract.setVisibility(View.GONE); } final View requirementsBlock = mRootView.findViewById(R.id.session_requirements_block); final String sessionRequirements = cursor.getString(SessionsQuery.REQUIREMENTS); if (!TextUtils.isEmpty(sessionRequirements)) { UIUtils.setTextMaybeHtml(mRequirements, sessionRequirements); requirementsBlock.setVisibility(View.VISIBLE); mHasSummaryContent = true; } else { requirementsBlock.setVisibility(View.GONE); } // Show empty message when all data is loaded, and nothing to show if (mSpeakersCursor && !mHasSummaryContent) { mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE); } AnalyticsUtils.getInstance(getActivity()).trackPageView("/Sessions/" + mTitleString); updateNotesTab(); updateLinksTab(cursor); } finally { cursor.close(); } }
From source file:com.google.android.apps.iosched.ui.SessionDetailFragment.java
/** * Handle {@link SessionsQuery} {@link Cursor}. *///from w w w . j a v a 2 s . c o m private void onSessionQueryComplete(Cursor cursor) { try { mSessionCursor = true; if (!cursor.moveToFirst()) { return; } // Format time block this session occupies final long blockStart = cursor.getLong(SessionsQuery.BLOCK_START); final long blockEnd = cursor.getLong(SessionsQuery.BLOCK_END); final String roomName = cursor.getString(SessionsQuery.ROOM_NAME); final String subtitle = UIUtils.formatSessionSubtitle(blockStart, blockEnd, roomName, getActivity()); mTitleString = cursor.getString(SessionsQuery.TITLE); mTitle.setText(mTitleString); mSubtitle.setText(subtitle); mUrl = cursor.getString(SessionsQuery.URL); if (TextUtils.isEmpty(mUrl)) { mUrl = ""; } mHashtag = cursor.getString(SessionsQuery.HASHTAG); mTagDisplay = (TextView) mRootView.findViewById(R.id.session_tags_button); if (!TextUtils.isEmpty(mHashtag)) { // Create the button text SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(getString(R.string.tag_stream) + " "); int boldStart = sb.length(); sb.append(getHashtagsString()); sb.setSpan(sBoldSpan, boldStart, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); mTagDisplay.setText(sb); mTagDisplay.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(getActivity(), TagStreamActivity.class); intent.putExtra(TagStreamFragment.EXTRA_QUERY, getHashtagsString()); startActivity(intent); } }); } else { mTagDisplay.setVisibility(View.GONE); } mRoomId = cursor.getString(SessionsQuery.ROOM_ID); // Unregister around setting checked state to avoid triggering // listener since change isn't user generated. mStarred.setOnCheckedChangeListener(null); mStarred.setChecked(cursor.getInt(SessionsQuery.STARRED) != 0); mStarred.setOnCheckedChangeListener(this); final String sessionAbstract = cursor.getString(SessionsQuery.ABSTRACT); if (!TextUtils.isEmpty(sessionAbstract)) { UIUtils.setTextMaybeHtml(mAbstract, sessionAbstract); mAbstract.setVisibility(View.VISIBLE); mHasSummaryContent = true; } else { mAbstract.setVisibility(View.GONE); } final View requirementsBlock = mRootView.findViewById(R.id.session_requirements_block); final String sessionRequirements = cursor.getString(SessionsQuery.REQUIREMENTS); if (!TextUtils.isEmpty(sessionRequirements)) { UIUtils.setTextMaybeHtml(mRequirements, sessionRequirements); requirementsBlock.setVisibility(View.VISIBLE); mHasSummaryContent = true; } else { requirementsBlock.setVisibility(View.GONE); } // Show empty message when all data is loaded, and nothing to show if (mSpeakersCursor && !mHasSummaryContent) { mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE); } AnalyticsUtils.getInstance(getActivity()).trackPageView("/Sessions/" + mTitleString); updateLinksTab(cursor); updateNotesTab(); } finally { cursor.close(); } }
From source file:cn.figo.mydemo.ui.activity.VideoActivity.java
private SpannableStringBuilder createSpannable(Drawable drawable) { String text = "bitmap"; SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text); ImageSpan span = new ImageSpan(drawable);//ImageSpan.ALIGN_BOTTOM); spannableStringBuilder.setSpan(span, 0, text.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); spannableStringBuilder.append(""); spannableStringBuilder.setSpan(new BackgroundColorSpan(Color.parseColor("#8A2233B1")), 0, spannableStringBuilder.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); return spannableStringBuilder; }
From source file:org.sufficientlysecure.keychain.ui.ViewKeyKeybaseFragment.java
@Override public void onCryptoOperationError(KeybaseVerificationResult result) { result.createNotify(getActivity()).show(); SpannableStringBuilder ssb = new SpannableStringBuilder(); ssb.append(getString(R.string.keybase_proof_failure)); String msg = getString(result.getLog().getLast().mType.mMsgId); if (msg == null) { msg = getString(R.string.keybase_unknown_proof_failure); }//from w ww . j a v a 2 s . c o m StyleSpan bold = new StyleSpan(Typeface.BOLD); ssb.setSpan(bold, 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); ssb.append("\n\n").append(msg); displaySpannableResult(ssb); }
From source file:com.juick.android.JuickMessagesAdapter.java
private static void setSSBSpan(SpannableStringBuilder ssb, Object span, int start, int end, int flags) { if (end > ssb.length()) { end = ssb.length();/*w ww. j a v a2 s.c om*/ } if (start > ssb.length()) return; if (start >= end) return; ssb.setSpan(span, start, end, flags); }
From source file:org.dalmasso.ietfsched.ui.SessionDetailFragment.java
/** * Handle {@link SessionsQuery} {@link Cursor}. *//*from ww w. jav a2 s.com*/ private void onSessionQueryComplete(Cursor cursor) { try { mSessionCursor = true; if (!cursor.moveToFirst()) { return; } // Format time block this session occupies final long blockStart = cursor.getLong(SessionsQuery.BLOCK_START); final long blockEnd = cursor.getLong(SessionsQuery.BLOCK_END); final String roomName = cursor.getString(SessionsQuery.ROOM_NAME); final String subtitle = UIUtils.formatSessionSubtitle(blockStart, blockEnd, roomName, getActivity()); mTitleString = cursor.getString(SessionsQuery.TITLE); mTitle.setText(mTitleString); mSubtitle.setText(subtitle); mUrl = cursor.getString(SessionsQuery.URL); if (TextUtils.isEmpty(mUrl)) { mUrl = ""; } mHashtag = cursor.getString(SessionsQuery.HASHTAG); mTagDisplay = (TextView) mRootView.findViewById(R.id.session_tags_button); if (!TextUtils.isEmpty(mHashtag)) { // Create the button text SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(getString(R.string.tag_stream) + " "); int boldStart = sb.length(); sb.append(getHashtagsString()); sb.setSpan(sBoldSpan, boldStart, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); mTagDisplay.setText(sb); mTagDisplay.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { /* Intent intent = new Intent(getActivity(), TagStreamActivity.class); intent.putExtra(TagStreamFragment.EXTRA_QUERY, getHashtagsString()); startActivity(intent); */ Log.d(TAG, "on click mTagDisplay"); } }); } else { mTagDisplay.setVisibility(View.GONE); } mRoomId = cursor.getString(SessionsQuery.ROOM_ID); // Unregister around setting checked state to avoid triggering // listener since change isn't user generated. mStarred.setOnCheckedChangeListener(null); mStarred.setChecked(cursor.getInt(SessionsQuery.STARRED) != 0); mStarred.setOnCheckedChangeListener(this); final String sessionAbstract = cursor.getString(SessionsQuery.ABSTRACT); if (!TextUtils.isEmpty(sessionAbstract)) { UIUtils.setTextMaybeHtml(mAbstract, sessionAbstract); mAbstract.setVisibility(View.VISIBLE); mHasSummaryContent = true; } else { mAbstract.setVisibility(View.GONE); } /* final View requirementsBlock = mRootView.findViewById(R.id.session_requirements_block); final String sessionRequirements = cursor.getString(SessionsQuery.REQUIREMENTS); if (!TextUtils.isEmpty(sessionRequirements)) { UIUtils.setTextMaybeHtml(mRequirements, sessionRequirements); requirementsBlock.setVisibility(View.VISIBLE); mHasSummaryContent = true; } else { requirementsBlock.setVisibility(View.GONE); } */ // Show empty message when all data is loaded, and nothing to show // if (mSpeakersCursor && !mHasSummaryContent) { if (!mHasSummaryContent) { mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE); } else { mTabHost.setCurrentTabByTag(TAG_SUMMARY); } // AnalyticsUtils.getInstance(getActivity()).trackPageView("/Sessions/" + mTitleString); updateLinksTab(cursor); updateNotesTab(); } finally { cursor.close(); } }
From source file:com.jecelyin.editor.v2.core.text.TextUtils.java
/** * Replace instances of "^1", "^2", etc. in the * <code>template</code> CharSequence with the corresponding * <code>values</code>. "^^" is used to produce a single caret in * the output. Only up to 9 replacement values are supported, * "^10" will be produce the first replacement value followed by a * '0'.//from w w w .j ava 2s . c o m * * @param template the input text containing "^1"-style * placeholder values. This object is not modified; a copy is * returned. * * @param values CharSequences substituted into the template. The * first is substituted for "^1", the second for "^2", and so on. * * @return the new CharSequence produced by doing the replacement * * @throws IllegalArgumentException if the template requests a * value that was not provided, or if more than 9 values are * provided. */ public static CharSequence expandTemplate(CharSequence template, CharSequence... values) { if (values.length > 9) { throw new IllegalArgumentException("max of 9 values are supported"); } SpannableStringBuilder ssb = new SpannableStringBuilder(template); try { int i = 0; while (i < ssb.length()) { if (ssb.charAt(i) == '^') { char next = ssb.charAt(i + 1); if (next == '^') { ssb.delete(i + 1, i + 2); ++i; continue; } else if (Character.isDigit(next)) { int which = Character.getNumericValue(next) - 1; if (which < 0) { throw new IllegalArgumentException("template requests value ^" + (which + 1)); } if (which >= values.length) { throw new IllegalArgumentException("template requests value ^" + (which + 1) + "; only " + values.length + " provided"); } ssb.replace(i, i + 2, values[which]); i += values[which].length(); continue; } } ++i; } } catch (IndexOutOfBoundsException ignore) { // happens when ^ is the last character in the string. } return ssb; }
From source file:com.google.android.apps.iosched2.ui.SessionDetailFragment.java
/** * Handle {@link SessionsQuery} {@link Cursor}. */// w ww. jav a 2s . com private void onSessionQueryComplete(Cursor cursor) { try { mSessionCursor = true; if (!cursor.moveToFirst()) { return; } // Format time block this session occupies final long blockStart = cursor.getLong(SessionsQuery.BLOCK_START); final long blockEnd = cursor.getLong(SessionsQuery.BLOCK_END); final String roomName = cursor.getString(SessionsQuery.ROOM_NAME); final String subtitle = UIUtils.formatSessionSubtitle(blockStart, blockEnd, roomName, getActivity()); mTitleString = cursor.getString(SessionsQuery.TITLE); mTitle.setText(mTitleString); mSubtitle.setText(subtitle); mUrl = cursor.getString(SessionsQuery.URL); if (TextUtils.isEmpty(mUrl)) { mUrl = ""; } mHashtag = cursor.getString(SessionsQuery.HASHTAG); mTagDisplay = (TextView) mRootView.findViewById(R.id.session_tags_button); if (!TextUtils.isEmpty(mHashtag)) { // Create the button text SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(getString(R.string.tag_stream) + " "); int boldStart = sb.length(); sb.append(getHashtagsString()); sb.setSpan(sBoldSpan, boldStart, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); mTagDisplay.setText(sb); mTagDisplay.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //Intent intent = new Intent(getActivity(), TagStreamActivity.class); Intent intent = new Intent(getActivity(), Setup.TagStreamActivityClass); intent.putExtra(TagStreamFragment.EXTRA_QUERY, getHashtagsString()); startActivity(intent); } }); } else { mTagDisplay.setVisibility(View.GONE); } mRoomId = cursor.getString(SessionsQuery.ROOM_ID); // Unregister around setting checked state to avoid triggering // listener since change isn't user generated. mStarred.setOnCheckedChangeListener(null); mStarred.setChecked(cursor.getInt(SessionsQuery.STARRED) != 0); mStarred.setOnCheckedChangeListener(this); final String sessionAbstract = cursor.getString(SessionsQuery.ABSTRACT); if (!TextUtils.isEmpty(sessionAbstract)) { UIUtils.setTextMaybeHtml(mAbstract, sessionAbstract); mAbstract.setVisibility(View.VISIBLE); mHasSummaryContent = true; } else { mAbstract.setVisibility(View.GONE); } final View requirementsBlock = mRootView.findViewById(R.id.session_requirements_block); final String sessionRequirements = cursor.getString(SessionsQuery.REQUIREMENTS); if (!TextUtils.isEmpty(sessionRequirements)) { UIUtils.setTextMaybeHtml(mRequirements, sessionRequirements); requirementsBlock.setVisibility(View.VISIBLE); mHasSummaryContent = true; } else { requirementsBlock.setVisibility(View.GONE); } final View levelBlock = mRootView.findViewById(R.id.session_level_block); final String sessionLevel = cursor.getString(SessionsQuery.LEVEL); if (!TextUtils.isEmpty(sessionLevel)) { UIUtils.setTextMaybeHtml(mLevel, sessionLevel); levelBlock.setVisibility(View.VISIBLE); mHasSummaryContent = true; } else { levelBlock.setVisibility(View.GONE); } // Show empty message when all data is loaded, and nothing to show if (mSpeakersCursor && !mHasSummaryContent) { mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE); } AnalyticsUtils.getInstance(getActivity()).trackPageView("/Sessions/" + mTitleString); updateLinksTab(cursor); updateNotesTab(); } finally { cursor.close(); } }
From source file:com.heneryh.aquanotes.ui.CtlrStatusFragment.java
/** * Handle {@link SessionsQuery} {@link Cursor}. */// www. j a v a2 s .c o m private void updateControllerTabs(Ctlr cntl, Cursor cursor) { try { mSessionCursor = true; // Header Area cntl.mTitleString = cursor.getString(ControllersQuery.TITLE); cntl.mSubtitle = cursor.getString(ControllersQuery.WAN_URL); cntl.mTitleView.setText(cntl.mTitleString); cntl.mSubtitleView.setText(cntl.mSubtitle); // Probes Tab Area cntl.mUrl = "http://test"; //cursor.getString(SessionsQuery.URL); if (TextUtils.isEmpty(cntl.mUrl)) { cntl.mUrl = ""; } cntl.mHashtag = ""; //cursor.getString(SessionsQuery.HASHTAG); if (!TextUtils.isEmpty(cntl.mHashtag)) { // Create the button text SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(getString(R.string.tag_stream) + " "); int boldStart = sb.length(); sb.append(getHashtagsString(cntl.mHashtag)); sb.setSpan(sBoldSpan, boldStart, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); cntl.mTagDisplayView.setText(sb); cntl.mTagDisplayView.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(getActivity(), TagStreamActivity.class); intent.putExtra(TagStreamFragment.EXTRA_QUERY, getHashtagsString("was hash tag")); startActivity(intent); } }); } else { cntl.mTagDisplayView.setVisibility(View.GONE); } cntl.mRoomName = "Room"; cntl.mRoomId = "Rm 202"; //cursor.getString(SessionsQuery.ROOM_ID); // Unregister around setting checked state to avoid triggering // listener since change isn't user generated. // cntl.mStarred.setOnCheckedChangeListener(null); // cntl.mStarred.setChecked(false); // cntl.mStarred.setOnCheckedChangeListener(this); final String sessionAbstract = "I can work on the order these show up, it is just a sort on the query. Note there is a title above in the header between the l/r icons. Also a title down in the tab host header. I will do one or the other not both. Oh, and you have to swipe l/r once to get that top title to sync."; //cursor.getString(SessionsQuery.ABSTRACT); if (!TextUtils.isEmpty(sessionAbstract)) { UIUtils.setTextMaybeHtml(cntl.mAbstractView, sessionAbstract); cntl.mAbstractView.setVisibility(View.VISIBLE); cntl.mHasSummaryContent = true; } else { cntl.mAbstractView.setVisibility(View.GONE); } final String sessionRequirements = "How shall I lay out this screen??? Suggestions?"; //cursor.getString(SessionsQuery.REQUIREMENTS); if (!TextUtils.isEmpty(sessionRequirements)) { UIUtils.setTextMaybeHtml(cntl.mRequirementsView, sessionRequirements); cntl.mRequirementsBlockView.setVisibility(View.VISIBLE); cntl.mHasSummaryContent = true; } else { cntl.mRequirementsBlockView.setVisibility(View.GONE); } // Show empty message when all data is loaded, and nothing to show if (mSpeakersCursor && !cntl.mHasSummaryContent) { cntl.mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE); } AnalyticsUtils.getInstance(getActivity()).trackPageView("/Sessions/" + cntl.mTitleString); // updateLinksTab(cursor); // updateNotesTab(); updateWorkspaceHeader(cntl.index); } finally { // cursor.close(); } }