Example usage for android.text SpannableString length

List of usage examples for android.text SpannableString length

Introduction

In this page you can find the example usage for android.text SpannableString length.

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:org.anoopam.main.anoopamvideo.VideoListActivity.java

@Override
public void manageAppBar(ActionBar actionBar, Toolbar toolbar, ActionBarDrawerToggle actionBarDrawerToggle) {

    actionBar.setDisplayHomeAsUpEnabled(true);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override/*  w w  w . ja  v  a  2  s.  co m*/
        public void onClick(View v) {
            finish();
        }
    });
    toolbar.setTitle(getString(R.string.nav_video));
    SpannableString spannableString = new SpannableString(currentAlbumName);
    spannableString.setSpan(new StyleSpan(Typeface.ITALIC), 0, spannableString.length(), 0);
    toolbar.setSubtitle(spannableString);
}

From source file:fyp.hkust.facet.activity.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    getDelegate().installViewFactory();/*from  w w w.j ava 2  s  .  com*/
    getDelegate().onCreate(savedInstanceState);
    getDelegate().getSupportActionBar().setHomeButtonEnabled(true);
    getDelegate().getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    super.onCreate(savedInstanceState);
    // ?SharePreferences
    SpannableString s = new SpannableString(getTitle().toString());
    s.setSpan(new TypefaceSpan(SettingsActivity.this, FontManager.CUSTOM_FONT), 0, s.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    getDelegate().getSupportActionBar().setTitle(s);

    getFragmentManager().beginTransaction()
            .replace(android.R.id.content, new SettingsActivity.MyPreferenceFragment()).commit();

}

From source file:com.aniruddhc.acemusic.player.MusicLibraryEditorActivity.MusicLibraryEditorActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.add_to_music_library, menu);

    ActionBar actionBar = getActionBar();
    actionBar.setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));
    actionBar.setIcon(// w  ww .j  a  v  a2 s  .c o m
            mContext.getResources().getIdentifier(libraryIconName, "drawable", mContext.getPackageName()));
    SpannableString s = new SpannableString(libraryName);
    s.setSpan(new TypefaceSpan(this, "RobotoCondensed-Light"), 0, s.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    actionBar.setTitle(s);

    return super.onCreateOptionsMenu(menu);
}

From source file:com.andrada.sitracker.ui.fragment.AboutDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    PackageManager pm = getActivity().getPackageManager();
    String packageName = getActivity().getPackageName();
    String versionName;/*from w ww . j  a v a  2  s.  c o  m*/
    try {
        PackageInfo info = pm.getPackageInfo(packageName, 0);
        versionName = info.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        versionName = VERSION_UNAVAILABLE;
    }

    SpannableStringBuilder aboutBody = new SpannableStringBuilder();
    SpannableString licensesLink = new SpannableString(getString(R.string.about_licenses));
    licensesLink.setSpan(new ClickableSpan() {
        @Override
        public void onClick(View view) {
            showOpenSourceLicenses(getActivity());
        }
    }, 0, licensesLink.length(), 0);
    SpannableString whatsNewLink = new SpannableString(getString(R.string.whats_new));
    whatsNewLink.setSpan(new ClickableSpan() {
        @Override
        public void onClick(View view) {
            showWhatsNew(getActivity());
        }
    }, 0, whatsNewLink.length(), 0);
    aboutBody.append(licensesLink);
    aboutBody.append("\n\n");
    aboutBody.append(whatsNewLink);

    AboutDialogView aboutBodyView = AboutDialogView_.build(getActivity());
    aboutBodyView.bindData(getString(R.string.app_version_format, versionName), aboutBody);

    return new AlertDialog.Builder(getActivity()).setTitle(R.string.action_about).setView(aboutBodyView)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.dismiss();
                }
            }).create();
}

From source file:app.philm.in.AndroidDisplay.java

