Tabletize Device administrator screen and fix the layout for DeviceAdminAdd.

Bug: 3376986

Convert the DeviceAdminSettings screen to a fragment, remove fat titlebar.
Convert the DeviceAdminAdd screen to layout nicely in the new holo DialogWhenLarge
style.

Change-Id: I20a9d16aed135a2178969dfff807075b0b79237c
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index f822ff6..5556fe7 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -656,9 +656,9 @@
             </intent-filter>
         </activity>
 
-        <activity android:name="DeviceAdminSettings"
+        <activity android:name="Settings$DeviceAdminSettingsActivity"
                 android:label="@string/device_admin_settings_title"
-                android:theme="@style/TallTitleBarTheme"
+                android:theme="@android:style/Theme.Holo"
                 android:clearTaskOnLaunch="true"
                 >
             <intent-filter>
@@ -667,11 +667,19 @@
                 <category android:name="android.intent.category.VOICE_LAUNCH" />
                 <category android:name="com.android.settings.SHORTCUT" />
             </intent-filter>
+            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+                android:value="com.android.settings.DeviceAdminSettings" />
+            <meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
+                android:resource="@id/security_settings" />
+            <meta-data android:name="com.android.settings.PARENT_FRAGMENT_TITLE"
+                android:resource="@string/location_security_settings_title" />
+            <meta-data android:name="com.android.settings.PARENT_FRAGMENT_CLASS"
+                android:value="com.android.settings.Settings$SecuritySettingsActivity" />
         </activity>
 
         <activity android:name="DeviceAdminAdd"
                 android:label="@string/device_admin_add_title"
-                android:theme="@style/TallTitleBarTheme"
+                android:theme="@android:style/Theme.Holo.DialogWhenLarge"
                 android:clearTaskOnLaunch="true"
                 >
             <intent-filter>
diff --git a/res/layout/device_admin_add.xml b/res/layout/device_admin_add.xml
index f3ba59e..ac30ed9 100644
--- a/res/layout/device_admin_add.xml
+++ b/res/layout/device_admin_add.xml
@@ -21,25 +21,12 @@
     android:layout_height="match_parent"
     android:orientation="vertical">
 
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="horizontal"
-        android:background="@*android:drawable/title_bar_medium">
-        <TextView android:id="@+id/title"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:gravity="center"
-            android:textAppearance="?android:attr/textAppearanceLarge"
-            android:textColor="?android:attr/textColorPrimary"
-            android:shadowColor="?android:attr/colorBackground"
-            android:shadowRadius="2" />
-    </LinearLayout>
-
     <ScrollView
         android:layout_width="match_parent"
         android:layout_height="0dip"
         android:layout_weight="1.0"
+        android:layout_marginLeft="16dip"
+        android:layout_marginRight="16dip"
         android:gravity="top">
         <LinearLayout
             android:layout_width="match_parent"
@@ -111,31 +98,50 @@
         </LinearLayout>
     </ScrollView>
 
