Android Open Source - CheckListView Density Util






From Project

Back to project page CheckListView.

License

The source code is released under:

Apache License

If you think the Android project CheckListView listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package it.feio.android.checklistview.utils;
//from  w w w  .j  ava  2  s  .  c om
import android.content.Context;
import android.util.DisplayMetrics;

public class DensityUtil {

    private DensityUtil(){

    }

    /**
     * This method converts dp unit to equivalent pixels, depending on device
     * density.
     *
     * @param dp      A value in dp (density independent pixels) unit. Which we need
     *                to convert into pixels
     * @param context Context to get resources and device specific display metrics
     * @return A float value to represent px equivalent to dp depending on
     * device density
     */
    public static int dpToPx(float dp, Context context) {
        DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
        int px = Math.round(dp * (displayMetrics.densityDpi / 160f));
        return px;
    }

    /**
     * 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
     */
    public static int pxToDp(float px, Context context) {
        DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
        int dp = Math.round(px / (displayMetrics.densityDpi / 160f));
        return dp;
    }
}




Java Source Code List

it.feio.android.checklistview.App.java
it.feio.android.checklistview.ChecklistManager.java
it.feio.android.checklistview.Settings.java
it.feio.android.checklistview.demo.MainActivity.java
it.feio.android.checklistview.demo.SettingsActivity.java
it.feio.android.checklistview.dragging.ChecklistViewDragShadowBuilder.java
it.feio.android.checklistview.dragging.ChecklistViewItemOnDragListener.java
it.feio.android.checklistview.dragging.ChecklistViewOnTouchListener.java
it.feio.android.checklistview.exceptions.ViewNotSupportedException.java
it.feio.android.checklistview.interfaces.CheckListChangedListener.java
it.feio.android.checklistview.interfaces.CheckListEventListener.java
it.feio.android.checklistview.interfaces.Constants.java
it.feio.android.checklistview.interfaces.EditTextEventListener.java
it.feio.android.checklistview.models.CheckListViewItem.java
it.feio.android.checklistview.models.CheckListView.java
it.feio.android.checklistview.models.EditTextMultiLineNoEnter.java
it.feio.android.checklistview.utils.AlphaManager.java
it.feio.android.checklistview.utils.DensityUtil.java