List of usage examples for android.util DisplayMetrics DENSITY_DEFAULT
int DENSITY_DEFAULT
To view the source code for android.util DisplayMetrics DENSITY_DEFAULT.
Click Source Link
From source file:Main.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 *//* www .j a va 2 s.co m*/ public static float convertPixelsToDp(float px, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float dp = px / ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); return dp; }
From source file:Main.java
/** * 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 *//*from w ww. ja v a 2 s . c o m*/ 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; }
From source file:Main.java
/** * Get bitmap from a URI.// w w w .j a v a2 s.co m * * @param context The context. * @param uriString The URI as a string. * * @return The bitmap. */ public static Bitmap getBitmapFromUri(final Context context, String uriString) { Bitmap bitmap = null; if (uriString == null) { return null; } Uri uri = Uri.parse(uriString); if (uri != null) { try { bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri); if (bitmap != null) { // We use default density for all bitmaps to avoid scaling. bitmap.setDensity(DisplayMetrics.DENSITY_DEFAULT); } } catch (IOException e) { } } return bitmap; }
From source file:Main.java
public static float convertDpToPixel(float dp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * (metrics.densityDpi / (float) DisplayMetrics.DENSITY_DEFAULT); return px;//from w ww. ja v a 2s .c o m }
From source file:com.calgen.udacity.lego.ui.Utils.java
/** * @param dp dp value//from w w w . j ava 2 s . c om * @return converted px value */ public static int dpToPx(int dp) { DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics(); return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)); }
From source file:com.calgen.udacity.lego.ui.Utils.java
/** * @param px dp value//w ww. ja v a 2 s .c o m * @return converted dp value */ public static int pxToDp(int px) { DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics(); return Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)); }
From source file:Main.java
/** * Checks if the device is a tablet or a phone * * @param activityContext/*from www . j av a 2 s. c o m*/ * The Activity Context. * @return Returns true if the device is a Tablet */ public static boolean isTabletDevice(Context activityContext) { // Verifies if the Generalized Size of the device is XLARGE to be // considered a Tablet boolean xlarge = ((activityContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE); // If XLarge, checks if the Generalized Density is at least MDPI // (160dpi) if (xlarge) { DisplayMetrics metrics = new DisplayMetrics(); Activity activity = (Activity) activityContext; activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); // MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160, // DENSITY_TV=213, DENSITY_XHIGH=320 if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM || metrics.densityDpi == DisplayMetrics.DENSITY_TV || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) { // Yes, this is a tablet! return true; } } // No, this is not a tablet! return false; }
From source file:org.kaaproject.kaa.demo.notification.fragment.BaseListFragment.java
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; }
From source file:me.ccrama.redditslide.Views.SubtleSlideInUp.java
public int pxToDp(int px, Context c) { DisplayMetrics displayMetrics = c.getResources().getDisplayMetrics(); int dp = Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)); return dp;/*from w ww.j ava2 s. c om*/ }
From source file:ch.rts.cordova.is.tablet.IsTablet.java
private boolean isTabletDevice(Context applicationContext) { boolean device_large = ((applicationContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE); if (device_large) { DisplayMetrics metrics = new DisplayMetrics(); Activity activity = this.cordova.getActivity(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM || metrics.densityDpi == DisplayMetrics.DENSITY_TV || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) { Log.d(LOG_TAG, "Is Tablet Device"); return true; }//from w w w. ja v a2s.c o m } Log.d(LOG_TAG, "Is NOT Tablet Device"); return false; }