Search in sources :

Example 66 with DisplayMetrics

use of android.util.DisplayMetrics in project material-camera by afollestad.

the class VideoStreamView method getScreenOrientation.

@ActivityOrientation
public static int getScreenOrientation(Activity context) {
    int rotation = context.getWindowManager().getDefaultDisplay().getRotation();
    DisplayMetrics dm = new DisplayMetrics();
    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("VideoStreamView", "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("VideoStreamView", "Unknown screen orientation. Defaulting to landscape.");
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                break;
        }
    }
    return orientation;
}
Also used : DisplayMetrics(android.util.DisplayMetrics)

Example 67 with DisplayMetrics

use of android.util.DisplayMetrics in project epoxy by airbnb.

the class VerticalGridCardSpacingDecoration method getItemOffsets.

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, State state) {
    if (outerPadding == -1 || innerPadding == -1) {
        DisplayMetrics m = view.getResources().getDisplayMetrics();
        outerPadding = (int) TypedValue.applyDimension(COMPLEX_UNIT_DIP, OUTER_PADDING_DP, m);
        innerPadding = (int) TypedValue.applyDimension(COMPLEX_UNIT_DIP, INNER_PADDING_DP, m);
    }
    int position = parent.getChildAdapterPosition(view);
    final GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager();
    final SpanSizeLookup spanSizeLookup = layoutManager.getSpanSizeLookup();
    // Zero everything out for the common case
    outRect.setEmpty();
    int spanSize = spanSizeLookup.getSpanSize(position);
    int spanCount = layoutManager.getSpanCount();
    int spanIndex = spanSizeLookup.getSpanIndex(position, spanCount);
    if (spanSize == spanCount) {
        // Only item in row
        outRect.left = outerPadding;
        outRect.right = outerPadding;
    } else if (spanIndex == 0) {
        // First item in row
        outRect.left = outerPadding;
        outRect.right = innerPadding;
    } else if (spanIndex == spanCount - 1) {
        // Last item in row
        outRect.left = innerPadding;
        outRect.right = outerPadding;
    } else {
        // Inner item (not relevant for less than three columns)
        outRect.left = innerPadding;
        outRect.right = innerPadding;
    }
}
Also used : SpanSizeLookup(android.support.v7.widget.GridLayoutManager.SpanSizeLookup) GridLayoutManager(android.support.v7.widget.GridLayoutManager) DisplayMetrics(android.util.DisplayMetrics)

Example 68 with DisplayMetrics

use of android.util.DisplayMetrics in project lottie-android by airbnb.

the class Utils method getScreenWidth.

static int getScreenWidth(Context context) {
    if (displayMetrics == null) {
        displayMetrics = new DisplayMetrics();
    }
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(displayMetrics);
    return displayMetrics.widthPixels;
}
Also used : DisplayMetrics(android.util.DisplayMetrics) WindowManager(android.view.WindowManager)

Example 69 with DisplayMetrics

use of android.util.DisplayMetrics in project Android-GoogleDirectionAndPlaceLibrary by akexorcist.

the class GoogleDirection method dpToPx.

private int dpToPx(int dp) {
    DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
    int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;
}
Also used : DisplayMetrics(android.util.DisplayMetrics) SuppressLint(android.annotation.SuppressLint)

Example 70 with DisplayMetrics

use of android.util.DisplayMetrics in project GestureViews by alexvasilkov.

the class GlideHelper method loadResource.

public static void loadResource(@DrawableRes int drawableId, @NonNull ImageView image) {
    DisplayMetrics metrics = image.getResources().getDisplayMetrics();
    final int displayWidth = metrics.widthPixels;
    final int displayHeight = metrics.heightPixels;
    Glide.with(image.getContext()).load(drawableId).asBitmap().dontAnimate().diskCacheStrategy(DiskCacheStrategy.NONE).into(new BitmapImageViewTarget(image) {

        @Override
        public void getSize(final SizeReadyCallback cb) {
            // We don't want to load very big images on devices with small screens.
            // This will help Glide correctly choose images scale when reading them.
            super.getSize(new SizeReadyCallback() {

                @Override
                public void onSizeReady(int width, int height) {
                    cb.onSizeReady(displayWidth / 2, displayHeight / 2);
                }
            });
        }
    });
}
Also used : BitmapImageViewTarget(com.bumptech.glide.request.target.BitmapImageViewTarget) SizeReadyCallback(com.bumptech.glide.request.target.SizeReadyCallback) DisplayMetrics(android.util.DisplayMetrics)

Aggregations

DisplayMetrics (android.util.DisplayMetrics)751 WindowManager (android.view.WindowManager)103 Resources (android.content.res.Resources)95 Display (android.view.Display)75 Configuration (android.content.res.Configuration)58 Point (android.graphics.Point)56 View (android.view.View)48 SuppressLint (android.annotation.SuppressLint)44 Paint (android.graphics.Paint)42 Bitmap (android.graphics.Bitmap)41 Activity (android.app.Activity)32 ImageView (android.widget.ImageView)26 TypedArray (android.content.res.TypedArray)25 AssetManager (android.content.res.AssetManager)24 TypedValue (android.util.TypedValue)23 ViewGroup (android.view.ViewGroup)22 TextView (android.widget.TextView)21 Intent (android.content.Intent)20 FrameLayout (android.widget.FrameLayout)19 RelativeLayout (android.widget.RelativeLayout)19