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.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Point;
import android.os.Build.VERSION;
import android.view.WindowManager;

public class Main {
    /**
     * Get the size of the Display.
     * @param context
     * @return Point
     */
    @SuppressWarnings("deprecation")
    @SuppressLint("NewApi")
    public static Point getScreenSize(Context context) {
        Point p = new Point();
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        if (VERSION.SDK_INT >= 13) {
            windowManager.getDefaultDisplay().getSize(p);
        } else {
            p.x = windowManager.getDefaultDisplay().getWidth();
            p.y = windowManager.getDefaultDisplay().getHeight();
        }
        return p;
    }
}