From a6145a656af1241fd771038715cf839a8fce76e1 Mon Sep 17 00:00:00 2001 From: Alexandra Gherghina Date: Thu, 24 Jul 2014 17:28:36 +0100 Subject: [PATCH] Toggle between primary and managed profile in App notif settings This adds a spinner to the app notifications screen which can be used to toggle between the Settings app in the primary and managed profile so that the user can edit settings belonging to both profiles. Bug: 16369104 Change-Id: I31c2fb4c0bc318fb8fa5c152621a29fd0c4bb403 --- .../notification/AppNotificationSettings.java | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java index 25047a47601..f8586775e34 100644 --- a/src/com/android/settings/notification/AppNotificationSettings.java +++ b/src/com/android/settings/notification/AppNotificationSettings.java @@ -36,6 +36,8 @@ import android.os.Parcelable; import android.os.ServiceManager; import android.os.SystemClock; import android.provider.Settings; +import android.os.UserHandle; +import android.os.UserManager; import android.util.ArrayMap; import android.util.Log; import android.util.TypedValue; @@ -44,12 +46,17 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.ArrayAdapter; +import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.AdapterView; import android.widget.ImageView; import android.widget.SectionIndexer; +import android.widget.Spinner; import android.widget.TextView; import com.android.settings.PinnedHeaderListFragment; import com.android.settings.R; +import com.android.settings.UserSpinnerAdapter; +import com.android.settings.UserSpinnerAdapter.UserDetails; import java.text.Collator; import java.util.ArrayList; @@ -58,7 +65,8 @@ import java.util.Comparator; import java.util.List; /** Just a sectioned list of installed applications, nothing else to index **/ -public class AppNotificationSettings extends PinnedHeaderListFragment { +public class AppNotificationSettings extends PinnedHeaderListFragment + implements OnItemSelectedListener { private static final String TAG = "AppNotificationSettings"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); @@ -79,6 +87,7 @@ public class AppNotificationSettings extends PinnedHeaderListFragment { private Signature[] mSystemSignature; private Parcelable mListViewState; private Backend mBackend = new Backend(); + private UserSpinnerAdapter mProfileSpinnerAdapter; @Override public void onCreate(Bundle savedInstanceState) { @@ -89,11 +98,37 @@ public class AppNotificationSettings extends PinnedHeaderListFragment { getActivity().setTitle(R.string.app_notifications_title); } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.notification_app_list, container, false); } + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); + List userProfiles = um.getUserProfiles(); + if (userProfiles.size() >= 2) { + Spinner spinner = (Spinner) getActivity().getLayoutInflater().inflate( + R.layout.spinner_view, null); + // TODO: Factor out spinner creation in a method in Utils class. See: http://b/16645615 + UserHandle myUserHandle = new UserHandle(UserHandle.myUserId()); + userProfiles.remove(myUserHandle); + userProfiles.add(0, myUserHandle); + 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), um, mContext)); + } + + mProfileSpinnerAdapter = new UserSpinnerAdapter(mContext, userDetails); + spinner.setAdapter(mProfileSpinnerAdapter); + spinner.setOnItemSelectedListener(this); + setPinnedHeaderView(spinner); + } + } + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); @@ -120,6 +155,24 @@ public class AppNotificationSettings extends PinnedHeaderListFragment { loadAppsList(); } + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + UserHandle selectedUser = mProfileSpinnerAdapter.getUserHandle(position); + if (selectedUser.getIdentifier() != UserHandle.myUserId()) { + // TODO: Factor out intent starting in a method in Utils class. See: http://b/16645615 + Intent intent = new Intent(); + intent.setClassName(mContext.getPackageName(), + com.android.settings.Settings.AppNotificationSettingsActivity.class.getName()); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivityAsUser(intent, selectedUser); + getActivity().finish(); + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + } + public void setBackend(Backend backend) { mBackend = backend; }