Java Examples for android.text.SpannableString

The following java examples will help you to understand the usage of android.text.SpannableString. These source code samples are taken from different open source projects.

Example 1
Project: 1Sheeld-Android-App-master  File: URLSpanNoUnderline.java View source code
public static void stripUnderlines(TextView textView) {
    Spannable s = new SpannableString(textView.getText());
    URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
    for (URLSpan span : spans) {
        int start = s.getSpanStart(span);
        int end = s.getSpanEnd(span);
        s.removeSpan(span);
        span = new URLSpanNoUnderline(span.getURL());
        s.setSpan(span, start, end, 0);
    }
    textView.setText(s);
}
Example 2
Project: Coding-Android-master  File: HoloUtils.java View source code
/**
     * 关键�加高亮
     *
     * @param textView
     * @param key
     * @param content
     */
public static void setHoloText(TextView textView, String key, String content) {
    if (content.contains("<em>")) {
        int start = content.indexOf("<em>");
        int end = content.indexOf("</em>") - 4;
        content = content.replace("<em>", "").replace("</em>", "");
        SpannableString sp = new SpannableString(content);
        sp.setSpan(new ForegroundColorSpan(Color.RED), start, end, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        textView.setText(sp);
    } else {
        textView.setText(content);
    }
}
Example 3
Project: GameRaven-master  File: PMDetailRowData.java View source code
public static SpannableString linkifyHtml(String html) {
    Spanned spanned = Html.fromHtml(html);
    SpannableString text = new SpannableString(spanned);
    URLSpan[] old = text.getSpans(0, text.length(), URLSpan.class);
    for (int i = old.length - 1; i >= 0; i--) {
        int start = text.getSpanStart(old[i]);
        int end = text.getSpanEnd(old[i]);
        String url = old[i].getURL();
        text.removeSpan(old[i]);
        text.setSpan(new MessageLinkSpan(url, AllInOneV2.get()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    return text;
}
Example 4
Project: gank.io-master  File: StringStyleUtil.java View source code
public static SpannableString getGankStyleStr(Gank gank) {
    String gankStr = gank.desc + " @" + gank.who;
    SpannableString spannableString = new SpannableString(gankStr);
    spannableString.setSpan(new RelativeSizeSpan(0.8f), gank.desc.length() + 1, gankStr.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(new ForegroundColorSpan(Color.GRAY), gank.desc.length() + 1, gankStr.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    return spannableString;
}
Example 5
Project: MagicViews-master  File: MagicUtils.java View source code
public static void addLetterSpacing(float spacing, TextView textView) {
    if (textView != null) {
        String originalText = textView.getText().toString();
        if (originalText.length() > 1) {
            originalText = originalText.replaceAll(MATCH_ALL_CHARACTERS, ADD_SPACE_TO_CHARACTER);
            SpannableString finalText = new SpannableString(originalText);
            finalText.setSpan(new ScaleXSpan(spacing), 0, originalText.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
            textView.setText(finalText, TextView.BufferType.SPANNABLE);
        }
    }
}
Example 6
Project: mensaapp-master  File: AboutDialog.java View source code
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final SpannableString s = new SpannableString(getActivity().getString(R.string.about_text));
    Linkify.addLinks(s, Linkify.ALL);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setMessage(s).setTitle(getActivity().getString(R.string.about_title)).setPositiveButton(getActivity().getString(android.R.string.ok), new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
        }
    });
    return builder.create();
}
Example 7
Project: NasaPic-master  File: URLSpanNoUnderline.java View source code
public static Spannable removeUrlUnderline(CharSequence text) {
    Spannable spannable = new SpannableString(text);
    for (URLSpan span : spannable.getSpans(0, text.length(), URLSpan.class)) {
        int start = spannable.getSpanStart(span);
        int end = spannable.getSpanEnd(span);
        spannable.removeSpan(span);
        span = new URLSpanNoUnderline(span.getURL());
        spannable.setSpan(span, start, end, 0);
    }
    return spannable;
}
Example 8
Project: WhatAndroid-master  File: ColorTagStyle.java View source code
@Override
public Spannable getStyle(CharSequence param, CharSequence text) {
    SpannableString styled = new SpannableString(text);
    //Default to secondary text dark if it's some unsupported color
    int color;
    //If it's a site hex color then parse the hex value otherwise lookup the color name
    switch(param.charAt(0)) {
        case '#':
            color = Integer.parseInt(param.toString().substring(1), 16);
            //Android colors are AARRGGBB but site colors are RRGGBB so stick on the alpha bits and make
            //the color fully opaque
            color |= 0xff << 24;
            break;
        case 'r':
            color = 0xffff4444;
            break;
        case 'g':
            color = 0xff99cc00;
            break;
        case 'b':
            color = 0xff33b5e5;
            break;
        case 'p':
            color = 0xffaa66cc;
            break;
        case 'y':
            color = 0xffffee33;
            break;
        case 'o':
            color = 0xffffbb33;
            break;
        default:
            color = 0xffbebebe;
    }
    styled.setSpan(new ForegroundColorSpan(color), 0, styled.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return styled;
}
Example 9
Project: WifiChat-master  File: PhotoTextView.java View source code
@Override
public void setText(CharSequence text, BufferType type) {
    if (!TextUtils.isEmpty(text) && text.toString().contains("/")) {
        String[] s = text.toString().split("/");
        SpannableString sp = new SpannableString(text);
        sp.setSpan(new AbsoluteSizeSpan((int) (this.getTextSize() + 25)), 0, s[0].length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        super.setText(sp, type);
    } else {
        super.setText(text, type);
    }
}
Example 10
Project: advanced-textview-master  File: ClickableSpanActivity.java View source code
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_clickable_span);
    TextView textView = (TextView) findViewById(R.id.text);
    String text = textView.getText().toString();
    String goToSettings = getString(R.string.go_to_settings);
    int start = text.indexOf(goToSettings);
    int end = start + goToSettings.length();
    SpannableString spannableString = new SpannableString(text);
    spannableString.setSpan(new GoToSettingsSpan(), start, end, 0);
    textView.setText(spannableString);
    textView.setMovementMethod(new LinkMovementMethod());
}
Example 11
Project: aMysqlClient-master  File: SpaceTokenizer.java View source code
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();
    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }
    if (i > 0 && text.charAt(i - 1) == ' ') {
        return text;
    } else {
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text + " ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
Example 12
Project: Bluetooth-LE-Library---Android-master  File: DialogFactory.java View source code
public static Dialog createAboutDialog(final Context context) {
    final View view = LayoutInflater.from(context).inflate(R.layout.dialog_textview, null);
    final TextView textView = (TextView) view.findViewById(R.id.text);
    final SpannableString text = new SpannableString(context.getString(R.string.about_dialog_text));
    textView.setText(text);
    textView.setAutoLinkMask(Activity.RESULT_OK);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    Linkify.addLinks(text, Linkify.ALL);
    final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {

        public void onClick(final DialogInterface dialog, final int id) {
        }
    };
    return new AlertDialog.Builder(context).setTitle(R.string.menu_about).setCancelable(false).setPositiveButton(android.R.string.ok, listener).setView(view).create();
}
Example 13
Project: BookReader-master  File: BookMarkAdapter.java View source code
@Override
public void convert(EasyLVHolder holder, int position, BookMark item) {
    TextView tv = holder.getView(R.id.tvMarkItem);
    SpannableString spanText = new SpannableString((position + 1) + ". " + item.title + ": ");
    spanText.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.light_coffee)), 0, spanText.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    tv.setText(spanText);
    if (item.desc != null) {
        tv.append(item.desc.replaceAll(" ", "").replaceAll(" ", "").replaceAll("\n", ""));
    }
}
Example 14
Project: Carbon-master  File: AllCapsTransformationMethod.java View source code
@Override
public CharSequence getTransformation(CharSequence source, View view) {
    if (source == null)
        return null;
    if (source instanceof Spanned) {
        SpannableString string = new SpannableString(source.toString().toUpperCase(locale));
        TextUtils.copySpansFrom((Spanned) source, 0, source.length(), null, string, 0);
        return string;
    }
    return source.toString().toUpperCase(locale);
}
Example 15
Project: cnBeta-master  File: AboutActivity.java View source code
@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Sherlock___Theme_Light);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setIcon(R.drawable.icon);
    TextView text = (TextView) this.findViewById(R.id.email_text);
    SpannableString msp = new SpannableString(text.getText());
    msp.setSpan(new URLSpan("mailto:simtice@gmail.com"), 0, text.getText().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    text.setText(msp);
    text.setMovementMethod(LinkMovementMethod.getInstance());
}
Example 16
Project: collect-mobile-master  File: ImportingDemoSurveyDialog.java View source code
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final TextView message = new TextView(getActivity());
    final SpannableString s = new SpannableString(getActivity().getText(R.string.import_demo_dialog_message));
    Linkify.addLinks(s, Linkify.WEB_URLS);
    message.setText(s);
    message.setMovementMethod(LinkMovementMethod.getInstance());
    message.setPadding(px(8), px(16), px(8), px(16));
    return new AlertDialog.Builder(getActivity()).setTitle(R.string.import_demo_dialog_title).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            SurveyListActivity activity = (SurveyListActivity) getActivity();
            ServiceLocator.importDefaultSurvey(activity);
            activity.startImportedSurveyNodeActivity();
        }
    }).setView(message).create();
}
Example 17
Project: FanXin2.0_IM-master  File: LinkifyUtil.java View source code
public void addIntentLink(final Intent intent, final TextView view, final int start, final int end) {
    CharSequence source = view.getText();
    if (source instanceof Spanned) {
        IntentSpan[] spans = ((Spanned) source).getSpans(start, end, IntentSpan.class);
        if (spans.length > 0) {
            return;
        }
    }
    SpannableString spannableString = new SpannableString(source);
    spannableString.setSpan(new IntentSpan(new OnClickListener() {

        public void onClick(View view) {
            currentActivity.startActivity(intent);
        }
    }), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    view.setText(spannableString);
    view.setMovementMethod(LinkMovementMethod.getInstance());
}
Example 18
Project: FanXin3.0-master  File: LinkifyUtil.java View source code
public void addIntentLink(final Intent intent, final TextView view, final int start, final int end) {
    CharSequence source = view.getText();
    if (source instanceof Spanned) {
        IntentSpan[] spans = ((Spanned) source).getSpans(start, end, IntentSpan.class);
        if (spans.length > 0) {
            return;
        }
    }
    SpannableString spannableString = new SpannableString(source);
    spannableString.setSpan(new IntentSpan(new OnClickListener() {

        public void onClick(View view) {
            currentActivity.startActivity(intent);
        }
    }), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    view.setText(spannableString);
    view.setMovementMethod(LinkMovementMethod.getInstance());
}
Example 19
Project: ho.la.urv-master  File: AboutActivity.java View source code
@AfterViews
void styleBrand() {
    // Set brand text
    Spannable wordToSpan = new SpannableString(getText(R.string.brand));
    wordToSpan.setSpan(new ForegroundColorSpan(Color.BLACK), 3, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    mAboutBrand.setText(wordToSpan);
    // Set brand font
    mAboutBrand.setTypeface(Typeface.createFromAsset(getAssets(), "Exo-ExtraBold.ttf"));
}
Example 20
Project: KISS-master  File: SpaceTokenizer.java View source code
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();
    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }
    if (i > 0 && text.charAt(i - 1) == ' ') {
        return text;
    } else {
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text + " ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
Example 21
Project: meetup-client-master  File: MentionTokenizer.java View source code
public final CharSequence terminateToken(CharSequence charsequence) {
    int i = charsequence.length();
    Object obj;
    if (i == 0 || Character.isWhitespace(charsequence.charAt(i - 1)))
        obj = charsequence;
    else if (charsequence instanceof Spanned) {
        obj = new SpannableString((new StringBuilder()).append(charsequence).append(" ").toString());
        TextUtils.copySpansFrom((Spanned) charsequence, 0, charsequence.length(), Object.class, ((Spannable) (obj)), 0);
    } else {
        obj = (new StringBuilder()).append(charsequence).append(" ").toString();
    }
    return ((CharSequence) (obj));
}
Example 22
Project: minicat-master  File: SpaceTokenizer.java View source code
@Override
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();
    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }
    if (i > 0 && text.charAt(i - 1) == ' ') {
        return text;
    } else {
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text + " ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
Example 23
Project: PhotoShare-master  File: UserTextView.java View source code
public synchronized void apply() {
    while (text.length() <= 8) {
        text = text.concat(" ");
    }
    SpannableString spStr = new SpannableString(text);
    DecoratedClickableSpan clickSpan = new DecoratedClickableSpan();
    spStr.setSpan(clickSpan, 0, text.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    clickSpan.registerListener(listener);
    textView.setText(spStr);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
}
Example 24
Project: q-municate-android-master  File: TextViewHelper.java View source code
public static void changeTextColorView(Context context, TextView textView, String target) {
    String stringTextView = (String) textView.getText();
    String stringTextViewLowerCase = stringTextView.toLowerCase();
    int startSpan;
    int endSpan = ConstsCore.ZERO_INT_VALUE;
    Spannable spanRange = new SpannableString(stringTextView);
    while (true) {
        startSpan = stringTextViewLowerCase.indexOf(target.toLowerCase(), endSpan);
        ForegroundColorSpan foreColour = new ForegroundColorSpan(context.getResources().getColor(R.color.accent));
        if (startSpan < 0) {
            break;
        }
        endSpan = startSpan + target.length();
        spanRange.setSpan(foreColour, startSpan, endSpan, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    textView.setText(spanRange);
}
Example 25
Project: Robin-Client-master  File: SpaceTokenizer.java View source code
@Override
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();
    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }
    if (i > 0 && text.charAt(i - 1) == ' ') {
        return text;
    } else {
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text + " ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
Example 26
Project: saguaro-master  File: SendFeedbackTextView.java View source code
private void refreshSendFeedbackText() {
    String myText = getText().toString();
    if (TextUtils.isEmpty(myText)) {
        myText = getContext().getString(R.string.saguaro__send_feedback);
    }
    SpannableString sendFeedbackLink = Saguaro.makeLinkSpan(myText, new OnClickListener() {

        @Override
        public void onClick(View v) {
            getContext().startActivity(Saguaro.getSendFeedbackIntent(getContext()));
        }
    });
    setText(sendFeedbackLink);
    setFocusable(false);
    Saguaro.makeLinksFocusable(this);
}
Example 27
Project: securereader-master  File: AllCapsTransformation.java View source code
@Override
public CharSequence getTransformation(CharSequence source, View view) {
    CharSequence ret = source;
    if (ret != null) {
        if (source instanceof Spanned) {
            ret = new SpannableString(ret.toString().toUpperCase(mLocale));
            TextUtils.copySpansFrom((Spanned) source, 0, source.length(), Object.class, (Spannable) ret, 0);
        } else {
            ret = ret.toString().toUpperCase(mLocale);
        }
    }
    return ret;
}
Example 28
Project: simplenote-android-master  File: SpaceTokenizer.java View source code
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();
    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }
    if (i > 0 && text.charAt(i - 1) == ' ') {
        return text;
    } else {
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text + " ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
Example 29
Project: SimpleThermometerProject-master  File: AboutDialogFragment.java View source code
/*
        DialogFragment override
	 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.about_title);
    builder.setCancelable(true);
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setInverseBackgroundForced(true);
    final TextView description = new TextView(getActivity());
    description.setMovementMethod(LinkMovementMethod.getInstance());
    final int paddingInPixelSize = getResources().getDimensionPixelSize(R.dimen.default_padding);
    description.setPadding(paddingInPixelSize, paddingInPixelSize, paddingInPixelSize, paddingInPixelSize);
    final SpannableString s = new SpannableString(getString(R.string.about_description));
    Linkify.addLinks(s, Linkify.WEB_URLS);
    description.setText(s);
    builder.setView(description);
    return builder.create();
}
Example 30
Project: VoiceCard-master  File: MailboxIconView.java View source code
public void update(int numberOfNewMail) {
    String prefix = getContext().getString(R.string.mail);
    CharSequence message;
    if (numberOfNewMail > 0) {
        SpannableString messageWithColor = new SpannableString(prefix + "(" + numberOfNewMail + ")");
        messageWithColor.setSpan(new ForegroundColorSpan(INDICATOR_NEW_MAIL_TEXTCOLOR), prefix.length(), messageWithColor.length(), 0);
        message = messageWithColor;
    } else {
        message = prefix;
    }
    indicator.setText(message);
}
Example 31
Project: WordPress-Android-master  File: WPTextView.java View source code
@Override
public void setText(CharSequence text, BufferType type) {
    if (!mFixWidowWordEnabled) {
        super.setText(text, type);
        return;
    }
    Spannable out;
    int lastSpace = text.toString().lastIndexOf(' ');
    if (lastSpace != -1 && lastSpace < text.length() - 1) {
        // Replace last space character by a non breaking space.
        CharSequence tmpText = replaceCharacter(text, lastSpace, " ");
        out = new SpannableString(tmpText);
        // Restore spans if text is an instance of Spanned
        if (text instanceof Spanned) {
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(), null, out, 0);
        }
    } else {
        out = new SpannableString(text);
    }
    super.setText(out, type);
}
Example 32
Project: 2Degrees-Toolbox-master  File: AboutDialog.java View source code
/* code from http://www.itkrauts.com/archives/26-Creating-a-simple-About-Dialog-in-Android-1.6.html */
public static AlertDialog create(Context context) throws NameNotFoundException {
    // Try to load the a package matching the name of our own package
    PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_META_DATA);
    String versionInfo = pInfo.versionName;
    String aboutTitle = String.format("About %s", context.getString(R.string.app_name));
    String versionString = String.format("Version: %s", versionInfo);
    String aboutText = context.getResources().getString(R.string.about_dialog_text);
    // Set up the TextView
    final TextView message = new TextView(context);
    // We'll use a spannablestring to be able to make links clickable
    final SpannableString s = new SpannableString(aboutText);
    // Set some padding
    message.setPadding(5, 5, 5, 5);
    // Set up the final string
    message.setText(versionString + "\n\n" + s);
    // Now linkify the text
    Linkify.addLinks(message, Linkify.ALL);
    message.setTextColor(Color.WHITE);
    return new AlertDialog.Builder(context).setTitle(aboutTitle).setCancelable(true).setIcon(R.drawable.icon).setPositiveButton(context.getString(android.R.string.ok), null).setView(message).create();
}
Example 33
Project: AirCastingAndroidClient-master  File: TextViewHelper.java View source code
public static Spanned stripUnderlines(Spanned spanned) {
    SpannableString spannable = new SpannableString(spanned);
    URLSpan[] spans = spannable.getSpans(0, spannable.length(), URLSpan.class);
    for (URLSpan span : spans) {
        URLSpan noUnderline = new URLSpanNoUnderline(span.getURL());
        int start = spannable.getSpanStart(span);
        int end = spannable.getSpanEnd(span);
        spannable.removeSpan(span);
        spannable.setSpan(noUnderline, start, end, 0);
    }
    return spannable;
}
Example 34
Project: AndFChat-master  File: AdEntry.java View source code
public Spannable createText(Context context) {
    String text = getText(context);
    text = BBCodeReader.modifyUrls(text, "http://");
    //text = BBCodeReader.modifyUrls(text, "https://");
    final Spannable textSpan = SmileyReader.addSmileys(context, BBCodeReader.createSpannableWithBBCode(text, context));
    if (adClickListener != null && !showText) {
        // Create display text
        Spannable displayedSpan = new SpannableString(displayText);
        ClickableSpan clickable = new ClickableSpan() {

            @Override
            public void onClick(View widget) {
                adClickListener.openAd(textSpan);
            }
        };
        displayedSpan.setSpan(clickable, 0, displayedSpan.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return displayedSpan;
    } else {
        return textSpan;
    }
}
Example 35
Project: Android-Cookbook-Examples-master  File: AboutBox.java View source code
public static void Show(Activity callingActivity) {
    //Use a Spannable to allow for links highlighting
    SpannableString aboutText = new SpannableString("Version " + VersionName(callingActivity) + "\n\n" + callingActivity.getString(R.string.about));
    // views to pass to AlertDialog.Builder and to set the text
    View about;
    TextView tvAbout;
    try {
        //Inflate the custom view
        LayoutInflater inflater = callingActivity.getLayoutInflater();
        about = inflater.inflate(R.layout.aboutbox, (ViewGroup) callingActivity.findViewById(R.id.aboutView));
        tvAbout = (TextView) about.findViewById(R.id.aboutText);
    } catch (InflateException e) {
        about = tvAbout = new TextView(callingActivity);
    }
    //Set the about text
    tvAbout.setText(aboutText);
    // Now Linkify the text
    Linkify.addLinks(tvAbout, Linkify.ALL);
    //Build and show the dialog
    new AlertDialog.Builder(callingActivity).setTitle("About " + callingActivity.getString(R.string.app_name)).setCancelable(true).setIcon(R.drawable.icon).setPositiveButton("OK", null).setView(about).show();
//Builder method returns allow for method chaining
}
Example 36
Project: android-typeface-helper-master  File: ActionBarHelper.java View source code
public static void setTitle(android.support.v7.app.ActionBar actionBar, SpannableString spannableString) {
    // @see http://stackoverflow.com/questions/7658725/android-java-lang-illegalargumentexception-invalid-payload-item-type
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN && Build.MANUFACTURER.toUpperCase().equals("LGE")) {
        actionBar.setTitle(spannableString.toString());
    } else {
        actionBar.setTitle(spannableString);
    }
}
Example 37
Project: AndroidChromium-master  File: UpdatePasswordInfoBar.java View source code
@Override
public void createContent(InfoBarLayout layout) {
    super.createContent(layout);
    if (mTitleLinkRangeStart != 0 && mTitleLinkRangeEnd != 0) {
        SpannableString title = new SpannableString(mTitle);
        title.setSpan(new ClickableSpan() {

            @Override
            public void onClick(View view) {
                onLinkClicked();
            }
        }, mTitleLinkRangeStart, mTitleLinkRangeEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        layout.setMessage(title);
    }
    InfoBarControlLayout controlLayout = layout.addControlLayout();
    if (mUsernames.length > 1) {
        InfoBarArrayAdapter<String> usernamesAdapter = new InfoBarArrayAdapter<String>(getContext(), mUsernames);
        mUsernamesSpinner = controlLayout.addSpinner(R.id.password_infobar_accounts_spinner, usernamesAdapter);
    } else {
        controlLayout.addDescription(mUsernames[0]);
    }
}
Example 38
Project: AndTweet-master  File: AtTokenizer.java View source code
/**
	 * @see android.widget.MultiAutoCompleteTextView.Tokenizer#terminateToken(java.lang.CharSequence)
	 */
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();
    while (i > 0 && text.charAt(i - 1) == ' ') i--;
    if (i > 0 && text.charAt(i - 1) == '@') {
        return text;
    } else {
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text);
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
            return sp;
        } else {
            return text;
        }
    }
}
Example 39
Project: anyplace-master  File: Forum.java View source code
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.forum);
    font = Typeface.createFromAsset(getAssets(), "Roboto-Thin.ttf");
    tvKausic = (TextView) findViewById(R.id.tvKausic);
    tvKausic.setTypeface(font);
    tvUtsav = (TextView) findViewById(R.id.tvUtsav);
    tvUtsav.setTypeface(font);
    tvAch1 = (TextView) findViewById(R.id.tvAch1);
    tvAch1.setTypeface(font);
    tvAch2 = (TextView) findViewById(R.id.tvAch2);
    tvAch2.setTypeface(font);
    tvChal1 = (TextView) findViewById(R.id.tvChal1);
    tvChal1.setTypeface(font);
    tvChal2 = (TextView) findViewById(R.id.tvChal2);
    tvChal2.setTypeface(font);
    android.app.ActionBar bar = this.getActionBar();
    ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#5677fc"));
    bar.setBackgroundDrawable(colorDrawable);
    int titleId = getResources().getIdentifier("action_bar_title", "id", "android");
    SpannableString s = new SpannableString("Forum");
    s.setSpan(new TypefaceSpan(this, "Roboto-Thin.ttf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
Example 40
Project: armatus-master  File: CommandHelpActivity.java View source code
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.command_help_activity);
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mCommandInfo = extras.getParcelable("commandInfo");
    }
    TextView commandInfoView = (TextView) findViewById(R.id.command_help_info_text);
    commandInfoView.setText(mCommandInfo.getHelp());
    TextView commandTypesView = (TextView) findViewById(R.id.command_help_types_text);
    commandTypesView.setTypeface(ConsoleActivity.TYPEFACE);
    for (String type : mCommandInfo.getArgTypes()) {
        commandTypesView.append(type + " → ");
    }
    commandTypesView.append(mCommandInfo.getResultType());
    TextView commandTagsView = (TextView) findViewById(R.id.command_help_tags_text);
    if (savedInstanceState == null) {
        SpannableStringBuilder builder = new SpannableStringBuilder();
        for (String tag : mCommandInfo.getTags()) {
            SpannableString tagBox = new SpannableString(' ' + tag + ' ');
            tagBox.setSpan(new BackgroundColorSpan(Color.GRAY), 0, tagBox.length(), 0);
            tagBox.setSpan(new ForegroundColorSpan(Color.BLACK), 0, tagBox.length(), 0);
            builder.append(tagBox).append(", ");
        }
        builder.delete(builder.length() - 2, builder.length());
        mTagBoxes = builder;
    } else {
        mTagBoxes = savedInstanceState.getCharSequence("tagBoxes");
    }
    commandTagsView.setText(mTagBoxes);
}
Example 41
Project: AwesomeValidation-master  File: SpanHelperTest.java View source code
@Override
protected void setUp() throws Exception {
    super.setUp();
    mMockEditText = mock(EditText.class, RETURNS_MOCKS);
    mMockEditable = mock(Editable.class);
    mMockSpannableString = mock(SpannableString.class);
    when(mMockEditText.getText()).thenReturn(mMockEditable);
    when(mMockEditText.getText().toString()).thenReturn(PowerMockito.mock(String.class));
    PowerMockito.whenNew(SpannableString.class).withArguments(PowerMockito.mock(String.class)).thenReturn(mMockSpannableString);
    PowerMockito.whenNew(BackgroundColorSpan.class).withArguments(mColor).thenReturn(mock(BackgroundColorSpan.class));
}
Example 42
Project: Badge-master  File: MainActivity.java View source code
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final TextView textView = (TextView) findViewById(R.id.tvHelloWorld);
    final ImageView imageView = (ImageView) findViewById(R.id.imageView);
    final BadgeDrawable drawable = new BadgeDrawable.Builder().type(BadgeDrawable.TYPE_NUMBER).number(9).build();
    final BadgeDrawable drawable2 = new BadgeDrawable.Builder().type(BadgeDrawable.TYPE_ONLY_ONE_TEXT).badgeColor(0xff336699).text1("VIP").build();
    final BadgeDrawable drawable3 = new BadgeDrawable.Builder().type(BadgeDrawable.TYPE_WITH_TWO_TEXT_COMPLEMENTARY).badgeColor(0xffCC9933).text1("LEVEL").text2("10").build();
    final BadgeDrawable drawable4 = new BadgeDrawable.Builder().type(BadgeDrawable.TYPE_WITH_TWO_TEXT).badgeColor(0xffCC9999).text1("TEST").text2("Pass").build();
    final BadgeDrawable drawable5 = new BadgeDrawable.Builder().type(BadgeDrawable.TYPE_NUMBER).number(999).badgeColor(0xff336699).build();
    SpannableString spannableString = new SpannableString(TextUtils.concat("TextView: ", drawable.toSpannable(), " ", drawable2.toSpannable(), " ", drawable3.toSpannable(), " ", drawable4.toSpannable(), " ", drawable5.toSpannable()));
    if (textView != null) {
        textView.setText(spannableString);
    }
    if (imageView != null) {
        final BadgeDrawable drawable6 = new BadgeDrawable.Builder().type(BadgeDrawable.TYPE_WITH_TWO_TEXT_COMPLEMENTARY).badgeColor(0xff336633).textSize(sp2px(this, 14)).text1("Author").text2("Nekocode").typeFace(Typeface.createFromAsset(getAssets(), "fonts/code-bold.otf")).build();
        imageView.setImageDrawable(drawable6);
    }
}
Example 43
Project: Bingo-master  File: SpecialViewUtil.java View source code
public static SpannableString getSpannableString(String text, List<String> tagList) {
    int lastIndex = -1;
    SpannableString spannableString = new SpannableString(text);
    for (int i = 0; i < tagList.size(); i++) {
        int index = text.indexOf(tagList.get(i), lastIndex);
        if (index != lastIndex) {
            lastIndex = index + tagList.get(i).length();
            spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#ea5550")), index, index + tagList.get(i).length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        }
    }
    return spannableString;
}
Example 44
Project: BottomSheetPickers-master  File: TimeTextUtils.java View source code
/**
     * Sets the given String on the TextView.
     * If the given String contains the "AM" or "PM" label,
     * this first applies a size span on the label.
     * @param textTime the time String that may contain "AM" or "PM"
     * @param textView the TextView to display {@code textTime}
     */
public static void setText(String textTime, TextView textView) {
    // TODO: This is not localized. Get the AM/PM translation from DateFormatSymbols.
    if (textTime.contains("AM") || textTime.contains("PM")) {
        SpannableString s = new SpannableString(textTime);
        s.setSpan(AMPM_SIZE_SPAN, textTime.indexOf(" "), textTime.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(s, TextView.BufferType.SPANNABLE);
    } else {
        textView.setText(textTime);
    }
}
Example 45
Project: Cadar-master  File: WeekHolder.java View source code
@Override
public void run() {
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(title.getContext().getString(R.string.calendar_week));
    stringBuilder.append(" ");
    stringBuilder.append(period.first.get(Calendar.WEEK_OF_YEAR));
    stringBuilder.append(", ");
    stringBuilder.append(DateFormat.format(DATE_FORMAT, period.first));
    stringBuilder.append(" - ");
    stringBuilder.append(DateFormat.format(DATE_FORMAT, period.second));
    final Spannable date = new SpannableString(stringBuilder.toString());
    uiHandler.post(new Runnable() {

        @Override
        public void run() {
            title.setText(date);
        }
    });
}
Example 46
Project: cnBetaReader-master  File: SpannableStringUtils.java View source code
public static SpannableString span(Context context, String text) {
    SpannableStringBuilder ssb = new SpannableStringBuilder(text);
    // Match Emoticons
    Matcher matcher = PATTERN_EMOTICON.matcher(text);
    while (matcher.find()) {
        // Don't be too long
        if (matcher.end() - matcher.start() < 8) {
            String iconName = matcher.group(0);
            Bitmap bitmap = Emoticons.EMOTICON_BITMAPS_SCALED.get(iconName);
            if (bitmap != null) {
                ImageSpan span = new ImageSpan(context, bitmap, ImageSpan.ALIGN_BASELINE);
                ssb.setSpan(span, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
    return SpannableString.valueOf(ssb);
}
Example 47
Project: ComicReader-master  File: ActionBarHelper.java View source code
public static void setTitle(android.support.v7.app.ActionBar actionBar, SpannableString spannableString) {
    // @see http://stackoverflow.com/questions/7658725/android-java-lang-illegalargumentexception-invalid-payload-item-type
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN && Build.MANUFACTURER.toUpperCase().equals("LGE")) {
        actionBar.setTitle(spannableString.toString());
    } else {
        actionBar.setTitle(spannableString);
    }
}
Example 48
Project: Conquer-master  File: EmoticonsEditText.java View source code
private CharSequence replace(String text) {
    try {
        SpannableString spannableString = new SpannableString(text);
        int start = 0;
        Pattern pattern = buildPattern();
        Matcher matcher = pattern.matcher(text);
        while (matcher.find()) {
            String faceText = matcher.group();
            String key = faceText.substring(1);
            BitmapFactory.Options options = new BitmapFactory.Options();
            Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), getContext().getResources().getIdentifier(key, "drawable", getContext().getPackageName()), options);
            ImageSpan imageSpan = new ImageSpan(getContext(), bitmap);
            int startIndex = text.indexOf(faceText, start);
            int endIndex = startIndex + faceText.length();
            if (startIndex >= 0)
                spannableString.setSpan(imageSpan, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            start = (endIndex - 1);
        }
        return spannableString;
    } catch (Exception e) {
        return text;
    }
}
Example 49
Project: cwac-richedit-master  File: SpannedUtils.java View source code
public static <A extends CharacterStyle, B extends CharacterStyle> Spannable replaceAll(Spanned original, Class<A> sourceType, SpanConverter<A, B> converter) {
    SpannableString result = new SpannableString(original);
    A[] spans = result.getSpans(0, result.length(), sourceType);
    for (A span : spans) {
        int start = result.getSpanStart(span);
        int end = result.getSpanEnd(span);
        int flags = result.getSpanFlags(span);
        result.removeSpan(span);
        result.setSpan(converter.convert(span), start, end, flags);
    }
    return (result);
}
Example 50
Project: cwac-richtextutils-master  File: SpannedUtils.java View source code
public static <A extends CharacterStyle, B extends CharacterStyle> Spannable replaceAll(Spanned original, Class<A> sourceType, SpanConverter<A, B> converter) {
    SpannableString result = new SpannableString(original);
    A[] spans = result.getSpans(0, result.length(), sourceType);
    for (A span : spans) {
        int start = result.getSpanStart(span);
        int end = result.getSpanEnd(span);
        int flags = result.getSpanFlags(span);
        result.removeSpan(span);
        result.setSpan(converter.convert(span), start, end, flags);
    }
    return (result);
}
Example 51
Project: DeliciousDroid-master  File: SpaceTokenizer.java View source code
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();
    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }
    if (i > 0 && text.charAt(i - 1) == ' ') {
        return text;
    } else {
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text + " ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
Example 52
Project: Diandi1.20-master  File: EmoticonsTextView.java View source code
private CharSequence replace(String text) {
    try {
        SpannableString spannableString = new SpannableString(text);
        int start = 0;
        Pattern pattern = buildPattern();
        Matcher matcher = pattern.matcher(text);
        while (matcher.find()) {
            String faceText = matcher.group();
            String key = faceText.substring(1);
            BitmapFactory.Options options = new BitmapFactory.Options();
            Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), getContext().getResources().getIdentifier(key, "drawable", getContext().getPackageName()), options);
            ImageSpan imageSpan = new ImageSpan(getContext(), bitmap);
            int startIndex = text.indexOf(faceText, start);
            int endIndex = startIndex + faceText.length();
            if (startIndex >= 0)
                spannableString.setSpan(imageSpan, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            start = (endIndex - 1);
        }
        return spannableString;
    } catch (Exception e) {
        return text;
    }
}
Example 53
Project: Diary.Ru-Client-master  File: SemicolonTokenizer.java View source code
@Override
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();
    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }
    if (i > 0 && text.charAt(i - 1) == ';') {
        return text;
    } else {
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text + "; ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
            return sp;
        } else {
            return text + "; ";
        }
    }
}
Example 54
Project: EhViewer-master  File: TextUrl.java View source code
public static CharSequence handleTextUrl(CharSequence content) {
    Matcher m = URL_PATTERN.matcher(content);
    Spannable spannable = null;
    while (m.find()) {
        // Ensure spannable
        if (spannable == null) {
            if (content instanceof Spannable) {
                spannable = (Spannable) content;
            } else {
                spannable = new SpannableString(content);
            }
        }
        int start = m.start();
        int end = m.end();
        URLSpan[] links = spannable.getSpans(start, end, URLSpan.class);
        if (links.length > 0) {
            // There has been URLSpan already, leave it alone
            continue;
        }
        URLSpan urlSpan = new URLSpan(m.group(0));
        spannable.setSpan(urlSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    return spannable == null ? content : spannable;
}
Example 55
Project: fanfouapp-opensource-master  File: SpaceTokenizer.java View source code
@Override
public CharSequence terminateToken(final CharSequence text) {
    int i = text.length();
    while ((i > 0) && (text.charAt(i - 1) == ' ')) {
        i--;
    }
    if ((i > 0) && (text.charAt(i - 1) == ' ')) {
        return text;
    } else {
        if (text instanceof Spanned) {
            final SpannableString sp = new SpannableString(text + " ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
Example 56
Project: Far-On-Droid-master  File: SearchableEditText.java View source code
private void generalSearch(String pattern, IOCase caseSensitive, boolean wholeWords, boolean replace) {
    if (pattern == null) {
        setText(mText);
        return;
    }
    Pattern patternMatch = FileUtilsExt.createWordSearchPattern(pattern, wholeWords, caseSensitive);
    Matcher matcher = patternMatch.matcher(mText);
    if (matcher.find()) {
        SpannableString string = new SpannableString(mText);
        int firstOccurrence;
        do {
            firstOccurrence = matcher.start();
            setSelection(pattern, string, firstOccurrence);
        } while (matcher.find());
        setText(string);
    } else {
        setText(mText);
    }
}
Example 57
Project: Flucso-master  File: WwTextView.java View source code
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
    TextView widget = (TextView) this;
    CharSequence text = widget.getText();
    if (text instanceof Spanned) {
        Spannable buffer = new SpannableString(text);
        int action = event.getAction();
        if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
            int x = (int) event.getX();
            int y = (int) event.getY();
            x -= widget.getTotalPaddingLeft();
            y -= widget.getTotalPaddingTop();
            x += widget.getScrollX();
            y += widget.getScrollY();
            Layout layout = widget.getLayout();
            int line = layout.getLineForVertical(y);
            int off = layout.getOffsetForHorizontal(line, x);
            ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
            if (link.length != 0) {
                if (action == MotionEvent.ACTION_UP)
                    link[0].onClick(widget);
                else if (action == MotionEvent.ACTION_DOWN)
                    Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0]));
                return true;
            }
        }
    }
    return false;
}
Example 58
Project: FriendsHost-master  File: FlowTextHelper.java View source code
public static void tryFlowText(String text, View thumbnailView, TextView messageView, Display display) {
    // There is nothing I can do for older versions, so just return
    if (!mNewClassAvailable)
        return;
    // Get height and width of the image and height of the text line
    thumbnailView.measure(display.getWidth(), display.getHeight());
    int height = thumbnailView.getMeasuredHeight();
    int width = thumbnailView.getMeasuredWidth();
    float textLineHeight = messageView.getPaint().getTextSize();
    // Set the span according to the number of lines and width of the image
    int lines = (int) Math.round(height / textLineHeight);
    SpannableString ss = new SpannableString(text);
    //For an html text you can use this line: SpannableStringBuilder ss = (SpannableStringBuilder)Html.fromHtml(text);
    ss.setSpan(new MyLeadingMarginSpan2(lines, width), 0, ss.length(), 0);
    messageView.setText(ss);
    // Align the text with the image by removing the rule that the text is to the right of the image
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) messageView.getLayoutParams();
    int[] rules = params.getRules();
    rules[RelativeLayout.RIGHT_OF] = 0;
}
Example 59
Project: Geekr-master  File: ImageEditText.java View source code
private Spanned convertImageTag(CharSequence text) {
    SpannableString span = new SpannableString(text);
    Set<String> keys = ImageHelper.emotionsMap.keySet();
    Pattern p = Pattern.compile("\\[[^\\[\\]]+\\]");
    Matcher m = p.matcher(text);
    while (m.find()) {
        try {
            InputStream input = getContext().getAssets().open("smileys" + File.separator + ImageHelper.emotionsMap.get(m.group()));
            if (input != null) {
                Bitmap bitmap = BitmapFactory.decodeStream(input);
                bitmap = Bitmap.createScaledBitmap(bitmap, 42, 42, true);
                ImageSpan imageSpan = new ImageSpan(getContext(), bitmap);
                span.setSpan(imageSpan, m.start(), m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        } catch (IOException e) {
            Log.e("sms", "Failed to loaded content " + m.group(), e);
        }
    }
    return span;
}
Example 60
Project: GitClub-master  File: PersonalPageTextView.java View source code
@Override
public void setText(CharSequence text, BufferType type) {
    mText = text;
    mType = type;
    if (txtAppend == null) {
        super.setText(text, type);
        return;
    }
    SpannableString sp = new SpannableString(text + txtAppend);
    sp.setSpan(new RelativeSizeSpan(0.6f), text.length(), text.length() + txtAppend.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    sp.setSpan(new StyleSpan(android.graphics.Typeface.NORMAL), text.length(), text.length() + txtAppend.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    StringUtils.changeFontStyle("fonts/Georgia.ttf", this);
    super.setText(sp, type);
}
Example 61
Project: hashtag-view-master  File: ContactsFragment.java View source code
private CharSequence getSourcesText() {
    SpannableString spannable = new SpannableString(getString(R.string.sources));
    spannable.setSpan(new ClickableSpan() {

        @Override
        public void onClick(View widget) {
            if (listener != null) {
                listener.openGitHubPage();
            }
        }
    }, spannable.toString().length() - 6, spannable.toString().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
}
Example 62
Project: IPARCOS-master  File: LightPropPref.java View source code
/**
	 * Create the summary rich-text string
	 * 
	 * @return the summary
	 */
@Override
protected Spannable createSummary() {
    String temp = "";
    ArrayList<INDIElement> elements = prop.getElementsAsList();
    int[] starts = new int[elements.size()];
    int[] ends = new int[elements.size()];
    starts[0] = 0;
    for (int i = 0; i < elements.size(); i++) {
        starts[i] = temp.length();
        temp = temp + elements.get(i).getLabel() + " ";
        ends[i] = temp.length();
    }
    Spannable summaryText = new SpannableString(temp);
    for (int i = 0; i < elements.size(); i++) {
        int color = Color.WHITE;
        switch(((INDILightElement) (elements.get(i))).getValue()) {
            case ALERT:
                color = Color.RED;
                break;
            case BUSY:
                color = Color.YELLOW;
                break;
            case IDLE:
                color = Color.WHITE;
                break;
            case OK:
                color = Color.GREEN;
                break;
        }
        summaryText.setSpan(new ForegroundColorSpan(color), starts[i], ends[i], 0);
    }
    return summaryText;
}
Example 63
Project: KingTV-master  File: ChatFragment.java View source code
@Override
public void initUI() {
    SpannableStringBuilder ssb = new SpannableStringBuilder();
    //系统通知图片
    ImageSpan imageSpan = new ImageSpan(context, R.drawable.img_dm_xttz);
    SpannableString spannableString = new SpannableString("tips");
    spannableString.setSpan(imageSpan, 0, spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.append(spannableString);
    //系统通知内容
    ssb.append(getText(R.string.tips_notice_desc));
    tvTips.setText(ssb);
}
Example 64
Project: LepraWatch-master  File: MainActivity.java View source code
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Set view wrapper.
    setContentView(R.layout.main);
    // Load auth fragment if not authorized.
    if (Lepra.getInstance().isAuthorized() == false) {
        // Request view to not to fit system windows.
        findViewById(R.id.main).setFitsSystemWindows(false);
        // Hide action bar
        getActionBar().hide();
        // Load auth fragment.
        if (savedInstanceState == null) {
            // Load auth fragment.
            getSupportFragmentManager().beginTransaction().add(R.id.main, new AuthFragment(), AuthFragment.TAG).commit();
        }
    } else {
        // Request view to fit system windows.
        findViewById(R.id.main).setFitsSystemWindows(true);
        // Create action bar title.
        SpannableString title = new SpannableString(getResources().getString(R.string.app_label));
        title.setSpan(new TypefaceSpan(this, "Bebas.ttf"), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        // Setup actionbar.
        ActionBar actionBar = getActionBar();
        actionBar.setTitle(title);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        // Load main fragment.
        if (savedInstanceState == null) {
            // Show main fragment.
            getSupportFragmentManager().beginTransaction().add(R.id.main, new MainFragment(), MainFragment.TAG).commit();
        }
    }
}
Example 65
Project: like_netease_news-master  File: TextViewActivity.java View source code
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTVTitle(R.string.tv_textview);
    //TODO setContentView Tag
    setContentView(R.layout.activity_textview);
    this.mTvText = (TextView) findViewById(R.id.tv_text);
    this.mTvCustomText = (TextView) findViewById(R.id.tv_custom_text);
    this.mTvCustomText1 = (TextView) findViewById(R.id.tv_custom_text_1);
    Typeface typeface = Typeface.createFromAsset(getAssets(), "custom.ttf");
    this.mTvText.setText(DEFAULT);
    this.mTvCustomText.setTypeface(typeface);
    this.mTvCustomText.setText(CUSTOM);
    SpannableString spannableString = new SpannableString(CUSTOM_1);
    ForegroundColorSpan redColorSpan = new ForegroundColorSpan(Color.RED);
    UnderlineSpan underlineSpan = new UnderlineSpan();
    spannableString.setSpan(redColorSpan, 6, 8, SpannableString.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(underlineSpan, 6, 8, SpannableString.SPAN_INCLUSIVE_EXCLUSIVE);
    this.mTvCustomText1.setMovementMethod(LinkMovementMethod.getInstance());
    this.mTvCustomText1.setText(spannableString);
}
Example 66
Project: link-bubble-master  File: SafeUrlSpan.java View source code
public static void fixUrlSpans(TextView tv) {
    SpannableString current = (SpannableString) tv.getText();
    URLSpan[] spans = current.getSpans(0, current.length(), URLSpan.class);
    for (URLSpan span : spans) {
        int start = current.getSpanStart(span);
        int end = current.getSpanEnd(span);
        current.removeSpan(span);
        current.setSpan(new SafeUrlSpan(span.getURL()), start, end, 0);
    }
}
Example 67
Project: Loop-master  File: Transformers.java View source code
@Override
public CharSequence prepare(String item) {
    SpannableString spannableString = new SpannableString("#" + item);
    spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#85F5F5F5")), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(new SuperscriptSpan(), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannableString;
}
Example 68
Project: m2e-master  File: AboutBox.java View source code
public static void Show(Activity callingActivity) {
    //Use a Spannable to allow for links highlighting
    SpannableString aboutText = new SpannableString("Version " + VersionName(callingActivity) + "\n\n" + callingActivity.getString(R.string.about));
    // views to pass to AlertDialog.Builder and to set the text
    View about;
    TextView tvAbout;
    try {
        //Inflate the custom view
        LayoutInflater inflater = callingActivity.getLayoutInflater();
        about = inflater.inflate(R.layout.aboutbox, (ViewGroup) callingActivity.findViewById(R.id.aboutView));
        tvAbout = (TextView) about.findViewById(R.id.aboutText);
    } catch (InflateException e) {
        about = tvAbout = new TextView(callingActivity);
    }
    //Set the about text
    tvAbout.setText(aboutText);
    // Now Linkify the text
    Linkify.addLinks(tvAbout, Linkify.ALL);
    //Build and show the dialog
    new AlertDialog.Builder(callingActivity).setTitle("About " + callingActivity.getString(R.string.app_name)).setCancelable(true).setIcon(R.drawable.icon).setPositiveButton("OK", null).setView(about).show();
//Builder method returns allow for method chaining
}
Example 69
Project: MonsterHunter3UDatabase-master  File: AboutDialogFragment.java View source code
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final TextView message = new TextView(getActivity());
    final SpannableString s = new SpannableString(getActivity().getText(R.string.about_message));
    Linkify.addLinks(s, Linkify.WEB_URLS);
    message.setText(s);
    message.setMovementMethod(LinkMovementMethod.getInstance());
    ;
    message.setPadding(20, 10, 20, 10);
    message.setTextSize(18);
    return new AlertDialog.Builder(getActivity()).setTitle(R.string.about).setPositiveButton(R.string.alert_rate, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.daviancorp.android.monsterhunter3udatabase"));
            startActivity(intent);
            dialog.dismiss();
        }
    }).setNegativeButton(R.string.alert_button, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    }).setView(message).create();
}
Example 70
Project: MonsterHunter4UDatabase-master  File: AboutDialogFragment.java View source code
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final TextView message = new TextView(getActivity());
    final SpannableString s = new SpannableString(getActivity().getText(R.string.about_message));
    Linkify.addLinks(s, Linkify.WEB_URLS);
    message.setText(s);
    message.setMovementMethod(LinkMovementMethod.getInstance());
    ;
    message.setPadding(20, 10, 20, 10);
    message.setTextSize(18);
    return new AlertDialog.Builder(getActivity()).setTitle(R.string.about).setNegativeButton(//						})
    R.string.alert_button, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    }).setView(message).create();
}
Example 71
Project: MVPAndroidBootstrap-master  File: DialogUtils.java View source code
/**
     * Show a model dialog box.  The <code>android.app.AlertDialog</code> object is returned so that
     * you can specify an OnDismissListener (or other listeners) if required.
     * <b>Note:</b> show() is already called on the AlertDialog being returned.
     *
     * @param context The current Context or Activity that this method is called from.
     * @param message Message to display in the dialog.
     * @return AlertDialog that is being displayed.
     */
