diff --git a/samples/Support7Demos/AndroidManifest.xml b/samples/Support7Demos/AndroidManifest.xml
index d9ff231d4..4112bcef0 100644
--- a/samples/Support7Demos/AndroidManifest.xml
+++ b/samples/Support7Demos/AndroidManifest.xml
@@ -49,7 +49,7 @@
android:label="@string/sample_media_router_activity">
-
+
@@ -63,24 +63,74 @@
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/Support7Demos/res/drawable-hdpi/apidemo_androidlogo.png b/samples/Support7Demos/res/drawable-hdpi/apidemo_androidlogo.png
new file mode 100644
index 000000000..088181b91
Binary files /dev/null and b/samples/Support7Demos/res/drawable-hdpi/apidemo_androidlogo.png differ
diff --git a/samples/Support7Demos/res/drawable-hdpi/ic_launcher_settings.png b/samples/Support7Demos/res/drawable-hdpi/ic_launcher_settings.png
new file mode 100644
index 000000000..c02bd424f
Binary files /dev/null and b/samples/Support7Demos/res/drawable-hdpi/ic_launcher_settings.png differ
diff --git a/samples/Support7Demos/res/drawable-mdpi/apidemo_androidlogo.png b/samples/Support7Demos/res/drawable-mdpi/apidemo_androidlogo.png
new file mode 100644
index 000000000..11cb47b28
Binary files /dev/null and b/samples/Support7Demos/res/drawable-mdpi/apidemo_androidlogo.png differ
diff --git a/samples/Support7Demos/res/drawable-mdpi/ic_launcher_settings.png b/samples/Support7Demos/res/drawable-mdpi/ic_launcher_settings.png
new file mode 100644
index 000000000..05cdd9aa9
Binary files /dev/null and b/samples/Support7Demos/res/drawable-mdpi/ic_launcher_settings.png differ
diff --git a/samples/Support7Demos/res/layout/action_bar_display_options.xml b/samples/Support7Demos/res/layout/action_bar_display_options.xml
new file mode 100644
index 000000000..d4216f5dd
--- /dev/null
+++ b/samples/Support7Demos/res/layout/action_bar_display_options.xml
@@ -0,0 +1,59 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/Support7Demos/res/layout/action_bar_display_options_custom.xml b/samples/Support7Demos/res/layout/action_bar_display_options_custom.xml
new file mode 100644
index 000000000..b7f5bd952
--- /dev/null
+++ b/samples/Support7Demos/res/layout/action_bar_display_options_custom.xml
@@ -0,0 +1,17 @@
+
+
+
diff --git a/samples/Support7Demos/res/layout/action_bar_settings_action_provider.xml b/samples/Support7Demos/res/layout/action_bar_settings_action_provider.xml
new file mode 100644
index 000000000..dd9807b74
--- /dev/null
+++ b/samples/Support7Demos/res/layout/action_bar_settings_action_provider.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
diff --git a/samples/Support7Demos/res/layout/action_bar_tab_content.xml b/samples/Support7Demos/res/layout/action_bar_tab_content.xml
new file mode 100644
index 000000000..c0aa7fade
--- /dev/null
+++ b/samples/Support7Demos/res/layout/action_bar_tab_content.xml
@@ -0,0 +1,19 @@
+
+
+
diff --git a/samples/Support7Demos/res/layout/action_bar_tabs.xml b/samples/Support7Demos/res/layout/action_bar_tabs.xml
new file mode 100644
index 000000000..a51f46ef7
--- /dev/null
+++ b/samples/Support7Demos/res/layout/action_bar_tabs.xml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/Support7Demos/res/menu/action_bar_settings_action_provider.xml b/samples/Support7Demos/res/menu/action_bar_settings_action_provider.xml
new file mode 100644
index 000000000..e9bb931c0
--- /dev/null
+++ b/samples/Support7Demos/res/menu/action_bar_settings_action_provider.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
diff --git a/samples/Support7Demos/res/menu/actions.xml b/samples/Support7Demos/res/menu/actions.xml
new file mode 100644
index 000000000..fbae7b1c4
--- /dev/null
+++ b/samples/Support7Demos/res/menu/actions.xml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+ -
+
+
+
+
+
+
diff --git a/samples/Support7Demos/res/menu/display_options_actions.xml b/samples/Support7Demos/res/menu/display_options_actions.xml
new file mode 100644
index 000000000..8feb6aace
--- /dev/null
+++ b/samples/Support7Demos/res/menu/display_options_actions.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
diff --git a/samples/Support7Demos/res/menu/sample_media_router_menu.xml b/samples/Support7Demos/res/menu/sample_media_router_menu.xml
index 404654fe9..aac1e967d 100644
--- a/samples/Support7Demos/res/menu/sample_media_router_menu.xml
+++ b/samples/Support7Demos/res/menu/sample_media_router_menu.xml
@@ -14,7 +14,8 @@
limitations under the License.
-->
-
+
-
-
Media/MediaRouter
+ MediaRouter
This activity demonstrates how to
use MediaRouter from the support library. Select a route from the action bar.
Play on...
@@ -32,8 +32,49 @@
Variable Volume Remote Playback Route
+
+ GridLayout/1. Simple Form
+ GridLayout/2. Form (XML)
+ GridLayout/3. Form (Java)
+
Type here:
Ok
Cancel
+
+
+ AppCompat/Action Bar/Action Bar Mechanics
+ AppCompat/Action Bar/Action Bar Usage
+ AppCompat/Action Bar/Action Bar Tabs
+ AppCompat/Action Bar/Settings Action Provider
+ Handling in onOptionsItemSelected avoided
+
+ Search
+ Add
+ Edit
+ Share
+ Sort
+ Alphabetically
+ By size
+ Settings
+
+ AppCompat/Action Bar/Display Options
+ DISPLAY_HOME_AS_UP
+ DISPLAY_SHOW_HOME
+ DISPLAY_USE_LOGO
+ DISPLAY_SHOW_TITLE
+ DISPLAY_SHOW_CUSTOM
+ Navigation
+ Cycle Custom View Gravity
+ Toggle Visibility
+ Toggle System UI
+
+ Custom View!
+ Menu Item
+
+ Add new tab
+ Remove last tab
+ Toggle tab mode
+ Remove all tabs
+
diff --git a/samples/Support7Demos/src/com/example/android/supportv7/Support7Demos.java b/samples/Support7Demos/src/com/example/android/supportv7/Support7Demos.java
index d2e633540..a135649bd 100644
--- a/samples/Support7Demos/src/com/example/android/supportv7/Support7Demos.java
+++ b/samples/Support7Demos/src/com/example/android/supportv7/Support7Demos.java
@@ -56,7 +56,7 @@ public class Support7Demos extends ListActivity {
List> myData = new ArrayList>();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
- mainIntent.addCategory("com.example.android.supportv7.SUPPORT4_SAMPLE_CODE");
+ mainIntent.addCategory("com.example.android.supportv7.SAMPLE_CODE");
PackageManager pm = getPackageManager();
List list = pm.queryIntentActivities(mainIntent, 0);
diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarDisplayOptions.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarDisplayOptions.java
new file mode 100644
index 000000000..f35844372
--- /dev/null
+++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarDisplayOptions.java
@@ -0,0 +1,148 @@
+/*
+ * 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.supportv7.app;
+
+import com.example.android.supportv7.R;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentTransaction;
+import android.support.v7.app.ActionBar;
+import android.support.v7.app.ActionBar.Tab;
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.view.Menu;
+import android.view.Gravity;
+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 ActionBarActivity
+ implements View.OnClickListener, ActionBar.TabListener {
+ private View mCustomView;
+ private ActionBar.LayoutParams mCustomViewLayoutParams;
+
+ @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);
+ findViewById(R.id.toggle_visibility).setOnClickListener(this);
+ findViewById(R.id.toggle_system_ui).setOnClickListener(this);
+
+ // Configure several action bar elements that will be toggled by display options.
+ mCustomView = getLayoutInflater().inflate(R.layout.action_bar_display_options_custom, null);
+ mCustomViewLayoutParams = new ActionBar.LayoutParams(
+ LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+
+ final ActionBar bar = getSupportActionBar();
+ bar.setCustomView(mCustomView, mCustomViewLayoutParams);
+ 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 onCreateSupportOptionsMenu(Menu menu) {
+ getSupportMenuInflater().inflate(R.menu.display_options_actions, menu);
+ return true;
+ }
+
+ @Override
+ public void onClick(View v) {
+ final ActionBar bar = getSupportActionBar();
+ 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 = mCustomViewLayoutParams;
+ 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;
+ }
+ case R.id.toggle_visibility:
+ if (bar.isShowing()) {
+ bar.hide();
+ } else {
+ bar.show();
+ }
+ return;
+ case R.id.toggle_system_ui:
+ if ((getWindow().getDecorView().getSystemUiVisibility()
+ & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0) {
+ getWindow().getDecorView().setSystemUiVisibility(0);
+ } else {
+ getWindow().getDecorView().setSystemUiVisibility(
+ View.SYSTEM_UI_FLAG_FULLSCREEN);
+ }
+ 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/Support7Demos/src/com/example/android/supportv7/app/ActionBarMechanics.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarMechanics.java
new file mode 100644
index 000000000..da899b159
--- /dev/null
+++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarMechanics.java
@@ -0,0 +1,72 @@
+/*
+ * 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.supportv7.app;
+
+import android.os.Bundle;
+import android.support.v4.view.WindowCompat;
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.view.Menu;
+import android.support.v7.view.MenuItem;
+import android.widget.Toast;
+
+/**
+ * This demonstrates the basics of the Action Bar and how it interoperates with the
+ * standard options menu. This demo is for informative purposes only; see ActionBarUsage for
+ * an example of using the Action Bar in a more idiomatic manner.
+ */
+public class ActionBarMechanics extends ActionBarActivity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // The Action Bar is a window feature. The feature must be requested
+ // before setting a content view. Normally this is set automatically
+ // by your Activity's theme in your manifest. The provided system
+ // theme Theme.WithActionBar enables this for you. Use it as you would
+ // use Theme.NoTitleBar. You can add an Action Bar to your own themes
+ // by adding the element - true
+ // to your style definition.
+ supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR);
+ }
+
+ @Override
+ public boolean onCreateSupportOptionsMenu(Menu menu) {
+ // Menu items default to never show in the action bar. On most devices this means
+ // they will show in the standard options menu panel when the menu button is pressed.
+ // On xlarge-screen devices a "More" button will appear in the far right of the
+ // Action Bar that will display remaining items in a cascading menu.
+ menu.add("Normal item");
+
+ MenuItem actionItem = menu.add("Action Button");
+
+ // Items that show as actions should favor the "if room" setting, which will
+ // prevent too many buttons from crowding the bar. Extra items will show in the
+ // overflow area.
+ actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+
+ // Items that show as actions are strongly encouraged to use an icon.
+ // These icons are shown without a text description, and therefore should
+ // be sufficiently descriptive on their own.
+ actionItem.setIcon(android.R.drawable.ic_menu_share);
+ return true;
+ }
+
+ @Override
+ public boolean onSupportOptionsItemSelected(MenuItem item) {
+ Toast.makeText(this, "Selected Item: " + item.getTitle(), Toast.LENGTH_SHORT).show();
+ return true;
+ }
+}
diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarSettingsActionProviderActivity.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarSettingsActionProviderActivity.java
new file mode 100644
index 000000000..5c70b702f
--- /dev/null
+++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarSettingsActionProviderActivity.java
@@ -0,0 +1,94 @@
+/*
+ * 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.supportv7.app;
+
+import com.example.android.supportv7.R;
+
+import android.content.Context;
+import android.content.Intent;
+import android.provider.Settings;
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.view.ActionProvider;
+import android.support.v7.view.Menu;
+import android.support.v7.view.MenuItem;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ImageButton;
+import android.widget.Toast;
+
+/**
+ * This activity demonstrates how to implement an {@link android.view.ActionProvider}
+ * for adding functionality to the Action Bar. In particular this demo creates an
+ * ActionProvider for launching the system settings and adds a menu item with that
+ * provider.
+ */
+public class ActionBarSettingsActionProviderActivity extends ActionBarActivity {
+ @Override
+ public boolean onCreateSupportOptionsMenu(Menu menu) {
+ super.onCreateSupportOptionsMenu(menu);
+ getSupportMenuInflater().inflate(R.menu.action_bar_settings_action_provider, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onSupportOptionsItemSelected(MenuItem item) {
+ // If this callback does not handle the item click, onPerformDefaultAction
+ // of the ActionProvider is invoked. Hence, the provider encapsulates the
+ // complete functionality of the menu item.
+ Toast.makeText(this, R.string.action_bar_settings_action_provider_no_handling,
+ Toast.LENGTH_SHORT).show();
+ return false;
+ }
+
+ public static class SettingsActionProvider extends ActionProvider {
+ /** An intent for launching the system settings. */
+ private static final Intent sSettingsIntent = new Intent(Settings.ACTION_SETTINGS);
+
+ /**
+ * Creates a new instance.
+ *
+ * @param context Context for accessing resources.
+ */
+ public SettingsActionProvider(Context context) {
+ super(context);
+ }
+
+ @Override
+ public View onCreateActionView() {
+ // Inflate the action view to be shown on the action bar.
+ LayoutInflater layoutInflater = LayoutInflater.from(getContext());
+ View view = layoutInflater.inflate(R.layout.action_bar_settings_action_provider, null);
+ ImageButton button = (ImageButton) view.findViewById(R.id.button);
+ // Attach a click listener for launching the system settings.
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ getContext().startActivity(sSettingsIntent);
+ }
+ });
+ return view;
+ }
+
+ @Override
+ public boolean onPerformDefaultAction() {
+ // This is called if the host menu item placed in the overflow menu of the
+ // action bar is clicked and the host activity did not handle the click.
+ getContext().startActivity(sSettingsIntent);
+ return true;
+ }
+ }
+}
diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarTabs.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarTabs.java
new file mode 100644
index 000000000..f0ee271e6
--- /dev/null
+++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarTabs.java
@@ -0,0 +1,135 @@
+/*
+ * 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.supportv7.app;
+
+import com.example.android.supportv7.R;
+
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentTransaction;
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.app.ActionBar;
+import android.support.v7.app.ActionBar.Tab;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+import android.widget.Toast;
+
+/**
+ * This demonstrates the use of action bar tabs and how they interact
+ * with other action bar features.
+ */
+public class ActionBarTabs extends ActionBarActivity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.action_bar_tabs);
+ }
+
+ public void onAddTab(View v) {
+ final ActionBar bar = getSupportActionBar();
+ final int tabCount = bar.getTabCount();
+ final String text = "Tab " + tabCount;
+ bar.addTab(bar.newTab()
+ .setText(text)
+ .setTabListener(new TabListener(new TabContentFragment(text))));
+ }
+
+ public void onRemoveTab(View v) {
+ final ActionBar bar = getSupportActionBar();
+ if (bar.getTabCount() > 0) {
+ bar.removeTabAt(bar.getTabCount() - 1);
+ }
+ }
+
+ public void onToggleTabs(View v) {
+ final ActionBar bar = getSupportActionBar();
+
+ if (bar.getNavigationMode() == ActionBar.NAVIGATION_MODE_TABS) {
+ bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
+ bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
+ } else {
+ bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
+ bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
+ }
+ }
+
+ public void onRemoveAllTabs(View v) {
+ getSupportActionBar().removeAllTabs();
+ }
+
+ /**
+ * A TabListener receives event callbacks from the action bar as tabs
+ * are deselected, selected, and reselected. A FragmentTransaction
+ * is provided to each of these callbacks; if any operations are added
+ * to it, it will be committed at the end of the full tab switch operation.
+ * This lets tab switches be atomic without the app needing to track
+ * the interactions between different tabs.
+ *
+ * NOTE: This is a very simple implementation that does not retain
+ * fragment state of the non-visible tabs across activity instances.
+ * Look at the FragmentTabs example for how to do a more complete
+ * implementation.
+ */
+ private class TabListener implements ActionBar.TabListener {
+ private TabContentFragment mFragment;
+
+ public TabListener(TabContentFragment fragment) {
+ mFragment = fragment;
+ }
+
+ @Override
+ public void onTabSelected(Tab tab, FragmentTransaction ft) {
+ ft.add(R.id.fragment_content, mFragment, mFragment.getText());
+ }
+
+ @Override
+ public void onTabUnselected(Tab tab, FragmentTransaction ft) {
+ ft.remove(mFragment);
+ }
+
+ @Override
+ public void onTabReselected(Tab tab, FragmentTransaction ft) {
+ Toast.makeText(ActionBarTabs.this, "Reselected!", Toast.LENGTH_SHORT).show();
+ }
+
+ }
+
+ private class TabContentFragment extends Fragment {
+ private String mText;
+
+ public TabContentFragment(String text) {
+ mText = text;
+ }
+
+ public String getText() {
+ return mText;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View fragView = inflater.inflate(R.layout.action_bar_tab_content, container, false);
+
+ TextView text = (TextView) fragView.findViewById(R.id.text);
+ text.setText(mText);
+
+ return fragView;
+ }
+ }
+}
diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarUsage.java b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarUsage.java
new file mode 100644
index 000000000..729e652bd
--- /dev/null
+++ b/samples/Support7Demos/src/com/example/android/supportv7/app/ActionBarUsage.java
@@ -0,0 +1,101 @@
+/*
+ * 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.supportv7.app;
+
+import com.example.android.supportv7.R;
+
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.support.v4.widget.SearchViewCompat;
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.view.Menu;
+import android.support.v7.view.MenuInflater;
+import android.support.v7.view.MenuItem;
+import android.view.View;
+import android.widget.SearchView;
+import android.widget.SearchView.OnQueryTextListener;
+import android.widget.TextView;
+import android.widget.Toast;
+
+/**
+ * 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 ActionBarActivity {
+ TextView mSearchText;
+ int mSortMode = -1;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mSearchText = new TextView(this);
+ setContentView(mSearchText);
+ }
+
+ @Override
+ public boolean onCreateSupportOptionsMenu(Menu menu) {
+ MenuInflater inflater = getSupportMenuInflater();
+ inflater.inflate(R.menu.actions, menu);
+ View searchView = menu.findItem(R.id.action_search).getActionView();
+ SearchViewCompat.setOnQueryTextListener(searchView, mOnQueryTextListener);
+ return true;
+ }
+
+ @Override
+ public boolean onPrepareSupportOptionsMenu(Menu menu) {
+ if (mSortMode != -1) {
+ Drawable icon = menu.findItem(mSortMode).getIcon();
+ menu.findItem(R.id.action_sort).setIcon(icon);
+ }
+ return super.onPrepareSupportOptionsMenu(menu);
+ }
+
+ @Override
+ public boolean onSupportOptionsItemSelected(MenuItem item) {
+ Toast.makeText(this, "Selected Item: " + item.getTitle(), Toast.LENGTH_SHORT).show();
+ return true;
+ }
+
+ // This method is specified as an onClick handler in the menu xml and will
+ // take precedence over the Activity's onOptionsItemSelected method.
+ // See res/menu/actions.xml for more info.
+ public void onSort(MenuItem item) {
+ mSortMode = item.getItemId();
+ // Request a call to onPrepareOptionsMenu so we can change the sort icon
+ supportInvalidateOptionsMenu();
+ }
+
+ // The following callbacks are called for the SearchView.OnQueryChangeListener
+ // For more about using SearchView, see src/.../view/SearchView1.java and SearchView2.java
+ private final SearchViewCompat.OnQueryTextListenerCompat mOnQueryTextListener =
+ new SearchViewCompat.OnQueryTextListenerCompat() {
+ @Override
+ public boolean onQueryTextChange(String newText) {
+ newText = newText.isEmpty() ? "" : "Query so far: " + newText;
+ mSearchText.setText(newText);
+ return true;
+ }
+
+ @Override
+ public boolean onQueryTextSubmit(String query) {
+ Toast.makeText(ActionBarUsage.this,
+ "Searching for: " + query + "...", Toast.LENGTH_SHORT).show();
+ return true;
+ }
+ };
+}
diff --git a/samples/Support7Demos/src/com/example/android/supportv7/app/_index.html b/samples/Support7Demos/src/com/example/android/supportv7/app/_index.html
index d203ffb6b..c316d1bfc 100644
--- a/samples/Support7Demos/src/com/example/android/supportv7/app/_index.html
+++ b/samples/Support7Demos/src/com/example/android/supportv7/app/_index.html
@@ -1,102 +1,33 @@
This section includes samples showing the use of the application
-package features of the static support library, in particular fragments
-and loaders.
+package features of the static support library.
-Fragment
+Action Bar
- Fragment Alert Dialog
- Demonstrates how to use a DialogFragment to show and manage an
- AlertDialog.
-
- Fragment Arguments
- Demonstrates how a fragment can be initialized with arguments,
- supplying them either as an argument Bundle at runtime or XML attributes
- in a <fragment> tag.
-
- Fragment Context Menu
- Demonstrates how to display and respond to a context menu that is
- display from a fragment's view hierarchy.
-
- Fragment Custom Animation
- Demonstrates the use of a custom animation for pushing and popping fragments
- on the back stack.
+ Action Bar Mechanics
+ Demonstrates the basics of the Action Bar and how it interoperates with the standard options
+menu. This demo is for informative purposes only; see Usage for an example of using the
+Action Bar in a more idiomatic manner.
- Fragment Dialog
- Demonstrates use of DialogFragment to show various types of dialogs.
-
- Fragment Dialog or Activity
- Demonstrates how the same Fragment implementation can be used to provide the UI
- for either an Activity or Dialog.
-
- Fragment Hide Show
- Demonstrates hiding and showing fragments.
-
- Fragment Layout
- Demonstrates use of the <fragment> tag to embed a Fragment in
- an Activity's content view layout, and making the layout change based on
- configuration to achieve different UI flows.
-
- Fragment List Array
- Demonstrates use of ListFragment to show the contents of a simple ArrayAdapter.
-
- Fragment Menu
- Demonstrates populating custom menu items from a Fragment.
-
- Fragment Pager Support
- Demonstrates the use of the support class ViewPager with a
- FragmentPagerAdapter to build a user interface where the user can fling
- left or right to switch between fragments.
+ Action Bar Tabs
+ Demonstrates the use of Action Bar tabs and how they interact with other action bar
+features. Also see the Fragment Tabs for a more
+complete example of how to switch between fragments.
- Fragment State Pager Support
- Demonstrates the use of the support class ViewPager with a
- FragmentStatePagerAdapter to build a user interface where the user can fling
- left or right to switch between fragments. This versions of the adapter
- doesn't keep around the fragment instances that ViewPager has destroyed.
+ Action Bar Usage
+ Demonstrates simple usage of the Action Bar, including a SearchView as an action item. 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
+Mechanics.
- Fragment Receive Result
- Demonstrates starting a new Activity from a Fragment, and receiving
- a result back from it.
-
- Fragment Retain Instance
- Demonstrates a Fragment can be used to easily retain active state across
- an Activity's configuration change.
-
- Fragment Stack
- Demonstrates creating a stack of Fragment instances similar to the
- traditional stack of activities.
-
- Fragment Tabs
- Demonstrates the use of fragments to implement switching between
- tabs in a TabHost.
-
- Fragment Tabs Pager
- Demonstrates the use of fragments to implement switching between
- tabs in a TabHost, using a ViewPager to manager the fragments so that
- the user can also fling left and right to switch tabs.
+ Settings Action Provider
+ Shows how to implement an ActionProvider for launching the system settings that supplies a
+ menu item with a specialized action view and handles standard menu item clicks in one place.
+ Display Options
+ Shows how various Action Bar display option flags can be combined and their effects.
-
-LoaderManager
-
- Loader Cursor
- Demonstrates use of LoaderManager to perform a query for a Cursor that
- populates a ListFragment.
-
- Loader Custom
- Demonstrates implementation and use of a custom Loader class. The
- custom class here "loads" the currently installed applications.
-
- Loader Throttle
- Complete end-to-end demonstration of a simple content provider that
- populates data in a list through a cursor loader. The UI allows the list
- to be populated with a series of items, showing how AsyncTaskLoader's
- throttling facility can be used to control how much a Loader is refreshed
- in this case.
-
-
\ No newline at end of file
diff --git a/samples/Support7Demos/src/com/example/android/supportv7/media/_index.html b/samples/Support7Demos/src/com/example/android/supportv7/media/_index.html
index a443287cc..0802cae76 100644
--- a/samples/Support7Demos/src/com/example/android/supportv7/media/_index.html
+++ b/samples/Support7Demos/src/com/example/android/supportv7/media/_index.html
@@ -2,20 +2,20 @@
This section includes samples showing the use of the application
package features of the static support library.
-
+
Media Route Provider
Demonstrates how to implement a MediaRouteProvider to discover,
publish and control custom media routes.
-
+
Media Route Provider Service
Demonstrates how to make a MediaRouteProvider available to all
running applications by registering it as a service.
-
+
Media Router Activity
Demonstrates how to use MediaRouter within an Activity to support
remote media playback.
diff --git a/samples/Support7Demos/src/com/example/android/supportv7/view/_index.html b/samples/Support7Demos/src/com/example/android/supportv7/view/_index.html
new file mode 100644
index 000000000..072967a1a
--- /dev/null
+++ b/samples/Support7Demos/src/com/example/android/supportv7/view/_index.html
@@ -0,0 +1,22 @@
+
+This section includes samples showing the use of the view
+package features of the static support library.
+
+
+
+Grid Layout
+
+ Grid Layout Simple Form
+ Demonstrates how to use GridLayout to create a simple data entry form.
+
+ Grid Layout Form (XML)
+ Demonstrates how to use GridLayout to create a more complex
+ data entry form using XML layout resources.
+
+ Grid Layout Form (Java)
+ Demonstrates how to use GridLayout to create a more complex
+ data entry form programmatically.
+
+
\ No newline at end of file