Search in sources :

Example 56 with DisplayMetrics

use of android.util.DisplayMetrics in project XobotOS by xamarin.

the class ActivityThread method getTopLevelResources.

/**
     * Creates the top level Resources for applications with the given compatibility info.
     *
     * @param resDir the resource directory.
     * @param compInfo the compability info. It will use the default compatibility info when it's
     * null.
     */
Resources getTopLevelResources(String resDir, CompatibilityInfo compInfo) {
    ResourcesKey key = new ResourcesKey(resDir, compInfo.applicationScale);
    Resources r;
    synchronized (mPackages) {
        // Resources is app scale dependent.
        if (false) {
            Slog.w(TAG, "getTopLevelResources: " + resDir + " / " + compInfo.applicationScale);
        }
        WeakReference<Resources> wr = mActiveResources.get(key);
        r = wr != null ? wr.get() : null;
        //if (r != null) Slog.i(TAG, "isUpToDate " + resDir + ": " + r.getAssets().isUpToDate());
        if (r != null && r.getAssets().isUpToDate()) {
            if (false) {
                Slog.w(TAG, "Returning cached resources " + r + " " + resDir + ": appScale=" + r.getCompatibilityInfo().applicationScale);
            }
            return r;
        }
    }
    //if (r != null) {
    //    Slog.w(TAG, "Throwing away out-of-date resources!!!! "
    //            + r + " " + resDir);
    //}
    AssetManager assets = new AssetManager();
    if (assets.addAssetPath(resDir) == 0) {
        return null;
    }
    //Slog.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics);
    DisplayMetrics metrics = getDisplayMetricsLocked(null, false);
    r = new Resources(assets, metrics, getConfiguration(), compInfo);
    if (false) {
        Slog.i(TAG, "Created app resources " + resDir + " " + r + ": " + r.getConfiguration() + " appScale=" + r.getCompatibilityInfo().applicationScale);
    }
    synchronized (mPackages) {
        WeakReference<Resources> wr = mActiveResources.get(key);
        Resources existing = wr != null ? wr.get() : null;
        if (existing != null && existing.getAssets().isUpToDate()) {
            // Someone else already created the resources while we were
            // unlocked; go ahead and use theirs.
            r.getAssets().close();
            return existing;
        }
        // XXX need to remove entries when weak references go away
        mActiveResources.put(key, new WeakReference<Resources>(r));
        return r;
    }
}
Also used : AssetManager(android.content.res.AssetManager) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics)

Example 57 with DisplayMetrics

use of android.util.DisplayMetrics in project LookLook by xinghongfei.

the class DensityUtil method getDeviceInfo.

public static int[] getDeviceInfo(Context context) {
    if ((deviceWidthHeight[0] == 0) && (deviceWidthHeight[1] == 0)) {
        DisplayMetrics metrics = new DisplayMetrics();
        ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);
        deviceWidthHeight[0] = metrics.widthPixels;
        deviceWidthHeight[1] = metrics.heightPixels;
    }
    return deviceWidthHeight;
}
Also used : Activity(android.app.Activity) DisplayMetrics(android.util.DisplayMetrics)

Example 58 with DisplayMetrics

use of android.util.DisplayMetrics in project VitamioBundle by yixia.

the class Device method getScreenFeatures.

public static String getScreenFeatures(Context ctx) {
    StringBuilder sb = new StringBuilder();
    DisplayMetrics disp = ctx.getResources().getDisplayMetrics();
    sb.append(getPair("screen_density", "" + disp.density));
    sb.append(getPair("screen_density_dpi", "" + disp.densityDpi));
    sb.append(getPair("screen_height_pixels", "" + disp.heightPixels));
    sb.append(getPair("screen_width_pixels", "" + disp.widthPixels));
    sb.append(getPair("screen_scaled_density", "" + disp.scaledDensity));
    sb.append(getPair("screen_xdpi", "" + disp.xdpi));
    sb.append(getPair("screen_ydpi", "" + disp.ydpi));
    return sb.toString();
}
Also used : DisplayMetrics(android.util.DisplayMetrics)

Example 59 with DisplayMetrics

use of android.util.DisplayMetrics in project ZI by yixia.

the class DeviceUtils method getScreenWidth.

@SuppressWarnings("deprecation")
public static int getScreenWidth(Activity ctx) {
    int width;
    Display display = ctx.getWindowManager().getDefaultDisplay();
    if (UIUtils.hasJellyBeanMR1()) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        display.getRealMetrics(displayMetrics);
        width = displayMetrics.widthPixels;
    } else {
        try {
            Method mGetRawW = Display.class.getMethod("getRawWidth");
            width = (Integer) mGetRawW.invoke(display);
        } catch (Exception e) {
            width = display.getWidth();
        }
    }
    return width;
}
Also used : Method(java.lang.reflect.Method) DisplayMetrics(android.util.DisplayMetrics) SuppressLint(android.annotation.SuppressLint) Display(android.view.Display)

Example 60 with DisplayMetrics

use of android.util.DisplayMetrics in project ZI by yixia.

the class DeviceUtils method getScreenPhysicalSize.

public static double getScreenPhysicalSize(Activity ctx) {
    DisplayMetrics dm = new DisplayMetrics();
    ctx.getWindowManager().getDefaultDisplay().getMetrics(dm);
    double diagonalPixels = Math.sqrt(Math.pow(dm.widthPixels, 2) + Math.pow(dm.heightPixels, 2));
    return diagonalPixels / (160 * dm.density);
}
Also used : DisplayMetrics(android.util.DisplayMetrics)

Aggregations

DisplayMetrics (android.util.DisplayMetrics)772 WindowManager (android.view.WindowManager)107 Resources (android.content.res.Resources)99 Display (android.view.Display)78 Configuration (android.content.res.Configuration)61 Point (android.graphics.Point)57 View (android.view.View)52 SuppressLint (android.annotation.SuppressLint)47 Bitmap (android.graphics.Bitmap)42 Paint (android.graphics.Paint)42 Activity (android.app.Activity)32 ImageView (android.widget.ImageView)27 AssetManager (android.content.res.AssetManager)25 TypedArray (android.content.res.TypedArray)25 Context (android.content.Context)23 TypedValue (android.util.TypedValue)23 ViewGroup (android.view.ViewGroup)23 TextView (android.widget.TextView)22 Intent (android.content.Intent)21 RelativeLayout (android.widget.RelativeLayout)20