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 mFaviconSize = -1;

    /**
     * Get the required size of the favicon, depending on current screen density.
     * @param activity The current activity.
     * @return The size of the favicon, in pixels.
     */
    public static int getFaviconSize(Activity activity) {
        if (mFaviconSize == -1) {
            DisplayMetrics metrics = new DisplayMetrics();
            activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

            switch (metrics.densityDpi) {
            case DisplayMetrics.DENSITY_LOW:
                mFaviconSize = 12;
                break;
            case DisplayMetrics.DENSITY_MEDIUM:
                mFaviconSize = 24;
                break;
            case DisplayMetrics.DENSITY_HIGH:
                mFaviconSize = 32;
                break;
            default:
                mFaviconSize = 24;
            }
        }

        return mFaviconSize;
    }
}