Example usage for android.graphics Typeface ITALIC

List of usage examples for android.graphics Typeface ITALIC

Introduction

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

Prototype

int ITALIC

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

Click Source Link

Usage

From source file:Main.java

public static void changeToComicSansItalic(CheckBox checkBox, AssetManager asset) {
    Typeface typeface = Typeface.createFromAsset(asset, "fonts/comicsans.ttf");
    checkBox.setTypeface(typeface, Typeface.ITALIC);
}

From source file:Main.java

public static int toTypefaceStyle(String fontWeight, String fontStyle) {
    int style = Typeface.NORMAL;

    if (fontWeight != null) {
        if (fontWeight.equals("bold")) {
            if (fontStyle != null && fontStyle.equals("italic")) {
                style = Typeface.BOLD_ITALIC;
            } else {
                style = Typeface.BOLD;//from   ww  w  .jav  a  2 s.c  om
            }
        } else if (fontStyle != null && fontStyle.equals("italic")) {
            style = Typeface.ITALIC;
        }
    } else if (fontStyle != null && fontStyle.equals("italic")) {
        style = Typeface.ITALIC;
    }
    return style;
}

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.ja va  2s .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.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  a2  s  . c  o m*/
    } 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:org.cyanogenmod.theme.chooser.FontPreviewFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPkgName = getArguments().getString(PKG_EXTRA);

    ThemedTypefaceHelper helper = new ThemedTypefaceHelper();
    helper.load(getActivity(), mPkgName);
    mTypefaceNormal = helper.getTypeface(Typeface.NORMAL);
    mTypefaceBold = helper.getTypeface(Typeface.BOLD);
    mTypefaceItalic = helper.getTypeface(Typeface.ITALIC);
    mTypefaceBoldItalic = helper.getTypeface(Typeface.BOLD_ITALIC);
}

From source file:org.mariotaku.twidere.util.HtmlSpanBuilder.java

private static Object createSpan(TagInfo info) {
    switch (info.name.toLowerCase(Locale.US)) {
    case "a": {
        return new URLSpan(info.getAttribute("href"));
    }//from  ww w .  java2s. c o  m
    case "b":
    case "strong": {
        return new StyleSpan(Typeface.BOLD);
    }
    case "em":
    case "cite":
    case "dfn":
    case "i": {
        return new StyleSpan(Typeface.ITALIC);
    }
    }
    return null;
}

From source file:com.chatwing.whitelabel.adapters.ConversationsAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    Conversation conversation = ConversationTable.getConversation(cursor);

    TextView aliasTv = (TextView) view.findViewById(android.R.id.text1);
    aliasTv.setText(conversation.getConversationAlias(mCurrentUser.getId()));

    int countIndexColumn = cursor.getColumnIndex(ConversationTable.UNREAD_COUNT);
    int count = cursor.getInt(countIndexColumn);
    TextView countTv = (TextView) view.findViewById(R.id.unread_count);
    if (count == 0) {
        countTv.setVisibility(View.GONE);
    } else {//from  ww  w  .j  av  a  2 s  . com
        countTv.setText(String.valueOf(count));
        countTv.setVisibility(View.VISIBLE);
    }

    LogUtils.v("Conversation " + aliasTv.getText() + ":" + conversation.isModerator());
    if (conversation.isModerator()) {
        aliasTv.setTypeface(null, Typeface.ITALIC);
    } else {
        aliasTv.setTypeface(null, Typeface.NORMAL);
    }
}

From source file:com.bdevlin.apps.ui.fragments.HelpListFragment.java

private void updateText() {
    // mHelpText = (TextView) getView().findViewById(R.id.help_text);
    mHelpText = (WebView) getView().findViewById(R.id.webView1);
    mHelpText.getSettings().setJavaScriptEnabled(false);

    CharSequence text = Utils.bold(Utils.italic(getResources().getString(R.string.about_eula)),
            Utils.color(Color.RED, getResources().getString(R.string.about_licenses)));
    CharSequence yourHtml = "<table>table</table>";

    CharSequence content = getContent();
    ;//from w  w  w . j  av  a 2s . co  m
    SpannedString sstr = SpannedString.valueOf(content);
    SpannedString message = SpannedString.valueOf(mMessage);
    SpannedString message2 = SpannedString.valueOf(text);
    SpannedString message3 = SpannedString.valueOf(yourHtml);

    SpannableStringBuilder aboutBody = new SpannableStringBuilder();
    aboutBody.append(Html.fromHtml(Html.toHtml(message)));
    aboutBody.append(Html.fromHtml(Html.toHtml(message2)));
    aboutBody.append(Html.fromHtml(Html.toHtml(message3)));
    aboutBody.append(Html.fromHtml(Html.toHtml(sstr)));
    aboutBody.setSpan(new StyleSpan(Typeface.ITALIC), 0, aboutBody.length(), 0);
    // mHelpText.setText(aboutBody);
    // mHelpText.loadData(Html.toHtml(aboutBody), "text/html", null);

    mHelpText.loadUrl("file:///android_asset/" + mTitle + ".html", null);

    //mHelpText.loadUrl("http://www.choosemyplate.gov/tools-supertracker");

}

