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:com.github.jobs.ui.fragment.JobDetailsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    Bundle arguments = getArguments();/*from   w  w  w  .ja  v a  2s  .  co  m*/
    String jobId = arguments.getString(KEY_JOB_ID);
    mJob = new Job();
    mJob.setId(jobId);
    mJob = adapter.findFirst(mJob);
    if (mJob == null) {
        mJob = new Job();
        Toast.makeText(getActivity(), R.string.error_getting_job_info, Toast.LENGTH_LONG).show();
    }
    setHasOptionsMenu(true);

    TextView title = (TextView) getView().findViewById(R.id.title);
    title.setText(StringUtils.trim(mJob.getTitle()));

    TextView description = (TextView) getView().findViewById(R.id.description);
    String jobDescription = mJob.getDescription();
    if (jobDescription != null) {
        description.setText(Html.fromHtml(jobDescription));
        description.setMovementMethod(LinkMovementMethod.getInstance());
    }

    TextView company = (TextView) getView().findViewById(R.id.company);
    company.setText(mJob.getCompany());

    TextView companyUrl = (TextView) getView().findViewById(R.id.company_url);
    if (mJob.getCompanyUrl() == null) {
        companyUrl.setVisibility(View.GONE);
    } else {
        SpannableString content = new SpannableString(mJob.getCompanyUrl());
        content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
        companyUrl.setText(content);
        companyUrl.setOnClickListener(this);
        companyUrl.setVisibility(View.VISIBLE);
    }

    TextView companyLocation = (TextView) getView().findViewById(R.id.company_location);
    if (mJob.getLocation() == null) {
        companyLocation.setVisibility(View.GONE);
    } else {
        companyLocation.setText(mJob.getLocation());
        companyLocation.setVisibility(View.VISIBLE);
    }

    if (!JobDetailsActivity.FULL_TIME.equalsIgnoreCase(mJob.getType())) {
        getView().findViewById(R.id.full_time).setVisibility(View.INVISIBLE);
    }

    mBackground = (ImageView) getView().findViewById(R.id.job_details_background);
    setLogoBackground();
}

From source file:com.android.talkback.menurules.RuleSpannables.java

@Override
public List<ContextMenuItem> getMenuItemsForNode(TalkBackService service,
        ContextMenuItemBuilder menuItemBuilder, AccessibilityNodeInfoCompat node) {
    final LinkedList<ContextMenuItem> result = new LinkedList<>();

    final SpannableString spannable = getStringWithUrlSpan(node);
    if (spannable == null) {
        return result;
    }/*  w w  w  .  jav  a2 s .  c om*/

    final URLSpan[] urlSpans = spannable.getSpans(0, spannable.length(), URLSpan.class);
    if ((urlSpans == null) || (urlSpans.length == 0)) {
        return result;
    }

    for (int i = 0; i < urlSpans.length; i++) {
        final URLSpan urlSpan = urlSpans[i];
        final String url = urlSpan.getURL();
        final int start = spannable.getSpanStart(urlSpan);
        final int end = spannable.getSpanEnd(urlSpan);
        final CharSequence label = spannable.subSequence(start, end);
        if (TextUtils.isEmpty(url) || TextUtils.isEmpty(label)) {
            continue;
        }

        final Uri uri = Uri.parse(url);
        if (uri.isRelative()) {
            // Generally, only absolute URIs are resolvable to an activity
            continue;
        }

        final ContextMenuItem item = menuItemBuilder.createMenuItem(service, Menu.NONE, i, Menu.NONE, label);
        item.setOnMenuItemClickListener(new SpannableMenuClickListener(service, uri));
        result.add(item);
    }

    return result;
}

From source file:task.application.com.colette.navigation.AppNavigationViewAsDrawerImpl.java

