Example usage for android.text SpannableString SpannableString

List of usage examples for android.text SpannableString SpannableString

Introduction

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

Prototype

public SpannableString(CharSequence source) 

Source Link

Document

For the backward compatibility reasons, this constructor copies all spans including android.text.NoCopySpan .

Usage

From source file:com.ibm.mil.readyapps.telco.hotspots.HotSpotActivity.java

private static SpannableString createSpan(String text, int start, int stop, Object... spans) {
    SpannableString spannableString = new SpannableString(text);
    for (Object span : spans) {
        spannableString.setSpan(span, start, stop, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    }/*from w  w w . j av a  2 s. c om*/
    return spannableString;
}

From source file:com.schautup.fragments.AboutDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Get app version
    PackageManager pm = getActivity().getPackageManager();
    String packageName = getActivity().getPackageName();
    String versionName;//from   w  w  w.  jav  a  2s.  co m
    String appName = getString(R.string.application_name);
    try {
        PackageInfo info = pm.getPackageInfo(packageName, 0);
        versionName = info.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        versionName = VERSION_UNAVAILABLE;
    }

    // About.
    SpannableStringBuilder aboutBody = new SpannableStringBuilder();
    aboutBody.append(Html.fromHtml(getString(R.string.about_body, appName, versionName)));

    // Licenses.
    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);
    aboutBody.append("\n\n");
    aboutBody.append(licensesLink);

    // End User License Agreement.
    SpannableString eulaLink = new SpannableString(getString(R.string.about_eula));
    eulaLink.setSpan(new ClickableSpan() {
        @Override
        public void onClick(View view) {
            showEula(getActivity());
        }
    }, 0, eulaLink.length(), 0);
    aboutBody.append("\n\n");
    aboutBody.append(eulaLink);

    // Show "About" dialog.
    LayoutInflater layoutInflater = (LayoutInflater) getActivity()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    TextView aboutBodyView = (TextView) layoutInflater.inflate(R.layout.dialog_about, null);
    aboutBodyView.setText(aboutBody);
    aboutBodyView.setMovementMethod(new LinkMovementMethod());

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

From source file:com.playground.notification.app.fragments.AboutDialogFragment.java

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

    // About.
    SpannableStringBuilder aboutBody = new SpannableStringBuilder();
    aboutBody.append(
            Html.fromHtml(getString(R.string.about_body, getString(R.string.application_name), versionName)));

    // Licenses.
    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);
    aboutBody.append("\n\n");
    aboutBody.append(licensesLink);

    // End User License Agreement.
    SpannableString eulaLink = new SpannableString(getString(R.string.about_eula));
    eulaLink.setSpan(new ClickableSpan() {
        @Override
        public void onClick(View view) {
            showEula(getActivity());
        }
    }, 0, eulaLink.length(), 0);
    aboutBody.append("\n\n");
    aboutBody.append(eulaLink);

    // Show "About" dialog.
    LayoutInflater layoutInflater = (LayoutInflater) getActivity()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View dialogV = layoutInflater.inflate(R.layout.fragment_dialog_about, null);
    ;
    TextView aboutBodyView = (TextView) dialogV.findViewById(R.id.dialog_text_tv);
    aboutBodyView.setText(aboutBody);
    aboutBodyView.setMovementMethod(new LinkMovementMethod());

    dialogV.findViewById(R.id.powered_by_ll).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Utils.openExternalBrowser(getActivity(), "http://" + getString(R.string.support_spielplatz_radar));
        }
    });

    dialogV.findViewById(R.id.weather_by_ll).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Utils.openExternalBrowser(getActivity(), "http://" + getString(R.string.support_openweathermap));
        }
    });

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

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  .ja v a  2 s. c om
}

