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.view.Display;

public class Main {
    /**
     * Get current {@link Activity} screen width.
     * 
     * @param activity Object of {@link Activity}
     * @return Screen width, failed will return 0.
     */
    public final static int getScreenWidth(Activity activity) {
        if (null == activity) {
            return 0;
        }

        try {
            Display d = activity.getWindowManager().getDefaultDisplay();
            return d.getWidth();
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
}