Java Code Examples for android.util.typedvalue#COMPLEX_UNIT_SP
The following examples show how to use
android.util.typedvalue#COMPLEX_UNIT_SP .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SizeUtils.java From AcgClub with MIT License | 6 votes |
/** * 各种单位转换 * <p>该方法存在于TypedValue</p> * * @param unit 单位 * @param value 值 * @param metrics DisplayMetrics * @return 转换结果 */ public static float applyDimension(int unit, float value, DisplayMetrics metrics) { switch (unit) { case TypedValue.COMPLEX_UNIT_PX: return value; case TypedValue.COMPLEX_UNIT_DIP: return value * metrics.density; case TypedValue.COMPLEX_UNIT_SP: return value * metrics.scaledDensity; case TypedValue.COMPLEX_UNIT_PT: return value * metrics.xdpi * (1.0f / 72); case TypedValue.COMPLEX_UNIT_IN: return value * metrics.xdpi; case TypedValue.COMPLEX_UNIT_MM: return value * metrics.xdpi * (1.0f / 25.4f); } return 0; }
Example 2
Source File: DimenUtils.java From Common with Apache License 2.0 | 6 votes |
/** * Converts an unpacked complex data value holding a dimension to its final floating * point value. The two parameters <var>unit</var> and <var>value</var> * are as in {@link TypedValue#TYPE_DIMENSION}. * * @param value The value to apply the unit to. * @param unit The unit to convert from. * @return The complex floating point value multiplied by the appropriate * metrics depending on its unit. */ public static float applyDimension(@NonNull final Context context, final float value, final int unit) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); switch (unit) { case TypedValue.COMPLEX_UNIT_PX: return value; case TypedValue.COMPLEX_UNIT_DIP: return value * metrics.density; case TypedValue.COMPLEX_UNIT_SP: return value * metrics.scaledDensity; case TypedValue.COMPLEX_UNIT_PT: return value * metrics.xdpi * (1.0f / 72); case TypedValue.COMPLEX_UNIT_IN: return value * metrics.xdpi; case TypedValue.COMPLEX_UNIT_MM: return value * metrics.xdpi * (1.0f / 25.4f); } return 0; }
Example 3
Source File: SizeUtils.java From Android-UtilCode with Apache License 2.0 | 6 votes |
/** * 各种单位转换 * <p>该方法存在于TypedValue</p> * * @param unit 单位 * @param value 值 * @param metrics DisplayMetrics * @return 转换结果 */ public static float applyDimension(int unit, float value, DisplayMetrics metrics) { switch (unit) { case TypedValue.COMPLEX_UNIT_PX: return value; case TypedValue.COMPLEX_UNIT_DIP: return value * metrics.density; case TypedValue.COMPLEX_UNIT_SP: return value * metrics.scaledDensity; case TypedValue.COMPLEX_UNIT_PT: return value * metrics.xdpi * (1.0f / 72); case TypedValue.COMPLEX_UNIT_IN: return value * metrics.xdpi; case TypedValue.COMPLEX_UNIT_MM: return value * metrics.xdpi * (1.0f / 25.4f); } return 0; }
Example 4
Source File: SizeUtils.java From Ticket-Analysis with MIT License | 6 votes |
/** * 各种单位转换 * <p>该方法存在于TypedValue */ public static float applyDimension(int unit, float value, DisplayMetrics metrics) { switch (unit) { case TypedValue.COMPLEX_UNIT_PX: return value; case TypedValue.COMPLEX_UNIT_DIP: return value * metrics.density; case TypedValue.COMPLEX_UNIT_SP: return value * metrics.scaledDensity; case TypedValue.COMPLEX_UNIT_PT: return value * metrics.xdpi * (1.0f / 72); case TypedValue.COMPLEX_UNIT_IN: return value * metrics.xdpi; case TypedValue.COMPLEX_UNIT_MM: return value * metrics.xdpi * (1.0f / 25.4f); } return 0; }
Example 5
Source File: ParametersUtils.java From HtmlNative with Apache License 2.0 | 6 votes |
@PixelValue.PixelUnit private static int getUnit(String s) throws ParametersParseException { switch (s.toLowerCase()) { default: throw new ParametersParseException("Unknown unit " + s); case "px": return TypedValue.COMPLEX_UNIT_PX; case "dp": case "dip": return TypedValue.COMPLEX_UNIT_DIP; case "sp": return TypedValue.COMPLEX_UNIT_SP; case "em": return PixelValue.EM; } }
Example 6
Source File: XDensityUtils.java From XFrame with Apache License 2.0 | 6 votes |
/** * 各种单位转换 * <p>该方法存在于TypedValue</p> * * @param unit 单位 * @param value 值 * @param metrics DisplayMetrics * @return 转换结果 */ public static float applyDimension(int unit, float value, DisplayMetrics metrics) { switch (unit) { case TypedValue.COMPLEX_UNIT_PX: return value; case TypedValue.COMPLEX_UNIT_DIP: return value * metrics.density; case TypedValue.COMPLEX_UNIT_SP: return value * metrics.scaledDensity; case TypedValue.COMPLEX_UNIT_PT: return value * metrics.xdpi * (1.0f / 72); case TypedValue.COMPLEX_UNIT_IN: return value * metrics.xdpi; case TypedValue.COMPLEX_UNIT_MM: return value * metrics.xdpi * (1.0f / 25.4f); } return 0; }
Example 7
Source File: SizeUtils.java From Matisse with Apache License 2.0 | 6 votes |
/** * 各种单位转换 * <p>该方法存在于TypedValue</p> * @param unit 单位 * @param value 值 * @param metrics DisplayMetrics * @return 转换结果 */ public static float applyDimension(int unit, float value, DisplayMetrics metrics) { switch (unit) { case TypedValue.COMPLEX_UNIT_PX: return value; case TypedValue.COMPLEX_UNIT_DIP: return value * metrics.density; case TypedValue.COMPLEX_UNIT_SP: return value * metrics.scaledDensity; case TypedValue.COMPLEX_UNIT_PT: return value * metrics.xdpi * (1.0f / 72); case TypedValue.COMPLEX_UNIT_IN: return value * metrics.xdpi; case TypedValue.COMPLEX_UNIT_MM: return value * metrics.xdpi * (1.0f / 25.4f); } return 0; }
Example 8
Source File: SizeUtils.java From AndroidUtilCode with Apache License 2.0 | 6 votes |
/** * Converts an unpacked complex data value holding a dimension to its final floating * point value. The two parameters <var>unit</var> and <var>value</var> * are as in {@link TypedValue#TYPE_DIMENSION}. * * @param value The value to apply the unit to. * @param unit The unit to convert from. * @return The complex floating point value multiplied by the appropriate * metrics depending on its unit. */ public static float applyDimension(final float value, final int unit) { DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); switch (unit) { case TypedValue.COMPLEX_UNIT_PX: return value; case TypedValue.COMPLEX_UNIT_DIP: return value * metrics.density; case TypedValue.COMPLEX_UNIT_SP: return value * metrics.scaledDensity; case TypedValue.COMPLEX_UNIT_PT: return value * metrics.xdpi * (1.0f / 72); case TypedValue.COMPLEX_UNIT_IN: return value * metrics.xdpi; case TypedValue.COMPLEX_UNIT_MM: return value * metrics.xdpi * (1.0f / 25.4f); } return 0; }
Example 9
Source File: MixtureTextView.java From MixtureTextView with Apache License 2.0 | 6 votes |
public void setTextSize(int unit, int size) { switch (unit) { case TypedValue.COMPLEX_UNIT_PX: mTextSize = size; break; case TypedValue.COMPLEX_UNIT_DIP: mTextSize = dp2px(size); break; case TypedValue.COMPLEX_UNIT_SP: mTextSize = sp2px(size); break; } mTextPaint.setTextSize(mTextSize); requestLayout(); invalidate(); }
Example 10
Source File: DimensionParser.java From android-cassowary-layout with Apache License 2.0 | 6 votes |
private static int getUnitFromString(String unitString) { int unit = TypedValue.COMPLEX_UNIT_DIP; if ("px".equals(unitString)) { unit = TypedValue.COMPLEX_UNIT_PX; } else if ("dp".equals(unitString)) { unit = TypedValue.COMPLEX_UNIT_DIP; } else if ("sp".equals(unitString)) { unit = TypedValue.COMPLEX_UNIT_SP; } else if ("pt".equals(unitString)) { unit = TypedValue.COMPLEX_UNIT_PT; } else if ("in".equals(unitString)) { unit = TypedValue.COMPLEX_UNIT_IN; } else if ("mm".equals(unitString)) { unit = TypedValue.COMPLEX_UNIT_MM; } return unit; }
Example 11
Source File: PixelValue.java From HtmlNative with Apache License 2.0 | 5 votes |
public final float getPxValue() { switch (unit) { case EM: return this.value / 16.f; case TypedValue.COMPLEX_UNIT_PX: return this.value; case TypedValue.COMPLEX_UNIT_SP: return ParametersUtils.spToPx(this.value); case TypedValue.COMPLEX_UNIT_DIP: return ParametersUtils.dpToPx(this.value); default: return value; } }
Example 12
Source File: DimensionResource.java From external-resources with Apache License 2.0 | 5 votes |
protected static int getTypeFromString(@NonNull String str) { String[] split = str.trim().split("[0-9]"); if (split.length > 0) { final String typeStr = split[split.length - 1]; switch (typeStr) { case TYPE_DP: case TYPE_DIP: return TypedValue.COMPLEX_UNIT_DIP; case TYPE_SP: return TypedValue.COMPLEX_UNIT_SP; case TYPE_PT: return TypedValue.COMPLEX_UNIT_PT; case TYPE_IN: return TypedValue.COMPLEX_UNIT_IN; case TYPE_MM: return TypedValue.COMPLEX_UNIT_MM; case TYPE_PX: return TypedValue.COMPLEX_UNIT_PX; default: throw new IllegalArgumentException(typeStr + " is not a valid type dimension format."); } } else { return TypedValue.COMPLEX_UNIT_PX; } }
Example 13
Source File: XmlToClassAttribHandler.java From MVPAndroidBootstrap with Apache License 2.0 | 5 votes |
public int gettextSizeUnit() { String value=mAttributeSet.getAttributeValue(namespace, KEY_TEXT_SIZE ); if (value==null) return TypedValue.COMPLEX_UNIT_SP; try{ String type=value.substring(value.length()-2, value.length()); if (type.equals("dp")) return TypedValue.COMPLEX_UNIT_DIP; else if (type.equals("sp")) return TypedValue.COMPLEX_UNIT_SP; else if (type.equals("pt")) return TypedValue.COMPLEX_UNIT_PT; else if (type.equals("mm")) return TypedValue.COMPLEX_UNIT_MM; else if (type.equals("in")) return TypedValue.COMPLEX_UNIT_IN; else if (type.equals("px")) return TypedValue.COMPLEX_UNIT_PX; } catch(Exception e){ return -1; } return -1; }
Example 14
Source File: XmlToClassAttribHandler.java From RxAndroidBootstrap with Apache License 2.0 | 5 votes |
public int gettextSizeUnit() { String value=mAttributeSet.getAttributeValue(namespace, KEY_TEXT_SIZE ); if (value==null) return TypedValue.COMPLEX_UNIT_SP; try{ String type=value.substring(value.length()-2, value.length()); if (type.equals("dp")) return TypedValue.COMPLEX_UNIT_DIP; else if (type.equals("sp")) return TypedValue.COMPLEX_UNIT_SP; else if (type.equals("pt")) return TypedValue.COMPLEX_UNIT_PT; else if (type.equals("mm")) return TypedValue.COMPLEX_UNIT_MM; else if (type.equals("in")) return TypedValue.COMPLEX_UNIT_IN; else if (type.equals("px")) return TypedValue.COMPLEX_UNIT_PX; } catch(Exception e){ return -1; } return -1; }
Example 15
Source File: ButtonView.java From react-native-android-kit with MIT License | 4 votes |
public void setTextSize(int size) { super.setTextSize(TypedValue.COMPLEX_UNIT_SP, size); return; }
Example 16
Source File: ButtonView.java From react-native-android-kit with MIT License | 4 votes |
public void setTextSize(int size) { super.setTextSize(TypedValue.COMPLEX_UNIT_SP, size); return; }