Updated AdvancedImmersiveMode sample to include some presets.
The presets improve how the sample shows the relevant flag combos for immersive & leanback mode.
Change-Id: Ib7d52574a56ded60ad6932cb73e7a9aab60e3dd5
diff --git a/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/README-fragmentview.txt b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/README-fragmentview.txt
new file mode 100644
index 0000000..38d903f
--- /dev/null
+++ b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/README-fragmentview.txt
@@ -0,0 +1,37 @@
+<!--
+ Copyright 2013 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.
+-->
+
+Steps to implement FragmentView template:
+-in template-params.xml.ftl:
+ -add the following line to common imports
+ <common src="activities"/>
+
+-Add a Fragment to show behavior. In your MainActivity.java class, it will reference a Fragment
+ called (yourProjectName)Fragment.java. Create that file in your project, using the "main" source
+ folder instead of "common" or "templates".
+ For instance, if your package name is com.example.foo, create the file
+ src/main/java/com/example/foo/FooFragment.java
+
+
+-Within this fragment, make sure that the onCreate method has the line
+ "setHasOptionsMenu(true);", to enable the fragment to handle menu events.
+
+-In order to override menu events, override onOptionsItemSelected.
+
+-refer to sampleSamples/fragmentViewSample for a reference implementation of a
+project built on this template.
+
+
diff --git a/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/build.gradle b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/build.gradle
index 4375218..49c4779 100644
--- a/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/build.gradle
+++ b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/build.gradle
@@ -1,6 +1,3 @@
-
-
-
buildscript {
repositories {
mavenCentral()
@@ -16,6 +13,7 @@
dependencies {
// Add the support lib that is appropriate for SDK 4
compile "com.android.support:support-v4:19.0.+"
+
}
// The sample build uses multiple directories to
@@ -39,6 +37,7 @@
}
instrumentTest.setRoot('tests')
instrumentTest.java.srcDirs = ['tests/src']
+
}
}
// BEGIN_EXCLUDE
diff --git a/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/java/com/example/android/advancedimmersivemode/AdvancedImmersiveModeFragment.java b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/java/com/example/android/advancedimmersivemode/AdvancedImmersiveModeFragment.java
index fe11ecb..6d38ce1 100644
--- a/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/java/com/example/android/advancedimmersivemode/AdvancedImmersiveModeFragment.java
+++ b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/java/com/example/android/advancedimmersivemode/AdvancedImmersiveModeFragment.java
@@ -17,9 +17,10 @@
import android.os.Bundle;
import android.support.v4.app.Fragment;
-import android.view.MenuItem;
+import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.Button;
import android.widget.CheckBox;
import com.example.android.common.logger.Log;
@@ -46,49 +47,97 @@
}
@Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
+ final View flagsView = inflater.inflate(R.layout.fragment_flags, container, false);
+ mLowProfileCheckBox = (CheckBox) flagsView.findViewById(R.id.flag_enable_lowprof);
+ mHideNavCheckbox = (CheckBox) flagsView.findViewById(R.id.flag_hide_navbar);
+ mHideStatusBarCheckBox = (CheckBox) flagsView.findViewById(R.id.flag_hide_statbar);
+ mImmersiveModeCheckBox = (CheckBox) flagsView.findViewById(R.id.flag_enable_immersive);
+ mImmersiveModeStickyCheckBox =
+ (CheckBox) flagsView.findViewById(R.id.flag_enable_immersive_sticky);
- final View decorView = getActivity().getWindow().getDecorView();
- ViewGroup parentView = (ViewGroup) getActivity().getWindow().getDecorView()
- .findViewById(R.id.sample_main_layout);
+ Button toggleFlagsButton = (Button) flagsView.findViewById(R.id.btn_changeFlags);
+ toggleFlagsButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ toggleUiFlags();
+ }
+ });
- mLowProfileCheckBox = new CheckBox(getActivity());
- mLowProfileCheckBox.setText("Enable Low Profile mode.");
- parentView.addView(mLowProfileCheckBox);
+ Button presetsImmersiveModeButton = (Button) flagsView.findViewById(R.id.btn_immersive);
+ presetsImmersiveModeButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
- mHideNavCheckbox = new CheckBox(getActivity());
- mHideNavCheckbox.setChecked(true);
- mHideNavCheckbox.setText("Hide Navigation bar");
- parentView.addView(mHideNavCheckbox);
+ // BEGIN_INCLUDE(immersive_presets)
+ // For immersive mode, the FULLSCREEN, HIDE_HAVIGATION and IMMERSIVE
+ // flags should be set (you can use IMMERSIVE_STICKY instead of IMMERSIVE
+ // as appropriate for your app). The LOW_PROFILE flag should be cleared.
- mHideStatusBarCheckBox = new CheckBox(getActivity());
- mHideStatusBarCheckBox.setChecked(true);
- mHideStatusBarCheckBox.setText("Hide Status Bar");
- parentView.addView(mHideStatusBarCheckBox);
+ // Immersive mode is primarily for situations where the user will be
+ // interacting with the screen, like games or reading books.
+ int uiOptions = flagsView.getSystemUiVisibility();
+ uiOptions &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
+ uiOptions |= View.SYSTEM_UI_FLAG_FULLSCREEN;
+ uiOptions |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
+ uiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE;
+ uiOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
+ flagsView.setSystemUiVisibility(uiOptions);
+ // END_INCLUDE(immersive_presets)
- mImmersiveModeCheckBox = new CheckBox(getActivity());
- mImmersiveModeCheckBox.setText("Enable Immersive Mode.");
- parentView.addView(mImmersiveModeCheckBox);
+ // The below code just updates the checkboxes to reflect which flags have been set.
+ mLowProfileCheckBox.setChecked(false);
+ mHideNavCheckbox.setChecked(true);
+ mHideStatusBarCheckBox.setChecked(true);
+ mImmersiveModeCheckBox.setChecked(true);
+ mImmersiveModeStickyCheckBox.setChecked(false);
+ }
+ });
- mImmersiveModeStickyCheckBox = new CheckBox(getActivity());
- mImmersiveModeStickyCheckBox.setText("Enable Immersive Mode (Sticky)");
- parentView.addView(mImmersiveModeStickyCheckBox);
- }
+ Button presetsLeanbackModeButton = (Button) flagsView.findViewById(R.id.btn_leanback);
+ presetsLeanbackModeButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ // BEGIN_INCLUDE(leanback_presets)
+ // For leanback mode, only the HIDE_NAVE and HIDE_STATUSBAR flags
+ // should be checked. In this case IMMERSIVE should *not* be set,
+ // since this mode is left as soon as the user touches the screen.
+ int uiOptions = flagsView.getSystemUiVisibility();
+ uiOptions &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
+ uiOptions |= View.SYSTEM_UI_FLAG_FULLSCREEN;
+ uiOptions |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
+ uiOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE;
+ uiOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
+ flagsView.setSystemUiVisibility(uiOptions);
+ // END_INCLUDE(leanback_presets)
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == R.id.sample_action) {
- toggleImmersiveMode();
- }
- return true;
+ // The below code just updates the checkboxes to reflect which flags have been set.
+ mLowProfileCheckBox.setChecked(false);
+ mHideNavCheckbox.setChecked(true);
+ mHideStatusBarCheckBox.setChecked(true);
+ mImmersiveModeCheckBox.setChecked(false);
+ mImmersiveModeStickyCheckBox.setChecked(false);
+ toggleUiFlags();
+ }
+ });
+
+ // Setting these flags makes the content appear under the navigation
+ // bars, so that showing/hiding the nav bars doesn't resize the content
+ // window, which can be jarring.
+ int uiOptions = flagsView.getSystemUiVisibility();
+ uiOptions |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
+ uiOptions |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
+ uiOptions |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
+ flagsView.setSystemUiVisibility(uiOptions);
+
+ return flagsView;
}
/**
* Detects and toggles immersive mode (also known as "hidey bar" mode).
*/
- public void toggleImmersiveMode() {
+ public void toggleUiFlags() {
// BEGIN_INCLUDE (get_current_ui_flags)
// The "Decor View" is the parent view of the Activity. It's also conveniently the easiest
diff --git a/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/drawable-hdpi/ic_launcher.png b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/drawable-hdpi/ic_launcher.png
index b1efaf4..b96e6a5 100644
--- a/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/drawable-hdpi/ic_launcher.png
+++ b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/drawable-mdpi/ic_launcher.png b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/drawable-mdpi/ic_launcher.png
index f5f9244..1294d5b 100644
--- a/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/drawable-mdpi/ic_launcher.png
+++ b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/drawable-xhdpi/ic_launcher.png b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/drawable-xhdpi/ic_launcher.png
index 5d07b3f..9f101ff 100644
--- a/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/drawable-xhdpi/ic_launcher.png
+++ b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/drawable-xxhdpi/ic_launcher.png b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/drawable-xxhdpi/ic_launcher.png
index 6ef21e1..7a195a1 100644
--- a/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/drawable-xxhdpi/ic_launcher.png
+++ b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/layout/fragment_flags.xml b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/layout/fragment_flags.xml
new file mode 100644
index 0000000..2c74e83
--- /dev/null
+++ b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/src/main/res/layout/fragment_flags.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical" android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <CheckBox
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/flag_enable_lowprof"
+ android:text="Enable Low Profile Mode" />
+
+ <CheckBox
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/flag_hide_navbar"
+ android:text="Hide Navigation bar" />
+
+ <CheckBox
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/flag_hide_statbar"
+ android:text="Hide Status Bar" />
+
+ <CheckBox
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/flag_enable_immersive"
+ android:text="Enable Immersive Mode" />
+
+ <CheckBox
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/flag_enable_immersive_sticky"
+ android:text="Enable Immersive Mode (Sticky)" />
+
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Do things!"
+ android:id="@+id/btn_changeFlags" />
+
+
+ <TextView
+ android:layout_marginTop="@dimen/margin_large"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Common flag presets"/>
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal" android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Immersive Mode"
+ android:id="@+id/btn_immersive" />
+
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Leanback Mode"
+ android:id="@+id/btn_leanback" />
+
+ </LinearLayout>
+
+
+
+</LinearLayout>
\ No newline at end of file
diff --git a/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/tests/src/com/example/android/advancedimmersivemode/tests/SampleTests.java b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/tests/src/com/example/android/advancedimmersivemode/tests/SampleTests.java
index c51a488..541791a 100644
--- a/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/tests/src/com/example/android/advancedimmersivemode/tests/SampleTests.java
+++ b/ui/window/AdvancedImmersiveMode/AdvancedImmersiveModeSample/tests/src/com/example/android/advancedimmersivemode/tests/SampleTests.java
@@ -74,53 +74,8 @@
mTestFragment.mImmersiveModeCheckBox.setChecked(true);
mTestFragment.mHideNavCheckbox.setChecked(true);
mTestFragment.mHideStatusBarCheckBox.setChecked(true);
- mTestFragment.toggleImmersiveMode();
+ mTestFragment.toggleUiFlags();
int newUiFlags = getActivity().getWindow().getDecorView().getSystemUiVisibility();
assertTrue("UI Flags didn't toggle.", uiFlags != newUiFlags);
}
-
- /**
- * Verify that the view's height actually changed when the toggle method is called.
- * This should result in a change in height for the DecorView.
- */
- public void testDecorHeightExpanded() {
- // Grab the initial height of the DecorWindow.
- int startingHeight = getActivity().getWindow().getDecorView().getHeight();
-
- // In order to test that this worked: Need to toggle the immersive mode on the UI thread,
- // wait a suitable amount of time (this test goes with 200 ms), then check to see if the
- // height changed.
- try {
- Runnable testRunnable = (new Runnable() {
- public void run() {
- // Toggle immersive mode
- mTestFragment.mImmersiveModeCheckBox.setChecked(true);
- mTestFragment.mHideNavCheckbox.setChecked(true);
- mTestFragment.mHideStatusBarCheckBox.setChecked(true);
- mTestFragment.toggleImmersiveMode();
- synchronized(this) {
- // Notify any thread waiting on this runnable that it can continue
- this.notify();
- }
- }
- });
- synchronized(testRunnable) {
- // Since toggling immersive mode makes changes to the view hierarchy, it needs to run
- // on the UI thread, or crashing will occur.
- mTestActivity.runOnUiThread(testRunnable);
- testRunnable.wait();
-
- }
- synchronized(this) {
- //Wait about 200ms for the change to take place
- wait(200L);
- }
- } catch (Throwable throwable) {
- fail(throwable.getMessage());
- }
-
- int expandedHeight = getActivity().getWindow().getDecorView().getHeight();
- assertTrue("Bars aren't hidden.", expandedHeight != startingHeight);
- }
-
}
\ No newline at end of file
diff --git a/ui/window/AdvancedImmersiveMode/buildSrc/build.gradle b/ui/window/AdvancedImmersiveMode/buildSrc/build.gradle
index 7cebf71..490642d 100644
--- a/ui/window/AdvancedImmersiveMode/buildSrc/build.gradle
+++ b/ui/window/AdvancedImmersiveMode/buildSrc/build.gradle
@@ -1,15 +1,8 @@
repositories {
mavenCentral()
}
+
dependencies {
compile 'org.freemarker:freemarker:2.3.20'
+ compile files("libs/buildSrc.jar")
}
-
-sourceSets {
- main {
- groovy {
- srcDir new File(rootDir, "../../../../../../build/buildSrc/src/main/groovy")
- }
- }
-}
-
diff --git a/ui/window/AdvancedImmersiveMode/buildSrc/libs/buildSrc.jar b/ui/window/AdvancedImmersiveMode/buildSrc/libs/buildSrc.jar
new file mode 100644
index 0000000..8154696
--- /dev/null
+++ b/ui/window/AdvancedImmersiveMode/buildSrc/libs/buildSrc.jar
Binary files differ
diff --git a/ui/window/AdvancedImmersiveMode/gradle/wrapper/gradle-wrapper.jar b/ui/window/AdvancedImmersiveMode/gradle/wrapper/gradle-wrapper.jar
index 8c0fb64..5838598 100644
--- a/ui/window/AdvancedImmersiveMode/gradle/wrapper/gradle-wrapper.jar
+++ b/ui/window/AdvancedImmersiveMode/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/ui/window/AdvancedImmersiveMode/gradle/wrapper/gradle-wrapper.properties b/ui/window/AdvancedImmersiveMode/gradle/wrapper/gradle-wrapper.properties
index 861eddc..9e133a0 100644
--- a/ui/window/AdvancedImmersiveMode/gradle/wrapper/gradle-wrapper.properties
+++ b/ui/window/AdvancedImmersiveMode/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Wed Apr 10 15:27:10 PDT 2013
+#Tue Feb 11 09:26:00 PST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip
diff --git a/ui/window/AdvancedImmersiveMode/template-params.xml b/ui/window/AdvancedImmersiveMode/template-params.xml
index 0f23700..e60bc38 100644
--- a/ui/window/AdvancedImmersiveMode/template-params.xml
+++ b/ui/window/AdvancedImmersiveMode/template-params.xml
@@ -27,20 +27,17 @@
<strings>
<intro>
<![CDATA[
- \"Immersive Mode\" is a new UI mode which improves \"hide full screen\" and
+ \"Immersive Mode\", added in Android 4.4, improves the \"hide full screen\" and
\"hide nav bar\" modes, by letting users swipe the bars in and out. This sample
- lets the user experiment with immersive mode by enabling it and seeing how it interacts
+ lets the user experiment with immersive mode by seeing how it interacts
with some of the other UI flags related to full-screen apps.
- \n\nThis sample also lets the user choose between normal immersive mode and "sticky"
- immersive mode, which removes the status bar and nav bar
- a few seconds after the user has swiped them back in.
]]>
</intro>
<sample_action>Try these settings!</sample_action>
</strings>
<template src="base"/>
- <template src="SingleView"/>
+ <template src="FragmentView"/>
<common src="logger"/>
<common src="activities"/>