use of android.view.Display in project facebook-android-sdk by facebook.
the class Utility method setAppEventExtendedDeviceInfoParameters.
public static void setAppEventExtendedDeviceInfoParameters(JSONObject params, Context appContext) throws JSONException {
JSONArray extraInfoArray = new JSONArray();
extraInfoArray.put(EXTRA_APP_EVENTS_INFO_FORMAT_VERSION);
Utility.refreshPeriodicExtendedDeviceInfo(appContext);
// Application Manifest info:
String pkgName = appContext.getPackageName();
int versionCode = -1;
String versionName = "";
try {
PackageInfo pi = appContext.getPackageManager().getPackageInfo(pkgName, 0);
versionCode = pi.versionCode;
versionName = pi.versionName;
} catch (PackageManager.NameNotFoundException e) {
// Swallow
}
// Application Manifest info:
extraInfoArray.put(pkgName);
extraInfoArray.put(versionCode);
extraInfoArray.put(versionName);
// OS/Device info
extraInfoArray.put(Build.VERSION.RELEASE);
extraInfoArray.put(Build.MODEL);
// Locale
Locale locale;
try {
locale = appContext.getResources().getConfiguration().locale;
} catch (Exception e) {
locale = Locale.getDefault();
}
extraInfoArray.put(locale.getLanguage() + "_" + locale.getCountry());
// Time zone
extraInfoArray.put(deviceTimezoneAbbreviation);
// Carrier
extraInfoArray.put(carrierName);
// Screen dimensions
int width = 0;
int height = 0;
double density = 0;
try {
WindowManager wm = (WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE);
if (wm != null) {
Display display = wm.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);
width = displayMetrics.widthPixels;
height = displayMetrics.heightPixels;
density = displayMetrics.density;
}
} catch (Exception e) {
// Swallow
}
extraInfoArray.put(width);
extraInfoArray.put(height);
extraInfoArray.put(String.format("%.2f", density));
// CPU Cores
extraInfoArray.put(refreshBestGuessNumberOfCPUCores());
// External Storage
extraInfoArray.put(totalExternalStorageGB);
extraInfoArray.put(availableExternalStorageGB);
extraInfoArray.put(deviceTimeZoneName);
params.put("extinfo", extraInfoArray.toString());
}
use of android.view.Display in project fresco by facebook.
the class MainActivity method getDisplayHeight.
/**
* Determines display's height.
*/
public int getDisplayHeight() {
Display display = getWindowManager().getDefaultDisplay();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
return display.getHeight();
} else {
final Point size = new Point();
display.getSize(size);
return size.y;
}
}
use of android.view.Display in project NoHttp by yanzhenjie.
the class DisplayUtils method initScreen.
/**
* 初始化屏幕宽度和高度
*/
public static void initScreen(Activity activity) {
if (isInitialize)
return;
isInitialize = true;
Display display = activity.getWindowManager().getDefaultDisplay();
DisplayMetrics metric = new DisplayMetrics();
// 屏幕宽度、高度、密度、缩放因子
if (VERSION.SDK_INT >= 17) {
display.getRealMetrics(metric);
} else {
try {
Class<?> clazz = Class.forName("android.view.Display");
Method method = clazz.getMethod("getRealMetrics", DisplayMetrics.class);
method.invoke(display, metric);
} catch (Throwable e) {
display.getMetrics(metric);
}
}
try {
// 状态栏高度
Class<?> clazz = Class.forName("com.android.internal.R$dimen");
Field field = clazz.getField("status_bar_height");
int x = Integer.parseInt(field.get(clazz.newInstance()).toString());
statusBarHeight = activity.getResources().getDimensionPixelSize(x);
} catch (Throwable e) {
e.printStackTrace();
Rect outRect = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect);
statusBarHeight = outRect.top;
}
screenWidth = metric.widthPixels;
screenHeight = metric.heightPixels;
screenDpi = metric.densityDpi;
density = metric.density;
scaledDensity = metric.scaledDensity;
if (screenWidth >= 320 && screenWidth < 480) {
displayType = DISPLAY_SMALL;
} else if (screenWidth >= 480 && screenWidth < 720) {
displayType = DISPLAY_MIDDLE;
} else if (screenWidth >= 720 && screenWidth < 1080) {
displayType = DISPLAY_LARGE;
} else {
displayType = DISPLAY_XLARGE;
}
}
use of android.view.Display in project TourGuide by worker8.
the class ToolTilMeasureTest method getScreenHeight.
public int getScreenHeight(Activity activity) {
Display display = activity.getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
return size.y;
}
use of android.view.Display 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;
}
Aggregations