-    <LinearLayout style="@android:style/ButtonBar"
+    <LinearLayout android:id="@+id/buttonPanel"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:orientation="horizontal">
-        <View
-           android:layout_width="0dip"
-           android:layout_height="0dip"
-           android:layout_weight="1" />
-        <Button android:id="@+id/action_button"
-            android:layout_width="wrap_content"
+        android:minHeight="54dip"
+        android:orientation="vertical"
+        android:divider="?android:attr/dividerHorizontal"
+        android:showDividers="beginning"
+        android:dividerPadding="16dip">
+        <LinearLayout
+            style="?android:attr/buttonBarStyle"
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_weight="1" />
-        <View
-           android:layout_width="0dip"
-           android:layout_height="0dip"
-           android:layout_weight="1" />
-        <Button android:id="@+id/cancel_button"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:text="@string/cancel" />
-        <View
-           android:layout_width="0dip"
-           android:layout_height="0dip"
-           android:layout_weight="1" />
-    </LinearLayout>
+            android:orientation="horizontal"
+            android:paddingLeft="2dip"
+            android:paddingRight="2dip"
+            android:measureWithLargestChild="true">
+            <LinearLayout android:id="@+id/leftSpacer"
+                android:layout_weight="0.25"
+                android:layout_width="0dip"
+                android:layout_height="wrap_content"
+                android:orientation="horizontal"
+                android:visibility="gone" />
+            <Button android:id="@+id/action_button"
+                android:layout_width="0dip"
+                android:layout_gravity="left"
+                android:layout_weight="1"
+                android:maxLines="2"
+                style="?android:attr/buttonBarButtonStyle"
+                android:layout_height="wrap_content" />
+            <Button android:id="@+id/cancel_button"
+                android:layout_width="0dip"
+                android:layout_gravity="right"
+                android:layout_weight="1"
+                android:maxLines="2"
+                android:text="@string/cancel"
+                style="?android:attr/buttonBarButtonStyle"
+                android:layout_height="wrap_content" />
+            <LinearLayout android:id="@+id/rightSpacer"
+                android:layout_width="0dip"
+                android:layout_weight="0.25"
+                android:layout_height="wrap_content"
+                android:orientation="horizontal"
+                android:visibility="gone" />
+        </LinearLayout>
+     </LinearLayout>
 
 </LinearLayout>
diff --git a/res/layout/device_admin_item.xml b/res/layout/device_admin_item.xml
index 49cbc61..fe9e45a 100644
--- a/res/layout/device_admin_item.xml
+++ b/res/layout/device_admin_item.xml
@@ -21,49 +21,62 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:minHeight="?android:attr/listPreferredItemHeight"
-    android:orientation="vertical"
+    android:orientation="horizontal"
     android:paddingRight="6dip"
     android:paddingLeft="6dip"
-    android:gravity="fill" >
+    android:gravity="center_vertical" >
 
     <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:minWidth="64dip"
+        android:gravity="center"
+        android:padding="8dip"
         android:orientation="horizontal">
-    
-        <ImageView android:id="@+id/icon"
+        <ImageView
+            android:id="@+id/icon"
             android:layout_width="@android:dimen/app_icon_size"
             android:layout_height="@android:dimen/app_icon_size"
-            android:layout_marginLeft="5dip"
-            android:layout_marginRight="11dip"
             android:layout_gravity="center_vertical"
-            android:scaleType="fitCenter"/>
-    
+            />
+    </LinearLayout>
+
+    <RelativeLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="8dip"
+        android:layout_marginBottom="8dip"
+        android:layout_weight="1">
+
         <TextView android:id="@+id/name"
-            android:layout_width="0dp"
-            android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:layout_gravity="center_vertical"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:textStyle="bold"
-            android:singleLine="true"
-            android:ellipsize="marquee"
-            android:layout_marginBottom="2dip" />
-            
-        <CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
-            android:id="@+id/checkbox" 
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_gravity="center_vertical"
-            android:focusable="false"
-            android:clickable="false" />
-    </LinearLayout>
-    
-    <TextView android:id="@+id/description"
-        android:layout_width="match_parent"
+            android:singleLine="true"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:ellipsize="marquee"
+            android:layout_alignParentTop="true"
+            android:fadingEdge="horizontal" />
+
+        <TextView android:id="@+id/description"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="4dip"
+            android:layout_below="@id/name"
+            android:layout_alignLeft="@id/name"
+            android:textAppearance="?android:attr/textAppearanceSmall"
+            android:textColor="?android:attr/textColorSecondary"
+            android:maxLines="4" />
+
+    </RelativeLayout>
+
+    <CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/checkbox"
+        android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:textAppearance="?android:attr/textAppearanceSmall"
-        android:singleLine="true"
-        android:ellipsize="end" />
-            
+        android:layout_gravity="center_vertical"
+        android:layout_marginRight="16dip"
+        android:layout_marginLeft="16dip"
+        android:focusable="false"
+        android:clickable="false" />
+
 </LinearLayout>