private void applyFontToMenuItem(MenuItem mi) {
    Typeface font = FontCache.getTypeface("Nunito-SemiBold.ttf", mActivity);
    SpannableString mNewTitle = new SpannableString(mi.getTitle());
    mNewTitle.setSpan(new CustomTypefaceSpan("", font), 0, mNewTitle.length(),
            Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    mi.setTitle(mNewTitle);//from w  ww  . j a v a  2 s.c  o  m
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {

    mContext = this;
    sharedPreferences = getSharedPreferences("com.aniruddhc.acemusic.player", Context.MODE_PRIVATE);

    //Get the screen's parameters.
    DisplayMetrics displayMetrics = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int screenWidth = displayMetrics.widthPixels;

    //Set the UI theme.
    if (sharedPreferences.getString(Common.CURRENT_THEME, "LIGHT_CARDS_THEME").equals("DARK_THEME")
            || sharedPreferences.getString(Common.CURRENT_THEME, "LIGHT_CARDS_THEME")
                    .equals("DARK_CARDS_THEME")) {
        setTheme(R.style.AppTheme);// www  .  j  av  a  2s. co m
    } else {
        setTheme(R.style.AppThemeLight);
    }

    super.onCreate(savedInstanceState);

    if (getOrientation().equals("PORTRAIT")) {

        //Finish this activity and relaunch the activity that called this one.
        Intent intent = new Intent(this, (Class<?>) getIntent().getSerializableExtra("CALLING_CLASS"));
        intent.putExtras(getIntent());
        intent.putExtra("NEW_PLAYLIST", false);
        intent.putExtra("CALLED_FROM_FOOTER", true);
        intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        finish();
        startActivity(intent);

        return;

    } else {

        setContentView(R.layout.activity_now_playing_queue);

        final Fragment nowPlayingQueueFragment = new NowPlayingQueueFragment();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.now_playing_queue_container, nowPlayingQueueFragment, "nowPlayingQueueFragment");
        transaction.commit();

        SpannableString s = new SpannableString(getResources().getString(R.string.current_queue));
        s.setSpan(new TypefaceSpan(this, "RobotoCondensed-Light"), 0, s.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // Update the action bar title with the TypefaceSpan instance.
        ActionBar actionBar = getActionBar();
        actionBar.setTitle(s);
        actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.holo_gray_selector));

    }

}

From source file:com.Duo.music.player.NowPlayingQueueActivity.NowPlayingQueueActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    mContext = this;
    sharedPreferences = getSharedPreferences("com.jams.music.player", Context.MODE_PRIVATE);

    //Get the screen's parameters.
    DisplayMetrics displayMetrics = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int screenWidth = displayMetrics.widthPixels;

    //Set the UI theme.
    if (sharedPreferences.getString(Common.CURRENT_THEME, "LIGHT_CARDS_THEME").equals("DARK_THEME")
            || sharedPreferences.getString(Common.CURRENT_THEME, "LIGHT_CARDS_THEME")
                    .equals("DARK_CARDS_THEME")) {
        setTheme(R.style.AppTheme);//from  ww w .j  a v a  2 s . c  o m
    } else {
        setTheme(R.style.AppThemeLight);
    }

    super.onCreate(savedInstanceState);

    if (getOrientation().equals("PORTRAIT")) {

        //Finish this activity and relaunch the activity that called this one.
        Intent intent = new Intent(this, (Class<?>) getIntent().getSerializableExtra("CALLING_CLASS"));
        intent.putExtras(getIntent());
        intent.putExtra("NEW_PLAYLIST", false);
        intent.putExtra("CALLED_FROM_FOOTER", true);
        intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        finish();
        startActivity(intent);

        return;

    } else {

        setContentView(R.layout.activity_now_playing_queue);

        final Fragment nowPlayingQueueFragment = new NowPlayingQueueFragment();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.now_playing_queue_container, nowPlayingQueueFragment, "nowPlayingQueueFragment");
        transaction.commit();

        SpannableString s = new SpannableString(getResources().getString(R.string.current_queue));
        s.setSpan(new TypefaceSpan(this, "RobotoCondensed-Light"), 0, s.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // Update the action bar title with the TypefaceSpan instance.
        ActionBar actionBar = getActionBar();
        actionBar.setTitle(s);
        actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.holo_gray_selector));

    }

}

