Added in API level 29

Builder


class Builder
kotlin.Any
   ↳ android.widget.Magnifier.Builder

Builder class for Magnifier objects.

Summary

Public constructors
Builder(view: View)

Construct a new builder for Magnifier objects.

Public methods
Magnifier

Builds a Magnifier instance based on the configuration of this Builder.

Magnifier.Builder

Defines the behavior of the magnifier when it is requested to position outside the surface of the main application window.

Magnifier.Builder
setCornerRadius(cornerRadius: Float)

Sets the corner radius of the magnifier window, in pixels.

Magnifier.Builder
setDefaultSourceToMagnifierOffset(horizontalOffset: Int, verticalOffset: Int)

Sets an offset that should be added to the content source center to obtain the position of the magnifier window, when the show(float,float) method is called.

Magnifier.Builder
setElevation(elevation: Float)

Sets the elevation of the magnifier window, in pixels.

Magnifier.Builder

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

Magnifier.Builder
setOverlay(overlay: Drawable?)

Sets an overlay that will be drawn on the top of the magnifier.

Magnifier.Builder
setSize(width: Int, height: Int)

Sets the size of the magnifier window, in pixels.

Magnifier.Builder
setSourceBounds(left: Int, top: Int, right: Int, bottom: Int)

Defines the bounds of the rectangle where the magnifier will be able to copy its content from.

Public constructors

Builder

Added in API level 29
Builder(view: View)

Construct a new builder for Magnifier objects.

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

Public methods

build

Added in API level 29
fun build(): Magnifier

Builds a Magnifier instance based on the configuration of this Builder.

Return
Magnifier This value cannot be null.

setClippingEnabled

Added in API level 29
fun setClippingEnabled(clip: Boolean): Magnifier.Builder

Defines the behavior of the magnifier when it is requested to position outside the surface of the main application window. The default value is true, which means that the position will be adjusted such that the magnifier will be fully within the bounds of the main application window, while also avoiding any overlap with system insets (such as the one corresponding to the status bar). If this flag is set to false, the area where the magnifier can be positioned will no longer be clipped, so the magnifier will be able to extend outside the main application window boundaries (and also overlap the system insets). This can be useful if you require a custom behavior, but it should be handled with care, when passing coordinates to show(float,float); note that:

  • in a multiwindow context, if the magnifier crosses the boundary between the two windows, it will not be able to show over the window of the other application
  • if the magnifier overlaps the status bar, there is no guarantee about which one will be displayed on top. This should be handled with care.

Parameters
clip Boolean: whether the magnifier position will be adjusted
Return
Magnifier.Builder This value cannot be null.

setCornerRadius

Added in API level 29
fun setCornerRadius(cornerRadius: Float): Magnifier.Builder

Sets the corner radius of the magnifier window, in pixels. Defaults to 2dp.

Parameters
cornerRadius Float: the corner radius to be set The units of this value are pixels. Value is 0 or greater
Return
Magnifier.Builder This value cannot be null.

setDefaultSourceToMagnifierOffset

Added in API level 29
fun setDefaultSourceToMagnifierOffset(
    horizontalOffset: Int,
    verticalOffset: Int
): Magnifier.Builder

Sets an offset that should be added to the content source center to obtain the position of the magnifier window, when the show(float,float) method is called. The offset is ignored when show(float,float,float,float) is used. The offset can be negative. It defaults to (0dp, 0dp).

Parameters
horizontalOffset Int: the horizontal component of the offset The units of this value are pixels.
verticalOffset Int: the vertical component of the offset The units of this value are pixels.
Return
Magnifier.Builder This value cannot be null.

setElevation

Added in API level 29
fun setElevation(elevation: Float): Magnifier.Builder

Sets the elevation of the magnifier window, in pixels. Defaults to 4dp.

Parameters
elevation Float: the elevation to be set The units of this value are pixels. Value is 0 or greater
Return
Magnifier.Builder This value cannot be null.

setInitialZoom

Added in API level 29
fun setInitialZoom(zoom: Float): Magnifier.Builder

Sets the zoom to be applied to the chosen content before being copied to the magnifier. A content of size (content_width, content_height) will be magnified to (content_width * zoom, content_height * zoom), which will coincide with the size of the magnifier. A zoom of 1 will translate to no magnification (the content will be just copied to the magnifier with no scaling). The zoom defaults to 1.25. Note that the zoom can also be changed after the instance is built, using the Magnifier#setZoom(float) method.

