Java Code Examples for android.util.DisplayMetrics#DENSITY_HIGH

The following examples show how to use android.util.DisplayMetrics#DENSITY_HIGH . 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: DeviceModule.java    From DebugDrawer with Apache License 2.0 6 votes vote down vote up
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 vote down vote up
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: BogusMoveEventDetector.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
public static void init(final Resources res) {
    // The proximate bogus down move up event hack is needed for a device such like,
    // 1) is large tablet, or 2) is small tablet and the screen density is less than hdpi.
    // Though it seems odd to use screen density as criteria of the quality of the touch
    // screen, the small table that has a less density screen than hdpi most likely has been
    // made with the touch screen that needs the hack.
    final int screenMetrics = res.getInteger(R.integer.config_screen_metrics);
    final boolean isLargeTablet = (screenMetrics == Constants.SCREEN_METRICS_LARGE_TABLET);
    final boolean isSmallTablet = (screenMetrics == Constants.SCREEN_METRICS_SMALL_TABLET);
    final int densityDpi = res.getDisplayMetrics().densityDpi;
    final boolean hasLowDensityScreen = (densityDpi < DisplayMetrics.DENSITY_HIGH);
    final boolean needsTheHack = isLargeTablet || (isSmallTablet && hasLowDensityScreen);
    if (DEBUG_MODE) {
        final int sw = res.getConfiguration().smallestScreenWidthDp;
        Log.d(TAG, "needsProximateBogusDownMoveUpEventHack=" + needsTheHack
                + " smallestScreenWidthDp=" + sw + " densityDpi=" + densityDpi
                + " screenMetrics=" + screenMetrics);
    }
    sNeedsProximateBogusDownMoveUpEventHack = needsTheHack;
}
 
Example 4
Source File: BogusMoveEventDetector.java    From LokiBoard-Android-Keylogger with Apache License 2.0 6 votes vote down vote up
public static void init(final Resources res) {
    // The proximate bogus down move up event hack is needed for a device such like,
    // 1) is large tablet, or 2) is small tablet and the screen density is less than hdpi.
    // Though it seems odd to use screen density as criteria of the quality of the touch
    // screen, the small table that has a less density screen than hdpi most likely has been
    // made with the touch screen that needs the hack.
    final int screenMetrics = res.getInteger(R.integer.config_screen_metrics);
    final boolean isLargeTablet = (screenMetrics == Constants.SCREEN_METRICS_LARGE_TABLET);
    final boolean isSmallTablet = (screenMetrics == Constants.SCREEN_METRICS_SMALL_TABLET);
    final int densityDpi = res.getDisplayMetrics().densityDpi;
    final boolean hasLowDensityScreen = (densityDpi < DisplayMetrics.DENSITY_HIGH);
    final boolean needsTheHack = isLargeTablet || (isSmallTablet && hasLowDensityScreen);
    if (DEBUG_MODE) {
        final int sw = res.getConfiguration().smallestScreenWidthDp;
        Log.d(TAG, "needsProximateBogusDownMoveUpEventHack=" + needsTheHack
                + " smallestScreenWidthDp=" + sw + " densityDpi=" + densityDpi
                + " screenMetrics=" + screenMetrics);
    }
    sNeedsProximateBogusDownMoveUpEventHack = needsTheHack;
}
 
Example 5
Source File: InvariantDeviceProfile.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
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 6
Source File: ScreenDensityInterceptor.java    From px-android with MIT License 6 votes vote down vote up
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 7
Source File: Theme.java    From YiBo with Apache License 2.0 6 votes vote down vote up
public String getResourcesPathInAssets(String resName) {
DisplayMetrics metrics = context.getApplicationContext().getResources().getDisplayMetrics();
      String drawableDpi;
      switch (metrics.densityDpi) {
      case DisplayMetrics.DENSITY_LOW:
      	drawableDpi = "drawable-ldpi";
      	break;
      case DisplayMetrics.DENSITY_MEDIUM:
      	drawableDpi = "drawable-mdpi";
      	break;
      case DisplayMetrics.DENSITY_HIGH:
      	drawableDpi = "drawable-hdpi";
      	break;
      case 320:
      	drawableDpi = "drawable-xhdpi";
      	break;
      default:
      	drawableDpi = "drawable-mdpi";
      }

      return currentPackageName + "/" + drawableDpi + "/" + resName + ".png";         
  }
 
