OSDN Git Service

Toggle between primary and managed profile in apps settings
authorAlexandra Gherghina <alexgherghina@google.com>
Thu, 24 Jul 2014 17:54:31 +0000 (18:54 +0100)
committerAlexandra Gherghina <alexgherghina@google.com>
Wed, 30 Jul 2014 09:15:38 +0000 (09:15 +0000)
This adds a spinner to the apps 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: I09a94c07597e6509de025dfbbe0e454ae3d9b0aa

res/layout/manage_applications_apps.xml
res/layout/manage_applications_running.xml
res/values/strings.xml
src/com/android/settings/applications/ManageApplications.java

index 5bfdb69..68fcb1b 100644 (file)
      limitations under the License.
 -->
 
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent" >
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:orientation="vertical">
 
-    <LinearLayout android:id="@+id/list_container"
+    <FrameLayout android:id="@+id/pinned_header"
             android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:orientation="vertical"
-            android:visibility="gone">
-        <FrameLayout android:layout_width="match_parent"
-                android:layout_height="0px"
-                android:layout_weight="1">
-            <ListView android:id="@android:id/list"
-                android:drawSelectorOnTop="false"
+            android:layout_height="wrap_content"
+            android:visibility="gone" />
+
+    <FrameLayout
+              android:layout_width="match_parent"
+              android:layout_height="0dp"
+              android:layout_weight="1">
+
+        <LinearLayout android:id="@+id/list_container"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
-                android:clipToPadding="false"
-                android:scrollbarStyle="@integer/preference_scrollbar_style" />
-            <TextView android:id="@android:id/empty"
+                android:orientation="vertical"
+                android:visibility="gone">
+
+            <FrameLayout android:layout_width="match_parent"
+                    android:layout_height="0px"
+                    android:layout_weight="1">
+
+                <ListView android:id="@android:id/list"
+                    android:drawSelectorOnTop="false"
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"
-                    android:gravity="center"
-                    android:text="@string/no_applications"
-                    android:textAppearance="?android:attr/textAppearanceLarge" />
-        </FrameLayout>
-    </LinearLayout>
-
-    <LinearLayout android:id="@+id/loading_container"
-            android:orientation="vertical"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:visibility="gone"
-            android:gravity="center">
-
-        <ProgressBar style="?android:attr/progressBarStyleLarge"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content" />
-        <TextView android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:textAppearance="?android:attr/textAppearanceSmall"
-                android:text="@string/settings_safetylegal_activity_loading"
-                android:paddingTop="4dip"
-                android:singleLine="true" />
-
-    </LinearLayout>
-
-</FrameLayout>
+                    android:clipToPadding="false"
+                    android:scrollbarStyle="@integer/preference_scrollbar_style" />
+
+                <TextView android:id="@android:id/empty"
+                        android:layout_width="match_parent"
+                        android:layout_height="match_parent"
+                        android:gravity="center"
+                        android:text="@string/no_applications"
+                        android:textAppearance="?android:attr/textAppearanceLarge" />
+
+            </FrameLayout>
+
+        </LinearLayout>
+
+        <LinearLayout android:id="@+id/loading_container"
+                android:orientation="vertical"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:visibility="gone"
+                android:gravity="center">
+
+            <ProgressBar style="?android:attr/progressBarStyleLarge"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content" />
+
+            <TextView android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:textAppearance="?android:attr/textAppearanceSmall"
+                    android:text="@string/settings_safetylegal_activity_loading"
+                    android:paddingTop="4dip"
+                    android:singleLine="true" />
+
+        </LinearLayout>
+
+    </FrameLayout>
+
+</LinearLayout>
index 352ce44..cc8c186 100644 (file)
      limitations under the License.
 -->
 
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent" >
-    <view class="com.android.settings.applications.RunningProcessesView"
-            android:id="@+id/running_processes"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:visibility="gone" />
-
-    <LinearLayout android:id="@+id/loading_container"
-            android:orientation="vertical"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:visibility="gone"
-            android:gravity="center">
-
-        <ProgressBar style="?android:attr/progressBarStyleLarge"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content" />
-        <TextView android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:textAppearance="?android:attr/textAppearanceSmall"
-                android:text="@string/settings_safetylegal_activity_loading"
-                android:paddingTop="4dip"
-                android:singleLine="true" />
-
-    </LinearLayout>
-
-</FrameLayout>
+            android:orientation="vertical">
+
+    <FrameLayout android:id="@+id/pinned_header"
+                 android:layout_width="match_parent"
+                 android:layout_height="wrap_content"
+                 android:visibility="gone" />
+
+    <FrameLayout
+              android:layout_width="match_parent"
+              android:layout_height="match_parent" >
+
+        <view class="com.android.settings.applications.RunningProcessesView"
+                android:id="@+id/running_processes"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:visibility="gone" />
+
+        <LinearLayout android:id="@+id/loading_container"
+                android:orientation="vertical"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:visibility="gone"
+                android:gravity="center">
+
+            <ProgressBar style="?android:attr/progressBarStyleLarge"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content" />
+
+            <TextView android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:textAppearance="?android:attr/textAppearanceSmall"
+                    android:text="@string/settings_safetylegal_activity_loading"
+                    android:paddingTop="4dip"
+                    android:singleLine="true" />
+
+        </LinearLayout>
+
+    </FrameLayout>
+
+</LinearLayout>
index d3fe9e7..a18835a 100644 (file)
     <string name="really_remove_account_message" product="tablet">Removing this account will delete all of its messages, contacts, and other data from the tablet!</string>
     <!-- Remove account message in dialog [CHAR LIMIT=NONE] -->
     <string name="really_remove_account_message" product="default">Removing this account will delete all of its messages, contacts, and other data from the phone!</string>
