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 android.app.Activity;
import android.content.Context;

import android.graphics.Point;

import android.view.WindowManager;

public class Main {
    /**
     * Gets device's display resolution.
     * @since   0.1.0
     * @param   aContext The context from which the system service is retrieved to get the window's information.
     * @return   The struct of Point with x attribute contains the width and y attribute contains the height.
     */
    public static Point getDisplayResolution(Context aContext) {
        WindowManager wm = (WindowManager) (aContext.getSystemService(Context.WINDOW_SERVICE));
        Point p = new Point();
        wm.getDefaultDisplay().getSize(p);
        return p;
    }

    /**
     * Gets device's display resolution.
     * @since   0.1.0
     * @param   aActivity The activity from which the window's information is retrieved.
     * @return   The struct of Point with x attribute contains the width and y attribute contains the height.
     */
    public static Point getDisplayResolution(Activity aActivity) {
        Point p = new Point();
        aActivity.getWindowManager().getDefaultDisplay().getSize(p);
        return p;
    }
}