public static AlertDialog quickDialog(final Activity context, final String message) {
    //Make links clickable
    final SpannableString s = new SpannableString(message);
    Linkify.addLinks(s, Linkify.ALL);
    Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(s);
    builder.setPositiveButton(android.R.string.ok, closeDialogListener());
    AlertDialog dialog = builder.create();
    dialog.show();
    //Make links clickable
    ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
    return dialog;
}
Example 72
Project: nices-master  File: ActionBarHelper.java View source code
public static void setTitle(android.support.v7.app.ActionBar actionBar, SpannableString spannableString) {
    // @see http://stackoverflow.com/questions/7658725/android-java-lang-illegalargumentexception-invalid-payload-item-type
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN && Build.MANUFACTURER.toUpperCase().equals("LGE")) {
        actionBar.setTitle(spannableString.toString());
    } else {
        actionBar.setTitle(spannableString);
    }
}
Example 73
Project: NineGridView-master  File: CommentsAdapter.java View source code
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = View.inflate(context, R.layout.item_evaluatereply, null);
        convertView.setTag(new ViewHolder(convertView));
    }
    ViewHolder holder = (ViewHolder) convertView.getTag();
    EvaluationReply replyItem = getItem(position);
    SpannableString msp = new SpannableString(replyItem.erReplyuser + ":" + replyItem.erContent);
    msp.setSpan(new ForegroundColorSpan(0xff6b8747), 0, replyItem.erReplyuser.length() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    holder.reply.setText(msp);
    return convertView;
}
Example 74
Project: ONE-Unofficial-master  File: AboutActivity.java View source code
@Override
public void init() {
    setTitle(R.string.item_about);
    String s = getResources().getString(R.string.content_about);
    int start = s.indexOf("『");
    int end = s.indexOf("�") + 1;
    SpannableString content = new SpannableString(s);
    //ClickableSpan会默认给区域内的文件设为下划线�绿色字体
    content.setSpan(new ClickableSpan() {

        @Override
        public void onClick(View widget) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("market://details?id=one.hh.oneclient"));
            startActivity(intent);
        }
    }, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    //此处将上�的绿色字体覆盖为了�色(�景色�为字体的颜色)
    content.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.blue)), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    textAbout.setText(content);
}
Example 75
Project: Onosendai-master  File: UsernameTokenizer.java View source code
@Override
public CharSequence terminateToken(final CharSequence text) {
    int i = text.length();
    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }
    if (i > 0 && text.charAt(i - 1) == ' ')
        return text;
    if (text instanceof Spanned) {
        final SpannableString sp = new SpannableString(text + " ");
        TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
        return sp;
    }
    return text + " ";
}
Example 76
Project: opensource-master  File: SpaceTokenizer.java View source code
@Override
public CharSequence terminateToken(final CharSequence text) {
    int i = text.length();
    while ((i > 0) && (text.charAt(i - 1) == ' ')) {
        i--;
    }
    if ((i > 0) && (text.charAt(i - 1) == ' ')) {
        return text;
    } else {
        if (text instanceof Spanned) {
            final SpannableString sp = new SpannableString(text + " ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
Example 77
Project: orgzly-android-master  File: SpaceTokenizer.java View source code
/* Returns text, modified, if necessary, to ensure that it ends with a token terminator (for example a space or comma). */
@Override
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();
    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }
    if (i > 0 && text.charAt(i - 1) == ' ') {
        return text;
    } else {
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text + " ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
Example 78
Project: Osmand-master  File: QuickSearchButtonListItem.java View source code
private static Spannable spannedToUpperCase(@NonNull Spanned s) {
    Object[] spans = s.getSpans(0, s.length(), Object.class);
    SpannableString spannableString = new SpannableString(s.toString().toUpperCase());
    // reapply the spans to the now uppercase string
    for (Object span : spans) {
        spannableString.setSpan(span, s.getSpanStart(span), s.getSpanEnd(span), s.getSpanFlags(span));
    }
    return spannableString;
}
Example 79
Project: PinDroid-master  File: SpaceTokenizer.java View source code
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();
    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }
    if (i > 0 && text.charAt(i - 1) == ' ') {
        return text;
    } else {
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text + " ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
Example 80
Project: plaphoons-for-android-master  File: AboutDialogBuilder.java View source code
public static AlertDialog create(Context context) throws NameNotFoundException {
    // Try to load the a package matching the name of our own package
    PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_META_DATA);
    String versionInfo = pInfo.versionName;
    String aboutTitle = String.format("About %s", context.getString(R.string.app_name));
    String versionString = String.format("Version: %s", versionInfo);
    String aboutText = context.getString(R.string.about);
    // Set up the TextView
    final TextView message = new TextView(context);
    // We'll use a spannablestring to be able to make links clickable
    final SpannableString s = new SpannableString(aboutText);
    // Set some padding
    message.setPadding(10, 10, 10, 10);
    // Set up the final string
    message.setText(versionString + "\n\n" + s);
    // Now linkify the text
    Linkify.addLinks(message, Linkify.ALL);
    return new AlertDialog.Builder(context).setTitle(aboutTitle).setCancelable(true).setIcon(R.drawable.icon).setPositiveButton(context.getString(android.R.string.ok), null).setView(message).create();
}
Example 81
Project: Purdue-App-Old-master  File: WeatherInfoDialog.java View source code
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Info");
    // Info message and credit to forecast.io API
    SpannableString message = new SpannableString("Weather data shown pertains to Purdue University's Campus." + "\n(40.4240¡ N, 86.9290¡ W)" + "\nPowered by Forecast.io (http://forecast.io)");
    // Format the message
    message.setSpan(new StyleSpan(Typeface.ITALIC), 84, 127, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    message.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 83, 127, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    message.setSpan(new RelativeSizeSpan(.7f), 84, 127, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.setMessage(message);
    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
        // Close the dialogue
        }
    });
    return builder.create();
}
Example 82
Project: pushup-master  File: AboutActivity.java View source code
protected void init() {
    appName = (TextView) findViewById(R.id.app_name);
    appVersion = (TextView) findViewById(R.id.app_version);
    appDetail = (TextView) findViewById(R.id.app_detail);
    appVersion.setText(Utils.getApplicationVersionName(getApplicationContext()) + "." + Utils.getApplicationVersionCode(getApplicationContext()));
    TextView appUrl = (TextView) findViewById(R.id.app_url);
    String url = getString(R.string.app_url);
    SpannableString sp = new SpannableString(url);
    sp.setSpan(new URLSpan(url), 0, url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    appUrl.setText(sp);
    appUrl.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Utils.openUrlInsideApp(AboutActivity.this, getString(R.string.app_url));
            Utils.overridePendingTransitionRight2Left(AboutActivity.this);
        }
    });
}
Example 83
Project: QQ-master  File: EmoticonsTextView.java View source code
private CharSequence replace(String text) {
    try {
        SpannableString spannableString = new SpannableString(text);
        int start = 0;
        Pattern pattern = buildPattern();
        Matcher matcher = pattern.matcher(text);
        while (matcher.find()) {
            String faceText = matcher.group();
            String key = faceText.substring(1);
            BitmapFactory.Options options = new BitmapFactory.Options();
            Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), getContext().getResources().getIdentifier(key, "drawable", getContext().getPackageName()), options);
            ImageSpan imageSpan = new ImageSpan(getContext(), bitmap);
            int startIndex = text.indexOf(faceText, start);
            int endIndex = startIndex + faceText.length();
            if (startIndex >= 0)
                spannableString.setSpan(imageSpan, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            start = (endIndex - 1);
        }
        return spannableString;
    } catch (Exception e) {
        return text;
    }
}
Example 84
Project: RecyclerTabLayout-master  File: DemoCustomView01Adapter.java View source code
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    ColorItem colorItem = mAdapater.getColorItem(position);
    holder.title.setText(colorItem.name);
    holder.color.setBackgroundColor(colorItem.color);
    SpannableString name = new SpannableString(colorItem.name);
    if (position == getCurrentIndicatorPosition()) {
        name.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
    }
    holder.title.setText(name);
}
Example 85
Project: rtty_modem-master  File: MapFileMessage.java View source code
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final SpannableString s = new SpannableString(getActivity().getText(R.string.maphelpermessage));
    Linkify.addLinks(s, Linkify.WEB_URLS);
    final TextView message = new TextView(getActivity());
    message.setText(s);
    message.setMovementMethod(LinkMovementMethod.getInstance());
    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(message).setPositiveButton(//.setMessage(s)//R.string.maphelpermessage)
    R.string.maphelpercontinue, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            mListener.onDialogPositiveClickMapHelp(MapFileMessage.this);
        }
    }).setNegativeButton(R.string.maphelpernomap, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            mListener.onDialogNegativeClickMapHelp(MapFileMessage.this);
        }
    }).setTitle(R.string.mapshelptitle);
    // Create the AlertDialog object and return it
    return builder.create();
}
Example 86
Project: RxAndroidBootstrap-master  File: DialogUtils.java View source code
/**
     * Show a model dialog box.  The <code>android.app.AlertDialog</code> object is returned so that
     * you can specify an OnDismissListener (or other listeners) if required.
     * <b>Note:</b> show() is already called on the AlertDialog being returned.
     *
     * @param context The current Context or Activity that this method is called from.
     * @param message Message to display in the dialog.
     * @return AlertDialog that is being displayed.
     */
