Update Full Screen Modes to demostrate more modes.

UI is now a set of check boxes to toggle the various modes.

Also add new API demos for two typical implementations using
system UI flags: a content browser and a video player.

Change-Id: If93659343cfc42b903b18997a5a0a04ee10e8343
diff --git a/samples/ApiDemos/AndroidManifest.xml b/samples/ApiDemos/AndroidManifest.xml
index 6a96c7e..4b31885 100644
--- a/samples/ApiDemos/AndroidManifest.xml
+++ b/samples/ApiDemos/AndroidManifest.xml
@@ -2204,7 +2204,29 @@
             </intent-filter>
         </activity>
 
-        <activity android:name=".view.OverscanActivity" android:label="Views/Full Screen Modes">
+        <activity android:name=".view.OverscanActivity"
+                android:label="Views/System UI Visibility/System UI Modes"
+                android:uiOptions="splitActionBarWhenNarrow">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.SAMPLE_CODE" />
+            </intent-filter>
+        </activity>
+
+        <activity android:name=".view.ContentBrowserActivity"
+                android:label="Views/System UI Visibility/Content Browser"
+                android:theme="@android:style/Theme.Holo.Light"
+                android:uiOptions="splitActionBarWhenNarrow">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.SAMPLE_CODE" />
+            </intent-filter>
+        </activity>
+
+        <activity android:name=".view.VideoPlayerActivity"
+                android:label="Views/System UI Visibility/Video Player"
+                android:theme="@android:style/Theme.Holo.Light"
+                android:uiOptions="splitActionBarWhenNarrow">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.SAMPLE_CODE" />
diff --git a/samples/ApiDemos/res/drawable-nodpi/frantic.jpg b/samples/ApiDemos/res/drawable-nodpi/frantic.jpg
index 7038ef3..4c62333 100644
--- a/samples/ApiDemos/res/drawable-nodpi/frantic.jpg
+++ b/samples/ApiDemos/res/drawable-nodpi/frantic.jpg
Binary files differ
diff --git a/samples/ApiDemos/res/layout/content_browser.xml b/samples/ApiDemos/res/layout/content_browser.xml
new file mode 100644
index 0000000..1e1ba37
--- /dev/null
+++ b/samples/ApiDemos/res/layout/content_browser.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent" android:layout_height="match_parent"
+    >
+    <view class="com.example.android.apis.view.ContentBrowserActivity$Content"
+        android:id="@+id/content"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        />
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:fitsSystemWindows="true"
+        >
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_gravity="top|center_horizontal"
+            android:textColor="#ff000000"
+            android:background="#ffa0a0a0"
+            android:textSize="16dp"
+            android:textStyle="bold"
+            android:gravity="center"
+            android:text="You Could Put Controls Here"
+            />
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_gravity="bottom|center_horizontal"
+            android:textColor="#ff000000"
+            android:background="#ffa0a0a0"
+            android:textSize="16dp"
+            android:textStyle="bold"
+            android:gravity="center"
+            android:text="Or Put Them Here, Too"
+            />
+    </FrameLayout>
+</FrameLayout>
diff --git a/samples/ApiDemos/res/layout/overscan.xml b/samples/ApiDemos/res/layout/overscan.xml
index 3112e18..a0329b0 100644
--- a/samples/ApiDemos/res/layout/overscan.xml
+++ b/samples/ApiDemos/res/layout/overscan.xml
@@ -33,47 +33,119 @@
         android:layout_gravity="bottom|center"
         android:background="#60000000"
         android:padding="8dp"
-        android:orientation="horizontal"
+        android:orientation="vertical"
         >
         <LinearLayout
-            android:layout_width="wrap_content"
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:orientation="vertical"
+            android:orientation="horizontal"
+            android:baselineAligned="true"
             >
             <TextView
-                android:id="@+id/text1"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
+                android:layout_weight="1"
                 android:textColor="#FFFFFFFF"
                 android:textSize="16dp"
                 android:textStyle="bold"
                 android:gravity="left"
+                android:text="Mode:"
                 />