diff --git a/res/layout/device_admin_settings.xml b/res/layout/device_admin_settings.xml
index eaf42fe..669ac3c 100644
--- a/res/layout/device_admin_settings.xml
+++ b/res/layout/device_admin_settings.xml
@@ -18,27 +18,10 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical">
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="horizontal"
-        android:background="@*android:drawable/title_bar_medium">
-        <TextView
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:text="@string/select_device_admin_msg"
-            android:gravity="center"
-            android:textAppearance="?android:attr/textAppearanceLarge"
-            android:textColor="?android:attr/textColorPrimary"
-            android:shadowColor="?android:attr/colorBackground"
-            android:shadowRadius="2" />
-    </LinearLayout>
     <FrameLayout
             android:layout_width="match_parent"
             android:layout_height="0px"
-            android:layout_weight="1"
-            android:paddingTop="10dip"
-            android:paddingBottom="10dip">
+            android:layout_weight="1">
         <ListView android:id="@android:id/list"
                 android:layout_width="match_parent" 
                 android:layout_height="match_parent"
@@ -49,6 +32,6 @@
                 android:layout_height="match_parent"
                 android:gravity="center"
                 android:text="@string/no_device_admins"
-                android:textAppearance="?android:attr/textAppearanceLarge" />
+                android:textAppearance="?android:attr/textAppearanceMedium" />
     </FrameLayout>
 </LinearLayout>
diff --git a/res/xml/security_settings_misc.xml b/res/xml/security_settings_misc.xml
index e67542b..68ee8c0 100644
--- a/res/xml/security_settings_misc.xml
+++ b/res/xml/security_settings_misc.xml
@@ -41,11 +41,8 @@
             android:persistent="false">
         <Preference android:title="@string/manage_device_admin"
                 android:summary="@string/manage_device_admin_summary"
-                android:persistent="false">
-            <intent android:action="android.intent.action.MAIN"
-                    android:targetPackage="com.android.settings"
-                    android:targetClass="com.android.settings.DeviceAdminSettings"/>
-        </Preference>
+                android:persistent="false"
+                android:fragment="com.android.settings.DeviceAdminSettings"/>
     </PreferenceCategory>
 
     <PreferenceCategory android:title="@string/credentials_title"
diff --git a/src/com/android/settings/DeviceAdminAdd.java b/src/com/android/settings/DeviceAdminAdd.java
index 26bd88a..63998e5 100644
--- a/src/com/android/settings/DeviceAdminAdd.java
+++ b/src/com/android/settings/DeviceAdminAdd.java
@@ -64,11 +64,11 @@
     DeviceAdminInfo mDeviceAdmin;
     CharSequence mAddMsgText;
     
-    TextView mTitle;
     ImageView mAdminIcon;
     TextView mAdminName;
     TextView mAdminDescription;
     TextView mAddMsg;
+    ImageView mAddMsgExpander;
     boolean mAddMsgEllipsized = true;
     TextView mAdminWarning;
     ViewGroup mAdminPolicies;
@@ -149,15 +149,15 @@
             }
         }
         mAddMsgText = getIntent().getCharSequenceExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION);
-        
+
         setContentView(R.layout.device_admin_add);
         
-        mTitle = (TextView)findViewById(R.id.title);
         mAdminIcon = (ImageView)findViewById(R.id.admin_icon);
         mAdminName = (TextView)findViewById(R.id.admin_name);
         mAdminDescription = (TextView)findViewById(R.id.admin_description);
 
         mAddMsg = (TextView)findViewById(R.id.add_msg);
+        mAddMsgExpander = (ImageView) findViewById(R.id.add_msg_expander);
         mAddMsg.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 toggleMessageEllipsis(v);
