Start implementing UI for changing requested policies.
diff --git a/samples/ApiDemos/res/layout/sample_device_admin.xml b/samples/ApiDemos/res/layout/sample_device_admin.xml
index e6c7e9a..f357eaf 100644
--- a/samples/ApiDemos/res/layout/sample_device_admin.xml
+++ b/samples/ApiDemos/res/layout/sample_device_admin.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2007 The Android Open Source Project
+<!-- Copyright (C) 2010 The Android Open Source Project
 
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
@@ -14,10 +14,10 @@
      limitations under the License.
 -->
 
-<!-- Demonstrates starting and stopping a local service.
-     See corresponding Java code com.android.sdk.app.LocalSerice.java. -->
+<!-- Demonstrates implementation of a DeviceAdmin. -->
 
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="4dip"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical" android:padding="4dip"
     android:gravity="center_horizontal"
     android:layout_width="match_parent" android:layout_height="match_parent">
 
@@ -27,16 +27,82 @@
         android:paddingBottom="4dip"
         android:text="@string/sample_device_admin_summary"/>
 
-    <Button android:id="@+id/enable"
-        android:layout_width="wrap_content" android:layout_height="wrap_content" 
-        android:text="@string/enable_admin">
-        <requestFocus />
-    </Button>
+	<LinearLayout android:orientation="horizontal" android:gravity="center"
+	    android:layout_width="match_parent" android:layout_height="wrap_content">
 
-    <Button android:id="@+id/disable"
-        android:layout_width="wrap_content" android:layout_height="wrap_content" 
-        android:text="@string/disable_admin">
-    </Button>
+	    <Button android:id="@+id/enable"
+	        android:layout_width="wrap_content" android:layout_height="wrap_content" 
+	        android:text="@string/enable_admin">
+	        <requestFocus />
+	    </Button>
+	
+	    <Button android:id="@+id/disable"
+	        android:layout_width="wrap_content" android:layout_height="wrap_content" 
+	        android:text="@string/disable_admin">
+	    </Button>
+	    
+    </LinearLayout>
 
+    <LinearLayout android:orientation="horizontal" android:gravity="center"
+        android:layout_width="match_parent" android:layout_height="wrap_content">
+
+	    <Spinner android:id="@+id/password_mode"
+	        android:layout_width="wrap_content"
+	        android:layout_height="wrap_content"
+	        android:drawSelectorOnTop="true"
+	        android:prompt="@string/password_mode">
+	    </Spinner>
+    
+        <EditText android:id="@+id/password_length"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:hint="@string/password_length_hint"
+            android:inputType="number">
+        </EditText>
+            
+    </LinearLayout>
+
+    <Button android:id="@+id/set_password"
+        android:layout_width="wrap_content" android:layout_height="wrap_content" 
+        android_layout_gravity="east|center_vertical"
+        android:text="@string/set_password">
+    </Button>
+        
+    <LinearLayout android:orientation="horizontal" android:gravity="center"
+        android:layout_width="match_parent" android:layout_height="wrap_content">
+
+        <EditText android:id="@+id/password"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:hint="@string/password_hint"
+            android:freezesText="true">
+        </EditText>
+            
+        <Button android:id="@+id/reset_password"
+            android:layout_width="wrap_content" android:layout_height="wrap_content" 
+            android:layout_weight="0"
+            android:text="@string/reset_password">
+        </Button>
+        
+    </LinearLayout>
+        
+    <LinearLayout android:orientation="horizontal" android:gravity="center"
+        android:layout_width="match_parent" android:layout_height="wrap_content">
+
+        <Button android:id="@+id/force_lock"
+            android:layout_width="wrap_content" android:layout_height="wrap_content" 
+            android:layout_weight="0"
+            android:text="@string/force_lock">
+        </Button>
+        
+        <Button android:id="@+id/wipe_data"
+            android:layout_width="wrap_content" android:layout_height="wrap_content" 
+            android:layout_weight="0"
+            android:text="@string/wipe_data">
+        </Button>
+        
+    </LinearLayout>
+    
 </LinearLayout>
 
diff --git a/samples/ApiDemos/res/values/arrays.xml b/samples/ApiDemos/res/values/arrays.xml
index ca3003f..a40212d 100644
--- a/samples/ApiDemos/res/values/arrays.xml
+++ b/samples/ApiDemos/res/values/arrays.xml
@@ -85,4 +85,12 @@
         <item>charlie</item>  
     </string-array>
     
