Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/widget/Magnifier.Builder#pubctors) \| [Methods](https://developer.android.com/reference/android/widget/Magnifier.Builder#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/widget/Magnifier.Builder#inhmethods)

# Magnifier.Builder

*** ** * ** ***

` public static final class Magnifier.Builder `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.widget.Magnifier.Builder |

<br />

*** ** * ** ***

Builder class for `https://developer.android.com/reference/android/widget/Magnifier` objects.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/widget/Magnifier.Builder#Builder(android.view.View)(https://developer.android.com/reference/android/view/View view) ` Construct a new builder for `https://developer.android.com/reference/android/widget/Magnifier` objects. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/widget/Magnifier` | ` https://developer.android.com/reference/android/widget/Magnifier.Builder#build()() ` Builds a `https://developer.android.com/reference/android/widget/Magnifier` instance based on the configuration of this `https://developer.android.com/reference/android/widget/Magnifier.Builder`. |
| ` https://developer.android.com/reference/android/widget/Magnifier.Builder` | ` https://developer.android.com/reference/android/widget/Magnifier.Builder#setClippingEnabled(boolean)(boolean clip) ` Defines the behavior of the magnifier when it is requested to position outside the surface of the main application window. |
| ` https://developer.android.com/reference/android/widget/Magnifier.Builder` | ` https://developer.android.com/reference/android/widget/Magnifier.Builder#setCornerRadius(float)(float cornerRadius) ` Sets the corner radius of the magnifier window, in pixels. |
| ` https://developer.android.com/reference/android/widget/Magnifier.Builder` | ` https://developer.android.com/reference/android/widget/Magnifier.Builder#setDefaultSourceToMagnifierOffset(int,%20int)(int horizontalOffset, int verticalOffset) ` Sets an offset that should be added to the content source center to obtain the position of the magnifier window, when the `https://developer.android.com/reference/android/widget/Magnifier#show(float,%20float)` method is called. |
| ` https://developer.android.com/reference/android/widget/Magnifier.Builder` | ` https://developer.android.com/reference/android/widget/Magnifier.Builder#setElevation(float)(float elevation) ` Sets the elevation of the magnifier window, in pixels. |
| ` https://developer.android.com/reference/android/widget/Magnifier.Builder` | ` https://developer.android.com/reference/android/widget/Magnifier.Builder#setInitialZoom(float)(float zoom) ` Sets the zoom to be applied to the chosen content before being copied to the magnifier. |
| ` https://developer.android.com/reference/android/widget/Magnifier.Builder` | ` https://developer.android.com/reference/android/widget/Magnifier.Builder#setOverlay(android.graphics.drawable.Drawable)(https://developer.android.com/reference/android/graphics/drawable/Drawable overlay) ` Sets an overlay that will be drawn on the top of the magnifier. |
| ` https://developer.android.com/reference/android/widget/Magnifier.Builder` | ` https://developer.android.com/reference/android/widget/Magnifier.Builder#setSize(int,%20int)(int width, int height) ` Sets the size of the magnifier window, in pixels. |
| ` https://developer.android.com/reference/android/widget/Magnifier.Builder` | ` https://developer.android.com/reference/android/widget/Magnifier.Builder#setSourceBounds(int,%20int,%20int,%20int)(int left, int top, int right, int bottom) ` Defines the bounds of the rectangle where the magnifier will be able to copy its content from. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public constructors

### Builder

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Builder (View view)
```

Construct a new builder for `https://developer.android.com/reference/android/widget/Magnifier` objects.

<br />

| Parameters ||
|---|---|
| `view` | `View`: the view this magnifier is attached to. This value cannot be `null`. <br /> |

## Public methods

### build

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Magnifier build ()
```

Builds a `https://developer.android.com/reference/android/widget/Magnifier` instance based on the configuration of this `https://developer.android.com/reference/android/widget/Magnifier.Builder`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/widget/Magnifier` | This value cannot be `null`. <br /> |

### setClippingEnabled

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Magnifier.Builder setClippingEnabled (boolean clip)
```

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 `https://developer.android.com/reference/android/widget/Magnifier#show(float,%20float)`; 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.

<br />

<br />

| Parameters ||
|---|---|
| `clip` | `boolean`: whether the magnifier position will be adjusted <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/widget/Magnifier.Builder` | This value cannot be `null`. <br /> |

### setCornerRadius

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Magnifier.Builder setCornerRadius (float cornerRadius)
```

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

<br />

| Parameters ||
|---|---|
| `cornerRadius` | `float`: the corner radius to be set. The units of this value are pixels. Value is 0.0f or greater <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/widget/Magnifier.Builder` | This value cannot be `null`. <br /> |

### setDefaultSourceToMagnifierOffset

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Magnifier.Builder setDefaultSourceToMagnifierOffset (int horizontalOffset, 
                int verticalOffset)
```

