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.util.DisplayMetrics;

public class Main {
    /**
     * Get the display size in inches.
     * @return the value in inches
     */
    public static double getDisplaySizeInches(Context context) {
        DisplayMetrics dm = context.getResources().getDisplayMetrics();

        double x = Math.pow((double) dm.widthPixels / (double) dm.densityDpi, 2);
        double y = Math.pow((double) dm.heightPixels / (double) dm.densityDpi, 2);

        return Math.sqrt(x + y);
    }
}