get Screen Rate - Android Phone

Android examples for Phone:Screen

Description

get Screen Rate

Demo Code


//package com.java2s;

import android.content.Context;

import android.view.Display;
import android.view.WindowManager;

public class Main {
    public static double getScreenRate(Context context) {
        return (getScreenHeight(context) + 0.00f)
                / (getScreenWidth(context) + 0.00f);
    }/*from  w  w  w.  ja  va2s.co  m*/

    public static int getScreenHeight(Context context) {
        if (context == null) {
            return 800;
        }
        Display display = ((WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();
        int h = display.getHeight();
        return h;
    }

    public static int getScreenWidth(Context context) {
        if (context == null) {
            return 0;
        }
        Display display = ((WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();
        int w = display.getWidth();
        return w;
    }
}

Related Tutorials