Search in sources :

Example 6 with UnderlineSpan

use of android.text.style.UnderlineSpan in project platform_frameworks_base by android.

the class ViewPropertyAlphaActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view_properties);
    getWindow().getDecorView().postDelayed(new Runnable() {

        @Override
        public void run() {
            startAnim(R.id.button);
            startAnim(R.id.textview);
            startAnim(R.id.spantext);
            startAnim(R.id.edittext);
            startAnim(R.id.selectedtext);
            startAnim(R.id.textviewbackground);
            startAnim(R.id.layout);
            startAnim(R.id.imageview);
            startAnim(myViewAlphaDefault);
            startAnim(myViewAlphaHandled);
            EditText selectedText = (EditText) findViewById(R.id.selectedtext);
            selectedText.setSelection(3, 8);
        }
    }, 2000);
    Button invalidator = (Button) findViewById(R.id.invalidateButton);
    invalidator.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            findViewById(R.id.textview).invalidate();
            findViewById(R.id.spantext).invalidate();
        }
    });
    TextView textView = (TextView) findViewById(R.id.spantext);
    if (textView != null) {
        SpannableStringBuilder text = new SpannableStringBuilder("Now this is a short text message with spans");
        text.setSpan(new BackgroundColorSpan(Color.RED), 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new ForegroundColorSpan(Color.BLUE), 4, 9, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new SuggestionSpan(this, new String[] { "longer" }, 3), 11, 16, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new UnderlineSpan(), 17, 20, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new ImageSpan(this, R.drawable.icon), 21, 22, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(text);
    }
    LinearLayout container = (LinearLayout) findViewById(R.id.container);
    myViewAlphaDefault = new MyView(this, false);
    myViewAlphaDefault.setLayoutParams(new LinearLayout.LayoutParams(75, 75));
    container.addView(myViewAlphaDefault);
    myViewAlphaHandled = new MyView(this, true);
    myViewAlphaHandled.setLayoutParams(new LinearLayout.LayoutParams(75, 75));
    container.addView(myViewAlphaHandled);
}
Also used : EditText(android.widget.EditText) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TextView(android.widget.TextView) View(android.view.View) UnderlineSpan(android.text.style.UnderlineSpan) Button(android.widget.Button) TextView(android.widget.TextView) SuggestionSpan(android.text.style.SuggestionSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) BackgroundColorSpan(android.text.style.BackgroundColorSpan) LinearLayout(android.widget.LinearLayout) ImageSpan(android.text.style.ImageSpan)

Example 7 with UnderlineSpan

use of android.text.style.UnderlineSpan in project MusicDNA by harjot-oberai.

the class AboutFragment method onViewCreated.

@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    // To add underline effect in open source license textView
    SpannableString content = new SpannableString("open source licenses");
    content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
    // Gets version and build number from package manager
    try {
        pInfo = view.getContext().getPackageManager().getPackageInfo(view.getContext().getPackageName(), 0);
        versionName = pInfo.versionName;
        versionCode = pInfo.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    versiontTextView = (TextView) view.findViewById(R.id.about_version_text);
    openSourceLicense = (TextView) view.findViewById(R.id.about_license_text);
    openSourceLicense.setText(content);
    openSourceLicense.setTextColor(HomeActivity.themeColor);
    githubLinkBtn = (ImageView) view.findViewById(R.id.about_github_link);
    reviewLinkBtn = (ImageView) view.findViewById(R.id.about_rate_link);
    shareLink = (ImageView) view.findViewById(R.id.about_share_link);
    backBtn = (ImageView) view.findViewById(R.id.about_back_btn);
    fragTitle = (TextView) view.findViewById(R.id.about_fragment_title);
    bottomMarginLayout = view.findViewById(R.id.bottom_margin_layout);
    versiontTextView.setText("Version " + versionName);
    if (SplashActivity.tf4 != null) {
        backBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                getActivity().onBackPressed();
            }
        });
        fragTitle.setTypeface(com.sdsmdg.harjot.MusicDNA.activities.SplashActivity.tf4);
    }
    if (HomeActivity.isReloaded) {
        bottomMarginLayout.getLayoutParams().height = 0;
    } else {
        bottomMarginLayout.getLayoutParams().height = com.sdsmdg.harjot.MusicDNA.utilities.CommonUtils.dpTopx(65, getContext());
    }
    openSourceLicense.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            displayOpenSourceLicenses();
        }
    });
    githubLinkBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Uri uri = Uri.parse("https://github.com/harjot-oberai/MusicStreamer");
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);
        }
    });
    reviewLinkBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Uri uri = Uri.parse("market://details?id=" + view.getContext().getPackageName());
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
            goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
            try {
                startActivity(goToMarket);
            } catch (ActivityNotFoundException e) {
                Log.e("AboutFragment.java: " + Thread.currentThread().getStackTrace()[2].getLineNumber(), e.getMessage());
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + view.getContext().getPackageName())));
            }
        }
    });
    shareLink.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.share_application_text) + " " + getResources().getString(R.string.music_dna_short_link));
            sendIntent.setType("text/plain");
            startActivity(sendIntent);
        }
    });
}
Also used : SpannableString(android.text.SpannableString) PackageManager(android.content.pm.PackageManager) ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) WebView(android.webkit.WebView) Uri(android.net.Uri) UnderlineSpan(android.text.style.UnderlineSpan)

Example 8 with UnderlineSpan

use of android.text.style.UnderlineSpan in project ExoPlayer by google.

the class Cea608Decoder method handlePreambleAddressCode.

private void handlePreambleAddressCode(byte cc1, byte cc2) {
    // cc1 - 0|0|0|1|C|E|ROW
    // C is the channel toggle, E is the extended flag, and ROW is the encoded row
    int row = ROW_INDICES[cc1 & 0x07];
    // TODO: Make use of the channel toggle
    // TODO: support the extended address and style
    // cc2 - 0|1|N|ATTRBTE|U
    // N is the next row down toggle, ATTRBTE is the 4-byte encoded attribute, and U is the
    // underline toggle.
    boolean nextRowDown = (cc2 & 0x20) != 0;
    if (nextRowDown) {
        row++;
    }
    if (row != currentCueBuilder.getRow()) {
        if (captionMode != CC_MODE_ROLL_UP && !currentCueBuilder.isEmpty()) {
            currentCueBuilder = new CueBuilder(captionMode, captionRowCount);
            cueBuilders.add(currentCueBuilder);
        }
        currentCueBuilder.setRow(row);
    }
    if ((cc2 & 0x01) == 0x01) {
        currentCueBuilder.setPreambleStyle(new UnderlineSpan());
    }
    // cc2 - 0|1|N|0|STYLE|U
    // cc2 - 0|1|N|1|CURSR|U
    int attribute = cc2 >> 1 & 0x0F;
    if (attribute <= 0x07) {
        if (attribute == 0x07) {
            currentCueBuilder.setPreambleStyle(new StyleSpan(Typeface.ITALIC));
            currentCueBuilder.setPreambleStyle(new ForegroundColorSpan(Color.WHITE));
        } else {
            currentCueBuilder.setPreambleStyle(new ForegroundColorSpan(COLORS[attribute]));
        }
    } else {
        currentCueBuilder.setIndent(COLUMN_INDICES[attribute & 0x07]);
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan) UnderlineSpan(android.text.style.UnderlineSpan)

Example 9 with UnderlineSpan

use of android.text.style.UnderlineSpan in project ExoPlayer by google.

the class WebvttCueParser method applySpansForTag.

private static void applySpansForTag(String cueId, StartTag startTag, SpannableStringBuilder text, List<WebvttCssStyle> styles, List<StyleMatch> scratchStyleMatches) {
    int start = startTag.position;
    int end = text.length();
    switch(startTag.name) {
        case TAG_BOLD:
            text.setSpan(new StyleSpan(STYLE_BOLD), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            break;
        case TAG_ITALIC:
            text.setSpan(new StyleSpan(STYLE_ITALIC), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            break;
        case TAG_UNDERLINE:
            text.setSpan(new UnderlineSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            break;
        case TAG_CLASS:
        case TAG_LANG:
        case TAG_VOICE:
        case // Case of the "whole cue" virtual tag.
        "":
            break;
        default:
            return;
    }
    scratchStyleMatches.clear();
    getApplicableStyles(styles, cueId, startTag, scratchStyleMatches);
    int styleMatchesCount = scratchStyleMatches.size();
    for (int i = 0; i < styleMatchesCount; i++) {
        applyStyleToText(text, scratchStyleMatches.get(i).style, start, end);
    }
}
Also used : StyleSpan(android.text.style.StyleSpan) UnderlineSpan(android.text.style.UnderlineSpan)

Example 10 with UnderlineSpan

use of android.text.style.UnderlineSpan in project WordPress-Android by wordpress-mobile.

the class HtmlStyleUtilsTest method testClearSpansShouldIgnoreUnderline.

@Test
public void testClearSpansShouldIgnoreUnderline() {
    // clearSpans() should ignore UnderlineSpan as it's used by the system for spelling suggestions
    Spannable content = new SpannableStringBuilder("test");
    content.setSpan(new UnderlineSpan(), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    HtmlStyleUtils.clearSpans(content, 0, 4);
    assertEquals(1, content.getSpans(0, 4, UnderlineSpan.class).length);
}
Also used : Spannable(android.text.Spannable) SpannableStringBuilder(android.text.SpannableStringBuilder) UnderlineSpan(android.text.style.UnderlineSpan) Test(org.junit.Test)

Aggregations

UnderlineSpan (android.text.style.UnderlineSpan)34 StyleSpan (android.text.style.StyleSpan)16 ForegroundColorSpan (android.text.style.ForegroundColorSpan)13 BackgroundColorSpan (android.text.style.BackgroundColorSpan)11 ImageSpan (android.text.style.ImageSpan)10 URLSpan (android.text.style.URLSpan)9 TextView (android.widget.TextView)9 SpannableStringBuilder (android.text.SpannableStringBuilder)8 StrikethroughSpan (android.text.style.StrikethroughSpan)8 SubscriptSpan (android.text.style.SubscriptSpan)8 SuperscriptSpan (android.text.style.SuperscriptSpan)8 TypefaceSpan (android.text.style.TypefaceSpan)8 View (android.view.View)8 SpannableString (android.text.SpannableString)7 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)7 RelativeSizeSpan (android.text.style.RelativeSizeSpan)7 LinearLayout (android.widget.LinearLayout)7 Application (android.app.Application)5 CharacterStyle (android.text.style.CharacterStyle)5 SuggestionSpan (android.text.style.SuggestionSpan)5