Example 8
Source File: SystemInfo.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * @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 9
Source File: MobileDeviceInfo.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
private void getScreenDensity() {

        int density;

        density = mContext.getResources().getDisplayMetrics().densityDpi;

        switch(density)
        {
            case DisplayMetrics.DENSITY_LOW:
                //  not used; but can't hurt adding it in case something changes
                formFactor = "LDPI";
                break;
            case DisplayMetrics.DENSITY_MEDIUM:
                formFactor = "MDPI";
                break;
            case DisplayMetrics.DENSITY_HIGH:
                formFactor = "HDPI";
                break;
            case DisplayMetrics.DENSITY_XHIGH:
                formFactor = "XHDPI";
                break;
            case DisplayMetrics.DENSITY_XXHIGH:
                formFactor = "XXHDPI";
                break;
            case DisplayMetrics.DENSITY_XXXHIGH:
                formFactor = "XXXHDPI";
                break;
            default:
                formFactor = "UNKNOWN";
                break;
        }
    }
 
Example 10
Source File: AptoideUtils.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
private static String getUserAvatarIconSize(WindowManager windowManager) {
  if (ScreenU.getDensityDpi(windowManager) <= DisplayMetrics.DENSITY_HIGH) {
    return "50x50";
  } else {
    return "150x150";
  }
}
 
Example 11
Source File: LinearColorBar.java    From android-cache-cleaner with MIT License 5 votes vote down vote up
public LinearColorBar(Context context, AttributeSet attrs) {
    super(context, attrs);
    setWillNotDraw(false);
    mPaint.setStyle(Paint.Style.FILL);
    mColorGradientPaint.setStyle(Paint.Style.FILL);
    mColorGradientPaint.setAntiAlias(true);
    mEdgeGradientPaint.setStyle(Paint.Style.STROKE);
    mLineWidth = getResources().getDisplayMetrics().densityDpi >= DisplayMetrics.DENSITY_HIGH
            ? 2 : 1;
    mEdgeGradientPaint.setStrokeWidth(mLineWidth);
    mEdgeGradientPaint.setAntiAlias(true);

}
 
Example 12
Source File: AppUtils.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static boolean isRunningOn2xOrGreaterScreen(Context context) {
    if (context == null) {
        return false;
    }
    int density = context.getResources().getDisplayMetrics().densityDpi;
    boolean result = density >= DisplayMetrics.DENSITY_HIGH;
    Log.d(TAG, String.format("Device density is %d, and result of @2x check is %b", density, result));
    return result;
}
 
Example 13
Source File: BaiduNewsDetailActivity.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);

	Intent intent = getIntent();
	mNewsTitle = intent.getStringExtra("news_title");
	mNewsUrl = intent.getStringExtra("news_url");

	setActionBarTitle(mNewsTitle);

	int screenDensity = getResources().getDisplayMetrics().densityDpi;
	WebSettings.ZoomDensity zoomDensity = WebSettings.ZoomDensity.MEDIUM;
	switch (screenDensity)
	{
		case DisplayMetrics.DENSITY_LOW:
		{
			zoomDensity = WebSettings.ZoomDensity.CLOSE;
			break;
		}
		case DisplayMetrics.DENSITY_MEDIUM:
		{
			zoomDensity = WebSettings.ZoomDensity.MEDIUM;
			break;
		}
		case DisplayMetrics.DENSITY_HIGH:
		{
			zoomDensity = WebSettings.ZoomDensity.FAR;
			break;
		}
	}
	// 设置默认缩放方式尺寸
	getWebview().getSettings().setDefaultZoom(zoomDensity);
	getWebview().getSettings().setBuiltInZoomControls(true);
	getWebview().loadUrl(mNewsUrl);
}
 
Example 14
Source File: SystemInfo.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * @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 15
Source File: SystemInfo.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * @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 16
Source File: StatsChart.java    From PressureNet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 = 1f;
	         break;
	     case DisplayMetrics.DENSITY_MEDIUM:
	    	 textSize = 16;
	    	 pointSize = 1f;
	    	 break;
	     case DisplayMetrics.DENSITY_HIGH:
	    	 textSize = 18;
	    	 pointSize = 1f;
	    	 break;
	     case DisplayMetrics.DENSITY_XHIGH:
	    	 textSize = 20;
	    	 pointSize = 1f;
                break;
	     case DisplayMetrics.DENSITY_XXHIGH:
	    	 textSize = 26;
	    	 pointSize = 1f;
                break;
	     default:
	    	 break;
		}
	} catch(Exception e) {
		e.printStackTrace();
	}
}
 
Example 17
Source File: SystemInfo.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * @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 android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * 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: ActivityManager.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * 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 20
Source File: AbstractAppLaunchShortcut.java    From island with Apache License 2.0 4 votes vote down vote up
private static int getDpiForLargeIcon(final int dpi) {
	if (dpi >= DisplayMetrics.DENSITY_XHIGH) return DisplayMetrics.DENSITY_XXHIGH;
	if (dpi >= DisplayMetrics.DENSITY_HIGH) return DisplayMetrics.DENSITY_XHIGH;
	if (dpi >= DisplayMetrics.DENSITY_MEDIUM) return DisplayMetrics.DENSITY_HIGH;
	return DisplayMetrics.DENSITY_MEDIUM;
}