Class PromptUtils
- java.lang.Object
-
- uk.co.samuelwall.materialtaptargetprompt.extras.PromptUtils
-
public class PromptUtils extends java.lang.Object
Useful methods for prompts that don't fit else where.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static float
calculateMaxTextWidth(android.text.Layout textLayout)
Calculates the maximum width line in a text layout.static float
calculateMaxWidth(float maxTextWidth, android.graphics.Rect clipBounds, int parentWidth, float textPadding)
Calculates the maximum width that the prompt can be.static boolean
containsInset(android.graphics.Rect bounds, int inset, int x, int y)
Determines if a point is within a rectangle that has been inset.static android.text.StaticLayout
createStaticTextLayout(java.lang.CharSequence text, android.text.TextPaint paint, int maxTextWidth, android.text.Layout.Alignment textAlignment, float alphaModifier)
Creates a static text layout.static android.text.Layout.Alignment
getTextAlignment(android.content.res.Resources resources, int gravity, java.lang.CharSequence text)
Gets the absolute text alignment value based on the supplied gravity and the activities layout direction.static boolean
isPointInCircle(float x, float y, android.graphics.PointF circleCentre, float radius)
Determines if a point is in the centre of a circle with a radius from the point.static boolean
isRtlText(android.text.Layout layout, android.content.res.Resources resources)
Determines if the text in the supplied layout is displayed right to left.static android.graphics.PorterDuff.Mode
parseTintMode(int value, android.graphics.PorterDuff.Mode defaultMode)
Based on parseTintMode in android appcompat v7 DrawableUtils, Copyright (C) 2014 The Android Open Source Project.static void
scale(android.graphics.PointF origin, android.graphics.RectF base, android.graphics.RectF out, float scale, boolean even)
Scales a rectangle.static void
setTypeface(android.text.TextPaint textPaint, android.graphics.Typeface typeface, int style)
Based on setTypeface in android TextView, Copyright (C) 2006 The Android Open Source Project.static android.graphics.Typeface
setTypefaceFromAttrs(java.lang.String familyName, int typefaceIndex, int styleIndex)
Based on setTypefaceFromAttrs in android TextView, Copyright (C) 2006 The Android Open Source Project.
-
-
-
Method Detail
-
isPointInCircle
public static boolean isPointInCircle(float x, float y, @NonNull android.graphics.PointF circleCentre, float radius)
Determines if a point is in the centre of a circle with a radius from the point.- Parameters:
x
- The x position in the view.y
- The y position in the view.circleCentre
- The circle centre positionradius
- The radius of the circle.- Returns:
- True if the point (x, y) is in the circle.
-
setTypeface
public static void setTypeface(@NonNull android.text.TextPaint textPaint, @Nullable android.graphics.Typeface typeface, int style)
Based on setTypeface in android TextView, Copyright (C) 2006 The Android Open Source Project. https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/android/widget/TextView.java
-
setTypefaceFromAttrs
@NonNull public static android.graphics.Typeface setTypefaceFromAttrs(@Nullable java.lang.String familyName, int typefaceIndex, int styleIndex)
Based on setTypefaceFromAttrs in android TextView, Copyright (C) 2006 The Android Open Source Project. https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/android/widget/TextView.java
-
parseTintMode
@Nullable public static android.graphics.PorterDuff.Mode parseTintMode(int value, @Nullable android.graphics.PorterDuff.Mode defaultMode)
Based on parseTintMode in android appcompat v7 DrawableUtils, Copyright (C) 2014 The Android Open Source Project. https://android.googlesource.com/platform/frameworks/support.git/+/master/v7/appcompat/src/android/support/v7/widget/DrawableUtils.java
-
getTextAlignment
@NonNull public static android.text.Layout.Alignment getTextAlignment(@NonNull android.content.res.Resources resources, int gravity, @Nullable java.lang.CharSequence text)
Gets the absolute text alignment value based on the supplied gravity and the activities layout direction.- Parameters:
gravity
- The gravity to convert to absolute values- Returns:
- absolute layout direction
-
createStaticTextLayout
@NonNull public static android.text.StaticLayout createStaticTextLayout(@NonNull java.lang.CharSequence text, @NonNull android.text.TextPaint paint, int maxTextWidth, @NonNull android.text.Layout.Alignment textAlignment, float alphaModifier)
Creates a static text layout. Uses theStaticLayout.Builder
if available.- Parameters:
text
- The text to be laid out, optionally with spanspaint
- The base paint used for layoutmaxTextWidth
- The width in pixelstextAlignment
- Alignment for the resultingStaticLayout
alphaModifier
- The modification to apply to the alpha value between 0 and 1.- Returns:
- the newly constructed
StaticLayout
object
-
scale
public static void scale(@NonNull android.graphics.PointF origin, @NonNull android.graphics.RectF base, @NonNull android.graphics.RectF out, float scale, boolean even)
Scales a rectangle.- Parameters:
origin
- The point to scale from.base
- The rectangle at scale 1.0.out
- The rectangle to put the scaled size in.scale
- The amount to scale the rectangle by.even
- Should the rectangle be scaled evenly in both directions.
-
isRtlText
public static boolean isRtlText(@Nullable android.text.Layout layout, @NonNull android.content.res.Resources resources)
Determines if the text in the supplied layout is displayed right to left.- Parameters:
layout
- The layout to check.- Returns:
- True if the text in the supplied layout is displayed right to left. False otherwise.
-
calculateMaxWidth
public static float calculateMaxWidth(float maxTextWidth, @Nullable android.graphics.Rect clipBounds, int parentWidth, float textPadding)
Calculates the maximum width that the prompt can be.- Returns:
- Maximum width in pixels that the prompt can be.
-
calculateMaxTextWidth
public static float calculateMaxTextWidth(@Nullable android.text.Layout textLayout)
Calculates the maximum width line in a text layout.- Parameters:
textLayout
- The text layout- Returns:
- The maximum length line
-
containsInset
public static boolean containsInset(@NonNull android.graphics.Rect bounds, int inset, int x, int y)
Determines if a point is within a rectangle that has been inset.- Parameters:
bounds
- The rectangle bounds.inset
- The amount that the rectangle is inset by.x
- The point x coordinate.y
- The point y coordinate.- Returns:
- True if the point is within the inset rectangle, false otherwise.
-
-