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();
for (int i = 0; i < listSize; i++) {
ResolveInfo resolveInfo = list.get(i);
if ((resolveInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM)
!= 0) {
- Drawable icon = null;
- String title = null;
+ int icon = 0;
+ CharSequence title = null;
String summary = null;
// Get the activity's meta-data
@@ -215,14 +218,18 @@ public final class Utils {
Bundle metaData = resolveInfo.activityInfo.metaData;
if (res != null && metaData != null) {
- icon = res.getDrawable(
- metaData.getInt(META_DATA_PREFERENCE_ICON), null);
- title = res.getString(metaData.getInt(META_DATA_PREFERENCE_TITLE));
- summary = res.getString(metaData.getInt(META_DATA_PREFERENCE_SUMMARY));
+ if (metaData.containsKey(META_DATA_PREFERENCE_ICON)) {
+ icon = metaData.getInt(META_DATA_PREFERENCE_ICON);
+ }
+ 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) {
- // Ignore
- } catch (NotFoundException e) {
+ } catch (NameNotFoundException | NotFoundException e) {
// Ignore
}
@@ -231,10 +238,13 @@ public final class Utils {
if (TextUtils.isEmpty(title)) {
title = resolveInfo.loadLabel(pm).toString();
}
+ if (icon == 0) {
+ icon = resolveInfo.activityInfo.icon;
+ }
// Set icon, title and summary for the preference
- // TODO:
- //tile.icon = icon;
+ tile.iconRes = icon;
+ tile.iconPkg = resolveInfo.activityInfo.packageName;
tile.title = title;
tile.summary = summary;
// 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.
*
* The adapter can be used to populate a spinner that switches between the Settings
* 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) {
List userProfiles = userManager.getUserProfiles();
if (userProfiles.size() < 2) {
@@ -747,12 +757,17 @@ public final class Utils {
userProfiles.remove(myUserHandle);
userProfiles.add(0, myUserHandle);
+ return createUserAdapter(userManager, context, userProfiles);
+ }
+
+ public static UserAdapter createUserAdapter(UserManager userManager,
+ Context context, List userProfiles) {
ArrayList userDetails = new ArrayList(userProfiles.size());
final int count = userProfiles.size();
for (int i = 0; i < count; i++) {
userDetails.add(new UserDetails(userProfiles.get(i), userManager, context));
}
- return new UserSpinnerAdapter(context, userDetails);
+ return new UserAdapter(context, userDetails);
}
/**
diff --git a/src/com/android/settings/dashboard/DashboardCategory.java b/src/com/android/settings/dashboard/DashboardCategory.java
index fedbf0abc8d..69d0316f761 100644
--- a/src/com/android/settings/dashboard/DashboardCategory.java
+++ b/src/com/android/settings/dashboard/DashboardCategory.java
@@ -51,6 +51,16 @@ public class DashboardCategory implements Parcelable {
*/
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
*/
@@ -105,7 +115,9 @@ public class DashboardCategory implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(titleRes);
+ dest.writeInt(externalIndex);
TextUtils.writeToParcel(title, dest, flags);
+ dest.writeString(key);
final int count = tiles.size();
dest.writeInt(count);
@@ -118,7 +130,9 @@ public class DashboardCategory implements Parcelable {
public void readFromParcel(Parcel in) {
titleRes = in.readInt();
+ externalIndex = in.readInt();
title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
+ key = in.readString();
final int count = in.readInt();
diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java
index cf398d7bec5..8a9286036c8 100644
--- a/src/com/android/settings/dashboard/DashboardSummary.java
+++ b/src/com/android/settings/dashboard/DashboardSummary.java
@@ -21,6 +21,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
@@ -32,6 +33,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
+
import com.android.settings.R;
import com.android.settings.SettingsActivity;
@@ -148,7 +150,15 @@ public class DashboardSummary extends Fragment {
private void updateTileView(Context context, Resources res, DashboardTile tile,
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);
} else {
tileIcon.setImageDrawable(null);
diff --git a/src/com/android/settings/dashboard/DashboardTile.java b/src/com/android/settings/dashboard/DashboardTile.java
index 1f1d9c2d422..94833d37836 100644
--- a/src/com/android/settings/dashboard/DashboardTile.java
+++ b/src/com/android/settings/dashboard/DashboardTile.java
@@ -21,8 +21,11 @@ import android.content.res.Resources;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
+import android.os.UserHandle;
import android.text.TextUtils;
+import java.util.ArrayList;
+
/**
* Description of a single dashboard tile that the user can select.
*/
@@ -72,6 +75,11 @@ public class DashboardTile implements Parcelable {
*/
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
* selected.
@@ -90,6 +98,11 @@ public class DashboardTile implements Parcelable {
*/
public Intent intent;
+ /**
+ * Optional list of user handles which the intent should be launched on.
+ */
+ public ArrayList userHandle = new ArrayList<>();
+
/**
* Optional additional data for use by subclasses of the activity
*/
@@ -136,6 +149,7 @@ public class DashboardTile implements Parcelable {
dest.writeInt(summaryRes);
TextUtils.writeToParcel(summary, dest, flags);
dest.writeInt(iconRes);
+ dest.writeString(iconPkg);
dest.writeString(fragment);
dest.writeBundle(fragmentArguments);
if (intent != null) {
@@ -144,6 +158,11 @@ public class DashboardTile implements Parcelable {
} else {
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);
}
@@ -154,11 +173,16 @@ public class DashboardTile implements Parcelable {
summaryRes = in.readInt();
summary = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
iconRes = in.readInt();
+ iconPkg = in.readString();
fragment = in.readString();
fragmentArguments = in.readBundle();
if (in.readInt() != 0) {
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();
}
diff --git a/src/com/android/settings/dashboard/DashboardTileView.java b/src/com/android/settings/dashboard/DashboardTileView.java
index a54217bc18f..0896b826296 100644
--- a/src/com/android/settings/dashboard/DashboardTileView.java
+++ b/src/com/android/settings/dashboard/DashboardTileView.java
@@ -16,14 +16,16 @@
package com.android.settings.dashboard;
+import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
-
import android.widget.ImageView;
import android.widget.TextView;
+
+import com.android.settings.ProfileSelectDialog;
import com.android.settings.R;
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,
mTile.titleRes, mTile.getTitle(getResources()));
} 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);
+ }
}
}
}
diff --git a/src/com/android/settings/print/PrintSettingsFragment.java b/src/com/android/settings/print/PrintSettingsFragment.java
index 3e989e4a85b..7317d79839c 100644
--- a/src/com/android/settings/print/PrintSettingsFragment.java
+++ b/src/com/android/settings/print/PrintSettingsFragment.java
@@ -52,13 +52,15 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
+import android.widget.Spinner;
import android.widget.TextView;
import com.android.internal.content.PackageMonitor;
-import com.android.settings.UserSpinnerAdapter;
import com.android.settings.DialogCreatable;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.UserAdapter;
import com.android.settings.Utils;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
@@ -68,9 +70,6 @@ import java.text.DateFormat;
import java.util.ArrayList;
import java.util.List;
-import android.widget.AdapterView.OnItemSelectedListener;
-import android.widget.Spinner;
-
/**
* Fragment with the top level print settings.
*/
@@ -120,7 +119,7 @@ public class PrintSettingsFragment extends SettingsPreferenceFragment
private PreferenceCategory mPrintServicesCategory;
private PrintJobsController mPrintJobsController;
- private UserSpinnerAdapter mProfileSpinnerAdapter;
+ private UserAdapter mProfileSpinnerAdapter;
private Spinner mSpinner;
@Override