Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.app.Activity;

import android.content.res.Resources;

import android.util.TypedValue;
import android.view.View;

public class Main {
    /**
     * Converts density independent pixel to real screen pixel. 160 dip = 1 inch
     * ~ 2.5 cm
     * 
     * @param dipValue
     *            dip
     * @return pixel
     */
    public static int getPixels(Resources r, double dipValue) {
        int dValue = (int) dipValue;
        int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dValue, r.getDisplayMetrics());
        return px;
    }

    public static int getPixels(View v, double dipValue) {
        return getPixels(v.getResources(), dipValue);
    }

    public static int getPixels(Activity v, double dipValue) {
        return getPixels(v.getResources(), dipValue);
    }
}