Magnifier
class Magnifier
kotlin.Any | |
↳ | android.widget.Magnifier |
Android magnifier widget. Can be used by any view which is attached to a window.
Summary
Nested classes | |
---|---|
Builder class for |
Constants | |
---|---|
static Int |
A source bound that will extend as much as possible, while remaining within the surface the content is copied from. |
static Int |
A source bound that will extend as much as possible, while remaining within the visible region of the magnified view, as determined by |
Public constructors | |
---|---|
Initializes a magnifier. |
Public methods | |
---|---|
Unit |
dismiss() Dismisses the magnifier from the screen. |
Float |
|
Int |
Returns the horizontal offset, in pixels, to be applied to the source center position to obtain the magnifier center position when |
Int |
Returns the vertical offset, in pixels, to be applied to the source center position to obtain the magnifier center position when |
Float |
|
Int |
|
Drawable? |
Returns the overlay to be drawn on the top of the magnifier, or |
Point? |
Returns the top left coordinates of the magnifier, relative to the main application window. |
Int |
|
Point? |
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. |
Int |
|
Int |
getWidth()
|
Float |
getZoom() Returns the zoom to be applied to the magnified view region copied to the magnifier. |
Boolean |
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. |
Unit |
Sets the zoom to be applied to the chosen content before being copied to the magnifier popup. |
Unit |
Shows the magnifier on the screen. |
Unit |
Shows the magnifier on the screen at a position that is independent from its content position. |
Unit |
update() Asks the magnifier to update its content. |
Constants
SOURCE_BOUND_MAX_IN_SURFACE
static val SOURCE_BOUND_MAX_IN_SURFACE: Int
A source bound that will extend as much as possible, while remaining within the surface the content is copied from.
Value: 0
SOURCE_BOUND_MAX_VISIBLE
static val SOURCE_BOUND_MAX_VISIBLE: Int
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)
.
Value: 1
Public constructors
Magnifier
Magnifier(view: View)
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
fun dismiss(): Unit
Dismisses the magnifier from the screen. Calling this on a dismissed magnifier is a no-op.
getCornerRadius
fun getCornerRadius(): Float
The units of this value are pixels.
Return | |
---|---|
Float |
the corner radius of the magnifier window, in pixels The units of this value are pixels. {} |
getDefaultHorizontalSourceToMagnifierOffset
fun getDefaultHorizontalSourceToMagnifierOffset(): Int
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.
The units of this value are pixels.
Return | |
---|---|
Int |
the default horizontal offset between the source center and the magnifier The units of this value are pixels. {} |
getDefaultVerticalSourceToMagnifierOffset
fun getDefaultVerticalSourceToMagnifierOffset(): Int
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.
The units of this value are pixels.
Return | |
---|---|
Int |
the default vertical offset between the source center and the magnifier The units of this value are pixels. {} |
getElevation
fun getElevation(): Float
The units of this value are pixels.
Return | |
---|---|
Float |
the elevation set for the magnifier window, in pixels The units of this value are pixels. {} |
getHeight
fun getHeight(): Int
The units of this value are pixels.
Return | |
---|---|
Int |
the height of the magnifier window, in pixels The units of this value are pixels. {} |
getOverlay
fun getOverlay(): Drawable?
Returns the overlay to be drawn on the top of the magnifier, or null
if no overlay should be drawn.
Return | |
---|---|
Drawable? |
the overlay |
getPosition
fun getPosition(): Point?
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.
Return | |
---|---|
Point? |
the top left coordinates of the magnifier |
getSourceHeight
fun getSourceHeight(): Int
The units of this value are pixels.
Return | |
---|---|
Int |
the initial height of the content magnified and copied to the magnifier, in pixels The units of this value are pixels. {} |
getSourcePosition
fun getSourcePosition(): Point?
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.
Return | |
---|---|
Point? |
the top left coordinates of the magnifier source |
getSourceWidth
fun getSourceWidth(): Int
The units of this value are pixels.
Return | |
---|---|
Int |
the initial width of the content magnified and copied to the magnifier, in pixels The units of this value are pixels. {} |
getWidth
fun getWidth(): Int
The units of this value are pixels.
Return | |
---|---|
Int |
the width of the magnifier window, in pixels The units of this value are pixels. {} |
getZoom
fun getZoom(): Float
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).
Return | |
---|---|
Float |
the zoom applied to the content |
isClippingEnabled
fun isClippingEnabled(): Boolean
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.
Return | |
---|---|
Boolean |
whether the magnifier position will be adjusted |
setZoom
fun setZoom(zoom: Float): Unit
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
fun show(
sourceCenterX: Float,
sourceCenterY: Float
): Unit
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 |
show
fun show(
sourceCenterX: Float,
sourceCenterY: Float,
magnifierCenterX: Float,
magnifierCenterY: Float
): Unit
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 |
update
fun update(): Unit
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.