@@ -167,15 +167,15 @@
         // toggleMessageEllipsis also handles initial layout:
         toggleMessageEllipsis(mAddMsg);
 
-        mAdminWarning = (TextView)findViewById(R.id.admin_warning);
-        mAdminPolicies = (ViewGroup)findViewById(R.id.admin_policies);
-        mCancelButton = (Button)findViewById(R.id.cancel_button);
+        mAdminWarning = (TextView) findViewById(R.id.admin_warning);
+        mAdminPolicies = (ViewGroup) findViewById(R.id.admin_policies);
+        mCancelButton = (Button) findViewById(R.id.cancel_button);
         mCancelButton.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 finish();
             }
         });
-        mActionButton = (Button)findViewById(R.id.action_button);
+        mActionButton = (Button) findViewById(R.id.action_button);
         mActionButton.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 if (mAdding) {
@@ -269,6 +269,7 @@
             mAddMsg.setVisibility(View.VISIBLE);
         } else {
             mAddMsg.setVisibility(View.GONE);
+            mAddMsgExpander.setVisibility(View.GONE);
         }
         if (!mRefreshing && mDPM.isAdminActive(mDeviceAdmin.getComponent())) {
             if (mActivePolicies.size() == 0) {
@@ -285,7 +286,7 @@
             setViewVisibility(mAddingPolicies, View.GONE);
             mAdminWarning.setText(getString(R.string.device_admin_status,
                     mDeviceAdmin.getActivityInfo().applicationInfo.loadLabel(getPackageManager())));
-            mTitle.setText(getText(R.string.active_device_admin_msg));
+            setTitle(getText(R.string.active_device_admin_msg));
             mActionButton.setText(getText(R.string.remove_device_admin));
             mAdding = false;
         } else {
@@ -303,7 +304,7 @@
             setViewVisibility(mActivePolicies, View.GONE);
             mAdminWarning.setText(getString(R.string.device_admin_warning,
                     mDeviceAdmin.getActivityInfo().applicationInfo.loadLabel(getPackageManager())));
-            mTitle.setText(getText(R.string.add_device_admin_msg));
+            setTitle(getText(R.string.add_device_admin_msg));
             mActionButton.setText(getText(R.string.add_device_admin));
             mAdding = true;
         }
@@ -317,8 +318,7 @@
         tv.setEllipsize(mAddMsgEllipsized ? TruncateAt.END : null);
         tv.setMaxLines(mAddMsgEllipsized ? getEllipsizedLines() : MAX_ADD_MSG_LINES);
 
-        ImageView iv = (ImageView) findViewById(R.id.add_msg_expander);
-        iv.setImageResource(mAddMsgEllipsized ?
+        mAddMsgExpander.setImageResource(mAddMsgEllipsized ?
             com.android.internal.R.drawable.expander_ic_minimized :
             com.android.internal.R.drawable.expander_ic_maximized);
     }
diff --git a/src/com/android/settings/DeviceAdminSettings.java b/src/com/android/settings/DeviceAdminSettings.java
index c3c74b6..310aae7 100644
--- a/src/com/android/settings/DeviceAdminSettings.java
+++ b/src/com/android/settings/DeviceAdminSettings.java
@@ -16,25 +16,21 @@
 
 package com.android.settings;
 
+import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
 import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.ListActivity;
+import android.app.ListFragment;
 import android.app.admin.DeviceAdminInfo;
 import android.app.admin.DeviceAdminReceiver;
 import android.app.admin.DevicePolicyManager;
 import android.content.ComponentName;
 import android.content.Context;
-import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.content.res.Resources;
 import android.os.Bundle;
-import android.os.Handler;
-import android.os.RemoteCallback;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -50,7 +46,7 @@
 import java.util.HashSet;
 import java.util.List;
 
-public class DeviceAdminSettings extends ListActivity {
+public class DeviceAdminSettings extends ListFragment {
     static final String TAG = "DeviceAdminSettings";
     
     static final int DIALOG_WARNING = 1;
@@ -58,18 +54,21 @@
     DevicePolicyManager mDPM;
     final HashSet<ComponentName> mActiveAdmins = new HashSet<ComponentName>();
     final ArrayList<DeviceAdminInfo> mAvailableAdmins = new ArrayList<DeviceAdminInfo>();
-    
-    @Override
-    protected void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
 
-        mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
-        
-        setContentView(R.layout.device_admin_settings);
-    }
-    
     @Override
-    protected void onResume() {
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        mDPM = (DevicePolicyManager) getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
+        return inflater.inflate(R.layout.device_admin_settings, container, false);
+    }
+
+    @Override
+    public void onResume() {
         super.onResume();
         updateList();
     }
@@ -82,16 +81,16 @@
                 mActiveAdmins.add(cur.get(i));
             }
         }
