Add switch demo

Added default on state and a listener triggering a toast.

Change-Id: I79a89801d878b08fee55919e92044cd71f47108c
diff --git a/samples/ApiDemos/AndroidManifest.xml b/samples/ApiDemos/AndroidManifest.xml
index a26bb88..39293e1 100644
--- a/samples/ApiDemos/AndroidManifest.xml
+++ b/samples/ApiDemos/AndroidManifest.xml
@@ -2102,6 +2102,13 @@
             </intent-filter>
         </activity>
 
+        <activity android:name=".view.Switches" android:label="Views/Switches">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.SAMPLE_CODE" />
+            </intent-filter>
+        </activity>
+
         <!-- ************************************* -->
         <!--           GRAPHICS SAMPLES            -->
         <!-- ************************************* -->
diff --git a/samples/ApiDemos/res/layout/switches.xml b/samples/ApiDemos/res/layout/switches.xml
new file mode 100644
index 0000000..9add5b6
--- /dev/null
+++ b/samples/ApiDemos/res/layout/switches.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+     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.
+  -->
+<ScrollView 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">
+
+        <Switch android:text="Standard switch"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginBottom="32dip" />
+
+        <Switch android:text="Default is on"
+                android:checked="true"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginBottom="32dip" />
+
+        <Switch android:id="@+id/monitored_switch"
+                android:text="Monitored switch"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginBottom="32dip" />
+
+        <Switch android:text="Customized text"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textOn="YES"
+                android:textOff="NO"
+                android:layout_marginBottom="32dip" />
+
+        <Switch android:text="This is an example of a switch with a lot of text in it. It may end up wrapping to another line. The switch will be pinned at the top."
+                android:singleLine="false"
+                android:layout_width="300dip"
+                android:layout_height="wrap_content"
+                android:gravity="top|left"
+                android:layout_marginBottom="32dip" />
+
+        <Switch android:text="This is an example of a switch with a lot of text in it. It may end up wrapping to another line. The switch will be vertically centered."
+                android:singleLine="false"
+                android:layout_width="300dip"
+                android:layout_height="wrap_content"
+                android:gravity="center_vertical|left"
+                android:layout_marginBottom="32dip" />
+
+        <Switch android:text="This is an example of a switch with a lot of text in it. It may end up wrapping to another line. The switch will be pinned at the bottom."
+                android:singleLine="false"
+                android:layout_width="300dip"
+                android:layout_height="wrap_content"
+                android:gravity="bottom|left"
+                android:layout_marginBottom="32dip" />
+
+        <Switch android:text="Switch with match_parent width"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginBottom="32dip" />
+
+        <TextView android:text="Standalone switch below:"
+                  android:layout_width="wrap_content"
+                  android:layout_height="wrap_content" />
+
+        <Switch android:layout_width="wrap_content"
+                android:layout_height="wrap_content" />
+
+    </LinearLayout>
+</ScrollView>
diff --git a/samples/ApiDemos/src/com/example/android/apis/view/Switches.java b/samples/ApiDemos/src/com/example/android/apis/view/Switches.java
new file mode 100644
index 0000000..0f4f48c
--- /dev/null
+++ b/samples/ApiDemos/src/com/example/android/apis/view/Switches.java
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ * 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.android.apis.view;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.widget.CompoundButton;
+import android.widget.Switch;
+import android.widget.Toast;
+
+import com.example.android.apis.R;
+
+/**
+ * Demonstrates the use of the toggle switch widget.
+ */
+public class Switches extends Activity implements CompoundButton.OnCheckedChangeListener {
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        
+        setContentView(R.layout.switches);
+        
+        Switch s = (Switch) findViewById(R.id.monitored_switch);
+        if (s != null) {
+            s.setOnCheckedChangeListener(this);
+        }
+    }
+
+    @Override
+    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+       Toast.makeText(this, "Monitored switch is " + (isChecked ? "on" : "off"),
+               Toast.LENGTH_SHORT).show();
+    }
+}