From source file:org.mdc.chess.SeekBarPreference.java

@Override
protected View onCreateView(ViewGroup parent) {
    TextView name = new TextView(getContext());
    name.setText(getTitle());/*  w w  w . jav  a 2s .c o m*/
    //name.setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
    TextViewCompat.setTextAppearance(name, android.R.style.TextAppearance_Large);
    name.setGravity(Gravity.START);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.START;
    lp.weight = 1.0f;
    name.setLayoutParams(lp);

    currValBox = new TextView(getContext());
    currValBox.setTextSize(12);
    currValBox.setTypeface(Typeface.MONOSPACE, Typeface.ITALIC);
    currValBox.setPadding(2, 5, 0, 0);
    currValBox.setText(valToString());
    lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.CENTER;
    currValBox.setLayoutParams(lp);

    LinearLayout row1 = new LinearLayout(getContext());
    row1.setOrientation(LinearLayout.HORIZONTAL);
    row1.addView(name);
    row1.addView(currValBox);

    final SeekBar bar = new SeekBar(getContext());
    bar.setMax(maxValue);
    bar.setProgress(currVal);
    bar.setOnSeekBarChangeListener(this);
    lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.END;
    bar.setLayoutParams(lp);

    CharSequence summaryCharSeq = getSummary();
    boolean haveSummary = (summaryCharSeq != null) && (summaryCharSeq.length() > 0);
    TextView summary = null;
    if (haveSummary) {
        summary = new TextView(getContext());
        summary.setText(getSummary());
        //            summary.setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
        summary.setGravity(Gravity.START);
        lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        lp.gravity = Gravity.START;
        lp.weight = 1.0f;
        summary.setLayoutParams(lp);
    }

    LinearLayout layout = new LinearLayout(getContext());
    layout.setPadding(25, 5, 25, 5);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(row1);
    layout.addView(bar);
    if (summary != null) {
        layout.addView(summary);
    }
    layout.setId(android.R.id.widget_frame);

    currValBox.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            View content = View.inflate(SeekBarPreference.this.getContext(), R.layout.select_percentage, null);
            final AlertDialog.Builder builder = new AlertDialog.Builder(SeekBarPreference.this.getContext());
            builder.setView(content);
            String title = "";
            String key = getKey();
            if (key.equals("strength")) {
                title = getContext().getString(R.string.edit_strength);
            } else if (key.equals("bookRandom")) {
                title = getContext().getString(R.string.edit_randomization);
            }
            builder.setTitle(title);
            final EditText valueView = (EditText) content.findViewById(R.id.selpercentage_number);
            valueView.setText(currValBox.getText().toString().replaceAll("%", "").replaceAll(",", "."));
            final Runnable selectValue = new Runnable() {
                public void run() {
                    try {
                        String txt = valueView.getText().toString();
                        int value = (int) (Double.parseDouble(txt) * 10 + 0.5);
                        if (value < 0)
                            value = 0;
                        if (value > maxValue)
                            value = maxValue;
                        onProgressChanged(bar, value, false);
                    } catch (NumberFormatException ignored) {

                    }
                }
            };
            valueView.setOnKeyListener(new OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        selectValue.run();
                        return true;
                    }
                    return false;
                }
            });
            builder.setPositiveButton("Ok", new Dialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    selectValue.run();
                }
            });
            builder.setNegativeButton("Cancel", null);

            builder.create().show();
        }
    });

    return layout;
}

From source file:com.normalexception.app.rx8club.view.profile.ProfileViewArrayAdapter.java

public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;//w  w w  . j  a  v  a  2 s  . c  o  m
    if (vi == null) {
        vi = new TextView(sourceFragment.getActivity());
    }

    TextView tv = (TextView) vi;
    final ProfileModel pm = data.get(position);
    String text = String.format("%s\n%s", pm.getName(), pm.getText());
    SpannableString spanString = new SpannableString(text);
    spanString.setSpan(new StyleSpan(Typeface.BOLD), 0, text.indexOf("\n"), 0);
    spanString.setSpan(new StyleSpan(Typeface.ITALIC), text.indexOf("\n") + 1, text.length(), 0);
    tv.setText(spanString);
    tv.setPadding(1, 10, 1, 10);
    tv.setBackgroundColor(Color.DKGRAY);
    tv.setTextColor(Color.WHITE);
    tv.setTextSize(10);
    tv.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Bundle args = new Bundle();
            args.putString("link", pm.getLink());
            args.putString("title", pm.getName());
            FragmentUtils.fragmentTransaction(sourceFragment.getActivity(), ThreadFragment.newInstance(), false,
                    true, args);
        }
    });

    return vi;
}