Search in sources :

Example 41 with Display

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());
}
Also used : Locale(java.util.Locale) PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) JSONArray(org.json.JSONArray) DisplayMetrics(android.util.DisplayMetrics) JSONException(org.json.JSONException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FacebookException(com.facebook.FacebookException) IOException(java.io.IOException) WindowManager(android.view.WindowManager) Display(android.view.Display)

Example 42 with Display

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;
    }
}
Also used : Point(android.graphics.Point) Display(android.view.Display)

Example 43 with Display

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;
    }
}
Also used : Field(java.lang.reflect.Field) Rect(android.graphics.Rect) Method(java.lang.reflect.Method) DisplayMetrics(android.util.DisplayMetrics) Display(android.view.Display)

Example 44 with Display

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;
}
Also used : Point(android.graphics.Point) Display(android.view.Display)

Example 45 with Display

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;
}
Also used : Method(java.lang.reflect.Method) DisplayMetrics(android.util.DisplayMetrics) SuppressLint(android.annotation.SuppressLint) Display(android.view.Display)

Aggregations

Display (android.view.Display)478 Point (android.graphics.Point)231 WindowManager (android.view.WindowManager)201 DisplayMetrics (android.util.DisplayMetrics)78 SuppressLint (android.annotation.SuppressLint)29 Resources (android.content.res.Resources)25 Bitmap (android.graphics.Bitmap)25 LinearLayout (android.widget.LinearLayout)25 Rect (android.graphics.Rect)23 View (android.view.View)23 Method (java.lang.reflect.Method)23 RemoteException (android.os.RemoteException)22 Canvas (android.graphics.Canvas)21 VirtualDisplay (android.hardware.display.VirtualDisplay)20 TextView (android.widget.TextView)18 Dialog (android.app.Dialog)17 Camera (android.hardware.Camera)17 Intent (android.content.Intent)16 ViewGroup (android.view.ViewGroup)16 Context (android.content.Context)15