-        
+
         mAvailableAdmins.clear();
-        List<ResolveInfo> avail = getPackageManager().queryBroadcastReceivers(
+        List<ResolveInfo> avail = getActivity().getPackageManager().queryBroadcastReceivers(
                 new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED),
                 PackageManager.GET_META_DATA);
         int count = avail == null ? 0 : avail.size();
         for (int i=0; i<count; i++) {
             ResolveInfo ri = avail.get(i);
             try {
-                DeviceAdminInfo dpi = new DeviceAdminInfo(this, ri);
+                DeviceAdminInfo dpi = new DeviceAdminInfo(getActivity(), ri);
                 if (dpi.isVisible() || mActiveAdmins.contains(dpi.getComponent())) {
                     mAvailableAdmins.add(dpi);
                 }
@@ -104,16 +103,16 @@
         
         getListView().setAdapter(new PolicyListAdapter());
     }
-    
+
     @Override
-    protected void onListItemClick(ListView l, View v, int position, long id) {
+    public void onListItemClick(ListView l, View v, int position, long id) {
         DeviceAdminInfo dpi = (DeviceAdminInfo)l.getAdapter().getItem(position);
         Intent intent = new Intent();
-        intent.setClass(this, DeviceAdminAdd.class);
+        intent.setClass(getActivity(), DeviceAdminAdd.class);
         intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, dpi.getComponent());
         startActivity(intent);
     }
-    
+
     static class ViewHolder {
         ImageView icon;
         TextView name;
@@ -125,7 +124,8 @@
         final LayoutInflater mInflater;
         
         PolicyListAdapter() {
-            mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+            mInflater = (LayoutInflater)
+                    getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         }
 
         public boolean hasStableIds() {
@@ -175,13 +175,14 @@
         }
         
         public void bindView(View view, int position) {
+            final Activity activity = getActivity();
             ViewHolder vh = (ViewHolder) view.getTag();
             DeviceAdminInfo item = mAvailableAdmins.get(position);
-            vh.icon.setImageDrawable(item.loadIcon(getPackageManager()));
-            vh.name.setText(item.loadLabel(getPackageManager()));
+            vh.icon.setImageDrawable(item.loadIcon(activity.getPackageManager()));
+            vh.name.setText(item.loadLabel(activity.getPackageManager()));
             vh.checkbox.setChecked(mActiveAdmins.contains(item.getComponent()));
             try {
-                vh.description.setText(item.loadDescription(getPackageManager()));
+                vh.description.setText(item.loadDescription(activity.getPackageManager()));
             } catch (Resources.NotFoundException e) {
             }
         }
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 1e54504..2532747 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -333,4 +333,5 @@
     public static class AccountSyncSettingsActivity extends Settings { }
     public static class AccountSyncSettingsInAddAccountActivity extends Settings { }
     public static class CryptKeeperSettingsActivity extends Settings { }
+    public static class DeviceAdminSettingsActivity extends Settings { }
 }