Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/java/text/Bidi#constants) \| [Ctors](https://developer.android.com/reference/java/text/Bidi#pubctors) \| [Methods](https://developer.android.com/reference/java/text/Bidi#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/text/Bidi#inhmethods)

# Bidi

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

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.text.Bidi |

<br />

*** ** * ** ***

This class implements the Unicode Bidirectional Algorithm.

A Bidi object provides information on the bidirectional reordering of the text used to create it. This is required, for example, to properly display Arabic or Hebrew text. These languages are inherently mixed directional, as they order numbers from left-to-right while ordering most other text from right-to-left.

Once created, a Bidi object can be queried to see if the text it represents is all left-to-right or all right-to-left. Such objects are very lightweight and this text is relatively easy to process.

If there are multiple runs of text, information about the runs can be accessed by indexing to get the start, limit, and level of a run. The level represents both the direction and the 'nesting level' of a directional run. Odd levels are right-to-left, while even levels are left-to-right. So for example level 0 represents left-to-right text, while level 1 represents right-to-left text, and level 2 represents left-to-right text embedded in a right-to-left run.

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/java/text/Bidi#DIRECTION_DEFAULT_LEFT_TO_RIGHT` Constant indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm. |
| `int` | `https://developer.android.com/reference/java/text/Bidi#DIRECTION_DEFAULT_RIGHT_TO_LEFT` Constant indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm. |
| `int` | `https://developer.android.com/reference/java/text/Bidi#DIRECTION_LEFT_TO_RIGHT` Constant indicating base direction is left-to-right. |
| `int` | `https://developer.android.com/reference/java/text/Bidi#DIRECTION_RIGHT_TO_LEFT` Constant indicating base direction is right-to-left. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/text/Bidi#Bidi(char[],%20int,%20byte[],%20int,%20int,%20int)(char[] text, int textStart, byte[] embeddings, int embStart, int paragraphLength, int flags) ` Create Bidi from the given text, embedding, and direction information. |
| ` https://developer.android.com/reference/java/text/Bidi#Bidi(java.lang.String,%20int)(https://developer.android.com/reference/java/lang/String paragraph, int flags) ` Create Bidi from the given paragraph of text and base direction. |
| ` https://developer.android.com/reference/java/text/Bidi#Bidi(java.text.AttributedCharacterIterator)(https://developer.android.com/reference/java/text/AttributedCharacterIterator paragraph) ` Create Bidi from the given paragraph of text. |

| ### Public methods ||
|---|---|
| ` boolean` | ` https://developer.android.com/reference/java/text/Bidi#baseIsLeftToRight()() ` Return true if the base direction is left-to-right. |
| ` https://developer.android.com/reference/java/text/Bidi` | ` https://developer.android.com/reference/java/text/Bidi#createLineBidi(int,%20int)(int lineStart, int lineLimit) ` Create a Bidi object representing the bidi information on a line of text within the paragraph represented by the current Bidi. |
| ` int` | ` https://developer.android.com/reference/java/text/Bidi#getBaseLevel()() ` Return the base level (0 if left-to-right, 1 if right-to-left). |
| ` int` | ` https://developer.android.com/reference/java/text/Bidi#getLength()() ` Return the length of text in the line. |
| ` int` | ` https://developer.android.com/reference/java/text/Bidi#getLevelAt(int)(int offset) ` Return the resolved level of the character at offset. |
| ` int` | ` https://developer.android.com/reference/java/text/Bidi#getRunCount()() ` Return the number of level runs. |
| ` int` | ` https://developer.android.com/reference/java/text/Bidi#getRunLevel(int)(int run) ` Return the level of the nth logical run in this line. |
| ` int` | ` https://developer.android.com/reference/java/text/Bidi#getRunLimit(int)(int run) ` Return the index of the character past the end of the nth logical run in this line, as an offset from the start of the line. |
| ` int` | ` https://developer.android.com/reference/java/text/Bidi#getRunStart(int)(int run) ` Return the index of the character at the start of the nth logical run in this line, as an offset from the start of the line. |
| ` boolean` | ` https://developer.android.com/reference/java/text/Bidi#isLeftToRight()() ` Return true if the line is all left-to-right text and the base direction is left-to-right. |
| ` boolean` | ` https://developer.android.com/reference/java/text/Bidi#isMixed()() ` Return true if the line is not left-to-right or right-to-left. |
| ` boolean` | ` https://developer.android.com/reference/java/text/Bidi#isRightToLeft()() ` Return true if the line is all right-to-left text, and the base direction is right-to-left. |
| ` static void` | ` https://developer.android.com/reference/java/text/Bidi#reorderVisually(byte[],%20int,%20java.lang.Object[],%20int,%20int)(byte[] levels, int levelStart, https://developer.android.com/reference/java/lang/Object objects, int objectStart, int count) ` Reorder the objects in the array into visual order based on their levels. |
| ` static boolean` | ` https://developer.android.com/reference/java/text/Bidi#requiresBidi(char[],%20int,%20int)(char[] text, int start, int limit) ` Return true if the specified text requires bidi analysis. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/text/Bidi#toString()() ` Display the bidi internal state, used in debugging. |

