Allow system apps to add to settings dashboard

Allow system apps to add a tile to the top level of settings that
links to an activity through adding a filter for a specific action.
Determine the info for the tile based off manifest info for the
activity. Also allow the same for managed profiles, but show a dialog
in between to select which profile.

The category in which the item is to be placed must be in meta-data.
The icon and title can be specified through meta-data as well or
if unspecified the activity's label and icon will be used.

Also added an optional <external-tiles> tag to the dashboard
category xml, this allows Settings to put external tiles
in the middle of some categories (Personal does this).

Bug: 19443117
Change-Id: Idc9938d1549d181103a3030a8784b527215a8399
This commit is contained in:
Jason Monk
2015-02-13 15:23:19 -05:00
parent 5528d8952b
commit 2ebc8a0169
14 changed files with 328 additions and 37 deletions

View File

@@ -18,6 +18,8 @@
android:id="@android:id/widget_frame" android:id="@android:id/widget_frame"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/user_spinner_item_height" android:layout_height="@dimen/user_spinner_item_height"
android:paddingStart="@dimen/user_spinner_padding_sides"
android:paddingEnd="@dimen/user_spinner_padding_sides"
android:orientation="horizontal" > android:orientation="horizontal" >
<ImageView <ImageView
@@ -42,4 +44,4 @@
android:paddingEnd="@dimen/user_spinner_padding" android:paddingEnd="@dimen/user_spinner_padding"
style="@style/TextAppearance.Medium" /> style="@style/TextAppearance.Medium" />
</LinearLayout> </LinearLayout>

View File

@@ -213,6 +213,7 @@
<!-- User spinner --> <!-- User spinner -->
<dimen name="user_spinner_height">72dp</dimen> <dimen name="user_spinner_height">72dp</dimen>
<dimen name="user_spinner_padding">4dp</dimen> <dimen name="user_spinner_padding">4dp</dimen>
<dimen name="user_spinner_padding_sides">20dp</dimen>
<dimen name="user_spinner_item_height">56dp</dimen> <dimen name="user_spinner_item_height">56dp</dimen>
<!-- CheckBoxPreference --> <!-- CheckBoxPreference -->

View File

@@ -33,4 +33,8 @@
<item>@string/input_method_selector_always_show_value</item> <item>@string/input_method_selector_always_show_value</item>
<item>@string/input_method_selector_always_hide_value</item> <item>@string/input_method_selector_always_hide_value</item>
</string-array> </string-array>
<string name="category_key_wireless">com.android.settings.category.wireless</string>
<string name="category_key_device">com.android.settings.category.device</string>
<string name="category_key_personal">com.android.settings.category.personal</string>
<string name="category_key_system">com.android.settings.category.system</string>
</resources> </resources>

View File

@@ -6132,4 +6132,7 @@
<!-- Warning toast shown when data usage screen can't find specified app --> <!-- Warning toast shown when data usage screen can't find specified app -->
<string name="unknown_app">Unknown app</string> <string name="unknown_app">Unknown app</string>
<!-- Title for profile selection dialog [CHAR LIMIT=30] -->
<string name="choose_profile">Choose Profile</string>
</resources> </resources>

View File

