summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/dashboard
diff options
context:
space:
mode:
authorJason Monk <jmonk@google.com>2015-02-13 15:23:19 -0500
committerJason Monk <jmonk@google.com>2015-03-25 11:11:36 -0400
commit2ebc8a01696c4e7dd29863b92a15ae0bbbbb254d (patch)
tree8ec8d8ad8b530d01d9aff027abbc992235562ee0 /src/com/android/settings/dashboard
parent5528d8952b0931593e645e1608bf3fe7f46b5ba8 (diff)
downloadpackages_apps_Settings-2ebc8a01696c4e7dd29863b92a15ae0bbbbb254d.zip
packages_apps_Settings-2ebc8a01696c4e7dd29863b92a15ae0bbbbb254d.tar.gz
packages_apps_Settings-2ebc8a01696c4e7dd29863b92a15ae0bbbbb254d.tar.bz2
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
Diffstat (limited to 'src/com/android/settings/dashboard')
-rw-r--r--src/com/android/settings/dashboard/DashboardCategory.java14
-rw-r--r--src/com/android/settings/dashboard/DashboardSummary.java12
-rw-r--r--src/com/android/settings/dashboard/DashboardTile.java24
-rw-r--r--src/com/android/settings/dashboard/DashboardTileView.java13
4 files changed, 60 insertions, 3 deletions
diff --git a/src/com/android/settings/dashboard/DashboardCategory.java b/src/com/android/settings/dashboard/DashboardCategory.java
index fedbf0a..69d0316 100644
--- a/src/com/android/settings/dashboard/DashboardCategory.java
+++ b/src/com/android/settings/dashboard/DashboardCategory.java
@@ -52,6 +52,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
*/
public List<DashboardTile> tiles = new ArrayList<DashboardTile>();
@@ -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 cf398d7..8a92860 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 1f1d9c2..94833d3 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.
*/
@@ -73,6 +76,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.
* @attr ref android.R.styleable#PreferenceHeader_fragment
@@ -91,6 +99,11 @@ public class DashboardTile implements Parcelable {
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
*/
public Bundle extras;
@@ -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 a54217b..0896b82 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);
+ }
}
}
}