Java Code Examples for android.util.DisplayMetrics#DENSITY_MEDIUM

The following examples show how to use android.util.DisplayMetrics#DENSITY_MEDIUM . 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: DebugView.java    From u2020-mvp 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: InvariantDeviceProfile.java    From Trebuchet 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 4
Source File: BugReportLens.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 5
Source File: BugReportLens.java    From u2020 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 6
Source File: Comman.java    From XERUNG with Apache License 2.0 6 votes vote down vote up
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 7
Source File: Comman.java    From XERUNG with Apache License 2.0 6 votes vote down vote up
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 8
Source File: AptoideUtils.java    From aptoide-client with GNU General Public License v2.0 6 votes vote down vote up
public static String getScreenDensity() {

            Context context = Aptoide.getContext();
            int density = context.getResources().getDisplayMetrics().densityDpi;

            switch (density) {
                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";

                default:
                    return "hdpi";
            }

        }
 
Example 9
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 10
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 11
Source File: EasyDisplayMod.java    From easydeviceinfo with Apache License 2.0 5 votes vote down vote up
/**
 * 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 12
Source File: ImageInflationTest.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testScaleDownDueToBoth_containerDominant() {
    // Both the container size and the relative densities impose scale down requirements,
    // but the container restrictions impose a larger scale down, so we scale to those dimens
    int targetDensity = DisplayMetrics.DENSITY_MEDIUM;
    testCorrectInflationWithDensity(targetDensity, lowDensityDevice, boundingDimens_RESTRICTIVE, 50);
}
 
Example 13
Source File: ImageInflationTest.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testScaleDownDueToBoth_densityDominant() {
    // Both the container size and the relative densities impose scale down requirements,
    // but the density factor imposes a larger scale down, so we scale to those dimens
    int targetDensity = DisplayMetrics.DENSITY_MEDIUM;
    testCorrectInflationWithDensity(targetDensity, lowDensityDevice, boundingDimens_LESS_RESTRICTIVE, 75);
}
 
Example 14
Source File: DeviceTypeDetector.java    From android-utilset with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the device is a tablet or a phone
 * 
 * @param activityContext The Activity Context.
 * @return Returns true if the device is a Tablet
 */
public DeviceType getDeviceType(Context activityContext) {
	// Verifies if the Generalized Size of the device is XLARGE to be
	// considered a Tablet
	boolean xlarge = ((activityContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == SCREENLAYOUT_SIZE_XLARGE);

	// If XLarge, checks if the Generalized Density is at least MDPI
	// (160dpi)
	if (xlarge) {
		DisplayMetrics metrics = new DisplayMetrics();
		Activity activity = (Activity)activityContext;
		activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
		
		// MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160,
		// DENSITY_TV=213, DENSITY_XHIGH=320
		if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT
			|| metrics.densityDpi == DisplayMetrics.DENSITY_HIGH
			|| metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM
			|| metrics.densityDpi == DENSITY_TV
			|| metrics.densityDpi == DENSITY_XHIGH) {

			// this is a tablet!
			return DeviceType.Tablet;
		}
	}

	// this is not a tablet!
	return DeviceType.Handset;
}
 
Example 15
Source File: Chart.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 = 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 16
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 17
Source File: ActivityManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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 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
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 20
Source File: Utils.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
public static int dpToPx(int dp) {
    DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
    float px = dp * (metrics.densityDpi / DisplayMetrics.DENSITY_MEDIUM);
    return Math.round(px);
}