-            <TextView
-                android:id="@+id/text2"
+            <LinearLayout
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
+                android:orientation="vertical"
+                android:baselineAlignedChildIndex="0"
+                >
+                <CheckBox
+                    android:id="@+id/modeLowProfile"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:textColor="#FFFFFFFF"
+                    android:textSize="16dp"
+                    android:textStyle="bold"
+                    android:text="LOW_PROFILE"
+                    />
+                <CheckBox
+                    android:id="@+id/modeFullscreen"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:textColor="#FFFFFFFF"
+                    android:textSize="16dp"
+                    android:textStyle="bold"
+                    android:text="FULLSCREEN"
+                    />
+                <CheckBox
+                    android:id="@+id/modeHideNavigation"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:textColor="#FFFFFFFF"
+                    android:textSize="16dp"
+                    android:textStyle="bold"
+                    android:text="HIDE_NAVIGATION"
+                    />
+            </LinearLayout>
+        </LinearLayout>
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="5dp"
+            android:orientation="horizontal"
+            android:baselineAligned="true"
+            >
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
                 android:textColor="#FFFFFFFF"
-                android:textSize="11dp"
+                android:textSize="16dp"
                 android:textStyle="bold"
                 android:gravity="left"
+                android:text="Layout:"
                 />
+            <LinearLayout
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:orientation="vertical"
+                android:baselineAlignedChildIndex="0"
+                >
+                <CheckBox
+                    android:id="@+id/layoutStable"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:textColor="#FFFFFFFF"
+                    android:textSize="16dp"
+                    android:textStyle="bold"
+                    android:text="STABLE"
+                    />
+                <CheckBox
+                    android:id="@+id/layoutFullscreen"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:textColor="#FFFFFFFF"
+                    android:textSize="16dp"
+                    android:textStyle="bold"
+                    android:text="FULLSCREEN"
+                    />
+                <CheckBox
+                    android:id="@+id/layoutHideNavigation"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:textColor="#FFFFFFFF"
+                    android:textSize="16dp"
+                    android:textStyle="bold"
+                    android:text="HIDE_NAVIGATION"
+                    />
+            </LinearLayout>
         </LinearLayout>
         <TextView
-            android:id="@+id/switchy"
-            android:background="#C0000000"
-            android:layout_width="wrap_content"
+            android:id="@+id/metricsText"
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_gravity="bottom"
-            android:layout_marginTop="4dp"
-            android:padding="10dp"
             android:textColor="#FFFFFFFF"
             android:textSize="11dp"
             android:textStyle="bold"
-            android:clickable="true"
-            android:onClick="clicked"
-            android:text="Switch"
+            android:gravity="center"
             />
     </LinearLayout>
 </FrameLayout>
