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