Example usage for android.text SpannableString setSpan

List of usage examples for android.text SpannableString setSpan

Introduction

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

Prototype

public void setSpan(Object what, int start, int end, int flags) 

Source Link

Usage

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);//from w w w . j a va2 s .c o  m
}

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);/*  w  w w  . j  a v  a 2s  . c o m*/

    return super.onCreateOptionsMenu(menu);
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    getDelegate().installViewFactory();//from  w w  w  .  j av a 2 s  . c  o  m
    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:org.iota.wallet.ui.fragment.NodeInfoFragment.java

private SpannableString generateCenterSpannableText() {
    SpannableString s = new SpannableString(getString(R.string.transactions));
    s.setSpan(new RelativeSizeSpan(0.75f), 0, 0, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    s.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getActivity(), R.color.colorAccent)), 0,
            s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return s;// w  ww .ja  va2 s .  com
}

From source file:io.spw.hello.SectionsPagerAdapter.java

@Override
public CharSequence getPageTitle(int position) {
    Drawable image = mActivity.getResources().getDrawable(imageResIdUnselected[position]);

    int currentPosition = ((MainActivity) mActivity).mViewPager.getCurrentItem();

    if (position == currentPosition) {
        image = mActivity.getResources().getDrawable(imageResIdSelected[position]);
    }//from   w w  w.ja  va2s .c  o m

    image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicWidth());
    SpannableString ss = new SpannableString(" ");
    ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM);
    ss.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return ss;

}

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//from   w  ww .  j ava2 s  .  c o  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: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);// ww w  .  j  ava  2s . c  o m
}

From source file:com.doomy.decode.ResultDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater mLayoutInflater = LayoutInflater.from(getActivity());
    View mView = mLayoutInflater.inflate(R.layout.view_result, null);

    TextView mTextViewFormat = (TextView) mView.findViewById(R.id.textViewFormat);
    TextView mTextViewContent = (TextView) mView.findViewById(R.id.textViewContent);

    if (mTitle.equals("EAN 13") && mMessage.startsWith("978")) {
        GetResponseTask mGetResponseTask = new GetResponseTask();
        mGetResponseTask.execute(mMessage);

        try {//from ww  w .  java  2 s  .  com
            if (mGetResponseTask.get().equals("")) {
                mTitle = "ISBN";
                mTextViewContent.setText(mMessage);
            } else {
                mTitle = "ISBN";
                mMessage = mGetResponseTask.get();
                SpannableString mSpan = new SpannableString(mMessage);
                mSpan.setSpan(new UnderlineSpan(), 0, mMessage.length(), 0);
                mTextViewContent.setText(mSpan);
                mTextViewContent.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        createURLIntent(makeURLSearch(mMessage));
                    }
                });
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    } else if (mTitle.equals("ISBN")) {
        if (!mMessage.startsWith("978")) {
            SpannableString mSpan = new SpannableString(mMessage);
            mSpan.setSpan(new UnderlineSpan(), 0, mMessage.length(), 0);
            mTextViewContent.setText(mSpan);
            mTextViewContent.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    createURLIntent(makeURLSearch(mMessage));
                }
            });
        } else {
            mTextViewContent.setText(mMessage);
        }
    } else if (mMessage.startsWith("www") || mMessage.startsWith("http://")
            || mMessage.startsWith("https://")) {
        SpannableString mSpan = new SpannableString(mMessage);
        mSpan.setSpan(new UnderlineSpan(), 0, mMessage.length(), 0);
        mTextViewContent.setText(mSpan);
        mTextViewContent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                createURLIntent(mMessage);
            }
        });
    } else {
        mTextViewContent.setText(mMessage);
    }

    if (mKey) {
        SimpleDateFormat mDateFormat = new SimpleDateFormat("dd/MM/yyyy-HH:mm");
        String mDate = mDateFormat.format(new Date());
        Scan mScan = new Scan(mTitle, mMessage, mDate);
        mDB.addOne(mScan);
    }

    mTextViewFormat.setText(mTitle);

    AlertDialog.Builder mAlertBuilder = new AlertDialog.Builder(getActivity(), Utils.setThemeDialog());

    mAlertBuilder.setTitle(getString(R.string.info)).setView(mView).setPositiveButton(getString(R.string.okay),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    if (mListener != null) {
                        mListener.onDialogPositiveClick(ResultDialogFragment.this);
                    }
                }
            });

    return mAlertBuilder.create();
}

