Add DND Suggestion after 30 days
Suggest users setup automatic rules if they haven't after 30 days Also fix the id labeling for the RV adapter, so that it can handle removing of suggestions properly. Change-Id: I0cce76f3db1d444011f7d8a31348714d102650cf
This commit is contained in:
@@ -813,6 +813,23 @@
|
|||||||
android:value="true" />
|
android:value="true" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name="Settings$ZenModeAutomationSuggestionActivity"
|
||||||
|
android:label="@string/zen_mode_automation_settings_title"
|
||||||
|
android:icon="@drawable/ic_settings_notifications"
|
||||||
|
android:exported="true"
|
||||||
|
android:taskAffinity="">
|
||||||
|
<intent-filter android:priority="1">
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="com.android.settings.suggested.category.SETTINGS_ONLY" />
|
||||||
|
</intent-filter>
|
||||||
|
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||||
|
android:value="com.android.settings.notification.ZenModeAutomationSettings" />
|
||||||
|
<meta-data android:name="com.android.settings.dismiss"
|
||||||
|
android:value="30" />
|
||||||
|
<meta-data android:name="com.android.settings.title"
|
||||||
|
android:resource="@string/zen_mode_automation_suggestion_title" />
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity android:name="Settings$ZenModeScheduleRuleSettingsActivity"
|
<activity android:name="Settings$ZenModeScheduleRuleSettingsActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:taskAffinity="">
|
android:taskAffinity="">
|
||||||
|
@@ -5768,6 +5768,9 @@
|
|||||||
<!-- Do not disturb: Title for the zen mode automation option and associated settings page. [CHAR LIMIT=30] -->
|
<!-- Do not disturb: Title for the zen mode automation option and associated settings page. [CHAR LIMIT=30] -->
|
||||||
<string name="zen_mode_automation_settings_title">Automatic rules</string>
|
<string name="zen_mode_automation_settings_title">Automatic rules</string>
|
||||||
|
|
||||||
|
<!-- Do not disturb: Title for the zen mode automation option Suggestion. [CHAR LIMIT=30] -->
|
||||||
|
<string name="zen_mode_automation_suggestion_title">Set up Do Not Disturb Schedule</string>
|
||||||
|
|
||||||
<!-- Do not disturb: Zen mode option: Important interruptions [CHAR LIMIT=60] -->
|
<!-- Do not disturb: Zen mode option: Important interruptions [CHAR LIMIT=60] -->
|
||||||
<string name="zen_mode_option_important_interruptions">Priority only</string>
|
<string name="zen_mode_option_important_interruptions">Priority only</string>
|
||||||
|
|
||||||
|
@@ -22,4 +22,6 @@
|
|||||||
multiple="true" />
|
multiple="true" />
|
||||||
<step category="com.android.settings.suggested.category.DEFAULT"
|
<step category="com.android.settings.suggested.category.DEFAULT"
|
||||||
multiple="true" />
|
multiple="true" />
|
||||||
|
<step category="com.android.settings.suggested.category.SETTINGS_ONLY"
|
||||||
|
multiple="true" />
|
||||||
</optional-steps>
|
</optional-steps>
|
||||||
|
@@ -103,6 +103,7 @@ public class Settings extends SettingsActivity {
|
|||||||
public static class ZenModeSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class ZenModeSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class ZenModePrioritySettingsActivity extends SettingsActivity { /* empty */ }
|
public static class ZenModePrioritySettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class ZenModeAutomationSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class ZenModeAutomationSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
|
public static class ZenModeAutomationSuggestionActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class ZenModeScheduleRuleSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class ZenModeScheduleRuleSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class ZenModeEventRuleSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class ZenModeEventRuleSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class ZenModeExternalRuleSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class ZenModeExternalRuleSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
|
@@ -43,6 +43,10 @@ import java.util.List;
|
|||||||
public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.DashboardItemHolder>
|
public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.DashboardItemHolder>
|
||||||
implements View.OnClickListener {
|
implements View.OnClickListener {
|
||||||
public static final String TAG = "DashboardAdapter";
|
public static final String TAG = "DashboardAdapter";
|
||||||
|
private static final int NS_SPACER = 0;
|
||||||
|
private static final int NS_SUGGESTION = 1000;
|
||||||
|
private static final int NS_ITEMS = 2000;
|
||||||
|
private static final int NS_CONDITION = 3000;
|
||||||
|
|
||||||
private static int SUGGESTION_MODE_DEFAULT = 0;
|
private static int SUGGESTION_MODE_DEFAULT = 0;
|
||||||
private static int SUGGESTION_MODE_COLLAPSED = 1;
|
private static int SUGGESTION_MODE_COLLAPSED = 1;
|
||||||
@@ -55,6 +59,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
private final List<Integer> mIds = new ArrayList<>();
|
private final List<Integer> mIds = new ArrayList<>();
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
private final SuggestionsChecks mSuggestionsChecks;
|
||||||
|
|
||||||
private List<DashboardCategory> mCategories;
|
private List<DashboardCategory> mCategories;
|
||||||
private List<Condition> mConditions;
|
private List<Condition> mConditions;
|
||||||
@@ -71,13 +76,20 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
|
|
||||||
public DashboardAdapter(Context context) {
|
public DashboardAdapter(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
mSuggestionsChecks = new SuggestionsChecks(mContext);
|
||||||
|
|
||||||
setHasStableIds(true);
|
setHasStableIds(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSuggestions(SuggestionParser suggestionParser) {
|
public void setSuggestions(SuggestionParser suggestionParser) {
|
||||||
mSuggestions = suggestionParser.getSuggestions();
|
|
||||||
mSuggestionParser = suggestionParser;
|
mSuggestionParser = suggestionParser;
|
||||||
|
mSuggestions = suggestionParser.getSuggestions();
|
||||||
|
for (int i = 0; i < mSuggestions.size(); i++) {
|
||||||
|
if (mSuggestionsChecks.isSuggestionComplete(mSuggestions.get(i))) {
|
||||||
|
disableSuggestion(mSuggestions.get(i));
|
||||||
|
mSuggestions.remove(i--);
|
||||||
|
}
|
||||||
|
}
|
||||||
recountItems();
|
recountItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,35 +139,42 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
for (int i = 0; mConditions != null && i < mConditions.size(); i++) {
|
for (int i = 0; mConditions != null && i < mConditions.size(); i++) {
|
||||||
boolean shouldShow = mConditions.get(i).shouldShow();
|
boolean shouldShow = mConditions.get(i).shouldShow();
|
||||||
hasConditions |= shouldShow;
|
hasConditions |= shouldShow;
|
||||||
countItem(mConditions.get(i), R.layout.condition_card, shouldShow);
|
countItem(mConditions.get(i), R.layout.condition_card, shouldShow, NS_CONDITION);
|
||||||
}
|
}
|
||||||
boolean hasSuggestions = mSuggestions != null && mSuggestions.size() != 0;
|
boolean hasSuggestions = mSuggestions != null && mSuggestions.size() != 0;
|
||||||
countItem(null, R.layout.dashboard_spacer, hasConditions && hasSuggestions);
|
countItem(null, R.layout.dashboard_spacer, hasConditions && hasSuggestions, NS_SPACER);
|
||||||
countItem(null, R.layout.suggestion_header, hasSuggestions);
|
countItem(null, R.layout.suggestion_header, hasSuggestions, NS_SPACER);
|
||||||
|
resetCount();
|
||||||
if (mSuggestions != null) {
|
if (mSuggestions != null) {
|
||||||
int maxSuggestions = mSuggestionMode == SUGGESTION_MODE_DEFAULT
|
int maxSuggestions = mSuggestionMode == SUGGESTION_MODE_DEFAULT
|
||||||
? Math.min(DEFAULT_SUGGESTION_COUNT, mSuggestions.size())
|
? Math.min(DEFAULT_SUGGESTION_COUNT, mSuggestions.size())
|
||||||
: mSuggestionMode == SUGGESTION_MODE_EXPANDED ? mSuggestions.size()
|
: mSuggestionMode == SUGGESTION_MODE_EXPANDED ? mSuggestions.size()
|
||||||
: 0;
|
: 0;
|
||||||
for (int i = 0; i < mSuggestions.size(); i++) {
|
for (int i = 0; i < mSuggestions.size(); i++) {
|
||||||
countItem(mSuggestions.get(i), R.layout.suggestion_tile, i < maxSuggestions);
|
countItem(mSuggestions.get(i), R.layout.suggestion_tile, i < maxSuggestions,
|
||||||
|
NS_SUGGESTION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
countItem(null, R.layout.dashboard_spacer, true);
|
countItem(null, R.layout.dashboard_spacer, true, NS_SPACER);
|
||||||
|
resetCount();
|
||||||
for (int i = 0; mCategories != null && i < mCategories.size(); i++) {
|
for (int i = 0; mCategories != null && i < mCategories.size(); i++) {
|
||||||
DashboardCategory category = mCategories.get(i);
|
DashboardCategory category = mCategories.get(i);
|
||||||
countItem(category, R.layout.dashboard_category, mIsShowingAll);
|
countItem(category, R.layout.dashboard_category, mIsShowingAll, NS_ITEMS);
|
||||||
for (int j = 0; j < category.tiles.size(); j++) {
|
for (int j = 0; j < category.tiles.size(); j++) {
|
||||||
Tile tile = category.tiles.get(j);
|
Tile tile = category.tiles.get(j);
|
||||||
countItem(tile, R.layout.dashboard_tile, mIsShowingAll
|
countItem(tile, R.layout.dashboard_tile, mIsShowingAll
|
||||||
|| ArrayUtils.contains(DashboardSummary.INITIAL_ITEMS,
|
|| ArrayUtils.contains(DashboardSummary.INITIAL_ITEMS,
|
||||||
tile.intent.getComponent().getClassName()));
|
tile.intent.getComponent().getClassName()), NS_ITEMS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
countItem(null, R.layout.see_all, true);
|
countItem(null, R.layout.see_all, true, NS_ITEMS);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resetCount() {
|
||||||
|
mId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
private void reset() {
|
private void reset() {
|
||||||
mItems.clear();
|
mItems.clear();
|
||||||
mTypes.clear();
|
mTypes.clear();
|
||||||
@@ -163,12 +182,12 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
mId = 0;
|
mId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void countItem(Object object, int type, boolean add) {
|
private void countItem(Object object, int type, boolean add, int nameSpace) {
|
||||||
if (add) {
|
if (add) {
|
||||||
mItems.add(object);
|
mItems.add(object);
|
||||||
mTypes.add(type);
|
mTypes.add(type);
|
||||||
// TODO: Counting namespaces for handling of suggestions/conds appearing/disappearing.
|
// TODO: Counting namespaces for handling of suggestions/conds appearing/disappearing.
|
||||||
mIds.add(mId);
|
mIds.add(mId + nameSpace);
|
||||||
}
|
}
|
||||||
mId++;
|
mId++;
|
||||||
}
|
}
|
||||||
@@ -238,12 +257,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
new MenuItem.OnMenuItemClickListener() {
|
new MenuItem.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
if (mSuggestionParser.dismissSuggestion(suggestion)) {
|
disableSuggestion(suggestion);
|
||||||
mContext.getPackageManager().setComponentEnabledSetting(
|
|
||||||
suggestion.intent.getComponent(),
|
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
|
||||||
PackageManager.DONT_KILL_APP);
|
|
||||||
}
|
|
||||||
mSuggestions.remove(suggestion);
|
mSuggestions.remove(suggestion);
|
||||||
recountItems();
|
recountItems();
|
||||||
return true;
|
return true;
|
||||||
@@ -252,6 +266,15 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
popup.show();
|
popup.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void disableSuggestion(Tile suggestion) {
|
||||||
|
if (mSuggestionParser.dismissSuggestion(suggestion)) {
|
||||||
|
mContext.getPackageManager().setComponentEnabledSetting(
|
||||||
|
suggestion.intent.getComponent(),
|
||||||
|
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||||
|
PackageManager.DONT_KILL_APP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void onBindSuggestionHeader(final DashboardItemHolder holder) {
|
private void onBindSuggestionHeader(final DashboardItemHolder holder) {
|
||||||
holder.icon.setImageResource(hasMoreSuggestions() ? R.drawable.ic_expand_more
|
holder.icon.setImageResource(hasMoreSuggestions() ? R.drawable.ic_expand_more
|
||||||
: R.drawable.ic_expand_less);
|
: R.drawable.ic_expand_less);
|
||||||
|
55
src/com/android/settings/dashboard/SuggestionsChecks.java
Normal file
55
src/com/android/settings/dashboard/SuggestionsChecks.java
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 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.dashboard;
|
||||||
|
|
||||||
|
import android.app.AutomaticZenRule;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import com.android.settings.Settings.ZenModeAutomationSuggestionActivity;
|
||||||
|
import com.android.settingslib.drawer.Tile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Home of all stupidly dynamic Settings Suggestions checks.
|
||||||
|
*/
|
||||||
|
public class SuggestionsChecks {
|
||||||
|
|
||||||
|
private final Context mContext;
|
||||||
|
|
||||||
|
public SuggestionsChecks(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSuggestionComplete(Tile suggestion) {
|
||||||
|
if (suggestion.intent.getComponent().getClassName().equals(
|
||||||
|
ZenModeAutomationSuggestionActivity.class.getName())) {
|
||||||
|
return hasEnabledZenAutoRules();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasEnabledZenAutoRules() {
|
||||||
|
List<AutomaticZenRule> zenRules = NotificationManager.from(mContext).getAutomaticZenRules();
|
||||||
|
final int N = zenRules.size();
|
||||||
|
for (int i = 0; i < N; i++) {
|
||||||
|
if (zenRules.get(i).isEnabled()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user