Most visited

Recently visited

DrawerArrowDrawable

public class DrawerArrowDrawable
extends Drawable

java.lang.Object
   ↳ android.graphics.drawable.Drawable
     ↳ android.support.v7.graphics.drawable.DrawerArrowDrawable


A drawable that can draw a "Drawer hamburger" menu or an arrow and animate between them.

The progress between the two states is controlled via setProgress(float).

Summary

Constants

int ARROW_DIRECTION_END

Direction to make the arrow point to the end.

int ARROW_DIRECTION_LEFT

Direction to make the arrow point towards the left.

int ARROW_DIRECTION_RIGHT

Direction to make the arrow point towards the right.

int ARROW_DIRECTION_START

Direction to make the arrow point towards the start.

Public constructors

DrawerArrowDrawable(Context context)

Public methods

void draw(Canvas canvas)

Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).

float getArrowHeadLength()

Returns the length of the arrow head (from tip to edge, perpendicular to the shaft), in pixels.

float getArrowShaftLength()

Returns the arrow shaft length in pixels.

float getBarLength()

The length of the bars when they are parallel to each other.

float getBarThickness()

Returns the thickness (stroke width) of the bars.

int getColor()

Returns the color of the drawable.

int getDirection()

Returns the arrow direction.

float getGapSize()

Returns the max gap between the bars when they are parallel to each other.

int getIntrinsicHeight()

Returns the drawable's intrinsic height.

int getIntrinsicWidth()

Returns the drawable's intrinsic width.

int getOpacity()

Return the opacity/transparency of this Drawable.

final Paint getPaint()

Returns the paint instance used for all drawing.

float getProgress()

Returns the current progress of the arrow.

boolean isSpinEnabled()

Returns whether the bars should rotate or not during the transition.

void setAlpha(int alpha)

Specify an alpha value for the drawable.

void setArrowHeadLength(float length)

Sets the length of the arrow head (from tip to edge, perpendicular to the shaft).

void setArrowShaftLength(float length)

Sets the arrow shaft length.

void setBarLength(float length)

Sets the length of the bars when they are parallel to each other.

void setBarThickness(float width)

Sets the thickness (stroke size) for the bars.

void setColor(int color)

Sets the color of the drawable.

void setColorFilter(ColorFilter colorFilter)

Specify an optional color filter for the drawable.

void setDirection(int direction)

Set the arrow direction.

void setGapSize(float gap)

Sets the max gap between the bars when they are parallel to each other.

void setProgress(float progress)

Set the progress of the arrow.

void setSpinEnabled(boolean enabled)

Returns whether the bars should rotate or not during the transition.

void setVerticalMirror(boolean verticalMirror)

If set, canvas is flipped when progress reached to end and going back to start.

Inherited methods

From class android.graphics.drawable.Drawable
From class java.lang.Object

Constants

ARROW_DIRECTION_END

int ARROW_DIRECTION_END

Direction to make the arrow point to the end.

When used in a view with a RTL layout direction, this is the same as ARROW_DIRECTION_LEFT, otherwise it is the same as ARROW_DIRECTION_RIGHT.

See also:

Constant Value: 3 (0x00000003)

ARROW_DIRECTION_LEFT

int ARROW_DIRECTION_LEFT

Direction to make the arrow point towards the left.

See also:

Constant Value: 0 (0x00000000)

ARROW_DIRECTION_RIGHT

int ARROW_DIRECTION_RIGHT

Direction to make the arrow point towards the right.

See also:

Constant Value: 1 (0x00000001)

ARROW_DIRECTION_START

int ARROW_DIRECTION_START

Direction to make the arrow point towards the start.

When used in a view with a RTL layout direction, this is the same as ARROW_DIRECTION_RIGHT, otherwise it is the same as ARROW_DIRECTION_LEFT.

See also:

Constant Value: 2 (0x00000002)

Public constructors

DrawerArrowDrawable

DrawerArrowDrawable (Context context)

Parameters
context Context: used to get the configuration for the drawable from

Public methods

draw

void draw (Canvas canvas)

Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).

Parameters
canvas Canvas: The canvas to draw into

getArrowHeadLength

float getArrowHeadLength ()

Returns the length of the arrow head (from tip to edge, perpendicular to the shaft), in pixels.

Returns
float

getArrowShaftLength

float getArrowShaftLength ()

Returns the arrow shaft length in pixels.

Returns
float

getBarLength

float getBarLength ()

The length of the bars when they are parallel to each other.

Returns
float

getBarThickness

float getBarThickness ()

Returns the thickness (stroke width) of the bars.

Returns
float

getColor

int getColor ()

Returns the color of the drawable.

Returns
int

