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