Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.app.Activity;
import android.util.DisplayMetrics;

public class Main {
    private static final int BASE = 720;
    private static int mWidthPixels = -1;
    private static int mHeightPixels = -1;

    public static int adjust(Activity activity, int length) {
        return getWindowWidth(activity) * length / BASE;
    }

    public static int getWindowWidth(Activity activity) {
        if (mWidthPixels < 0) {
            DisplayMetrics dm = new DisplayMetrics();
            activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
            mWidthPixels = dm.widthPixels;
            mHeightPixels = dm.heightPixels;
        }
        return mWidthPixels;
    }
}