本文整理汇总了Java中android.util.DisplayMetrics.DENSITY_DEFAULT属性的典型用法代码示例。如果您正苦于以下问题:Java DisplayMetrics.DENSITY_DEFAULT属性的具体用法?Java DisplayMetrics.DENSITY_DEFAULT怎么用?Java DisplayMetrics.DENSITY_DEFAULT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.util.DisplayMetrics
的用法示例。
在下文中一共展示了DisplayMetrics.DENSITY_DEFAULT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getScreenType
private static int getScreenType(Context con) {
if (mDeviceType == -1) {
WindowManager wm = (WindowManager) con.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
int shortSize = Math.min(outMetrics.heightPixels, outMetrics.widthPixels);
int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / outMetrics.densityDpi;
if (shortSizeDp < 600) {
// 0-599dp: "phone" UI with a separate status & navigation bar
mDeviceType = DEVICE_PHONE;
} else if (shortSizeDp < 720) {
// 600-719dp: "phone" UI with modifications for larger screens
mDeviceType = DEVICE_HYBRID;
} else {
// 720dp: "tablet" UI with a single combined status & navigation bar
mDeviceType = DEVICE_TABLET;
}
}
return mDeviceType;
}
示例2: CrumbView
public CrumbView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
defaultPaint.setColor(fetchDefaultColour());
int densityRatio = getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT;
dotInterval = 16 * densityRatio;
dotRadius = 4 * densityRatio;
}
示例3: temporaryRestoreDefaultDensity
/**
* restores normal density without saving it for next start
*/
public void temporaryRestoreDefaultDensity(){
Resources res = mActivity.getResources();
DisplayMetrics displayMetrics = res.getDisplayMetrics();
Configuration config = res.getConfiguration();
displayMetrics.densityDpi = DisplayMetrics.DENSITY_DEFAULT;
config.densityDpi = Configuration.DENSITY_DPI_UNDEFINED;
res.updateConfiguration(config, displayMetrics);
}
示例4: dpToPx
public static int dpToPx(int dp) {
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
return dp * (metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
示例5: convertPixelsToDp
public static float convertPixelsToDp(float px, Context context){
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float dp = px / ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
return dp;
}
示例6: convertDpToPixel
public static float convertDpToPixel(float dp, Context context) {
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float px = dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
return px;
}
示例7: convertPixelsToDp
private int convertPixelsToDp(int px) {
return px / (mDisplayMetrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
示例8: convertDpToPixel
public static int convertDpToPixel(float dp, Context context) {
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
return (int) (dp * (metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT));
}
示例9: ConvertTopx
private int ConvertTopx(float dp) {
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
return ((int) (dp * ((float) metrics.densityDpi) / DisplayMetrics.DENSITY_DEFAULT));
}
示例10: dpiFromPx
public static float dpiFromPx(int size, DisplayMetrics metrics){
float densityRatio = (float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT;
return (size / densityRatio);
}
示例11: FromDpToPixels
public static float FromDpToPixels(float dp, Context context) {
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
return dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
示例12: convertDpToPixel
public static float convertDpToPixel(float dp, Context context){
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
return dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
示例13: getPixelScaleFactor
private static float getPixelScaleFactor(Context context) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
return (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT);
}
示例14: convertPixelsToDp
/**
* This method converts device specific pixels to density independent pixels.
*
* @param px A value in px (pixels) unit. Which we need to convert into db
* @param context Context to get resources and device specific display metrics
* @return A float value to represent dp equivalent to px value
*/
public static float convertPixelsToDp(float px, Context context){
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float dp = px / ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
return dp;
}
示例15: convertDpToPixel
/**
* This method converts dp unit to equivalent pixels, depending on device density.
*
* @param dp A value in dp (density independent pixels) unit. Which we need to convert into pixels
* @param context Context to get resources and device specific display metrics
* @return A float value to represent px equivalent to dp depending on device density
*/
private static float convertDpToPixel(float dp, Context context) {
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float px = dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
return px;
}