Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.util.DisplayMetrics;

import android.view.WindowManager;

public class Main {
    public static int convertDpToPixels(WindowManager windowManager, float dp) {
        DisplayMetrics metrics = new DisplayMetrics();
        windowManager.getDefaultDisplay().getMetrics(metrics);
        float logicalDensity = metrics.density;

        return (int) (dp * logicalDensity + 0.5);
    }
}