merge in ics-mr1-release history after reset to ics-mr1
diff --git a/samples/training/ads-and-ux/AndroidManifest.xml b/samples/training/ads-and-ux/AndroidManifest.xml
new file mode 100644
index 0000000..30032f2
--- /dev/null
+++ b/samples/training/ads-and-ux/AndroidManifest.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.training.ads"
+ android:versionCode="1"
+ android:versionName="1.0">
+
+ <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="13" />
+
+ <application android:label="@string/app_name">
+ <activity android:name=".AdsCatalogActivity" android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <!-- Ad network-specific activity packaged in the SDK. -->
+ <activity android:name="com.google.ads.AdActivity"
+ android:configChanges="keyboard|keyboardHidden|orientation"/>
+ </application>
+
+ <!-- Mobile ad networks typically require these permissions in order to fetch contents -->
+ <!-- over the network. -->
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+
+</manifest>
diff --git a/samples/training/ads-and-ux/ReadMe.txt b/samples/training/ads-and-ux/ReadMe.txt
new file mode 100644
index 0000000..137397c
--- /dev/null
+++ b/samples/training/ads-and-ux/ReadMe.txt
@@ -0,0 +1,9 @@
+This sample demonstrates the integration of an mobile ad SDK with your application. In this case,
+AdMob is used.
+
+The application has the following external dependencies. In order to build, be sure to obtain these
+JAR files and put them under the libs directory.
+1. AdMob SDK
+ http://code.google.com/mobile/ads/download.html
+2. ViewPager depends on the Android Support Package v4 or above.
+ http://developer.android.com/sdk/compatibility-library.html
\ No newline at end of file
diff --git a/samples/training/ads-and-ux/_index.html b/samples/training/ads-and-ux/_index.html
new file mode 100644
index 0000000..a4eeb31
--- /dev/null
+++ b/samples/training/ads-and-ux/_index.html
@@ -0,0 +1,14 @@
+<p>This sample demonstrates the integration of a mobile ad SDK with your application. In this case, <a href="http://www.admob.com">AdMob</a> is used to illustrate key integration concepts.</p>
+
+<p>The application has the following external dependencies. In order to build, be sure to obtain these JAR files and put them under the <code>libs/</code> directory.
+ <ol>
+ <li>
+ <strong>AdMob SDK</strong> - <a href="http://code.google.com/mobile/ads/download.html" >http://code.google.com/mobile/ads/download.html</a>
+ </li>
+ <li>
+ <strong>Android Support Package v4 or above</strong> - <a href="http://developer.android.com/sdk/compatibility-library.html" >http://developer.android.com/sdk/compatibility-library.html</a>
+ </li>
+ </ol>
+</p>
+
+<p>Refer to the <a href="/training/monetization/ads-and-ux.html" />Advertising without Compromising User Experience</a> class for detail.
\ No newline at end of file
diff --git a/samples/training/ads-and-ux/res/drawable-hdpi/ic_home.png b/samples/training/ads-and-ux/res/drawable-hdpi/ic_home.png
new file mode 100644
index 0000000..7e52ff5
--- /dev/null
+++ b/samples/training/ads-and-ux/res/drawable-hdpi/ic_home.png
Binary files differ
diff --git a/samples/training/ads-and-ux/res/drawable-mdpi/android_logo.png b/samples/training/ads-and-ux/res/drawable-mdpi/android_logo.png
new file mode 100644
index 0000000..15f1545
--- /dev/null
+++ b/samples/training/ads-and-ux/res/drawable-mdpi/android_logo.png
Binary files differ
diff --git a/samples/training/ads-and-ux/res/layout-land/ad_bottom.xml b/samples/training/ads-and-ux/res/layout-land/ad_bottom.xml
new file mode 100644
index 0000000..0b3ac14
--- /dev/null
+++ b/samples/training/ads-and-ux/res/layout-land/ad_bottom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- Top-level content view for the simple fragment sample. -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/ad_catalog_layout"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+ <TextView android:id="@+id/title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/banner_bottom" />
+ <TextView android:id="@+id/status"
+ android:layout_width="match_parent"
+ android:layout_height="0px"
+ android:layout_weight="1"
+ android:text="" />
+ <com.google.ads.AdView xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
+ android:id="@+id/ad"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ googleads:adSize="BANNER"
+ googleads:adUnitId="@string/admob_id" />
+</LinearLayout>
diff --git a/samples/training/ads-and-ux/res/layout-large/ad_bottom.xml b/samples/training/ads-and-ux/res/layout-large/ad_bottom.xml
new file mode 100644
index 0000000..54de750
--- /dev/null
+++ b/samples/training/ads-and-ux/res/layout-large/ad_bottom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- Top-level content view for the simple fragment sample. -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/ad_catalog_layout"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+ <TextView android:id="@+id/title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/banner_bottom" />
+ <TextView android:id="@+id/status"
+ android:layout_width="match_parent"
+ android:layout_height="0px"
+ android:layout_weight="1"
+ android:text="" />
+ <com.google.ads.AdView xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
+ android:id="@+id/ad"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ googleads:adSize="IAB_BANNER"
+ googleads:adUnitId="@string/admob_id" />
+</LinearLayout>
\ No newline at end of file
diff --git a/samples/training/ads-and-ux/res/layout-large/ad_covers_content.xml b/samples/training/ads-and-ux/res/layout-large/ad_covers_content.xml
new file mode 100644
index 0000000..b3359c2
--- /dev/null
+++ b/samples/training/ads-and-ux/res/layout-large/ad_covers_content.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- Top-level content view for the simple fragment sample. -->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+ <LinearLayout android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+ <TextView android:id="@+id/title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/ad_covers_content" />
+ <TextView android:id="@+id/status"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+ </LinearLayout>
+ <ImageView android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@drawable/android_logo"
+ android:layout_gravity="center"/>
+ <com.google.ads.AdView xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
+ android:id="@+id/ad"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ googleads:adSize="IAB_LEADERBOARD"
+ googleads:adUnitId="@string/admob_id"
+ android:layout_gravity="center" />
+</FrameLayout>
diff --git a/samples/training/ads-and-ux/res/layout-large/ad_next_to_button.xml b/samples/training/ads-and-ux/res/layout-large/ad_next_to_button.xml
new file mode 100644
index 0000000..a83f4f2
--- /dev/null
+++ b/samples/training/ads-and-ux/res/layout-large/ad_next_to_button.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- Top-level content view for the simple fragment sample. -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/ad_catalog_layout"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+ <com.google.ads.AdView xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
+ android:id="@+id/ad"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ googleads:adSize="IAB_LEADERBOARD"
+ googleads:adUnitId="@string/admob_id" />
+ <Button android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:text="@string/button_close_to_ad"/>
+ <TextView android:id="@+id/status"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="" />
+</LinearLayout>
diff --git a/samples/training/ads-and-ux/res/layout-large/ad_top.xml b/samples/training/ads-and-ux/res/layout-large/ad_top.xml
new file mode 100644
index 0000000..ea36ee7
--- /dev/null
+++ b/samples/training/ads-and-ux/res/layout-large/ad_top.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- Top-level content view for the simple fragment sample. -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/ad_catalog_layout"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+ <com.google.ads.AdView xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
+ android:id="@+id/ad"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ googleads:adSize="IAB_LEADERBOARD"
+ googleads:adUnitId="@string/admob_id" />
+
+ <TextView android:id="@+id/title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/banner_top" />
+ <TextView android:id="@+id/status"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="" />
+</LinearLayout>
\ No newline at end of file
diff --git a/samples/training/ads-and-ux/res/layout/ad_bottom.xml b/samples/training/ads-and-ux/res/layout/ad_bottom.xml
new file mode 100644
index 0000000..677f5fd
--- /dev/null
+++ b/samples/training/ads-and-ux/res/layout/ad_bottom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- Top-level content view for the simple fragment sample. -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/ad_catalog_layout"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+ <TextView android:id="@+id/title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/banner_bottom" />
+ <TextView android:id="@+id/status"
+ android:layout_width="match_parent"
+ android:layout_height="0px"
+ android:layout_weight="1"
+ android:text="" />
+ <com.google.ads.AdView xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
+ android:id="@+id/ad"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ googleads:adSize="IAB_MRECT"
+ googleads:adUnitId="@string/admob_id" />
+</LinearLayout>
\ No newline at end of file
diff --git a/samples/training/ads-and-ux/res/layout/ad_covers_content.xml b/samples/training/ads-and-ux/res/layout/ad_covers_content.xml
new file mode 100644
index 0000000..71764c3
--- /dev/null
+++ b/samples/training/ads-and-ux/res/layout/ad_covers_content.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- Top-level content view for the simple fragment sample. -->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+ <LinearLayout android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+ <TextView android:id="@+id/title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/ad_covers_content" />
+ <TextView android:id="@+id/status"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+ </LinearLayout>
+ <ImageView android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@drawable/android_logo"
+ android:layout_gravity="center"/>
+ <com.google.ads.AdView xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
+ android:id="@+id/ad"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ googleads:adSize="BANNER"
+ googleads:adUnitId="@string/admob_id"
+ android:layout_gravity="center" />
+</FrameLayout>
\ No newline at end of file
diff --git a/samples/training/ads-and-ux/res/layout/ad_next_to_button.xml b/samples/training/ads-and-ux/res/layout/ad_next_to_button.xml
new file mode 100644
index 0000000..1284884
--- /dev/null
+++ b/samples/training/ads-and-ux/res/layout/ad_next_to_button.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- Top-level content view for the simple fragment sample. -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/ad_catalog_layout"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+ <com.google.ads.AdView xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
+ android:id="@+id/ad"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ googleads:adSize="BANNER"
+ googleads:adUnitId="@string/admob_id" />
+ <Button android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:text="@string/button_close_to_ad"/>
+ <TextView android:id="@+id/status"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="" />
+</LinearLayout>
diff --git a/samples/training/ads-and-ux/res/layout/ad_top.xml b/samples/training/ads-and-ux/res/layout/ad_top.xml
new file mode 100644
index 0000000..9d92c45
--- /dev/null
+++ b/samples/training/ads-and-ux/res/layout/ad_top.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- Top-level content view for the simple fragment sample. -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/ad_catalog_layout"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+ <com.google.ads.AdView xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
+ android:id="@+id/ad"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ googleads:adSize="BANNER"
+ googleads:adUnitId="@string/admob_id" />
+
+ <TextView android:id="@+id/title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/banner_top" />
+ <TextView android:id="@+id/status"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="" />
+</LinearLayout>
diff --git a/samples/training/ads-and-ux/res/layout/fragment_pager.xml b/samples/training/ads-and-ux/res/layout/fragment_pager.xml
new file mode 100644
index 0000000..89b2d44
--- /dev/null
+++ b/samples/training/ads-and-ux/res/layout/fragment_pager.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- Top-level content view for the simple fragment sample. -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <android.support.v4.view.ViewPager
+ android:id="@+id/pager"
+ android:layout_width="match_parent"
+ android:layout_height="0px"
+ android:layout_weight="1" />
+</LinearLayout>
\ No newline at end of file
diff --git a/samples/training/ads-and-ux/res/values/attrs.xml b/samples/training/ads-and-ux/res/values/attrs.xml
new file mode 100644
index 0000000..fa23866
--- /dev/null
+++ b/samples/training/ads-and-ux/res/values/attrs.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources>
+
+ <declare-styleable name="AppTheme">
+ <attr name="actionbarCompatTitleStyle" format="reference" />
+ <attr name="actionbarCompatButtonStyle" format="reference" />
+ <attr name="actionbarCompatButtonHomeStyle" format="reference" />
+ <attr name="actionbarCompatProgressIndicatorStyle" format="reference" />
+ </declare-styleable>
+
+ <!-- Mostly taken from frameworks/base.git/core/res/res/values/attrs.xml -->
+ <declare-styleable name="TextAppearance">
+ <attr name="textColor" format="color" />
+ <attr name="textSize" format="dimension" />
+
+ <attr name="textStyle">
+ <flag name="normal" value="0" />
+ <flag name="bold" value="1" />
+ <flag name="italic" value="2" />
+ </attr>
+
+ <attr name="typeface">
+ <enum name="normal" value="0" />
+ <enum name="sans" value="1" />
+ <enum name="serif" value="2" />
+ <enum name="monospace" value="3" />
+ </attr>
+
+ <attr name="shadowRadius" format="float" />
+ <attr name="shadowDx" format="float" />
+ <attr name="shadowDy" format="float" />
+ <attr name="shadowColor" format="color" />
+ </declare-styleable>
+
+</resources>
diff --git a/samples/training/ads-and-ux/res/values/colors.xml b/samples/training/ads-and-ux/res/values/colors.xml
new file mode 100644
index 0000000..531c8c1
--- /dev/null
+++ b/samples/training/ads-and-ux/res/values/colors.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources>
+ <color name="accent_1">#224894</color>
+</resources>
diff --git a/samples/training/ads-and-ux/res/values/dimens.xml b/samples/training/ads-and-ux/res/values/dimens.xml
new file mode 100644
index 0000000..46bf31d
--- /dev/null
+++ b/samples/training/ads-and-ux/res/values/dimens.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources>
+ <!-- UI elements -->
+ <dimen name="top_padding">10dp</dimen>
+ <dimen name="side_padding">5dp</dimen>
+
+ <!-- body content -->
+ <dimen name="text_size_small">14sp</dimen>
+ <dimen name="text_size_medium">18sp</dimen>
+ <dimen name="text_size_large">20sp</dimen>
+</resources>
diff --git a/samples/training/ads-and-ux/res/values/strings.xml b/samples/training/ads-and-ux/res/values/strings.xml
new file mode 100644
index 0000000..f143f46
--- /dev/null
+++ b/samples/training/ads-and-ux/res/values/strings.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources>
+ <string name="ad_covers_content">Ad shouldn\'t cover content!</string>
+ <string name="app_name">Ads sample</string>
+ <string name="banner_top">Top Banner Ad</string>
+ <string name="banner_bottom">Bottom Banner Ad</string>
+ <string name="button_close_to_ad">Button that\'s too close</string>
+ <string name="error_receive_ad">Unable to fetch Ad. Waiting for the next refresh.</string>
+ <string name="admob_id">a14b5f8130c17ef</string>
+</resources>
diff --git a/samples/training/ads-and-ux/src/com/example/training/ads/AdsCatalogActivity.java b/samples/training/ads-and-ux/src/com/example/training/ads/AdsCatalogActivity.java
new file mode 100644
index 0000000..4050981
--- /dev/null
+++ b/samples/training/ads-and-ux/src/com/example/training/ads/AdsCatalogActivity.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2011 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.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.training.ads;
+
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentActivity;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentStatePagerAdapter;
+import android.support.v4.view.ViewPager;
+import android.view.LayoutInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+// Ad network-specific imports (AdMob).
+import com.google.ads.Ad;
+import com.google.ads.AdListener;
+import com.google.ads.AdRequest;
+import com.google.ads.AdView;
+import com.google.ads.AdRequest.ErrorCode;
+
+public class AdsCatalogActivity extends FragmentActivity {
+ private static final int NUM_ITEMS = 4;
+
+ // Ad network-specific mechanism to enable test mode.
+ private static final String TEST_DEVICE_ID = "...";
+
+ PagerAdapter mAdapter;
+ ViewPager mPager;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.fragment_pager);
+
+ mAdapter = new PagerAdapter(getSupportFragmentManager());
+
+ mPager = (ViewPager) findViewById(R.id.pager);
+ mPager.setAdapter(mAdapter);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ mPager.setCurrentItem(0);
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ public static class PagerAdapter extends FragmentStatePagerAdapter {
+ public PagerAdapter(FragmentManager fm) {
+ super(fm);
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ return AdFragment.newInstance(position);
+ }
+
+ @Override
+ public int getCount() {
+ return NUM_ITEMS;
+ }
+ }
+
+ public static class AdFragment extends Fragment {
+ private int mNum;
+ private AdView mAdView;
+ private TextView mAdStatus;
+
+ static AdFragment newInstance(int num) {
+ AdFragment af = new AdFragment();
+
+ // Supply num input as an argument.
+ Bundle args = new Bundle();
+ args.putInt("num", num);
+ af.setArguments(args);
+
+ return af;
+ }
+
+ /**
+ * When creating, retrieve this instance's number from its arguments.
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Bundle args = getArguments();
+ mNum = args != null ? args.getInt("num") : 1;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Set up the various ad layouts on different flip pages.
+ final int[] layouts = {
+ R.layout.ad_top,
+ R.layout.ad_bottom,
+ R.layout.ad_next_to_button,
+ R.layout.ad_covers_content };
+ int layoutId = layouts[mNum];
+ View v = inflater.inflate(layoutId, container, false);
+ mAdStatus = (TextView) v.findViewById(R.id.status);
+ mAdView = (AdView) v.findViewById(R.id.ad);
+ mAdView.setAdListener(new MyAdListener());
+
+ AdRequest adRequest = new AdRequest();
+ // adRequest.addKeyword("ad keywords");
+
+ // Ad network-specific mechanism to enable test mode. Be sure to disable before
+ // publishing your application.
+ adRequest.addTestDevice(TEST_DEVICE_ID);
+ mAdView.loadAd(adRequest);
+ return v;
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ mAdView.destroy();
+ }
+
+ // Receives callbacks on various events related to fetching ads. In this sample,
+ // the application displays a message on the screen. A real application may,
+ // for example, fill the ad with a banner promoting a feature.
+ private class MyAdListener implements AdListener {
+
+ @Override
+ public void onDismissScreen(Ad ad) {}
+
+ @Override
+ public void onFailedToReceiveAd(Ad ad, ErrorCode errorCode) {
+ mAdStatus.setText(R.string.error_receive_ad);
+ }
+
+ @Override
+ public void onLeaveApplication(Ad ad) {}
+
+ @Override
+ public void onPresentScreen(Ad ad) {}
+
+ @Override
+ public void onReceiveAd(Ad ad) { mAdStatus.setText(""); }
+ }
+ }
+}
diff --git a/samples/training/device-management-policy/AndroidManifest.xml b/samples/training/device-management-policy/AndroidManifest.xml
new file mode 100644
index 0000000..30c15c4
--- /dev/null
+++ b/samples/training/device-management-policy/AndroidManifest.xml
@@ -0,0 +1,44 @@
+<!--
+ Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.training.deviceadmin"
+ android:versionCode="1"
+ android:versionName="1.0">
+
+ <uses-sdk android:minSdkVersion="8"
+ android:targetSdkVersion="14" />
+
+ <application android:label="@string/app_name">
+ <activity android:name=".PolicySetupActivity" android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <activity android:name="com.example.training.deviceadmin.SecureActivity"
+ android:label="@string/app_name"/>
+ <receiver android:name="com.example.training.deviceadmin.Policy$PolicyAdmin"
+ android:label="@string/app_policy_admin_name"
+ android:permission="android.permission.BIND_DEVICE_ADMIN">
+ <meta-data android:name="android.app.device_admin"
+ android:resource="@xml/device_admin" />
+ <intent-filter>
+ <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
+ </intent-filter>
+ </receiver>
+ </application>
+</manifest>
diff --git a/samples/training/device-management-policy/_index.html b/samples/training/device-management-policy/_index.html
new file mode 100755
index 0000000..7799330
--- /dev/null
+++ b/samples/training/device-management-policy/_index.html
@@ -0,0 +1,3 @@
+<p>This is a security-aware sample application that demonstrates the enforcement of device administration policies on Android 2.2 or above platforms.</p>
+
+<p>Refer to the <a href="/training/enterprise/device-management-policy.html" />Enhancing Security with Device Management Policies</a> class for detail.
diff --git a/samples/training/device-management-policy/res/layout/activity_policy_setup.xml b/samples/training/device-management-policy/res/layout/activity_policy_setup.xml
new file mode 100644
index 0000000..cf36ba0
--- /dev/null
+++ b/samples/training/device-management-policy/res/layout/activity_policy_setup.xml
@@ -0,0 +1,93 @@
+<!--
+ Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical">
+ <ScrollView android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1" >
+
+ <LinearLayout android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:paddingTop="@dimen/top_padding"
+ android:paddingLeft="@dimen/side_padding"
+ android:paddingRight="@dimen/side_padding" >
+ <TextView android:id="@+id/policy_instructions"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/setup_policy_instruction"
+ android:textSize="@dimen/text_size_medium" />
+ <!-- Password type -->
+ <TextView android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/setup_password_quality"
+ android:textSize="@dimen/text_size_small"
+ android:paddingTop="3dp" />
+ <Spinner android:id="@+id/policy_password_quality"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:prompt="@string/setup_password_quality"
+ android:paddingBottom="3dp"
+ android:focusable="true" >
+ <requestFocus/>
+ </Spinner>
+ <!-- Minimum password length -->
+ <TextView android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/setup_password_length"
+ android:textSize="@dimen/text_size_small"
+ android:paddingTop="3dp" />
+ <EditText android:id="@+id/policy_password_length"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:hint="@string/setup_password_length"
+ android:inputType="number" />
+ <!-- Minimum password uppercase characters -->
+ <LinearLayout android:id="@+id/password_uppercase_view"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:visibility="gone" >
+ <TextView android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/setup_password_uppercase"
+ android:textSize="@dimen/text_size_small"
+ android:paddingTop="3dp" />
+ <EditText android:id="@+id/policy_password_uppercase"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:hint="@string/setup_password_uppercase"
+ android:inputType="number" />
+ </LinearLayout>
+ </LinearLayout>
+ </ScrollView>
+ <TextView android:id="@+id/setup_message"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textSize="@dimen/text_size_medium"
+ android:paddingBottom="5dp"
+ android:paddingLeft="@dimen/side_padding"
+ android:paddingRight="@dimen/side_padding" />
+ <Button android:id="@+id/setup_action_btn"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:minWidth="200dp"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginBottom="@dimen/top_padding" />
+</LinearLayout>
diff --git a/samples/training/device-management-policy/res/layout/activity_secure.xml b/samples/training/device-management-policy/res/layout/activity_secure.xml
new file mode 100644
index 0000000..7790574
--- /dev/null
+++ b/samples/training/device-management-policy/res/layout/activity_secure.xml
@@ -0,0 +1,26 @@
+<!--
+ Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical">
+ <TextView android:layout_height="wrap_content"
+ android:text="@string/secure_message"
+ android:textSize="@dimen/text_size_large"
+ android:layout_width="wrap_content"
+ android:gravity="center_vertical|center_horizontal" />
+</LinearLayout>
diff --git a/samples/training/device-management-policy/res/layout/activity_view_policy.xml b/samples/training/device-management-policy/res/layout/activity_view_policy.xml
new file mode 100644
index 0000000..5a7c214
--- /dev/null
+++ b/samples/training/device-management-policy/res/layout/activity_view_policy.xml
@@ -0,0 +1,89 @@
+<!--
+ Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical">
+ <ScrollView android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1" >
+
+ <LinearLayout android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:paddingTop="@dimen/top_padding"
+ android:paddingLeft="@dimen/side_padding"
+ android:paddingRight="@dimen/side_padding" >
+ <TextView android:id="@+id/policy_instructions"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/view_policy_instruction"
+ android:textSize="@dimen/text_size_medium" />
+ <!-- Password type -->
+ <TextView android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/view_password_quality"
+ android:textSize="@dimen/text_size_small"
+ android:paddingTop="3dp" />
+ <TextView android:id="@+id/policy_password_quality"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:paddingBottom="3dp"
+ android:paddingLeft="3dp" />
+ <!-- Minimum password length -->
+ <TextView android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/view_password_length"
+ android:textSize="@dimen/text_size_small"
+ android:paddingTop="3dp" />
+ <TextView android:id="@+id/policy_password_length"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:paddingBottom="3dp"
+ android:paddingLeft="3dp" />
+ <!-- Minimum password uppercase characters -->
+ <LinearLayout android:id="@+id/password_uppercase_view"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:visibility="gone" >
+ <TextView android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/view_password_uppercase"
+ android:textSize="@dimen/text_size_small"
+ android:paddingTop="3dp" />
+ <TextView android:id="@+id/policy_password_uppercase"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:paddingLeft="3dp" />
+ </LinearLayout>
+ </LinearLayout>
+ </ScrollView>
+ <TextView android:id="@+id/setup_message"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textSize="@dimen/text_size_medium"
+ android:paddingBottom="5dp"
+ android:paddingLeft="@dimen/side_padding"
+ android:paddingRight="@dimen/side_padding" />
+ <Button android:id="@+id/setup_action_btn"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:minWidth="200dp"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginBottom="@dimen/top_padding" />
+</LinearLayout>
diff --git a/samples/training/device-management-policy/res/values-v11/arrays.xml b/samples/training/device-management-policy/res/values-v11/arrays.xml
new file mode 100644
index 0000000..45b23c1
--- /dev/null
+++ b/samples/training/device-management-policy/res/values-v11/arrays.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources>
+ <string-array name="password_types">
+ <item>Anything</item>
+ <item>Something</item>
+ <item>Numeric</item>
+ <item>Alphabetic</item>
+ <item>Alphanumeric</item>
+ <item>Complex</item>
+ </string-array>
+</resources>
diff --git a/samples/training/device-management-policy/res/values-xlarge/dimens.xml b/samples/training/device-management-policy/res/values-xlarge/dimens.xml
new file mode 100644
index 0000000..de75d95
--- /dev/null
+++ b/samples/training/device-management-policy/res/values-xlarge/dimens.xml
@@ -0,0 +1,26 @@
+<!--
+ Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources>
+ <!-- UI elements -->
+ <dimen name="top_padding">60dp</dimen>
+ <dimen name="side_padding">100dp</dimen>
+
+ <!-- body content -->
+ <dimen name="text_size_small">18sp</dimen>
+ <dimen name="text_size_medium">24sp</dimen>
+ <dimen name="text_size_large">26sp</dimen>
+</resources>
diff --git a/samples/training/device-management-policy/res/values/arrays.xml b/samples/training/device-management-policy/res/values/arrays.xml
new file mode 100644
index 0000000..09f3eac
--- /dev/null
+++ b/samples/training/device-management-policy/res/values/arrays.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources>
+ <string-array name="password_types">
+ <item>Anything</item>
+ <item>Something</item>
+ <item>Numeric</item>
+ <item>Alphabetic</item>
+ <item>Alphanumeric</item>
+ </string-array>
+</resources>
\ No newline at end of file
diff --git a/samples/training/device-management-policy/res/values/attrs.xml b/samples/training/device-management-policy/res/values/attrs.xml
new file mode 100644
index 0000000..e781a0c
--- /dev/null
+++ b/samples/training/device-management-policy/res/values/attrs.xml
@@ -0,0 +1,50 @@
+<!--
+ Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<resources>
+
+ <declare-styleable name="AppTheme">
+ <attr name="actionbarCompatTitleStyle" format="reference" />
+ <attr name="actionbarCompatButtonStyle" format="reference" />
+ <attr name="actionbarCompatButtonHomeStyle" format="reference" />
+ <attr name="actionbarCompatProgressIndicatorStyle" format="reference" />
+ </declare-styleable>
+
+ <!-- Mostly taken from frameworks/base.git/core/res/res/values/attrs.xml -->
+ <declare-styleable name="TextAppearance">
+ <attr name="textColor" format="color" />
+ <attr name="textSize" format="dimension" />
+
+ <attr name="textStyle">
+ <flag name="normal" value="0" />
+ <flag name="bold" value="1" />
+ <flag name="italic" value="2" />
+ </attr>
+
+ <attr name="typeface">
+ <enum name="normal" value="0" />
+ <enum name="sans" value="1" />
+ <enum name="serif" value="2" />
+ <enum name="monospace" value="3" />
+ </attr>
+
+ <attr name="shadowRadius" format="float" />
+ <attr name="shadowDx" format="float" />
+ <attr name="shadowDy" format="float" />
+ <attr name="shadowColor" format="color" />
+ </declare-styleable>
+
+</resources>
diff --git a/samples/training/device-management-policy/res/values/colors.xml b/samples/training/device-management-policy/res/values/colors.xml
new file mode 100644
index 0000000..8c3bec7
--- /dev/null
+++ b/samples/training/device-management-policy/res/values/colors.xml
@@ -0,0 +1,19 @@
+<!--
+ Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<resources>
+ <color name="accent_1">#224894</color>
+</resources>
diff --git a/samples/training/device-management-policy/res/values/dimens.xml b/samples/training/device-management-policy/res/values/dimens.xml
new file mode 100644
index 0000000..6f84ef6
--- /dev/null
+++ b/samples/training/device-management-policy/res/values/dimens.xml
@@ -0,0 +1,26 @@
+<!--
+ Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<resources>
+ <!-- UI elements -->
+ <dimen name="top_padding">10dp</dimen>
+ <dimen name="side_padding">5dp</dimen>
+
+ <!-- body content -->
+ <dimen name="text_size_small">14sp</dimen>
+ <dimen name="text_size_medium">18sp</dimen>
+ <dimen name="text_size_large">20sp</dimen>
+</resources>
diff --git a/samples/training/device-management-policy/res/values/strings.xml b/samples/training/device-management-policy/res/values/strings.xml
new file mode 100644
index 0000000..5a37bd1
--- /dev/null
+++ b/samples/training/device-management-policy/res/values/strings.xml
@@ -0,0 +1,43 @@
+<!--
+ Copyright (C) 2011 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.
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<resources>
+ <string name="app_name">Device Admin Lesson</string>
+ <string name="app_policy_admin_name">Policy Admin Receiver</string>
+
+ <!-- Setup activity -->
+ <string name="setup_policy_instruction">Set up device administration policy:</string>
+ <string name="setup_password_quality">Select a password quality</string>
+ <string name="setup_password_length">Set min. pw. length</string>
+ <string name="setup_password_uppercase">Set min. pw. uppercase</string>
+ <string name="setup_action_activate">Activate</string>
+ <string name="setup_message_activate">Press button to activate the device administrator</string>
+ <string name="setup_action_set_policy">Enforce Policy</string>
+ <string name="setup_message_set_policy">Press button to enforce specified policy.</string>
+ <string name="setup_action_enforce_policy">Update Password</string>
+ <string name="setup_message_enforce_policy">Current password doesn\'t conform to the policy.\nPress button to update password.</string>
+ <string name="setup_action_go_secured">Go</string>
+ <string name="setup_message_go_secured">Current password conforms to policy. Device is protected.\nPress button to access secured content.</string>
+
+ <!-- View policy activity -->
+ <string name="view_policy_instruction">Review device administration policy:</string>
+ <string name="view_password_quality">Password quality:</string>
+ <string name="view_password_length">Minimum password length:</string>
+ <string name="view_password_uppercase">Minimum password upper case:</string>
+
+ <string name="secure_message">Device is properly secured. Access is granted to secured content</string>
+ <string name="device_admin_activation_message">Provide a message here explaining why an application needs to become a device administrator.</string>
+</resources>
diff --git a/samples/training/device-management-policy/res/xml/device_admin.xml b/samples/training/device-management-policy/res/xml/device_admin.xml
new file mode 100644
index 0000000..af1e664
--- /dev/null
+++ b/samples/training/device-management-policy/res/xml/device_admin.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2011 Google Inc.
+
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
+ <uses-policies>
+ <limit-password />
+ </uses-policies>
+</device-admin>
\ No newline at end of file
diff --git a/samples/training/device-management-policy/src/com/example/training/deviceadmin/Policy.java b/samples/training/device-management-policy/src/com/example/training/deviceadmin/Policy.java
new file mode 100644
index 0000000..4cf63f5
--- /dev/null
+++ b/samples/training/device-management-policy/src/com/example/training/deviceadmin/Policy.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2011 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.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.training.deviceadmin;
+
+import android.app.Activity;
+import android.app.admin.DeviceAdminReceiver;
+import android.app.admin.DevicePolicyManager;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Build;
+
+public class Policy {
+ public static final int REQUEST_ADD_DEVICE_ADMIN = 1;
+
+ private static final String APP_PREF = "APP_PREF";
+ private static final String KEY_PASSWORD_LENGTH = "PW_LENGTH";
+ private static final String KEY_PASSWORD_QUALITY = "PW_QUALITY";
+ private static final String KEY_PASSWORD_MIN_UPPERCASE = "PW_MIN_UPPERCASE";
+
+ // Password quality values. This list must match the list
+ // found in res/values/arrays.xml
+ final static int[] PASSWORD_QUALITY_VALUES = new int[] {
+ DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED,
+ DevicePolicyManager.PASSWORD_QUALITY_SOMETHING,
+ DevicePolicyManager.PASSWORD_QUALITY_NUMERIC,
+ DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC,
+ DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC,
+ DevicePolicyManager.PASSWORD_QUALITY_COMPLEX
+ };
+
+ private int mPasswordQuality;
+ private int mPasswordLength;
+ private int mPasswordMinUpperCase;
+ private Context mContext;
+ private DevicePolicyManager mDPM;
+ private ComponentName mPolicyAdmin;
+
+ public Policy(Context context) {
+ mContext = context;
+ mPasswordQuality = -1;
+ mPasswordLength = 0;
+ mPasswordMinUpperCase = 0;
+ mDPM = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
+ mPolicyAdmin = new ComponentName(context, PolicyAdmin.class);
+ }
+
+ /**
+ * Saves the policy parameters.
+ *
+ * @param passwordQuality Password quality.
+ * @param passwordLength Password minimum length.
+ * @param passwordUppercase Password minimum number of upper case alphabets.
+ */
+ public void saveToLocal(int passwordQuality, int passwordLength, int passwordMinUppercase) {
+ SharedPreferences.Editor editor =
+ mContext.getSharedPreferences(APP_PREF, Context.MODE_PRIVATE).edit();
+ if (mPasswordQuality != passwordQuality) {
+ editor.putInt(KEY_PASSWORD_QUALITY, passwordQuality);
+ mPasswordQuality = passwordQuality;
+ }
+ if (mPasswordLength != passwordLength) {
+ editor.putInt(KEY_PASSWORD_LENGTH, passwordLength);
+ mPasswordLength = passwordLength;
+ }
+ if (mPasswordMinUpperCase != passwordMinUppercase) {
+ editor.putInt(KEY_PASSWORD_MIN_UPPERCASE, passwordMinUppercase);
+ mPasswordMinUpperCase = passwordMinUppercase;
+ }
+ editor.commit();
+ }
+
+ public void readFromLocal() {
+ SharedPreferences prefs = mContext.getSharedPreferences(APP_PREF, Context.MODE_PRIVATE);
+ mPasswordQuality = prefs.getInt(KEY_PASSWORD_QUALITY, -1);
+ mPasswordLength = prefs.getInt(KEY_PASSWORD_LENGTH, -1);
+ mPasswordMinUpperCase = prefs.getInt(KEY_PASSWORD_MIN_UPPERCASE, -1);
+ }
+
+ /**
+ * Getter for password quality.
+ *
+ * @return
+ */
+ public int getPasswordQuality() { return mPasswordQuality; }
+
+ /**
+ * Getter for password length.
+ *
+ * @return
+ */
+ public int getPasswordLength() { return mPasswordLength; }
+
+ /**
+ * Getter for password minimum upper case alphabets.
+ *
+ * @return
+ */
+ public int getPasswordMinUpperCase() { return mPasswordMinUpperCase; }
+
+ /**
+ * Getter for the policy administrator ComponentName object.
+ *
+ * @return
+ */
+ public ComponentName getPolicyAdmin() { return mPolicyAdmin; }
+
+ /**
+ * Indicates whether the device administrator is currently active.
+ *
+ * @return
+ */
+ public boolean isAdminActive() {
+ return mDPM.isAdminActive(mPolicyAdmin);
+ }
+
+ public boolean isActivePasswordSufficient() {
+ return mDPM.isActivePasswordSufficient();
+ }
+
+ public boolean isDeviceSecured() {
+ return isAdminActive() && isActivePasswordSufficient();
+ }
+
+ /**
+ * Configure policy defined in the object.
+ */
+ public void configurePolicy() {
+ mDPM.setPasswordQuality(mPolicyAdmin, PASSWORD_QUALITY_VALUES[mPasswordQuality]);
+ mDPM.setPasswordMinimumLength(mPolicyAdmin, mPasswordLength);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+ mDPM.setPasswordMinimumUpperCase(mPolicyAdmin, mPasswordMinUpperCase);
+ }
+ }
+
+ /**
+ * Through the PolicyAdmin receiver, the app can use this to trap various device
+ * administration events, such as password change, incorrect password entry, etc.
+ *
+ */
+ public static class PolicyAdmin extends DeviceAdminReceiver {
+
+ @Override
+ public void onDisabled(Context context, Intent intent) {
+ // Called when the app is about to be deactivated as a device administrator.
+ // Deletes previously stored password policy.
+ super.onDisabled(context, intent);
+ SharedPreferences prefs = context.getSharedPreferences(APP_PREF, Activity.MODE_PRIVATE);
+ prefs.edit().clear().commit();
+ }
+ }
+}
+
diff --git a/samples/training/device-management-policy/src/com/example/training/deviceadmin/PolicySetupActivity.java b/samples/training/device-management-policy/src/com/example/training/deviceadmin/PolicySetupActivity.java
new file mode 100644
index 0000000..8c7381b
--- /dev/null
+++ b/samples/training/device-management-policy/src/com/example/training/deviceadmin/PolicySetupActivity.java
@@ -0,0 +1,275 @@
+/*
+ * Copyright (C) 2011 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.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.training.deviceadmin;
+
+import android.app.Activity;
+import android.app.admin.DevicePolicyManager;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.Spinner;
+import android.widget.TextView;
+
+/**
+ * Main Activity for the sample application.
+ *
+ * The Activity maintains and presents 2 different
+ * screens to the user -- a screen for configuring device administration policy and another screen
+ * for viewing configured policy. When it is detected that the screen-lock password satisfies
+ * the password strength required by the policy, the user is sent to an Activity containing
+ * protected content.
+ */
+public class PolicySetupActivity extends Activity {
+ private static final int REQ_ACTIVATE_DEVICE_ADMIN = 10;
+ private static final String SCREEN_ID_KEY = "LAYOUT_ID";
+
+ private static final String APP_PREF = "APP_PREF";
+ private static final int UNKNOWN_SCREEN_ID = -1;
+
+ // UI controls in policy setup screen.
+ private Spinner mPasswordQualityInputField;
+ private EditText mPasswordLengthInputField;
+ private EditText mPasswordMinUppercaseInputField;
+
+ private Policy mPolicy;
+ private int mCurrentScreenId;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mPolicy = new Policy(this);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ SharedPreferences prefs = getSharedPreferences(APP_PREF, MODE_PRIVATE);
+ final int savedScreenId = prefs.getInt(SCREEN_ID_KEY, UNKNOWN_SCREEN_ID);
+ if (savedScreenId == UNKNOWN_SCREEN_ID || !mPolicy.isAdminActive()) {
+ setScreenContent(R.layout.activity_policy_setup);
+ } else {
+ setScreenContent(savedScreenId);
+ }
+ }
+
+ private void setScreenContent(final int screenId) {
+ mCurrentScreenId = screenId;
+ setContentView(mCurrentScreenId);
+ getSharedPreferences(APP_PREF, MODE_PRIVATE).edit().putInt(
+ SCREEN_ID_KEY, mCurrentScreenId).commit();
+ switch (mCurrentScreenId) {
+ case R.layout.activity_policy_setup:
+ initPolicySetupScreen();
+ initNavigation();
+ break;
+ case R.layout.activity_view_policy:
+ initViewPolicyScreen();
+ initNavigation();
+ break;
+ }
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ if (mCurrentScreenId == R.layout.activity_policy_setup) writePolicy();
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQ_ACTIVATE_DEVICE_ADMIN && resultCode == RESULT_OK) {
+ // User just activated the application as a device administrator.
+ setScreenContent(mCurrentScreenId);
+ } else {
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+ }
+
+ @Override
+ public void onBackPressed() {
+ if (mCurrentScreenId == R.layout.activity_view_policy) {
+ setScreenContent(R.layout.activity_policy_setup);
+ return;
+ }
+ super.onBackPressed();
+ }
+
+ // Initialize policy set up screen.
+ private void initPolicySetupScreen() {
+ mPasswordQualityInputField = (Spinner) findViewById(R.id.policy_password_quality);
+ mPasswordLengthInputField = (EditText) findViewById(R.id.policy_password_length);
+ mPasswordMinUppercaseInputField = (EditText) findViewById(R.id.policy_password_uppercase);
+ ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
+ R.array.password_types, android.R.layout.simple_spinner_item);
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ mPasswordQualityInputField.setAdapter(adapter);
+ mPasswordQualityInputField.setOnItemSelectedListener(
+ new AdapterView.OnItemSelectedListener() {
+ public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
+ LinearLayout passwordMinUppercaseView =
+ (LinearLayout) findViewById(R.id.password_uppercase_view);
+ // The minimum number of upper case field is only applicable for password
+ // qualities: alpha, alphanumeric, or complex.
+ if (pos > 2)
+ passwordMinUppercaseView.setVisibility(View.VISIBLE);
+ else
+ passwordMinUppercaseView.setVisibility(View.GONE);
+ }
+
+ public void onNothingSelected(AdapterView<?> parent) {}
+ });
+
+ // Read previously saved policy and populate on the UI.
+ mPolicy.readFromLocal();
+ mPasswordQualityInputField.setSelection(mPolicy.getPasswordQuality());
+ if (mPolicy.getPasswordLength() > 0) {
+ mPasswordLengthInputField.setText(String.valueOf(mPolicy.getPasswordLength()));
+ } else {
+ mPasswordLengthInputField.setText("");
+ }
+
+ if (mPolicy.getPasswordMinUpperCase() > 0) {
+ mPasswordMinUppercaseInputField.setText(
+ String.valueOf(mPolicy.getPasswordMinUpperCase()));
+ } else {
+ mPasswordMinUppercaseInputField.setText("");
+ }
+ }
+
+ // Initialize policy viewing screen.
+ private void initViewPolicyScreen() {
+ TextView passwordQualityView = (TextView) findViewById(R.id.policy_password_quality);
+ TextView passwordLengthView = (TextView) findViewById(R.id.policy_password_length);
+
+ // Read previously saved policy and populate on the UI.
+ mPolicy.readFromLocal();
+ int passwordQualitySelection = mPolicy.getPasswordQuality();
+ passwordQualityView.setText(
+ getResources().getStringArray(R.array.password_types)[passwordQualitySelection]);
+ passwordLengthView.setText(String.valueOf(mPolicy.getPasswordLength()));
+ if (passwordQualitySelection > 2) {
+ LinearLayout passwordMinUppercaseView =
+ (LinearLayout) findViewById(R.id.password_uppercase_view);
+ passwordMinUppercaseView.setVisibility(View.VISIBLE);
+ ((TextView) findViewById(R.id.policy_password_uppercase)).setText(
+ String.valueOf(mPolicy.getPasswordMinUpperCase()));
+ }
+ }
+
+ // Set up navigation message and action button.
+ private void initNavigation() {
+ if (!mPolicy.isAdminActive()) {
+ // Activates device administrator.
+ setupNavigation(R.string.setup_message_activate,
+ R.string.setup_action_activate,
+ mActivateButtonListener);
+ } else if (mCurrentScreenId == R.layout.activity_policy_setup) {
+ setupNavigation(R.string.setup_message_set_policy,
+ R.string.setup_action_set_policy,
+ new View.OnClickListener() {
+ public void onClick(View view) {
+ writePolicy();
+ mPolicy.configurePolicy();
+ setScreenContent(R.layout.activity_view_policy);
+ }
+ });
+ }
+ else if (!mPolicy.isActivePasswordSufficient()) {
+ // Launches password set-up screen in Settings.
+ setupNavigation(R.string.setup_message_enforce_policy,
+ R.string.setup_action_enforce_policy,
+ mEnforcePolicyListener);
+ } else {
+ // Grants access to secure content.
+ setupNavigation(R.string.setup_message_go_secured,
+ R.string.setup_action_go_secured,
+ new View.OnClickListener() {
+ public void onClick(View view) {
+ startActivity(new Intent(view.getContext(), SecureActivity.class));
+ }
+ });
+ }
+ }
+
+ private View.OnClickListener mActivateButtonListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ // First, persist the policy. Then, launch intent to trigger the system screen
+ // requesting user to confirm the activation of the device administrator.
+ writePolicy();
+ Intent activateDeviceAdminIntent =
+ new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
+ activateDeviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
+ mPolicy.getPolicyAdmin());
+ // It is good practice to include the optional explanation text to explain to
+ // user why the application is requesting to be a device administrator. The system
+ // will display this message on the activation screen.
+ activateDeviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
+ getResources().getString(R.string.device_admin_activation_message));
+ startActivityForResult(activateDeviceAdminIntent, REQ_ACTIVATE_DEVICE_ADMIN);
+ }
+ };
+
+ private View.OnClickListener mEnforcePolicyListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ writePolicy();
+ // The device administration API does not "fix" the password if it is
+ // determined that the current password does not conform to what is requested
+ // by the policy. The caller is responsible for triggering the password set up
+ // screen via the below intent.
+ Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
+ startActivity(intent);
+ }
+ };
+
+ // Setup action button text and listener.
+ private void setupNavigation(int messageResId, int buttonTextResId,
+ View.OnClickListener listener) {
+ TextView setupMessage = (TextView) findViewById(R.id.setup_message);
+ setupMessage.setText(messageResId);
+ Button actionBtn = (Button) findViewById(R.id.setup_action_btn);
+ actionBtn.setText(buttonTextResId);
+ actionBtn.setOnClickListener(listener);
+ }
+
+ // Save policy to shared preferences.
+ private void writePolicy() {
+ int passwordQuality = (int) mPasswordQualityInputField.getSelectedItemId();
+
+ int passwordLength = 0;
+ try {
+ passwordLength = Integer.valueOf(mPasswordLengthInputField.getText().toString());
+ } catch (NumberFormatException nfe) {} // Defaults to 0.
+
+ int passwordMinUppercase = 0;
+ try {
+ passwordMinUppercase =
+ Integer.valueOf(mPasswordMinUppercaseInputField.getText().toString());
+ } catch (NumberFormatException nfe) {} // Defaults to 0.
+
+ mPolicy.saveToLocal(passwordQuality, passwordLength, passwordMinUppercase);
+ }
+}
+
diff --git a/samples/training/device-management-policy/src/com/example/training/deviceadmin/SecureActivity.java b/samples/training/device-management-policy/src/com/example/training/deviceadmin/SecureActivity.java
new file mode 100644
index 0000000..d2ae34c
--- /dev/null
+++ b/samples/training/device-management-policy/src/com/example/training/deviceadmin/SecureActivity.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2011 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.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.training.deviceadmin;
+
+import android.app.Activity;
+import android.content.Intent;
+
+public class SecureActivity extends Activity {
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ // Check to see if the device is properly secured as per the policy. Send user
+ // back to policy set up screen if necessary.
+ Policy policy = new Policy(this);
+ policy.readFromLocal();
+ if (!policy.isDeviceSecured()) {
+ Intent intent = new Intent();
+ intent.setClass(this, PolicySetupActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP |
+ Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ startActivity(intent);
+ finish();
+ }
+ setContentView(R.layout.activity_secure);
+ }
+}
+
diff --git a/tools/emulator/skins/WXGA720/layout b/tools/emulator/skins/WXGA720/layout
index 8332bdc..47cddd6 100755
--- a/tools/emulator/skins/WXGA720/layout
+++ b/tools/emulator/skins/WXGA720/layout
@@ -12,8 +12,8 @@
device {
display {
- width 1280
- height 720
+ width 720
+ height 1280
x 0
y 0
}
@@ -23,11 +23,38 @@
layouts {
+ portrait {
+ width 773
+ height 1334
+ color 0xe0e0e0
+ event EV_SW:0:1
+
+ part1 {
+ name portrait
+ x 0
+ y 0
+ }
+
+ part2 {
+ name landscape
+ x 1400
+ y 0
+ }
+
+ part3 {
+ name device
+ x 27
+ y 27
+ }
+ }
+
landscape {
width 1333
height 775
color 0xe0e0e0
- event EV_SW:0:1
+ event EV_SW:0:0
+
+ dpad-rotation 3
part1 {
name portrait
@@ -44,34 +71,7 @@
part3 {
name device
x 26
- y 29
- }
- }
-
- portrait {
- width 773
- height 1334
- color 0xe0e0e0
- event EV_SW:0:0
-
- dpad-rotation 3
-
- part1 {
- name portrait
- x 0
- y 0
- }
-
- part2 {
- name landscape
- x 1400
- y 0
- }
-
- part3 {
- name device
- x 27
- y 1307
+ y 749
rotation 3
}
}