Settings: Do not disturb automatic rule updates.
- Remove FAB for adding rules, move to last preference. - Add first-class event condition type and config sub-page. - Always show radio buttons when adding rules. - Add new data model for event rules. - Add stub condition provider for event rules (always false for now). - Add rule-type icons to rule preference rows. Bug: 20064962 Change-Id: Id5acde371eb2e7d22b1f195459897614db5ba80a
This commit is contained in:
@@ -99,6 +99,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 */ }
|
||||
|
@@ -101,6 +101,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;
|
||||
@@ -341,6 +342,7 @@ public class SettingsActivity extends Activity
|
||||
WifiCallingSettings.class.getName(),
|
||||
ZenModePrioritySettings.class.getName(),
|
||||
ZenModeScheduleRuleSettings.class.getName(),
|
||||
ZenModeEventRuleSettings.class.getName(),
|
||||
ZenModeExternalRuleSettings.class.getName(),
|
||||
ProcessStatsUi.class.getName(),
|
||||
};
|
||||
|
@@ -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<ZenRuleInfo> RULE_COMPARATOR = new Comparator<ZenRuleInfo>() {
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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<String> 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<String> 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() {
|
||||
|
Reference in New Issue
Block a user