+    <!-- Used in app/Sample Device Admin -->
+    <string-array name="password_modes">
+        <item>Unspecified</item>
+        <item>Something</item>
+        <item>Numeric</item>
+        <item>Alphanumeric</item>
+    </string-array>
+
 </resources>
diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml
index 63ac249..25774d8 100644
--- a/samples/ApiDemos/res/values/strings.xml
+++ b/samples/ApiDemos/res/values/strings.xml
@@ -444,6 +444,13 @@
         class for administering the user\'s device.</string>
     <string name="enable_admin">Enable Admin</string>
     <string name="disable_admin">Disable Admin</string>
+    <string name="password_mode">Password Mode</string>
+    <string name="password_length_hint">Minimum Length</string>
+    <string name="set_password">Set Password</string>
+    <string name="password_hint">Password</string>
+    <string name="reset_password">Reset Password</string>
+    <string name="force_lock">Force Lock</string>
+    <string name="wipe_data">Wipe Data</string>
     
     <!-- ============================== -->
     <!--  app/voice recognition examples strings  -->
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/SampleDeviceAdmin.java b/samples/ApiDemos/src/com/example/android/apis/app/SampleDeviceAdmin.java
index 57dae9c..819d85b 100644
--- a/samples/ApiDemos/src/com/example/android/apis/app/SampleDeviceAdmin.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/SampleDeviceAdmin.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 The Android Open Source Project
+ * Copyright (C) 2010 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,17 +19,27 @@
 import com.example.android.apis.R;
 
 import android.app.Activity;
+import android.app.AlertDialog;
 import android.app.DeviceAdmin;
 import android.app.DevicePolicyManager;
 import android.content.ComponentName;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
+import android.content.SharedPreferences;
 import android.os.Bundle;
+import android.text.Editable;
+import android.text.TextWatcher;
 import android.util.Log;
 import android.view.View;
 import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
 import android.widget.Button;
+import android.widget.EditText;
+import android.widget.Spinner;
 import android.widget.Toast;
+import android.widget.AdapterView.OnItemSelectedListener;
 
 /**
  * Example of a do-nothing admin class.  When enabled, it lets you control
@@ -37,6 +47,13 @@
  */
 public class SampleDeviceAdmin extends DeviceAdmin {
 
+    static SharedPreferences getSamplePreferences(Context context) {
+        return context.getSharedPreferences(DeviceAdmin.class.getName(), 0);
+    }
+    
+    static String PREF_PASSWORD_MODE = "password_mode";
+    static String PREF_PASSWORD_LENGTH = "password_length";
+    
     void showToast(Context context, CharSequence msg) {
         Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
     }
@@ -61,11 +78,15 @@
         showToast(context, "Sample Device Admin: pw failed");
     }
 
