Java Code Examples for android.util.DisplayMetrics#DENSITY_XHIGH
The following examples show how to use
android.util.DisplayMetrics#DENSITY_XHIGH .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BugReportLens.java From debugdrawer with Apache License 2.0 | 6 votes |
private static String getDensityString(DisplayMetrics displayMetrics) { switch (displayMetrics.densityDpi) { case DisplayMetrics.DENSITY_LOW: return "ldpi"; case DisplayMetrics.DENSITY_MEDIUM: return "mdpi"; case DisplayMetrics.DENSITY_HIGH: return "hdpi"; case DisplayMetrics.DENSITY_XHIGH: return "xhdpi"; case DisplayMetrics.DENSITY_XXHIGH: return "xxhdpi"; case DisplayMetrics.DENSITY_XXXHIGH: return "xxxhdpi"; case DisplayMetrics.DENSITY_TV: return "tvdpi"; default: return String.valueOf(displayMetrics.densityDpi); } }
Example 2
Source File: NinePatchBitmapFactory.java From Aria with Apache License 2.0 | 6 votes |
public static String getDensityPostfix(Resources res) { String result = null; switch (res.getDisplayMetrics().densityDpi) { case DisplayMetrics.DENSITY_LOW: result = "ldpi"; break; case DisplayMetrics.DENSITY_MEDIUM: result = "mdpi"; break; case DisplayMetrics.DENSITY_HIGH: result = "hdpi"; break; case DisplayMetrics.DENSITY_XHIGH: result = "xhdpi"; break; case DisplayMetrics.DENSITY_XXHIGH: result = "xxhdpi"; break; case DisplayMetrics.DENSITY_XXXHIGH: result = "xxxhdpi"; break; } return result; }
Example 3
Source File: DeviceInfo.java From Cangol-appcore with Apache License 2.0 | 6 votes |
/** * 获取设备Densitydpi 类型 * * @param context * @return */ public static String getDensityDpiStr(Context context) { switch (context.getResources().getDisplayMetrics().densityDpi) { case DisplayMetrics.DENSITY_LOW: return "LDPI"; case DisplayMetrics.DENSITY_MEDIUM: return "MDPI"; case DisplayMetrics.DENSITY_TV: return "TVDPI"; case DisplayMetrics.DENSITY_HIGH: return "HDPI"; case DisplayMetrics.DENSITY_XHIGH: return "XHDPI"; case DisplayMetrics.DENSITY_XXHIGH: return "XXHDPI"; case DisplayMetrics.DENSITY_XXXHIGH: return "XXXHDPI"; default: return ""; } }
Example 4
Source File: InvariantDeviceProfile.java From Trebuchet with GNU General Public License v3.0 | 6 votes |
private int getLauncherIconDensity(int requiredSize) { // Densities typically defined by an app. int[] densityBuckets = new int[] { DisplayMetrics.DENSITY_LOW, DisplayMetrics.DENSITY_MEDIUM, DisplayMetrics.DENSITY_TV, DisplayMetrics.DENSITY_HIGH, DisplayMetrics.DENSITY_XHIGH, DisplayMetrics.DENSITY_XXHIGH, DisplayMetrics.DENSITY_XXXHIGH }; int density = DisplayMetrics.DENSITY_XXXHIGH; for (int i = densityBuckets.length - 1; i >= 0; i--) { float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i] / DisplayMetrics.DENSITY_DEFAULT; if (expectedSize >= requiredSize) { density = densityBuckets[i]; } } return density; }
Example 5
Source File: BugReportLens.java From u2020-mvp with Apache License 2.0 | 6 votes |
private static String getDensityString(DisplayMetrics displayMetrics) { switch (displayMetrics.densityDpi) { case DisplayMetrics.DENSITY_LOW: return "ldpi"; case DisplayMetrics.DENSITY_MEDIUM: return "mdpi"; case DisplayMetrics.DENSITY_HIGH: return "hdpi"; case DisplayMetrics.DENSITY_XHIGH: return "xhdpi"; case DisplayMetrics.DENSITY_XXHIGH: return "xxhdpi"; case DisplayMetrics.DENSITY_XXXHIGH: return "xxxhdpi"; case DisplayMetrics.DENSITY_TV: return "tvdpi"; default: return String.valueOf(displayMetrics.densityDpi); } }
Example 6
Source File: DeviceModule.java From DebugDrawer with Apache License 2.0 | 6 votes |
private static String getDensityString(DisplayMetrics displayMetrics) { switch (displayMetrics.densityDpi) { case DisplayMetrics.DENSITY_LOW: return "ldpi"; case DisplayMetrics.DENSITY_MEDIUM: return "mdpi"; case DisplayMetrics.DENSITY_HIGH: return "hdpi"; case DisplayMetrics.DENSITY_XHIGH: return "xhdpi"; case DisplayMetrics.DENSITY_XXHIGH: return "xxhdpi"; case DisplayMetrics.DENSITY_XXXHIGH: return "xxxhdpi"; case DisplayMetrics.DENSITY_TV: return "tvdpi"; default: return String.valueOf(displayMetrics.densityDpi); } }
Example 7
Source File: DeviceInfoModule.java From debugdrawer with Apache License 2.0 | 6 votes |
private static String getDensityString(DisplayMetrics displayMetrics) { switch (displayMetrics.densityDpi) { case DisplayMetrics.DENSITY_LOW: return "ldpi"; case DisplayMetrics.DENSITY_MEDIUM: return "mdpi"; case DisplayMetrics.DENSITY_HIGH: return "hdpi"; case DisplayMetrics.DENSITY_XHIGH: return "xhdpi"; case DisplayMetrics.DENSITY_XXHIGH: return "xxhdpi"; case DisplayMetrics.DENSITY_XXXHIGH: return "xxxhdpi"; case DisplayMetrics.DENSITY_TV: return "tvdpi"; default: return "unknown"; } }
Example 8
Source File: DebugView.java From u2020-mvp with Apache License 2.0 | 6 votes |
private static String getDensityString(DisplayMetrics displayMetrics) { switch (displayMetrics.densityDpi) { case DisplayMetrics.DENSITY_LOW: return "ldpi"; case DisplayMetrics.DENSITY_MEDIUM: return "mdpi"; case DisplayMetrics.DENSITY_HIGH: return "hdpi"; case DisplayMetrics.DENSITY_XHIGH: return "xhdpi"; case DisplayMetrics.DENSITY_XXHIGH: return "xxhdpi"; case DisplayMetrics.DENSITY_XXXHIGH: return "xxxhdpi"; case DisplayMetrics.DENSITY_TV: return "tvdpi"; default: return String.valueOf(displayMetrics.densityDpi); } }
Example 9
Source File: Comman.java From XERUNG with Apache License 2.0 | 6 votes |
public boolean isTabletDevice(Context activityContext) { boolean device_large = ((activityContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE); if (device_large) { DisplayMetrics metrics = new DisplayMetrics(); Activity activity = (Activity) activityContext; activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM || metrics.densityDpi == DisplayMetrics.DENSITY_TV || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) { return true; } } return false; }
Example 10
Source File: ScreenDensityInterceptor.java From px-android with MIT License | 6 votes |
private String getDensityName(@NonNull final Context context) { final float densityScale = 1.0f / DisplayMetrics.DENSITY_DEFAULT; final float density = context.getResources().getDisplayMetrics().density / densityScale; if (density >= DisplayMetrics.DENSITY_XXXHIGH) { return "xxxhdpi"; } if (density >= DisplayMetrics.DENSITY_XXHIGH) { return "xxhdpi"; } if (density >= DisplayMetrics.DENSITY_XHIGH) { return "xhdpi"; } if (density >= DisplayMetrics.DENSITY_HIGH) { return "hdpi"; } if (density >= DisplayMetrics.DENSITY_MEDIUM) { return "mdpi"; } return "ldpi"; }
Example 11
Source File: WeekLabelView.java From Android-LunarView with Apache License 2.0 | 6 votes |
private static int dip2px(Context context) { int dpValue = 10; int dpi = context.getResources().getDisplayMetrics().densityDpi; if (dpi >= DisplayMetrics.DENSITY_XXXHIGH) { dpValue = 18; } else if (dpi >= DisplayMetrics.DENSITY_XXHIGH) { dpValue = 16; } else if (dpi >= DisplayMetrics.DENSITY_XHIGH) { dpValue = 15; } else if (dpi >= DisplayMetrics.DENSITY_HIGH) { dpValue = 14; } final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); }
Example 12
Source File: SystemInfo.java From Noyze with Apache License 2.0 | 5 votes |
/** * @return The height of the system status bar. This is * done by querying the system's resources, or if that fails * by using fallbacks for different screen densities. */ public static int getStatusBarHeight(Context context) { if (mBarHeight > 0) return mBarHeight; // Get display metrics for window. final DisplayMetrics mMetrics = new DisplayMetrics(); ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay().getMetrics(mMetrics); int statusBarHeight; switch (mMetrics.densityDpi) { case DisplayMetrics.DENSITY_HIGH: statusBarHeight = HIGH_DPI_STATUS_BAR_HEIGHT; break; case DisplayMetrics.DENSITY_MEDIUM: statusBarHeight = MEDIUM_DPI_STATUS_BAR_HEIGHT; break; case DisplayMetrics.DENSITY_LOW: statusBarHeight = LOW_DPI_STATUS_BAR_HEIGHT; break; case DisplayMetrics.DENSITY_XHIGH: statusBarHeight = XHIGH_DPI_STATUS_BAR_HEIGHT; break; default: statusBarHeight = MEDIUM_DPI_STATUS_BAR_HEIGHT; } return statusBarHeight; }
Example 13
Source File: EasyDisplayMod.java From easydeviceinfo with Apache License 2.0 | 5 votes |
/** * Gets density. * * @return the density */ public final String getDensity() { String densityStr = null; final int density = context.getResources().getDisplayMetrics().densityDpi; switch (density) { case DisplayMetrics.DENSITY_LOW: densityStr = "LDPI"; break; case DisplayMetrics.DENSITY_MEDIUM: densityStr = "MDPI"; break; case DisplayMetrics.DENSITY_TV: densityStr = "TVDPI"; break; case DisplayMetrics.DENSITY_HIGH: densityStr = "HDPI"; break; case DisplayMetrics.DENSITY_XHIGH: densityStr = "XHDPI"; break; case DisplayMetrics.DENSITY_400: densityStr = "XMHDPI"; break; case DisplayMetrics.DENSITY_XXHIGH: densityStr = "XXHDPI"; break; case DisplayMetrics.DENSITY_XXXHIGH: densityStr = "XXXHDPI"; break; default: //do nothing break; } return CheckValidityUtil.checkValidData(densityStr); }
Example 14
Source File: Chart.java From PressureNet with GNU General Public License v3.0 | 5 votes |
/** * Set the chart text size based on screen metrics */ private void setTextSize() { try { DisplayMetrics displayMetrics = new DisplayMetrics(); displayMetrics = context.getResources().getDisplayMetrics(); log("setting text size, density is " + displayMetrics.densityDpi); switch(displayMetrics.densityDpi){ case DisplayMetrics.DENSITY_LOW: textSize = 12; pointSize = 2f; break; case DisplayMetrics.DENSITY_MEDIUM: textSize = 16; pointSize = 3f; break; case DisplayMetrics.DENSITY_HIGH: textSize = 18; pointSize = 4f; break; case DisplayMetrics.DENSITY_XHIGH: textSize = 20; pointSize = 5f; break; case DisplayMetrics.DENSITY_XXHIGH: textSize = 26; pointSize = 7f; break; default: break; } } catch(Exception e) { e.printStackTrace(); } }
Example 15
Source File: ActivityManager.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
static int getLauncherLargeIconSizeInner(Context context) { final Resources res = context.getResources(); final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size); final int sw = res.getConfiguration().smallestScreenWidthDp; if (sw < 600) { // Smaller than approx 7" tablets, use the regular icon size. return size; } final int density = res.getDisplayMetrics().densityDpi; switch (density) { case DisplayMetrics.DENSITY_LOW: return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW; case DisplayMetrics.DENSITY_MEDIUM: return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM; case DisplayMetrics.DENSITY_TV: return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH; case DisplayMetrics.DENSITY_HIGH: return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH; case DisplayMetrics.DENSITY_XHIGH: return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH; case DisplayMetrics.DENSITY_XXHIGH: return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH; default: // The density is some abnormal value. Return some other // abnormal value that is a reasonable scaling of it. return (int)((size*1.5f) + .5f); } }
Example 16
Source File: ActivityManager.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Get the preferred density of icons for the launcher. This is used when * custom drawables are created (e.g., for shortcuts). * * @return density in terms of DPI */ public int getLauncherLargeIconDensity() { final Resources res = mContext.getResources(); final int density = res.getDisplayMetrics().densityDpi; final int sw = res.getConfiguration().smallestScreenWidthDp; if (sw < 600) { // Smaller than approx 7" tablets, use the regular icon size. return density; } switch (density) { case DisplayMetrics.DENSITY_LOW: return DisplayMetrics.DENSITY_MEDIUM; case DisplayMetrics.DENSITY_MEDIUM: return DisplayMetrics.DENSITY_HIGH; case DisplayMetrics.DENSITY_TV: return DisplayMetrics.DENSITY_XHIGH; case DisplayMetrics.DENSITY_HIGH: return DisplayMetrics.DENSITY_XHIGH; case DisplayMetrics.DENSITY_XHIGH: return DisplayMetrics.DENSITY_XXHIGH; case DisplayMetrics.DENSITY_XXHIGH: return DisplayMetrics.DENSITY_XHIGH * 2; default: // The density is some abnormal value. Return some other // abnormal value that is a reasonable scaling of it. return (int)((density*1.5f)+.5f); } }
Example 17
Source File: SystemInfo.java From Noyze with Apache License 2.0 | 5 votes |
/** * @return The height of the system bar. This is * done by querying the system's resources, or if that fails * by using fallbacks for different screen densities. */ public static int getSystemBarHeight(Context context) { if (mBarHeight2 > 0) return mBarHeight2; // Get display metrics for window. final DisplayMetrics mMetrics = new DisplayMetrics(); ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay().getMetrics(mMetrics); int statusBarHeight; switch (mMetrics.densityDpi) { case DisplayMetrics.DENSITY_HIGH: statusBarHeight = HIGH_DPI_SYSTEM_BAR_HEIGHT; break; case DisplayMetrics.DENSITY_MEDIUM: statusBarHeight = MEDIUM_DPI_SYSTEM_BAR_HEIGHT; break; case DisplayMetrics.DENSITY_LOW: statusBarHeight = LOW_DPI_SYSTEM_BAR_HEIGHT; break; case DisplayMetrics.DENSITY_XHIGH: statusBarHeight = XHIGH_DPI_SYSTEM_BAR_HEIGHT; break; default: statusBarHeight = MEDIUM_DPI_SYSTEM_BAR_HEIGHT; } return statusBarHeight; }
Example 18
Source File: ActivityManager.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** * Get the preferred density of icons for the launcher. This is used when * custom drawables are created (e.g., for shortcuts). * * @return density in terms of DPI */ public int getLauncherLargeIconDensity() { final Resources res = mContext.getResources(); final int density = res.getDisplayMetrics().densityDpi; final int sw = res.getConfiguration().smallestScreenWidthDp; if (sw < 600) { // Smaller than approx 7" tablets, use the regular icon size. return density; } switch (density) { case DisplayMetrics.DENSITY_LOW: return DisplayMetrics.DENSITY_MEDIUM; case DisplayMetrics.DENSITY_MEDIUM: return DisplayMetrics.DENSITY_HIGH; case DisplayMetrics.DENSITY_TV: return DisplayMetrics.DENSITY_XHIGH; case DisplayMetrics.DENSITY_HIGH: return DisplayMetrics.DENSITY_XHIGH; case DisplayMetrics.DENSITY_XHIGH: return DisplayMetrics.DENSITY_XXHIGH; case DisplayMetrics.DENSITY_XXHIGH: return DisplayMetrics.DENSITY_XHIGH * 2; default: // The density is some abnormal value. Return some other // abnormal value that is a reasonable scaling of it. return (int)((density*1.5f)+.5f); } }
Example 19
Source File: WebViewActivity.java From movienow with GNU General Public License v3.0 | 5 votes |
private void initWebSettings() { WebSettings webSettings = webViewT.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(true); webSettings.setSupportZoom(true); webSettings.setDisplayZoomControls(false); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setAllowFileAccess(true); webSettings.setDefaultTextEncodingName("UTF-8"); webSettings.setLoadWithOverviewMode(true); webSettings.setUseWideViewPort(true); webSettings.setDomStorageEnabled(true); webSettings.setAppCacheMaxSize(1024 * 1024 * 8); String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath(); webSettings.setAppCachePath(appCachePath); webSettings.setAllowFileAccess(true); webSettings.setAppCacheEnabled(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int mDensity = metrics.densityDpi; if (mDensity == 240) { webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR); } else if (mDensity == 160) { webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM); } else if (mDensity == 120) { webSettings.setDefaultZoom(WebSettings.ZoomDensity.CLOSE); } else if (mDensity == DisplayMetrics.DENSITY_XHIGH) { webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR); } else if (mDensity == DisplayMetrics.DENSITY_TV) { webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR); } else { webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM); } }
Example 20
Source File: BarometerNetworkActivity.java From PressureNet with GNU General Public License v3.0 | 4 votes |
private Bitmap drawableToBitmap(Drawable drawable, CbObservation obs) { /* * if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) * drawable).getBitmap(); } */ if (obs == null) { return ((BitmapDrawable) drawable).getBitmap(); } Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); String display = displayPressureValue(obs.getObservationValue(), obs.getLocation().getAltitude()); if (display.contains(" ")) { display = display.split(" ")[0]; } int x = 0; int y = canvas.getHeight(); // Use the screen data to determine text size int defaultTextSize = 16; int defaultTextXOffset = 48; int defaultTextYOffset = 30; int textSize = defaultTextSize; int textXOffset = defaultTextXOffset; int textYOffset = defaultTextYOffset; // Check screen metrics DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); switch (metrics.densityDpi) { case DisplayMetrics.DENSITY_LOW: textSize = defaultTextSize - 10; textXOffset = defaultTextXOffset - 30; textYOffset = defaultTextYOffset - 25; break; case DisplayMetrics.DENSITY_MEDIUM: textSize = defaultTextSize - 8; textXOffset = defaultTextXOffset - 24; textYOffset = defaultTextYOffset - 15; break; case DisplayMetrics.DENSITY_HIGH: textSize = defaultTextSize - 4; textXOffset = defaultTextXOffset - 12; textYOffset = defaultTextYOffset - 8; break; case DisplayMetrics.DENSITY_XHIGH: textSize = defaultTextSize + 2; textXOffset = defaultTextXOffset + 3; textYOffset = defaultTextYOffset; break; case DisplayMetrics.DENSITY_XXHIGH: textSize = defaultTextSize + 16; textXOffset = defaultTextXOffset + 22; textYOffset = defaultTextYOffset + 14; break; default: break; } // Paint Paint paint = new Paint(); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(textSize); paint.setShadowLayer(15, 5, 5, 0); paint.setAntiAlias(true); paint.setColor(Color.BLACK); paint.setFlags(Paint.ANTI_ALIAS_FLAG); int xMax = canvas.getWidth(); int yMax = canvas.getHeight(); drawable.draw(canvas); canvas.drawText(display, textXOffset, textYOffset, paint); return bitmap; }