Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.Context;

public class Main {
    /**
     * convert hardcoded density independent pixel value into a raw pixel value
     * @param dps an int specifying number of dps
     * @param context the context in which to calculate the correct number of pixels
     * @return number of pixels for the specified dps value
     */
    public static int dpToPixels(int dps, Context context) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dps * scale + 0.5f);
    }
}