| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app.smartspace.uitemplatedata; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.SystemApi; |
| 21 |
import android.app.smartspace.SmartspaceUtils; |
| 22 |
import android.os.Parcel; |
| 23 |
import android.os.Parcelable; |
| 24 |
import android.text.TextUtils; |
| 25 |
|
| 26 |
import java.util.Objects; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
@SystemApi |
| 35 |
public final class Text implements Parcelable { |
| 36 |
|
| 37 |
@NonNull |
| 38 |
private final CharSequence mText; |
| 39 |
|
| 40 |
private final TextUtils.TruncateAt mTruncateAtType; |
| 41 |
|
| 42 |
private final int mMaxLines; |
| 43 |
|
| 44 |
Text(Parcel in) { |
| 45 |
mText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 46 |
mTruncateAtType = TextUtils.TruncateAt.valueOf(in.readString()); |
| 47 |
mMaxLines = in.readInt(); |
| 48 |
} |
| 49 |
|
| 50 |
private Text(@NonNull CharSequence text, TextUtils.TruncateAt truncateAtType, int maxLines) { |
| 51 |
mText = text; |
| 52 |
mTruncateAtType = truncateAtType; |
| 53 |
mMaxLines = maxLines; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
@NonNull |
| 58 |
public CharSequence getText() { |
| 59 |
return mText; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
@NonNull |
| 64 |
public TextUtils.TruncateAt getTruncateAtType() { |
| 65 |
return mTruncateAtType; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
public int getMaxLines() { |
| 70 |
return mMaxLines; |
| 71 |
} |
| 72 |
|
| 73 |
@NonNull |
| 74 |
public static final Creator<Text> CREATOR = new Creator<Text>() { |
| 75 |
@Override |
| 76 |
public Text createFromParcel(Parcel in) { |
| 77 |
return new Text(in); |
| 78 |
} |
| 79 |
|
| 80 |
@Override |
| 81 |
public Text[] newArray(int size) { |
| 82 |
return new Text[size]; |
| 83 |
} |
| 84 |
}; |
| 85 |
|
| 86 |
@Override |
| 87 |
public int describeContents() { |
| 88 |
return 0; |
| 89 |
} |
| 90 |
|
| 91 |
@Override |
| 92 |
public boolean equals(Object o) { |
| 93 |
if (this == o) return true; |
| 94 |
if (!(o instanceof Text)) return false; |
| 95 |
Text that = (Text) o; |
| 96 |
return mTruncateAtType == that.mTruncateAtType && SmartspaceUtils.isEqual(mText, |
| 97 |
that.mText) && mMaxLines == that.mMaxLines; |
| 98 |
} |
| 99 |
|
| 100 |
@Override |
| 101 |
public int hashCode() { |
| 102 |
return Objects.hash(mText, mTruncateAtType, mMaxLines); |
| 103 |
} |
| 104 |
|
| 105 |
@Override |
| 106 |
public void writeToParcel(@NonNull Parcel out, int flags) { |
| 107 |
TextUtils.writeToParcel(mText, out, flags); |
| 108 |
out.writeString(mTruncateAtType.name()); |
| 109 |
out.writeInt(mMaxLines); |
| 110 |
} |
| 111 |
|
| 112 |
@Override |
| 113 |
public String toString() { |
| 114 |
return "Text{" |
| 115 |
+ "mText=" + mText |
| 116 |
+ ", mTruncateAtType=" + mTruncateAtType |
| 117 |
+ ", mMaxLines=" + mMaxLines |
| 118 |
+ '}'; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
@SystemApi |
| 127 |
public static final class Builder { |
| 128 |
private final CharSequence mText; |
| 129 |
private TextUtils.TruncateAt mTruncateAtType; |
| 130 |
private int mMaxLines; |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
public Builder(@NonNull CharSequence text) { |
| 137 |
mText = Objects.requireNonNull(text); |
| 138 |
mTruncateAtType = TextUtils.TruncateAt.END; |
| 139 |
mMaxLines = 1; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
@NonNull |
| 147 |
public Builder setTruncateAtType(@NonNull TextUtils.TruncateAt truncateAtType) { |
| 148 |
mTruncateAtType = Objects.requireNonNull(truncateAtType); |
| 149 |
return this; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
@NonNull |
| 156 |
public Builder setMaxLines(int maxLines) { |
| 157 |
mMaxLines = maxLines; |
| 158 |
return this; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
@NonNull |
| 165 |
public Text build() { |
| 166 |
return new Text(mText, mTruncateAtType, mMaxLines); |
| 167 |
} |
| 168 |
} |
| 169 |
} |