### 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*.

## Constants

### DIRECTION_DEFAULT_LEFT_TO_RIGHT

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

```
public static final int DIRECTION_DEFAULT_LEFT_TO_RIGHT
```

Constant indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm. If no strong directional character is present, the base direction is left-to-right.

<br />

Constant Value: -2 (0xfffffffe)

### DIRECTION_DEFAULT_RIGHT_TO_LEFT

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

```
public static final int DIRECTION_DEFAULT_RIGHT_TO_LEFT
```

Constant indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm. If no strong directional character is present, the base direction is right-to-left.

<br />

Constant Value: -1 (0xffffffff)

### DIRECTION_LEFT_TO_RIGHT

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

```
public static final int DIRECTION_LEFT_TO_RIGHT
```

Constant indicating base direction is left-to-right.

<br />

Constant Value: 0 (0x00000000)

### DIRECTION_RIGHT_TO_LEFT

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

```
public static final int DIRECTION_RIGHT_TO_LEFT
```

Constant indicating base direction is right-to-left.

<br />

Constant Value: 1 (0x00000001)

## Public constructors

### Bidi

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

```
public Bidi (char[] text, 
                int textStart, 
                byte[] embeddings, 
                int embStart, 
                int paragraphLength, 
                int flags)
```

Create Bidi from the given text, embedding, and direction information. The embeddings array may be null. If present, the values represent embedding level information. Negative values from -1 to -61 indicate overrides at the absolute value of the level. Positive values from 1 to 61 indicate embeddings. Where values are zero, the base embedding level as determined by the base direction is assumed.

<br />

| Parameters ||
|---|---|
| `text` | `char`: an array containing the paragraph of text to process. <br /> |
| `textStart` | `int`: the index into the text array of the start of the paragraph. <br /> |
| `embeddings` | `byte`: an array containing embedding values for each character in the paragraph. This can be null, in which case it is assumed that there is no external embedding information. <br /> |
| `embStart` | `int`: the index into the embedding array of the start of the paragraph. <br /> |
| `paragraphLength` | `int`: the length of the paragraph in the text and embeddings arrays. <br /> |
| `flags` | `int`: a collection of flags that control the algorithm. The algorithm understands the flags DIRECTION_LEFT_TO_RIGHT, DIRECTION_RIGHT_TO_LEFT, DIRECTION_DEFAULT_LEFT_TO_RIGHT, and DIRECTION_DEFAULT_RIGHT_TO_LEFT. Other values are reserved. <br /> |

### Bidi

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

```
public Bidi (String paragraph, 
                int flags)
```

Create Bidi from the given paragraph of text and base direction.

<br />

| Parameters ||
|---|---|
| `paragraph` | `String`: a paragraph of text <br /> |
| `flags` | `int`: a collection of flags that control the algorithm. The algorithm understands the flags DIRECTION_LEFT_TO_RIGHT, DIRECTION_RIGHT_TO_LEFT, DIRECTION_DEFAULT_LEFT_TO_RIGHT, and DIRECTION_DEFAULT_RIGHT_TO_LEFT. Other values are reserved. <br /> |

### Bidi

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

```
public Bidi (AttributedCharacterIterator paragraph)
```

Create Bidi from the given paragraph of text.

The RUN_DIRECTION attribute in the text, if present, determines the base direction (left-to-right or right-to-left). If not present, the base direction is computes using the Unicode Bidirectional Algorithm, defaulting to left-to-right if there are no strong directional characters in the text. This attribute, if present, must be applied to all the text in the paragraph.

The BIDI_EMBEDDING attribute in the text, if present, represents embedding level information. Negative values from -1 to -62 indicate overrides at the absolute value of the level. Positive values from 1 to 62 indicate embeddings. Where values are zero or not defined, the base embedding level as determined by the base direction is assumed.

The NUMERIC_SHAPING attribute in the text, if present, converts European digits to other decimal digits before running the bidi algorithm. This attribute, if present, must be applied to all the text in the paragraph.

<br />

| Parameters ||
|---|---|
| `paragraph` | `AttributedCharacterIterator`: a paragraph of text with optional character and paragraph attribute information <br /> |

**See also:**

- `https://developer.android.com/reference/java/awt/font/TextAttribute#BIDI_EMBEDDING`
- `https://developer.android.com/reference/java/awt/font/TextAttribute#NUMERIC_SHAPING`
- `https://developer.android.com/reference/java/awt/font/TextAttribute#RUN_DIRECTION`

## Public methods

### baseIsLeftToRight

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

```
public boolean baseIsLeftToRight ()
```

Return true if the base direction is left-to-right.

<br />

| Returns ||
|---|---|
| `boolean` | true if the base direction is left-to-right <br /> |

### createLineBidi

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

```
public Bidi createLineBidi (int lineStart, 
                int lineLimit)
```

