Example usage for android.graphics Typeface create

List of usage examples for android.graphics Typeface create

Introduction

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

Prototype

public static Typeface create(Typeface family, @Style int style) 

Source Link

Document

Create a typeface object that best matches the specified existing typeface and the specified Style.

Usage

From source file:com.ryan.demostore.logger.LogFragment.java

public View inflateViews() {
    mScrollView = new ScrollView(getActivity());
    ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    mScrollView.setLayoutParams(scrollParams);

    mLogView = new LogView(getActivity());
    ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
    logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLogView.setTextAppearance(android.R.style.TextAppearance_Material_Medium);
    mLogView.setLayoutParams(logParams);
    mLogView.setClickable(true);//from   ww w .ja  va2s.  co m
    mLogView.setFocusable(true);
    mLogView.setTypeface(Typeface.create("monospace", Typeface.NORMAL));

    // Want to set padding as 16 dips, setPadding takes pixels.  Hooray math!
    int paddingDips = 16;
    double scale = getResources().getDisplayMetrics().density;
    int paddingPixels = (int) ((paddingDips * (scale)) + .5);
    mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
    mLogView.setCompoundDrawablePadding(paddingPixels);

    mLogView.setGravity(Gravity.BOTTOM);

    mScrollView.addView(mLogView);
    return mScrollView;
}

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;//from  www.  ja  v a2s.  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:app.philm.in.util.TypefaceManager.java

public Typeface getRobotoCondensed() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        return Typeface.create(ROBOTO_CONDENSED_NATIVE_FONT_FAMILY, Typeface.NORMAL);
    }//from  w  w w .  ja  va 2s  .  c  o m
    return getTypeface(ROBOTO_CONDENSED_FILENAME);
}

From source file:app.hacked.ChallengeDetailsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.challenge_details, null);

    ((TextView) view.findViewById(R.id.Title)).setTypeface(Typeface.create("sans-serif-thin", Typeface.NORMAL));
    ((TextView) view.findViewById(R.id.Title)).setText(Html.fromHtml(ChallengeTitle));

    ((TextView) view.findViewById(R.id.challengeDetails)).setText(Html.fromHtml(ChallengeDetails));
    return view;//from   w ww  .jav  a 2 s. com
}

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 {//ww w  .jav a 2  s . c o 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 Typeface getOrCreateTypeface(String family, int style) {
    FontDO fontDo = sCacheMap.get(family);
    if (fontDo != null && fontDo.getTypeface() != null) {
        return fontDo.getTypeface();
    }/*from   ww w .ja v a 2  s  .  c  o m*/

    return Typeface.create(family, style);
}

From source file:app.philm.in.util.TypefaceManager.java

public Typeface getRobotoCondensedBold() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        return Typeface.create(ROBOTO_CONDENSED_NATIVE_FONT_FAMILY, Typeface.BOLD);
    }//  www .  j a  v  a  2s  . c o m
    return getTypeface(ROBOTO_CONDENSED_BOLD_FILENAME);
}

From source file:com.mobisci_lab.virtualkeyboard.softkeyboard.LatinKeyboardView.java

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    TextPaint paint = new TextPaint();
    paint.setAntiAlias(true);/*from   ww  w.j a v a  2 s. c om*/
    paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
    paint.setTextSize(11 * getResources().getDisplayMetrics().density);
    paint.setColor(ContextCompat.getColor(this.getContext(), R.color.candidate_other));

    List<Key> keys = getKeyboard().getKeys();
    for (Key key : keys) {
        float x = key.x + key.width / 2 + key.width / 5;
        float y = key.y + key.width / 2;
        String text = "";
        switch (key.codes[0]) {
        case 113:
            text = "1";
            break;
        case 119:
            text = "2";
            break;
        case 101:
            text = "3";
            break;
        case 114:
            text = "4";
            break;
        case 116:
            text = "5";
            break;
        case 121:
            text = "6";
            break;
        case 117:
            text = "7";
            break;
        case 105:
            text = "8";
            break;
        case 111:
            text = "9";
            break;
        case 112:
            text = "0";
            break;

        }
        canvas.drawText(text, x, y, paint);
    }
}

