Code example for Context

Methods: getResources

0
	 * Convert from device-independent-pixels to pixels for use in custom view drawing, as 
	 * used throughout Android.  
	 * See: http://bit.ly/MfsAUZ (Romain Guy's comment)   
	 */ 
	public static int convertDPsToPixels(Context context, final int dps) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dps * scale + 0.5f);
	} 
 
    /** 
     * Sets the alpha of a view in a manner that is safe to use before API version 11. 
     * If alpha isn't supported, just make the view invisible if the alpha is so low 
     * that it may as well be. 
     */ 
    public static void setViewAlpha(View v, float alpha) {
        v.setVisibility((alpha > 0.001) ? View.VISIBLE : View.INVISIBLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            v.setAlpha(alpha);
        } 
    } 
Experience pair programming with AI  Get Codota for Java