private CharSequence convertToCondensed(final CharSequence string) {
    if (TextUtils.isEmpty(string)) {
        return string;
    }/*w ww  .j a va2  s .c om*/

    SpannableString s = new SpannableString(string);
    s.setSpan(mDefaultTitleSpan, 0, s.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    return s;
}

From source file:com.fuzz.emptyhusk.BoldTextCellGenerator.java

@NonNull
@Override/*from w  w  w  .ja v a  2s  . com*/
protected Spannable getTextFor(@NonNull Context context, int position) {
    String[] introStrings = context.getResources().getStringArray(R.array.introductory_messages);

    SpannableString ssb = new SpannableString(introStrings[position]);
    MigratoryStyleSpan span = new MigratoryStyleSpan(BOLD);

    // Order matters when setting spans. The base color must be in place first

    ForegroundColorSpan colorSpan = new ForegroundColorSpan(
            ContextCompat.getColor(context, R.color.colorSecondary));
    ssb.setSpan(colorSpan, 0, ssb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);

    // Only then should custom MigratorySpans be set.

    MigratoryRange<Integer> coverage = span.getCoverage(ssb);
    int start = coverage.getLower();
    int end = coverage.getUpper();
    ssb.setSpan(span, start, end, span.preferredFlags(0));

    MigratoryForegroundColorSpan boldColorSpan = new MigratoryForegroundColorSpan(
            ContextCompat.getColor(context, R.color.colorAccent));
    ssb.setSpan(boldColorSpan, start, end, boldColorSpan.preferredFlags(0));

    return ssb;
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

public static SpannableString highlightKeywords(int color, String text, String keywords,
        boolean actionFirstMatch) {

    if (text != null && keywords != null && text.trim().length() == keywords.trim().length()) {
        return SpannableString.valueOf(text.trim());
    }/*www. j av  a  2 s .  c o  m*/

    SpannableString s = new SpannableString(text);
    Pattern p = Pattern.compile(keywords, Pattern.LITERAL);
    Matcher m = p.matcher(s);
    while (m.find()) {
        int end = m.end();
        try {
            if (s.charAt(end) != ' ') {
                s.setSpan(new UnderlineSpan(), end, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            } else {
                s.setSpan(new UnderlineSpan(), end + 1, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (actionFirstMatch) {
            break;
        }
    }
    return s;
}

From source file:net.yoching.android.MainActivity.java

private void setupDrawer() {
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open,
            R.string.drawer_close) {/*from  www .  j  a  v a 2s. c  o m*/

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);

            SpannableString s = new SpannableString("64 WREXAGRAMS");
            s.setSpan(new TypefaceSpan("Exo-Bold.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            getSupportActionBar().setTitle(s);

            // invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            getSupportActionBar().setTitle(mActivityTitle);
            //   invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()

        }
    };

    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

From source file:crackerjack.education.Indijisites.StartUp.java

private void render(Marker marker, View view) {
    int badge;/*w  w  w  . j a va  2 s . c  o m*/
    if (marker.equals(mBrisbane)) {
        badge = R.drawable.badge_qld;
    } else {
        badge = 0;
    }
    ((ImageView) view.findViewById(R.id.badge)).setImageResource(badge);

    String title = marker.getTitle();
    TextView titleUi = ((TextView) view.findViewById(R.id.title));
    if (title != null) {
        // Spannable string allows us to edit the formatting of the text.
        SpannableString titleText = new SpannableString(title);
        titleText.setSpan(new ForegroundColorSpan(Color.RED), 0, titleText.length(), 0);
        titleUi.setText(titleText);
    } else {
        titleUi.setText("");
    }

    String snippet = marker.getSnippet();
    TextView snippetUi = ((TextView) view.findViewById(R.id.snippet));
    if (snippet != null && snippet.length() > 12) {
        SpannableString snippetText = new SpannableString(snippet);
        snippetText.setSpan(new ForegroundColorSpan(Color.BLUE), 0, snippet.length(), 0);
        snippetUi.setText(snippetText);
    } else {
        snippetUi.setText("");
    }
}

From source file:com.ntsync.android.sync.activities.KeyPasswordActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    SystemHelper.initSystem(this);

    Log.i(TAG, "loading data from Intent");
    final Intent intent = getIntent();
    mUsername = intent.getStringExtra(PARAM_USERNAME);
    pwdSalt = intent.getByteArrayExtra(PARAM_SALT);
    pwdCheck = intent.getByteArrayExtra(PARAM_CHECK);

    requestWindowFeature(Window.FEATURE_LEFT_ICON);
    setContentView(R.layout.keypassword_activity);
    getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.key);
    mMessage = (TextView) findViewById(R.id.message_bottom);

    mPasswordEdit = new AutoCompleteTextView[5];
    mPasswordEdit[0] = (AutoCompleteTextView) findViewById(R.id.pwd1_edit);
    mPasswordEdit[1] = (AutoCompleteTextView) findViewById(R.id.pwd2_edit);
    mPasswordEdit[2] = (AutoCompleteTextView) findViewById(R.id.pwd3_edit);
    mPasswordEdit[3] = (AutoCompleteTextView) findViewById(R.id.pwd4_edit);
    mPasswordEdit[4] = (AutoCompleteTextView) findViewById(R.id.pwd5_edit);
    for (AutoCompleteTextView textView : mPasswordEdit) {
        textView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE
                | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    }/*from   w ww .  j  a v a2s .  c  o m*/

    if (pwdSalt == null || pwdSalt.length != ClientKeyHelper.SALT_LENGHT || pwdCheck == null) {
        // disable password input
        for (AutoCompleteTextView textView : mPasswordEdit) {
            if (textView != null) {
                textView.setEnabled(false);
            }
        }
    }
    msgNewKey = (TextView) findViewById(R.id.message_newkey);
    SpannableString newKeyText = SpannableString.valueOf(getText(R.string.keypwd_activity_newkey_label));

    newKeyText.setSpan(new InternalURLSpan(this), 0, newKeyText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    msgNewKey.setText(newKeyText, BufferType.SPANNABLE);
    msgNewKey.setMovementMethod(LinkMovementMethod.getInstance());
}