diff --git a/samples/ApiDemos/res/layout/device_admin_sample.xml b/samples/ApiDemos/res/layout/device_admin_sample.xml index cbd4dc962..2827c010b 100644 --- a/samples/ApiDemos/res/layout/device_admin_sample.xml +++ b/samples/ApiDemos/res/layout/device_admin_sample.xml @@ -4,9 +4,9 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 - + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,47 +27,47 @@ android:paddingBottom="4dip" android:text="@string/sample_device_admin_summary"/> - + + + + + - - - - - - - + + + - + - + @@ -78,15 +78,15 @@ android:hint="@string/password_hint" android:freezesText="true"> - + - + - + @@ -96,25 +96,45 @@ android:hint="@string/max_failed_pw_hint" android:inputType="number"> - + - + - + - + - + + + + + + + + + + diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml index 799d67fa0..802fc805d 100644 --- a/samples/ApiDemos/res/values/strings.xml +++ b/samples/ApiDemos/res/values/strings.xml @@ -43,7 +43,7 @@ App/Activity/SetWallpaper Set Wallpaper Randomize - + App/Activity/Translucent Example of how you can make an activity have a translucent background, compositing over @@ -146,7 +146,7 @@ Start failed delivery Service created. Service destroyed. - + Service is in the foreground Sample Foreground Service @@ -235,7 +235,7 @@ Content/Storage/External Storage Create Delete - + Content/Resources/Styled Text Initialized from a resource: Plain, bold, italic, bold-italic @@ -249,11 +249,11 @@ - + App/Intents Example of launching various Intents. Get Music - + @@ -440,18 +440,18 @@ This activity creates shortcuts for the launcher (home screen), and receives intents from those shortcuts. To try it, return to the launcher and long-press to create a shortcut. Intent: - + - + App/Device Admin Sample Device Admin Sample code for writing a DeviceAdmin class. This implementation provides a UI (in ApiDemos) for you to directly control what the DeviceAdmin does with the system. - + Demonstration of a DeviceAdmin class for administering the user\'s device. Enable Admin @@ -464,7 +464,9 @@ Password Attempts Wipe Data Force Lock Wipe Data - + Max screen timeout + Set Timeout + @@ -472,7 +474,7 @@ This activity demonstrates the voice recognition APIs. Speak! Results: - + @@ -480,7 +482,7 @@ Hide Me! Density: Unknown Screen - + diff --git a/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java b/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java index d29f12305..f7ee2d73c 100644 --- a/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java +++ b/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java @@ -51,15 +51,15 @@ public class DeviceAdminSample extends DeviceAdminReceiver { static SharedPreferences getSamplePreferences(Context context) { return context.getSharedPreferences(DeviceAdminReceiver.class.getName(), 0); } - + static String PREF_PASSWORD_QUALITY = "password_quality"; static String PREF_PASSWORD_LENGTH = "password_length"; static String PREF_MAX_FAILED_PW = "max_failed_pw"; - + void showToast(Context context, CharSequence msg) { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); } - + @Override public void onEnabled(Context context, Intent intent) { showToast(context, "Sample Device Admin: enabled"); @@ -94,20 +94,20 @@ public class DeviceAdminSample extends DeviceAdminReceiver { *

UI control for the sample device admin. This provides an interface * to enable, disable, and perform other operations with it to see * their effect.

- * + * *

Note that this is implemented as an inner class only keep the sample * all together; typically this code would appear in some separate class. */ public static class Controller extends Activity { static final int RESULT_ENABLE = 1; - + DevicePolicyManager mDPM; ActivityManager mAM; ComponentName mDeviceAdminSample; - + Button mEnableButton; Button mDisableButton; - + // Password quality spinner choices // This list must match the list found in samples/ApiDemos/res/values/arrays.xml final static int mPasswordQualityValues[] = new int[] { @@ -120,15 +120,19 @@ public class DeviceAdminSample extends DeviceAdminReceiver { Spinner mPasswordQuality; EditText mPasswordLength; Button mSetPasswordButton; - + EditText mPassword; Button mResetPasswordButton; - + EditText mMaxFailedPw; - + Button mForceLockButton; Button mWipeDataButton; - + + private Button mTimeoutButton; + + private EditText mTimeout; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -136,7 +140,7 @@ public class DeviceAdminSample extends DeviceAdminReceiver { mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE); mAM = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); mDeviceAdminSample = new ComponentName(Controller.this, DeviceAdminSample.class); - + setContentView(R.layout.device_admin_sample); // Watch for button clicks. @@ -144,7 +148,7 @@ public class DeviceAdminSample extends DeviceAdminReceiver { mEnableButton.setOnClickListener(mEnableListener); mDisableButton = (Button)findViewById(R.id.disable); mDisableButton.setOnClickListener(mDisableListener); - + mPasswordQuality = (Spinner)findViewById(R.id.password_quality); ArrayAdapter adapter = ArrayAdapter.createFromResource( this, R.array.password_qualities, android.R.layout.simple_spinner_item); @@ -176,11 +180,11 @@ public class DeviceAdminSample extends DeviceAdminReceiver { }); 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); - + mMaxFailedPw = (EditText)findViewById(R.id.max_failed_pw); mMaxFailedPw.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { @@ -199,11 +203,15 @@ public class DeviceAdminSample extends DeviceAdminReceiver { } } }); - + mForceLockButton = (Button)findViewById(R.id.force_lock); mForceLockButton.setOnClickListener(mForceLockListener); mWipeDataButton = (Button)findViewById(R.id.wipe_data); mWipeDataButton.setOnClickListener(mWipeDataListener); + + mTimeout = (EditText) findViewById(R.id.timeout); + mTimeoutButton = (Button) findViewById(R.id.set_timeout); + mTimeoutButton.setOnClickListener(mSetTimeoutListener); } void updateButtonStates() { @@ -230,14 +238,14 @@ public class DeviceAdminSample extends DeviceAdminReceiver { mWipeDataButton.setEnabled(false); } } - + void updateControls() { SharedPreferences prefs = getSamplePreferences(this); final int pwQuality = prefs.getInt(PREF_PASSWORD_QUALITY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); final int pwLength = prefs.getInt(PREF_PASSWORD_LENGTH, 0); final int maxFailedPw = prefs.getInt(PREF_MAX_FAILED_PW, 0); - + for (int i=0; i