From source file:typical_if.android.fragment.FragmentAboutUs.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_about, container, false);
    setRetainInstance(true);//from w  w  w.  ja  v  a  2  s .  c  om

    final ImageView devLight = (ImageView) rootView.findViewById(R.id.DevLightBtn);
    final ImageView stantsiya = (ImageView) rootView.findViewById(R.id.stantsiya);
    final ImageView tf = (ImageView) rootView.findViewById(R.id.tf_site);

    final TextView viktor = (TextView) rootView.findViewById(R.id.viktor_ref);
    final SpannableString content = new SpannableString(viktor.getText());
    content.setSpan(new UnderlineSpan(), 0, viktor.length(), 0);
    viktor.setText(content);

    final TextView yura = (TextView) rootView.findViewById(R.id.yurij_ref);
    final SpannableString content1 = new SpannableString(yura.getText());
    content1.setSpan(new UnderlineSpan(), 0, yura.length(), 0);
    yura.setText(content1);

    final TextView lyubomir = (TextView) rootView.findViewById(R.id.lyubomir_ref);
    final SpannableString content2 = new SpannableString(lyubomir.getText());
    content2.setSpan(new UnderlineSpan(), 0, lyubomir.length(), 0);
    lyubomir.setText(content2);

    final TextView vasil = (TextView) rootView.findViewById(R.id.vasil_ref);
    final SpannableString content3 = new SpannableString(vasil.getText());
    content3.setSpan(new UnderlineSpan(), 0, vasil.length(), 0);
    vasil.setText(content3);

    final TextView our_site_ref = (TextView) rootView.findViewById(R.id.devlight_com_ua_ref);
    final SpannableString content4 = new SpannableString(our_site_ref.getText());
    content4.setSpan(new UnderlineSpan(), 0, our_site_ref.length(), 0);
    our_site_ref.setText(content4);

    final TextView goToLicensePage = (TextView) rootView.findViewById(R.id.go_to_license);
    final SpannableString content5 = new SpannableString(goToLicensePage.getText());
    content5.setSpan(new UnderlineSpan(), 0, goToLicensePage.length(), 0);
    goToLicensePage.setText(content5);

    goToLicensePage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            LicenseFragment fragment = LicenseFragment.newInstance();
            getFragmentManager().beginTransaction().add(R.id.container, fragment).addToBackStack(null).commit();

        }
    });

    devLight.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Uri uri = Uri.parse("http://devLight.com.ua");
            getActivity().getApplicationContext().startActivity(
                    Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), Constants.BROWSER_CHOOSER)
                            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    });

    viktor.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Uri uri = Uri.parse("http://vk.com/sokeoner");
            getActivity().getApplicationContext().startActivity(
                    Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), Constants.BROWSER_CHOOSER)
                            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    });

    yura.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Uri uri = Uri.parse("http://vk.com/yura0202");
            getActivity().getApplicationContext().startActivity(
                    Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), Constants.BROWSER_CHOOSER)
                            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    });

    lyubomir.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Uri uri = Uri.parse("http://vk.com/lubomiru4");
            getActivity().getApplicationContext().startActivity(
                    Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), Constants.BROWSER_CHOOSER)
                            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    });

    vasil.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Uri uri = Uri.parse("http://vk.com/gigamole");
            getActivity().getApplicationContext().startActivity(
                    Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), Constants.BROWSER_CHOOSER)
                            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    });

    stantsiya.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Uri uri = Uri.parse("https://vk.com/stantsiya_if");
            getActivity().getApplicationContext().startActivity(
                    Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), Constants.BROWSER_CHOOSER)
                            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    });

    tf.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Uri uri = Uri.parse("http://typical.if.ua");
            getActivity().getApplicationContext().startActivity(
                    Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), Constants.BROWSER_CHOOSER)
                            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    });

    our_site_ref.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Uri uri = Uri.parse("http://devLight.com.ua");
            getActivity().getApplicationContext().startActivity(
                    Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), Constants.BROWSER_CHOOSER)
                            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    });

    return rootView;

}

From source file:se.tmeit.app.ui.members.MemberInfoFragment.java

private void setTextWithPrefix(TextView textView, int prefixResId, String str) {
    String prefixStr = getString(prefixResId);
    SpannableString teamStr = new SpannableString(prefixStr + " " + str);
    teamStr.setSpan(new RelativeSizeSpan(0.8f), 0, prefixStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    int foregroundColor = ContextCompat.getColor(getContext(), R.color.insektionen);
    teamStr.setSpan(new ForegroundColorSpan(foregroundColor), 0, prefixStr.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    textView.setText(teamStr);/*from  ww w  .  j  av a  2s . com*/
}