Java Code Examples for android.util.DisplayMetrics#DENSITY_XXXHIGH

The following examples show how to use android.util.DisplayMetrics#DENSITY_XXXHIGH . 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: DeviceInfo.java    From Cangol-appcore with Apache License 2.0 6 votes vote down vote up
/**
 * 获取设备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 3
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 4
Source File: DebugView.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 5
Source File: BugReportLens.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 6
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 7
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 8
Source File: DeviceInfoModule.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 "unknown";
    }
}
 
Example 9
Source File: WeekLabelView.java    From Android-LunarView with Apache License 2.0 6 votes vote down vote up
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 10
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 11
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 12
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 13
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 14
Source File: DrawableHelper.java    From candybar-library with Apache License 2.0 6 votes vote down vote up
@Nullable
public static Drawable getHighQualityIcon(@NonNull Context context, String packageName) {
    try {
        PackageManager packageManager = context.getPackageManager();
        ApplicationInfo info = packageManager.getApplicationInfo(
                packageName, PackageManager.GET_META_DATA);

        Resources resources = packageManager.getResourcesForApplication(packageName);
        int density = DisplayMetrics.DENSITY_XXHIGH;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            density = DisplayMetrics.DENSITY_XXXHIGH;
        }

        Drawable drawable = ResourcesCompat.getDrawableForDensity(
                resources, info.icon, density, null);
        if (drawable != null) return drawable;
        return info.loadIcon(packageManager);
    } catch (Exception | OutOfMemoryError e) {
        LogUtil.e(Log.getStackTraceString(e));
    }
    return null;
}
 
Example 15
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 16
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 17
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 18
Source File: EmailDeviceInfoLens.java    From telescope with Apache License 2.0 5 votes vote down vote up
public static String getDensityString(DisplayMetrics displayMetrics) {
  switch (displayMetrics.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_260:
    case DisplayMetrics.DENSITY_280:
    case DisplayMetrics.DENSITY_300:
    case DisplayMetrics.DENSITY_XHIGH:
      return "xhdpi";
    case DisplayMetrics.DENSITY_340:
    case DisplayMetrics.DENSITY_360:
    case DisplayMetrics.DENSITY_400:
    case DisplayMetrics.DENSITY_420:
    case DisplayMetrics.DENSITY_XXHIGH:
      return "xxhdpi";
    case DisplayMetrics.DENSITY_560:
    case DisplayMetrics.DENSITY_XXXHIGH:
      return "xxxhdpi";
    default:
      return "unknown";
  }
}
 
Example 19
Source File: OverlayDisplayAdapter.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void updateOverlayDisplayDevicesLocked() {
    String value = Settings.Global.getString(getContext().getContentResolver(),
            Settings.Global.OVERLAY_DISPLAY_DEVICES);
    if (value == null) {
        value = "";
    }

    if (value.equals(mCurrentOverlaySetting)) {
        return;
    }
    mCurrentOverlaySetting = value;

    if (!mOverlays.isEmpty()) {
        Slog.i(TAG, "Dismissing all overlay display devices.");
        for (OverlayDisplayHandle overlay : mOverlays) {
            overlay.dismissLocked();
        }
        mOverlays.clear();
    }

    int count = 0;
    for (String part : value.split(";")) {
        Matcher displayMatcher = DISPLAY_PATTERN.matcher(part);
        if (displayMatcher.matches()) {
            if (count >= 4) {
                Slog.w(TAG, "Too many overlay display devices specified: " + value);
                break;
            }
            String modeString = displayMatcher.group(1);
            String flagString = displayMatcher.group(2);
            ArrayList<OverlayMode> modes = new ArrayList<>();
            for (String mode : modeString.split("\\|")) {
                Matcher modeMatcher = MODE_PATTERN.matcher(mode);
                if (modeMatcher.matches()) {
                    try {
                        int width = Integer.parseInt(modeMatcher.group(1), 10);
                        int height = Integer.parseInt(modeMatcher.group(2), 10);
                        int densityDpi = Integer.parseInt(modeMatcher.group(3), 10);
                        if (width >= MIN_WIDTH && width <= MAX_WIDTH
                                && height >= MIN_HEIGHT && height <= MAX_HEIGHT
                                && densityDpi >= DisplayMetrics.DENSITY_LOW
                                && densityDpi <= DisplayMetrics.DENSITY_XXXHIGH) {
                            modes.add(new OverlayMode(width, height, densityDpi));
                            continue;
                        } else {
                            Slog.w(TAG, "Ignoring out-of-range overlay display mode: " + mode);
                        }
                    } catch (NumberFormatException ex) {
                    }
                } else if (mode.isEmpty()) {
                    continue;
                }
            }
            if (!modes.isEmpty()) {
                int number = ++count;
                String name = getContext().getResources().getString(
                        com.android.internal.R.string.display_manager_overlay_display_name,
                        number);
                int gravity = chooseOverlayGravity(number);
                boolean secure = flagString != null && flagString.contains(",secure");

                Slog.i(TAG, "Showing overlay display device #" + number
                        + ": name=" + name + ", modes=" + Arrays.toString(modes.toArray()));

                mOverlays.add(new OverlayDisplayHandle(name, modes, gravity, secure, number));
                continue;
            }
        }
        Slog.w(TAG, "Malformed overlay display devices setting: " + value);
    }
}