/* * This is the source code of DMPLayer for Android v. 1.0.0. * You should have received a copy of the license in this archive (see LICENSE). * Copyright @Dibakar_Mistry, 2015. */ package com.dmplayer.uicomponent; import android.content.res.Resources; import android.util.TypedValue; import android.view.View; public class ViewHelperUtils { /** * Convert Dp to Pixel */ public static int dpToPx(float dp, Resources resources) { float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics()); return (int) px; } public static int getRelativeTop(View myView) { // if (myView.getParent() == myView.getRootView()) if (myView.getId() == android.R.id.content) return myView.getTop(); else return myView.getTop() + getRelativeTop((View) myView.getParent()); } public static int getRelativeLeft(View myView) { // if (myView.getParent() == myView.getRootView()) if (myView.getId() == android.R.id.content) return myView.getLeft(); else return myView.getLeft() + getRelativeLeft((View) myView.getParent()); } }