Magnifier

public final class Magnifier
extends Object

java.lang.Object
   ↳ android.widget.Magnifier


Android magnifier widget. Can be used by any view which is attached to a window.

Summary

Nested classes

class Magnifier.Builder

Builder class for Magnifier objects. 

Constants

int SOURCE_BOUND_MAX_IN_SURFACE

A source bound that will extend as much as possible, while remaining within the surface the content is copied from.

int SOURCE_BOUND_MAX_VISIBLE

A source bound that will extend as much as possible, while remaining within the visible region of the magnified view, as determined by View#getGlobalVisibleRect(Rect).

Public constructors

Magnifier(View view)

This constructor is deprecated. Please use Builder instead

Public methods

void dismiss()

Dismisses the magnifier from the screen.

float getCornerRadius()


This units of this value are pixels.

int getDefaultHorizontalSourceToMagnifierOffset()

Returns the horizontal offset, in pixels, to be applied to the source center position to obtain the magnifier center position when show(float, float) is called.

int getDefaultVerticalSourceToMagnifierOffset()

Returns the vertical offset, in pixels, to be applied to the source center position to obtain the magnifier center position when show(float, float) is called.

float getElevation()


This units of this value are pixels.

int getHeight()


This units of this value are pixels.

Drawable getOverlay()

Returns the overlay to be drawn on the top of the magnifier, or null if no overlay should be drawn.

Point getPosition()

Returns the top left coordinates of the magnifier, relative to the main application window.

int getSourceHeight()


This units of this value are pixels.

Point getSourcePosition()

