android.util.DisplayMetrics#DENSITY_DEFAULT源码实例Demo

下面列出了android.util.DisplayMetrics#DENSITY_DEFAULT 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Trebuchet   文件: InvariantDeviceProfile.java
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;
}
 
源代码2 项目: GravityBox   文件: Utils.java
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;
}
 
/**
 * Set the density at which this drawable will be rendered.
 *
 * @param density The density scale for this drawable.
 *
 * @see android.graphics.Bitmap#setDensity(int)
 * @see android.graphics.Bitmap#getDensity()
 */
public void setTargetDensity(int density) {
    if (mTargetDensity != density) {
        mTargetDensity = density == 0 ? DisplayMetrics.DENSITY_DEFAULT : density;
        if (mBitmap != null) {
            computeBitmapSize();
        }
        invalidateSelf();
    }
}
 
源代码4 项目: SecondScreen   文件: U.java
public static boolean isBlacklisted(Context context, String requestedRes, String requestedDpi) {
    boolean blacklisted = false;

    SharedPreferences prefMain = getPrefMain(context);
    int defaultHeight = prefMain.getInt("height", 0);
    int defaultWidth = prefMain.getInt("width", 0);
    int defaultDpi = getSystemProperty("ro.sf.lcd_density", prefMain.getInt("density", 0));

    int height, width, density;
    if("reset".equals(requestedRes)) {
        height = defaultHeight;
        width = defaultWidth;
    } else {
        Scanner scanner = new Scanner(requestedRes);
        scanner.useDelimiter("x");

        width = scanner.nextInt();
        height = scanner.nextInt();

        scanner.close();
    }

    if("reset".equals(requestedDpi))
        density = defaultDpi;
    else
        density = Integer.parseInt(requestedDpi);

    // Blacklist DPI values that result in a smallest width that's too low or too high
    int smallestWidth = (DisplayMetrics.DENSITY_DEFAULT * Math.min(height, width)) / density;
    if(smallestWidth < 320 || smallestWidth > 1280)
        blacklisted = true;

    // On Android 10, blacklist resolutions that are larger than the device's native resolution
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && (height > defaultHeight || width > defaultWidth))
        blacklisted = true;

    return blacklisted;
}
 
源代码5 项目: ExpansionPanel   文件: Utils.java
public static float pxToDp(Context context, float px) {
    return px / ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
 
源代码6 项目: similarLoadingView   文件: SimilarLoadingView.java
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 项目: MagicalExoPlayer   文件: PublicFunctions.java
public static int convertDpToPixel(Context context, float dp) {
    return (int) (dp * (context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT));
}
 
源代码8 项目: WatermarkCreator   文件: MainActivity.java
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;
}
 
源代码9 项目: SwipeRevealLayout   文件: SwipeRevealLayout.java
private int pxToDp(int px) {
    Resources resources = getContext().getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    return (int) (px / ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT));
}
 
源代码10 项目: LaunchEnr   文件: Utilities.java
static float dpiFromPx(int size, DisplayMetrics metrics){
    float densityRatio = (float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT;
    return (size / densityRatio);
}
 
源代码11 项目: react-native-navigation   文件: UiUtils.java
public static int dpToPx(Context context, int dp) {
    if (dp <= 0) return dp;
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    return (int) (dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT));
}
 
源代码12 项目: geopackage-android   文件: IconCache.java
/**
 * Create or retrieve from cache an icon bitmap for the icon row
 *
 * @param icon      icon row
 * @param density   display density: {@link android.util.DisplayMetrics#density}
 * @param iconCache icon cache
 * @return icon bitmap
 */
public static Bitmap createIcon(IconRow icon, float density, IconCache iconCache) {

    Bitmap iconImage = null;

    if (icon != null) {

        if (iconCache != null) {
            iconImage = iconCache.get(icon.getId());
        }

        if (iconImage == null) {

            BitmapFactory.Options options = icon.getDataBounds();
            int dataWidth = options.outWidth;
            int dataHeight = options.outHeight;

            double styleWidth = dataWidth;
            double styleHeight = dataHeight;

            double widthDensity = DisplayMetrics.DENSITY_DEFAULT;
            double heightDensity = DisplayMetrics.DENSITY_DEFAULT;

            if (icon.getWidth() != null) {
                styleWidth = icon.getWidth();
                double widthRatio = dataWidth / styleWidth;
                widthDensity *= widthRatio;
                if (icon.getHeight() == null) {
                    heightDensity = widthDensity;
                }
            }

            if (icon.getHeight() != null) {
                styleHeight = icon.getHeight();
                double heightRatio = dataHeight / styleHeight;
                heightDensity *= heightRatio;
                if (icon.getWidth() == null) {
                    widthDensity = heightDensity;
                }
            }

            options = new BitmapFactory.Options();
            options.inDensity = (int) (Math.min(widthDensity, heightDensity) + 0.5f);
            options.inTargetDensity = (int) (DisplayMetrics.DENSITY_DEFAULT * density + 0.5f);

            iconImage = icon.getDataBitmap(options);

            if (widthDensity != heightDensity) {

                int width = (int) (styleWidth * density + 0.5f);
                int height = (int) (styleHeight * density + 0.5f);

                if (width != iconImage.getWidth() || height != iconImage.getHeight()) {
                    Bitmap scaledBitmap = Bitmap.createScaledBitmap(iconImage, width, height, false);
                    iconImage.recycle();
                    iconImage = scaledBitmap;
                }

            }

            if (iconCache != null) {
                iconCache.put(icon.getId(), iconImage);
            }
        }

    }

    return iconImage;
}
 
源代码13 项目: 1Rramp-Android   文件: ViewExpanderCollapser.java
private static float getPixelScaleFactor(Context context) {
  DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
  return (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT);
}
 
源代码14 项目: 4pdaClient-plus   文件: Utils.java
public static int dpToPix(int dp, DisplayMetrics metrics) {
    return (dp * metrics.densityDpi) / DisplayMetrics.DENSITY_DEFAULT;
}
 
public static int convertDpToPixel(float dp, Context context){
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    float px = dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
    return (int)px;
}
 
源代码16 项目: ChatView   文件: MessageAdapter.java
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;
}
 
源代码17 项目: prayer-times-android   文件: Utils.java
/**
 * This method converts dp unit to equivalent pixels, depending on device density.
 *
 * @param context Context to get resources and device specific display metrics
 * @param dp      A value in dp (density independent pixels) unit. Which we need to convert into pixels
 * @return A float value to represent px equivalent to dp depending on device density
 */
public static float convertDpToPixel(Context context, float dp) {
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    return dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
 
源代码18 项目: call_manage   文件: Utilities.java
/**
 * This method converts device specific pixels to density independent pixels.
 *
 * @param context Context to get resources and device specific display metrics
 * @param px      A value in px (pixels) unit. Which we need to convert into db
 * @return A float value to represent dp equivalent to px value
 */
public static float convertPixelsToDp(Context context, float px) {
    return px / (dpi(context) / DisplayMetrics.DENSITY_DEFAULT);
}
 
源代码19 项目: mage-android   文件: ObservationShapeStyle.java
/**
 * Set the stroke width
 *
 * @param strokeWidth stroke width
 */
public void setStrokeWidth(float strokeWidth) {
    this.strokeWidth = strokeWidth * (displayMetrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
 
源代码20 项目: FABsMenu   文件: DimensionUtils.java
/**
 * 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
 */
static float convertPixelsToDp(float px, Context context) {
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    return px / ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}