diff --git a/samples/ApiDemos/res/layout/video_player.xml b/samples/ApiDemos/res/layout/video_player.xml
new file mode 100644
index 0000000..fb9479c
--- /dev/null
+++ b/samples/ApiDemos/res/layout/video_player.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent" android:layout_height="match_parent"
+    >
+    <view class="com.example.android.apis.view.VideoPlayerActivity$Content"
+        android:id="@+id/image"
+        android:src="@drawable/frantic"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:scaleType="center"
+        />
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:fitsSystemWindows="true"
+        >
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_gravity="top|center_horizontal"
+            android:textColor="#ff000000"
+            android:background="#ffa0a0a0"
+            android:textSize="16dp"
+            android:textStyle="bold"
+            android:gravity="center"
+            android:text="You Could Put Controls Here"
+            />
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_gravity="bottom|center_horizontal"
+            android:textColor="#ff000000"
+            android:background="#ffa0a0a0"
+            android:textSize="16dp"
+            android:textStyle="bold"
+            android:gravity="center"
+            android:text="Or Put Them Here, Too"
+            />
+    </FrameLayout>
+</FrameLayout>
diff --git a/samples/ApiDemos/res/menu/content_actions.xml b/samples/ApiDemos/res/menu/content_actions.xml
new file mode 100644
index 0000000..84d783f
--- /dev/null
+++ b/samples/ApiDemos/res/menu/content_actions.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:id="@+id/action_search"
+          android:icon="@android:drawable/ic_menu_search"
+          android:title="@string/action_bar_search"
+          android:showAsAction="always"
+          android:actionViewClass="android.widget.SearchView" />
+    <item android:id="@+id/menu_item_share_action_provider_action_bar"
+          android:showAsAction="always"
+          android:title="@string/action_bar_share_with"
+          android:actionProviderClass="android.widget.ShareActionProvider" />
+    <group android:id="@+id/show_tabs_group"
+            android:checkableBehavior="single">
+        <item android:id="@+id/show_tabs"
+                android:title="Show Tabs"
+                android:showAsAction="never" />
+        <item android:id="@+id/hide_tabs"
+                android:title="Hide Tabs"
+                android:checked="true"
+                android:showAsAction="never" />
+    </group>
+    <group android:id="@+id/stable_layout_group"
+            android:checkableBehavior="all">
+        <item android:id="@+id/stable_layout"
+                android:title="Stable Layout"
+                android:checked="true"
+                android:showAsAction="never" />
+    </group>
+    <item android:id="@+id/action_share"
+          android:icon="@android:drawable/ic_menu_share"
+          android:title="@string/action_bar_share"
+          android:showAsAction="ifRoom" />
+    <item android:id="@+id/action_sort"
+          android:icon="@android:drawable/ic_menu_sort_by_size"
+          android:title="@string/action_bar_sort"
+          android:showAsAction="ifRoom">
+        <menu>
+            <item android:id="@+id/action_sort_size"
+                  android:icon="@android:drawable/ic_menu_sort_by_size"
+                  android:title="@string/action_bar_sort_size"
+                  android:onClick="onSort" />
+            <item android:id="@+id/action_sort_alpha"
+                  android:icon="@android:drawable/ic_menu_sort_alphabetically"
+                  android:title="@string/action_bar_sort_alpha"
+                  android:onClick="onSort" />
+        </menu>
+    </item>
+</menu>
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/MenuInflateFromXml.java b/samples/ApiDemos/src/com/example/android/apis/app/MenuInflateFromXml.java
index fc7b62a..877714f 100644
--- a/samples/ApiDemos/src/com/example/android/apis/app/MenuInflateFromXml.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/MenuInflateFromXml.java
@@ -23,6 +23,8 @@
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
+import android.view.View;
+import android.widget.AdapterView;
 import android.widget.ArrayAdapter;
 import android.widget.LinearLayout;
 import android.widget.Spinner;
@@ -86,6 +88,15 @@
         // so it will automatically save its instance state
         mSpinner.setId(R.id.spinner);
         mSpinner.setAdapter(adapter);
