diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 866eaaac87c..f01110ad79e 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -759,6 +759,26 @@ android:value="true" /> + + + + + + + + + + + + + + + diff --git a/res/drawable/ic_add.xml b/res/drawable/ic_add.xml new file mode 100644 index 00000000000..5939c97b7c0 --- /dev/null +++ b/res/drawable/ic_add.xml @@ -0,0 +1,24 @@ + + + + diff --git a/res/drawable/ic_event.xml b/res/drawable/ic_event.xml new file mode 100644 index 00000000000..2ca958f1c03 --- /dev/null +++ b/res/drawable/ic_event.xml @@ -0,0 +1,24 @@ + + + + diff --git a/res/drawable/ic_label.xml b/res/drawable/ic_label.xml new file mode 100644 index 00000000000..b1ed068abec --- /dev/null +++ b/res/drawable/ic_label.xml @@ -0,0 +1,24 @@ + + + + diff --git a/res/drawable/ic_schedule.xml b/res/drawable/ic_schedule.xml new file mode 100644 index 00000000000..c77c50edc0a --- /dev/null +++ b/res/drawable/ic_schedule.xml @@ -0,0 +1,29 @@ + + + + + diff --git a/res/layout/zen_rule_name.xml b/res/layout/zen_rule_name.xml index a192c83b544..b7b0415281a 100755 --- a/res/layout/zen_rule_name.xml +++ b/res/layout/zen_rule_name.xml @@ -23,6 +23,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" + android:hint="@string/zen_mode_rule_name_hint" android:layout_marginLeft="22dp" android:layout_marginRight="22dp" > @@ -32,7 +33,6 @@ - + android:layout_height="wrap_content" + android:text="@string/zen_event_rule_type_name" /> + + diff --git a/res/values/strings.xml b/res/values/strings.xml index dd30244d409..9f59b35725f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -6061,8 +6061,11 @@ Rule name + + Enter rule name + - Add rule + Add rule Delete rule @@ -6083,7 +6086,58 @@ Configure rule - Schedule rule + Time rule + + + Automatic rule set to turn on Do Not Disturb during specified times + + + Event rule + + + Automatic rule set to turn on Do Not Disturb during specified events + + + Calendar + + + Any calendar + + + Any reply + + + Any reply except no + + + Replied yes + + + Any + + + Attendance + + + Required or optional + + + Required + + + Optional + + + Reply + + + Any + + + Any except no + + + Yes Rule not found. @@ -6091,7 +6145,7 @@ %1$s / %2$s - + Days diff --git a/res/xml/zen_mode_event_rule_settings.xml b/res/xml/zen_mode_event_rule_settings.xml new file mode 100644 index 00000000000..acad96cad63 --- /dev/null +++ b/res/xml/zen_mode_event_rule_settings.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index f073b43af5e..6723839944f 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -100,6 +100,7 @@ public class Settings extends SettingsActivity { public static class ZenModePrioritySettingsActivity extends SettingsActivity { /* empty */ } public static class ZenModeAutomationSettingsActivity extends SettingsActivity { /* empty */ } public static class ZenModeScheduleRuleSettingsActivity extends SettingsActivity { /* empty */ } + public static class ZenModeEventRuleSettingsActivity extends SettingsActivity { /* empty */ } public static class ZenModeExternalRuleSettingsActivity extends SettingsActivity { /* empty */ } public static class NotificationSettingsActivity extends SettingsActivity { /* empty */ } public static class NotificationAppListActivity extends SettingsActivity { /* empty */ } diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java index 1ae923ab473..502f164f6cf 100644 --- a/src/com/android/settings/SettingsActivity.java +++ b/src/com/android/settings/SettingsActivity.java @@ -102,6 +102,7 @@ import com.android.settings.notification.NotificationAccessSettings; import com.android.settings.notification.NotificationSettings; import com.android.settings.notification.NotificationStation; import com.android.settings.notification.OtherSoundSettings; +import com.android.settings.notification.ZenModeEventRuleSettings; import com.android.settings.notification.ZenModeExternalRuleSettings; import com.android.settings.notification.ZenModePrioritySettings; import com.android.settings.notification.ZenModeSettings; @@ -343,6 +344,7 @@ public class SettingsActivity extends Activity WifiCallingSettings.class.getName(), ZenModePrioritySettings.class.getName(), ZenModeScheduleRuleSettings.class.getName(), + ZenModeEventRuleSettings.class.getName(), ZenModeExternalRuleSettings.class.getName(), ProcessStatsUi.class.getName(), }; diff --git a/src/com/android/settings/notification/ZenModeAutomationSettings.java b/src/com/android/settings/notification/ZenModeAutomationSettings.java index dab0a0d01e2..e33e32f4ba6 100644 --- a/src/com/android/settings/notification/ZenModeAutomationSettings.java +++ b/src/com/android/settings/notification/ZenModeAutomationSettings.java @@ -29,21 +29,22 @@ import android.provider.Settings; import android.provider.Settings.Global; import android.service.notification.ConditionProviderService; import android.service.notification.ZenModeConfig; +import android.service.notification.ZenModeConfig.EventInfo; import android.service.notification.ZenModeConfig.ScheduleInfo; import android.service.notification.ZenModeConfig.ZenRule; import android.text.format.DateFormat; import android.util.Log; -import android.view.View; -import android.view.View.OnClickListener; import com.android.internal.logging.MetricsLogger; import com.android.settings.R; import com.android.settings.notification.ManagedServiceSettings.Config; +import com.android.settings.notification.ZenModeEventRuleSettings.CalendarInfo; import com.android.settings.notification.ZenRuleNameDialog.RuleInfo; -import com.android.settings.widget.FloatingActionButton; import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Calendar; +import java.util.Comparator; import java.util.List; import java.util.TreeSet; @@ -67,21 +68,6 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { mServiceListing.setListening(true); } - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - final FloatingActionButton fab = getFloatingActionButton(); - fab.setVisibility(View.VISIBLE); - fab.setImageResource(R.drawable.ic_menu_add_white); - fab.setContentDescription(getString(R.string.zen_mode_time_add_rule)); - fab.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - showAddRuleDialog(); - } - }); - } - @Override public void onDestroy() { super.onDestroy(); @@ -133,15 +119,32 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { .putExtra(ZenModeRuleSettingsBase.EXTRA_RULE_ID, ruleId)); } + private ZenRuleInfo[] sortedRules() { + final ZenRuleInfo[] rt = new ZenRuleInfo[mConfig.automaticRules.size()]; + for (int i = 0; i < rt.length; i++) { + final ZenRuleInfo zri = new ZenRuleInfo(); + zri.id = mConfig.automaticRules.keyAt(i); + zri.rule = mConfig.automaticRules.valueAt(i); + rt[i] = zri; + } + Arrays.sort(rt, RULE_COMPARATOR); + return rt; + } + private void updateControls() { final PreferenceScreen root = getPreferenceScreen(); root.removeAll(); if (mConfig == null) return; - for (int i = 0; i < mConfig.automaticRules.size(); i++) { - final String id = mConfig.automaticRules.keyAt(i); - final ZenRule rule = mConfig.automaticRules.valueAt(i); + final ZenRuleInfo[] sortedRules = sortedRules(); + for (int i = 0; i < sortedRules.length; i++) { + final String id = sortedRules[i].id; + final ZenRule rule = sortedRules[i].rule; final boolean isSchedule = ZenModeConfig.isValidScheduleConditionId(rule.conditionId); + final boolean isEvent = ZenModeConfig.isValidEventConditionId(rule.conditionId); final Preference p = new Preference(mContext); + p.setIcon(isSchedule ? R.drawable.ic_schedule + : isEvent ? R.drawable.ic_event + : R.drawable.ic_label); p.setTitle(rule.name); p.setSummary(computeRuleSummary(rule)); p.setPersistent(false); @@ -149,6 +152,7 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { @Override public boolean onPreferenceClick(Preference preference) { final String action = isSchedule ? ZenModeScheduleRuleSettings.ACTION + : isEvent ? ZenModeEventRuleSettings.ACTION : ZenModeExternalRuleSettings.ACTION; showRule(action, null, id, rule.name); return true; @@ -156,6 +160,18 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { }); root.addPreference(p); } + final Preference p = new Preference(mContext); + p.setIcon(R.drawable.ic_add); + p.setTitle(R.string.zen_mode_add_rule); + p.setPersistent(false); + p.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + showAddRuleDialog(); + return true; + } + }); + root.addPreference(p); } @Override @@ -165,19 +181,69 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { private String computeRuleSummary(ZenRule rule) { if (rule == null || !rule.enabled) return getString(R.string.switch_off_text); - final ScheduleInfo schedule = ZenModeConfig.tryParseScheduleConditionId(rule.conditionId); final String mode = ZenModeSettings.computeZenModeCaption(getResources(), rule.zenMode); String summary = getString(R.string.switch_on_text); + final ScheduleInfo schedule = ZenModeConfig.tryParseScheduleConditionId(rule.conditionId); + final EventInfo event = ZenModeConfig.tryParseEventConditionId(rule.conditionId); if (schedule != null) { - final String days = computeContiguousDayRanges(schedule.days); - final String start = getTime(schedule.startHour, schedule.startMinute); - final String end = getTime(schedule.endHour, schedule.endMinute); - final String time = getString(R.string.summary_range_verbal_combination, start, end); - summary = getString(R.string.zen_mode_rule_summary_combination, days, time); + summary = computeScheduleRuleSummary(schedule); + } else if (event != null) { + summary = computeEventRuleSummary(event); } return getString(R.string.zen_mode_rule_summary_combination, summary, mode); } + private String computeScheduleRuleSummary(ScheduleInfo schedule) { + final String days = computeContiguousDayRanges(schedule.days); + final String start = getTime(schedule.startHour, schedule.startMinute); + final String end = getTime(schedule.endHour, schedule.endMinute); + final String time = getString(R.string.summary_range_verbal_combination, start, end); + return getString(R.string.zen_mode_rule_summary_combination, days, time); + } + + private String computeEventRuleSummary(EventInfo event) { + final String calendar = computeCalendarName(event); + final String attendance = getString(computeAttendance(event)); + final String reply = getString(computeReply(event)); + return getString(R.string.zen_mode_rule_summary_combination, + getString(R.string.zen_mode_rule_summary_combination, calendar, attendance), reply); + } + + private String computeCalendarName(EventInfo event) { + if (event.calendar != 0) { + final CalendarInfo[] calendars = ZenModeEventRuleSettings.getCalendars(mContext); + for (int i = 0; i < calendars.length; i++) { + final CalendarInfo calendar = calendars[i]; + if (calendar.id == event.calendar) { + return calendar.name; + } + } + } + return getString(R.string.zen_mode_event_rule_summary_any_calendar); + } + + private int computeAttendance(EventInfo event) { + switch (event.attendance) { + case EventInfo.ATTENDANCE_REQUIRED: + return R.string.zen_mode_event_rule_attendance_required; + case EventInfo.ATTENDANCE_OPTIONAL: + return R.string.zen_mode_event_rule_attendance_optional; + default: + return R.string.zen_mode_event_rule_attendance_required_optional; + } + } + + private int computeReply(EventInfo event) { + switch (event.reply) { + case EventInfo.REPLY_ANY_EXCEPT_NO: + return R.string.zen_mode_event_rule_summary_any_reply_except_no; + case EventInfo.REPLY_YES: + return R.string.zen_mode_event_rule_summary_replied_yes; + default: + return R.string.zen_mode_event_rule_summary_any_reply; + } + } + private String getTime(int hour, int minute) { mCalendar.set(Calendar.HOUR_OF_DAY, hour); mCalendar.set(Calendar.MINUTE, minute); @@ -248,4 +314,24 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { } }; + private static final Comparator RULE_COMPARATOR = new Comparator() { + @Override + public int compare(ZenRuleInfo lhs, ZenRuleInfo rhs) { + return key(lhs).compareTo(key(rhs)); + } + + private String key(ZenRuleInfo zri) { + final ZenRule rule = zri.rule; + final int type = ZenModeConfig.isValidScheduleConditionId(rule.conditionId) ? 1 + : ZenModeConfig.isValidEventConditionId(rule.conditionId) ? 2 + : 3; + return type + rule.name; + } + }; + + private static class ZenRuleInfo { + String id; + ZenRule rule; + } + } diff --git a/src/com/android/settings/notification/ZenModeEventRuleSettings.java b/src/com/android/settings/notification/ZenModeEventRuleSettings.java new file mode 100644 index 00000000000..38581b6d6e9 --- /dev/null +++ b/src/com/android/settings/notification/ZenModeEventRuleSettings.java @@ -0,0 +1,180 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.notification; + +import android.content.Context; +import android.database.Cursor; +import android.preference.PreferenceScreen; +import android.provider.CalendarContract.Calendars; +import android.provider.Settings; +import android.service.notification.ZenModeConfig; +import android.service.notification.ZenModeConfig.EventInfo; +import android.service.notification.ZenModeConfig.ZenRule; + +import com.android.internal.logging.MetricsLogger; +import com.android.settings.DropDownPreference; +import com.android.settings.R; + +public class ZenModeEventRuleSettings extends ZenModeRuleSettingsBase { + private static final String KEY_CALENDAR = "calendar"; + private static final String KEY_ATTENDANCE = "attendance"; + private static final String KEY_REPLY = "reply"; + + public static final String ACTION = Settings.ACTION_ZEN_MODE_EVENT_RULE_SETTINGS; + + private DropDownPreference mCalendar; + private DropDownPreference mAttendance; + private DropDownPreference mReply; + + private EventInfo mEvent; + private CalendarInfo[] mCalendars; + + @Override + protected boolean setRule(ZenRule rule) { + mEvent = rule != null ? ZenModeConfig.tryParseEventConditionId(rule.conditionId) + : null; + return mEvent != null; + } + + @Override + protected String getZenModeDependency() { + return null; + } + + @Override + protected int getEnabledToastText() { + return R.string.zen_event_rule_enabled_toast; + } + + @Override + public void onResume() { + super.onResume(); + reloadCalendar(); + } + + private void reloadCalendar() { + mCalendars = getCalendars(mContext); + mCalendar.clearItems(); + mCalendar.addItem(R.string.zen_mode_event_rule_calendar_any, 0L); + for (int i = 0; i < mCalendars.length; i++) { + mCalendar.addItem(mCalendars[i].name, mCalendars[i].id); + } + } + + @Override + protected void onCreateInternal() { + addPreferencesFromResource(R.xml.zen_mode_event_rule_settings); + final PreferenceScreen root = getPreferenceScreen(); + + mCalendar = (DropDownPreference) root.findPreference(KEY_CALENDAR); + mCalendar.setCallback(new DropDownPreference.Callback() { + @Override + public boolean onItemSelected(int pos, Object value) { + final long calendar = (Long) value; + if (calendar == mEvent.calendar) return true; + mEvent.calendar = calendar; + updateRule(ZenModeConfig.toEventConditionId(mEvent)); + return true; + } + }); + + mAttendance = (DropDownPreference) root.findPreference(KEY_ATTENDANCE); + mAttendance.addItem(R.string.zen_mode_event_rule_attendance_required_optional, + EventInfo.ATTENDANCE_REQUIRED_OR_OPTIONAL); + mAttendance.addItem(R.string.zen_mode_event_rule_attendance_required, + EventInfo.ATTENDANCE_REQUIRED); + mAttendance.addItem(R.string.zen_mode_event_rule_attendance_optional, + EventInfo.ATTENDANCE_OPTIONAL); + mAttendance.setCallback(new DropDownPreference.Callback() { + @Override + public boolean onItemSelected(int pos, Object value) { + final int attendance = (Integer) value; + if (attendance == mEvent.attendance) return true; + mEvent.attendance = attendance; + updateRule(ZenModeConfig.toEventConditionId(mEvent)); + return true; + } + }); + + mReply = (DropDownPreference) root.findPreference(KEY_REPLY); + mReply.addItem(R.string.zen_mode_event_rule_reply_any, + EventInfo.REPLY_ANY); + mReply.addItem(R.string.zen_mode_event_rule_reply_any_except_no, + EventInfo.REPLY_ANY_EXCEPT_NO); + mReply.addItem(R.string.zen_mode_event_rule_reply_yes, + EventInfo.REPLY_YES); + mReply.setCallback(new DropDownPreference.Callback() { + @Override + public boolean onItemSelected(int pos, Object value) { + final int reply = (Integer) value; + if (reply == mEvent.reply) return true; + mEvent.reply = reply; + updateRule(ZenModeConfig.toEventConditionId(mEvent)); + return true; + } + }); + + reloadCalendar(); + updateControlsInternal(); + } + + @Override + protected void updateControlsInternal() { + mCalendar.setSelectedValue(mEvent.calendar); + mAttendance.setSelectedValue(mEvent.attendance); + mReply.setSelectedValue(mEvent.reply); + } + + @Override + protected int getMetricsCategory() { + return MetricsLogger.NOTIFICATION_ZEN_MODE_EVENT_RULE; + } + + public static CalendarInfo[] getCalendars(Context context) { + final String primary = "\"primary\""; + final String[] projection = { Calendars._ID, Calendars.CALENDAR_DISPLAY_NAME, + "(" + Calendars.ACCOUNT_NAME + "=" + Calendars.OWNER_ACCOUNT + ") AS " + primary }; + final String selection = primary + " = 1"; + Cursor cursor = null; + try { + cursor = context.getContentResolver().query(Calendars.CONTENT_URI, projection, + selection, null, null); + if (cursor == null) { + return new CalendarInfo[0]; + } + final CalendarInfo[] rt = new CalendarInfo[cursor.getCount()]; + int i = 0; + while (cursor.moveToNext()) { + final CalendarInfo ci = new CalendarInfo(); + ci.id = cursor.getLong(0); + ci.name = cursor.getString(1); + rt[i++] = ci; + } + return rt; + } finally { + if (cursor != null) { + cursor.close(); + } + } + } + + public static class CalendarInfo { + public long id; + public String name; + } + +} diff --git a/src/com/android/settings/notification/ZenModeExternalRuleSettings.java b/src/com/android/settings/notification/ZenModeExternalRuleSettings.java index 9f9dc8a5fcc..8a24e0238f3 100644 --- a/src/com/android/settings/notification/ZenModeExternalRuleSettings.java +++ b/src/com/android/settings/notification/ZenModeExternalRuleSettings.java @@ -57,6 +57,11 @@ public class ZenModeExternalRuleSettings extends ZenModeRuleSettingsBase { return null; } + @Override + protected int getEnabledToastText() { + return 0; + } + @Override protected void onCreateInternal() { addPreferencesFromResource(R.xml.zen_mode_external_rule_settings); diff --git a/src/com/android/settings/notification/ZenModeRuleSettingsBase.java b/src/com/android/settings/notification/ZenModeRuleSettingsBase.java index f6bc75f16d9..cf66da8222f 100644 --- a/src/com/android/settings/notification/ZenModeRuleSettingsBase.java +++ b/src/com/android/settings/notification/ZenModeRuleSettingsBase.java @@ -59,11 +59,13 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase private Preference mRuleName; private SwitchBar mSwitchBar; private DropDownPreference mZenMode; + private Toast mEnabledToast; abstract protected void onCreateInternal(); abstract protected boolean setRule(ZenRule rule); abstract protected String getZenModeDependency(); abstract protected void updateControlsInternal(); + abstract protected int getEnabledToastText(); @Override public void onCreate(Bundle icicle) { @@ -154,6 +156,17 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase mRule.enabled = enabled; mRule.snoozing = false; setZenModeConfig(mConfig); + if (enabled) { + final int toastText = getEnabledToastText(); + if (toastText != 0) { + mEnabledToast = Toast.makeText(mContext, toastText, Toast.LENGTH_SHORT); + mEnabledToast.show(); + } + } else { + if (mEnabledToast != null) { + mEnabledToast.cancel(); + } + } } protected void updateRule(Uri newConditionId) { @@ -247,10 +260,10 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase updateRuleName(); updateControlsInternal(); mZenMode.setSelectedValue(mRule.zenMode); - mDisableListeners = false; if (mSwitchBar != null) { mSwitchBar.setChecked(mRule.enabled); } + mDisableListeners = false; } } diff --git a/src/com/android/settings/notification/ZenModeScheduleRuleSettings.java b/src/com/android/settings/notification/ZenModeScheduleRuleSettings.java index fef31752619..b6b87b5e706 100644 --- a/src/com/android/settings/notification/ZenModeScheduleRuleSettings.java +++ b/src/com/android/settings/notification/ZenModeScheduleRuleSettings.java @@ -73,6 +73,11 @@ public class ZenModeScheduleRuleSettings extends ZenModeRuleSettingsBase { return mDays.getKey(); } + @Override + protected int getEnabledToastText() { + return R.string.zen_schedule_rule_enabled_toast; + } + @Override protected void onCreateInternal() { addPreferencesFromResource(R.xml.zen_mode_schedule_rule_settings); diff --git a/src/com/android/settings/notification/ZenRuleNameDialog.java b/src/com/android/settings/notification/ZenRuleNameDialog.java index 8b44e46f300..cd5c7664fd2 100644 --- a/src/com/android/settings/notification/ZenRuleNameDialog.java +++ b/src/com/android/settings/notification/ZenRuleNameDialog.java @@ -24,6 +24,7 @@ import android.content.DialogInterface.OnDismissListener; import android.content.pm.ServiceInfo; import android.net.Uri; import android.service.notification.ZenModeConfig; +import android.service.notification.ZenModeConfig.EventInfo; import android.service.notification.ZenModeConfig.ScheduleInfo; import android.text.Editable; import android.text.TextUtils; @@ -50,25 +51,30 @@ public abstract class ZenRuleNameDialog { private final ArraySet mExistingNames; private final ServiceListing mServiceListing; private final RuleInfo[] mExternalRules = new RuleInfo[3]; + private final boolean mIsNew; public ZenRuleNameDialog(Context context, ServiceListing serviceListing, String ruleName, ArraySet existingNames) { mServiceListing = serviceListing; + mIsNew = ruleName == null; final View v = LayoutInflater.from(context).inflate(R.layout.zen_rule_name, null, false); mEditText = (EditText) v.findViewById(R.id.rule_name); - if (ruleName != null) { + if (!mIsNew) { mEditText.setText(ruleName); } mEditText.setSelectAllOnFocus(true); mTypes = (RadioGroup) v.findViewById(R.id.rule_types); if (mServiceListing != null) { bindType(R.id.rule_type_schedule, defaultNewSchedule()); + bindType(R.id.rule_type_event, defaultNewEvent()); bindExternalRules(); mServiceListing.addCallback(mServiceListingCallback); mServiceListing.reload(); + } else { + mTypes.setVisibility(View.GONE); } mDialog = new AlertDialog.Builder(context) - .setTitle(R.string.zen_mode_rule_name) + .setTitle(mIsNew ? R.string.zen_mode_add_rule : R.string.zen_mode_rule_name) .setView(v) .setPositiveButton(R.string.okay, new DialogInterface.OnClickListener() { @Override @@ -157,12 +163,21 @@ public abstract class ZenRuleNameDialog { return rt; } + private static RuleInfo defaultNewEvent() { + final EventInfo event = new EventInfo(); + event.calendar = 0; // any + event.attendance = EventInfo.ATTENDANCE_REQUIRED_OR_OPTIONAL; + event.reply = EventInfo.REPLY_ANY_EXCEPT_NO; + final RuleInfo rt = new RuleInfo(); + rt.settingsAction = ZenModeEventRuleSettings.ACTION; + rt.defaultConditionId = ZenModeConfig.toEventConditionId(event); + return rt; + } + private void bindExternalRules() { - bindType(R.id.rule_type_2, mExternalRules[0]); - bindType(R.id.rule_type_3, mExternalRules[1]); - bindType(R.id.rule_type_4, mExternalRules[2]); - // show radio group if we have at least one external rule type - mTypes.setVisibility(mExternalRules[0] != null ? View.VISIBLE : View.GONE); + bindType(R.id.rule_type_3, mExternalRules[0]); + bindType(R.id.rule_type_4, mExternalRules[1]); + bindType(R.id.rule_type_5, mExternalRules[2]); } private final ServiceListing.Callback mServiceListingCallback = new ServiceListing.Callback() {