-
public class StyleHelperHelper class for Style-related methods. If you want to implement rules that are applied to all views, that's the right place. Also contains some general measurement/general purpose helpers.
-
-
Method Summary
Modifier and Type Method Description static DocumentparseStyle(@Nullable() String css)Parse raw css static voidapplyCommonRules(View targetView, Map<String, String> rules)Apply common rules to a view. static FlexboxLayout.LayoutParamsgetFlexLayoutParams(Context context, FlexboxLayout.LayoutParams baseParams, Map<String, String> rules)Generate FlexboxLayout.LayoutParams for the given CSS rules. static PercentRelativeLayout.LayoutParamsgetRelativeLayoutParams(Context context, PercentRelativeLayout.LayoutParams base, Map<String, String> rules, int defaultHorizontalAlign, View relativeToView)Generate RelativeLayout.LayoutParams for the given CSS rules. static FrameLayout.LayoutParamsgetFrameLayoutParams(Context context, FrameLayout.LayoutParams base, Map<String, String> rules)Generate FrameLayout.LayoutParams for the given CSS rules. static intdpToPixels(Resources resources, Float dp)Converts a density-independent pixels measurement value to pixels. static floatpixelsToDp(Resources resources, Float px)Converts a pixels measurement value to density-independent pixels. static IntegeroptInt(String stringValue)Returns the integer value of a string.Doesn't throw an exception if it fails. static FloatoptFloat(String stringValue)Returns the float value of a string.Doesn't throw an exception if it fails. static intparseColor(String color)Parse a color. static intdarkenColor(int color)Darkens a color, using HSL -
-
Method Detail
-
parseStyle
static Document parseStyle(@Nullable() String css)
Parse raw css
-
applyCommonRules
static void applyCommonRules(View targetView, Map<String, String> rules)
Apply common rules to a view.
While this method tries to peek at the View's class to avoid code duplication (especially for the background drawable stuff),a view implementing specific rules should extends its base class and implement the com.batch.android.messaging.view.styled.Styleable interface.
- Parameters:
targetView- View that the rules will be applied to.rules- CSS-like rules.
-
getFlexLayoutParams
static FlexboxLayout.LayoutParams getFlexLayoutParams(Context context, FlexboxLayout.LayoutParams baseParams, Map<String, String> rules)
Generate FlexboxLayout.LayoutParams for the given CSS rules.
- Parameters:
context- The view's contextbaseParams- Base layout parameters.rules- CSS-like rules
-
getRelativeLayoutParams
static PercentRelativeLayout.LayoutParams getRelativeLayoutParams(Context context, PercentRelativeLayout.LayoutParams base, Map<String, String> rules, int defaultHorizontalAlign, View relativeToView)
Generate RelativeLayout.LayoutParams for the given CSS rules.
- Parameters:
context- The view's contextbase- Base layout parameters.rules- CSS-like rulesrelativeToView- Sets if the alignments should be relative to a view.
-
getFrameLayoutParams
static FrameLayout.LayoutParams getFrameLayoutParams(Context context, FrameLayout.LayoutParams base, Map<String, String> rules)
Generate FrameLayout.LayoutParams for the given CSS rules.
- Parameters:
context- The view's contextbase- Base layout parameters.rules- CSS-like rules
-
dpToPixels
static int dpToPixels(Resources resources, Float dp)
Converts a density-independent pixels measurement value to pixels.
- Parameters:
resources- View's resourcesdp- Density-independent pixel value
-
pixelsToDp
static float pixelsToDp(Resources resources, Float px)
Converts a pixels measurement value to density-independent pixels.
- Parameters:
resources- View's resourcespx- Pixel value
-
optInt
static Integer optInt(String stringValue)
Returns the integer value of a string.Doesn't throw an exception if it fails.
- Parameters:
stringValue- String to parse
-
optFloat
static Float optFloat(String stringValue)
Returns the float value of a string.Doesn't throw an exception if it fails.
- Parameters:
stringValue- String to parse
-
parseColor
static int parseColor(String color)
Parse a color. Accepts "#rrggbb", "#aarrggbb" or "transparent".Will fallback on TRANSPARENT when an error occurs.
- Parameters:
color- Color string to parse
-
darkenColor
static int darkenColor(int color)
Darkens a color, using HSL
- Parameters:
color- Color to be darkened
-
-
-
-