Search in sources :

Example 91 with DisplayMetrics

use of android.util.DisplayMetrics in project okhttputils by hongyangAndroid.

the class ImageUtils method getExpectWidth.

/**
     * 根据view获得期望的宽度
     *
     * @param view
     * @return
     */
private static int getExpectWidth(View view) {
    int width = 0;
    if (view == null)
        return 0;
    final ViewGroup.LayoutParams params = view.getLayoutParams();
    //如果是WRAP_CONTENT,此时图片还没加载,getWidth根本无效
    if (params != null && params.width != ViewGroup.LayoutParams.WRAP_CONTENT) {
        // 获得实际的宽度
        width = view.getWidth();
    }
    if (width <= 0 && params != null) {
        // 获得布局文件中的声明的宽度
        width = params.width;
    }
    if (width <= 0) {
        // 获得设置的最大的宽度
        width = getImageViewFieldValue(view, "mMaxWidth");
    }
    //如果宽度还是没有获取到,憋大招,使用屏幕的宽度
    if (width <= 0) {
        DisplayMetrics displayMetrics = view.getContext().getResources().getDisplayMetrics();
        width = displayMetrics.widthPixels;
    }
    return width;
}
Also used : ViewGroup(android.view.ViewGroup) DisplayMetrics(android.util.DisplayMetrics)

Example 92 with DisplayMetrics

use of android.util.DisplayMetrics in project packer-ng-plugin by mcxiaoke.

the class MainActivity method addDeviceInfoSection.

@SuppressLint("NewApi")
private void addDeviceInfoSection() {
    StringBuilder builder = new StringBuilder();
    builder.append("[Device]\n");
    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    final MemoryInfo memoryInfo = new MemoryInfo();
    am.getMemoryInfo(memoryInfo);
    if (AndroidUtils.hasJellyBean()) {
        builder.append("Mem Total: ").append(StringUtils.getHumanReadableByteCount(memoryInfo.totalMem)).append("\n");
    }
    builder.append("Mem Free: ").append(StringUtils.getHumanReadableByteCount(memoryInfo.availMem)).append("\n");
    builder.append("Mem Heap: ").append(am.getMemoryClass()).append("M\n");
    builder.append("Mem Low: ").append(memoryInfo.lowMemory).append("\n");
    Display display = getWindowManager().getDefaultDisplay();
    DisplayMetrics dm = new DisplayMetrics();
    //DisplayMetrics dm = getResources().getDisplayMetrics();
    display.getMetrics(dm);
    int statusBarHeightDp = ViewUtils.getStatusBarHeightInDp(this);
    int systemBarHeightDp = ViewUtils.getSystemBarHeightInDp(this);
    int statusBarHeight = ViewUtils.getStatusBarHeight(this);
    int systemBarHeight = ViewUtils.getSystemBarHeight(this);
    Point point = getScreenRawSize(display);
    builder.append("statusBarHeightDp: ").append(statusBarHeightDp).append("\n");
    builder.append("systemBarHeightDp: ").append(systemBarHeightDp).append("\n");
    builder.append("statusBarHeightPx: ").append(statusBarHeight).append("\n");
    builder.append("systemBarHeightPx: ").append(systemBarHeight).append("\n");
    builder.append("screenWidth: ").append(point.x).append("\n");
    builder.append("screenHeight: ").append(point.y).append("\n");
    builder.append("WindowWidth: ").append(dm.widthPixels).append("\n");
    builder.append("WindowHeight: ").append(dm.heightPixels).append("\n");
    builder.append(toString2(dm));
    builder.append("\n");
    addSection(builder.toString());
}
Also used : MemoryInfo(android.app.ActivityManager.MemoryInfo) Point(android.graphics.Point) ActivityManager(android.app.ActivityManager) DisplayMetrics(android.util.DisplayMetrics) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Display(android.view.Display) SuppressLint(android.annotation.SuppressLint)

Example 93 with DisplayMetrics

use of android.util.DisplayMetrics in project packer-ng-plugin by mcxiaoke.

the class ViewUtils method getActionBarHeight.

public static int getActionBarHeight(Context context) {
    int actionBarHeight = 0;
    TypedValue tv = new TypedValue();
    final DisplayMetrics dm = context.getResources().getDisplayMetrics();
    if (Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
        if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, dm);
    } else {
        tv.data = 48;
        actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, dm);
    }
    return actionBarHeight;
}
Also used : DisplayMetrics(android.util.DisplayMetrics) Point(android.graphics.Point) SuppressLint(android.annotation.SuppressLint) TypedValue(android.util.TypedValue)

Example 94 with DisplayMetrics

use of android.util.DisplayMetrics in project packer-ng-plugin by mcxiaoke.

the class ViewUtils method getActionBarHeightInDp.

public static int getActionBarHeightInDp(Context context) {
    int actionBarHeight = 0;
    TypedValue tv = new TypedValue();
    final DisplayMetrics dm = context.getResources().getDisplayMetrics();
    if (Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
        if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
            actionBarHeight = (int) TypedValue.complexToFloat(tv.data);
    } else {
        tv.data = 48;
        actionBarHeight = (int) TypedValue.complexToFloat(tv.data);
    }
    return actionBarHeight;
}
Also used : DisplayMetrics(android.util.DisplayMetrics) Point(android.graphics.Point) SuppressLint(android.annotation.SuppressLint) TypedValue(android.util.TypedValue)

Example 95 with DisplayMetrics

use of android.util.DisplayMetrics in project zxingfragmentlib by mitoyarzun.

the class CameraConfigurationManager method getScreenOrientation.

// Taken from http://stackoverflow.com/a/10383164/902599
private int getScreenOrientation() {
    int rotation;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        rotation = ((Activity) context).getWindowManager().getDefaultDisplay().getRotation();
    } else {
        rotation = ((Activity) context).getWindowManager().getDefaultDisplay().getOrientation();
    }
    DisplayMetrics dm = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
    int width = dm.widthPixels;
    int height = dm.heightPixels;
    int orientation;
    // if the device's natural orientation is portrait:
    if ((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) && height > width || (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) && width > height) {
        switch(rotation) {
            case Surface.ROTATION_0:
                orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
                break;
            case Surface.ROTATION_90:
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                break;
            case Surface.ROTATION_180:
                orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
                break;
            case Surface.ROTATION_270:
                orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
                break;
            default:
                Log.e(TAG, "Unknown screen orientation. Defaulting to " + "portrait.");
                orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
                break;
        }
    } else // if the device's natural orientation is landscape or if the device
    // is square:
    {
        switch(rotation) {
            case Surface.ROTATION_0:
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                break;
            case Surface.ROTATION_90:
                orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
                break;
            case Surface.ROTATION_180:
                orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
                break;
            case Surface.ROTATION_270:
                orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
                break;
            default:
                Log.e(TAG, "Unknown screen orientation. Defaulting to " + "landscape.");
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                break;
        }
    }
    Log.v(TAG, "Orientation: " + orientation);
    return orientation;
}
Also used : PreferencesActivity(com.google.zxing.client.android.PreferencesActivity) Activity(android.app.Activity) DisplayMetrics(android.util.DisplayMetrics) Point(android.graphics.Point)

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