From source file:com.example.adbird.MenuTabActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_menu);/* w w w . j  a  v a 2  s.c o m*/
    mContext = this.getApplicationContext();

    SharedPreferences prefs = getSharedPreferences("prefs", MODE_PRIVATE);
    String lang = prefs.getString("lang", null);
    Locale locale = new Locale(lang);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());
    SpannableString s = new SpannableString(mContext.getResources().getString(R.string.ads_title));
    s.setSpan(new TypefaceSpan(this, "GothaProReg.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setTitle(s);
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);

            SpannableString s = new SpannableString(mAppSectionsPagerAdapter.getPageTitle(position));
            s.setSpan(new TypefaceSpan(getApplicationContext(), "GothaProReg.otf"), 0, s.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            actionBar.setTitle(s);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab().setIcon(mAppSectionsPagerAdapter.getPageIcon(i)).setTabListener(this));

    }

}

From source file:com.coinblesk.client.utils.UIUtils.java

public static SpannableString getLargeBalance(Context context, Coin balanceCoin, Fiat balanceFiat) {
    SpannableString result;//  w  ww .  ja v  a 2s  .  co m
    if (SharedPrefUtils.isBitcoinPrimaryBalance(context)) {
        String coinScale = SharedPrefUtils.getBitcoinScalePrefix(context);
        result = toLargeSpannable(context, scaleCoin(context, balanceCoin), coinScale);
    } else if (SharedPrefUtils.isFiatPrimaryBalance(context)) {
        result = toLargeSpannable(context, balanceFiat.toPlainString(), balanceFiat.getCurrencyCode());
    } else {
        Log.e(TAG, "Unknown setting for primary balance: " + SharedPrefUtils.getPrimaryBalance(context));
        result = new SpannableString("N/A");
    }
    return result;
}

From source file:org.solovyev.android.calculator.App.java

@NonNull
public static SpannableString colorString(@Nonnull String s, int color) {
    final SpannableString spannable = new SpannableString(s);
    spannable.setSpan(new ForegroundColorSpan(color), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
}

From source file:fr.simon.marquis.secretcodes.util.Utils.java

public static SpannableString applyCustomTypeFace(CharSequence src, Context ctx) {
    SpannableString span = new SpannableString(src);

    span.setSpan(/*from w  w  w . ja  v a2s.  co  m*/
            new CustomTypefaceSpan("",
                    RobotoTypefaceManager.obtaintTypeface(ctx, RobotoTypefaceManager.ROBOTOSLAB_REGULAR)),
            0, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return span;
}

From source file:eu.lucazanini.arpav.fragment.CreditsFragment.java

@Nullable
@Override//from  www .  j  av a 2 s . c om
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    View v = inflater.inflate(R.layout.fragment_credits, container, false);

    unbinder = ButterKnife.bind(this, v);

    tvDataTitle.setText(dataTitle);
    tvDataBody.setMovementMethod(LinkMovementMethod.getInstance());
    SpannableString ssDataBody = getTextWithLink(new SpannableString(dataBody), arpavName, arpavSite);
    ssDataBody = getTextWithLink(ssDataBody, arpavLicenseName, arpavLicenseSite);
    tvDataBody.setText(ssDataBody);

    tvIconsTitle.setText(iconsTitle);
    tvIconsBody.setMovementMethod(LinkMovementMethod.getInstance());
    SpannableString ssIconsBody = getTextWithLink(new SpannableString(iconsBody), nickName, nickSite);
    ssIconsBody = getTextWithLink(ssIconsBody, nickLicenseName, nickSite);
    ssIconsBody = getTextWithLink(ssIconsBody, emilieName, emilieSite);
    ssIconsBody = getTextWithLink(ssIconsBody, emilieLicenseName, emilieLicenseSite);
    tvIconsBody.setText(ssIconsBody);

    tvDeveloperTitle.setText(developerTitle);
    tvDeveloperBody.setMovementMethod(LinkMovementMethod.getInstance());
    SpannableString ssDeveloperBody = getTextWithLink(new SpannableString(developerBody), developerName,
            developerSite);
    ssDeveloperBody = getTextWithLink(ssDeveloperBody, appLicenseName, appLicenseSite);
    ssDeveloperBody = getTextWithLink(ssDeveloperBody, repositoryName, repositorySite);
    tvDeveloperBody.setText(ssDeveloperBody);

    return v;
}

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);// w  ww  .  j  a v  a2  s  . com
    } 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));

    }

}