Example usage for android.graphics Typeface BOLD

List of usage examples for android.graphics Typeface BOLD

Introduction

In this page you can find the example usage for android.graphics Typeface BOLD.

Prototype

int BOLD

To view the source code for android.graphics Typeface BOLD.

Click Source Link

Usage

From source file:Main.java

/**
 * Given a snippet string with matching segments surrounded by curly
 * braces, turn those areas into bold spans, removing the curly braces.
 *//*from  w  w w .ja v a  2s .  c  om*/
public static Spannable buildStyledSnippet(String snippet) {
    final SpannableStringBuilder builder = new SpannableStringBuilder(snippet);

    // Walk through string, inserting bold snippet spans
    int startIndex, endIndex = -1, delta = 0;
    while ((startIndex = snippet.indexOf('{', endIndex)) != -1) {
        endIndex = snippet.indexOf('}', startIndex);

        // Remove braces from both sides
        builder.delete(startIndex - delta, startIndex - delta + 1);
        builder.delete(endIndex - delta - 1, endIndex - delta);

        // Insert bold style
        builder.setSpan(new StyleSpan(Typeface.BOLD), startIndex - delta, endIndex - delta - 1,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        //builder.setSpan(new ForegroundColorSpan(0xff111111),
        //        startIndex - delta, endIndex - delta - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        delta += 2;
    }

    return builder;
}

From source file:Main.java

public static void showChangelog(final Context context, final String title, final String appname,
        final int resChanges, final int resNotes) {
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
    final String v0 = p.getString(PREFS_LAST_RUN, "");
    String v1 = null;//from w w w. ja v  a  2s  .co m
    try {
        v1 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "package not found: " + context.getPackageName(), e);
    }
    p.edit().putString(PREFS_LAST_RUN, v1).commit();
    if (v0.length() == 0) {
        Log.d(TAG, "first boot, skip changelog");
        // return;
    }
    if (v0.equals(v1)) {
        Log.d(TAG, "no changes");
        return;
    }

    String[] changes = context.getResources().getStringArray(resChanges);
    String[] notes = resNotes > 0 ? context.getResources().getStringArray(resNotes) : null;

    final SpannableStringBuilder sb = new SpannableStringBuilder();
    for (String s : notes) {
        SpannableString ss = new SpannableString(s + "\n");
        int j = s.indexOf(":");
        if (j > 0) {
            if (!TextUtils.isEmpty(s)) {
                ss.setSpan(new StyleSpan(Typeface.BOLD), 0, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        sb.append(ss);
        sb.append("\n");
    }
    if (notes != null && notes.length > 0) {
        sb.append("\n");
    }
    for (String s : changes) {
        s = appname + " " + s.replaceFirst(": ", ":\n* ").replaceAll(", ", "\n* ") + "\n";
        SpannableString ss = new SpannableString(s);
        int j = s.indexOf(":");
        if (j > 0) {
            ss.setSpan(new StyleSpan(Typeface.BOLD), 0, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        sb.append(ss);
        sb.append("\n");
    }
    sb.setSpan(new RelativeSizeSpan(0.75f), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    changes = null;
    notes = null;

    AlertDialog.Builder b = new AlertDialog.Builder(context);
    b.setTitle(title);
    b.setMessage(sb);
    b.setCancelable(true);
    b.setPositiveButton(android.R.string.ok, null);
    b.show();
}

From source file:Main.java

public static void setTitle(TextView titleTv, int titleColor, int titleTextSize, int messageColor,
        int messageTextSize, CharSequence title, CharSequence message) {
    titleTv.setMinHeight(titleTextSize * 3);

    if (!TextUtils.isEmpty(title) && TextUtils.isEmpty(message)) {
        titleTv.setTextColor(titleColor);
        titleTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize);
        titleTv.getPaint().setFakeBoldText(true);
        titleTv.setText(title);//from  www  . java  2s  .c om
    } else if (TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) {
        titleTv.setTextColor(messageColor);
        titleTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, messageTextSize);
        titleTv.setText(message);
    } else if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) {
        SpannableString titleSs = new SpannableString(title + "\n" + message);
        titleSs.setSpan(new ForegroundColorSpan(titleColor), 0, title.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        titleSs.setSpan(new AbsoluteSizeSpan(titleTextSize), 0, title.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        titleSs.setSpan(new StyleSpan(Typeface.BOLD), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        titleSs.setSpan(new ForegroundColorSpan(messageColor), title.length(), titleSs.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        titleSs.setSpan(new AbsoluteSizeSpan(messageTextSize), title.length(), titleSs.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        titleTv.setText(titleSs);
        titleTv.setLineSpacing(0.0f, 1.2f);
    } else {
        titleTv.setVisibility(View.GONE);
    }
}

From source file:com.github.fountaingeyser.typefacecompat.TypefaceCompat.java

public static Typeface create(Context ctx, String familyName, int style) {
    if (isSupported(familyName)) {
        boolean styleAfterwards = false;
        String fileName = FONT_FAMILY_FILE_PREFIX.get(familyName);
        if (fileName.endsWith("-")) {
            // All styles are supported.
            fileName += STYLE_SUFFIX[style];
        } else {//w w  w  .j a  v a 2  s.  co  m
            switch (style) {
            case Typeface.NORMAL:
                break;
            case Typeface.BOLD:
            case Typeface.BOLD_ITALIC:
                // These styles are not supported by default. Therefore force style after retrieving normal font.
                styleAfterwards = true;
                break;
            case Typeface.ITALIC:
                fileName += STYLE_SUFFIX[style];
                break;
            }
        }
        fileName += TTF_SUFFIX;
        // Retrieve Typeface from cache.
        Typeface tf = TYPEFACE_CACHE.get(fileName);
        if (tf == null) {
            // Create Typeface and cache it for later.
            String fontPath = "fonts/" + fileName;
            tf = Typeface.createFromAsset(ctx.getAssets(), fontPath);
            if (tf != null) {
                TYPEFACE_CACHE.put(fileName, tf);
            }
        }
        if (tf != null) {
            return styleAfterwards ? Typeface.create(tf, style) : tf;
        }
    }
    // Let the default implementation of Typeface try.
    return Typeface.create(familyName, style);
}

From source file:com.example.android.capstone.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from w ww .  jav  a  2  s  .c om*/
    TextView myTitle = (TextView) toolbar.getChildAt(0);
    Typeface tf = Typeface.createFromAsset(getAssets(), getResources().getString(R.string.font_name));
    myTitle.setTypeface(tf, Typeface.BOLD);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(getResources().getString(R.string.ad_device_test)).build();
    mAdView.loadAd(adRequest);
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager()));
    TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
    tabLayout.setupWithViewPager(viewPager);
}

From source file:com.taobao.weex.utils.TypefaceUtil.java

public static void applyFontStyle(Paint paint, int style, int weight, String family) {
    int oldStyle;
    Typeface typeface = paint.getTypeface();
    if (typeface == null) {
        oldStyle = 0;//  w  w w . ja v  a  2  s .c  om
    } else {
        oldStyle = typeface.getStyle();
    }

    int want = 0;
    if ((weight == Typeface.BOLD) || ((oldStyle & Typeface.BOLD) != 0 && weight == WXStyle.UNSET)) {
        want |= Typeface.BOLD;
    }

    if ((style == Typeface.ITALIC) || ((oldStyle & Typeface.ITALIC) != 0 && style == WXStyle.UNSET)) {
        want |= Typeface.ITALIC;
    }

    if (family != null) {
        typeface = getOrCreateTypeface(family, want);
    }

    if (typeface != null) {
        paint.setTypeface(Typeface.create(typeface, want));
    } else {
        paint.setTypeface(Typeface.defaultFromStyle(want));
    }
}

From source file:gr.sepals.eshop.info.gui.OrderSlidePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_info_order, container, false);
    title = (TextView) rootView.findViewById(R.id.info_order_title_textview);
    desc = (TextView) rootView.findViewById(R.id.info_order_description_textview);
    Typeface titleFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/GFS_Pyrsos.otf");
    Typeface descFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/GFS_Goschen-Italic.otf");
    title.setTypeface(titleFont, Typeface.BOLD);
    desc.setTypeface(descFont);//  ww w. j  a  v  a 2  s.c om
    return rootView;
}

From source file:gr.sepals.eshop.info.gui.BalconySlidePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_info_balcony, container, false);
    title = (TextView) rootView.findViewById(R.id.info_balcony_title_textview);
    desc = (TextView) rootView.findViewById(R.id.info_balcony_description_textview);
    Typeface titleFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/GFS_Pyrsos.otf");
    Typeface descFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/GFS_Goschen-Italic.otf");
    title.setTypeface(titleFont, Typeface.BOLD);
    desc.setTypeface(descFont);//from w  w  w  .  j  av  a  2  s .c o  m
    return rootView;
}

From source file:gr.sepals.eshop.info.gui.NetworkSlidePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_info_network, container, false);
    title = (TextView) rootView.findViewById(R.id.info_network_title_textview);
    desc = (TextView) rootView.findViewById(R.id.info_network_description_textview);
    Typeface titleFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/GFS_Pyrsos.otf");
    Typeface descFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/GFS_Goschen-Italic.otf");
    title.setTypeface(titleFont, Typeface.BOLD);
    desc.setTypeface(descFont);// w  w w.j a  v a  2 s  .c  om
    return rootView;
}

From source file:gr.sepals.eshop.info.gui.ProductsSlidePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_info_products, container, false);
    title = (TextView) rootView.findViewById(R.id.info_products_title_textview);
    desc = (TextView) rootView.findViewById(R.id.info_products_description_textview);
    Typeface titleFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/GFS_Pyrsos.otf");
    Typeface descFont = Typeface.createFromAsset(getActivity().getAssets(), "fonts/GFS_Goschen-Italic.otf");
    title.setTypeface(titleFont, Typeface.BOLD);
    desc.setTypeface(descFont);//from w w w.j  av a2  s .  c  o  m
    return rootView;
}