All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.devnied.emvnfccard.utils.ViewUtils Maven / Gradle / Ivy

There is a newer version: 2.1.1
Show newest version
package com.github.devnied.emvnfccard.utils;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.DisplayMetrics;
import android.widget.TextView;

/**
 * Utils class used to manager view
 * 
 * @author Millau Julien
 * 
 */
public final class ViewUtils {

	/**
	 * Apply typeFace to all view
	 * 
	 * @param pTypeFace
	 *            the type face to apply
	 * @param pViews
	 *            all view to apply typeface
	 */
	public static void setTypeFace(final Typeface pTypeFace, final TextView... pViews) {
		for (TextView view : pViews) {
			view.setTypeface(pTypeFace);
			view.setPaintFlags(view.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
		}
	}

	/**
	 * This method converts dp unit to equivalent pixels, depending on device density.
	 * 
	 * @param dp
	 *            A value in dp (density independent pixels) unit. Which we need to convert into pixels
	 * @param context
	 *            Context to get resources and device specific display metrics
	 * @return A float value to represent px equivalent to dp depending on device density
	 */
	public static float convertDpToPixel(final float dp, final Context context) {
		Resources resources = context.getResources();
		DisplayMetrics metrics = resources.getDisplayMetrics();
		float px = dp * (metrics.densityDpi / 160f);
		return px;
	}

	/**
	 * Private constructor
	 */
	private ViewUtils() {
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy