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:app.hacked.ScheduleItemDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.schedule_detail_fragment, container, false);

    ((TextView) rootView.findViewById(R.id.times)).setText(scheduleStartTime + " till " + scheduleEndTime);
    ((TextView) rootView.findViewById(R.id.times))
            .setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));

    if (rootView.findViewById(R.id.Title) != null) {
        ((TextView) rootView.findViewById(R.id.Title)).setText(scheduleDesc);
        ((TextView) rootView.findViewById(R.id.Title))
                .setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));
        ((TextView) rootView.findViewById(R.id.times))
                .setTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL));
        getActivity().getActionBar()//from w  ww  .jav  a2 s.co m
                .setTitle(scheduleTitle + " - " + getActivity().getString(R.string.app_name));
    }

    TextView fullDetailsTV = (TextView) rootView.findViewById(R.id.fullDetails);

    if (null == scheduleFullDataHTML || scheduleFullDataHTML.equals("")
            || scheduleFullDataHTML.equals("null")) {
        fullDetailsTV.setText(Html.fromHtml(scheduleDesc));
    } else {
        fullDetailsTV.setText(Html.fromHtml(scheduleFullDataHTML));
    }
    fullDetailsTV.setTypeface(Typeface.create("sans-serif", Typeface.NORMAL));

    try {
        fullDetailsTV.setMovementMethod(LinkMovementMethod.getInstance());
    } catch (Exception e) {
        //Worth a shot
    }
    return rootView;
}

From source file:ru.tinkoff.acquiring.sdk.views.KeyView.java

private void applyAttrs(AttributeSet attrs) {
    if (attrs == null) {
        return;/*from w w w.j  av a  2 s  .c o  m*/
    }

    final TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.KeyView, 0, 0);

    try {
        keyCode = a.getInt(R.styleable.KeyView_keyCode, -1);

        final float textSize = a.getDimension(R.styleable.KeyView_keyTextSize, -1.F);
        if (textSize != -1.F) {
            contentPaint.setTextSize(dpToPx(textSize));
        }

        final String fontFamily = a.getString(R.styleable.KeyView_keyTextFontFamily);
        if (fontFamily != null) {
            contentPaint.setTypeface(Typeface.create(fontFamily, Typeface.NORMAL));
        }

        contentText = a.getString(R.styleable.KeyView_keyText);
        if (contentText != null) {
            textWidth = contentPaint.measureText(contentText);
        }

        final int imageDrawableId = a.getResourceId(R.styleable.KeyView_keyImage, -1);
        if (imageDrawableId != -1) {
            contentImage = BitmapFactory.decodeResource(getResources(), imageDrawableId);
        }

        final int textColor = a.getColor(R.styleable.KeyView_keyTextColor, contentPaint.getColor());
        contentPaint.setColor(textColor);

        final int circleColor = a.getColor(R.styleable.KeyView_keyCircleColor, circlePaint.getColor());
        circlePaint.setColor(circleColor);
    } finally {
        a.recycle();
    }
}

From source file:com.amazonaws.mobile.auth.userpools.SignUpView.java

/**
 * Constructs the SignUp View.//from  w w  w.j a  v  a 2  s  . c  o m
 * @param context The activity context.
 * @param attrs The Attribute Set for the view from which the resources can be accessed.
 * @param defStyleAttr The resource identifier for the default style attribute.
 */
public SignUpView(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setOrientation(VERTICAL);

    final int backgroundColor;
    if (isInEditMode()) {
        backgroundColor = Color.DKGRAY;
    } else {
        final TypedArray styledAttributes = context.obtainStyledAttributes(attrs, R.styleable.SignUpView);
        backgroundColor = styledAttributes.getInt(R.styleable.SignUpView_signUpViewBackgroundColor,
                Color.DKGRAY);
        styledAttributes.recycle();
    }

    this.fontFamily = CognitoUserPoolsSignInProvider.getFontFamily();
    this.typeFace = Typeface.create(this.fontFamily, Typeface.NORMAL);
    this.fullScreenBackgroundColor = CognitoUserPoolsSignInProvider.isBackgroundColorFullScreen();
    this.backgroundColor = CognitoUserPoolsSignInProvider.getBackgroundColor();

    if (this.fullScreenBackgroundColor) {
        this.backgroundDrawable = new BackgroundDrawable(this.backgroundColor);
    } else {
        this.splitBackgroundDrawable = new SplitBackgroundDrawable(0, this.backgroundColor);
    }
}

From source file:com.layer_net.stepindicator.StepIndicator.java

