Code example for Typeface

Methods: setTypeface

0
 
	public static Typeface getTypeface(Context context, String typeface) {
		Typeface font = typefaceMap.get(typeface);
		if (font == null) {
			font = Typeface.createFromAsset(context.getAssets(), typeface);
			typefaceMap.put(typeface, font);
		} 
        return font; 
	} 
	 
	/** 
	 * Changes the size dimension to fit within the width/height ratio 
	 */ 
	public static void contain(Dimension size, int width, int height) {
		 
		if (width == 0 || height == 0) {
			size.setWidth(0);
			size.setHeight(0);
			return; 
		} 
 
		double ratio = size.getWidth()/(double)size.getHeight();
		 
		if (size.getWidth() < size.getHeight()) {
			size.setHeight(height);
			size.setWidth((int)(height * ratio));
			 
			if (size.getWidth() > width) {
				size.setWidth(width);
				size.setHeight((int)(width/ratio));
			} 
		} else { 
			size.setWidth(width);
			size.setHeight((int)(width / ratio));
			 
			if (size.getHeight() > height) {
				size.setHeight(height);
				size.setWidth((int)(height*ratio));
			} 
		} 
	} 
 
	/** 
	 * Recursively set the font on all text views on this root 
	 */ 
	public static void setFont(View view, Typeface font) {
		 
		if (view == null) {
			return; 
		} 
		 
		if (view instanceof ViewGroup) {
			for (int i = 0, lim = ((ViewGroup)view).getChildCount(); i < lim; i++) {
				setFont(((ViewGroup)view).getChildAt(i), font);
			} 
			return; 
		} 
		 
		if (view instanceof TextView) {
			((TextView)view).setTypeface(font);
		} 
	}	 
 
	/** 
	 * Convenience method to show a loading dialog with message 
	 */ 
	public static ProgressDialog showProgressDialog(Context context, String message) {
		return ProgressDialog.show(context, null, message, true);
	} 
 
	/** 
	 * Set the font on this specific view 
	 */ 
	public void setFont(Context context, TextView view, String font) {
		Typeface typeface = UIUtil.getTypeface(context, font);
		view.setTypeface(typeface);
	} 
 
	/** 
	 * Set the font on the specific textview with the given ID 
	 */ 
Experience pair programming with AI  Get Codota for Java