Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Method;
import android.annotation.SuppressLint;
import android.content.Context;

import android.graphics.Point;
import android.os.Build;

import android.util.DisplayMetrics;

import android.view.Display;

import android.view.WindowManager;

public class Main {
    @SuppressWarnings("deprecation")
    @SuppressLint("NewApi")
    public static Point getFullDisplaySize(Context context) {
        Point point = new Point();

        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

        Display display = wm.getDefaultDisplay();
        Method mGetRawH = null, mGetRawW = null;

        DisplayMetrics outMetrics = new DisplayMetrics();
        display.getMetrics(outMetrics);

        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
            display.getRealMetrics(outMetrics);
            point.x = outMetrics.widthPixels;
            point.y = outMetrics.heightPixels;
        } else {
            try {
                mGetRawH = Display.class.getMethod("getRawHeight");
                mGetRawW = Display.class.getMethod("getRawWidth");
                point.x = (Integer) mGetRawW.invoke(display);
                point.y = (Integer) mGetRawH.invoke(display);
            } catch (Exception e) {
                display.getMetrics(outMetrics);
                point.x = display.getWidth();
                point.y = display.getHeight();
                e.printStackTrace();
            }
        }

        return point;
    }
}