Java Code Examples for android.text.SpannableStringBuilder

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/widget/.

Source file: SearchView.java

  24 
vote

private CharSequence getDecoratedHint(CharSequence hintText){
  if (!mIconifiedByDefault)   return hintText;
  SpannableStringBuilder ssb=new SpannableStringBuilder("   ");
  ssb.append(hintText);
  Drawable searchIcon=getContext().getResources().getDrawable(getSearchIconId());
  int textSize=(int)(mQueryTextView.getTextSize() * 1.25);
  searchIcon.setBounds(0,0,textSize,textSize);
  ssb.setSpan(new ImageSpan(searchIcon),1,2,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  return ssb;
}
 

Example 2

From project android-thaiime, under directory /common/src/com/android/ex/editstyledtext/.

Source file: EditStyledText.java

  23 
vote

private SpannableStringBuilder removeImageChar(SpannableStringBuilder text){
  SpannableStringBuilder buf=new SpannableStringBuilder(text);
  DynamicDrawableSpan[] styles=buf.getSpans(0,buf.length(),DynamicDrawableSpan.class);
  for (  DynamicDrawableSpan style : styles) {
    if (style instanceof HorizontalLineSpan || style instanceof RescalableImageSpan) {
      int start=buf.getSpanStart(style);
      int end=buf.getSpanEnd(style);
      buf.replace(start,end,"");
    }
  }
  return buf;
}
 

Example 3

From project agit, under directory /agit/src/main/java/com/madgag/agit/.

Source file: CommitViewerActivity.java

  22 
vote

private void setActionBarTitles(){
  SpannableStringBuilder prefixTitle=new SpannableStringBuilder(commit.name().substring(0,4));
  prefixTitle.setSpan(MONOSPACE_SPAN,0,4,SPAN_EXCLUSIVE_EXCLUSIVE);
  String pathPrefix=niceNameFor(repo()) + " ? ";
  String currentRef=logStartProvider.getCurrentRef();
  if (currentRef != null) {
    pathPrefix=pathPrefix + shortenRefName(currentRef) + " ? ";
  }
  prefixTitle.insert(0,pathPrefix);
  setPrefixedTitleOn(getSupportActionBar(),prefixTitle,commit.getShortMessage());
}
 

Example 4

From project android-api-demos, under directory /src/com/mobeelizer/demos/activities/.

Source file: ConflictsActivity.java

  22 
vote

/** 
 * Shows or hides conflicts warning text below the list view and above add/sync buttons. It should be visible only when at least one field is in conflict.
 * @param isVisible Whether warning should be visible.
 */
private void showWarning(final boolean isVisible){
  mWarningText.setVisibility(isVisible ? View.VISIBLE : View.GONE);
  StyleSpan boldSpan=new StyleSpan(Typeface.BOLD);
  String text=mWarningText.getText().toString();
  if (text.contains("|")) {
    SpannableStringBuilder ssb=new SpannableStringBuilder(text);
    ssb.setSpan(boldSpan,0,text.indexOf(':'),Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    Bitmap syncIcon=BitmapFactory.decodeResource(getResources(),R.drawable.ic_sync);
    int syncIndex=text.indexOf('|');
    ssb.setSpan(new ImageSpan(syncIcon),syncIndex,syncIndex + 1,Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mWarningText.setText(ssb,BufferType.SPANNABLE);
  }
}
 

Example 5

From project android-ocr, under directory /android/src/edu/sfsu/cs/orange/ocr/.

Source file: CaptureActivity.java

  22 
vote

/** 
 * Given either a Spannable String or a regular String and a token, apply the given CharacterStyle to the span between the tokens. NOTE: This method was adapted from: http://www.androidengineer.com/2010/08/easy-method-for-formatting-android.html <p> For example,  {@code setSpanBetweenTokens("Hello ##world##!", "##", newForegroundColorSpan(0xFFFF0000));} will return a CharSequence {@code "Hello world!"} with {@code world} in red.
 */
private CharSequence setSpanBetweenTokens(CharSequence text,String token,CharacterStyle... cs){
  int tokenLen=token.length();
  int start=text.toString().indexOf(token) + tokenLen;
  int end=text.toString().indexOf(token,start);
  if (start > -1 && end > -1) {
    SpannableStringBuilder ssb=new SpannableStringBuilder(text);
    for (    CharacterStyle c : cs)     ssb.setSpan(c,start,end,0);
    text=ssb;
  }
  return text;
}
 

Example 6

From project android-xbmcremote-sandbox, under directory /src/org/xbmc/android/util/.

Source file: UIUtils.java

  22 
vote

/** 
 * Given a snippet string with matching segments surrounded by curly braces, turn those areas into bold spans, removing the curly braces.
 */
public static Spannable buildStyledSnippet(String snippet){
  final SpannableStringBuilder builder=new SpannableStringBuilder(snippet);
  int startIndex=-1, endIndex=-1, delta=0;
  while ((startIndex=snippet.indexOf('{',endIndex)) != -1) {
    endIndex=snippet.indexOf('}',startIndex);
    builder.delete(startIndex - delta,startIndex - delta + 1);
    builder.delete(endIndex - delta - 1,endIndex - delta);
    builder.setSpan(sBoldSpan,startIndex - delta,endIndex - delta - 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    delta+=2;
  }
  return builder;
}
 

Example 7

From project android_packages_apps_CellBroadcastReceiver, under directory /src/com/android/cellbroadcastreceiver/.

Source file: CellBroadcastListItem.java

  22 
vote

private static CharSequence formatMessage(CellBroadcastMessage message){
  String body=message.getMessageBody();
  SpannableStringBuilder buf=new SpannableStringBuilder(body);
  if (!message.isRead()) {
    buf.setSpan(Typeface.DEFAULT_BOLD,0,buf.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
  }
  return buf;
}
 

Example 8

From project android_packages_inputmethods_LatinIME, under directory /java/src/com/android/inputmethod/deprecated/.

Source file: VoiceProxy.java

  22 
vote

private Spanned replaceURLSpan(CharSequence message){
  final SpannableStringBuilder ssb=new SpannableStringBuilder(message);
  for (  URLSpan span : ssb.getSpans(0,ssb.length(),URLSpan.class)) {
    int spanStart=ssb.getSpanStart(span);
    int spanEnd=ssb.getSpanEnd(span);
    int spanFlags=ssb.getSpanFlags(span);
    ssb.removeSpan(span);
    ssb.setSpan(new ClickableSpan(span.getURL()),spanStart,spanEnd,spanFlags);
  }
  return ssb;
}
 

Example 9

From project AquaNotesTest, under directory /src/com/google/android/apps/iosched/util/.

Source file: UIUtils.java

  22 
vote

/** 
 * Given a snippet string with matching segments surrounded by curly braces, turn those areas into bold spans, removing the curly braces.
 */
public static Spannable buildStyledSnippet(String snippet){
  final SpannableStringBuilder builder=new SpannableStringBuilder(snippet);
  int startIndex=-1, endIndex=-1, delta=0;
  while ((startIndex=snippet.indexOf('{',endIndex)) != -1) {
    endIndex=snippet.indexOf('}',startIndex);
    builder.delete(startIndex - delta,startIndex - delta + 1);
    builder.delete(endIndex - delta - 1,endIndex - delta);
    builder.setSpan(sBoldSpan,startIndex - delta,endIndex - delta - 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    delta+=2;
  }
  return builder;
}
 

Example 10

From project Bitcoin-Wallet-for-Android, under directory /wallet/src/de/schildbach/wallet/ui/.

Source file: CurrencyAmountView.java

  22 
vote

public void setHint(final BigInteger amount){
  final SpannableStringBuilder hint;
  if (amount != null)   hint=new SpannableStringBuilder(WalletUtils.formatValue(amount));
 else   hint=new SpannableStringBuilder("0.00");
  WalletUtils.formatValue(hint);
  textView.setHint(hint);
}
 

Example 11

From project com.juick.android, under directory /src/com/juick/android/.

Source file: ThreadActivity.java

  22 
vote

public void onReplySelected(int newrid,String txt){
  rid=newrid;
  if (rid > 0) {
    SpannableStringBuilder ssb=new SpannableStringBuilder();
    String inreplyto=getResources().getString(R.string.In_reply_to_) + " ";
    ssb.append(inreplyto + txt);
    ssb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),0,inreplyto.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    tvReplyTo.setText(ssb);
    tvReplyTo.setVisibility(View.VISIBLE);
  }
 else {
    tvReplyTo.setVisibility(View.GONE);
  }
}
 

Example 12

From project conference-mobile-app, under directory /android-app/src/com/google/android/apps/iosched/util/.

Source file: UIUtils.java

  22 
vote

/** 
 * Given a snippet string with matching segments surrounded by curly braces, turn those areas into bold spans, removing the curly braces.
 */
public static Spannable buildStyledSnippet(String snippet){
  final SpannableStringBuilder builder=new SpannableStringBuilder(snippet);
  int startIndex=-1, endIndex=-1, delta=0;
  while ((startIndex=snippet.indexOf('{',endIndex)) != -1) {
    endIndex=snippet.indexOf('}',startIndex);
    builder.delete(startIndex - delta,startIndex - delta + 1);
    builder.delete(endIndex - delta - 1,endIndex - delta);
    builder.setSpan(sBoldSpan,startIndex - delta,endIndex - delta - 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    delta+=2;
  }
  return builder;
}
 

Example 13

From project dccsched, under directory /src/com/underhilllabs/dccsched/util/.

Source file: UIUtils.java

  22 
vote

/** 
 * Given a snippet string with matching segments surrounded by curly braces, turn those areas into bold spans, removing the curly braces.
 */
public static Spannable buildStyledSnippet(String snippet){
  final SpannableStringBuilder builder=new SpannableStringBuilder(snippet);
  int startIndex=-1, endIndex=-1, delta=0;
  while ((startIndex=snippet.indexOf('{',endIndex)) != -1) {
    endIndex=snippet.indexOf('}',startIndex);
    builder.delete(startIndex - delta,startIndex - delta + 1);
    builder.delete(endIndex - delta - 1,endIndex - delta);
    builder.setSpan(sBoldSpan,startIndex - delta,endIndex - delta - 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    delta+=2;
  }
  return builder;
}
 

Example 14

From project dcnyc10-android, under directory /android/src/com/lullabot/android/apps/iosched/util/.

Source file: UIUtils.java

  22 
vote

/** 
 * Given a snippet string with matching segments surrounded by curly braces, turn those areas into bold spans, removing the curly braces.
 */
public static Spannable buildStyledSnippet(String snippet){
  final SpannableStringBuilder builder=new SpannableStringBuilder(snippet);
  int startIndex=-1, endIndex=-1, delta=0;
  while ((startIndex=snippet.indexOf('{',endIndex)) != -1) {
    endIndex=snippet.indexOf('}',startIndex);
    builder.delete(startIndex - delta,startIndex - delta + 1);
    builder.delete(endIndex - delta - 1,endIndex - delta);
    builder.setSpan(sBoldSpan,startIndex - delta,endIndex - delta - 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    delta+=2;
  }
  return builder;
}
 

Example 15

From project devoxx-france-android-in-fine, under directory /src/com/infine/android/devoxx/util/.

Source file: UIUtils.java

  22 
vote

/** 
 * Given a snippet string with matching segments surrounded by curly braces, turn those areas into bold spans, removing the curly braces.
 */
public static Spannable buildStyledSnippet(String snippet){
  final SpannableStringBuilder builder=new SpannableStringBuilder(snippet);
  int startIndex=-1, endIndex=-1, delta=0;
  while ((startIndex=snippet.indexOf('{',endIndex)) != -1) {
    endIndex=snippet.indexOf('}',startIndex);
    builder.delete(startIndex - delta,startIndex - delta + 1);
    builder.delete(endIndex - delta - 1,endIndex - delta);
    builder.setSpan(sBoldSpan,startIndex - delta,endIndex - delta - 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    delta+=2;
  }
  return builder;
}
 

Example 16

From project Diktofon, under directory /app/src/kaljurand_at_gmail_dot_com/diktofon/.

Source file: GuiUtils.java

  22 
vote

public static Spannable highlightCollection(Collection<String> collection,int color){
  SpannableStringBuilder ssb=new SpannableStringBuilder();
  for (  String str : collection) {
    ssb.append(' ');
    int start=ssb.length();
    ssb.append(str);
    int end=ssb.length();
    ssb.setSpan(new HighlightSpan(color),start,end,Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
  }
  return ssb;
}
 

Example 17

From project evodroid, under directory /src/com/sonorth/evodroid/.

Source file: EditPost.java

  22 
vote

@Override protected SpannableStringBuilder doInBackground(Vector<?>... args){
  ArrayList<?> multi_stream=(ArrayList<?>)args[0].get(0);
  String type=(String)args[0].get(1);
  SpannableStringBuilder ssb=new SpannableStringBuilder();
  for (int i=0; i < multi_stream.size(); i++) {
    Uri curStream=(Uri)multi_stream.get(i);
    if (curStream != null && type != null) {
      String imgPath=curStream.getEncodedPath();
      ssb=addMediaFromShareAction(imgPath,curStream,ssb);
    }
  }
  return ssb;
}
 

Example 18

From project examples_2, under directory /SearchView/search-view-lib/src/com/actionbarsherlock/widget/searchview/internal/.

Source file: CompatSearchView.java

  22 
vote

private CharSequence getDecoratedHint(CharSequence hintText){
  if (!mIconifiedByDefault)   return hintText;
  SpannableStringBuilder ssb=new SpannableStringBuilder("   ");
  ssb.append(hintText);
  Drawable searchIcon=getContext().getResources().getDrawable(getSearchIconId());
  int textSize=(int)(mQueryTextView.getTextSize() * 1.25);
  searchIcon.setBounds(0,0,textSize,textSize);
  ssb.setSpan(new ImageSpan(searchIcon),1,2,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  return ssb;
}
 

Example 19

From project gddsched2, under directory /trunk/android/src/com/google/android/apps/iosched2/util/.

Source file: UIUtils.java

  22 
vote

/** 
 * Given a snippet string with matching segments surrounded by curly braces, turn those areas into bold spans, removing the curly braces.
 */
public static Spannable buildStyledSnippet(String snippet){
  final SpannableStringBuilder builder=new SpannableStringBuilder(snippet);
  int startIndex=-1, endIndex=-1, delta=0;
  while ((startIndex=snippet.indexOf('{',endIndex)) != -1) {
    endIndex=snippet.indexOf('}',startIndex);
    builder.delete(startIndex - delta,startIndex - delta + 1);
    builder.delete(endIndex - delta - 1,endIndex - delta);
    builder.setSpan(sBoldSpan,startIndex - delta,endIndex - delta - 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    delta+=2;
  }
  return builder;
}
 

Example 20

From project ICS_LatinIME_QHD, under directory /java/src/com/android/inputmethod/deprecated/.

Source file: VoiceProxy.java

  22 
vote

private Spanned replaceURLSpan(CharSequence message){
  final SpannableStringBuilder ssb=new SpannableStringBuilder(message);
  for (  URLSpan span : ssb.getSpans(0,ssb.length(),URLSpan.class)) {
    int spanStart=ssb.getSpanStart(span);
    int spanEnd=ssb.getSpanEnd(span);
    int spanFlags=ssb.getSpanFlags(span);
    ssb.removeSpan(span);
    ssb.setSpan(new ClickableSpan(span.getURL()),spanStart,spanEnd,spanFlags);
  }
  return ssb;
}
 

Example 21

From project iosched, under directory /android/src/com/google/android/apps/iosched/util/.

Source file: UIUtils.java

  22 
vote

/** 
 * Given a snippet string with matching segments surrounded by curly braces, turn those areas into bold spans, removing the curly braces.
 */
public static Spannable buildStyledSnippet(String snippet){
  final SpannableStringBuilder builder=new SpannableStringBuilder(snippet);
  int startIndex=-1, endIndex=-1, delta=0;
  while ((startIndex=snippet.indexOf('{',endIndex)) != -1) {
    endIndex=snippet.indexOf('}',startIndex);
    builder.delete(startIndex - delta,startIndex - delta + 1);
    builder.delete(endIndex - delta - 1,endIndex - delta);
    builder.setSpan(sBoldSpan,startIndex - delta,endIndex - delta - 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    delta+=2;
  }
  return builder;
}
 

Example 22

From project iosched2011, under directory /android/src/com/google/android/apps/iosched/util/.

Source file: UIUtils.java

  22 
vote

/** 
 * Given a snippet string with matching segments surrounded by curly braces, turn those areas into bold spans, removing the curly braces.
 */
public static Spannable buildStyledSnippet(String snippet){
  final SpannableStringBuilder builder=new SpannableStringBuilder(snippet);
  int startIndex=-1, endIndex=-1, delta=0;
  while ((startIndex=snippet.indexOf('{',endIndex)) != -1) {
    endIndex=snippet.indexOf('}',startIndex);
    builder.delete(startIndex - delta,startIndex - delta + 1);
    builder.delete(endIndex - delta - 1,endIndex - delta);
    builder.setSpan(sBoldSpan,startIndex - delta,endIndex - delta - 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    delta+=2;
  }
  return builder;
}
 

Example 23

From project iosched_1, under directory /src/com/google/android/apps/iosched/util/.

Source file: UIUtils.java

  22 
vote

/** 
 * Given a snippet string with matching segments surrounded by curly braces, turn those areas into bold spans, removing the curly braces.
 */
public static Spannable buildStyledSnippet(String snippet){
  final SpannableStringBuilder builder=new SpannableStringBuilder(snippet);
  int startIndex=-1, endIndex=-1, delta=0;
  while ((startIndex=snippet.indexOf('{',endIndex)) != -1) {
    endIndex=snippet.indexOf('}',startIndex);
    builder.delete(startIndex - delta,startIndex - delta + 1);
    builder.delete(endIndex - delta - 1,endIndex - delta);
    builder.setSpan(sBoldSpan,startIndex - delta,endIndex - delta - 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    delta+=2;
  }
  return builder;
}
 

Example 24

From project iosched_2, under directory /android/src/com/google/android/apps/iosched/util/.

Source file: UIUtils.java

  22 
vote

/** 
 * Given a snippet string with matching segments surrounded by curly braces, turn those areas into bold spans, removing the curly braces.
 */
public static Spannable buildStyledSnippet(String snippet){
  final SpannableStringBuilder builder=new SpannableStringBuilder(snippet);
  int startIndex=-1, endIndex=-1, delta=0;
  while ((startIndex=snippet.indexOf('{',endIndex)) != -1) {
    endIndex=snippet.indexOf('}',startIndex);
    builder.delete(startIndex - delta,startIndex - delta + 1);
    builder.delete(endIndex - delta - 1,endIndex - delta);
    builder.setSpan(sBoldSpan,startIndex - delta,endIndex - delta - 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    delta+=2;
  }
  return builder;
}
 

Example 25

From project iosched_3, under directory /android/src/com/google/android/apps/iosched/util/.

Source file: UIUtils.java

  22 
vote

/** 
 * Given a snippet string with matching segments surrounded by curly braces, turn those areas into bold spans, removing the curly braces.
 */
public static Spannable buildStyledSnippet(String snippet){
  final SpannableStringBuilder builder=new SpannableStringBuilder(snippet);
  int startIndex=-1, endIndex=-1, delta=0;
  while ((startIndex=snippet.indexOf('{',endIndex)) != -1) {
    endIndex=snippet.indexOf('}',startIndex);
    builder.delete(startIndex - delta,startIndex - delta + 1);
    builder.delete(endIndex - delta - 1,endIndex - delta);
    builder.setSpan(sBoldSpan,startIndex - delta,endIndex - delta - 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    delta+=2;
  }
  return builder;
}
 

Example 26

From project kumvandroid, under directory /src/com/ijuru/kumva/ui/.

Source file: Format.java

  22 
vote

/** 
 * Formats the roots into a spannable string of links
 * @param context the context
 * @param defLang the active dictionary's definition language
 * @param tags the root tags
 * @return the spannable string
 */
public static Spannable rootList(Context context,String defLang,List<Tag> tags){
  if (tags == null || tags.size() == 0)   return null;
  SpannableStringBuilder sb=new SpannableStringBuilder();
  for (int t=0; t < tags.size(); ++t) {
    Tag tag=tags.get(t);
    if (t > 0)     sb.append(", ");
    if (tag.getLang().equals(defLang))     sb.append(queryLink(context,tag.getText()));
 else     sb.append(Utils.capitalize(tag.getLang()) + ". " + tag.getText());
  }
  return sb;
}
 

Example 27

From project MIT-Mobile-for-Android, under directory /src/edu/mit/mitmobile2/libraries/.

Source file: LibraryDetailView.java

  22 
vote

private Spannable composeDetailInfo(){
  SpannableStringBuilder builder=new SpannableStringBuilder();
  builder.append(bold("Today's Hours: "));
  builder.append(bodyText(mLibraryItem.hoursToday));
  builder.append("\n\n");
  addTermContent(builder,mLibraryItem.currentTerm);
  for (  Schedule term : mLibraryItem.previousTerms) {
    addTermContent(builder,term);
  }
  for (  Schedule term : mLibraryItem.nextTerms) {
    addTermContent(builder,term);
  }
  return builder;
}
 

Example 28

From project MyHeath-Android, under directory /actionbarlib/src/com/actionbarsherlock/widget/.

Source file: SearchViewSherlock.java

  22 
vote

private CharSequence getDecoratedHint(CharSequence hintText){
  if (!mIconifiedByDefault)   return hintText;
  SpannableStringBuilder ssb=new SpannableStringBuilder("   ");
  ssb.append(hintText);
  Drawable searchIcon=getContext().getResources().getDrawable(getSearchIconId());
  int textSize=(int)(mQueryTextView.getTextSize() * 1.25);
  searchIcon.setBounds(0,0,textSize,textSize);
  ssb.setSpan(new ImageSpan(searchIcon),1,2,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  return ssb;
}
 

Example 29

From project platform_frameworks_ex, under directory /common/java/com/android/ex/editstyledtext/.

Source file: EditStyledText.java

  22 
vote

private SpannableStringBuilder removeImageChar(SpannableStringBuilder text){
  SpannableStringBuilder buf=new SpannableStringBuilder(text);
  DynamicDrawableSpan[] styles=buf.getSpans(0,buf.length(),DynamicDrawableSpan.class);
  for (  DynamicDrawableSpan style : styles) {
    if (style instanceof HorizontalLineSpan || style instanceof RescalableImageSpan) {
      int start=buf.getSpanStart(style);
      int end=buf.getSpanEnd(style);
      buf.replace(start,end,"");
    }
  }
  return buf;
}
 

Example 30

From project platform_packages_apps_contacts, under directory /tests/src/com/android/contacts/util/.

Source file: HtmlUtilsTest.java

  22 
vote

public void testPostProcess_with_newlines(){
  final SpannableStringBuilder builder=new SpannableStringBuilder("01234\n\n");
  setSpans(builder);
  checkPostProcess(HtmlUtils.postprocess(getContext(),builder));
  checkPostProcess(HtmlUtils.postprocess(getContext(),new SpannedString(builder)));
}
 

Example 31

From project platform_packages_apps_mms, under directory /src/com/android/mms/transaction/.

Source file: MessagingNotification.java

  22 
vote

public CharSequence formatPictureMessage(Context context){
  final TextAppearanceSpan notificationSubjectSpan=new TextAppearanceSpan(context,R.style.NotificationPrimaryText);
  final String message=!TextUtils.isEmpty(mMessage) ? mMessage.replaceAll("\\n\\s+","\n") : "";
  SpannableStringBuilder spannableStringBuilder=new SpannableStringBuilder();
  if (!TextUtils.isEmpty(mSubject)) {
    spannableStringBuilder.append(mSubject);
    spannableStringBuilder.setSpan(notificationSubjectSpan,0,mSubject.length(),0);
  }
  if (message.length() > 0 && spannableStringBuilder.length() == 0) {
    spannableStringBuilder.append(message);
    spannableStringBuilder.setSpan(notificationSubjectSpan,0,message.length(),0);
  }
  return spannableStringBuilder;
}
 

Example 32

From project rbb, under directory /src/com/btmura/android/reddit/text/.

Source file: Formatter.java

  22 
vote

static CharSequence replace(CharSequence s,int start,int end,String r){
  if (!(s instanceof SpannableStringBuilder)) {
    s=new SpannableStringBuilder(s);
  }
  SpannableStringBuilder b=(SpannableStringBuilder)s;
  b.replace(start,end,r);
  return s;
}
 

Example 33

From project RC4A, under directory /src/org/rubychina/android/util/.

Source file: ImageParser.java

  22 
vote

public CharSequence replace(String text){
  SpannableStringBuilder builder=new SpannableStringBuilder(text);
  Matcher matcher=mPattern.matcher(text);
  while (matcher.find()) {
    String rawUrl=text.substring(matcher.start(),matcher.end());
    String url=getImageUrl(rawUrl);
    Bitmap b=((RCApplication)mContext.getApplicationContext()).getImgLoader().load(url,null);
    if (b != null) {
      builder.setSpan(new ImageSpan(mContext,getScaledBitmap(b)),matcher.start(),matcher.end(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
  }
  return builder;
}
 

Example 34

From project rozkladpkp-android, under directory /src/org/tyszecki/rozkladpkp/.

Source file: ConnectionsWidget.java

  22 
vote

static Spannable delayText(String time,int delay){
  ForegroundColorSpan span;
  if (delay <= 0)   span=new ForegroundColorSpan(Color.rgb(73,194,98));
 else   if (delay <= 5)   span=new ForegroundColorSpan(Color.rgb(197,170,73));
 else   span=new ForegroundColorSpan(Color.rgb(220,59,76));
  time+=(delay >= 0) ? " +" : " ";
  time+=Integer.toString(delay);
  SpannableStringBuilder spanBuilder=new SpannableStringBuilder();
  spanBuilder.clearSpans();
  spanBuilder.clear();
  spanBuilder.append(time);
  spanBuilder.setSpan(span,6,time.length(),Spannable.SPAN_INCLUSIVE_INCLUSIVE);
  return spanBuilder;
}
 

Example 35

From project Schedule, under directory /android/src/com/happytap/schedule/adapter/.

Source file: ScheduleAdapter.java

  22 
vote

public static CharSequence time(StationToStation sts){
  String depart=time.format(sts.getDepartTime().getTime());
  String arrive=time.format(sts.getArriveTime().getTime());
  String orig=String.format("%s - %s #%s",depart,arrive,sts.blockId).toLowerCase();
  SpannableStringBuilder ssb=new SpannableStringBuilder(orig);
  int pound=orig.indexOf("#");
  if (pound >= 0) {
    ssb.setSpan(new SuperscriptSpan(),pound,orig.length(),0);
  }
  return ssb;
}
 

Example 36

From project ShortcutLink, under directory /src/org/bibimbap/shortcutlink/.

Source file: Help.java

  22 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  setContentView(R.layout.help);
  TextView msg=(TextView)findViewById(R.id.help_usage);
  SpannableStringBuilder builder=new SpannableStringBuilder();
  String helpSteps[]=getResources().getStringArray(R.array.help_steps);
  for (int index=0; index < helpSteps.length; index++) {
    builder.append(String.valueOf(index + 1) + ") ");
    builder.append(Html.fromHtml(helpSteps[index]));
    builder.append("\n");
  }
  msg.setText(builder);
}
 

Example 37

From project smsdroid, under directory /src/de/ub0r/android/smsdroid/.

Source file: SmileyParser.java

  22 
vote

/** 
 * Adds ImageSpans to a CharSequence that replace textual emoticons such as :-) with a graphical version.
 * @param text A CharSequence possibly containing emoticons
 * @return A CharSequence annotated with ImageSpans covering any recognizedemoticons.
 */
public CharSequence addSmileySpans(final CharSequence text){
  SpannableStringBuilder builder=new SpannableStringBuilder(text);
  Matcher matcher=this.mPattern.matcher(text);
  while (matcher.find()) {
    int resId=this.mSmileyToRes.get(matcher.group());
    builder.setSpan(new ImageSpan(this.mContext,resId),matcher.start(),matcher.end(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  }
  return builder;
}
 

Example 38

From project TextSecure, under directory /src/org/thoughtcrime/securesms/contacts/.

Source file: RecipientsEditor.java

  22 
vote

public void populate(Recipients list){
  SpannableStringBuilder sb=new SpannableStringBuilder();
  for (  Recipient c : list.getRecipientsList()) {
    if (sb.length() != 0) {
      sb.append(", ");
    }
    sb.append(contactToToken(c));
  }
  setText(sb);
}
 

Example 39

From project Wordpress-Android-App, under directory /src/org/wordpress/android/.

Source file: EditPost.java

  22 
vote

@Override protected SpannableStringBuilder doInBackground(Vector<?>... args){
  ArrayList<?> multi_stream=(ArrayList<?>)args[0].get(0);
  String type=(String)args[0].get(1);
  SpannableStringBuilder ssb=new SpannableStringBuilder();
  for (int i=0; i < multi_stream.size(); i++) {
    Uri curStream=(Uri)multi_stream.get(i);
    if (curStream != null && type != null) {
      String imgPath=curStream.getEncodedPath();
      ssb=addMediaFromShareAction(imgPath,curStream,ssb);
    }
  }
  return ssb;
}
 

Example 40

From project android_frameworks_ex, under directory /common/java/com/android/common/.

Source file: Rfc822InputFilter.java

  21 
vote

public CharSequence filter(CharSequence source,int start,int end,Spanned dest,int dstart,int dend){
  if (end - start != 1 || source.charAt(start) != ' ') {
    return null;
  }
  int scanBack=dstart;
  boolean dotFound=false;
  while (scanBack > 0) {
    char c=dest.charAt(--scanBack);
switch (c) {
case '.':
      dotFound=true;
    break;
case ',':
  return null;
case '@':
if (!dotFound) {
  return null;
}
if (source instanceof Spanned) {
SpannableStringBuilder sb=new SpannableStringBuilder(",");
sb.append(source);
return sb;
}
 else {
return ", ";
}
default :
}
}
return null;
}
 

Example 41

From project android_packages_apps_QuickSearchBox, under directory /src/com/android/quicksearchbox/.

Source file: SearchWidgetProvider.java

  21 
vote

private static CharSequence formatVoiceSearchHint(Context context,CharSequence hint){
  if (TextUtils.isEmpty(hint))   return null;
  SpannableStringBuilder spannedHint=new SpannableStringBuilder(context.getString(R.string.voice_search_hint_quotation_start));
  spannedHint.append(hint);
  Object[] items=spannedHint.getSpans(0,spannedHint.length(),Object.class);
  for (  Object item : items) {
    if (item instanceof Annotation) {
      Annotation annotation=(Annotation)item;
      if (annotation.getKey().equals("action") && annotation.getValue().equals("true")) {
        final int start=spannedHint.getSpanStart(annotation);
        final int end=spannedHint.getSpanEnd(annotation);
        spannedHint.removeSpan(item);
        spannedHint.setSpan(new StyleSpan(Typeface.BOLD),start,end,0);
      }
    }
  }
  spannedHint.append(context.getString(R.string.voice_search_hint_quotation_end));
  return spannedHint;
}
 

Example 42

From project Anki-Android, under directory /src/com/ichi2/anki/.

Source file: AnkiDroidWidget.java

  21 
vote

private CharSequence getDeckText(){
  String deckName=formatDeckName();
  SpannableStringBuilder sb=new SpannableStringBuilder();
  sb.append(deckName);
  sb.append(" ");
  SpannableString red=new SpannableString(Integer.toString(mFailedCards));
  red.setSpan(new ForegroundColorSpan(Color.RED),0,red.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  SpannableString black=new SpannableString(Integer.toString(mDueCards));
  black.setSpan(new ForegroundColorSpan(Color.BLACK),0,black.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  SpannableString blue=new SpannableString(Integer.toString(mNewCards));
  blue.setSpan(new ForegroundColorSpan(Color.BLUE),0,blue.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  sb.append(red);
  sb.append(" ");
  sb.append(black);
  sb.append(" ");
  sb.append(blue);
  return sb;
}
 

Example 43

From project BombusLime, under directory /src/org/bombusim/lime/fragments/.

Source file: ChatFragment.java

  21 
vote

public void setText(long time,String sender,String message,int messageType){
  long delay=System.currentTimeMillis() - time;
  String fmt="%H:%M ";
  if (delay > MS_PER_DAY) {
    fmt="%d.%m.%Y %H:%M ";
  }
  tf.set(time);
  String tm=tf.format(fmt);
  SpannableStringBuilder ss=new SpannableStringBuilder(tm);
  int addrEnd=0;
  if (message.startsWith("/me ")) {
    message="*" + message.replaceAll("(/me)(?:\\s|$)",sender + ' ');
    ;
  }
 else {
    ss.append('<').append(sender).append("> ");
  }
  addrEnd=ss.length() - 1;
  int color=Message.getColor(messageType);
  ss.setSpan(new ForegroundColorSpan(color),0,addrEnd,Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
  SpannableString msg=new SpannableString(message);
  Linkify.addLinks(msg,Linkify.EMAIL_ADDRESSES | Linkify.WEB_URLS);
  Lime.getInstance().getSmilify().addSmiles(msg);
  ss.append(msg);
  setText(ss);
  setMovementMethod(LinkMovementMethod.getInstance());
}
 

Example 44

From project cmsandroid, under directory /src/com/zia/freshdocs/widget/.

Source file: HostAdapter.java

  21 
vote

@Override public View getView(int position,View convertView,ViewGroup parent){
  Context context=getContext();
  Resources res=context.getResources();
  ViewGroup container=(ViewGroup)super.getView(position,convertView,parent);
  TextView child=(TextView)container.getChildAt(0);
  CMISHost host=getItem(position);
  child.setText(host.getHostname());
  if (host.getId().equals(Constants.NEW_HOST_ID)) {
    SpannableStringBuilder sb=new SpannableStringBuilder(res.getString(com.zia.freshdocs.R.string.add_server));
    sb.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC),0,sb.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    child.setText(sb);
    child.setTextAppearance(context,R.style.TextAppearance_Medium);
    Drawable icon=res.getDrawable(R.drawable.ic_menu_add);
    icon.setBounds(new Rect(0,0,25,25));
    child.setCompoundDrawables(icon,null,null,null);
  }
 else {
    child.setTextAppearance(context,R.style.TextAppearance_Large);
    child.setCompoundDrawables(null,null,null,null);
  }
  return container;
}
 

Example 45

From project DeliciousDroid, under directory /src/com/deliciousdroid/activity/.

Source file: AddBookmark.java

  21 
vote

protected void onPostExecute(ArrayList<Tag> result){
  mRecommendedProgress.setVisibility(View.GONE);
  mPopularProgress.setVisibility(View.GONE);
  mNetworkProgress.setVisibility(View.GONE);
  if (result != null) {
    SpannableStringBuilder recommendedBuilder=new SpannableStringBuilder();
    SpannableStringBuilder popularBuilder=new SpannableStringBuilder();
    SpannableStringBuilder networkBuilder=new SpannableStringBuilder();
    for (    Tag t : result) {
      if (t.getType().equals("recommended")) {
        addTag(recommendedBuilder,t);
      }
 else       if (t.getType().equals("popular")) {
        addTag(popularBuilder,t);
      }
 else       if (t.getType().equals("network")) {
        addTag(networkBuilder,t);
      }
    }
    mRecommendedTags.setText(recommendedBuilder);
    mPopularTags.setText(popularBuilder);
    mNetworkTags.setText(networkBuilder);
    mRecommendedTags.setVisibility(View.VISIBLE);
    mPopularTags.setVisibility(View.VISIBLE);
    mNetworkTags.setVisibility(View.VISIBLE);
  }
}
 

Example 46

From project friendica-for-android, under directory /mw-android-friendica-01/src/de/wikilab/android/friendica01/.

Source file: Max.java

  21 
vote

public static void setHtmlWithImages(TextView t,String html){
  Spanned spanned=Html.fromHtml(html);
  Spannable htmlSpannable;
  if (spanned instanceof SpannableStringBuilder) {
    htmlSpannable=(SpannableStringBuilder)spanned;
  }
 else {
    htmlSpannable=new SpannableStringBuilder(spanned);
  }
  t.setText(htmlSpannable);
  new ImageLoadTask(t.getContext(),htmlSpannable,t).execute();
}
 

Example 47

From project Gibberbot, under directory /src/info/guardianproject/otr/app/im/app/.

Source file: MessageView.java

  21 
vote

private CharSequence formatMessage(String contact,String body,Date date,Markup smileyRes,boolean scrolling){
  if (body.indexOf('\r') != -1) {
    body=body.replace("\r\n","\n").replace('\r','\n');
  }
  body=body.replaceAll("\\<.*?\\>","");
  SpannableStringBuilder buf=new SpannableStringBuilder();
  if (contact != null) {
    buf.append(contact);
    buf.append(": ");
  }
  if (scrolling) {
    buf.append(body);
  }
 else {
    buf.setSpan(ChatView.STYLE_BOLD,0,buf.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    buf.append(body);
    if (date != null) {
      appendTimeStamp(buf,date);
    }
  }
  return buf;
}
 

Example 48

From project k-9, under directory /src/com/fsck/k9/mail/.

Source file: Address.java

  21 
vote

public static CharSequence toFriendly(Address[] addresses,Contacts contacts){
  if (addresses == null) {
    return null;
  }
  if (addresses.length >= TOO_MANY_ADDRESSES) {
    contacts=null;
  }
  SpannableStringBuilder sb=new SpannableStringBuilder();
  for (int i=0; i < addresses.length; i++) {
    sb.append(addresses[i].toFriendly(contacts));
    if (i < addresses.length - 1) {
      sb.append(',');
    }
  }
  return sb;
}
 

Example 49

From project packages_apps_Calendar, under directory /src/com/android/calendar/.

Source file: DayView.java

  21 
vote

/** 
 * Return the layout for a numbered event. Create it if not already existing
 */
private StaticLayout getEventLayout(StaticLayout[] layouts,int i,Event event,Paint paint,Rect r){
  if (i < 0 || i >= layouts.length) {
    return null;
  }
  StaticLayout layout=layouts[i];
  if (layout == null || r.width() != layout.getWidth()) {
    SpannableStringBuilder bob=new SpannableStringBuilder();
    if (event.title != null) {
      bob.append(drawTextSanitizer(event.title.toString(),MAX_EVENT_TEXT_LEN - 1));
      bob.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),0,bob.length(),0);
      bob.append(' ');
    }
    if (event.location != null) {
      bob.append(drawTextSanitizer(event.location.toString(),MAX_EVENT_TEXT_LEN - bob.length()));
    }
switch (event.selfAttendeeStatus) {
case Attendees.ATTENDEE_STATUS_INVITED:
      paint.setColor(event.color);
    break;
case Attendees.ATTENDEE_STATUS_DECLINED:
  paint.setColor(mEventTextColor);
paint.setAlpha(Utils.DECLINED_EVENT_TEXT_ALPHA);
break;
case Attendees.ATTENDEE_STATUS_NONE:
case Attendees.ATTENDEE_STATUS_ACCEPTED:
case Attendees.ATTENDEE_STATUS_TENTATIVE:
default :
paint.setColor(mEventTextColor);
break;
}
layout=new StaticLayout(bob,0,bob.length(),new TextPaint(paint),r.width(),Alignment.ALIGN_NORMAL,1.0f,0.0f,true,null,r.width());
layouts[i]=layout;
}
return layout;
}
 

Example 50

From project PageTurner, under directory /src/main/java/net/nightwhistler/pageturner/view/.

Source file: ScrollingStrategy.java

  21 
vote

private Spanned addEndTag(Spanned text){
  PageTurnerSpine spine=bookView.getSpine();
  if (spine == null || spine.getPosition() >= spine.size() - 1) {
    return text;
  }
  SpannableStringBuilder builder=new SpannableStringBuilder(text);
  int length=builder.length();
  builder.append("\uFFFC");
  builder.append("\n");
  builder.append("End of section. Click here to continue.");
  ClickableSpan span=new ClickableSpan(){
    @Override public void onClick(    View widget){
      pageDown();
    }
  }
;
  Drawable img=context.getResources().getDrawable(R.drawable.gateway);
  img.setBounds(0,0,img.getIntrinsicWidth(),img.getIntrinsicHeight());
  builder.setSpan(new ImageSpan(img),length,length + 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  builder.setSpan(span,length,builder.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  builder.setSpan(new AlignmentSpan(){
    @Override public Alignment getAlignment(){
      return Alignment.ALIGN_CENTER;
    }
  }
,length,builder.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  return builder;
}
 

Example 51

From project PinDroid, under directory /src/com/pindroid/fragment/.

Source file: AddBookmarkFragment.java

  21 
vote

protected void onPostExecute(ArrayList<Tag> result){
  if (result != null) {
    SpannableStringBuilder recommendedBuilder=new SpannableStringBuilder();
    SpannableStringBuilder popularBuilder=new SpannableStringBuilder();
    for (    Tag t : result) {
      if (t.getType().equals("recommended")) {
        addTag(recommendedBuilder,t);
      }
 else       if (t.getType().equals("popular")) {
        addTag(popularBuilder,t);
      }
    }
    mRecommendedTags.setText(recommendedBuilder);
    mPopularTags.setText(popularBuilder);
    mRecommendedTags.setVisibility(View.VISIBLE);
    mPopularTags.setVisibility(View.VISIBLE);
    mRecommendedProgress.setVisibility(View.GONE);
    mPopularProgress.setVisibility(View.GONE);
  }
}
 

Example 52

From project platform_packages_apps_calendar, under directory /src/com/android/calendar/alerts/.

Source file: AlertReceiver.java

  21 
vote

/** 
 * Creates an expanding notification.  The initial expanded state is decided by the notification manager based on the priority.
 */
public static NotificationWrapper makeExpandingNotification(Context context,String title,String summaryText,String description,long startMillis,long endMillis,long eventId,int notificationId,boolean doPopup,boolean highPriority){
  Notification.Builder basicBuilder=makeBasicNotificationBuilder(context,title,summaryText,startMillis,endMillis,eventId,notificationId,doPopup,highPriority,true);
  Notification.BigTextStyle expandedBuilder=new Notification.BigTextStyle(basicBuilder);
  if (description != null) {
    description=mBlankLinePattern.matcher(description).replaceAll("");
    description=description.trim();
  }
  CharSequence text;
  if (TextUtils.isEmpty(description)) {
    text=summaryText;
  }
 else {
    SpannableStringBuilder stringBuilder=new SpannableStringBuilder();
    stringBuilder.append(summaryText);
    stringBuilder.append("\n\n");
    stringBuilder.setSpan(new RelativeSizeSpan(0.5f),summaryText.length(),stringBuilder.length(),0);
    stringBuilder.append(description);
    text=stringBuilder;
  }
  expandedBuilder.bigText(text);
  return new NotificationWrapper(expandedBuilder.build(),notificationId,eventId,startMillis,endMillis,doPopup);
}
 

Example 53

From project platform_packages_apps_im, under directory /src/com/android/im/app/.

Source file: MessageView.java

  21 
vote

private CharSequence formatMessage(String contact,String body,Date date,Markup smileyRes,boolean scrolling){
  if (body.indexOf('\r') != -1) {
    body=body.replace("\r\n","\n").replace('\r','\n');
  }
  SpannableStringBuilder buf=new SpannableStringBuilder(contact);
  buf.append(": ");
  if (scrolling) {
    buf.append(body);
  }
 else {
    buf.setSpan(ChatView.STYLE_BOLD,0,buf.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    buf.append(smileyRes.markup(body));
    if (date != null) {
      appendTimeStamp(buf,date);
    }
  }
  return buf;
}
 

Example 54

From project reddit-is-fun, under directory /src/com/andrewshu/android/reddit/mail/.

Source file: InboxListActivity.java

  21 
vote

@Override public View getView(int position,View convertView,ViewGroup parent){
  View view;
  ThingInfo item=this.getItem(position);
  if (convertView == null) {
    view=mInflater.inflate(R.layout.inbox_list_item,null);
  }
 else {
    view=convertView;
  }
  TextView fromInfoView=(TextView)view.findViewById(R.id.from_info);
  TextView subjectView=(TextView)view.findViewById(R.id.subject);
  TextView bodyView=(TextView)view.findViewById(R.id.body);
  if (item.isNew())   fromInfoView.setTextColor(getResources().getColor(R.color.red));
 else   fromInfoView.setTextColor(getResources().getColor(R.color.gray_50));
  SpannableStringBuilder builder=new SpannableStringBuilder();
  SpannableString authorSS=new SpannableString(item.getAuthor());
  builder.append("from ");
  int authorLen=item.getAuthor().length();
  StyleSpan authorStyleSpan=new StyleSpan(Typeface.BOLD);
  authorSS.setSpan(authorStyleSpan,0,authorLen,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  ForegroundColorSpan fcs;
  if (Util.isLightTheme(mSettings.getTheme()))   fcs=new ForegroundColorSpan(getResources().getColor(R.color.dark_blue));
 else   fcs=new ForegroundColorSpan(getResources().getColor(R.color.white));
  authorSS.setSpan(fcs,0,authorLen,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  builder.append(authorSS);
  builder.append(" sent ");
  builder.append(Util.getTimeAgo(Double.valueOf(item.getCreated_utc())));
  fromInfoView.setText(builder);
  subjectView.setText(item.getSubject());
  bodyView.setText(item.getSpannedBody());
  return view;
}
 

Example 55

From project ub0rlib, under directory /src/de/ub0r/android/lib/.

Source file: DonationHelper.java

  21 
vote

/** 
 * Show "donate" dialog.
 * @param context {@link Context}
 * @param title title
 * @param btnDonate button text for donate
 * @param btnNoads button text for "i did a donation"
 * @param messages messages for dialog body
 */
public static void showDonationDialog(final Activity context,final String title,final String btnDonate,final String btnNoads,final String[] messages){
  final Intent marketIntent=Market.getInstallAppIntent(context,DONATOR_PACKAGE,null);
  String btnTitle=String.format(btnDonate,"Play Store");
  SpannableStringBuilder sb=new SpannableStringBuilder();
  for (  String m : messages) {
    sb.append(m);
    sb.append("\n");
  }
  sb.delete(sb.length() - 1,sb.length());
  sb.setSpan(new RelativeSizeSpan(0.75f),0,sb.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  AlertDialog.Builder b=new AlertDialog.Builder(context);
  b.setTitle(title);
  b.setMessage(sb);
  b.setCancelable(true);
  b.setPositiveButton(btnTitle,new DialogInterface.OnClickListener(){
    @Override public void onClick(    final DialogInterface dialog,    final int which){
      try {
        context.startActivity(marketIntent);
      }
 catch (      ActivityNotFoundException e) {
        Log.e(TAG,"activity not found",e);
        Toast.makeText(context,"activity not found",Toast.LENGTH_LONG).show();
      }
    }
  }
);
  b.setNeutralButton(btnNoads,new DialogInterface.OnClickListener(){
    @Override public void onClick(    final DialogInterface dialog,    final int which){
      try {
        context.startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://code.google.com/p/ub0rapps/downloads/list?" + "can=3&q=Product%3DDonator")));
      }
 catch (      ActivityNotFoundException e) {
        Log.e(TAG,"activity not found",e);
        Toast.makeText(context,"activity not found",Toast.LENGTH_LONG).show();
      }
    }
  }
);
  b.show();
}
 

Example 56

From project Yaaic, under directory /application/src/org/yaaic/utils/.

Source file: MircColors.java

  21 
vote

/** 
 * Converts a string with mIRC style and color codes to a SpannableString with all the style and color codes applied.
 * @param text  A string with mIRC color codes.
 * @return      A SpannableString with all the styles applied.
 */
public static SpannableString toSpannable(SpannableString text){
  SpannableStringBuilder ssb=new SpannableStringBuilder(text);
  replaceControlCodes(boldPattern.matcher(ssb),ssb,new StyleSpan(Typeface.BOLD));
  replaceControlCodes(underlinePattern.matcher(ssb),ssb,new UnderlineSpan());
  replaceControlCodes(italicPattern.matcher(ssb),ssb,new StyleSpan(Typeface.ITALIC));
  replaceControlCodes(inversePattern.matcher(ssb),ssb,new BackgroundColorSpan(colors[0] | 0xFF000000));
  BackgroundColorSpan[] inverseSpans=ssb.getSpans(0,ssb.length(),BackgroundColorSpan.class);
  for (int i=0; i < inverseSpans.length; i++) {
    ssb.setSpan(new ForegroundColorSpan(colors[1] | 0xFF000000),ssb.getSpanStart(inverseSpans[i]),ssb.getSpanEnd(inverseSpans[i]),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  }
  Matcher m=colorPattern.matcher(ssb);
  while (m.find()) {
    int start=m.start();
    int end=m.end();
    Integer color=Integer.parseInt(m.group(1));
    int codelength=m.group(1).length() + 1;
    if (color <= 15 && color >= 0) {
      ssb.setSpan(new ForegroundColorSpan(colors[color] | 0xFF000000),start,end,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    if (m.group(2) != null) {
      color=Integer.parseInt(m.group(2));
      if (color <= 15 && color >= 0) {
        ssb.setSpan(new BackgroundColorSpan(colors[color] | 0xFF000000),start,end,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
      }
      codelength=codelength + m.group(2).length() + 1;
    }
    ssb.delete(start,start + codelength);
    m.reset(ssb);
  }
  return new SpannableString(removeStyleAndColors(ssb));
}
 

Example 57

From project Yeno-Checklist, under directory /src/com/yeno/checklist/view/.

Source file: ChecklistSelectionActivity.java

  21 
vote

private void reviewProblems(){
  List<Task> problematicTasks=new ArrayList<Task>();
  for (  Checklist checklist : checklistGroup.getChecklists()) {
    for (    Task task : checklist.getTasks()) {
      if (task.getTaskState().equals(TaskState.PROBLEM)) {
        problematicTasks.add(task);
      }
    }
  }
  SpannableStringBuilder sb=new SpannableStringBuilder();
  if (!problematicTasks.isEmpty()) {
    for (    Task problemTask : problematicTasks) {
      sb.append("   - ");
      sb.append(problemTask.getName());
      String problem=problemTask.getProblem();
      if (!TextUtils.isEmpty(problem)) {
        int start=sb.length();
        sb.append("\n      \u21B3 ");
        sb.append(problem);
        int end=sb.length();
        sb.setSpan(new StyleSpan(Typeface.BOLD),start,end,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        sb.setSpan(new ForegroundColorSpan(0xffc54d39),start,end,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      }
      sb.append('\n');
    }
  }
 else {
    sb.append(getString(R.string.no_problem_label));
  }
  new AlertDialog.Builder(this).setTitle(R.string.problems_review_menu).setMessage(sb).setPositiveButton(R.string.clear_all_button,new DialogInterface.OnClickListener(){
    @Override public void onClick(    DialogInterface dialog,    int which){
      for (      Checklist checklist : checklistGroup.getChecklists()) {
        checklist.clearAllProblems();
      }
      adapter.notifyDataSetChanged();
    }
  }
).setNeutralButton(R.string.close_button_label,null).show();
}
 

Example 58

From project creamed_glacier_app_settings, under directory /src/com/android/settings/widget/.

Source file: ChartSweepView.java

  20 
vote

private void invalidateLabelTemplate(){
  if (mLabelTemplateRes != 0) {
    final CharSequence template=getResources().getText(mLabelTemplateRes);
    final TextPaint paint=new TextPaint(Paint.ANTI_ALIAS_FLAG);
    paint.density=getResources().getDisplayMetrics().density;
    paint.setCompatibilityScaling(getResources().getCompatibilityInfo().applicationScale);
    paint.setColor(mLabelColor);
    paint.setShadowLayer(4 * paint.density,0,0,Color.BLACK);
    mLabelTemplate=new SpannableStringBuilder(template);
    mLabelLayout=new DynamicLayout(mLabelTemplate,paint,LARGE_WIDTH,Alignment.ALIGN_RIGHT,1f,0f,false);
    invalidateLabel();
  }
 else {
    mLabelTemplate=null;
    mLabelLayout=null;
  }
  invalidate();
  requestLayout();
}
 

Example 59

From project Gingerbread-Keyboard, under directory /src/com/android/inputmethod/latin/.

Source file: Tutorial.java

  20 
vote

Bubble(Context context,View inputView,int backgroundResource,int bx,int by,int textResource1,int textResource2){
  bubbleBackground=context.getResources().getDrawable(backgroundResource);
  x=bx;
  y=by;
  width=(int)(inputView.getWidth() * 0.9);
  this.gravity=Gravity.TOP | Gravity.LEFT;
  text=new SpannableStringBuilder().append(context.getResources().getText(textResource1)).append("\n").append(context.getResources().getText(textResource2));
  this.dismissOnTouch=true;
  this.dismissOnClose=false;
  this.inputView=inputView;
  window=new PopupWindow(context);
  window.setBackgroundDrawable(null);
  LayoutInflater inflate=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  textView=(TextView)inflate.inflate(R.layout.bubble_text,null);
  textView.setBackgroundDrawable(bubbleBackground);
  textView.setText(text);
  window.setContentView(textView);
  window.setFocusable(false);
  window.setTouchable(true);
  window.setOutsideTouchable(false);
}
 

Example 60

From project HeLauncher, under directory /src/com/handlerexploit/launcher_reloaded/.

Source file: Launcher.java

  20 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  mInflater=getLayoutInflater();
  mAppWidgetManager=AppWidgetManager.getInstance(this);
  mAppWidgetHost=new LauncherAppWidgetHost(this,APPWIDGET_HOST_ID);
  mAppWidgetHost.startListening();
  if (PROFILE_STARTUP) {
    android.os.Debug.startMethodTracing("/sdcard/launcher");
  }
  checkForLocaleChange();
  setWallpaperDimension();
  setContentView(R.layout.launcher);
  setupViews();
  registerIntentReceivers();
  registerContentObservers();
  mSavedState=savedInstanceState;
  restoreState(mSavedState);
  if (PROFILE_STARTUP) {
    android.os.Debug.stopMethodTracing();
  }
  if (!mRestoring)   startLoaders();
  mDefaultKeySsb=new SpannableStringBuilder();
  Selection.setSelection(mDefaultKeySsb,0);
  PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
}
 

Example 61

From project platform_packages_apps_launcher, under directory /src/com/android/launcher/.

Source file: Launcher.java

  20 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  mInflater=getLayoutInflater();
  mAppWidgetManager=AppWidgetManager.getInstance(this);
  mAppWidgetHost=new LauncherAppWidgetHost(this,APPWIDGET_HOST_ID);
  mAppWidgetHost.startListening();
  if (PROFILE_STARTUP) {
    android.os.Debug.startMethodTracing("/sdcard/launcher");
  }
  checkForLocaleChange();
  setWallpaperDimension();
  setContentView(R.layout.launcher);
  setupViews();
  registerIntentReceivers();
  registerContentObservers();
  mSavedState=savedInstanceState;
  restoreState(mSavedState);
  if (PROFILE_STARTUP) {
    android.os.Debug.stopMethodTracing();
  }
  if (!mRestoring) {
    startLoaders();
  }
  mDefaultKeySsb=new SpannableStringBuilder();
  Selection.setSelection(mDefaultKeySsb,0);
}
 

Example 62

From project platform_packages_apps_settings, under directory /src/com/android/settings/widget/.

Source file: ChartSweepView.java

  20 
vote

private void invalidateLabelTemplate(){
  if (mLabelTemplateRes != 0) {
    final CharSequence template=getResources().getText(mLabelTemplateRes);
    final TextPaint paint=new TextPaint(Paint.ANTI_ALIAS_FLAG);
    paint.density=getResources().getDisplayMetrics().density;
    paint.setCompatibilityScaling(getResources().getCompatibilityInfo().applicationScale);
    paint.setColor(mLabelColor);
    paint.setShadowLayer(4 * paint.density,0,0,Color.BLACK);
    mLabelTemplate=new SpannableStringBuilder(template);
    mLabelLayout=new DynamicLayout(mLabelTemplate,paint,LARGE_WIDTH,Alignment.ALIGN_RIGHT,1f,0f,false);
    invalidateLabel();
  }
 else {
    mLabelTemplate=null;
    mLabelLayout=null;
  }
  invalidate();
  requestLayout();
}
 

Example 63

From project RA_Launcher, under directory /src/com/android/ra/launcher/.

Source file: Launcher.java

  20 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  LauncherApplication app=((LauncherApplication)getApplication());
  mModel=app.setLauncher(this);
  mIconCache=app.getIconCache();
  mAppDB=app.getAppDB();
  mDragController=new DragController(this);
  mInflater=getLayoutInflater();
  Preferences.getInstance().setLauncher(this);
  mAppWidgetManager=AppWidgetManager.getInstance(this);
  mAppWidgetHost=new LauncherAppWidgetHost(this,APPWIDGET_HOST_ID);
  mAppWidgetHost.startListening();
  if (PROFILE_STARTUP) {
    android.os.Debug.startMethodTracing(Environment.getExternalStorageDirectory() + "/launcher");
  }
  populateQA();
  checkForLocaleChange();
  setWallpaperDimension();
  setContentView(R.layout.launcher);
  setupViews();
  registerContentObservers();
  mSavedState=savedInstanceState;
  restoreState(mSavedState);
  if (PROFILE_STARTUP) {
    android.os.Debug.stopMethodTracing();
  }
  if (!mRestoring) {
    mModel.startLoader(this,true);
  }
  mDefaultKeySsb=new SpannableStringBuilder();
  Selection.setSelection(mDefaultKeySsb,0);
  IntentFilter filter=new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
  registerReceiver(mCloseSystemDialogsReceiver,filter);
  LauncherActions.getInstance().init(this);
}
 

Example 64

From project RebeLauncher, under directory /src/com/dirtypepper/rebelauncher/.

Source file: Launcher.java

  20 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  mMessWithPersistence=AlmostNexusSettingsHelper.getSystemPersistent(this);
  if (mMessWithPersistence) {
    changeOrientation(AlmostNexusSettingsHelper.getDesktopOrientation(this),true);
    setPersistent(true);
  }
 else {
    setPersistent(false);
    changeOrientation(AlmostNexusSettingsHelper.getDesktopOrientation(this),false);
  }
  mBlockDesktop=AlmostNexusSettingsHelper.getDesktopBlocked(this);
  super.onCreate(savedInstanceState);
  mInflater=getLayoutInflater();
  AppCatalogueFilters.getInstance().init(this);
  LauncherActions.getInstance().init(this);
  mAppWidgetManager=AppWidgetManager.getInstance(this);
  mAppWidgetHost=new LauncherAppWidgetHost(this,APPWIDGET_HOST_ID);
  mAppWidgetHost.startListening();
  if (PROFILE_STARTUP) {
    android.os.Debug.startMethodTracing("/sdcard/launcher");
  }
  updateAlmostNexusVars();
  checkForLocaleChange();
  setWallpaperDimension();
  setContentView(R.layout.launcher);
  setupViews();
  registerIntentReceivers();
  registerContentObservers();
  mSavedState=savedInstanceState;
  restoreState(mSavedState);
  if (PROFILE_STARTUP) {
    android.os.Debug.stopMethodTracing();
  }
  if (!mRestoring) {
    startLoaders();
  }
  mDefaultKeySsb=new SpannableStringBuilder();
  Selection.setSelection(mDefaultKeySsb,0);
  getSharedPreferences("launcher.preferences.almostnexus",Context.MODE_PRIVATE).registerOnSharedPreferenceChangeListener(this);
}
 

Example 65

From project TeclaAccess, under directory /source/src/ca/idi/tekla/ime/.

Source file: Tutorial.java

  20 
vote

Bubble(Context context,View inputView,int backgroundResource,int bx,int by,int textResource1,int textResource2){
  bubbleBackground=context.getResources().getDrawable(backgroundResource);
  x=bx;
  y=by;
  width=(int)(inputView.getWidth() * 0.9);
  this.gravity=Gravity.TOP | Gravity.LEFT;
  text=new SpannableStringBuilder().append(context.getResources().getText(textResource1)).append("\n").append(context.getResources().getText(textResource2));
  this.dismissOnTouch=true;
  this.dismissOnClose=false;
  this.inputView=inputView;
  window=new PopupWindow(context);
  window.setBackgroundDrawable(null);
  LayoutInflater inflate=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  textView=(TextView)inflate.inflate(R.layout.bubble_text,null);
  textView.setBackgroundDrawable(bubbleBackground);
  textView.setText(text);
  window.setContentView(textView);
  window.setFocusable(false);
  window.setTouchable(true);
  window.setOutsideTouchable(false);
}
 

Example 66

From project daily-money, under directory /dailymoney/src/com/bottleworks/dailymoney/calculator2/.

Source file: CalculatorEditable.java

  19 
vote

@Override public SpannableStringBuilder replace(int start,int end,CharSequence tb,int tbstart,int tbend){
  if (isInsideReplace) {
    return super.replace(start,end,tb,tbstart,tbend);
  }
 else {
    isInsideReplace=true;
    try {
      String delta=tb.subSequence(tbstart,tbend).toString();
      return internalReplace(start,end,delta);
    }
  finally {
      isInsideReplace=false;
    }
  }
}
 

Example 67

From project HtmlSpanner, under directory /src/main/java/net/nightwhistler/htmlspanner/handlers/.

Source file: HeaderHandler.java

  19 
vote

@Override public void handleTagNode(TagNode node,SpannableStringBuilder builder,int start,int end){
  builder.setSpan(new RelativeSizeSpan(size),start,end,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  FontFamilySpan boldSpan=new FontFamilySpan(getSpanner().getFontFamily());
  boldSpan.setBold(true);
  builder.setSpan(boldSpan,start,end,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  appendNewLine(builder);
  appendNewLine(builder);
}
 

Example 68

From project platform_packages_apps_calculator, under directory /src/com/android/calculator2/.

Source file: CalculatorEditable.java

  19 
vote

@Override public SpannableStringBuilder replace(int start,int end,CharSequence tb,int tbstart,int tbend){
  if (isInsideReplace) {
    return super.replace(start,end,tb,tbstart,tbend);
  }
 else {
    isInsideReplace=true;
    try {
      String delta=tb.subSequence(tbstart,tbend).toString();
      return internalReplace(start,end,delta);
    }
  finally {
      isInsideReplace=false;
    }
  }
}
 

Example 69

From project TL-android-app, under directory /tlandroidapp/src/org/opensourcetlapp/tl/Adapters/.

Source file: ShowPostAdapter.java

  19 
vote

public ShowPostAdapter(SpannableStringBuilder[] headers,SpannableStringBuilder[] posts,Context context){
  this.headers=headers;
  this.posts=posts;
  this.context=context;
  mInflater=LayoutInflater.from(context);
}