+    @Override
+    public void onPasswordSucceeded(Context context, Intent intent) {
+        showToast(context, "Sample Device Admin: pw succeeded");
+    }
+
     /**
-     * <p>Example of explicitly starting and stopping the local service.
-     * This demonstrates the implementation of a service that runs in the same
-     * process as the rest of the application, which is explicitly started and stopped
-     * as desired.</p>
+     * <p>UI control for the sample device admin.  This provides an interface
+     * to enable, disable, and perform other operations with it to see
+     * their effect.</p>
      * 
      * <p>Note that this is implemented as an inner class only keep the sample
      * all together; typically this code would appear in some separate class.
@@ -79,6 +100,24 @@
         Button mEnableButton;
         Button mDisableButton;
         
+        // Password mode spinner choices
+        // This list must match the list found in samples/ApiDemos/res/values/arrays.xml
+        final static int mPasswordModeValues[] = new int[] {
+            DevicePolicyManager.PASSWORD_MODE_UNSPECIFIED,
+            DevicePolicyManager.PASSWORD_MODE_SOMETHING,
+            DevicePolicyManager.PASSWORD_MODE_NUMERIC,
+            DevicePolicyManager.PASSWORD_MODE_ALPHANUMERIC
+        };
+        Spinner mPasswordMode;
+        EditText mPasswordLength;
+        Button mSetPasswordButton;
+        
+        EditText mPassword;
+        Button mResetPasswordButton;
+        
+        Button mForceLockButton;
+        Button mWipeDataButton;
+        
         @Override
         protected void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
@@ -93,6 +132,47 @@
             mEnableButton.setOnClickListener(mEnableListener);
             mDisableButton = (Button)findViewById(R.id.disable);
             mDisableButton.setOnClickListener(mDisableListener);
+            
+            mPasswordMode = (Spinner)findViewById(R.id.password_mode);
+            ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
+                    this, R.array.password_modes, android.R.layout.simple_spinner_item);
+            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+            mPasswordMode.setAdapter(adapter);
+            mPasswordMode.setOnItemSelectedListener(
+                    new OnItemSelectedListener() {
+                        public void onItemSelected(
+                                AdapterView<?> parent, View view, int position, long id) {
+                            setPasswordMode(mPasswordModeValues[position]);
+                        }
+
+                        public void onNothingSelected(AdapterView<?> parent) {
+                            setPasswordMode(DevicePolicyManager.PASSWORD_MODE_UNSPECIFIED);
+                        }
+                    });
+            mPasswordLength = (EditText)findViewById(R.id.password_length);
+            mPasswordLength.addTextChangedListener(new TextWatcher() {
+                public void afterTextChanged(Editable s) {
+                }
+                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+                }
+                public void onTextChanged(CharSequence s, int start, int before, int count) {
+                    try {
+                        setPasswordLength(Integer.parseInt(s.toString()));
+                    } catch (NumberFormatException e) {
+                    }
+                }
+            });
+            mSetPasswordButton = (Button)findViewById(R.id.set_password);
+            mSetPasswordButton.setOnClickListener(mSetPasswordListener);
+            
+            mPassword = (EditText)findViewById(R.id.password);
+            mResetPasswordButton = (Button)findViewById(R.id.reset_password);
+            mResetPasswordButton.setOnClickListener(mResetPasswordListener);
+            
+            mForceLockButton = (Button)findViewById(R.id.force_lock);
+            mForceLockButton.setOnClickListener(mForceLockListener);
+            mWipeDataButton = (Button)findViewById(R.id.wipe_data);
+            mWipeDataButton.setOnClickListener(mWipeDataListener);
         }
 
         void updateButtonStates() {
@@ -100,12 +180,64 @@
             if (active) {
                 mEnableButton.setEnabled(false);
                 mDisableButton.setEnabled(true);
+                mPasswordMode.setEnabled(true);
+                mPasswordLength.setEnabled(true);
+                mSetPasswordButton.setEnabled(true);
+                mPassword.setEnabled(true);
+                mResetPasswordButton.setEnabled(true);
+                mForceLockButton.setEnabled(true);
+                mWipeDataButton.setEnabled(true);
             } else {
                 mEnableButton.setEnabled(true);
                 mDisableButton.setEnabled(false);
+                mPasswordMode.setEnabled(false);
+                mPasswordLength.setEnabled(false);
+                mSetPasswordButton.setEnabled(false);
+                mPassword.setEnabled(false);
+                mResetPasswordButton.setEnabled(false);
+                mForceLockButton.setEnabled(false);
+                mWipeDataButton.setEnabled(false);
             }
         }
         
+        void updateControls() {
+            SharedPreferences prefs = getSamplePreferences(this);
+            final int pwMode = prefs.getInt(PREF_PASSWORD_MODE,
+                    DevicePolicyManager.PASSWORD_MODE_UNSPECIFIED);
+            final int pwLength = prefs.getInt(PREF_PASSWORD_LENGTH, 0);
+            for (int i=0; i<mPasswordModeValues.length; i++) {
+                if (mPasswordModeValues[i] == pwMode) {
+                    mPasswordMode.setSelection(i);
+                }
+            }
+            mPasswordLength.setText(Integer.toString(pwLength));
+        }
+        
+        void updatePolicies() {
+            SharedPreferences prefs = getSamplePreferences(this);
+            final int pwMode = prefs.getInt(PREF_PASSWORD_MODE,
+                    DevicePolicyManager.PASSWORD_MODE_UNSPECIFIED);
+            final int pwLength = prefs.getInt(PREF_PASSWORD_LENGTH, 0);
+            
+            boolean active = mDPM.isAdminActive(mSampleDeviceAdmin);
+            if (active) {
+                mDPM.setPasswordMode(mSampleDeviceAdmin, pwMode);
+                mDPM.setMinimumPasswordLength(mSampleDeviceAdmin, pwLength);
+            }
+        }
+        
+        void setPasswordMode(int mode) {
+            SharedPreferences prefs = getSamplePreferences(this);
+            prefs.edit().putInt(PREF_PASSWORD_MODE, mode).commit();
+            updatePolicies();
+        }
+        
+        void setPasswordLength(int length) {
+            SharedPreferences prefs = getSamplePreferences(this);
+            prefs.edit().putInt(PREF_PASSWORD_LENGTH, length).commit();
+            updatePolicies();
+        }
+        
         @Override
         protected void onResume() {
             super.onResume();
@@ -143,7 +275,48 @@
                 updateButtonStates();
             }
         };
-    }
 
-    
+        private OnClickListener mSetPasswordListener = new OnClickListener() {
+            public void onClick(View v) {
+                // Launch the activity to have the user set a new password.
+                Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
+                startActivity(intent);
+            }
+        };
+
+        private OnClickListener mResetPasswordListener = new OnClickListener() {
+            public void onClick(View v) {
+                boolean active = mDPM.isAdminActive(mSampleDeviceAdmin);
+                if (active) {
+                    mDPM.resetPassword(mPassword.getText().toString());
+                }
+            }
+        };
+
+        private OnClickListener mForceLockListener = new OnClickListener() {
+            public void onClick(View v) {
+                boolean active = mDPM.isAdminActive(mSampleDeviceAdmin);
+                if (active) {
+                    mDPM.lockNow();
+                }
+            }
+        };
+
+        private OnClickListener mWipeDataListener = new OnClickListener() {
+            public void onClick(View v) {
+                AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this);
+                builder.setMessage("This will erase all of your data.  Are you sure?");
+                builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
+                    public void onClick(DialogInterface dialog, int which) {
+                        boolean active = mDPM.isAdminActive(mSampleDeviceAdmin);
+                        if (active) {
+                            mDPM.wipeData(0);
+                        }
+                    }
+                });
+                builder.setNegativeButton("No way!", null);
+                builder.show();
+            }
+        };
+    }
 }
diff --git a/samples/ApiDemos/src/com/example/android/apis/view/Spinner1.java b/samples/ApiDemos/src/com/example/android/apis/view/Spinner1.java
index a35a909..c5b4bd9 100644
--- a/samples/ApiDemos/src/com/example/android/apis/view/Spinner1.java
+++ b/samples/ApiDemos/src/com/example/android/apis/view/Spinner1.java
@@ -22,12 +22,20 @@
 
 import android.app.Activity;
 import android.os.Bundle;
+import android.view.View;
+import android.widget.AdapterView;
 import android.widget.ArrayAdapter;
 import android.widget.Spinner;
+import android.widget.Toast;
+import android.widget.AdapterView.OnItemSelectedListener;
 
 
 public class Spinner1 extends Activity {
 
+    void showToast(CharSequence msg) {
+        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
+    }
+    
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -38,11 +46,33 @@
                 this, R.array.colors, android.R.layout.simple_spinner_item);
         adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
         s1.setAdapter(adapter);
+        s1.setOnItemSelectedListener(
+                new OnItemSelectedListener() {
+                    public void onItemSelected(
+                            AdapterView<?> parent, View view, int position, long id) {
+                        showToast("Spinner1: position=" + position + " id=" + id);
+                    }
+
+                    public void onNothingSelected(AdapterView<?> parent) {
+                        showToast("Spinner1: unselected");
+                    }
+                });
 
         Spinner s2 = (Spinner) findViewById(R.id.spinner2);
         adapter = ArrayAdapter.createFromResource(this, R.array.planets,
                 android.R.layout.simple_spinner_item);
         adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
         s2.setAdapter(adapter);
+        s2.setOnItemSelectedListener(
+                new OnItemSelectedListener() {
+                    public void onItemSelected(
+                            AdapterView<?> parent, View view, int position, long id) {
+                        showToast("Spinner2: position=" + position + " id=" + id);
+                    }
+
+                    public void onNothingSelected(AdapterView<?> parent) {
+                        showToast("Spinner2: unselected");
+                    }
+                });
     }
 }