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