ZenModeConfigpublic class ZenModeConfig extends Object implements android.os.ParcelablePersisted configuration for zen mode. |
Fields Summary |
---|
private static String | TAG | public static final String | SLEEP_MODE_NIGHTS | public static final String | SLEEP_MODE_WEEKNIGHTS | public static final String | SLEEP_MODE_DAYS_PREFIX | public static final int | SOURCE_ANYONE | public static final int | SOURCE_CONTACT | public static final int | SOURCE_STAR | public static final int | MAX_SOURCE | public static final int[] | ALL_DAYS | public static final int[] | WEEKNIGHT_DAYS | public static final int[] | MINUTE_BUCKETS | private static final int | SECONDS_MS | private static final int | MINUTES_MS | private static final int | ZERO_VALUE_MS | private static final boolean | DEFAULT_ALLOW_EVENTS | private static final int | XML_VERSION | private static final String | ZEN_TAG | private static final String | ZEN_ATT_VERSION | private static final String | ALLOW_TAG | private static final String | ALLOW_ATT_CALLS | private static final String | ALLOW_ATT_MESSAGES | private static final String | ALLOW_ATT_FROM | private static final String | ALLOW_ATT_EVENTS | private static final String | SLEEP_TAG | private static final String | SLEEP_ATT_MODE | private static final String | SLEEP_ATT_NONE | private static final String | SLEEP_ATT_START_HR | private static final String | SLEEP_ATT_START_MIN | private static final String | SLEEP_ATT_END_HR | private static final String | SLEEP_ATT_END_MIN | private static final String | CONDITION_TAG | private static final String | CONDITION_ATT_COMPONENT | private static final String | CONDITION_ATT_ID | private static final String | CONDITION_ATT_SUMMARY | private static final String | CONDITION_ATT_LINE1 | private static final String | CONDITION_ATT_LINE2 | private static final String | CONDITION_ATT_ICON | private static final String | CONDITION_ATT_STATE | private static final String | CONDITION_ATT_FLAGS | private static final String | EXIT_CONDITION_TAG | private static final String | EXIT_CONDITION_ATT_COMPONENT | public boolean | allowCalls | public boolean | allowMessages | public boolean | allowEvents | public int | allowFrom | public String | sleepMode | public int | sleepStartHour | public int | sleepStartMinute | public int | sleepEndHour | public int | sleepEndMinute | public boolean | sleepNone | public android.content.ComponentName[] | conditionComponents | public android.net.Uri[] | conditionIds | public Condition | exitCondition | public android.content.ComponentName | exitConditionComponent | public static final Parcelable.Creator | CREATOR | public static final String | SYSTEM_AUTHORITY | public static final String | COUNTDOWN_PATH | public static final String | DOWNTIME_PATH | public static final String | NEXT_ALARM_PATH |
Constructors Summary |
---|
public ZenModeConfig()
| public ZenModeConfig(android.os.Parcel source)
allowCalls = source.readInt() == 1;
allowMessages = source.readInt() == 1;
allowEvents = source.readInt() == 1;
if (source.readInt() == 1) {
sleepMode = source.readString();
}
sleepStartHour = source.readInt();
sleepStartMinute = source.readInt();
sleepEndHour = source.readInt();
sleepEndMinute = source.readInt();
sleepNone = source.readInt() == 1;
int len = source.readInt();
if (len > 0) {
conditionComponents = new ComponentName[len];
source.readTypedArray(conditionComponents, ComponentName.CREATOR);
}
len = source.readInt();
if (len > 0) {
conditionIds = new Uri[len];
source.readTypedArray(conditionIds, Uri.CREATOR);
}
allowFrom = source.readInt();
exitCondition = source.readParcelable(null);
exitConditionComponent = source.readParcelable(null);
|
Methods Summary |
---|
public android.service.notification.ZenModeConfig | copy()
final Parcel parcel = Parcel.obtain();
try {
writeToParcel(parcel, 0);
parcel.setDataPosition(0);
return new ZenModeConfig(parcel);
} finally {
parcel.recycle();
}
| public int | describeContents()
return 0;
| public boolean | equals(java.lang.Object o)
if (!(o instanceof ZenModeConfig)) return false;
if (o == this) return true;
final ZenModeConfig other = (ZenModeConfig) o;
return other.allowCalls == allowCalls
&& other.allowMessages == allowMessages
&& other.allowFrom == allowFrom
&& other.allowEvents == allowEvents
&& Objects.equals(other.sleepMode, sleepMode)
&& other.sleepNone == sleepNone
&& other.sleepStartHour == sleepStartHour
&& other.sleepStartMinute == sleepStartMinute
&& other.sleepEndHour == sleepEndHour
&& other.sleepEndMinute == sleepEndMinute
&& Objects.deepEquals(other.conditionComponents, conditionComponents)
&& Objects.deepEquals(other.conditionIds, conditionIds)
&& Objects.equals(other.exitCondition, exitCondition)
&& Objects.equals(other.exitConditionComponent, exitConditionComponent);
| public int | hashCode()
return Objects.hash(allowCalls, allowMessages, allowFrom, allowEvents, sleepMode, sleepNone,
sleepStartHour, sleepStartMinute, sleepEndHour, sleepEndMinute,
Arrays.hashCode(conditionComponents), Arrays.hashCode(conditionIds),
exitCondition, exitConditionComponent);
| public boolean | isValid()
return isValidHour(sleepStartHour) && isValidMinute(sleepStartMinute)
&& isValidHour(sleepEndHour) && isValidMinute(sleepEndMinute)
&& isValidSleepMode(sleepMode);
| public static boolean | isValidCountdownConditionId(android.net.Uri conditionId)
return tryParseCountdownConditionId(conditionId) != 0;
| public static boolean | isValidDowntimeConditionId(android.net.Uri conditionId)
return tryParseDowntimeConditionId(conditionId) != null;
| public static boolean | isValidHour(int val)
return val >= 0 && val < 24;
| public static boolean | isValidMinute(int val)
return val >= 0 && val < 60;
| public static boolean | isValidSleepMode(java.lang.String sleepMode)
return sleepMode == null || sleepMode.equals(SLEEP_MODE_NIGHTS)
|| sleepMode.equals(SLEEP_MODE_WEEKNIGHTS) || tryParseDays(sleepMode) != null;
| public static Condition | readConditionXml(org.xmlpull.v1.XmlPullParser parser)
final Uri id = safeUri(parser, CONDITION_ATT_ID);
final String summary = parser.getAttributeValue(null, CONDITION_ATT_SUMMARY);
final String line1 = parser.getAttributeValue(null, CONDITION_ATT_LINE1);
final String line2 = parser.getAttributeValue(null, CONDITION_ATT_LINE2);
final int icon = safeInt(parser, CONDITION_ATT_ICON, -1);
final int state = safeInt(parser, CONDITION_ATT_STATE, -1);
final int flags = safeInt(parser, CONDITION_ATT_FLAGS, -1);
try {
return new Condition(id, summary, line1, line2, icon, state, flags);
} catch (IllegalArgumentException e) {
Slog.w(TAG, "Unable to read condition xml", e);
return null;
}
| public static android.service.notification.ZenModeConfig | readXml(org.xmlpull.v1.XmlPullParser parser)
int type = parser.getEventType();
if (type != XmlPullParser.START_TAG) return null;
String tag = parser.getName();
if (!ZEN_TAG.equals(tag)) return null;
final ZenModeConfig rt = new ZenModeConfig();
final int version = safeInt(parser, ZEN_ATT_VERSION, XML_VERSION);
final ArrayList<ComponentName> conditionComponents = new ArrayList<ComponentName>();
final ArrayList<Uri> conditionIds = new ArrayList<Uri>();
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
tag = parser.getName();
if (type == XmlPullParser.END_TAG && ZEN_TAG.equals(tag)) {
if (!conditionComponents.isEmpty()) {
rt.conditionComponents = conditionComponents
.toArray(new ComponentName[conditionComponents.size()]);
rt.conditionIds = conditionIds.toArray(new Uri[conditionIds.size()]);
}
return rt;
}
if (type == XmlPullParser.START_TAG) {
if (ALLOW_TAG.equals(tag)) {
rt.allowCalls = safeBoolean(parser, ALLOW_ATT_CALLS, false);
rt.allowMessages = safeBoolean(parser, ALLOW_ATT_MESSAGES, false);
rt.allowEvents = safeBoolean(parser, ALLOW_ATT_EVENTS, DEFAULT_ALLOW_EVENTS);
rt.allowFrom = safeInt(parser, ALLOW_ATT_FROM, SOURCE_ANYONE);
if (rt.allowFrom < SOURCE_ANYONE || rt.allowFrom > MAX_SOURCE) {
throw new IndexOutOfBoundsException("bad source in config:" + rt.allowFrom);
}
} else if (SLEEP_TAG.equals(tag)) {
final String mode = parser.getAttributeValue(null, SLEEP_ATT_MODE);
rt.sleepMode = isValidSleepMode(mode)? mode : null;
rt.sleepNone = safeBoolean(parser, SLEEP_ATT_NONE, false);
final int startHour = safeInt(parser, SLEEP_ATT_START_HR, 0);
final int startMinute = safeInt(parser, SLEEP_ATT_START_MIN, 0);
final int endHour = safeInt(parser, SLEEP_ATT_END_HR, 0);
final int endMinute = safeInt(parser, SLEEP_ATT_END_MIN, 0);
rt.sleepStartHour = isValidHour(startHour) ? startHour : 0;
rt.sleepStartMinute = isValidMinute(startMinute) ? startMinute : 0;
rt.sleepEndHour = isValidHour(endHour) ? endHour : 0;
rt.sleepEndMinute = isValidMinute(endMinute) ? endMinute : 0;
} else if (CONDITION_TAG.equals(tag)) {
final ComponentName component =
safeComponentName(parser, CONDITION_ATT_COMPONENT);
final Uri conditionId = safeUri(parser, CONDITION_ATT_ID);
if (component != null && conditionId != null) {
conditionComponents.add(component);
conditionIds.add(conditionId);
}
} else if (EXIT_CONDITION_TAG.equals(tag)) {
rt.exitCondition = readConditionXml(parser);
if (rt.exitCondition != null) {
rt.exitConditionComponent =
safeComponentName(parser, EXIT_CONDITION_ATT_COMPONENT);
}
}
}
}
throw new IllegalStateException("Failed to reach END_DOCUMENT");
| private static boolean | safeBoolean(org.xmlpull.v1.XmlPullParser parser, java.lang.String att, boolean defValue)
final String val = parser.getAttributeValue(null, att);
if (TextUtils.isEmpty(val)) return defValue;
return Boolean.valueOf(val);
| private static android.content.ComponentName | safeComponentName(org.xmlpull.v1.XmlPullParser parser, java.lang.String att)
final String val = parser.getAttributeValue(null, att);
if (TextUtils.isEmpty(val)) return null;
return ComponentName.unflattenFromString(val);
| private static int | safeInt(org.xmlpull.v1.XmlPullParser parser, java.lang.String att, int defValue)
final String val = parser.getAttributeValue(null, att);
return tryParseInt(val, defValue);
| private static android.net.Uri | safeUri(org.xmlpull.v1.XmlPullParser parser, java.lang.String att)
final String val = parser.getAttributeValue(null, att);
if (TextUtils.isEmpty(val)) return null;
return Uri.parse(val);
| public static java.lang.String | sourceToString(int source)
switch (source) {
case SOURCE_ANYONE:
return "anyone";
case SOURCE_CONTACT:
return "contacts";
case SOURCE_STAR:
return "stars";
default:
return "UNKNOWN";
}
| public static android.net.Uri | toCountdownConditionId(long time)
return new Uri.Builder().scheme(Condition.SCHEME)
.authority(SYSTEM_AUTHORITY)
.appendPath(COUNTDOWN_PATH)
.appendPath(Long.toString(time))
.build();
| public static android.net.Uri | toDowntimeConditionId(android.service.notification.ZenModeConfig$DowntimeInfo downtime)
return new Uri.Builder().scheme(Condition.SCHEME)
.authority(SYSTEM_AUTHORITY)
.appendPath(DOWNTIME_PATH)
.appendQueryParameter("start", downtime.startHour + "." + downtime.startMinute)
.appendQueryParameter("end", downtime.endHour + "." + downtime.endMinute)
.appendQueryParameter("mode", downtime.mode)
.appendQueryParameter("none", Boolean.toString(downtime.none))
.build();
| public android.service.notification.ZenModeConfig$DowntimeInfo | toDowntimeInfo()
final DowntimeInfo downtime = new DowntimeInfo();
downtime.startHour = sleepStartHour;
downtime.startMinute = sleepStartMinute;
downtime.endHour = sleepEndHour;
downtime.endMinute = sleepEndMinute;
downtime.mode = sleepMode;
downtime.none = sleepNone;
return downtime;
| public java.lang.String | toString()
return new StringBuilder(ZenModeConfig.class.getSimpleName()).append('[")
.append("allowCalls=").append(allowCalls)
.append(",allowMessages=").append(allowMessages)
.append(",allowFrom=").append(sourceToString(allowFrom))
.append(",allowEvents=").append(allowEvents)
.append(",sleepMode=").append(sleepMode)
.append(",sleepStart=").append(sleepStartHour).append('.").append(sleepStartMinute)
.append(",sleepEnd=").append(sleepEndHour).append('.").append(sleepEndMinute)
.append(",sleepNone=").append(sleepNone)
.append(",conditionComponents=")
.append(conditionComponents == null ? null : TextUtils.join(",", conditionComponents))
.append(",conditionIds=")
.append(conditionIds == null ? null : TextUtils.join(",", conditionIds))
.append(",exitCondition=").append(exitCondition)
.append(",exitConditionComponent=").append(exitConditionComponent)
.append(']").toString();
| public static Condition | toTimeCondition(android.content.Context context, int minutesFromNow, int userHandle)
final long now = System.currentTimeMillis();
final long millis = minutesFromNow == 0 ? ZERO_VALUE_MS : minutesFromNow * MINUTES_MS;
return toTimeCondition(context, now + millis, minutesFromNow, now, userHandle);
| public static Condition | toTimeCondition(android.content.Context context, long time, int minutes, long now, int userHandle)
final int num, summaryResId, line1ResId;
if (minutes < 60) {
// display as minutes
num = minutes;
summaryResId = R.plurals.zen_mode_duration_minutes_summary;
line1ResId = R.plurals.zen_mode_duration_minutes;
} else {
// display as hours
num = Math.round(minutes / 60f);
summaryResId = com.android.internal.R.plurals.zen_mode_duration_hours_summary;
line1ResId = com.android.internal.R.plurals.zen_mode_duration_hours;
}
final String skeleton = DateFormat.is24HourFormat(context, userHandle) ? "Hm" : "hma";
final String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
final CharSequence formattedTime = DateFormat.format(pattern, time);
final Resources res = context.getResources();
final String summary = res.getQuantityString(summaryResId, num, num, formattedTime);
final String line1 = res.getQuantityString(line1ResId, num, num, formattedTime);
final String line2 = res.getString(R.string.zen_mode_until, formattedTime);
final Uri id = toCountdownConditionId(time);
return new Condition(id, summary, line1, line2, 0, Condition.STATE_TRUE,
Condition.FLAG_RELEVANT_NOW);
| public static long | tryParseCountdownConditionId(android.net.Uri conditionId)
if (!Condition.isValidId(conditionId, SYSTEM_AUTHORITY)) return 0;
if (conditionId.getPathSegments().size() != 2
|| !COUNTDOWN_PATH.equals(conditionId.getPathSegments().get(0))) return 0;
try {
return Long.parseLong(conditionId.getPathSegments().get(1));
} catch (RuntimeException e) {
Slog.w(TAG, "Error parsing countdown condition: " + conditionId, e);
return 0;
}
| public static int[] | tryParseDays(java.lang.String sleepMode)
if (sleepMode == null) return null;
sleepMode = sleepMode.trim();
if (SLEEP_MODE_NIGHTS.equals(sleepMode)) return ALL_DAYS;
if (SLEEP_MODE_WEEKNIGHTS.equals(sleepMode)) return WEEKNIGHT_DAYS;
if (!sleepMode.startsWith(SLEEP_MODE_DAYS_PREFIX)) return null;
if (sleepMode.equals(SLEEP_MODE_DAYS_PREFIX)) return null;
final String[] tokens = sleepMode.substring(SLEEP_MODE_DAYS_PREFIX.length()).split(",");
if (tokens.length == 0) return null;
final int[] rt = new int[tokens.length];
for (int i = 0; i < tokens.length; i++) {
final int day = tryParseInt(tokens[i], -1);
if (day == -1) return null;
rt[i] = day;
}
return rt;
| public static android.service.notification.ZenModeConfig$DowntimeInfo | tryParseDowntimeConditionId(android.net.Uri conditionId)
if (!Condition.isValidId(conditionId, SYSTEM_AUTHORITY)
|| conditionId.getPathSegments().size() != 1
|| !DOWNTIME_PATH.equals(conditionId.getPathSegments().get(0))) {
return null;
}
final int[] start = tryParseHourAndMinute(conditionId.getQueryParameter("start"));
final int[] end = tryParseHourAndMinute(conditionId.getQueryParameter("end"));
if (start == null || end == null) return null;
final DowntimeInfo downtime = new DowntimeInfo();
downtime.startHour = start[0];
downtime.startMinute = start[1];
downtime.endHour = end[0];
downtime.endMinute = end[1];
downtime.mode = conditionId.getQueryParameter("mode");
downtime.none = Boolean.toString(true).equals(conditionId.getQueryParameter("none"));
return downtime;
| private static int[] | tryParseHourAndMinute(java.lang.String value)
if (TextUtils.isEmpty(value)) return null;
final int i = value.indexOf('.");
if (i < 1 || i >= value.length() - 1) return null;
final int hour = tryParseInt(value.substring(0, i), -1);
final int minute = tryParseInt(value.substring(i + 1), -1);
return isValidHour(hour) && isValidMinute(minute) ? new int[] { hour, minute } : null;
| private static int | tryParseInt(java.lang.String value, int defValue)
if (TextUtils.isEmpty(value)) return defValue;
try {
return Integer.valueOf(value);
} catch (NumberFormatException e) {
return defValue;
}
| public static void | writeConditionXml(Condition c, org.xmlpull.v1.XmlSerializer out)
out.attribute(null, CONDITION_ATT_ID, c.id.toString());
out.attribute(null, CONDITION_ATT_SUMMARY, c.summary);
out.attribute(null, CONDITION_ATT_LINE1, c.line1);
out.attribute(null, CONDITION_ATT_LINE2, c.line2);
out.attribute(null, CONDITION_ATT_ICON, Integer.toString(c.icon));
out.attribute(null, CONDITION_ATT_STATE, Integer.toString(c.state));
out.attribute(null, CONDITION_ATT_FLAGS, Integer.toString(c.flags));
| public void | writeToParcel(android.os.Parcel dest, int flags)
dest.writeInt(allowCalls ? 1 : 0);
dest.writeInt(allowMessages ? 1 : 0);
dest.writeInt(allowEvents ? 1 : 0);
if (sleepMode != null) {
dest.writeInt(1);
dest.writeString(sleepMode);
} else {
dest.writeInt(0);
}
dest.writeInt(sleepStartHour);
dest.writeInt(sleepStartMinute);
dest.writeInt(sleepEndHour);
dest.writeInt(sleepEndMinute);
dest.writeInt(sleepNone ? 1 : 0);
if (conditionComponents != null && conditionComponents.length > 0) {
dest.writeInt(conditionComponents.length);
dest.writeTypedArray(conditionComponents, 0);
} else {
dest.writeInt(0);
}
if (conditionIds != null && conditionIds.length > 0) {
dest.writeInt(conditionIds.length);
dest.writeTypedArray(conditionIds, 0);
} else {
dest.writeInt(0);
}
dest.writeInt(allowFrom);
dest.writeParcelable(exitCondition, 0);
dest.writeParcelable(exitConditionComponent, 0);
| public void | writeXml(org.xmlpull.v1.XmlSerializer out)
out.startTag(null, ZEN_TAG);
out.attribute(null, ZEN_ATT_VERSION, Integer.toString(XML_VERSION));
out.startTag(null, ALLOW_TAG);
out.attribute(null, ALLOW_ATT_CALLS, Boolean.toString(allowCalls));
out.attribute(null, ALLOW_ATT_MESSAGES, Boolean.toString(allowMessages));
out.attribute(null, ALLOW_ATT_EVENTS, Boolean.toString(allowEvents));
out.attribute(null, ALLOW_ATT_FROM, Integer.toString(allowFrom));
out.endTag(null, ALLOW_TAG);
out.startTag(null, SLEEP_TAG);
if (sleepMode != null) {
out.attribute(null, SLEEP_ATT_MODE, sleepMode);
}
out.attribute(null, SLEEP_ATT_NONE, Boolean.toString(sleepNone));
out.attribute(null, SLEEP_ATT_START_HR, Integer.toString(sleepStartHour));
out.attribute(null, SLEEP_ATT_START_MIN, Integer.toString(sleepStartMinute));
out.attribute(null, SLEEP_ATT_END_HR, Integer.toString(sleepEndHour));
out.attribute(null, SLEEP_ATT_END_MIN, Integer.toString(sleepEndMinute));
out.endTag(null, SLEEP_TAG);
if (conditionComponents != null && conditionIds != null
&& conditionComponents.length == conditionIds.length) {
for (int i = 0; i < conditionComponents.length; i++) {
out.startTag(null, CONDITION_TAG);
out.attribute(null, CONDITION_ATT_COMPONENT,
conditionComponents[i].flattenToString());
out.attribute(null, CONDITION_ATT_ID, conditionIds[i].toString());
out.endTag(null, CONDITION_TAG);
}
}
if (exitCondition != null && exitConditionComponent != null) {
out.startTag(null, EXIT_CONDITION_TAG);
out.attribute(null, EXIT_CONDITION_ATT_COMPONENT,
exitConditionComponent.flattenToString());
writeConditionXml(exitCondition, out);
out.endTag(null, EXIT_CONDITION_TAG);
}
out.endTag(null, ZEN_TAG);
|
|