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.graphics.Point;

import android.view.WindowManager;

public class Main {
    private static int screenWidth = -1;

    public static int getScreenWidth(Context context) {
        if (screenWidth != -1) {
            return screenWidth;
        }

        Point size = new Point();
        ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getSize(size);

        screenWidth = size.x;
        return screenWidth;
    }
}