@@ -20,6 +20,7 @@
<!-- WIRELESS and NETWORKS --> <!-- WIRELESS and NETWORKS -->
<dashboard-category <dashboard-category
android:id="@+id/wireless_section" android:id="@+id/wireless_section"
android:key="@string/category_key_wireless"
android:title="@string/header_category_wireless_networks" > android:title="@string/header_category_wireless_networks" >
<!-- Wifi --> <!-- Wifi -->
@@ -74,6 +75,7 @@
<!-- DEVICE --> <!-- DEVICE -->
<dashboard-category <dashboard-category
android:id="@+id/device_section" android:id="@+id/device_section"
android:key="@string/category_key_device"
android:title="@string/header_category_device" > android:title="@string/header_category_device" >
<!-- Home --> <!-- Home -->
@@ -152,6 +154,7 @@
<!-- PERSONAL --> <!-- PERSONAL -->
<dashboard-category <dashboard-category
android:id="@+id/personal_section" android:id="@+id/personal_section"
android:key="@string/category_key_personal"
android:title="@string/header_category_personal" > android:title="@string/header_category_personal" >
<!-- Location --> <!-- Location -->
@@ -178,6 +181,9 @@
android:icon="@drawable/ic_settings_accounts" android:icon="@drawable/ic_settings_accounts"
/> />
<!-- Marker for where to place external tiles in this category -->
<external-tiles />
<!-- Language --> <!-- Language -->
<dashboard-tile <dashboard-tile
android:id="@+id/language_settings" android:id="@+id/language_settings"
@@ -199,6 +205,7 @@
<!-- SYSTEM --> <!-- SYSTEM -->
<dashboard-category <dashboard-category
android:id="@+id/system_section" android:id="@+id/system_section"
android:key="@string/category_key_system"
android:title="@string/header_category_system" > android:title="@string/header_category_system" >
<!-- Date & Time --> <!-- Date & Time -->

View File

