/* Copyright (c) 2009 Matthias Käppler
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.droidfu.support;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;

public class DisplaySupport {

    private static DisplayMetrics displayMetrics;

    public static int dipToPx(Activity context, int dip) {
        if (displayMetrics == null) {
            displayMetrics = new DisplayMetrics();
            context.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        }
        return (int) (dip * displayMetrics.density + 0.5f);
    }

    public static Drawable scaleDrawable(Context context, int drawableResourceId, int width,
            int height) {
        Bitmap sourceBitmap = BitmapFactory.decodeResource(context.getResources(),
            drawableResourceId);
        return new BitmapDrawable(Bitmap.createScaledBitmap(sourceBitmap, width, height, true));
    }

}
@@ -933,22 +933,21 @@
    p
-rivate
+ublic
  static 
 Disp
@@ -946,37 +946,200 @@
 tic 
-DisplayMetrics displayMetrics
+final int SCREEN_DENSITY_LOW = 120;%0A    public static final int SCREEN_DENSITY_MEDIUM = 160;%0A    public static final int SCREEN_DENSITY_HIGH = 240;%0A%0A    private static float screenDensity = -1
 ;%0A%0A 
@@ -1208,13 +1208,9 @@
     
-if (d
+D
 ispl
@@ -1223,141 +1223,52 @@
 ics 
-== null) %7B%0A            displayMetrics = new DisplayMetrics();%0A            context.getWindowManager().getDefaultDisplay().getMetrics(d
+displayMetrics = context.getResources().getD
 ispl
@@ -1280,21 +1280,12 @@
 rics
+(
 );%0A
-        %7D%0A
     
@@ -1686,9 +1686,463 @@
 %0A    %7D%0A%0A
+    public static float getScreenDensity(Context context) %7B%0A        if (screenDensity == -1) %7B%0A            DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();%0A            try %7B%0A                screenDensity = DisplayMetrics.class.getField(%22densityDpi%22).getFloat(displayMetrics);%0A            %7D catch (Exception e) %7B%0A                screenDensity = SCREEN_DENSITY_MEDIUM;%0A            %7D%0A        %7D%0A        return screenDensity;%0A    %7D%0A
 %7D

include platform-safe call to get current screen density