Sets an offset that should be added to the content source center to obtain the position of the magnifier window, when the `https://developer.android.com/reference/android/widget/Magnifier#show(float,%20float)` method is called. The offset is ignored when `https://developer.android.com/reference/android/widget/Magnifier#show(float,%20float,%20float,%20float)` is used. The offset can be negative. It defaults to (0dp, 0dp).

<br />

| Parameters ||
|---|---|
| `horizontalOffset` | `int`: the horizontal component of the offset. The units of this value are pixels. <br /> |
| `verticalOffset` | `int`: the vertical component of the offset. The units of this value are pixels. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/widget/Magnifier.Builder` | This value cannot be `null`. <br /> |

### setElevation

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Magnifier.Builder setElevation (float elevation)
```

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

<br />

| Parameters ||
|---|---|
| `elevation` | `float`: the elevation to be set. The units of this value are pixels. Value is 0.0f or greater <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/widget/Magnifier.Builder` | This value cannot be `null`. <br /> |

### setInitialZoom

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Magnifier.Builder setInitialZoom (float zoom)
```

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 `https://developer.android.com/reference/android/widget/Magnifier#setZoom(float)` method.

<br />

| Parameters ||
|---|---|
| `zoom` | `float`: the zoom to be set. Value is 0.0f or greater <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/widget/Magnifier.Builder` | This value cannot be `null`. <br /> |

### setOverlay

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Magnifier.Builder setOverlay (Drawable overlay)
```

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 `https://developer.android.com/reference/android/graphics/drawable/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 `https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback` for the overlay drawable, so keep in mind that any existing one set by the application will be lost.

<br />

| Parameters ||
|---|---|
| `overlay` | `Drawable`: the overlay to be drawn on top. This value may be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/widget/Magnifier.Builder` | <br /> |

### setSize

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Magnifier.Builder setSize (int width, 
                int height)
```

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).

<br />

| Parameters ||
|---|---|
| `width` | `int`: the window width to be set. The units of this value are pixels. Value is 0 or greater <br /> |
| `height` | `int`: the window height to be set. The units of this value are pixels. Value is 0 or greater <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/widget/Magnifier.Builder` | This value cannot be `null`. <br /> |

### setSourceBounds

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Magnifier.Builder setSourceBounds (int left, 
                int top, 
                int right, 
                int bottom)
```

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 `https://developer.android.com/reference/android/view/Surface` of the main application window unless the magnified view is a `https://developer.android.com/reference/android/view/SurfaceView`, in which case its backing surface will be used. Each bound can have a different behavior, with the options being:

- `https://developer.android.com/reference/android/widget/Magnifier#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 `https://developer.android.com/reference/android/view/View#getGlobalVisibleRect(android.graphics.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
- `https://developer.android.com/reference/android/widget/Magnifier#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 `https://developer.android.com/reference/android/widget/Magnifier#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: `https://developer.android.com/reference/android/widget/Magnifier#SOURCE_BOUND_MAX_VISIBLE`, top: `https://developer.android.com/reference/android/widget/Magnifier#SOURCE_BOUND_MAX_IN_SURFACE`, right: `https://developer.android.com/reference/android/widget/Magnifier#SOURCE_BOUND_MAX_VISIBLE`, bottom: `https://developer.android.com/reference/android/widget/Magnifier#SOURCE_BOUND_MAX_IN_SURFACE`.

<br />

<br />

| Parameters ||
|---|---|
| `left` | `int`: the left bound for content copy. Value is one of the following: - `https://developer.android.com/reference/android/widget/Magnifier#SOURCE_BOUND_MAX_IN_SURFACE` - `https://developer.android.com/reference/android/widget/Magnifier#SOURCE_BOUND_MAX_VISIBLE` |
| `top` | `int`: the top bound for content copy. Value is one of the following: - `https://developer.android.com/reference/android/widget/Magnifier#SOURCE_BOUND_MAX_IN_SURFACE` - `https://developer.android.com/reference/android/widget/Magnifier#SOURCE_BOUND_MAX_VISIBLE` |
| `right` | `int`: the right bound for content copy. Value is one of the following: - `https://developer.android.com/reference/android/widget/Magnifier#SOURCE_BOUND_MAX_IN_SURFACE` - `https://developer.android.com/reference/android/widget/Magnifier#SOURCE_BOUND_MAX_VISIBLE` |
| `bottom` | `int`: the bottom bound for content copy. Value is one of the following: - `https://developer.android.com/reference/android/widget/Magnifier#SOURCE_BOUND_MAX_IN_SURFACE` - `https://developer.android.com/reference/android/widget/Magnifier#SOURCE_BOUND_MAX_VISIBLE` |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/widget/Magnifier.Builder` | This value cannot be `null`. <br /> |