Code example for Context

Methods: getResources

	 * Convert from device-independent-pixels to pixels for use in custom view drawing, as 
	 * used throughout Android.  
	 * See: (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);
Stop searching for code, let great code find you!  Add Codota to your java IDE