getDirection

int getDirection ()

Returns the arrow direction.

Returns
int

getGapSize

float getGapSize ()

Returns the max gap between the bars when they are parallel to each other.

Returns
float

See also:

getIntrinsicHeight

int getIntrinsicHeight ()

Returns the drawable's intrinsic height.

Intrinsic height is the height at which the drawable would like to be laid out, including any inherent padding. If the drawable has no intrinsic height, such as a solid color, this method returns -1.

Returns
int the intrinsic height, or -1 if no intrinsic height

getIntrinsicWidth

int getIntrinsicWidth ()

Returns the drawable's intrinsic width.

Intrinsic width is the width at which the drawable would like to be laid out, including any inherent padding. If the drawable has no intrinsic width, such as a solid color, this method returns -1.

Returns
int the intrinsic width, or -1 if no intrinsic width

getOpacity

int getOpacity ()

Return the opacity/transparency of this Drawable. The returned value is one of the abstract format constants in PixelFormat: UNKNOWN, TRANSLUCENT, TRANSPARENT, or OPAQUE.

An OPAQUE drawable is one that draws all all content within its bounds, completely covering anything behind the drawable. A TRANSPARENT drawable is one that draws nothing within its bounds, allowing everything behind it to show through. A TRANSLUCENT drawable is a drawable in any other state, where the drawable will draw some, but not all, of the content within its bounds and at least some content behind the drawable will be visible. If the visibility of the drawable's contents cannot be determined, the safest/best return value is TRANSLUCENT.

Generally a Drawable should be as conservative as possible with the value it returns. For example, if it contains multiple child drawables and only shows one of them at a time, if only one of the children is TRANSLUCENT and the others are OPAQUE then TRANSLUCENT should be returned. You can use the method resolveOpacity(int, int) to perform a standard reduction of two opacities to the appropriate single output.

Note that the returned value does not necessarily take into account a custom alpha or color filter that has been applied by the client through the setAlpha(int) or setColorFilter(ColorFilter) methods. Some subclasses, such as BitmapDrawable, ColorDrawable, and GradientDrawable, do account for the value of setAlpha(int), but the general behavior is dependent upon the implementation of the subclass.

Returns
int int The opacity class of the Drawable.

getPaint

Paint getPaint ()

Returns the paint instance used for all drawing.

Returns
Paint

getProgress

float getProgress ()

Returns the current progress of the arrow.

Returns
float

isSpinEnabled

boolean isSpinEnabled ()

Returns whether the bars should rotate or not during the transition.

Returns
boolean

See also:

setAlpha

void setAlpha (int alpha)

Specify an alpha value for the drawable. 0 means fully transparent, and 255 means fully opaque.

Parameters
alpha int

setArrowHeadLength

void setArrowHeadLength (float length)

Sets the length of the arrow head (from tip to edge, perpendicular to the shaft).

Parameters
length float: the length in pixels

setArrowShaftLength

void setArrowShaftLength (float length)

Sets the arrow shaft length.

Parameters
length float: the length in pixels

setBarLength

void setBarLength (float length)

Sets the length of the bars when they are parallel to each other.

Parameters
length float: the length in pixels

setBarThickness

void setBarThickness (float width)

Sets the thickness (stroke size) for the bars.

Parameters
width float: stroke width in pixels

setColor

void setColor (int color)

Sets the color of the drawable.

Parameters
color int

setColorFilter

void setColorFilter (ColorFilter colorFilter)

Specify an optional color filter for the drawable.

If a Drawable has a ColorFilter, each output pixel of the Drawable's drawing contents will be modified by the color filter before it is blended onto the render target of a Canvas.

Pass null to remove any existing color filter.

Note: Setting a non-null color filter disables tint.

Parameters
colorFilter ColorFilter: The color filter to apply, or null to remove the existing color filter

setDirection

void setDirection (int direction)

Set the arrow direction.

Parameters
direction int

setGapSize

void setGapSize (float gap)

Sets the max gap between the bars when they are parallel to each other.

Parameters
gap float: the gap in pixels

See also:

setProgress

void setProgress (float progress)

Set the progress of the arrow.

A value of 0.0 indicates that the arrow should be drawn in it's starting position. A value of 1.0 indicates that the arrow should be drawn in it's ending position.

Parameters
progress float

setSpinEnabled

void setSpinEnabled (boolean enabled)

Returns whether the bars should rotate or not during the transition.

Parameters
enabled boolean: true if the bars should rotate.

See also:

setVerticalMirror

void setVerticalMirror (boolean verticalMirror)

If set, canvas is flipped when progress reached to end and going back to start.

Parameters
verticalMirror boolean

Hooray!