Returns the top left coordinates of the magnifier source (i.e.

int getSourceWidth()


This units of this value are pixels.

int getWidth()


This units of this value are pixels.

float getZoom()

Returns the zoom to be applied to the magnified view region copied to the magnifier.

boolean isClippingEnabled()

Returns whether the magnifier position will be adjusted such that the magnifier will be fully within the bounds of the main application window, by also avoiding any overlap with system insets (such as the one corresponding to the status bar) i.e.

void setZoom(float zoom)

Sets the zoom to be applied to the chosen content before being copied to the magnifier popup.

void show(float sourceCenterX, float sourceCenterY, float magnifierCenterX, float magnifierCenterY)

Shows the magnifier on the screen at a position that is independent from its content position.

void show(float sourceCenterX, float sourceCenterY)

Shows the magnifier on the screen.

void update()

Asks the magnifier to update its content.

Inherited methods

Constants

SOURCE_BOUND_MAX_IN_SURFACE

Added in API level 29
public static final int SOURCE_BOUND_MAX_IN_SURFACE

A source bound that will extend as much as possible, while remaining within the surface the content is copied from.

Constant Value: 0 (0x00000000)

SOURCE_BOUND_MAX_VISIBLE

Added in API level 29
public static final int SOURCE_BOUND_MAX_VISIBLE

A source bound that will extend as much as possible, while remaining within the visible region of the magnified view, as determined by View#getGlobalVisibleRect(Rect).

Constant Value: 1 (0x00000001)

Public constructors

Magnifier

Added in API level 28
public Magnifier (View view)

This constructor is deprecated.
Please use Builder instead

Initializes a magnifier.

Parameters
view View: the view for which this magnifier is attached This value cannot be null.

Public methods

dismiss

Added in API level 28
public void dismiss ()

Dismisses the magnifier from the screen. Calling this on a dismissed magnifier is a no-op.

getCornerRadius

Added in API level 29
public float getCornerRadius ()


This units of this value are pixels.

Returns
float the corner radius of the magnifier window, in pixels This units of this value are pixels. {}

getDefaultHorizontalSourceToMagnifierOffset

Added in API level 29
public int getDefaultHorizontalSourceToMagnifierOffset ()

Returns the horizontal offset, in pixels, to be applied to the source center position to obtain the magnifier center position when show(float, float) is called. The value is ignored when show(float, float, float, float) is used instead.
This units of this value are pixels.

Returns
int the default horizontal offset between the source center and the magnifier This units of this value are pixels. {}

getDefaultVerticalSourceToMagnifierOffset

Added in API level 29
public int getDefaultVerticalSourceToMagnifierOffset ()

Returns the vertical offset, in pixels, to be applied to the source center position to obtain the magnifier center position when show(float, float) is called. The value is ignored when show(float, float, float, float) is used instead.
This units of this value are pixels.

Returns
int the default vertical offset between the source center and the magnifier This units of this value are pixels. {}

getElevation

Added in API level 29
public float getElevation ()


This units of this value are pixels.

Returns
float the elevation set for the magnifier window, in pixels This units of this value are pixels. {}

getHeight

Added in API level 28
public int getHeight ()


This units of this value are pixels.

Returns
int the height of the magnifier window, in pixels This units of this value are pixels. {}

getOverlay

Added in API level 29
public Drawable getOverlay ()

Returns the overlay to be drawn on the top of the magnifier, or null if no overlay should be drawn.

Returns
Drawable the overlay

getPosition

Added in API level 29
public Point getPosition ()

Returns the top left coordinates of the magnifier, relative to the main application window. They will be determined by the coordinates of the last show(float, float) or show(float, float, float, float) call, adjusted to take into account any potential clamping behavior. The method can be used immediately after a #show call to find out where the magnifier will be positioned. However, the position of the magnifier will not be updated visually in the same frame, due to the async nature of the content copying and of the magnifier rendering. The method will return null if #show has not yet been called, or if the last operation performed was a #dismiss.

Returns
Point the top left coordinates of the magnifier

getSourceHeight

Added in API level 29
public int getSourceHeight ()


This units of this value are pixels.

Returns
int the initial height of the content magnified and copied to the magnifier, in pixels This units of this value are pixels. {}

getSourcePosition

Added in API level 29
public Point getSourcePosition ()

Returns the top left coordinates of the magnifier source (i.e. the view region going to be magnified and copied to the magnifier), relative to the window or surface the content is copied from. The content will be copied: - if the magnified view is a SurfaceView, from the surface backing it - otherwise, from the surface backing the main application window, and the coordinates returned will be relative to the main application window The method will return null if #show has not yet been called, or if the last operation performed was a #dismiss.

Returns
Point the top left coordinates of the magnifier source

getSourceWidth

Added in API level 29
public int getSourceWidth ()


This units of this value are pixels.

Returns
int the initial width of the content magnified and copied to the magnifier, in pixels This units of this value are pixels. {}

getWidth

Added in API level 28
public int getWidth ()


This units of this value are pixels.

Returns
int the width of the magnifier window, in pixels This units of this value are pixels. {}

getZoom

Added in API level 28
public float getZoom ()

Returns the zoom to be applied to the magnified view region copied to the magnifier. If the zoom is x and the magnifier window size is (width, height), the original size of the content being magnified will be (width / x, height / x).

Returns
float the zoom applied to the content

isClippingEnabled

Added in API level 29
public boolean isClippingEnabled ()

Returns whether the magnifier position will be adjusted such that the magnifier will be fully within the bounds of the main application window, by also avoiding any overlap with system insets (such as the one corresponding to the status bar) i.e. whether the area where the magnifier can be positioned will be clipped to the main application window and the system insets.

Returns
boolean whether the magnifier position will be adjusted

setZoom

Added in API level 29
public void setZoom (float zoom)

Sets the zoom to be applied to the chosen content before being copied to the magnifier popup. The change will become effective at the next #show or #update call.

Parameters
zoom float: the zoom to be set Value is 0f or greater

show

Added in API level 29
public void show (float sourceCenterX, 
                float sourceCenterY, 
                float magnifierCenterX, 
                float magnifierCenterY)

Shows the magnifier on the screen at a position that is independent from its content position. The first two arguments represent the coordinates of the center of the content source going to be magnified and copied to the magnifier. The last two arguments represent the coordinates of the center of the magnifier itself. All four coordinates are relative to the top left corner of the magnified view. If you consider using this method such that the offset between the source center and the magnifier center coordinates remains constant, you should consider using method show(float, float) instead.

Parameters
sourceCenterX float: horizontal coordinate of the source center relative to the view Value is 0 or greater

sourceCenterY float: vertical coordinate of the source center, relative to the view Value is 0 or greater

magnifierCenterX float: horizontal coordinate of the magnifier center, relative to the view

magnifierCenterY float: vertical coordinate of the magnifier center, relative to the view

show

Added in API level 28
public void show (float sourceCenterX, 
                float sourceCenterY)

Shows the magnifier on the screen. The method takes the coordinates of the center of the content source going to be magnified and copied to the magnifier. The coordinates are relative to the top left corner of the magnified view. The magnifier will be positioned such that its center will be at the default offset from the center of the source. The default offset can be specified using the method Builder#setDefaultSourceToMagnifierOffset(int, int). If the offset should be different across calls to this method, you should consider to use method show(float, float, float, float) instead.

Parameters
sourceCenterX float: horizontal coordinate of the source center, relative to the view Value is 0 or greater

sourceCenterY float: vertical coordinate of the source center, relative to the view Value is 0 or greater

update

Added in API level 28
public void update ()

Asks the magnifier to update its content. It uses the previous coordinates passed to show(float, float) or show(float, float, float, float). The method only has effect if the magnifier is currently showing.