+        mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+            @Override
+            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+                invalidateOptionsMenu();
+            }
+            @Override
+            public void onNothingSelected(AdapterView<?> parent) {
+            }
+        });
         
         // Add the spinner
         layout.addView(mSpinner,
@@ -118,10 +129,6 @@
         MenuInflater inflater = getMenuInflater();
         inflater.inflate(sMenuExampleResources[mSpinner.getSelectedItemPosition()], menu);
         
-        // Disable the spinner since we've already created the menu and the user
-        // can no longer pick a different menu XML.
-        mSpinner.setEnabled(false);
-        
         // Change instructions
         mInstructionsText.setText(getResources().getString(
                 R.string.menu_from_xml_instructions_go_back));
@@ -136,6 +143,7 @@
             //                   the XML
             case R.id.jump:
                 Toast.makeText(this, "Jump up in the air!", Toast.LENGTH_SHORT).show();
+                invalidateOptionsMenu();
                 return true;
 
             case R.id.dive:
diff --git a/samples/ApiDemos/src/com/example/android/apis/view/ContentBrowserActivity.java b/samples/ApiDemos/src/com/example/android/apis/view/ContentBrowserActivity.java
new file mode 100644
index 0000000..af802a6
--- /dev/null
+++ b/samples/ApiDemos/src/com/example/android/apis/view/ContentBrowserActivity.java
@@ -0,0 +1,247 @@
+/*
+ * 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.android.apis.view;
+
+import android.app.ActionBar;
+import android.app.ActionBar.Tab;
+import android.app.Activity;
+import android.app.FragmentTransaction;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Handler;
+import android.util.AttributeSet;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.widget.ScrollView;
+import android.widget.SearchView;
+import android.widget.ShareActionProvider;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.widget.SearchView.OnQueryTextListener;
+
+import com.example.android.apis.R;
+
+/**
+ * This activity demonstrates how to use system UI flags to implement
+ * a content browser style of UI (such as a book reader).
+ */
+public class ContentBrowserActivity extends Activity
+        implements OnQueryTextListener, ActionBar.TabListener {
+
+    /**
+     * Implementation of a view for displaying immersive content, using system UI
+     * flags to transition in and out of modes where the user is focused on that
+     * content.
+     */
+//BEGIN_INCLUDE(content)
+    public static class Content extends ScrollView
+            implements View.OnSystemUiVisibilityChangeListener, View.OnClickListener {
+        TextView mText;
+        boolean mNavVisible;
+        int mBaseSystemUiVisibility = SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+                | SYSTEM_UI_FLAG_LAYOUT_STABLE;
+        int mLastSystemUiVis;
+
+        Runnable mNavHider = new Runnable() {
+            @Override public void run() {
+                setNavVisibility(false);
+            }
+        };
+
+        public Content(Context context, AttributeSet attrs) {
+            super(context, attrs);
+    
+            mText = new TextView(context);
+            mText.setText(context.getString(R.string.alert_dialog_two_buttons2ultra_msg));
+            mText.setClickable(false);
+            mText.setLongClickable(false);
+            mText.setOnClickListener(this);
+            addView(mText, new ViewGroup.LayoutParams(
+                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
+
+            setOnSystemUiVisibilityChangeListener(this);
+            setNavVisibility(true);
+        }
+
+        @Override public void onSystemUiVisibilityChange(int visibility) {
+            // Detect when we go out of low-profile mode, to also go out
+            // of full screen.  We only do this when the low profile mode
+            // is changing from its last state, and turning off.
+            int diff = mLastSystemUiVis ^ visibility;
+            mLastSystemUiVis = visibility;
+            if ((diff&SYSTEM_UI_FLAG_LOW_PROFILE) != 0
+                    && (visibility&SYSTEM_UI_FLAG_LOW_PROFILE) == 0) {
+                setNavVisibility(true);
+            }
+        }
+
+        @Override protected void onWindowVisibilityChanged(int visibility) {
+            super.onWindowVisibilityChanged(visibility);
+
+            // When we become visible, we show our navigation elements briefly
+            // before hiding them.
+            setNavVisibility(true);
+            getHandler().postDelayed(mNavHider, 2000);
+        }
+
+        @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) {
+            super.onScrollChanged(l, t, oldl, oldt);
+
+            // When the user scrolls, we hide navigation elements.
+            setNavVisibility(false);
+        }
+
+        @Override public void onClick(View v) {
+            // When the user clicks, we toggle the visibility of navigation elements.
+            int curVis = getSystemUiVisibility();
+            setNavVisibility((curVis&SYSTEM_UI_FLAG_LOW_PROFILE) != 0);
+        }
+
+        void setBaseSystemUiVisibility(int visibility) {
+            mBaseSystemUiVisibility = visibility;
+        }
+
+        void setNavVisibility(boolean visible) {
+            int newVis = mBaseSystemUiVisibility;
+            if (!visible) {
+                newVis |= SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_FULLSCREEN;
+            }
+            final boolean changed = newVis == getSystemUiVisibility();
+
+            // Unschedule any pending event to hide navigation if we are
+            // changing the visibility, or making the UI visible.
+            if (changed || visible) {
+                Handler h = getHandler();
+                if (h != null) {
+                    h.removeCallbacks(mNavHider);
+                }
+            }
+
+            // Set the new desired visibility.
+            setSystemUiVisibility(newVis);
+        }
+    }
+//END_INCLUDE(content)
+
+    Content mContent;
+
+    public ContentBrowserActivity() {
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
+
+        setContentView(R.layout.content_browser);
+        mContent = (Content)findViewById(R.id.content);
+
+        ActionBar bar = getActionBar();
+        bar.addTab(bar.newTab().setText("Tab 1").setTabListener(this));
+        bar.addTab(bar.newTab().setText("Tab 2").setTabListener(this));
+        bar.addTab(bar.newTab().setText("Tab 3").setTabListener(this));
+    }
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        MenuInflater inflater = getMenuInflater();
+        inflater.inflate(R.menu.content_actions, menu);
+        SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
+        searchView.setOnQueryTextListener(this);
+
+        // Set file with share history to the provider and set the share intent.
+        MenuItem actionItem = menu.findItem(R.id.menu_item_share_action_provider_action_bar);
+        ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
+        actionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
+        // Note that you can set/change the intent any time,
+        // say when the user has selected an image.
+        Intent shareIntent = new Intent(Intent.ACTION_SEND);
+        shareIntent.setType("image/*");
+        Uri uri = Uri.fromFile(getFileStreamPath("shared.png"));
+        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
+        actionProvider.setShareIntent(shareIntent);
+        return true;
+    }
+
+    @Override
+    public void onAttachedToWindow() {
+        super.onAttachedToWindow();
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+    }
+
+    /**
+     * This method is declared in the menu.
+     */
+    public void onSort(MenuItem item) {
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        switch (item.getItemId()) {
+            case R.id.show_tabs:
+                getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
+                item.setChecked(true);
+                return true;
+            case R.id.hide_tabs:
+                getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
+                item.setChecked(true);
+                return true;
+            case R.id.stable_layout:
+                item.setChecked(!item.isChecked());
+                mContent.setBaseSystemUiVisibility(item.isChecked()
+                        ? View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+                                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+                        : View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
+                return true;
+        }
+        return false;
+    }
+
+    @Override
+    public boolean onQueryTextChange(String newText) {
+        return true;
+    }
+
+    @Override
+    public boolean onQueryTextSubmit(String query) {
+        Toast.makeText(this, "Searching for: " + query + "...", Toast.LENGTH_SHORT).show();
+        return true;
+    }
+
+    @Override
+    public void onTabSelected(Tab tab, FragmentTransaction ft) {
+    }
+
+    @Override
+    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
+    }
+
+    @Override
+    public void onTabReselected(Tab tab, FragmentTransaction ft) {
+    }
+}
diff --git a/samples/ApiDemos/src/com/example/android/apis/view/OverscanActivity.java b/samples/ApiDemos/src/com/example/android/apis/view/OverscanActivity.java
index 464b601..7b149a0 100644
--- a/samples/ApiDemos/src/com/example/android/apis/view/OverscanActivity.java
+++ b/samples/ApiDemos/src/com/example/android/apis/view/OverscanActivity.java
@@ -16,20 +16,32 @@
 
 package com.example.android.apis.view;
 
+import android.app.ActionBar;
 import android.app.Activity;
+import android.app.FragmentTransaction;
+import android.app.ActionBar.Tab;
 import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
 import android.os.Bundle;
 import android.util.AttributeSet;
 import android.util.DisplayMetrics;
 import android.view.KeyEvent;
 import android.view.Menu;
+import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.Window;
 import android.view.WindowManager;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
 import android.widget.ImageView;
+import android.widget.SearchView;
+import android.widget.ShareActionProvider;
 import android.widget.TextView;
+import android.widget.Toast;
+import android.widget.SearchView.OnQueryTextListener;
 
 import com.example.android.apis.R;
 
@@ -38,8 +50,9 @@
  * the system decor, in order to better focus the user's attention or use available screen real
  * estate on the task at hand.
  */
-public class OverscanActivity extends Activity {
-    public static class IV extends ImageView {
+public class OverscanActivity extends Activity
+        implements OnQueryTextListener, ActionBar.TabListener {
+    public static class IV extends ImageView implements View.OnSystemUiVisibilityChangeListener {
         private OverscanActivity mActivity;
         public IV(Context context) {
             super(context);
@@ -48,64 +61,16 @@
             super(context, attrs);
         }
         public void setActivity(OverscanActivity act) {
+            setOnSystemUiVisibilityChangeListener(this);
             mActivity = act;
         }
+        @Override
         public void onSizeChanged(int w, int h, int oldw, int oldh) {
             mActivity.refreshSizes();
         }
-        public void onSystemUiVisibilityChanged(int visibility) {
-            mActivity.getState().onSystemUiVisibilityChanged(visibility);
-        }
-    }
-
-    private interface State {
-        void apply();
-        State next();
-        void onSystemUiVisibilityChanged(int visibility);
-    }
-    private class NormalState implements State {
-        public void apply() {
-            display("Normal");
-            setFullscreen(false);
-            mImage.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
-        }
-        public State next() {
-            return new FullscreenState();
-        }
-        public void onSystemUiVisibilityChanged(int visibility) {
-        }
-    }
-    private class FullscreenState implements State {
-        public void apply() {
-            display("FULLSCREEN");
-            setFullscreen(true);
-        }
-        public State next() {
-            return new FullscreenLightsOutState();
-        }
-        public void onSystemUiVisibilityChanged(int visibility) {
-        }
-    }
-    private class FullscreenLightsOutState implements State {
-        public void apply() {
-            display("FULLSCREEN + LOW_PROFILE");
-            mImage.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
-        }
-        public State next() {
-            return new OverscanState();
-        }
-        public void onSystemUiVisibilityChanged(int visibility) {
-        }
-    }
-    private class OverscanState implements State {
-        public void apply() {
-            display("FULLSCREEN + HIDE_NAVIGATION");
-            mImage.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
-        }
-        public State next() {
-            return new NormalState();
-        }
-        public void onSystemUiVisibilityChanged(int visibility) {
+        @Override
+        public void onSystemUiVisibilityChange(int visibility) {
+            mActivity.updateCheckControls();
         }
     }
 
@@ -131,20 +96,18 @@
                 mImage.getRight(), mImage.getBottom());
     }
     void refreshSizes() {
-        mText2.setText(getDisplaySize() + " " + getViewSize());
-    }
-    private void display(String text) {
-        mText1.setText(text);
-        refreshSizes();
-    }
-    State getState() {
-        return mState;
+        mMetricsText.setText(getDisplaySize() + " " + getViewSize());
     }
 
     static int TOAST_LENGTH = 500;
     IV mImage;
-    TextView mText1, mText2;
-    State mState;
+    CheckBox[] mCheckControls = new CheckBox[6];
+    int[] mCheckFlags = new int[] { View.SYSTEM_UI_FLAG_LOW_PROFILE,
+            View.SYSTEM_UI_FLAG_FULLSCREEN, View.SYSTEM_UI_FLAG_HIDE_NAVIGATION,
+            View.SYSTEM_UI_FLAG_LAYOUT_STABLE, View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN,
+            View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+    };
+    TextView mMetricsText;
 
     public OverscanActivity() {
     }
@@ -153,23 +116,54 @@
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
-        // we need to ask for LAYOUT_IN_SCREEN before the window decor appears
-        Window win = getWindow();
-        WindowManager.LayoutParams winParams = win.getAttributes();
-        winParams.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
-        win.setAttributes(winParams);
+        getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
 
         setContentView(R.layout.overscan);
         mImage = (IV) findViewById(R.id.image);
         mImage.setActivity(this);
-        mText1 = (TextView) findViewById(R.id.text1);
-        mText2 = (TextView) findViewById(R.id.text2);
+
+        CompoundButton.OnCheckedChangeListener checkChangeListener
+                = new CompoundButton.OnCheckedChangeListener() {
+            @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+                updateSystemUi();
+            }
+        };
+        mCheckControls[0] = (CheckBox) findViewById(R.id.modeLowProfile);
+        mCheckControls[1] = (CheckBox) findViewById(R.id.modeFullscreen);
+        mCheckControls[2] = (CheckBox) findViewById(R.id.modeHideNavigation);
+        mCheckControls[3] = (CheckBox) findViewById(R.id.layoutStable);
+        mCheckControls[4] = (CheckBox) findViewById(R.id.layoutFullscreen);
+        mCheckControls[5] = (CheckBox) findViewById(R.id.layoutHideNavigation);
+        for (int i=0; i<mCheckControls.length; i++) {
+            mCheckControls[i].setOnCheckedChangeListener(checkChangeListener);
+        }
+        mMetricsText = (TextView) findViewById(R.id.metricsText);
+    }
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        MenuInflater inflater = getMenuInflater();
+        inflater.inflate(R.menu.content_actions, menu);
+        SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
+        searchView.setOnQueryTextListener(this);
+
+        // Set file with share history to the provider and set the share intent.
+        MenuItem actionItem = menu.findItem(R.id.menu_item_share_action_provider_action_bar);
+        ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
+        actionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
+        // Note that you can set/change the intent any time,
+        // say when the user has selected an image.
+        Intent shareIntent = new Intent(Intent.ACTION_SEND);
+        shareIntent.setType("image/*");
+        Uri uri = Uri.fromFile(getFileStreamPath("shared.png"));
+        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
+        actionProvider.setShareIntent(shareIntent);
+        return true;
     }
 
     @Override
     public void onAttachedToWindow() {
-        mState = new NormalState();
-        mState.apply();
+        updateCheckControls();
     }
 
     @Override