From source file:com.jelly.music.player.NowPlayingQueueActivity.NowPlayingQueueActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    mContext = this;
    sharedPreferences = getSharedPreferences("com.jelly.music.player", Context.MODE_PRIVATE);

    //Get the screen's parameters.
    DisplayMetrics displayMetrics = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int screenWidth = displayMetrics.widthPixels;

    //Set the UI theme.
    if (sharedPreferences.getString(Common.CURRENT_THEME, "LIGHT_CARDS_THEME").equals("DARK_THEME")
            || sharedPreferences.getString(Common.CURRENT_THEME, "LIGHT_CARDS_THEME")
                    .equals("DARK_CARDS_THEME")) {
        setTheme(R.style.AppTheme);/* ww w . j a  v a 2s  . co  m*/
    } else {
        setTheme(R.style.AppThemeLight);
    }

    super.onCreate(savedInstanceState);

    if (getOrientation().equals("PORTRAIT")) {

        //Finish this activity and relaunch the activity that called this one.
        Intent intent = new Intent(this, (Class<?>) getIntent().getSerializableExtra("CALLING_CLASS"));
        intent.putExtras(getIntent());
        intent.putExtra("NEW_PLAYLIST", false);
        intent.putExtra("CALLED_FROM_FOOTER", true);
        intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        finish();
        startActivity(intent);

        return;

    } else {

        setContentView(R.layout.activity_now_playing_queue);

        final Fragment nowPlayingQueueFragment = new NowPlayingQueueFragment();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.now_playing_queue_container, nowPlayingQueueFragment, "nowPlayingQueueFragment");
        transaction.commit();

        SpannableString s = new SpannableString(getResources().getString(R.string.current_queue));
        s.setSpan(new TypefaceSpan(this, "RobotoCondensed-Light"), 0, s.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        // Update the action bar title with the TypefaceSpan instance.
        ActionBar actionBar = getActionBar();
        actionBar.setTitle(s);
        actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.holo_gray_selector));

    }

}

From source file:io.vit.vitio.Settings.SettingsActivity.java

private void setToolbar() {

    toolbar.setBackgroundColor(getResources().getColor(R.color.darkgray));
    setSupportActionBar(toolbar);//from  ww  w. j  a  v a 2 s . com
    SpannableString s = new SpannableString("SETTINGS");
    myTheme.refreshTheme();
    s.setSpan(myTheme.getMyThemeTypeFaceSpan(), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    getSupportActionBar().setTitle(s);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            returnBack();

        }
    });
    changeStatusBarColor(getResources().getColor(R.color.darkergray));
}

From source file:ar.uba.fi.mileem.SimpleFormActivity.java

protected void setTitle() {
    SpannableString s = new SpannableString(getString(R.string.app_name));
    s.setSpan(new TypefaceSpan(this, "Roboto-Light.ttf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    // Update the action bar title with the TypefaceSpan instance
    ActionBar actionBar = getActionBar();
    actionBar.setTitle(s);/*  w  ww .  ja v  a  2 s. c  om*/
}

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

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

    ActionBar actionBar = getActionBar();
    SpannableString s = new SpannableString(getResources().getString(R.string.create_playlist));
    s.setSpan(new TypefaceSpan(this, "RobotoCondensed-Light"), 0, s.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    actionBar.setTitle(s);//from w w  w  .j av  a  2  s.  com

    return super.onCreateOptionsMenu(menu);
}

From source file:io.github.hidroh.materialistic.widget.StoryView.java

public void setPromoted(int change) {
    SpannableString spannable = new SpannableString(String.format(Locale.US, PROMOTED, change));
    spannable.setSpan(new SuperscriptSpan(), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannable.setSpan(new RelativeSizeSpan(0.6f), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    spannable.setSpan(new ForegroundColorSpan(mPromotedColorResId), 0, spannable.length(),
            Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    mRankTextView.append(spannable);//from  w  w w .  j  av  a2  s.  c o m
}