-    <!-- This is shown if the autheticator for a given account fails to remove it. -->
+    <!-- This is shown if the autheticator for a given account fails to remove it. [CHAR LIMIT=NONE] -->
     <string name="remove_account_failed">This change isn\'t allowed by your administrator</string>
     <!-- What to show in messaging that refers to this provider, e.g. AccountSyncSettings -->
     <string name="provider_label">Push subscriptions</string>
index e40ad25..493caf6 100644 (file)
@@ -43,12 +43,12 @@ import android.os.IBinder;
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.os.UserHandle;
+import android.os.UserManager;
 import android.preference.PreferenceFrameLayout;
+import android.provider.Settings;
 import android.support.v4.view.PagerAdapter;
 import android.support.v4.view.PagerTabStrip;
 import android.support.v4.view.ViewPager;
-import android.text.BidiFormatter;
-import android.text.format.Formatter;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.Menu;
@@ -60,18 +60,21 @@ import android.view.animation.AnimationUtils;
 import android.widget.AbsListView;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
+import android.widget.AdapterView.OnItemSelectedListener;
 import android.widget.BaseAdapter;
 import android.widget.Filter;
 import android.widget.Filterable;
 import android.widget.ListView;
-import android.widget.TextView;
+import android.widget.Spinner;
 
 import com.android.internal.app.IMediaContainerService;
 import com.android.internal.content.PackageHelper;
 import com.android.settings.R;
 import com.android.settings.SettingsActivity;
+import com.android.settings.UserSpinnerAdapter;
 import com.android.settings.Settings.RunningServicesActivity;
 import com.android.settings.Settings.StorageUseActivity;
+import com.android.settings.UserSpinnerAdapter.UserDetails;
 import com.android.settings.applications.ApplicationsState.AppEntry;
 import com.android.settings.deviceinfo.StorageMeasurement;
 import com.android.settings.Utils;
@@ -134,7 +137,7 @@ interface AppClickListener {
  */
 public class ManageApplications extends Fragment implements
         AppClickListener, DialogInterface.OnClickListener,
-        DialogInterface.OnDismissListener {
+        DialogInterface.OnDismissListener, OnItemSelectedListener  {
 
     static final String TAG = "ManageApplications";
     static final boolean DEBUG = false;
@@ -194,6 +197,8 @@ public class ManageApplications extends Fragment implements
 
         private View mListContainer;
 
+        private ViewGroup mPinnedHeader;
+
         // ListView used to display list
         private ListView mListView;
         // Custom view used to display running processes
@@ -245,6 +250,14 @@ public class ManageApplications extends Fragment implements
             mRootView = inflater.inflate(mListType == LIST_TYPE_RUNNING
                     ? R.layout.manage_applications_running
                     : R.layout.manage_applications_apps, null);
+            mPinnedHeader = (ViewGroup) mRootView.findViewById(R.id.pinned_header);
+            if (mOwner.mProfileSpinnerAdapter != null) {
+                Spinner spinner = (Spinner) inflater.inflate(R.layout.spinner_view, null);
+                spinner.setAdapter(mOwner.mProfileSpinnerAdapter);
+                spinner.setOnItemSelectedListener(mOwner);
+                mPinnedHeader.addView(spinner);
+                mPinnedHeader.setVisibility(View.VISIBLE);
+            }
             mLoadingContainer = mRootView.findViewById(R.id.loading_container);
             mLoadingContainer.setVisibility(View.VISIBLE);
             mListContainer = mRootView.findViewById(R.id.list_container);
@@ -468,6 +481,8 @@ public class ManageApplications extends Fragment implements
     private ViewGroup mContentContainer;
     private View mRootView;
     private ViewPager mViewPager;
+    private UserSpinnerAdapter mProfileSpinnerAdapter;
+    private Context mContext;
 
     AlertDialog mResetDialog;
 
@@ -830,13 +845,14 @@ public class ManageApplications extends Fragment implements
             mActive.remove(view);
         }
     }
-    
+
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
         setHasOptionsMenu(true);
 
+        mContext = getActivity();
         mApplicationsState = ApplicationsState.getInstance(getActivity().getApplication());
         Intent intent = getActivity().getIntent();
         String action = intent.getAction();
@@ -903,6 +919,22 @@ public class ManageApplications extends Fragment implements
         mTabs.add(tab);
 
         mNumTabs = mTabs.size();
+
+        final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
+        List<UserHandle> userProfiles = um.getUserProfiles();
+        if (userProfiles.size() >= 2) {
+
+            UserHandle myUserHandle = new UserHandle(UserHandle.myUserId());
+            userProfiles.remove(myUserHandle);
+            userProfiles.add(0, myUserHandle);
+            ArrayList<UserDetails> userDetails = new ArrayList<UserDetails>(userProfiles.size());
+            final int count = userProfiles.size();
+            for (int i = 0; i < count; i++) {
+                userDetails.add(new UserDetails(userProfiles.get(i), um, mContext));
+            }
+            // TODO: Factor out spinner creation in a method in Utils class. See: http://b/16645615
+            mProfileSpinnerAdapter = new UserSpinnerAdapter(mContext, userDetails);
+        }
     }
 
 
@@ -1011,6 +1043,23 @@ public class ManageApplications extends Fragment implements
         }
     }
 
+    @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(Settings.ACTION_APPLICATION_SETTINGS);
+            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            mContext.startActivityAsUser(intent, selectedUser);
+            getActivity().finish();
+        }
+    }
+
+    @Override
+    public void onNothingSelected(AdapterView<?> parent) {
+        // Nothing to do
+    }
+
     private void updateNumTabs() {
         int newNum = mApplicationsState.haveDisabledApps() ? mTabs.size() : (mTabs.size()-1);
         if (newNum != mNumTabs) {