@@ -177,8 +171,61 @@
         super.onResume();
     }
 
-    public void clicked(View v) {
-        mState = mState.next();
-        mState.apply();
+    public void onSort(MenuItem item) {
+    }
+
+    @Override
+    public boolean onQueryTextChange(String newText) {
+        return true;
+    }
+
+    @Override
+    public boolean onQueryTextSubmit(String query) {
+        Toast.makeText(this, "Searching for: " + query + "...", Toast.LENGTH_SHORT).show();
+        return true;
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        switch (item.getItemId()) {
+            case R.id.show_tabs:
+                getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
+                item.setChecked(true);
+                return true;
+            case R.id.hide_tabs:
+                getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
+                item.setChecked(true);
+                return true;
+        }
+        return false;
+    }
+
+    @Override
+    public void onTabSelected(Tab tab, FragmentTransaction ft) {
+    }
+
+    @Override
+    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
+    }
+
+    @Override
+    public void onTabReselected(Tab tab, FragmentTransaction ft) {
+    }
+
+    public void updateCheckControls() {
+        int visibility = mImage.getSystemUiVisibility();
+        for (int i=0; i<mCheckControls.length; i++) {
+            mCheckControls[i].setChecked((visibility&mCheckFlags[i]) != 0);
+        }
+    }
+
+    public void updateSystemUi() {
+        int visibility = 0;
+        for (int i=0; i<mCheckControls.length; i++) {
+            if (mCheckControls[i].isChecked()) {
+                visibility |= mCheckFlags[i];
+            }
+        }
+        mImage.setSystemUiVisibility(visibility);
     }
 }
