Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.graphics.Point;

import android.os.Build;

import android.util.DisplayMetrics;
import android.view.Display;

import android.view.WindowManager;

public class Main {
    /**
     * <p>
     * This method takes in the WindowManager and returns the Screen Dimensions in pixels.</br></br>
     * </p>
     * <p>To get width (getWindowDisplaySize(wm).x) or height (getWindowDisplaySize(wm).y)</p>
     *
     * @return WindowDisplaySize
     */
    public static Point getWindowDisplaySize(WindowManager wm) {
        Display display;
        Point WindowDisplaySize = new Point();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            display = wm.getDefaultDisplay();
            display.getSize(WindowDisplaySize);
        } else {
            DisplayMetrics displaymetrics = new DisplayMetrics();
            wm.getDefaultDisplay().getMetrics(displaymetrics);
            int height = displaymetrics.heightPixels;
            int width = displaymetrics.widthPixels;
            WindowDisplaySize.set(width, height);
        }
        return WindowDisplaySize;
    }
}