Added demo for ActionBar display options
Change-Id: Ib916c36c0d3f8866b4f7f3a616fe15dcf0ca007f
diff --git a/samples/ApiDemos/AndroidManifest.xml b/samples/ApiDemos/AndroidManifest.xml
index cad8dd7..dbcbdab 100644
--- a/samples/ApiDemos/AndroidManifest.xml
+++ b/samples/ApiDemos/AndroidManifest.xml
@@ -686,6 +686,15 @@
</intent-filter>
</activity>
+ <activity android:name=".app.ActionBarDisplayOptions"
+ android:label="@string/action_bar_display_options"
+ android:logo="@drawable/apidemo_androidlogo">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.SAMPLE_CODE" />
+ </intent-filter>
+ </activity>
+
<!-- ************************************* -->
<!-- PREFERENCE PACKAGE SAMPLES -->
<!-- ************************************* -->
diff --git a/samples/ApiDemos/res/drawable-hdpi/apidemo_androidlogo.png b/samples/ApiDemos/res/drawable-hdpi/apidemo_androidlogo.png
new file mode 100644
index 0000000..088181b
--- /dev/null
+++ b/samples/ApiDemos/res/drawable-hdpi/apidemo_androidlogo.png
Binary files differ
diff --git a/samples/ApiDemos/res/drawable-mdpi/apidemo_androidlogo.png b/samples/ApiDemos/res/drawable-mdpi/apidemo_androidlogo.png
new file mode 100644
index 0000000..11cb47b
--- /dev/null
+++ b/samples/ApiDemos/res/drawable-mdpi/apidemo_androidlogo.png
Binary files differ
diff --git a/samples/ApiDemos/res/layout/action_bar_display_options.xml b/samples/ApiDemos/res/layout/action_bar_display_options.xml
new file mode 100644
index 0000000..1718fdb
--- /dev/null
+++ b/samples/ApiDemos/res/layout/action_bar_display_options.xml
@@ -0,0 +1,48 @@
+<?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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+ <Button android:id="@+id/toggle_home_as_up"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/toggle_home_as_up" />
+ <Button android:id="@+id/toggle_show_home"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/toggle_show_home" />
+ <Button android:id="@+id/toggle_use_logo"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/toggle_use_logo" />
+ <Button android:id="@+id/toggle_show_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/toggle_show_title" />
+ <Button android:id="@+id/toggle_show_custom"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/toggle_show_custom" />
+ <Button android:id="@+id/toggle_navigation"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/toggle_navigation" />
+ <Button android:id="@+id/cycle_custom_gravity"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/cycle_custom_gravity" />
+</LinearLayout>
diff --git a/samples/ApiDemos/res/layout/action_bar_display_options_custom.xml b/samples/ApiDemos/res/layout/action_bar_display_options_custom.xml
new file mode 100644
index 0000000..b7f5bd9
--- /dev/null
+++ b/samples/ApiDemos/res/layout/action_bar_display_options_custom.xml
@@ -0,0 +1,17 @@
+<?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.
+-->
+<Button xmlns:android="http://schemas.android.com/apk/res/android"
+ android:text="@string/display_options_custom_button" />
diff --git a/samples/ApiDemos/res/menu/display_options_actions.xml b/samples/ApiDemos/res/menu/display_options_actions.xml
new file mode 100644
index 0000000..7c72de4
--- /dev/null
+++ b/samples/ApiDemos/res/menu/display_options_actions.xml
@@ -0,0 +1,19 @@
+<?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.
+-->
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/simple_item"
+ android:title="@string/display_options_menu_item" />
+</menu>
diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml
index 5e353a0..81b5a6d 100644
--- a/samples/ApiDemos/res/values/strings.xml
+++ b/samples/ApiDemos/res/values/strings.xml
@@ -566,6 +566,18 @@
<string name="action_bar_zoom">Zoom</string>
<string name="action_bar_save">Save</string>
+ <string name="action_bar_display_options">App/Action Bar/Display Options</string>
+ <string name="toggle_home_as_up">DISPLAY_HOME_AS_UP</string>
+ <string name="toggle_show_home">DISPLAY_SHOW_HOME</string>
+ <string name="toggle_use_logo">DISPLAY_USE_LOGO</string>
+ <string name="toggle_show_title">DISPLAY_SHOW_TITLE</string>
+ <string name="toggle_show_custom">DISPLAY_SHOW_CUSTOM</string>
+ <string name="toggle_navigation">Navigation</string>
+ <string name="cycle_custom_gravity">Cycle Custom View Gravity</string>
+
+ <string name="display_options_custom_button">Custom View!</string>
+ <string name="display_options_menu_item">Menu Item</string>
+
<!-- ============================ -->
<!-- graphics examples strings -->
<!-- ============================ -->
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/ActionBarDisplayOptions.java b/samples/ApiDemos/src/com/example/android/apis/app/ActionBarDisplayOptions.java
new file mode 100644
index 0000000..02904ce
--- /dev/null
+++ b/samples/ApiDemos/src/com/example/android/apis/app/ActionBarDisplayOptions.java
@@ -0,0 +1,128 @@
+/*
+ * 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.app;
+
+import com.example.android.apis.R;
+
+import android.app.ActionBar;
+import android.app.ActionBar.Tab;
+import android.app.Activity;
+import android.app.FragmentTransaction;
+import android.os.Bundle;
+import android.view.Gravity;
+import android.view.Menu;
+import android.view.View;
+import android.view.ViewGroup.LayoutParams;
+
+/**
+ * This demo shows how various action bar display option flags can be combined and their effects.
+ */
+public class ActionBarDisplayOptions extends Activity
+ implements View.OnClickListener, ActionBar.TabListener {
+ private View mCustomView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.action_bar_display_options);
+
+ findViewById(R.id.toggle_home_as_up).setOnClickListener(this);
+ findViewById(R.id.toggle_show_home).setOnClickListener(this);
+ findViewById(R.id.toggle_use_logo).setOnClickListener(this);
+ findViewById(R.id.toggle_show_title).setOnClickListener(this);
+ findViewById(R.id.toggle_show_custom).setOnClickListener(this);
+ findViewById(R.id.toggle_navigation).setOnClickListener(this);
+ findViewById(R.id.cycle_custom_gravity).setOnClickListener(this);
+
+ mCustomView = getLayoutInflater().inflate(R.layout.action_bar_display_options_custom, null);
+ // Configure several action bar elements that will be toggled by display options.
+ final ActionBar bar = getActionBar();
+ bar.setCustomView(mCustomView,
+ new ActionBar.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
+
+ 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) {
+ getMenuInflater().inflate(R.menu.display_options_actions, menu);
+ return true;
+ }
+
+ @Override
+ public void onClick(View v) {
+ final ActionBar bar = getActionBar();
+ int flags = 0;
+ switch (v.getId()) {
+ case R.id.toggle_home_as_up:
+ flags = ActionBar.DISPLAY_HOME_AS_UP;
+ break;
+ case R.id.toggle_show_home:
+ flags = ActionBar.DISPLAY_SHOW_HOME;
+ break;
+ case R.id.toggle_use_logo:
+ flags = ActionBar.DISPLAY_USE_LOGO;
+ break;
+ case R.id.toggle_show_title:
+ flags = ActionBar.DISPLAY_SHOW_TITLE;
+ break;
+ case R.id.toggle_show_custom:
+ flags = ActionBar.DISPLAY_SHOW_CUSTOM;
+ break;
+
+ case R.id.toggle_navigation:
+ bar.setNavigationMode(
+ bar.getNavigationMode() == ActionBar.NAVIGATION_MODE_STANDARD
+ ? ActionBar.NAVIGATION_MODE_TABS
+ : ActionBar.NAVIGATION_MODE_STANDARD);
+ return;
+ case R.id.cycle_custom_gravity:
+ ActionBar.LayoutParams lp = (ActionBar.LayoutParams) mCustomView.getLayoutParams();
+ int newGravity = 0;
+ switch (lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
+ case Gravity.LEFT:
+ newGravity = Gravity.CENTER_HORIZONTAL;
+ break;
+ case Gravity.CENTER_HORIZONTAL:
+ newGravity = Gravity.RIGHT;
+ break;
+ case Gravity.RIGHT:
+ newGravity = Gravity.LEFT;
+ break;
+ }
+ lp.gravity = lp.gravity & ~Gravity.HORIZONTAL_GRAVITY_MASK | newGravity;
+ bar.setCustomView(mCustomView, lp);
+ return;
+ }
+
+ int change = bar.getDisplayOptions() ^ flags;
+ bar.setDisplayOptions(change, flags);
+ }
+
+ @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/app/ActionBarUsage.java b/samples/ApiDemos/src/com/example/android/apis/app/ActionBarUsage.java
index 9657558..6980050 100644
--- a/samples/ApiDemos/src/com/example/android/apis/app/ActionBarUsage.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/ActionBarUsage.java
@@ -24,10 +24,10 @@
import com.example.android.apis.R;
/**
- * This demonstrates idiomatic usage of the Action Bar. The theme Theme.WithActionBar
- * is specified for this activity in AndroidManifest.xml and a menu resource is used
- * to populate the menu data itself. If you'd like to see how these things work under
- * the hood, see ActionBarMechanics.
+ * This demonstrates idiomatic usage of the Action Bar. The default Honeycomb theme
+ * includes the action bar by default and a menu resource is used to populate the
+ * menu data itself. If you'd like to see how these things work under the hood, see
+ * ActionBarMechanics.
*/
public class ActionBarUsage extends Activity {
@Override