| 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.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.graphics.RectF; |
| 22 |
import android.os.Parcel; |
| 23 |
import android.os.Parcelable; |
| 24 |
|
| 25 |
import java.util.Objects; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public final class EditorBoundsInfo implements Parcelable { |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
private final RectF mEditorBounds; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
private final RectF mHandwritingBounds; |
| 42 |
|
| 43 |
private final int mHashCode; |
| 44 |
|
| 45 |
private EditorBoundsInfo(@NonNull Parcel source) { |
| 46 |
mHashCode = source.readInt(); |
| 47 |
mEditorBounds = source.readTypedObject(RectF.CREATOR); |
| 48 |
mHandwritingBounds = source.readTypedObject(RectF.CREATOR); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
@Nullable |
| 58 |
public RectF getEditorBounds() { |
| 59 |
return mEditorBounds; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
@Nullable |
| 70 |
public RectF getHandwritingBounds() { |
| 71 |
return mHandwritingBounds; |
| 72 |
} |
| 73 |
|
| 74 |
@Override |
| 75 |
public int hashCode() { |
| 76 |
return mHashCode; |
| 77 |
} |
| 78 |
|
| 79 |
@Override |
| 80 |
public String toString() { |
| 81 |
return "EditorBoundsInfo{mEditorBounds=" + mEditorBounds |
| 82 |
+ " mHandwritingBounds=" + mHandwritingBounds |
| 83 |
+ "}"; |
| 84 |
} |
| 85 |
|
| 86 |
@Override |
| 87 |
public boolean equals(@Nullable Object obj) { |
| 88 |
if (obj == null) { |
| 89 |
return false; |
| 90 |
} |
| 91 |
EditorBoundsInfo bounds; |
| 92 |
if (obj instanceof EditorBoundsInfo) { |
| 93 |
bounds = (EditorBoundsInfo) obj; |
| 94 |
} else { |
| 95 |
return false; |
| 96 |
} |
| 97 |
return Objects.equals(bounds.mEditorBounds, mEditorBounds) |
| 98 |
&& Objects.equals(bounds.mHandwritingBounds, mHandwritingBounds); |
| 99 |
} |
| 100 |
|
| 101 |
@Override |
| 102 |
public int describeContents() { |
| 103 |
return 0; |
| 104 |
} |
| 105 |
|
| 106 |
@Override |
| 107 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 108 |
dest.writeInt(mHashCode); |
| 109 |
dest.writeTypedObject(mEditorBounds, flags); |
| 110 |
dest.writeTypedObject(mHandwritingBounds, flags); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public static final @android.annotation.NonNull Parcelable.Creator<EditorBoundsInfo> CREATOR |
| 117 |
= new Parcelable.Creator<EditorBoundsInfo>() { |
| 118 |
@Override |
| 119 |
public EditorBoundsInfo createFromParcel(@NonNull Parcel source) { |
| 120 |
return new EditorBoundsInfo(source); |
| 121 |
} |
| 122 |
|
| 123 |
@Override |
| 124 |
public EditorBoundsInfo[] newArray(int size) { |
| 125 |
return new EditorBoundsInfo[size]; |
| 126 |
} |
| 127 |
}; |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
public static final class Builder { |
| 133 |
private RectF mEditorBounds = null; |
| 134 |
private RectF mHandwritingBounds = null; |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
@NonNull |
| 142 |
public EditorBoundsInfo.Builder setEditorBounds(@Nullable RectF bounds) { |
| 143 |
mEditorBounds = bounds; |
| 144 |
return this; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
@NonNull |
| 153 |
public EditorBoundsInfo.Builder setHandwritingBounds(@Nullable RectF bounds) { |
| 154 |
mHandwritingBounds = bounds; |
| 155 |
return this; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
@NonNull |
| 163 |
public EditorBoundsInfo build() { |
| 164 |
return new EditorBoundsInfo(this); |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
private EditorBoundsInfo(final EditorBoundsInfo.Builder builder) { |
| 169 |
mEditorBounds = builder.mEditorBounds; |
| 170 |
mHandwritingBounds = builder.mHandwritingBounds; |
| 171 |
|
| 172 |
int hash = Objects.hashCode(mEditorBounds); |
| 173 |
hash *= 31; |
| 174 |
hash += Objects.hashCode(mHandwritingBounds); |
| 175 |
mHashCode = hash; |
| 176 |
} |
| 177 |
} |