@@ -0,0 +1,68 @@
/*
* 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;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import com.android.settings.dashboard.DashboardTile;
public class ProfileSelectDialog extends DialogFragment implements OnClickListener {
private static final String ARG_SELECTED_TILE = "selectedTile";
private DashboardTile mSelectedTile;
public static void show(FragmentManager manager, DashboardTile tile) {
ProfileSelectDialog dialog = new ProfileSelectDialog();
Bundle args = new Bundle();
args.putParcelable(ARG_SELECTED_TILE, tile);
dialog.setArguments(args);
dialog.show(manager, "select_profile");
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSelectedTile = getArguments().getParcelable(ARG_SELECTED_TILE);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Context context = getActivity();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
UserAdapter adapter = Utils.createUserAdapter(UserManager.get(context), context,
mSelectedTile.userHandle);
builder.setTitle(R.string.choose_profile)
.setAdapter(adapter, this);
return builder.create();
}
@Override
public void onClick(DialogInterface dialog, int which) {
UserHandle user = mSelectedTile.userHandle.get(which);
getActivity().startActivityAsUser(mSelectedTile.intent, user);
}
}

View File

@@ -16,6 +16,8 @@
package com.android.settings; package com.android.settings;
import static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED;
import android.app.ActionBar; import android.app.ActionBar;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
@@ -49,8 +51,10 @@ import android.preference.PreferenceManager;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.text.TextUtils; import android.text.TextUtils;
import android.transition.TransitionManager; import android.transition.TransitionManager;
import android.util.ArrayMap;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.util.Pair;
import android.util.TypedValue; import android.util.TypedValue;
import android.util.Xml; import android.util.Xml;
import android.view.Menu; import android.view.Menu;
@@ -81,9 +85,6 @@ import com.android.settings.deviceinfo.Memory;
import com.android.settings.deviceinfo.UsbSettings; import com.android.settings.deviceinfo.UsbSettings;
import com.android.settings.fuelgauge.BatterySaverSettings; import com.android.settings.fuelgauge.BatterySaverSettings;
import com.android.settings.fuelgauge.PowerUsageSummary; import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.notification.OtherSoundSettings;
import com.android.settings.search.DynamicIndexableContentMonitor;
import com.android.settings.search.Index;
import com.android.settings.inputmethod.InputMethodAndLanguageSettings; import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
import com.android.settings.inputmethod.KeyboardLayoutPickerFragment; import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
import com.android.settings.inputmethod.SpellCheckersSettings; import com.android.settings.inputmethod.SpellCheckersSettings;
@@ -96,9 +97,12 @@ import com.android.settings.notification.ConditionProviderSettings;
import com.android.settings.notification.NotificationAccessSettings; import com.android.settings.notification.NotificationAccessSettings;
import com.android.settings.notification.NotificationSettings; import com.android.settings.notification.NotificationSettings;
import com.android.settings.notification.NotificationStation; import com.android.settings.notification.NotificationStation;
import com.android.settings.notification.OtherSoundSettings;
import com.android.settings.notification.ZenModeSettings; import com.android.settings.notification.ZenModeSettings;
import com.android.settings.print.PrintJobSettingsFragment; import com.android.settings.print.PrintJobSettingsFragment;
import com.android.settings.print.PrintSettingsFragment; import com.android.settings.print.PrintSettingsFragment;
import com.android.settings.search.DynamicIndexableContentMonitor;
import com.android.settings.search.Index;
import com.android.settings.sim.SimSettings; import com.android.settings.sim.SimSettings;
import com.android.settings.tts.TextToSpeechSettings; import com.android.settings.tts.TextToSpeechSettings;
import com.android.settings.users.UserSettings; import com.android.settings.users.UserSettings;
@@ -110,16 +114,16 @@ import com.android.settings.wifi.AdvancedWifiSettings;
import com.android.settings.wifi.SavedAccessPointsWifiSettings; import com.android.settings.wifi.SavedAccessPointsWifiSettings;
import com.android.settings.wifi.WifiSettings; import com.android.settings.wifi.WifiSettings;
import com.android.settings.wifi.p2p.WifiP2pSettings; import com.android.settings.wifi.p2p.WifiP2pSettings;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED;
public class SettingsActivity extends Activity public class SettingsActivity extends Activity
implements PreferenceManager.OnPreferenceTreeClickListener, implements PreferenceManager.OnPreferenceTreeClickListener,
PreferenceFragment.OnPreferenceStartFragmentCallback, PreferenceFragment.OnPreferenceStartFragmentCallback,
@@ -201,6 +205,35 @@ public class SettingsActivity extends Activity
private static final String EMPTY_QUERY = ""; private static final String EMPTY_QUERY = "";
/**
* Settings will search for system activities of this action and add them as a top level
* settings tile using the following parameters.
*
* <p>A category must be specified in the meta-data for the activity named
* {@link #EXTRA_CATEGORY_KEY}
*
* <p>The title may be defined by meta-data named {@link Utils#META_DATA_PREFERENCE_TITLE}
* otherwise the label for the activity will be used.
*
* <p>The icon may be defined by meta-data named {@link Utils#META_DATA_PREFERENCE_ICON}
* otherwise the icon for the activity will be used.
*
* <p>A summary my be defined by meta-data named {@link Utils#META_DATA_PREFERENCE_SUMMARY}
*/
private static final String EXTRA_SETTINGS_ACTION =
"com.android.settings.action.EXTRA_SETTINGS";
/**
* The key used to get the category from metadata of activities of action
* {@link #EXTRA_SETTINGS_ACTION}
* The value must be one of:
* <li>com.android.settings.category.wireless</li>
* <li>com.android.settings.category.device</li>
* <li>com.android.settings.category.personal</li>
* <li>com.android.settings.category.system</li>
*/
private static final String EXTRA_CATEGORY_KEY = "com.android.settings.category";
private static boolean sShowNoHomeNotice = false; private static boolean sShowNoHomeNotice = false;
private String mFragmentClass; private String mFragmentClass;
@@ -1035,6 +1068,17 @@ public class SettingsActivity extends Activity
} }
} }
sa.recycle(); sa.recycle();
sa = obtainStyledAttributes(attrs, com.android.internal.R.styleable.Preference);
tv = sa.peekValue(
com.android.internal.R.styleable.Preference_key);
if (tv != null && tv.type == TypedValue.TYPE_STRING) {
if (tv.resourceId != 0) {
category.key = getString(tv.resourceId);
} else {
category.key = tv.string.toString();
}
}
sa.recycle();
final int innerDepth = parser.getDepth(); final int innerDepth = parser.getDepth();
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
@@ -1110,6 +1154,8 @@ public class SettingsActivity extends Activity
category.addTile(tile); category.addTile(tile);
} }
} else if (innerNodeName.equals("external-tiles")) {
category.externalIndex = category.getTilesCount();
} else { } else {
XmlUtils.skipCurrentTag(parser); XmlUtils.skipCurrentTag(parser);
} }
@@ -1231,6 +1277,73 @@ public class SettingsActivity extends Activity
n--; n--;
} }
} }
addExternalTiles(target);
}
private void addExternalTiles(List<DashboardCategory> target) {
Map<Pair<String, String>, DashboardTile> addedCache =
new ArrayMap<Pair<String, String>, DashboardTile>();
UserManager userManager = UserManager.get(this);
for (UserHandle user : userManager.getUserProfiles()) {
addExternalTiles(target, user, addedCache);
}
}
private void addExternalTiles(List<DashboardCategory> target, UserHandle user,
Map<Pair<String, String>, DashboardTile> addedCache) {
PackageManager pm = getPackageManager();
Intent intent = new Intent(EXTRA_SETTINGS_ACTION);
List<ResolveInfo> results = pm.queryIntentActivitiesAsUser(intent,
PackageManager.GET_META_DATA, user.getIdentifier());
for (ResolveInfo resolved : results) {
if (!resolved.system) {
// Do not allow any app to add to settings, only system ones.
continue;
}
ActivityInfo activityInfo = resolved.activityInfo;
Bundle metaData = activityInfo.metaData;
if ((metaData == null) || !metaData.containsKey(EXTRA_CATEGORY_KEY)) {
Log.w(LOG_TAG, "Found " + resolved.activityInfo.name + " for action "
+ EXTRA_SETTINGS_ACTION + " missing metadata " +
(metaData == null ? "" : EXTRA_CATEGORY_KEY));
continue;
}
String categoryKey = metaData.getString(EXTRA_CATEGORY_KEY);
DashboardCategory category = getCategory(target, categoryKey);
if (category == null) {
Log.w(LOG_TAG, "Activity " + resolved.activityInfo.name + " has unknown "
+ "category key " + categoryKey);
continue;
}
Pair<String, String> key = new Pair<String, String>(activityInfo.packageName,
activityInfo.name);
DashboardTile tile = addedCache.get(key);
if (tile == null) {
tile = new DashboardTile();
tile.intent = new Intent().setClassName(
activityInfo.packageName, activityInfo.name);
Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, tile);
if (category.externalIndex == -1) {
// If no location for external tiles has been specified for this category,
// then just put them at the end.
category.addTile(tile);
} else {
category.addTile(category.externalIndex, tile);
}
addedCache.put(key, tile);
}
tile.userHandle.add(user);
}
}
private DashboardCategory getCategory(List<DashboardCategory> target, String categoryKey) {
for (DashboardCategory category : target) {
if (categoryKey.equals(category.key)) {
return category;
}
}
return null;
} }
private boolean updateHomeSettingTiles(DashboardTile tile) { private boolean updateHomeSettingTiles(DashboardTile tile) {

View File

@@ -16,6 +16,7 @@
package com.android.settings; package com.android.settings;
import android.app.ActivityManager;
import android.content.Context; import android.content.Context;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.database.DataSetObserver; import android.database.DataSetObserver;
@@ -27,6 +28,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.SpinnerAdapter; import android.widget.SpinnerAdapter;
import android.widget.TextView; import android.widget.TextView;
@@ -38,7 +40,7 @@ import java.util.ArrayList;
/** /**
* Adapter for a spinner that shows a list of users. * Adapter for a spinner that shows a list of users.
*/ */
public class UserSpinnerAdapter implements SpinnerAdapter { public class UserAdapter implements SpinnerAdapter, ListAdapter {
// TODO: Update UI. See: http://b/16518801 // TODO: Update UI. See: http://b/16518801
/** Holder for user details */ /** Holder for user details */
public static class UserDetails { public static class UserDetails {
@@ -73,7 +75,7 @@ public class UserSpinnerAdapter implements SpinnerAdapter {
private ArrayList<UserDetails> data; private ArrayList<UserDetails> data;
private final LayoutInflater mInflater; private final LayoutInflater mInflater;
public UserSpinnerAdapter(Context context, ArrayList<UserDetails> users) { public UserAdapter(Context context, ArrayList<UserDetails> users) {
if (users == null) { if (users == null) {
throw new IllegalArgumentException("A list of user details must be provided"); throw new IllegalArgumentException("A list of user details must be provided");
} }
@@ -94,10 +96,20 @@ public class UserSpinnerAdapter implements SpinnerAdapter {
UserDetails user = data.get(position); UserDetails user = data.get(position);
((ImageView) row.findViewById(android.R.id.icon)).setImageDrawable(user.mIcon); ((ImageView) row.findViewById(android.R.id.icon)).setImageDrawable(user.mIcon);
((TextView) row.findViewById(android.R.id.title)).setText(user.mName); ((TextView) row.findViewById(android.R.id.title)).setText(getTitle(user));
return row; return row;
} }
private int getTitle(UserDetails user) {
int userHandle = user.mUserHandle.getIdentifier();
if (userHandle == UserHandle.USER_CURRENT
|| userHandle == ActivityManager.getCurrentUser()) {
return R.string.category_personal;
} else {
return R.string.category_work;
}
}
private View createUser(ViewGroup parent) { private View createUser(ViewGroup parent) {
return mInflater.inflate(R.layout.user_preference, parent, false); return mInflater.inflate(R.layout.user_preference, parent, false);
} }
@@ -151,4 +163,14 @@ public class UserSpinnerAdapter implements SpinnerAdapter {
public boolean isEmpty() { public boolean isEmpty() {
return data.isEmpty(); return data.isEmpty();
} }
@Override
public boolean areAllItemsEnabled() {
return true;
}
@Override
public boolean isEnabled(int position) {
return true;
}
} }

View File

@@ -75,7 +75,7 @@ import android.widget.ListView;
import android.widget.TabWidget; import android.widget.TabWidget;
import com.android.internal.util.UserIcons; import com.android.internal.util.UserIcons;
import com.android.settings.UserSpinnerAdapter.UserDetails; import com.android.settings.UserAdapter.UserDetails;
import com.android.settings.dashboard.DashboardTile; import com.android.settings.dashboard.DashboardTile;
import com.android.settings.drawable.CircleFramedDrawable; import com.android.settings.drawable.CircleFramedDrawable;
@@ -114,19 +114,19 @@ public final class Utils {
* Name of the meta-data item that should be set in the AndroidManifest.xml * Name of the meta-data item that should be set in the AndroidManifest.xml
* to specify the icon that should be displayed for the preference. * to specify the icon that should be displayed for the preference.
*/ */
private static final String META_DATA_PREFERENCE_ICON = "com.android.settings.icon"; public static final String META_DATA_PREFERENCE_ICON = "com.android.settings.icon";
/** /**
* Name of the meta-data item that should be set in the AndroidManifest.xml * Name of the meta-data item that should be set in the AndroidManifest.xml
* to specify the title that should be displayed for the preference. * to specify the title that should be displayed for the preference.
*/ */
private static final String META_DATA_PREFERENCE_TITLE = "com.android.settings.title"; public static final String META_DATA_PREFERENCE_TITLE = "com.android.settings.title";
/** /**
* Name of the meta-data item that should be set in the AndroidManifest.xml * Name of the meta-data item that should be set in the AndroidManifest.xml
* to specify the summary text that should be displayed for the preference. * to specify the summary text that should be displayed for the preference.
*/ */
private static final String META_DATA_PREFERENCE_SUMMARY = "com.android.settings.summary"; public static final String META_DATA_PREFERENCE_SUMMARY = "com.android.settings.summary";
private static final String SETTINGS_PACKAGE_NAME = "com.android.settings"; private static final String SETTINGS_PACKAGE_NAME = "com.android.settings";
@@ -198,14 +198,17 @@ public final class Utils {
if (intent != null) { if (intent != null) {
// Find the activity that is in the system image // Find the activity that is in the system image
PackageManager pm = context.getPackageManager(); PackageManager pm = context.getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.GET_META_DATA); List<ResolveInfo> list = tile.userHandle.size() != 0
? pm.queryIntentActivitiesAsUser(intent, PackageManager.GET_META_DATA,
tile.userHandle.get(0).getIdentifier())
: pm.queryIntentActivities(intent, PackageManager.GET_META_DATA);
int listSize = list.size(); int listSize = list.size();
for (int i = 0; i < listSize; i++) { for (int i = 0; i < listSize; i++) {
ResolveInfo resolveInfo = list.get(i); ResolveInfo resolveInfo = list.get(i);
if ((resolveInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) if ((resolveInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM)
!= 0) { != 0) {
Drawable icon = null; int icon = 0;
String title = null; CharSequence title = null;
String summary = null; String summary = null;
// Get the activity's meta-data // Get the activity's meta-data
@@ -215,14 +218,18 @@ public final class Utils {
Bundle metaData = resolveInfo.activityInfo.metaData; Bundle metaData = resolveInfo.activityInfo.metaData;
if (res != null && metaData != null) { if (res != null && metaData != null) {
icon = res.getDrawable( if (metaData.containsKey(META_DATA_PREFERENCE_ICON)) {
metaData.getInt(META_DATA_PREFERENCE_ICON), null); icon = metaData.getInt(META_DATA_PREFERENCE_ICON);
title = res.getString(metaData.getInt(META_DATA_PREFERENCE_TITLE)); }
summary = res.getString(metaData.getInt(META_DATA_PREFERENCE_SUMMARY)); if (metaData.containsKey(META_DATA_PREFERENCE_TITLE)) {
title = res.getString(metaData.getInt(META_DATA_PREFERENCE_TITLE));
}
if (metaData.containsKey(META_DATA_PREFERENCE_SUMMARY)) {
summary = res.getString(
metaData.getInt(META_DATA_PREFERENCE_SUMMARY));
}
} }
} catch (NameNotFoundException e) { } catch (NameNotFoundException | NotFoundException e) {
// Ignore
} catch (NotFoundException e) {
// Ignore // Ignore
} }
@@ -231,10 +238,13 @@ public final class Utils {
if (TextUtils.isEmpty(title)) { if (TextUtils.isEmpty(title)) {
title = resolveInfo.loadLabel(pm).toString(); title = resolveInfo.loadLabel(pm).toString();
} }
if (icon == 0) {
icon = resolveInfo.activityInfo.icon;
}
// Set icon, title and summary for the preference // Set icon, title and summary for the preference
// TODO: tile.iconRes = icon;
//tile.icon = icon; tile.iconPkg = resolveInfo.activityInfo.packageName;
tile.title = title; tile.title = title;
tile.summary = summary; tile.summary = summary;
// Replace the intent with this specific activity // Replace the intent with this specific activity
@@ -728,14 +738,14 @@ public final class Utils {
} }
/** /**
* Creates a {@link UserSpinnerAdapter} if there is more than one profile on the device. * Creates a {@link UserAdapter} if there is more than one profile on the device.
* *
* <p> The adapter can be used to populate a spinner that switches between the Settings * <p> The adapter can be used to populate a spinner that switches between the Settings
* app on the different profiles. * app on the different profiles.
* *
* @return a {@link UserSpinnerAdapter} or null if there is only one profile. * @return a {@link UserAdapter} or null if there is only one profile.
*/ */
public static UserSpinnerAdapter createUserSpinnerAdapter(UserManager userManager, public static UserAdapter createUserSpinnerAdapter(UserManager userManager,
Context context) { Context context) {
List<UserHandle> userProfiles = userManager.getUserProfiles(); List<UserHandle> userProfiles = userManager.getUserProfiles();
if (userProfiles.size() < 2) { if (userProfiles.size() < 2) {
@@ -747,12 +757,17 @@ public final class Utils {
userProfiles.remove(myUserHandle); userProfiles.remove(myUserHandle);
userProfiles.add(0, myUserHandle); userProfiles.add(0, myUserHandle);
return createUserAdapter(userManager, context, userProfiles);
}
public static UserAdapter createUserAdapter(UserManager userManager,
Context context, List<UserHandle> userProfiles) {
ArrayList<UserDetails> userDetails = new ArrayList<UserDetails>(userProfiles.size()); ArrayList<UserDetails> userDetails = new ArrayList<UserDetails>(userProfiles.size());
final int count = userProfiles.size(); final int count = userProfiles.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
userDetails.add(new UserDetails(userProfiles.get(i), userManager, context)); userDetails.add(new UserDetails(userProfiles.get(i), userManager, context));
} }
return new UserSpinnerAdapter(context, userDetails); return new UserAdapter(context, userDetails);
} }
/** /**

View File

@@ -51,6 +51,16 @@ public class DashboardCategory implements Parcelable {
*/ */
public CharSequence title; public CharSequence title;
/**
* Key used for placing external tiles.
*/
public String key;
/**
* Optional index of where to place tiles specified by system apps.
*/
public int externalIndex = -1;
/** /**
* List of the category's children * List of the category's children
*/ */
@@ -105,7 +115,9 @@ public class DashboardCategory implements Parcelable {
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(titleRes); dest.writeInt(titleRes);
dest.writeInt(externalIndex);
TextUtils.writeToParcel(title, dest, flags); TextUtils.writeToParcel(title, dest, flags);
dest.writeString(key);
final int count = tiles.size(); final int count = tiles.size();
dest.writeInt(count); dest.writeInt(count);
@@ -118,7 +130,9 @@ public class DashboardCategory implements Parcelable {
public void readFromParcel(Parcel in) { public void readFromParcel(Parcel in) {
titleRes = in.readInt(); titleRes = in.readInt();
externalIndex = in.readInt();
title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
key = in.readString();
final int count = in.readInt(); final int count = in.readInt();

View File

@@ -21,6 +21,7 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@@ -32,6 +33,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
@@ -148,7 +150,15 @@ public class DashboardSummary extends Fragment {
private void updateTileView(Context context, Resources res, DashboardTile tile, private void updateTileView(Context context, Resources res, DashboardTile tile,
ImageView tileIcon, TextView tileTextView, TextView statusTextView) { ImageView tileIcon, TextView tileTextView, TextView statusTextView) {
if (tile.iconRes > 0) { if (!TextUtils.isEmpty(tile.iconPkg)) {
try {
tileIcon.setImageDrawable(context.getPackageManager()
.getResourcesForApplication(tile.iconPkg).getDrawable(tile.iconRes, null));
} catch (NameNotFoundException | Resources.NotFoundException e) {
tileIcon.setImageDrawable(null);
tileIcon.setBackground(null);
}
} else if (tile.iconRes > 0) {
tileIcon.setImageResource(tile.iconRes); tileIcon.setImageResource(tile.iconRes);
} else { } else {
tileIcon.setImageDrawable(null); tileIcon.setImageDrawable(null);

View File

@@ -21,8 +21,11 @@ import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.os.UserHandle;
import android.text.TextUtils; import android.text.TextUtils;
import java.util.ArrayList;
/** /**
* Description of a single dashboard tile that the user can select. * Description of a single dashboard tile that the user can select.
*/ */
@@ -72,6 +75,11 @@ public class DashboardTile implements Parcelable {
*/ */
public int iconRes; public int iconRes;
/**
* Optional package to pull the icon resource from.
*/
public String iconPkg;
/** /**
* Full class name of the fragment to display when this tile is * Full class name of the fragment to display when this tile is
* selected. * selected.
@@ -90,6 +98,11 @@ public class DashboardTile implements Parcelable {
*/ */
public Intent intent; public Intent intent;
/**
* Optional list of user handles which the intent should be launched on.
*/
public ArrayList<UserHandle> userHandle = new ArrayList<>();
/** /**
* Optional additional data for use by subclasses of the activity * Optional additional data for use by subclasses of the activity
*/ */
@@ -136,6 +149,7 @@ public class DashboardTile implements Parcelable {
dest.writeInt(summaryRes); dest.writeInt(summaryRes);
TextUtils.writeToParcel(summary, dest, flags); TextUtils.writeToParcel(summary, dest, flags);
dest.writeInt(iconRes); dest.writeInt(iconRes);
dest.writeString(iconPkg);
dest.writeString(fragment); dest.writeString(fragment);
dest.writeBundle(fragmentArguments); dest.writeBundle(fragmentArguments);
if (intent != null) { if (intent != null) {
@@ -144,6 +158,11 @@ public class DashboardTile implements Parcelable {
} else { } else {
dest.writeInt(0); dest.writeInt(0);
} }
final int N = userHandle.size();
dest.writeInt(N);
for (int i = 0; i < N; i++) {
dest.writeParcelable(userHandle.get(i), flags);
}
dest.writeBundle(extras); dest.writeBundle(extras);
} }
@@ -154,11 +173,16 @@ public class DashboardTile implements Parcelable {
summaryRes = in.readInt(); summaryRes = in.readInt();
summary = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); summary = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
iconRes = in.readInt(); iconRes = in.readInt();
iconPkg = in.readString();
fragment = in.readString(); fragment = in.readString();
fragmentArguments = in.readBundle(); fragmentArguments = in.readBundle();
if (in.readInt() != 0) { if (in.readInt() != 0) {
intent = Intent.CREATOR.createFromParcel(in); intent = Intent.CREATOR.createFromParcel(in);
} }
final int N = in.readInt();
for (int i = 0; i < N; i++) {
userHandle.add(UserHandle.CREATOR.createFromParcel(in));
}
extras = in.readBundle(); extras = in.readBundle();
} }

View File

@@ -16,14 +16,16 @@
package com.android.settings.dashboard; package com.android.settings.dashboard;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.android.settings.ProfileSelectDialog;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.Utils; import com.android.settings.Utils;
@@ -93,7 +95,14 @@ public class DashboardTileView extends FrameLayout implements View.OnClickListen
Utils.startWithFragment(getContext(), mTile.fragment, mTile.fragmentArguments, null, 0, Utils.startWithFragment(getContext(), mTile.fragment, mTile.fragmentArguments, null, 0,
mTile.titleRes, mTile.getTitle(getResources())); mTile.titleRes, mTile.getTitle(getResources()));
} else if (mTile.intent != null) { } else if (mTile.intent != null) {
getContext().startActivity(mTile.intent); int numUserHandles = mTile.userHandle.size();
if (numUserHandles > 1) {
ProfileSelectDialog.show(((Activity) getContext()).getFragmentManager(), mTile);
} else if (numUserHandles == 1) {
getContext().startActivityAsUser(mTile.intent, mTile.userHandle.get(0));
} else {
getContext().startActivity(mTile.intent);
}
} }
} }
} }

View File

@@ -52,13 +52,15 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import com.android.internal.content.PackageMonitor; import com.android.internal.content.PackageMonitor;
import com.android.settings.UserSpinnerAdapter;
import com.android.settings.DialogCreatable; import com.android.settings.DialogCreatable;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.UserAdapter;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable; import com.android.settings.search.Indexable;
@@ -68,9 +70,6 @@ import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;
/** /**
* Fragment with the top level print settings. * Fragment with the top level print settings.
*/ */
@@ -120,7 +119,7 @@ public class PrintSettingsFragment extends SettingsPreferenceFragment
private PreferenceCategory mPrintServicesCategory; private PreferenceCategory mPrintServicesCategory;
private PrintJobsController mPrintJobsController; private PrintJobsController mPrintJobsController;
private UserSpinnerAdapter mProfileSpinnerAdapter; private UserAdapter mProfileSpinnerAdapter;
private Spinner mSpinner; private Spinner mSpinner;
@Override @Override