private void init(Context context, AttributeSet attributeSet) {

    initAttributes(context, attributeSet);

    paint = new Paint();
    pStoke = new Paint();
    pText = new Paint();
    paint.setColor(stepColor);//  w  w  w . j a  v a2s .  c  om
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setStrokeWidth(lineWidth);
    pStoke.setColor(stepColor);
    pStoke.setStrokeWidth(strokeWidth);
    pStoke.setStyle(Paint.Style.STROKE);
    pStoke.setFlags(Paint.ANTI_ALIAS_FLAG);
    pText.setColor(textColor);
    pText.setTextSize(radius);
    pText.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
    pText.setTextAlign(Paint.Align.CENTER);
    pText.setFlags(Paint.ANTI_ALIAS_FLAG);
    setMinimumHeight(radius * 3);
    Color.colorToHSV(currentColor, hsvCurrent);
    Color.colorToHSV(backgroundColor, hsvBG);
    Color.colorToHSV(stepColor, hsvProgress);
    invalidate();
}

From source file:com.grarak.kerneladiutor.elements.SplashView.java

private void draw(Canvas canvas, int x, int y, int radius) {
    if (radius > 0)
        canvas.drawCircle(x / 2, y / 2, radius, mPaintCircle);
    matrix.postRotate(rotate);/*from w w  w  . jav  a 2 s . c  o m*/
    Bitmap iconRotate = Bitmap.createBitmap(icon, 0, 0, icon.getWidth(), icon.getHeight(), matrix, false);
    canvas.drawBitmap(iconRotate, x / 2 - iconRotate.getWidth() / 2, y / 2 - iconRotate.getHeight() / 2,
            mPaintCircle);

    TextPaint textPaint = new TextPaint();
    textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
    textPaint.setColor(textColor);
    textPaint.setAntiAlias(true);
    textPaint.setTextAlign(Paint.Align.CENTER);
    textPaint.setTextSize(textSize);
    float textHeight = textPaint.descent() - textPaint.ascent();
    float textOffset = (textHeight / 2) - textPaint.descent();

    canvas.drawText(getResources().getString(R.string.root_waiting), x / 2, y - textOffset - y / 4, textPaint);
}

From source file:app.hacked.ProjectDetailsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.project_detail_fragment, container, false);

    ((TextView) rootView.findViewById(R.id.Title)).setText(Name);
    ((TextView) rootView.findViewById(R.id.Title))
            .setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));

    /*((TextView) rootView.findViewById(R.id.TeamMembers)).setText(TeamMembers);
    ((TextView) rootView.findViewById(R.id.TeamMembers)).setTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL));*/

    ((TextView) rootView.findViewById(R.id.Tech)).setText(Technologies);
    ((TextView) rootView.findViewById(R.id.Tech))
            .setTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL));

    ((TextView) rootView.findViewById(R.id.Description)).setText(Html.fromHtml(Description));
    ((TextView) rootView.findViewById(R.id.Description))
            .setTypeface(Typeface.create("sans-serif", Typeface.NORMAL));

    ((Button) rootView.findViewById(R.id.VoteUp)).setOnClickListener(new View.OnClickListener() {
        @Override// www. j a  v  a  2 s.co  m
        public void onClick(View view) {
            doVote(true);
        }
    });

    ((Button) rootView.findViewById(R.id.VoteDown)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            doVote(false);
        }
    });

    ((Button) rootView.findViewById(R.id.EditProject)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("https://www.hackerleague.org/hackathons/hacked/hacks")));
        }
    });

    return rootView;
}

From source file:com.mehdi.graphview.custom.SimpleLineGraph.java