diff --git a/samples/ApiDemos/src/com/example/android/apis/view/VideoPlayerActivity.java b/samples/ApiDemos/src/com/example/android/apis/view/VideoPlayerActivity.java
new file mode 100644
index 0000000..0263ca6
--- /dev/null
+++ b/samples/ApiDemos/src/com/example/android/apis/view/VideoPlayerActivity.java
@@ -0,0 +1,236 @@
+/*
+ * 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.android.apis.view;
+
+import android.app.ActionBar;
+import android.app.ActionBar.Tab;
+import android.app.Activity;
+import android.app.FragmentTransaction;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Handler;
+import android.util.AttributeSet;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.widget.ImageView;
+import android.widget.ScrollView;
+import android.widget.SearchView;
+import android.widget.ShareActionProvider;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.widget.SearchView.OnQueryTextListener;
+
+import com.example.android.apis.R;
+
+/**
+ * This activity demonstrates how to use system UI flags to implement
+ * a video player style of UI (where the navigation bar should be hidden
+ * when the user isn't interacting with the screen to achieve full screen
+ * video playback).
+ */
+public class VideoPlayerActivity extends Activity
+        implements OnQueryTextListener, ActionBar.TabListener {
+
+    /**
+     * Implementation of a view for displaying full-screen video playback,
+     * using system UI flags to transition in and out of modes where the entire
+     * screen can be filled with content (at the expense of no user interaction).
+     */
+//BEGIN_INCLUDE(content)
+    public static class Content extends ImageView implements
+            View.OnSystemUiVisibilityChangeListener, View.OnClickListener {
+        TextView mText;
+        boolean mNavVisible;
+        int mBaseSystemUiVisibility = SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+                | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | SYSTEM_UI_FLAG_LAYOUT_STABLE;
+        int mLastSystemUiVis;
+
+        Runnable mNavHider = new Runnable() {
+            @Override public void run() {
+                setNavVisibility(false);
+            }
+        };
+
+        public Content(Context context, AttributeSet attrs) {
+            super(context, attrs);
+            setOnSystemUiVisibilityChangeListener(this);
+            setOnClickListener(this);
+            setNavVisibility(true);
+        }
+
+        @Override public void onSystemUiVisibilityChange(int visibility) {
+            // Detect when we go out of low-profile mode, to also go out
+            // of full screen.  We only do this when the low profile mode
+            // is changing from its last state, and turning off.
+            int diff = mLastSystemUiVis ^ visibility;
+            mLastSystemUiVis = visibility;
+            if ((diff&SYSTEM_UI_FLAG_LOW_PROFILE) != 0
+                    && (visibility&SYSTEM_UI_FLAG_LOW_PROFILE) == 0) {
+                setNavVisibility(true);
+            }
+        }
+
+        @Override protected void onWindowVisibilityChanged(int visibility) {
+            super.onWindowVisibilityChanged(visibility);
+
+            // When we become visible, we show our navigation elements briefly
+            // before hiding them.
+            setNavVisibility(true);
+        }
+
+        @Override public void onClick(View v) {
+            // When the user clicks, we make the navigation visible.  In a real
+            // implementation, this would probably toggle between pause/play.
+            setNavVisibility(true);
+        }
+
+        void setBaseSystemUiVisibility(int visibility) {
+            mBaseSystemUiVisibility = visibility;
+        }
+
+        void setNavVisibility(boolean visible) {
+            int newVis = mBaseSystemUiVisibility;
+            if (!visible) {
+                newVis |= SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_FULLSCREEN
+                        | SYSTEM_UI_FLAG_HIDE_NAVIGATION;
+            }
+
+            // If we are now visible, schedule a timer for us to go invisible.
+            if (visible) {
+                Handler h = getHandler();
+                if (h != null) {
+                    h.removeCallbacks(mNavHider);
+                    h.postDelayed(mNavHider, 3000);
+                }
+            }
+
+            // Set the new desired visibility.
+            setSystemUiVisibility(newVis);
+        }
+    }
+//END_INCLUDE(content)
+
+    Content mContent;
+
+    public VideoPlayerActivity() {
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
+
+        setContentView(R.layout.video_player);
+        mContent = (Content)findViewById(R.id.content);
+
+        ActionBar bar = getActionBar();
+        bar.addTab(bar.newTab().setText("Tab 1").setTabListener(this));
+        bar.addTab(bar.newTab().setText("Tab 2").setTabListener(this));
+        bar.addTab(bar.newTab().setText("Tab 3").setTabListener(this));
+    }
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        MenuInflater inflater = getMenuInflater();
+        inflater.inflate(R.menu.content_actions, menu);
+        SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
+        searchView.setOnQueryTextListener(this);
+
+        // Set file with share history to the provider and set the share intent.
+        MenuItem actionItem = menu.findItem(R.id.menu_item_share_action_provider_action_bar);
+        ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
+        actionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
+        // Note that you can set/change the intent any time,
+        // say when the user has selected an image.
+        Intent shareIntent = new Intent(Intent.ACTION_SEND);
+        shareIntent.setType("image/*");
+        Uri uri = Uri.fromFile(getFileStreamPath("shared.png"));
+        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
+        actionProvider.setShareIntent(shareIntent);
+        return true;
+    }
+
+    @Override
+    public void onAttachedToWindow() {
+        super.onAttachedToWindow();
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+    }
+
+    /**
+     * This method is declared in the menu.
+     */
+    public void onSort(MenuItem item) {
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        switch (item.getItemId()) {
+            case R.id.show_tabs:
+                getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
+                item.setChecked(true);
+                return true;
+            case R.id.hide_tabs:
+                getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
+                item.setChecked(true);
+                return true;
+            case R.id.stable_layout:
+                item.setChecked(!item.isChecked());
+                mContent.setBaseSystemUiVisibility(item.isChecked()
+                        ? View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+                                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+                                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+                        : View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+                                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
+                return true;
+        }
+        return false;
+    }
+
+    @Override
+    public boolean onQueryTextChange(String newText) {
+        return true;
+    }
+
+    @Override
+    public boolean onQueryTextSubmit(String query) {
+        Toast.makeText(this, "Searching for: " + query + "...", Toast.LENGTH_SHORT).show();
+        return true;
+    }
+
+    @Override
+    public void onTabSelected(Tab tab, FragmentTransaction ft) {
+    }
+
+    @Override
+    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
+    }
+
+    @Override
+    public void onTabReselected(Tab tab, FragmentTransaction ft) {
+    }
+}