Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Zirco Browser for Android
 * 
 * Copyright (C) 2010 J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

import android.app.Activity;

import android.util.DisplayMetrics;

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

    public static int getImageButtonSize(Activity activity) {
        if (mImageButtonSize == -1) {
            DisplayMetrics metrics = new DisplayMetrics();
            activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

            switch (metrics.densityDpi) {
            case DisplayMetrics.DENSITY_LOW:
                mImageButtonSize = 16;
                break;
            case DisplayMetrics.DENSITY_MEDIUM:
                mImageButtonSize = 32;
                break;
            case DisplayMetrics.DENSITY_HIGH:
                mImageButtonSize = 48;
                break;
            default:
                mImageButtonSize = 32;
            }
        }

        return mImageButtonSize;
    }
}