From source file:app.hacked.AddProjectFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.add_project_fragment, null);

    ((TextView) view.findViewById(R.id.Title)).setTypeface(Typeface.create("sans-serif-thin", Typeface.NORMAL));

    ProjectNameET = (EditText) view.findViewById(R.id.ProjectNameET);
    SynopsisET = (EditText) view.findViewById(R.id.SynopsisET);
    DescET = (EditText) view.findViewById(R.id.DescET);
    TeamMemberET = (EditText) view.findViewById(R.id.TeamMemberET);
    TechET = (EditText) view.findViewById(R.id.ProjectNameET);

    ((Button) view.findViewById(R.id.CancelButton)).setOnClickListener(new View.OnClickListener() {
        @Override/*from w w w  . j a  va 2 s.c  o m*/
        public void onClick(View view) {
            getActivity().finish();
        }
    });

    ((Button) view.findViewById(R.id.addProjectButton)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (ProjectNameET.getText().toString().equals("")) {
                Toast.makeText(getActivity(), "A project needs a name for people to recognise!",
                        Toast.LENGTH_SHORT).show();
                return;
            }

            JSONObject post = new JSONObject();
            try {
                post.put("project_name", ProjectNameET.getText().toString());
                post.put("project_synopsis", SynopsisET.getText().toString());
                post.put("project_desc", DescET.getText().toString());
                post.put("project_team", TeamMemberET.getText().toString());
                post.put("project_tech", TechET.getText().toString());
                post.put("auth", API.md5(API.BETTER_THAN_NOTHING_STUFF_TO_PREVENT_INJECTION_ATTEMPTS
                        + ProjectNameET.getText().toString()));
            } catch (Exception e) {
                e.printStackTrace();
                Toast.makeText(getActivity(),
                        "An Error Was encountered parsing the entered details: " + e.getMessage(),
                        Toast.LENGTH_SHORT).show();
                return;
            }

            JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST,
                    "http://hackedioapp.networksaremadeofstring.co.uk/addproject.php", post,
                    new Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject response) {
                            Log.e("response", response.toString());
                            try {
                                if (response.has("success") && response.getBoolean("success")) {
                                    Toast.makeText(getActivity(), "Project added successfully!",
                                            Toast.LENGTH_SHORT).show();

                                    if (getActivity().findViewById(R.id.ProjectDetails) != null) {
                                        Bundle arguments = new Bundle();
                                        arguments.putInt(ProjectDetailsFragment.PROJECTID,
                                                response.getInt("uuid"));
                                        arguments.putString(ProjectDetailsFragment.NAME,
                                                ProjectNameET.getText().toString());
                                        arguments.putString(ProjectDetailsFragment.SYNOPSIS,
                                                SynopsisET.getText().toString());
                                        arguments.putString(ProjectDetailsFragment.DESCRIPTION,
                                                DescET.getText().toString());
                                        arguments.putString(ProjectDetailsFragment.TECHNOLOGIES,
                                                TechET.getText().toString());
                                        arguments.putInt(ProjectDetailsFragment.POPULARITY, 1);
                                        arguments.putString(ProjectDetailsFragment.TEAMMEMBERS,
                                                TeamMemberET.getText().toString());
                                        arguments.putBoolean(ProjectDetailsFragment.ARG_2PANE, true);

                                        ProjectDetailsFragment fragment = new ProjectDetailsFragment();
                                        fragment.setArguments(arguments);
                                        fragment.setHasOptionsMenu(true);
                                        getActivity().getSupportFragmentManager().beginTransaction()
                                                .replace(R.id.ProjectDetails, fragment).commit();
                                    } else {
                                        getActivity().finish();

                                        Intent detailIntent = new Intent(getActivity(),
                                                ProjectDetailsActivity.class);
                                        detailIntent.putExtra(ProjectDetailsFragment.PROJECTID,
                                                response.getInt("uuid"));
                                        detailIntent.putExtra(ProjectDetailsFragment.NAME,
                                                ProjectNameET.getText().toString());
                                        detailIntent.putExtra(ProjectDetailsFragment.SYNOPSIS,
                                                SynopsisET.getText().toString());
                                        detailIntent.putExtra(ProjectDetailsFragment.DESCRIPTION,
                                                DescET.getText().toString());
                                        detailIntent.putExtra(ProjectDetailsFragment.TECHNOLOGIES,
                                                TechET.getText().toString());
                                        detailIntent.putExtra(ProjectDetailsFragment.POPULARITY, 1);
                                        detailIntent.putExtra(ProjectDetailsFragment.TEAMMEMBERS,
                                                TeamMemberET.getText().toString());
                                        detailIntent.putExtra(ProjectDetailsFragment.ARG_2PANE, true);
                                        startActivity(detailIntent);
                                    }
                                } else {
                                    String error = "";
                                    if (response.has("error"))
                                        error = ": " + response.getString("error");

                                    Toast.makeText(getActivity(), "An Error Was encountered" + error,
                                            Toast.LENGTH_SHORT).show();
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                Toast.makeText(getActivity(), "An Error Was encountered: " + e.getMessage(),
                                        Toast.LENGTH_SHORT).show();
                            }

                        }
                    }, new Response.ErrorListener() {

                        @Override
                        public void onErrorResponse(VolleyError error) {
                            // TODO Auto-generated method stub
                            Toast.makeText(getActivity(), "An Error Was encountered: " + error.getMessage(),
                                    Toast.LENGTH_SHORT).show();
                        }
                    });

            queue.add(jsObjRequest);
        }
    });
    return view;
}

From source file:com.codetroopers.betterpickers.radialtimepicker.AmPmCirclesView.java

public void initialize(Context context, int amOrPm) {
    if (mIsInitialized) {
        Log.e(TAG, "AmPmCirclesView may only be initialized once.");
        return;/*from  w ww.  j a  v a 2s  . co  m*/
    }

    Resources res = context.getResources();
    mUnselectedColor = res.getColor(R.color.bpWhite);
    mSelectedColor = res.getColor(R.color.bpBlue);
    mAmPmTextColor = res.getColor(R.color.ampm_text_color);
    String typefaceFamily = res.getString(R.string.sans_serif);
    Typeface tf = Typeface.create(typefaceFamily, Typeface.NORMAL);
    mPaint.setTypeface(tf);
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Align.CENTER);

    mCircleRadiusMultiplier = Float.parseFloat(res.getString(R.string.circle_radius_multiplier));
    mAmPmCircleRadiusMultiplier = Float.parseFloat(res.getString(R.string.ampm_circle_radius_multiplier));
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    setAmOrPm(amOrPm);
    mAmOrPmPressed = -1;

    mIsInitialized = true;
}