Merge changes I81380323,I0cce76f3
* changes: Add wallpaper suggestion if one isn't set. Add DND Suggestion after 30 days
This commit is contained in:
@@ -103,6 +103,7 @@ public class Settings extends SettingsActivity {
|
||||
public static class ZenModeSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class ZenModePrioritySettingsActivity 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 ZenModeEventRuleSettingsActivity 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 ManageDefaultAppsActivity extends SettingsActivity { /* empty */ }
|
||||
|
||||
public static class WallpaperSuggestionActivity extends SettingsActivity { /* empty */ }
|
||||
|
||||
// Categories.
|
||||
public static class WirelessSettings extends SettingsActivity { /* empty */ }
|
||||
public static class DeviceSettings extends SettingsActivity { /* empty */ }
|
||||
|
@@ -316,6 +316,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
DrawOverlayDetails.class.getName(),
|
||||
WriteSettingsDetails.class.getName(),
|
||||
ManageDefaultApps.class.getName(),
|
||||
WallpaperTypeSettings.class.getName(),
|
||||
};
|
||||
|
||||
|
||||
|
@@ -43,6 +43,10 @@ import java.util.List;
|
||||
public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.DashboardItemHolder>
|
||||
implements View.OnClickListener {
|
||||
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_COLLAPSED = 1;
|
||||
@@ -55,6 +59,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
private final List<Integer> mIds = new ArrayList<>();
|
||||
|
||||
private final Context mContext;
|
||||
private final SuggestionsChecks mSuggestionsChecks;
|
||||
|
||||
private List<DashboardCategory> mCategories;
|
||||
private List<Condition> mConditions;
|
||||
@@ -71,13 +76,20 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
|
||||
public DashboardAdapter(Context context) {
|
||||
mContext = context;
|
||||
mSuggestionsChecks = new SuggestionsChecks(mContext);
|
||||
|
||||
setHasStableIds(true);
|
||||
}
|
||||
|
||||
public void setSuggestions(SuggestionParser suggestionParser) {
|
||||
mSuggestions = suggestionParser.getSuggestions();
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -127,35 +139,42 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
for (int i = 0; mConditions != null && i < mConditions.size(); i++) {
|
||||
boolean shouldShow = mConditions.get(i).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;
|
||||
countItem(null, R.layout.dashboard_spacer, hasConditions && hasSuggestions);
|
||||
countItem(null, R.layout.suggestion_header, hasSuggestions);
|
||||
countItem(null, R.layout.dashboard_spacer, hasConditions && hasSuggestions, NS_SPACER);
|
||||
countItem(null, R.layout.suggestion_header, hasSuggestions, NS_SPACER);
|
||||
resetCount();
|
||||
if (mSuggestions != null) {
|
||||
int maxSuggestions = mSuggestionMode == SUGGESTION_MODE_DEFAULT
|
||||
? Math.min(DEFAULT_SUGGESTION_COUNT, mSuggestions.size())
|
||||
: mSuggestionMode == SUGGESTION_MODE_EXPANDED ? mSuggestions.size()
|
||||
: 0;
|
||||
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++) {
|
||||
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++) {
|
||||
Tile tile = category.tiles.get(j);
|
||||
countItem(tile, R.layout.dashboard_tile, mIsShowingAll
|
||||
|| 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();
|
||||
}
|
||||
|
||||
private void resetCount() {
|
||||
mId = 0;
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
mItems.clear();
|
||||
mTypes.clear();
|
||||
@@ -163,12 +182,12 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
mId = 0;
|
||||
}
|
||||
|
||||
private void countItem(Object object, int type, boolean add) {
|
||||
private void countItem(Object object, int type, boolean add, int nameSpace) {
|
||||
if (add) {
|
||||
mItems.add(object);
|
||||
mTypes.add(type);
|
||||
// TODO: Counting namespaces for handling of suggestions/conds appearing/disappearing.
|
||||
mIds.add(mId);
|
||||
mIds.add(mId + nameSpace);
|
||||
}
|
||||
mId++;
|
||||
}
|
||||
@@ -238,12 +257,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
if (mSuggestionParser.dismissSuggestion(suggestion)) {
|
||||
mContext.getPackageManager().setComponentEnabledSetting(
|
||||
suggestion.intent.getComponent(),
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
PackageManager.DONT_KILL_APP);
|
||||
}
|
||||
disableSuggestion(suggestion);
|
||||
mSuggestions.remove(suggestion);
|
||||
recountItems();
|
||||
return true;
|
||||
@@ -252,6 +266,15 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
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) {
|
||||
holder.icon.setImageResource(hasMoreSuggestions() ? R.drawable.ic_expand_more
|
||||
: 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