Files
react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/PixelUtil.java
Andrei Coman 228a1fe7d4 Expose screen metrics and window metrics
Summary:
public
https://github.com/facebook/react-native/pull/4935 changed the window dimensions for android by replacing them with the actual screen dimensions. This changes the window dimensions back to their original values and adds `Dimensions.get('screen')` for the actual screen dimensions of the device.

Reviewed By: astreet

Differential Revision: D2921584

fb-gh-sync-id: 5d2677029c71d50691691dc651a11e9c8b115e8f
shipit-source-id: 5d2677029c71d50691691dc651a11e9c8b115e8f
2016-02-11 06:33:36 -08:00

61 lines
1.4 KiB
Java

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.uimanager;
import android.util.TypedValue;
/**
* Android dp to pixel manipulation
*/
public class PixelUtil {
/**
* Convert from DIP to PX
*/
public static float toPixelFromDIP(float value) {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
value,
DisplayMetricsHolder.getWindowDisplayMetrics());
}
/**
* Convert from DIP to PX
*/
public static float toPixelFromDIP(double value) {
return toPixelFromDIP((float) value);
}
/**
* Convert from SP to PX
*/
public static float toPixelFromSP(float value) {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP,
value,
DisplayMetricsHolder.getWindowDisplayMetrics());
}
/**
* Convert from SP to PX
*/
public static float toPixelFromSP(double value) {
return toPixelFromSP((float) value);
}
/**
* Convert from PX to DP
*/
public static float toDIPFromPixel(float value) {
return value / DisplayMetricsHolder.getWindowDisplayMetrics().density;
}
}