Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;
import android.content.res.Resources;

import android.util.TypedValue;

public class Main {
    /**
     * This method converts dp to pixels
     *
     * @param dp
     *         Oiringla dp
     * @param context
     *         App context
     *
     * @return Dp value in pixels
     */
    public static int dp2Pixels(int dp, Context context) {
        Resources r = context.getResources();
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
    }
}