Example usage for android.util DisplayMetrics DENSITY_DEFAULT

List of usage examples for android.util DisplayMetrics DENSITY_DEFAULT

Introduction

In this page you can find the example usage for android.util DisplayMetrics DENSITY_DEFAULT.

Prototype

int DENSITY_DEFAULT

To view the source code for android.util DisplayMetrics DENSITY_DEFAULT.

Click Source Link

Document

The reference density used throughout the system.

Usage

From source file:com.amaze.carbonfilemanager.fragments.ZipViewer.java

public int dpToPx(int dp) {
    DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
    int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;/*from   w  w w. j  a v a2s . c o  m*/
}

From source file:edu.ttu.spm.cheapride.MainActivity.java

public void activateComparisonChart(RideEstimateDTO rideEstimateDto) {

    Resources resources = this.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    float pxRatio = ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);

    double uberTimeWidth = this.getUberTimeWidth(rideEstimateDto);
    double lyftTimeWidth = this.getLyftTimeWidth(rideEstimateDto);

    this.uberArrivalTime.setWidth((int) (uberTimeWidth * pxRatio));
    this.uberArrivalTime.setText(String.valueOf(rideEstimateDto.getUberArrivalTime()));
    this.lyftArrivalTime.setWidth((int) (lyftTimeWidth * pxRatio));
    this.lyftArrivalTime.setText(String.valueOf(rideEstimateDto.getLyftArrivalTime()));

    double uberCostWidth = this.getUberCostWidth(rideEstimateDto);
    double lyftCostWidth = this.getLyftCostWidth(rideEstimateDto);

    this.uberCost.setWidth((int) (uberCostWidth * pxRatio));
    this.uberCost.setText(String.valueOf(rideEstimateDto.getUberCost()));
    this.lyftCost.setWidth((int) (lyftCostWidth * pxRatio));
    this.lyftCost.setText(String.valueOf(rideEstimateDto.getLyftCost()));

    this.comparisonChart.setVisibility(View.VISIBLE);

    if (LoginActivity.isLogin) {
        driveInfoBoard.setVisibility(View.INVISIBLE);
        this.rideBooking.setVisibility(View.VISIBLE);
        bookingButtons.setVisibility(View.VISIBLE);
    }//from w  w w  .j a  v a  2  s  .c o  m
}

From source file:app.akexorcist.gdaplibrary.GoogleDirection.java

private int dpToPx(int dp) {
    DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
    int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;/*from  w  w w  .  j a v a2s  . c  o m*/
}

From source file:com.hippo.vector.VectorDrawable.java

void updateDimensionInfo(@Nullable Resources res, boolean updateConstantStateDensity) {
    if (res != null) {
        final int densityDpi = res.getDisplayMetrics().densityDpi;
        final int targetDensity = densityDpi == 0 ? DisplayMetrics.DENSITY_DEFAULT : densityDpi;

        if (updateConstantStateDensity) {
            mVectorState.mVPathRenderer.mTargetDensity = targetDensity;
        } else {//from ww  w .  j  ava 2 s .co m
            final int constantStateDensity = mVectorState.mVPathRenderer.mTargetDensity;
            if (targetDensity != constantStateDensity && constantStateDensity != 0) {
                mDpiScaledWidth = Utils.scaleFromDensity((int) mVectorState.mVPathRenderer.mBaseWidth,
                        constantStateDensity, targetDensity);
                mDpiScaledHeight = Utils.scaleFromDensity((int) mVectorState.mVPathRenderer.mBaseHeight,
                        constantStateDensity, targetDensity);
                final int left = Utils.scaleFromDensity(mVectorState.mVPathRenderer.mOpticalInsets.left,
                        constantStateDensity, targetDensity);
                final int right = Utils.scaleFromDensity(mVectorState.mVPathRenderer.mOpticalInsets.right,
                        constantStateDensity, targetDensity);
                final int top = Utils.scaleFromDensity(mVectorState.mVPathRenderer.mOpticalInsets.top,
                        constantStateDensity, targetDensity);
                final int bottom = Utils.scaleFromDensity(mVectorState.mVPathRenderer.mOpticalInsets.bottom,
                        constantStateDensity, targetDensity);
                mDpiScaleInsets = Insets.of(left, top, right, bottom);
                return;
            }
        }
    }
    // For all the other cases, like either res is null, constant state is not initialized or
    // target density is the same as the constant state, we will just use the constant state
    // dimensions.
    mDpiScaledWidth = (int) mVectorState.mVPathRenderer.mBaseWidth;
    mDpiScaledHeight = (int) mVectorState.mVPathRenderer.mBaseHeight;
    mDpiScaleInsets = mVectorState.mVPathRenderer.mOpticalInsets;
}

From source file:com.bettervectordrawable.lib.graphics.drawable.VectorDrawable.java

