| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view.inputmethod; |
| 18 |
|
| 19 |
import android.annotation.IntRange; |
| 20 |
import android.annotation.NonNull; |
| 21 |
|
| 22 |
import java.util.Objects; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public final class TextSnapshot { |
| 28 |
@NonNull |
| 29 |
private final SurroundingText mSurroundingText; |
| 30 |
@IntRange(from = -1) |
| 31 |
private final int mCompositionStart; |
| 32 |
@IntRange(from = -1) |
| 33 |
private final int mCompositionEnd; |
| 34 |
private final int mCursorCapsMode; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public TextSnapshot(@NonNull SurroundingText surroundingText, |
| 51 |
@IntRange(from = -1) int compositionStart, @IntRange(from = -1) int compositionEnd, |
| 52 |
int cursorCapsMode) { |
| 53 |
Objects.requireNonNull(surroundingText); |
| 54 |
mSurroundingText = surroundingText; |
| 55 |
if (compositionStart < -1) { |
| 56 |
throw new IllegalArgumentException("compositionStart must be -1 or higher but was " |
| 57 |
+ compositionStart); |
| 58 |
} |
| 59 |
if (compositionEnd < -1) { |
| 60 |
throw new IllegalArgumentException("compositionEnd must be -1 or higher but was " |
| 61 |
+ compositionEnd); |
| 62 |
} |
| 63 |
if (compositionStart == -1 && compositionEnd != -1) { |
| 64 |
throw new IllegalArgumentException("compositionEnd must be -1 if compositionStart is " |
| 65 |
+ "-1 but was " + compositionEnd); |
| 66 |
} |
| 67 |
if (compositionStart != -1 && compositionEnd == -1) { |
| 68 |
throw new IllegalArgumentException("compositionStart must be -1 if compositionEnd is " |
| 69 |
+ "-1 but was " + compositionStart); |
| 70 |
} |
| 71 |
if (compositionStart > compositionEnd) { |
| 72 |
throw new IllegalArgumentException("compositionStart=" + compositionStart + " must be" |
| 73 |
+ " equal to or greater than compositionEnd=" + compositionEnd); |
| 74 |
} |
| 75 |
mCompositionStart = compositionStart; |
| 76 |
mCompositionEnd = compositionEnd; |
| 77 |
mCursorCapsMode = cursorCapsMode; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
@NonNull |
| 84 |
public SurroundingText getSurroundingText() { |
| 85 |
return mSurroundingText; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
@IntRange(from = -1) |
| 92 |
public int getSelectionStart() { |
| 93 |
if (mSurroundingText.getOffset() < 0) { |
| 94 |
return -1; |
| 95 |
} |
| 96 |
return mSurroundingText.getSelectionStart() + mSurroundingText.getOffset(); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
@IntRange(from = -1) |
| 103 |
public int getSelectionEnd() { |
| 104 |
if (mSurroundingText.getOffset() < 0) { |
| 105 |
return -1; |
| 106 |
} |
| 107 |
return mSurroundingText.getSelectionEnd() + mSurroundingText.getOffset(); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
@IntRange(from = -1) |
| 114 |
public int getCompositionStart() { |
| 115 |
return mCompositionStart; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
@IntRange(from = -1) |
| 122 |
public int getCompositionEnd() { |
| 123 |
return mCompositionEnd; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
public int getCursorCapsMode() { |
| 141 |
return mCursorCapsMode; |
| 142 |
} |
| 143 |
} |
| 144 |
|