public class DimensionsLabel extends java.lang.Object implements RhythmSpecLayer
setGravity(int)
. Experimental at the moment, meaning its behavior, appearance, and parameters may
change.Modifier and Type | Class and Description |
---|---|
static class |
DimensionsLabel.Factory
A default factory that creates new
DimensionsLabel layers from config lines according to the docs |
Modifier and Type | Field and Description |
---|---|
protected static java.text.DecimalFormat |
DECIMAL_FORMAT |
static int |
DEFAULT_BACKGROUND |
static float |
DEFAULT_SCALE_FACTOR |
static int |
DEFAULT_TEXT_COLOR |
static int |
DEFAULT_TEXT_SIZE |
protected android.graphics.Paint |
mBackgroundPaint |
protected int |
mGravity |
protected float |
mScaleFactor |
protected android.text.TextPaint |
mTextPaint |
static char |
MULTIPLY |
static char |
ONE_FOURTH |
static char |
ONE_HALF |
static char |
ONE_THIRD |
static char |
THREE_FOURTHS |
static char |
TWO_THIRDS |
Constructor and Description |
---|
DimensionsLabel() |
Modifier and Type | Method and Description |
---|---|
void |
draw(android.graphics.Canvas canvas,
android.graphics.Rect drawableBounds)
Draw itself to the provided canvas within provided bounds according to internal configuration (if any)
|
static java.lang.String |
prettyPrintDips(int px,
float scaleFactor)
Sophisticated conversion of pixels to dips with the use of vulgar fractions (to save screen space)
|
DimensionsLabel |
setBackgroundColor(int color)
Set label background color
|
DimensionsLabel |
setGravity(int gravity)
Set label gravity.
|
DimensionsLabel |
setScaleFactor(float scaleFactor)
Set a scale factor that will be applied to width and height of provided bounds
|
DimensionsLabel |
setTextColor(int color)
Set the color of the label text itself
|
DimensionsLabel |
setTextSize(float size)
Set text size
|
public static final int DEFAULT_BACKGROUND
public static final int DEFAULT_TEXT_COLOR
public static final float DEFAULT_SCALE_FACTOR
public static final int DEFAULT_TEXT_SIZE
public static final char ONE_HALF
public static final char ONE_FOURTH
public static final char THREE_FOURTHS
public static final char ONE_THIRD
public static final char TWO_THIRDS
public static final char MULTIPLY
protected static final java.text.DecimalFormat DECIMAL_FORMAT
protected float mScaleFactor
protected int mGravity
protected android.graphics.Paint mBackgroundPaint
protected android.text.TextPaint mTextPaint
public DimensionsLabel setScaleFactor(float scaleFactor)
scaleFactor
- Scale factor to divide pixels by. Provide DisplayMetrics.density
here to display
dimensions as dips, DisplayMetrics.scaledDensity
to display them as sp
,
or DEFAULT_SCALE_FACTOR
(1f
) to get pixels.public DimensionsLabel setGravity(int gravity)
gravity
- Desired gravity. Can be combinations, e.g. Gravity.BOTTOM
| Gravity.LEFT
public DimensionsLabel setBackgroundColor(int color)
color
- Label background color, in #AARRGGBB format as usualpublic DimensionsLabel setTextColor(int color)
color
- Label text color, in #AARRGGBB format as usualpublic DimensionsLabel setTextSize(float size)
size
- Text size, in pixelspublic void draw(android.graphics.Canvas canvas, android.graphics.Rect drawableBounds)
RhythmSpecLayer
draw
in interface RhythmSpecLayer
canvas
- Canvas for the layer to draw itself todrawableBounds
- Bounds where this layer should draw itself. Since these are the bounds of a RhythmDrawable
connected to the view, they are usually the same as the view’s bounds, so
you can use this parameter to get the view’s dimensions should you need them.public static java.lang.String prettyPrintDips(int px, float scaleFactor)
px
- Pixels to convert to dipsscaleFactor
- Scale factor, should be equal to DisplayMetrics.density
for px to dp conversion