Java tutorial
//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 mFaviconSizeForBookmarks = -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 getFaviconSizeForBookmarks(Activity activity) { if (mFaviconSizeForBookmarks == -1) { DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); switch (metrics.densityDpi) { case DisplayMetrics.DENSITY_LOW: mFaviconSizeForBookmarks = 12; break; case DisplayMetrics.DENSITY_MEDIUM: mFaviconSizeForBookmarks = 16; break; case DisplayMetrics.DENSITY_HIGH: mFaviconSizeForBookmarks = 24; break; default: mFaviconSizeForBookmarks = 16; } } return mFaviconSizeForBookmarks; } }