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:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user