Search in sources :

Example 31 with ClickableSpan

use of android.text.style.ClickableSpan in project zype-android by zype.

the class ConsumerActivity method bindViews.

// //////////
// UI
// 
private void bindViews() {
    if (consumer != null) {
        layoutEmail.getEditText().setText(consumer.email);
        layoutPassword.getEditText().setText(consumer.password);
    }
    // Set link to Terms screen
    String terms = getString(R.string.consumer_create_terms);
    String termsLink = getString(R.string.consumer_create_terms_link);
    SpannableString spannableTerms = new SpannableString(terms);
    ClickableSpan spanTerms = new ClickableSpan() {

        @Override
        public void onClick(View widget) {
            switchToTermsScreen();
        }
    };
    int index = terms.indexOf(termsLink);
    spannableTerms.setSpan(spanTerms, index, index + termsLink.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    textTerms.setText(spannableTerms);
    textTerms.setMovementMethod(LinkMovementMethod.getInstance());
    // Set link to Sign in
    String signIn = getString(R.string.consumer_create_sign_in);
    String signInLink = getString(R.string.consumer_create_sign_in_link);
    SpannableString spannableSignIn = new SpannableString(signIn);
    ClickableSpan spanSignIn = new ClickableSpan() {

        @Override
        public void onClick(View widget) {
            switchToLoginScreen();
        }
    };
    int indexSignIn = signIn.indexOf(signInLink);
    spannableSignIn.setSpan(spanSignIn, indexSignIn, indexSignIn + signInLink.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    textSignIn.setText(spannableSignIn);
    textSignIn.setMovementMethod(LinkMovementMethod.getInstance());
}
Also used : SpannableString(android.text.SpannableString) SpannableString(android.text.SpannableString) ClickableSpan(android.text.style.ClickableSpan) View(android.view.View) TextView(android.widget.TextView)

Example 32 with ClickableSpan

use of android.text.style.ClickableSpan in project Klyph by jonathangerbaud.

the class TextViewUtil method setTextClickableForTags.

/**
 * Make a clickable for the tags in parameters
 * If callback is null, TextViewUtil.onTagClick is called
 */
public static void setTextClickableForTags(final Context context, TextView textView, Map<String, List<Tag>> tags, final TagCallback callback, boolean clickable) {
    SpannableStringBuilder strBuilder = new SpannableStringBuilder(textView.getText());
    for (final List<Tag> tagList : tags.values()) {
        if (tagList.size() > 0) {
            CharacterStyle span;
            if (clickable) {
                span = new ClickableSpan() {

                    @Override
                    public void onClick(View widget) {
                        if (callback != null)
                            callback.onTagClick(tagList);
                        else
                            onTagClick(context, tagList);
                    }

                    @Override
                    public void updateDrawState(TextPaint ds) {
                        super.updateDrawState(ds);
                        ds.setUnderlineText(false);
                        ds.setFakeBoldText(true);
                    }
                };
            } else {
                span = new StyleSpan(Typeface.BOLD);
            }
            Tag tag = tagList.get(0);
            strBuilder.setSpan(span, tag.getOffset(), tag.getOffset() + tag.getLength(), 0);
        }
    }
    textView.setText(strBuilder);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
}
Also used : StyleSpan(android.text.style.StyleSpan) Tag(com.abewy.android.apps.klyph.core.fql.Tag) ClickableSpan(android.text.style.ClickableSpan) View(android.view.View) TextView(android.widget.TextView) SpannableStringBuilder(android.text.SpannableStringBuilder) CharacterStyle(android.text.style.CharacterStyle) TextPaint(android.text.TextPaint)

Example 33 with ClickableSpan

use of android.text.style.ClickableSpan in project TextJustify-Android by bluejamesbond.

the class ClickableSpanTest method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final DocumentView documentView = addDocumentView(new ArticleBuilder().append("Healthcare workers returning to New York or New Jersey after treating Ebola patients in West Africa will be placed under a mandatory quarantine, officials announced Friday, one day after a Doctors Without Borders doctor was diagnosed with the virus in New York City. Illinois announced a similar policy Saturday, meaning it will be enforced in states with three of the five airports through which passengers traveling from the Ebola-stricken West African countries must enter the United States.", true, new RelativeSizeSpan(1f), new JustifiedSpan()).append("N.J. Gov. Chris Christie and N.Y. Gov. Andrew Cuomo made the announcement as part of a broader procedural plan to help protect the densely packed, highly populated area from any further spread of the disease. ", true, new RelativeSizeSpan(0.8f), new JustifiedSpan(), new MyQuoteSpan(0xFFFFC801)).append("“Since taking office, I have erred on the side of caution when it comes to the safety and protection of New Yorkers, and the current situation regarding Ebola will be no different,” Gov. Cuomo said. “The steps New York and New Jersey are taking today will strengthen our safeguards to protect our residents against this disease and help ensure those that may be infected by Ebola are treated with the highest precautions.”", true, new RelativeSizeSpan(1f), new JustifiedSpan(), new ClickableSpan() {

        @Override
        public void onClick(View widget) {
            Toast.makeText(ClickableSpanTest.this, "Clicked", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            ds.setColor(Color.parseColor("#ff05c5cf"));
            ds.setUnderlineText(true);
        }
    }).append("New York and New Jersey state health department staff will be present on the ground at John F. Kennedy International Airport in New York and Newark Liberty Airport in New Jersey. In addition to implementing the mandatory quarantine of health care workers and others who had direct contact with Ebola patients, health department officials in each state will determine whether others should travelers should be hospitalized or quarantined.", true, new RelativeSizeSpan(1f), new JustifiedSpan()).append("“The announcements mark a dramatic escalation in measures designed to prevent the spread of Ebola in the United States. Previously, only individuals with symptoms of Ebola would be quarantined upon entry to the U.S. under a federal rule from the Centers for Diseases Control and the Department of Homeland Security.”", true, new RelativeSizeSpan(1f), new JustifiedSpan()), DocumentView.FORMATTED_TEXT);
    documentView.getDocumentLayoutParams().setHyphenator(SqueezeHyphenator.getInstance());
    documentView.getDocumentLayoutParams().setHyphenated(true);
}
Also used : JustifiedSpan(com.bluejamesbond.text.style.JustifiedSpan) MyQuoteSpan(com.bluejamesbond.text.sample.helper.MyQuoteSpan) ArticleBuilder(com.bluejamesbond.text.util.ArticleBuilder) RelativeSizeSpan(android.text.style.RelativeSizeSpan) DocumentView(com.bluejamesbond.text.DocumentView) ClickableSpan(android.text.style.ClickableSpan) DocumentView(com.bluejamesbond.text.DocumentView) View(android.view.View) TextPaint(android.text.TextPaint)

Example 34 with ClickableSpan

use of android.text.style.ClickableSpan in project actor-platform by actorapp.

the class BaseAuthFragment method findAndHilightTos.

private void findAndHilightTos(SpannableStringBuilder builder, String text, boolean urlAvailable) {
    String tosIndex = getString(R.string.auth_tos_index);
    int index = text.indexOf(tosIndex);
    ClickableSpan span;
    if (urlAvailable) {
        span = new BaseUrlSpan(ActorSDK.sharedActor().getTosUrl(), false);
    } else {
        span = new CustomClicableSpan(new CustomClicableSpan.SpanClickListener() {

            @Override
            public void onClick() {
                new AlertDialog.Builder(getContext()).setTitle(R.string.auth_tos_index).setMessage(ActorSDK.sharedActor().getTosText()).setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).show();
            }
        });
    }
    builder.setSpan(span, index, index + tosIndex.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
Also used : DialogInterface(android.content.DialogInterface) CustomClicableSpan(im.actor.sdk.view.CustomClicableSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) BaseUrlSpan(im.actor.sdk.view.BaseUrlSpan) ClickableSpan(android.text.style.ClickableSpan)

Example 35 with ClickableSpan

use of android.text.style.ClickableSpan in project actor-platform by actorapp.

the class BaseAuthFragment method findAndHilightPrivacy.

private void findAndHilightPrivacy(SpannableStringBuilder builder, String text, boolean urlAvailable) {
    String ppIndex = getString(R.string.auth_privacy_index);
    int index = text.indexOf(ppIndex);
    ClickableSpan span;
    if (urlAvailable) {
        span = new BaseUrlSpan(ActorSDK.sharedActor().getPrivacyUrl(), false);
    } else {
        span = new CustomClicableSpan(new CustomClicableSpan.SpanClickListener() {

            @Override
            public void onClick() {
                new AlertDialog.Builder(getContext()).setTitle(R.string.auth_privacy_index).setMessage(ActorSDK.sharedActor().getPrivacyText()).setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).show();
            }
        });
    }
    builder.setSpan(span, index, index + ppIndex.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
Also used : DialogInterface(android.content.DialogInterface) CustomClicableSpan(im.actor.sdk.view.CustomClicableSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) BaseUrlSpan(im.actor.sdk.view.BaseUrlSpan) ClickableSpan(android.text.style.ClickableSpan)

Aggregations

ClickableSpan (android.text.style.ClickableSpan)66 View (android.view.View)29 Layout (android.text.Layout)20 TextPaint (android.text.TextPaint)19 TextView (android.widget.TextView)19 SpannableString (android.text.SpannableString)15 Spannable (android.text.Spannable)14 Paint (android.graphics.Paint)13 SpannableStringBuilder (android.text.SpannableStringBuilder)11 Intent (android.content.Intent)7 InputMethodManager (android.view.inputmethod.InputMethodManager)7 Context (android.content.Context)5 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)4 StyleSpan (android.text.style.StyleSpan)4 SuppressLint (android.annotation.SuppressLint)3 DialogInterface (android.content.DialogInterface)3 AlertDialog (android.support.v7.app.AlertDialog)3 ImageView (android.widget.ImageView)3 SpanInfo (org.chromium.ui.text.SpanApplier.SpanInfo)3 PendingIntent (android.app.PendingIntent)2