Merge changes I81380323,I0cce76f3
* changes: Add wallpaper suggestion if one isn't set. Add DND Suggestion after 30 days
This commit is contained in:
@@ -810,6 +810,37 @@
|
|||||||
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$WallpaperSuggestionActivity"
|
||||||
|
android:label="@string/wallpaper_settings_title"
|
||||||
|
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.WallpaperTypeSettings" />
|
||||||
|
<meta-data android:name="com.android.settings.title"
|
||||||
|
android:resource="@string/wallpaper_suggestion_title" />
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity android:name="Settings$ZenModeScheduleRuleSettingsActivity"
|
<activity android:name="Settings$ZenModeScheduleRuleSettingsActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:taskAffinity="">
|
android:taskAffinity="">
|
||||||
|
@@ -2055,6 +2055,8 @@
|
|||||||
<string name="screen_timeout_summary">After <xliff:g id="timeout_description">%1$s</xliff:g> of inactivity</string>
|
<string name="screen_timeout_summary">After <xliff:g id="timeout_description">%1$s</xliff:g> of inactivity</string>
|
||||||
<!-- Wallpaper settings title [CHAR LIMIT=30] -->
|
<!-- Wallpaper settings title [CHAR LIMIT=30] -->
|
||||||
<string name="wallpaper_settings_title">Wallpaper</string>
|
<string name="wallpaper_settings_title">Wallpaper</string>
|
||||||
|
<!-- Wallpaper suggestion title [CHAR LIMIT=30] -->
|
||||||
|
<string name="wallpaper_suggestion_title">Set up wallpaper</string>
|
||||||
<!-- Wallpaper settings fragment title [CHAR LIMIT=30] -->
|
<!-- Wallpaper settings fragment title [CHAR LIMIT=30] -->
|
||||||
<string name="wallpaper_settings_fragment_title">Choose wallpaper from</string>
|
<string name="wallpaper_settings_fragment_title">Choose wallpaper from</string>
|
||||||
<!-- Display settings screen, trigger for screen saver options -->
|
<!-- Display settings screen, trigger for screen saver options -->
|
||||||
@@ -5767,6 +5769,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 */ }
|
||||||
@@ -124,6 +125,8 @@ public class Settings extends SettingsActivity {
|
|||||||
public static class AppWriteSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class AppWriteSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class ManageDefaultAppsActivity extends SettingsActivity { /* empty */ }
|
public static class ManageDefaultAppsActivity extends SettingsActivity { /* empty */ }
|
||||||
|
|
||||||
|
public static class WallpaperSuggestionActivity extends SettingsActivity { /* empty */ }
|
||||||
|
|
||||||
// Categories.
|
// Categories.
|
||||||
public static class WirelessSettings extends SettingsActivity { /* empty */ }
|
public static class WirelessSettings extends SettingsActivity { /* empty */ }
|
||||||
public static class DeviceSettings extends SettingsActivity { /* empty */ }
|
public static class DeviceSettings extends SettingsActivity { /* empty */ }
|
||||||
|
@@ -316,6 +316,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
DrawOverlayDetails.class.getName(),
|
DrawOverlayDetails.class.getName(),
|
||||||
WriteSettingsDetails.class.getName(),
|
WriteSettingsDetails.class.getName(),
|
||||||
ManageDefaultApps.class.getName(),
|
ManageDefaultApps.class.getName(),
|
||||||
|
WallpaperTypeSettings.class.getName(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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);
|
||||||
|
81
src/com/android/settings/dashboard/SuggestionsChecks.java
Normal file
81
src/com/android/settings/dashboard/SuggestionsChecks.java
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* 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.IWallpaperManager;
|
||||||
|
import android.app.IWallpaperManager.Stub;
|
||||||
|
import android.app.IWallpaperManagerCallback;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.os.RemoteException;
|
||||||
|
import android.os.ServiceManager;
|
||||||
|
import com.android.settings.Settings.WallpaperSuggestionActivity;
|
||||||
|
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) {
|
||||||
|
String className = suggestion.intent.getComponent().getClassName();
|
||||||
|
if (className.equals(ZenModeAutomationSuggestionActivity.class.getName())) {
|
||||||
|
return hasEnabledZenAutoRules();
|
||||||
|
} else if (className.equals(WallpaperSuggestionActivity.class.getName())) {
|
||||||
|
return hasWallpaperSet();
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasWallpaperSet() {
|
||||||
|
IBinder b = ServiceManager.getService(Context.WALLPAPER_SERVICE);
|
||||||
|
IWallpaperManager service = Stub.asInterface(b);
|
||||||
|
try {
|
||||||
|
return service.getWallpaper(mCallback, new Bundle()) != null;
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final IWallpaperManagerCallback mCallback = new IWallpaperManagerCallback.Stub() {
|
||||||
|
@Override
|
||||||
|
public void onWallpaperChanged() throws RemoteException {
|
||||||
|
// Don't care.
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Reference in New Issue
Block a user