@Override
public void onFinished(TickerList tickerList) {

    if (null == tickerList) {
        return;/*ww  w . j a  va  2s .  c  om*/
    }

    GraphView graphView = (GraphView) rootView.findViewById(R.id.graph);
    LineGraphSeries<DataPoint> series = new LineGraphSeries<>();

    ArrayList<Tickers> tickers = tickerList.tickers;
    ArrayList<DataPoint> dataPointArrayList = new ArrayList<>();
    for (int i = 0; i < tickers.get(0).historical.size(); i++) {
        dataPointArrayList.add(new DataPoint(i,
                //Double.parseDouble(String.valueOf(tickers.get(0).historical.get(i).get(0))),
                Double.parseDouble(String.valueOf(tickers.get(0).historical.get(i).get(1)))));
    }

    DataPoint[] dataPoints = dataPointArrayList.toArray(new DataPoint[dataPointArrayList.size()]);

    series.resetData(dataPoints);
    graphView.addSeries(series);

    // set manual X bounds
    graphView.getViewport().setXAxisBoundsManual(true);
    graphView.getViewport().setMinX(0);
    graphView.getViewport().setMaxX(series.getHighestValueX());

    // set manual Y bounds
    graphView.getViewport().setYAxisBoundsManual(true);
    graphView.getViewport().setMinY(series.getLowestValueY());
    graphView.getViewport().setMaxY(series.getHighestValueY());

    graphView.getViewport().setScrollable(false);

    StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graphView);

    // set xLabels values
    int middleIndex = tickers.get(0).historical.size() / 2;
    staticLabelsFormatter.setHorizontalLabels(new String[] {
            getHourMinute(String.valueOf(tickers.get(0).historical.get(0).get(0))), "",
            getHourMinute(String.valueOf(tickers.get(0).historical.get(middleIndex).get(0))), "",
            getHourMinute(String
                    .valueOf(tickers.get(0).historical.get(tickers.get(0).historical.size() - 1).get(0))) });

    staticLabelsFormatter.setVerticalLabels(new String[] { "", "", "" });

    graphView.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
    //        graphView.getGridLabelRenderer().setTextSize(35);
    //        graphView.getGridLabelRenderer().setTextSize(25);
    float spToFloat = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 25,
            graphView.getContext().getResources().getDisplayMetrics());
    graphView.getGridLabelRenderer().setTextSize(spToFloat);

    // setting label typeface
    if (null != getContext()) {
        Typeface plain = Typeface.createFromAsset(getContext().getAssets(),
                "SouthernAire_Personal_Use_Only.ttf");
        Typeface typeface = Typeface.create(plain, Typeface.BOLD_ITALIC);
        graphView.getGridLabelRenderer().setLabelTypeface(typeface);
    }

    // set second scale. This one is used to show the vertical labels
    // on the right side as per UI Spec.
    graphView.getSecondScale().setMinY(getMinimumValue(tickers.get(0).historical));
    graphView.getSecondScale().setMaxY(getMaximumValue(tickers.get(0).historical));
    graphView.getGridLabelRenderer().setVerticalLabelsSecondScaleAlign(Paint.Align.CENTER);

    if (null != getContext()) {
        int colorStockLabelGray = Color.GRAY;
        graphView.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(colorStockLabelGray);
        graphView.getGridLabelRenderer().setHorizontalLabelsColor(colorStockLabelGray);
        graphView.getGridLabelRenderer().setGridColor(colorStockLabelGray);
    }

    graphView.getGridLabelRenderer().setHighlightZeroLines(false);
    graphView.getGridLabelRenderer().setGridStyle(GridLabelRenderer.GridStyle.VERTICAL);
    graphView.getGridLabelRenderer().reloadStyles();
    //series.setColor(Color.GREEN);
    series.setColor(Color.WHITE);
}

From source file:com.d2connect.droidltest.util.LPreviewUtilsImpl.java

@Override
public void setMediumTypeface(TextView textView) {
    if (sMediumTypeface == null) {
        sMediumTypeface = Typeface.create("sans-serif-medium", Typeface.NORMAL);
    }/*from   www  . ja v a2 s  . c o  m*/

    textView.setTypeface(sMediumTypeface);
}

From source file:com.tr4android.support.extension.typeface.TypefaceCompat.java

/**
 * Creates a typeface object that best matches the specified typeface and the specified style.
 * Use this call if you want to pick a new style from the same family of an typeface object.
 * If family is null, this selects from the default font's family.
 *
 * @param ctx        A context./*from   w w  w  .  ja  v  a  2  s  . co  m*/
 * @param familyName May be null. The name of the font family.
 * @param style      The style (normal, bold, italic) of the typeface, e.g. NORMAL, BOLD, ITALIC, BOLD_ITALIC.
 * @return The best matching typeface.
 * @since 0.1.1
 * @deprecated
 */
@Deprecated
public static Typeface create(Context ctx, String familyName, int style) {
    if (!mInitialized)
        initialize();
    if (isSupported(familyName) || familyName == null) {
        boolean styleAfterwards = false;
        String fileName = FONT_FAMILY_FILE_PREFIX.get(familyName == null ? "sans-serif" : familyName);
        if (fileName.endsWith("-")) {
            // All styles are supported.
            fileName += STYLE_SUFFIX[style];
        } else {
            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:io.coldstart.android.TrapListFragment.java

@Override
public void onStart() {
    super.onStart();

    try {// w w w. java2  s  .c o  m
        if (listOfTraps.size() == 0) {
            getActivity().findViewById(R.id.noTrapsMessage).setVisibility(View.VISIBLE);
            ((TextView) getActivity().findViewById(R.id.noTrapsMessage))
                    .setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));
        } else {
            getActivity().findViewById(R.id.noTrapsMessage).setVisibility(View.GONE);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}