void updateDimensionInfo(@Nullable Resources res, boolean updateConstantStateDensity) {
    if (res != null) {
        final int densityDpi = res.getDisplayMetrics().densityDpi;
        final int targetDensity = densityDpi == 0 ? DisplayMetrics.DENSITY_DEFAULT : densityDpi;
        if (updateConstantStateDensity) {
            mVectorState.mVPathRenderer.mTargetDensity = targetDensity;
        } else {//www .  j  a  v a 2  s  .com
            final int constantStateDensity = mVectorState.mVPathRenderer.mTargetDensity;
            if (targetDensity != constantStateDensity && constantStateDensity != 0) {
                mDpiScaledWidth = BitmapExtension.scaleFromDensity((int) mVectorState.mVPathRenderer.mBaseWidth,
                        constantStateDensity, targetDensity);
                mDpiScaledHeight = BitmapExtension.scaleFromDensity(
                        (int) mVectorState.mVPathRenderer.mBaseHeight, constantStateDensity, targetDensity);
                final int left = BitmapExtension.scaleFromDensity(
                        mVectorState.mVPathRenderer.mOpticalInsets.left, constantStateDensity, targetDensity);
                final int right = BitmapExtension.scaleFromDensity(
                        mVectorState.mVPathRenderer.mOpticalInsets.right, constantStateDensity, targetDensity);
                final int top = BitmapExtension.scaleFromDensity(mVectorState.mVPathRenderer.mOpticalInsets.top,
                        constantStateDensity, targetDensity);
                final int bottom = BitmapExtension.scaleFromDensity(
                        mVectorState.mVPathRenderer.mOpticalInsets.bottom, constantStateDensity, targetDensity);
                mDpiScaleInsets = Insets.of(left, top, right, bottom);
                return;
            }
        }
    }
    // For all the other cases, like either res is null, constant state is not initialized or
    // target density is the same as the constant state, we will just use the constant state
    // dimensions.
    mDpiScaledWidth = (int) mVectorState.mVPathRenderer.mBaseWidth;
    mDpiScaledHeight = (int) mVectorState.mVPathRenderer.mBaseHeight;
    mDpiScaleInsets = mVectorState.mVPathRenderer.mOpticalInsets;
}

From source file:com.gh4a.utils.HttpImageGetter.java

private static Bitmap renderSvgToBitmap(Resources res, InputStream is, int maxWidth, int maxHeight) {
    //noinspection TryWithIdenticalCatches
    try {//  ww  w .jav a 2 s  . com
        SVG svg = SVG.getFromInputStream(is);
        if (svg != null) {
            svg.setRenderDPI(DisplayMetrics.DENSITY_DEFAULT);
            Float density = res.getDisplayMetrics().density;
            int docWidth = (int) (svg.getDocumentWidth() * density);
            int docHeight = (int) (svg.getDocumentHeight() * density);
            if (docWidth < 0 || docHeight < 0) {
                float aspectRatio = svg.getDocumentAspectRatio();
                if (aspectRatio > 0) {
                    float heightForAspect = (float) maxWidth / aspectRatio;
                    float widthForAspect = (float) maxHeight * aspectRatio;
                    if (widthForAspect < heightForAspect) {
                        docWidth = Math.round(widthForAspect);
                        docHeight = maxHeight;
                    } else {
                        docWidth = maxWidth;
                        docHeight = Math.round(heightForAspect);
                    }
                } else {
                    docWidth = maxWidth;
                    docHeight = maxHeight;
                }

                // we didn't take density into account anymore when calculating docWidth
                // and docHeight, so don't scale with it and just let the renderer
                // figure out the scaling
                density = null;
            }

            while (docWidth >= maxWidth || docHeight >= maxHeight) {
                docWidth /= 2;
                docHeight /= 2;
                if (density != null) {
                    density /= 2;
                }
            }

            Bitmap bitmap = Bitmap.createBitmap(docWidth, docHeight, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            if (density != null) {
                canvas.scale(density, density);
            }
            svg.renderToCanvas(canvas);
            return bitmap;
        }
    } catch (SVGParseException e) {
        // fall through
    } catch (NullPointerException e) {
        // https://github.com/BigBadaboom/androidsvg/issues/81
        // remove me when there's a 1.2.3 release
    }
    return null;
}

From source file:com.softminds.matrixcalculator.base_activities.FillingMatrix.java

private int ConvertTopx(float dp) {
    DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
    return ((int) (dp * ((float) metrics.densityDpi) / DisplayMetrics.DENSITY_DEFAULT));

}

From source file:com.github.rubensousa.floatingtoolbar.FloatingToolbar.java

static float dpToPixels(Context context, int dp) {
    return context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT * dp;
}

From source file:com.sinyuk.jianyimaterial.widgets.FloatingToolbar.java

private float dpToPixels(int dp) {
    return Resources.getSystem().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT * dp;
}

From source file:com.chauthai.overscroll.BouncyAdapter.java

private double dpToPx(double dp) {
    Resources resources = mContext.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    return dp * ((double) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}