Parameters
zoom Float: the zoom to be set Value is 0f or greater
Return
Magnifier.Builder This value cannot be null.

setOverlay

Added in API level 29
fun setOverlay(overlay: Drawable?): Magnifier.Builder

Sets an overlay that will be drawn on the top of the magnifier. In general, the overlay should not be opaque, in order to let the magnified content be partially visible in the magnifier. The default overlay is null (no overlay). As an example, TextView applies a white ColorDrawable overlay with 5% alpha, aiming to make the magnifier distinguishable when shown in dark application regions. To disable the overlay, the parameter should be set to null. If not null, the overlay will be automatically redrawn when the drawable is invalidated. To achieve this, the magnifier will set a new android.graphics.drawable.Drawable.Callback for the overlay drawable, so keep in mind that any existing one set by the application will be lost.

Parameters
overlay Drawable?: the overlay to be drawn on top This value may be null.

setSize

Added in API level 29
fun setSize(
    width: Int,
    height: Int
): Magnifier.Builder

Sets the size of the magnifier window, in pixels. Defaults to (100dp, 48dp). Note that the size of the content being magnified and copied to the magnifier will be computed as (window width / zoom, window height / zoom).

Parameters
width Int: the window width to be set The units of this value are pixels. Value is 0 or greater
height Int: the window height to be set The units of this value are pixels. Value is 0 or greater
Return
Magnifier.Builder This value cannot be null.

setSourceBounds

Added in API level 29
fun setSourceBounds(
    left: Int,
    top: Int,
    right: Int,
    bottom: Int
): Magnifier.Builder

Defines the bounds of the rectangle where the magnifier will be able to copy its content from. The content will always be copied from the Surface of the main application window unless the magnified view is a SurfaceView, in which case its backing surface will be used. Each bound can have a different behavior, with the options being:

  • SOURCE_BOUND_MAX_VISIBLE, which extends the bound as much as possible while remaining in the visible region of the magnified view, as given by android.view.View#getGlobalVisibleRect(Rect). For example, this will take into account the case when the view is contained in a scrollable container, and the magnifier will refuse to copy content outside of the visible view region
  • SOURCE_BOUND_MAX_IN_SURFACE, which extends the bound as much as possible while remaining inside the surface the content is copied from.
Note that if either of the first three options is used, the bound will be compared to the bound of the surface (i.e. as if SOURCE_BOUND_MAX_IN_SURFACE was used), and the more restrictive one will be chosen. In other words, no attempt to copy content from outside the surface will be permitted. If two opposite bounds are not well-behaved (i.e. left + sourceWidth > right or top + sourceHeight > bottom), the left and top bounds will have priority and the others will be extended accordingly. If the pairs obtained this way still remain out of bounds, the smallest possible offset will be added to the pairs to bring them inside the surface bounds. If this is impossible (i.e. the surface is too small for the size of the content we try to copy on either dimension), an error will be logged and the magnifier content will look distorted. The default values assumed by the builder for the source bounds are left: SOURCE_BOUND_MAX_VISIBLE, top: SOURCE_BOUND_MAX_IN_SURFACE, right: SOURCE_BOUND_MAX_VISIBLE, bottom: SOURCE_BOUND_MAX_IN_SURFACE.

Parameters
left Int: the left bound for content copy Value is android.widget.Magnifier#SOURCE_BOUND_MAX_IN_SURFACE, or android.widget.Magnifier#SOURCE_BOUND_MAX_VISIBLE
top Int: the top bound for content copy Value is android.widget.Magnifier#SOURCE_BOUND_MAX_IN_SURFACE, or android.widget.Magnifier#SOURCE_BOUND_MAX_VISIBLE
right Int: the right bound for content copy Value is android.widget.Magnifier#SOURCE_BOUND_MAX_IN_SURFACE, or android.widget.Magnifier#SOURCE_BOUND_MAX_VISIBLE
bottom Int: the bottom bound for content copy Value is android.widget.Magnifier#SOURCE_BOUND_MAX_IN_SURFACE, or android.widget.Magnifier#SOURCE_BOUND_MAX_VISIBLE
Return
Magnifier.Builder This value cannot be null.