summaryrefslogtreecommitdiffstats
path: root/samples/devbytes
diff options
context:
space:
mode:
authorRoman Nurik <romannurik@google.com>2013-10-28 11:00:57 -0400
committerRoman Nurik <romannurik@google.com>2013-10-28 11:53:23 -0400
commite7a6ab4fd835d768fc1c3e374681bfdd37e981c5 (patch)
tree25c56b5aec59c30988f229d2310f505de48c5446 /samples/devbytes
parent30278c6f481ac0e10459337d84f421c68583abbf (diff)
downloadandroid_development-e7a6ab4fd835d768fc1c3e374681bfdd37e981c5.tar.gz
android_development-e7a6ab4fd835d768fc1c3e374681bfdd37e981c5.tar.bz2
android_development-e7a6ab4fd835d768fc1c3e374681bfdd37e981c5.zip
Add Android 4.4 Immersive Mode DevByte sample code.
Change-Id: I3515e2742a4b8285f7e3f7c214af1d43dde605a0
Diffstat (limited to 'samples/devbytes')
-rw-r--r--samples/devbytes/ui/ImmersiveMode/build.gradle39
-rw-r--r--samples/devbytes/ui/ImmersiveMode/src/main/AndroidManifest.xml50
-rw-r--r--samples/devbytes/ui/ImmersiveMode/src/main/java/com/example/android/immersive/ImmersiveActivity.java117
-rw-r--r--samples/devbytes/ui/ImmersiveMode/src/main/java/com/example/android/immersive/ImmersiveStickyActivity.java49
-rw-r--r--samples/devbytes/ui/ImmersiveMode/src/main/res/drawable-xxhdpi/ic_launcher.pngbin0 -> 11345 bytes
-rw-r--r--samples/devbytes/ui/ImmersiveMode/src/main/res/drawable-xxhdpi/ic_launcher_translucent_actionbar.pngbin0 -> 3624 bytes
-rw-r--r--samples/devbytes/ui/ImmersiveMode/src/main/res/layout/immersive_activity.xml50
-rw-r--r--samples/devbytes/ui/ImmersiveMode/src/main/res/layout/immersive_sticky_activity.xml23
-rw-r--r--samples/devbytes/ui/ImmersiveMode/src/main/res/layout/include_content.xml31
-rw-r--r--samples/devbytes/ui/ImmersiveMode/src/main/res/values/colors.xml20
-rw-r--r--samples/devbytes/ui/ImmersiveMode/src/main/res/values/strings.xml22
-rw-r--r--samples/devbytes/ui/ImmersiveMode/src/main/res/values/styles.xml36
12 files changed, 437 insertions, 0 deletions
diff --git a/samples/devbytes/ui/ImmersiveMode/build.gradle b/samples/devbytes/ui/ImmersiveMode/build.gradle
new file mode 100644
index 000000000..da6ff3598
--- /dev/null
+++ b/samples/devbytes/ui/ImmersiveMode/build.gradle
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.6.+'
+ }
+}
+apply plugin: 'android'
+
+repositories {
+ mavenCentral()
+}
+
+android {
+ compileSdkVersion 19
+ buildToolsVersion "18.0.1"
+
+ defaultConfig {
+ minSdkVersion 19
+ targetSdkVersion 19
+ }
+}
diff --git a/samples/devbytes/ui/ImmersiveMode/src/main/AndroidManifest.xml b/samples/devbytes/ui/ImmersiveMode/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..b4a35321f
--- /dev/null
+++ b/samples/devbytes/ui/ImmersiveMode/src/main/AndroidManifest.xml
@@ -0,0 +1,50 @@
+<!--
+ 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.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ android:versionCode="1"
+ android:versionName="1.0"
+ package="com.example.android.immersive">
+
+ <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" />
+
+ <application android:icon="@drawable/ic_launcher"
+ android:label="@string/immersive_mode"
+ android:allowBackup="true">
+
+ <activity android:name=".ImmersiveActivity"
+ android:label="@string/immersive_mode"
+ android:configChanges="orientation|keyboardHidden|screenSize"
+ android:theme="@style/ImmersiveTheme">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ <activity android:name=".ImmersiveStickyActivity"
+ android:taskAffinity=""
+ android:label="@string/immersive_sticky"
+ android:configChanges="orientation|keyboardHidden|screenSize"
+ android:theme="@style/ImmersiveStickyTheme">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ </application>
+</manifest>
diff --git a/samples/devbytes/ui/ImmersiveMode/src/main/java/com/example/android/immersive/ImmersiveActivity.java b/samples/devbytes/ui/ImmersiveMode/src/main/java/com/example/android/immersive/ImmersiveActivity.java
new file mode 100644
index 000000000..8fdde0853
--- /dev/null
+++ b/samples/devbytes/ui/ImmersiveMode/src/main/java/com/example/android/immersive/ImmersiveActivity.java
@@ -0,0 +1,117 @@
+/*
+ * 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.
+ */
+
+package com.example.android.immersive;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.view.GestureDetector;
+import android.view.MotionEvent;
+import android.view.View;
+
+public class ImmersiveActivity extends Activity {
+ private static final int INITIAL_HIDE_DELAY = 300;
+
+ private View mDecorView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.immersive_activity);
+
+ final View controlsView = findViewById(R.id.fullscreen_content_controls);
+ final View contentView = findViewById(R.id.fullscreen_content);
+
+ mDecorView = getWindow().getDecorView();
+ mDecorView.setOnSystemUiVisibilityChangeListener(
+ new View.OnSystemUiVisibilityChangeListener() {
+ @Override
+ public void onSystemUiVisibilityChange(int flags) {
+ boolean visible = (flags & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
+ controlsView.animate()
+ .alpha(visible ? 1 : 0)
+ .translationY(visible ? 0 : controlsView.getHeight());
+ }
+ });
+ contentView.setClickable(true);
+ final GestureDetector clickDetector = new GestureDetector(this,
+ new GestureDetector.SimpleOnGestureListener() {
+ @Override
+ public boolean onSingleTapUp(MotionEvent e) {
+ boolean visible = (mDecorView.getSystemUiVisibility()
+ & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
+ if (visible) {
+ hideSystemUI();
+ } else {
+ showSystemUI();
+ }
+ return true;
+ }
+ });
+ contentView.setOnTouchListener(new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View view, MotionEvent motionEvent) {
+ return clickDetector.onTouchEvent(motionEvent);
+ }
+ });
+
+ showSystemUI();
+ }
+
+ @Override
+ public void onWindowFocusChanged(boolean hasFocus) {
+ super.onWindowFocusChanged(hasFocus);
+
+ // When the window loses focus (e.g. the action overflow is shown),
+ // cancel any pending hide action. When the window gains focus,
+ // hide the system UI.
+ if (hasFocus) {
+ delayedHide(INITIAL_HIDE_DELAY);
+ } else {
+ mHideHandler.removeMessages(0);
+ }
+ }
+
+ private void hideSystemUI() {
+ mDecorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_LOW_PROFILE
+ | View.SYSTEM_UI_FLAG_IMMERSIVE);
+ }
+
+ private void showSystemUI() {
+ mDecorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
+ }
+
+ private final Handler mHideHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ hideSystemUI();
+ }
+ };
+
+ private void delayedHide(int delayMillis) {
+ mHideHandler.removeMessages(0);
+ mHideHandler.sendEmptyMessageDelayed(0, delayMillis);
+ }
+}
diff --git a/samples/devbytes/ui/ImmersiveMode/src/main/java/com/example/android/immersive/ImmersiveStickyActivity.java b/samples/devbytes/ui/ImmersiveMode/src/main/java/com/example/android/immersive/ImmersiveStickyActivity.java
new file mode 100644
index 000000000..d6dfd3695
--- /dev/null
+++ b/samples/devbytes/ui/ImmersiveMode/src/main/java/com/example/android/immersive/ImmersiveStickyActivity.java
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+package com.example.android.immersive;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.view.GestureDetector;
+import android.view.MotionEvent;
+import android.view.View;
+
+public class ImmersiveStickyActivity extends Activity {
+ private View mDecorView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.immersive_sticky_activity);
+ mDecorView = getWindow().getDecorView();
+ }
+
+ @Override
+ public void onWindowFocusChanged(boolean hasFocus) {
+ super.onWindowFocusChanged(hasFocus);
+ if (hasFocus) {
+ mDecorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
+ }
+ }
+}
diff --git a/samples/devbytes/ui/ImmersiveMode/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/devbytes/ui/ImmersiveMode/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 000000000..f47fc3203
--- /dev/null
+++ b/samples/devbytes/ui/ImmersiveMode/src/main/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/devbytes/ui/ImmersiveMode/src/main/res/drawable-xxhdpi/ic_launcher_translucent_actionbar.png b/samples/devbytes/ui/ImmersiveMode/src/main/res/drawable-xxhdpi/ic_launcher_translucent_actionbar.png
new file mode 100644
index 000000000..bf344ad86
--- /dev/null
+++ b/samples/devbytes/ui/ImmersiveMode/src/main/res/drawable-xxhdpi/ic_launcher_translucent_actionbar.png
Binary files differ
diff --git a/samples/devbytes/ui/ImmersiveMode/src/main/res/layout/immersive_activity.xml b/samples/devbytes/ui/ImmersiveMode/src/main/res/layout/immersive_activity.xml
new file mode 100644
index 000000000..e4ce45540
--- /dev/null
+++ b/samples/devbytes/ui/ImmersiveMode/src/main/res/layout/immersive_activity.xml
@@ -0,0 +1,50 @@
+<!--
+ 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.
+ -->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <include layout="@layout/include_content" />
+
+ <!-- This FrameLayout insets its children based on system windows using
+ android:fitsSystemWindows. These insets will be stable across system
+ UI visibility changes because we use the SYSTEM_UI_FLAG_LAYOUT_STABLE
+ flag in addition to SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN and
+ SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION. -->
+ <FrameLayout android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:clipToPadding="false"
+ android:fitsSystemWindows="true">
+
+ <LinearLayout android:id="@+id/fullscreen_content_controls"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="bottom|center_horizontal"
+ android:background="@color/fullscreen_control_overlay_color"
+ android:orientation="horizontal">
+
+ <Button android:id="@+id/placeholder_button"
+ android:layout_width="0dp"
+ android:layout_height="48dp"
+ android:layout_weight="1"
+ android:text="@string/placeholder_button"
+ android:background="?android:selectableItemBackground" />
+
+ </LinearLayout>
+ </FrameLayout>
+
+</FrameLayout>
diff --git a/samples/devbytes/ui/ImmersiveMode/src/main/res/layout/immersive_sticky_activity.xml b/samples/devbytes/ui/ImmersiveMode/src/main/res/layout/immersive_sticky_activity.xml
new file mode 100644
index 000000000..b98b923aa
--- /dev/null
+++ b/samples/devbytes/ui/ImmersiveMode/src/main/res/layout/immersive_sticky_activity.xml
@@ -0,0 +1,23 @@
+<!--
+ 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.
+ -->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <include layout="@layout/include_content" />
+
+</FrameLayout>
diff --git a/samples/devbytes/ui/ImmersiveMode/src/main/res/layout/include_content.xml b/samples/devbytes/ui/ImmersiveMode/src/main/res/layout/include_content.xml
new file mode 100644
index 000000000..967573b3d
--- /dev/null
+++ b/samples/devbytes/ui/ImmersiveMode/src/main/res/layout/include_content.xml
@@ -0,0 +1,31 @@
+<!--
+ 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.
+ -->
+
+<!-- The primary full-screen view. This can be replaced with whatever view
+ is needed to present your content, e.g. VideoView, SurfaceView,
+ TextureView, etc. -->
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/fullscreen_content"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:keepScreenOn="true"
+ android:textColor="#fb3"
+ android:fontFamily="sans-serif-condensed"
+ android:textStyle="bold"
+ android:lineSpacingMultiplier="0.8"
+ android:textSize="50sp"
+ android:gravity="center"
+ android:text="@string/placeholder_content" />
diff --git a/samples/devbytes/ui/ImmersiveMode/src/main/res/values/colors.xml b/samples/devbytes/ui/ImmersiveMode/src/main/res/values/colors.xml
new file mode 100644
index 000000000..7e91c5094
--- /dev/null
+++ b/samples/devbytes/ui/ImmersiveMode/src/main/res/values/colors.xml
@@ -0,0 +1,20 @@
+<!--
+ 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.
+ -->
+
+<resources>
+ <color name="background">#f80</color>
+ <color name="fullscreen_control_overlay_color">#66000000</color>
+</resources>
diff --git a/samples/devbytes/ui/ImmersiveMode/src/main/res/values/strings.xml b/samples/devbytes/ui/ImmersiveMode/src/main/res/values/strings.xml
new file mode 100644
index 000000000..3c520f939
--- /dev/null
+++ b/samples/devbytes/ui/ImmersiveMode/src/main/res/values/strings.xml
@@ -0,0 +1,22 @@
+<!--
+ 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.
+ -->
+
+<resources>
+ <string name="immersive_mode">Immersive Mode</string>
+ <string name="immersive_sticky">Immersive/Sticky</string>
+ <string name="placeholder_button">Placeholder Button</string>
+ <string name="placeholder_content">IMMERSIVE\nCONTENT</string>
+</resources>
diff --git a/samples/devbytes/ui/ImmersiveMode/src/main/res/values/styles.xml b/samples/devbytes/ui/ImmersiveMode/src/main/res/values/styles.xml
new file mode 100644
index 000000000..2d7d458b3
--- /dev/null
+++ b/samples/devbytes/ui/ImmersiveMode/src/main/res/values/styles.xml
@@ -0,0 +1,36 @@
+<!--
+ 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.
+ -->
+
+<resources>
+
+ <style name="ImmersiveTheme" parent="android:Theme.Holo">
+ <item name="android:windowBackground">@color/background</item>
+ <item name="android:windowContentOverlay">@null</item>
+ <item name="android:windowActionBarOverlay">true</item>
+ <item name="android:actionBarStyle">@style/ImmersiveActionBarStyle</item>
+ </style>
+
+ <style name="ImmersiveStickyTheme" parent="ImmersiveTheme">
+ <item name="android:windowNoTitle">true</item>
+ <item name="android:windowActionBar">false</item>
+ </style>
+
+ <style name="ImmersiveActionBarStyle" parent="android:Widget.Holo.ActionBar.Solid">
+ <item name="android:background">@color/fullscreen_control_overlay_color</item>
+ <item name="android:icon">@drawable/ic_launcher_translucent_actionbar</item>
+ </style>
+
+</resources>