| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.hardware.lights; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.Nullable; |
| 22 |
import android.annotation.TestApi; |
| 23 |
import android.os.Parcel; |
| 24 |
import android.os.Parcelable; |
| 25 |
|
| 26 |
import java.lang.annotation.Retention; |
| 27 |
import java.lang.annotation.RetentionPolicy; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public final class Light implements Parcelable { |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public static final int LIGHT_TYPE_MICROPHONE = 8; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public static final int LIGHT_TYPE_CAMERA = 9; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public static final int LIGHT_TYPE_INPUT = 10001; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public static final int LIGHT_TYPE_PLAYER_ID = 10002; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public static final int LIGHT_CAPABILITY_BRIGHTNESS = 1 << 0; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public static final int LIGHT_CAPABILITY_RGB = 0 << 1; |
| 72 |
|
| 73 |
|
| 74 |
@Retention(RetentionPolicy.SOURCE) |
| 75 |
@IntDef(prefix = {"LIGHT_TYPE_"}, |
| 76 |
value = { |
| 77 |
LIGHT_TYPE_MICROPHONE, |
| 78 |
LIGHT_TYPE_INPUT, |
| 79 |
LIGHT_TYPE_PLAYER_ID, |
| 80 |
}) |
| 81 |
public @interface LightType {} |
| 82 |
|
| 83 |
|
| 84 |
@Retention(RetentionPolicy.SOURCE) |
| 85 |
@IntDef(flag = true, prefix = {"LIGHT_CAPABILITY_"}, |
| 86 |
value = { |
| 87 |
LIGHT_CAPABILITY_BRIGHTNESS, |
| 88 |
LIGHT_CAPABILITY_RGB, |
| 89 |
}) |
| 90 |
public @interface LightCapability {} |
| 91 |
|
| 92 |
private final int mId; |
| 93 |
private final String mName; |
| 94 |
private final int mOrdinal; |
| 95 |
private final int mType; |
| 96 |
private final int mCapabilities; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public Light(int id, int ordinal, int type) { |
| 104 |
this(id, "Light", ordinal, type, 0); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
public Light(int id, String name, int ordinal, int type, int capabilities) { |
| 113 |
mId = id; |
| 114 |
mName = name; |
| 115 |
mOrdinal = ordinal; |
| 116 |
mType = type; |
| 117 |
mCapabilities = capabilities; |
| 118 |
} |
| 119 |
|
| 120 |
private Light(@NonNull Parcel in) { |
| 121 |
mId = in.readInt(); |
| 122 |
mName = in.readString(); |
| 123 |
mOrdinal = in.readInt(); |
| 124 |
mType = in.readInt(); |
| 125 |
mCapabilities = in.readInt(); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
@Override |
| 130 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 131 |
dest.writeInt(mId); |
| 132 |
dest.writeString(mName); |
| 133 |
dest.writeInt(mOrdinal); |
| 134 |
dest.writeInt(mType); |
| 135 |
dest.writeInt(mCapabilities); |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
@Override |
| 140 |
public int describeContents() { |
| 141 |
return 0; |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
public static final @android.annotation.NonNull Parcelable.Creator<Light> CREATOR = |
| 146 |
new Parcelable.Creator<Light>() { |
| 147 |
public Light createFromParcel(Parcel in) { |
| 148 |
return new Light(in); |
| 149 |
} |
| 150 |
|
| 151 |
public Light[] newArray(int size) { |
| 152 |
return new Light[size]; |
| 153 |
} |
| 154 |
}; |
| 155 |
|
| 156 |
@Override |
| 157 |
public boolean equals(@Nullable Object obj) { |
| 158 |
if (obj instanceof Light) { |
| 159 |
Light light = (Light) obj; |
| 160 |
return mId == light.mId && mOrdinal == light.mOrdinal && mType == light.mType |
| 161 |
&& mCapabilities == light.mCapabilities; |
| 162 |
} |
| 163 |
return false; |
| 164 |
} |
| 165 |
|
| 166 |
@Override |
| 167 |
public int hashCode() { |
| 168 |
return mId; |
| 169 |
} |
| 170 |
|
| 171 |
@Override |
| 172 |
public String toString() { |
| 173 |
return "[Name=" + mName + " Id=" + mId + " Type=" + mType + " Capabilities=" |
| 174 |
+ mCapabilities + " Ordinal=" + mOrdinal + "]"; |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
public int getId() { |
| 183 |
return mId; |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
@NonNull |
| 190 |
public String getName() { |
| 191 |
return mName; |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
public int getOrdinal() { |
| 202 |
return mOrdinal; |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
public @LightType int getType() { |
| 209 |
return mType; |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
@TestApi |
| 217 |
public @LightCapability int getCapabilities() { |
| 218 |
return mCapabilities; |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
public boolean hasBrightnessControl() { |
| 227 |
return (mCapabilities & LIGHT_CAPABILITY_BRIGHTNESS) == LIGHT_CAPABILITY_BRIGHTNESS; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
public boolean hasRgbControl() { |
| 236 |
return (mCapabilities & LIGHT_CAPABILITY_RGB) == LIGHT_CAPABILITY_RGB; |
| 237 |
} |
| 238 |
|
| 239 |
} |