Add suggestions to settings

Use an XML to define the categories that Settings will look for,
and surface enabled activities under those categories as suggestions.

When clicked on the activity will be started for result.  If the result
is not cancelled, then the operation is assumed successful and the
suggestion is disabled.  Users can also use an overflow -> remove
flow to get rid of unwanted suggestions.

Change-Id: I767abf8efe103af0509bc6b6b55888ae82643512
This commit is contained in:
Jason Monk
2016-01-07 16:25:34 -05:00
parent c24d360328
commit d4f03ec86f
14 changed files with 340 additions and 56 deletions

View File

@@ -50,7 +50,6 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.SearchView;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.util.ArrayUtils;
import com.android.settings.Settings.WifiSettingsActivity;
import com.android.settings.accessibility.AccessibilitySettings;
@@ -111,7 +110,7 @@ import com.android.settings.wifi.SavedAccessPointsWifiSettings;
import com.android.settings.wifi.WifiSettings;
import com.android.settings.wifi.p2p.WifiP2pSettings;
import com.android.settingslib.drawer.DashboardCategory;
import com.android.settingslib.drawer.DashboardTile;
import com.android.settingslib.drawer.Tile;
import com.android.settingslib.drawer.SettingsDrawerActivity;
import java.util.ArrayList;
@@ -199,6 +198,8 @@ public class SettingsActivity extends SettingsDrawerActivity
private static final String EMPTY_QUERY = "";
private static final int REQUEST_SUGGESTION = 42;
private String mFragmentClass;
private CharSequence mInitialTitle;
@@ -365,6 +366,7 @@ public class SettingsActivity extends SettingsDrawerActivity
private int mHomeActivitiesCount = 1;
private Intent mResultIntentData;
private ComponentName mCurrentSuggestion;
public SwitchBar getSwitchBar() {
return mSwitchBar;
@@ -1031,7 +1033,7 @@ public class SettingsActivity extends SettingsDrawerActivity
// When on restricted users, disable all extra categories (but only the settings ones).
List<DashboardCategory> categories = getDashboardCategories();
for (DashboardCategory category : categories) {
for (DashboardTile tile : category.tiles) {
for (Tile tile : category.tiles) {
ComponentName component = tile.intent.getComponent();
if (packageName.equals(component)&& !ArrayUtils.contains(
SETTINGS_FOR_RESTRICTED, component.getClassName())) {
@@ -1146,7 +1148,7 @@ public class SettingsActivity extends SettingsDrawerActivity
}
@Override
protected void onTileClicked(DashboardTile tile) {
protected void onTileClicked(Tile tile) {
if (mIsShowingDashboard) {
// If on dashboard, don't finish so the back comes back to here.
openTile(tile);
@@ -1200,4 +1202,20 @@ public class SettingsActivity extends SettingsDrawerActivity
public void setResultIntentData(Intent resultIntentData) {
mResultIntentData = resultIntentData;
}
public void startSuggestion(Intent intent) {
mCurrentSuggestion = intent.getComponent();
startActivityForResult(intent, REQUEST_SUGGESTION);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
&& resultCode != RESULT_CANCELED) {
getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
super.onActivityResult(requestCode, resultCode, data);
}
}