public static AlertDialog quickDialog(final Activity context, final String message) {
    //Make links clickable
    final SpannableString s = new SpannableString(message);
    Linkify.addLinks(s, Linkify.ALL);
    Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(s);
    builder.setPositiveButton(android.R.string.ok, closeDialogListener());
    AlertDialog dialog = builder.create();
    dialog.show();
    //Make links clickable
    ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
    return dialog;
}
Example 87
Project: S1-Go-master  File: ImageLinkParser.java View source code
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    Layout layout = widget.getLayout();
    if (layout == null) {
        return super.onTouchEvent(widget, buffer, event);
    }
    int x = (int) event.getX();
    int y = (int) event.getY();
    int line = layout.getLineForVertical(y);
    int offset = layout.getOffsetForHorizontal(line, x);
    SpannableString value = SpannableString.valueOf(widget.getText());
    switch(event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            findSpan = null;
            ImageSpan[] imageSpans = value.getSpans(0, value.length(), ImageSpan.class);
            int findStart = 0;
            int findEnd = 0;
            for (ImageSpan imageSpan : imageSpans) {
                int start = value.getSpanStart(imageSpan);
                int end = value.getSpanEnd(imageSpan);
                if (start <= offset && offset <= end) {
                    find = true;
                    findStart = start;
                    findEnd = end;
                    findSpan = imageSpan;
                    break;
                }
            }
            return find || super.onTouchEvent(widget, buffer, event);
        case MotionEvent.ACTION_MOVE:
            break;
        case MotionEvent.ACTION_CANCEL:
            findSpan = null;
            break;
        case MotionEvent.ACTION_UP:
            if (findSpan != null) {
                String url = findSpan.getSource();
                if (url.startsWith("static/image/smiley/")) {
                    return false;
                }
                PictureActivity.start(widget.getContext(), url);
                return true;
            }
    }
    return super.onTouchEvent(widget, buffer, event);
}
Example 88
Project: sgchat-master  File: MessageTranslate.java View source code
public static SpannableString Trans(Context context, String str) {
    SpannableString ss = new SpannableString(str);
    MarkRecorder markrecorder = new MarkRecorder();
    FindMark(str, markrecorder);
    for (MarkItem item : markrecorder.listItems) {
        Drawable d = PicCatch.GetI().Get(item);
        if (d != null) {
            d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
            ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
            ss.setSpan(span, item.nStart, item.nEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            ss.setSpan(typeClick(d, context), item.nStart, item.nEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return ss;
}
Example 89
Project: shuffle-gtd-master  File: StatusView.java View source code
private void createStatusStrings() {
    String deleted = getResources().getString(R.string.deleted);
    int deletedColour = getResources().getColor(R.drawable.red);
    ForegroundColorSpan deletedColorSpan = new ForegroundColorSpan(deletedColour);
    String inactive = getResources().getString(R.string.inactive);
    int inactiveColour = getResources().getColor(R.drawable.mid_gray);
    ForegroundColorSpan inactiveColorSpan = new ForegroundColorSpan(inactiveColour);
    mDeleted = new SpannableString(deleted);
    mDeleted.setSpan(deletedColorSpan, 0, deleted.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mDeletedAndInactive = new SpannableString(inactive + " " + deleted);
    mDeletedAndInactive.setSpan(inactiveColorSpan, 0, inactive.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
    mDeletedAndInactive.setSpan(deletedColorSpan, inactive.length(), mDeletedAndInactive.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mInactive = new SpannableString(inactive);
    mInactive.setSpan(inactiveColorSpan, 0, inactive.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
}
Example 90
Project: SITracker-master  File: SearchAuthorItemView.java View source code
public void bind(@NotNull SearchedAuthor author, @NotNull OnClickListener listener) {
    searchTarget.setOnClickListener(listener);
    if (author.isAdded()) {
        actionText.setText(getContext().getString(R.string.already_in_library));
        actionImg.setImageResource(R.drawable.in_library);
        searchTarget.setBackgroundColor(getResources().getColor(R.color.search_back_positive));
    } else {
        actionText.setText(getContext().getString(R.string.tap_to_add_to_library));
        actionImg.setImageResource(R.drawable.not_in_library);
        searchTarget.setBackgroundColor(getResources().getColor(R.color.search_back_default));
    }
    authorName.setText(author.getAuthorName());
    authorUrl.setText(author.getAuthorUrl().replace("http://", "").replace("/indextitle.shtml", ""));
    SpannableString spannableString = new SpannableString(Html.fromHtml(author.getContextDescription()));
    matchDescription.setText(spannableString);
}
Example 91
Project: sketch-master  File: AboutFragment.java View source code
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    SpannableString string = new SpannableString("(点击查看示例)");
    string.setSpan(new ClickableSpan() {

        @Override
        public void onClick(View widget) {
            if (togglePageListener != null) {
                togglePageListener.onToggleToGifSample();
            }
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            ds.setColor(Color.parseColor("#0000ff"));
            super.updateDrawState(ds);
        }
    }, 0, string.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    gifIntroTextView.setMovementMethod(LinkMovementMethod.getInstance());
    gifIntroTextView.append(string);
}
Example 92
Project: TextViewSpanClickable-master  File: PraiseTextView.java View source code
/**
     * 设置点赞的å??å­—
     *
     * @param names
     * @return
     */
public void setPraiseName(List<String> names) {
    setText("");
    String nameStr;
    StringBuilder sBuilder = new StringBuilder();
    for (String name : names) {
        sBuilder.append(name);
        sBuilder.append("�");
    }
    String lengthStr = "等" + names.size() + "人";
    nameStr = sBuilder.substring(0, sBuilder.length() - 1);
    nameStr += lengthStr;
    SpannableString mSpannableString = new SpannableString(nameStr);
    int start = nameStr.indexOf(lengthStr);
    mSpannableString.setSpan(boldSpan, 0, start, //加粗
    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    append(mSpannableString);
}
Example 93
Project: TokenAutoComplete-master  File: CharacterTokenizer.java View source code
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();
    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }
    if (i > 0 && splitChar.contains(text.charAt(i - 1))) {
        return text;
    } else {
        // Try not to use a space as a token character
        String token = (splitChar.size() > 1 && splitChar.get(0) == ' ' ? splitChar.get(1) : splitChar.get(0)) + " ";
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text + token);
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
            return sp;
        } else {
            return text + token;
        }
    }
}
Example 94
Project: tradutorgalego-android-master  File: CustomDialog.java View source code
public static AlertDialog create(Context context, int titleId, int messageId, int drawableId) {
    final TextView message = new TextView(context);
    // i.e.: R.string.dialog_message =>
    // "Test this dialog following the link to dtmilano.blogspot.com"
    final SpannableString s = new SpannableString(context.getText(messageId));
    Linkify.addLinks(s, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
    message.setText(s);
    message.setMovementMethod(LinkMovementMethod.getInstance());
    return new AlertDialog.Builder(context).setTitle(titleId).setCancelable(true).setIcon(drawableId).setPositiveButton(R.string.ok, null).setView(message).create();
}
Example 95
Project: Under-the-Hood---Android-master  File: MyAlertBox.java View source code
public static ScrollView LinkifyText(Context context, String message) {
    ScrollView svMessage = new ScrollView(context);
    TextView tvMessage = new TextView(context);
    SpannableString spanText = new SpannableString(message);
    Linkify.addLinks(spanText, Linkify.ALL);
    tvMessage.setText(spanText);
    tvMessage.setTextColor(context.getResources().getColor(R.color.default_text_color));
    tvMessage.setMovementMethod(LinkMovementMethod.getInstance());
    svMessage.setPadding(14, 2, 10, 12);
    svMessage.addView(tvMessage);
    return svMessage;
}
Example 96
Project: USB-Device-Info---Android-master  File: AboutDialogFactory.java View source code
public static Dialog createAboutDialog(final Context context) {
    final View view = LayoutInflater.from(context).inflate(R.layout.dialog_textview, null);
    final TextView textView = (TextView) view.findViewById(R.id.text);
    final SpannableString text = new SpannableString(constructAboutText(context));
    textView.setText(text);
    textView.setAutoLinkMask(Activity.RESULT_OK);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    Linkify.addLinks(text, Linkify.ALL);
    final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {

        public void onClick(final DialogInterface dialog, final int id) {
        }
    };
    return new AlertDialog.Builder(context).setTitle(R.string.label_menu_about).setCancelable(false).setPositiveButton(android.R.string.ok, listener).setView(view).create();
}
Example 97
Project: Wallet32-master  File: SpaceyTextView.java View source code
private void applySpacey() {
    StringBuilder builder = new StringBuilder(originalText);
    SpannableString finalText = new SpannableString(builder.toString());
    if (builder.toString().length() > 1) {
        for (int ii = 1; ii < builder.toString().length(); ++ii) {
            if (builder.charAt(ii) == ' ')
                finalText.setSpan(new ScaleXSpan((float) 0.35), ii, ii + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    super.setText(finalText, BufferType.SPANNABLE);
}
Example 98
Project: WeddingCalculator-master  File: Fragment5.java View source code
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    activity = getActivity();
    View view = inflater.inflate(R.layout.fragment5, container, false);
    TextView textView = (TextView) view.findViewById(R.id.version);
    // Display the version
    try {
        textView.setText(activity.getResources().getText(R.string.currentVersion) + activity.getPackageManager().getPackageInfo(activity.getBaseContext().getPackageName(), 0).versionName);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    TextView textViewTitle1 = (TextView) view.findViewById(R.id.title1);
    SpannableString s = null;
    try {
        s = new SpannableString(activity.getResources().getText(R.string.fragment4Title1Content));
    } catch (NotFoundException e) {
        s = new SpannableString("");
    }
    Linkify.addLinks(s, Linkify.ALL);
    textViewTitle1.setMovementMethod(LinkMovementMethod.getInstance());
    textViewTitle1.setText(s);
    Button button = (Button) view.findViewById(R.id.loanButton);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse(activity.getResources().getText(R.string.fragment5ButtonLink).toString()));
            startActivity(intent);
        }
    });
    return view;
}
Example 99
Project: WeiBo_LH-master  File: SpannableStringUtils.java View source code
public static SpannableString span(Context context, String text) {
    text = text.replace("\\n", "\n").replace("<br>", "\n");
    SpannableStringBuilder ssb = new SpannableStringBuilder(text);
    Linkify.addLinks(ssb, PATTERN_WEB, HTTP_SCHEME);
    Linkify.addLinks(ssb, PATTERN_TOPIC, TOPIC_SCHEME);
    Linkify.addLinks(ssb, PATTERN_MENTION, MENTION_SCHEME);
    return null;
}
Example 100
Project: Wifi-Key-Recovery---Android-master  File: MyAlertBox.java View source code
public static ScrollView LinkifyText(Context context, String message) {
    final ScrollView svMessage = new ScrollView(context);
    final TextView tvMessage = new TextView(context);
    final SpannableString spanText = new SpannableString(message);
    Linkify.addLinks(spanText, Linkify.ALL);
    tvMessage.setText(spanText);
    tvMessage.setTextColor(context.getResources().getColor(R.color.default_text_color_light));
    tvMessage.setMovementMethod(LinkMovementMethod.getInstance());
    svMessage.setPadding(14, 2, 10, 12);
    svMessage.addView(tvMessage);
    return svMessage;
}
Example 101
Project: XposedInstaller-master  File: NavUtil.java View source code
public static Uri parseURL(String str) {
    if (str == null || str.isEmpty())
        return null;
    Spannable spannable = new SpannableString(str);
    Linkify.addLinks(spannable, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
    URLSpan spans[] = spannable.getSpans(0, spannable.length(), URLSpan.class);
    return (spans.length > 0) ? Uri.parse(spans[0].getURL()) : null;
}