Create a Bidi object representing the bidi information on a line of text within the paragraph represented by the current Bidi. This call is not required if the entire paragraph fits on one line.

<br />

| Parameters ||
|---|---|
| `lineStart` | `int`: the offset from the start of the paragraph to the start of the line. <br /> |
| `lineLimit` | `int`: the offset from the start of the paragraph to the limit of the line. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/text/Bidi` | a `Bidi` object <br /> |

### getBaseLevel

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

```
public int getBaseLevel ()
```

Return the base level (0 if left-to-right, 1 if right-to-left).

<br />

| Returns ||
|---|---|
| `int` | the base level <br /> |

### getLength

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

```
public int getLength ()
```

Return the length of text in the line.

<br />

| Returns ||
|---|---|
| `int` | the length of text in the line <br /> |

### getLevelAt

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

```
public int getLevelAt (int offset)
```

Return the resolved level of the character at offset. If offset is \< 0 or ≥ the length of the line, return the base direction level.

<br />

| Parameters ||
|---|---|
| `offset` | `int`: the index of the character for which to return the level <br /> |

| Returns ||
|---|---|
| `int` | the resolved level of the character at offset <br /> |

### getRunCount

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

```
public int getRunCount ()
```

Return the number of level runs.

<br />

| Returns ||
|---|---|
| `int` | the number of level runs <br /> |

### getRunLevel

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

```
public int getRunLevel (int run)
```

Return the level of the nth logical run in this line.

<br />

| Parameters ||
|---|---|
| `run` | `int`: the index of the run, between 0 and `getRunCount()` <br /> |

| Returns ||
|---|---|
| `int` | the level of the run <br /> |

### getRunLimit

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

```
public int getRunLimit (int run)
```

Return the index of the character past the end of the nth logical run in this line, as an offset from the start of the line. For example, this will return the length of the line for the last run on the line.

<br />

| Parameters ||
|---|---|
| `run` | `int`: the index of the run, between 0 and `getRunCount()` <br /> |

| Returns ||
|---|---|
| `int` | limit the limit of the run <br /> |

### getRunStart

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

```
public int getRunStart (int run)
```

Return the index of the character at the start of the nth logical run in this line, as an offset from the start of the line.

<br />

| Parameters ||
|---|---|
| `run` | `int`: the index of the run, between 0 and `getRunCount()` <br /> |

| Returns ||
|---|---|
| `int` | the start of the run <br /> |

### isLeftToRight

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

```
public boolean isLeftToRight ()
```

Return true if the line is all left-to-right text and the base direction is left-to-right.

<br />

| Returns ||
|---|---|
| `boolean` | true if the line is all left-to-right text and the base direction is left-to-right <br /> |

### isMixed

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

```
public boolean isMixed ()
```

Return true if the line is not left-to-right or right-to-left. This means it either has mixed runs of left-to-right and right-to-left text, or the base direction differs from the direction of the only run of text.

<br />

| Returns ||
|---|---|
| `boolean` | true if the line is not left-to-right or right-to-left. <br /> |

### isRightToLeft

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

```
public boolean isRightToLeft ()
```

Return true if the line is all right-to-left text, and the base direction is right-to-left.

<br />

| Returns ||
|---|---|
| `boolean` | true if the line is all right-to-left text, and the base direction is right-to-left <br /> |

### reorderVisually

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

```
public static void reorderVisually (byte[] levels, 
                int levelStart, 
                Object[] objects, 
                int objectStart, 
                int count)
```

Reorder the objects in the array into visual order based on their levels. This is a utility function to use when you have a collection of objects representing runs of text in logical order, each run containing text at a single level. The elements at `index` from `objectStart` up to `objectStart + count` in the objects array will be reordered into visual order assuming each run of text has the level indicated by the corresponding element in the levels array (at `index - objectStart + levelStart`).

<br />

| Parameters ||
|---|---|
| `levels` | `byte`: an array representing the bidi level of each object <br /> |
| `levelStart` | `int`: the start position in the levels array <br /> |
| `objects` | `Object`: the array of objects to be reordered into visual order <br /> |
| `objectStart` | `int`: the start position in the objects array <br /> |
| `count` | `int`: the number of objects to reorder <br /> |

### requiresBidi

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

```
public static boolean requiresBidi (char[] text, 
                int start, 
                int limit)
```

Return true if the specified text requires bidi analysis. If this returns false, the text will display left-to-right. Clients can then avoid constructing a Bidi object. Text in the Arabic Presentation Forms area of Unicode is presumed to already be shaped and ordered for display, and so will not cause this function to return true.

<br />

| Parameters ||
|---|---|
| `text` | `char`: the text containing the characters to test <br /> |
| `start` | `int`: the start of the range of characters to test <br /> |
| `limit` | `int`: the limit of the range of characters to test <br /> |

| Returns ||
|---|---|
| `boolean` | true if the range of characters requires bidi analysis <br /> |

### toString

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

```
public String toString ()
```

Display the bidi internal state, used in debugging.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of the object. <br /> |