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;
}
}
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;
}
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();
}
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;
}
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);
}
Aggregations