Add action bar support library samples.

These samples are simply ported from the ApiDemos package
with package names updated to use the support library
implementation instead.

Bug: 8175766
Change-Id: Idfa35708d4db65a201a20c3726bb18663c2c0a81
This commit is contained in:
Jeff Brown
2013-03-20 18:14:48 -07:00
parent 63c90a5512
commit 84e6be0c69
24 changed files with 973 additions and 104 deletions

View File

@@ -49,7 +49,7 @@
android:label="@string/sample_media_router_activity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.supportv7.SUPPORT4_SAMPLE_CODE" />
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
</intent-filter>
</activity>
@@ -63,24 +63,74 @@
<!-- GridLayout Support Samples -->
<activity android:name=".view.GridLayout1" android:label="Views/Layouts/GridLayout/1. Simple Form">
<activity android:name=".view.GridLayout1"
android:label="@string/grid_layout_1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.supportv7.SUPPORT4_SAMPLE_CODE" />
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
</intent-filter>
</activity>
<activity android:name=".view.GridLayout2" android:label="Views/Layouts/GridLayout/2. Form (XML)">
<activity android:name=".view.GridLayout2"
android:label="@string/grid_layout_2">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.supportv7.SUPPORT4_SAMPLE_CODE" />
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
</intent-filter>
</activity>
<activity android:name=".view.GridLayout3" android:label="Views/Layouts/GridLayout/3. Form (Java)">
<activity android:name=".view.GridLayout3"
android:label="@string/grid_layout_3">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.supportv7.SUPPORT4_SAMPLE_CODE" />
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
</intent-filter>
</activity>
<!-- Action Bar Samples -->
<activity android:name=".app.ActionBarMechanics"
android:label="@string/action_bar_mechanics"
android:theme="@style/Theme.AppCompat">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
</intent-filter>
</activity>
<activity android:name=".app.ActionBarUsage"
android:label="@string/action_bar_usage"
android:theme="@style/Theme.AppCompat">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
</intent-filter>
</activity>
<activity android:name=".app.ActionBarDisplayOptions"
android:label="@string/action_bar_display_options"
android:logo="@drawable/apidemo_androidlogo"
android:theme="@style/Theme.AppCompat">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
</intent-filter>
</activity>
<activity android:name=".app.ActionBarTabs"
android:label="@string/action_bar_tabs"
android:theme="@style/Theme.AppCompat">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
</intent-filter>
</activity>
<activity android:name=".app.ActionBarSettingsActionProviderActivity"
android:label="@string/action_bar_settings_action_provider"
android:theme="@style/Theme.AppCompat">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.example.android.supportv7.SAMPLE_CODE" />
</intent-filter>
</activity>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@@ -0,0 +1,59 @@
<?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.
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout 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" />
<Button android:id="@+id/toggle_visibility"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/toggle_visibility" />
<Button android:id="@+id/toggle_system_ui"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/toggle_system_ui" />
</LinearLayout>
</ScrollView>

View File

@@ -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" />

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:focusable="true"
android:addStatesFromChildren="true"
android:background="?android:attr/actionBarItemBackground"
style="?android:attr/actionButtonStyle">
<ImageButton android:id="@+id/button"
android:background="@drawable/ic_launcher_settings"
android:layout_width="32dip"
android:layout_height="32dip"
android:layout_gravity="center"
android:scaleType="fitCenter"
android:adjustViewBounds="true" />
</LinearLayout>

View File

@@ -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.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

View File

@@ -0,0 +1,49 @@
<?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">
<FrameLayout android:id="@+id/fragment_content"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<LinearLayout android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:orientation="vertical">
<Button android:id="@+id/btn_add_tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_add_tab"
android:onClick="onAddTab" />
<Button android:id="@+id/btn_remove_tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_remove_tab"
android:onClick="onRemoveTab" />
<Button android:id="@+id/btn_toggle_tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_toggle_tabs"
android:onClick="onToggleTabs" />
<Button android:id="@+id/btn_remove_all_tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_remove_all_tabs"
android:onClick="onRemoveAllTabs" />
</LinearLayout>
</LinearLayout>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 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"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/menu_item_action_provider_action_bar"
android:title="@string/action_bar_settings"
app:showAsAction="ifRoom"
app:actionProviderClass="com.example.android.supportv7.app.ActionBarSettingsActionProviderActivity$SettingsActionProvider"/>
<item android:id="@+id/menu_item_action_provider_overflow"
android:title="@string/action_bar_settings"
app:showAsAction="never"
app:actionProviderClass="com.example.android.supportv7.app.ActionBarSettingsActionProviderActivity$SettingsActionProvider"/>
</menu>

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2010 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"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_search"
android:icon="@android:drawable/ic_menu_search"
android:title="@string/action_bar_search"
app:showAsAction="ifRoom"
app:actionProviderClass="android.support.v7.widget.SearchActionProvider" />
<item android:id="@+id/action_add"
android:icon="@android:drawable/ic_menu_add"
android:title="@string/action_bar_add" />
<item android:id="@+id/action_edit"
android:icon="@android:drawable/ic_menu_edit"
android:title="@string/action_bar_edit"
app:showAsAction="always" />
<item android:id="@+id/action_share"
android:icon="@android:drawable/ic_menu_share"
android:title="@string/action_bar_share"
app:showAsAction="ifRoom" />
<item android:id="@+id/action_sort"
android:icon="@android:drawable/ic_menu_sort_by_size"
android:title="@string/action_bar_sort"
app: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>

View File

@@ -0,0 +1,20 @@
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/simple_item"
android:title="@string/display_options_menu_item" />
</menu>

View File

@@ -14,7 +14,8 @@
limitations under the License.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- TODO: Use MediaRouter support library -->
<item android:id="@+id/menu_media_route"
android:title="@string/sample_media_router_play_on"

View File

@@ -19,7 +19,7 @@
<!-- MediaRouter -->
<string name="sample_media_router_activity">Media/MediaRouter</string>
<string name="sample_media_router_activity">MediaRouter</string>
<string name="sample_media_router_text">This activity demonstrates how to
use MediaRouter from the support library. Select a route from the action bar.</string>
<string name="sample_media_router_play_on">Play on...</string>
@@ -32,8 +32,49 @@
<string name="variable_volume_route_name">Variable Volume Remote Playback Route</string>
<!-- GridLayout -->
<string name="grid_layout_1">GridLayout/1. Simple Form</string>
<string name="grid_layout_2">GridLayout/2. Form (XML)</string>
<string name="grid_layout_3">GridLayout/3. Form (Java)</string>
<string name="grid_layout_1_instructions">Type here:</string>
<string name="grid_layout_1_ok">Ok</string>
<string name="grid_layout_1_cancel">Cancel</string>
<!-- ActionBar -->
<string name="action_bar_mechanics">AppCompat/Action Bar/Action Bar Mechanics</string>
<string name="action_bar_usage">AppCompat/Action Bar/Action Bar Usage</string>
<string name="action_bar_tabs">AppCompat/Action Bar/Action Bar Tabs</string>
<string name="action_bar_settings_action_provider">AppCompat/Action Bar/Settings Action Provider</string>
<string name="action_bar_settings_action_provider_no_handling">Handling in onOptionsItemSelected avoided</string>
<string name="action_bar_search">Search</string>
<string name="action_bar_add">Add</string>
<string name="action_bar_edit">Edit</string>
<string name="action_bar_share">Share</string>
<string name="action_bar_sort">Sort</string>
<string name="action_bar_sort_alpha">Alphabetically</string>
<string name="action_bar_sort_size">By size</string>
<string name="action_bar_settings">Settings</string>
<string name="action_bar_display_options">AppCompat/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="toggle_visibility">Toggle Visibility</string>
<string name="toggle_system_ui">Toggle System UI</string>
<string name="display_options_custom_button">Custom View!</string>
<string name="display_options_menu_item">Menu Item</string>
<string name="btn_add_tab">Add new tab</string>
<string name="btn_remove_tab">Remove last tab</string>
<string name="btn_toggle_tabs">Toggle tab mode</string>
<string name="btn_remove_all_tabs">Remove all tabs</string>
</resources>

View File

@@ -56,7 +56,7 @@ public class Support7Demos extends ListActivity {
List<Map<String, Object>> myData = new ArrayList<Map<String, Object>>();
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<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);

View File

@@ -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) {
}
}

View File

@@ -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 <item name="android:windowActionBar">true</item>
// 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;
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
};
}

View File

@@ -1,102 +1,33 @@
<p>This section includes samples showing the use of the application
package features of the static support library, in particular fragments
and loaders.</p>
package features of the static support library.</p>
<ul>
<li><a href="#Fragment">Fragment</a></li>
<li><a href="#LoaderManager">LoaderManager</a></li>
<li><a href="#ActionBar">Action Bar</a></li>
</ul>
<h3 id="Fragment">Fragment</h3>
<h3 id="ActionBar">Action Bar</h3>
<dl>
<dt><a href="FragmentAlertDialogSupport.html">Fragment Alert Dialog</a></dt>
<dd>Demonstrates how to use a DialogFragment to show and manage an
AlertDialog.</dd>
<dt><a href="FragmentArgumentsSupport.html">Fragment Arguments</a></dt>
<dd>Demonstrates how a fragment can be initialized with arguments,
supplying them either as an argument Bundle at runtime or XML attributes
in a &lt;fragment> tag.</dd>
<dt><a href="FragmentContextMenuSupport.html">Fragment Context Menu</a></dt>
<dd>Demonstrates how to display and respond to a context menu that is
display from a fragment's view hierarchy.</dd>
<dt><a href="FragmentCustomAnimationSupport.html">Fragment Custom Animation</a></dt>
<dd>Demonstrates the use of a custom animation for pushing and popping fragments
on the back stack.</dd>
<dt><a href="ActionBarMechanics.html">Action Bar Mechanics</a></dt>
<dd>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.</dd>
<dt><a href="FragmentDialogSupport.html">Fragment Dialog</a></dt>
<dd>Demonstrates use of DialogFragment to show various types of dialogs.</dd>
<dt><a href="FragmentDialogOrActivitySupport.html">Fragment Dialog or Activity</a></dt>
<dd>Demonstrates how the same Fragment implementation can be used to provide the UI
for either an Activity or Dialog.</dd>
<dt><a href="FragmentHideShowSupport.html">Fragment Hide Show</a></dt>
<dd>Demonstrates hiding and showing fragments.</dd>
<dt><a href="FragmentLayoutSupport.html">Fragment Layout</a></dt>
<dd>Demonstrates use of the &lt;fragment&gt; 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.</dd>
<dt><a href="FragmentListArraySupport.html">Fragment List Array</a></dt>
<dd>Demonstrates use of ListFragment to show the contents of a simple ArrayAdapter.</dd>
<dt><a href="FragmentMenuSupport.html">Fragment Menu</a></dt>
<dd>Demonstrates populating custom menu items from a Fragment.</dd>
<dt><a href="FragmentPagerSupport.html">Fragment Pager Support</a></dt>
<dd>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.</dd>
<dt><a href="ActionBarTabs.html">Action Bar Tabs</a></dt>
<dd>Demonstrates the use of Action Bar tabs and how they interact with other action bar
features. Also see the <a href="FragmentTabs.html">Fragment Tabs</a> for a more
complete example of how to switch between fragments.</dd>
<dt><a href="FragmentStatePagerSupport.html">Fragment State Pager Support</a></dt>
<dd>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.</dd>
<dt><a href="ActionBarUsage.html">Action Bar Usage</a></dt>
<dd>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.</dd>
<dt><a href="FragmentReceiveResultSupport.html">Fragment Receive Result</a></dt>
<dd>Demonstrates starting a new Activity from a Fragment, and receiving
a result back from it.</dd>
<dt><a href="FragmentRetainInstanceSupport.html">Fragment Retain Instance</a></dt>
<dd>Demonstrates a Fragment can be used to easily retain active state across
an Activity's configuration change.</dd>
<dt><a href="FragmentStackSupport.html">Fragment Stack</a></dt>
<dd>Demonstrates creating a stack of Fragment instances similar to the
traditional stack of activities.</dd>
<dt><a href="FragmentTabs.html">Fragment Tabs</a></dt>
<dd>Demonstrates the use of fragments to implement switching between
tabs in a TabHost.</dd>
<dt><a href="FragmentTabsPager.html">Fragment Tabs Pager</a></dt>
<dd>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.</dd>
<dt><a href="ActionBarActionProviderSettingsActivity.html">Settings Action Provider</a></dt>
<dd>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.</dd>
<dt><a href="ActionBarDisplayOptions.html">Display Options</a></dt>
<dd>Shows how various Action Bar display option flags can be combined and their effects.</dd>
</dl>
<h3 id="LoaderManager">LoaderManager</h3>
<dl>
<dt><a href="LoaderCursorSupport.html">Loader Cursor</a></dt>
<dd>Demonstrates use of LoaderManager to perform a query for a Cursor that
populates a ListFragment.</dd>
<dt><a href="LoaderCustomSupport.html">Loader Custom</a></dt>
<dd>Demonstrates implementation and use of a custom Loader class. The
custom class here "loads" the currently installed applications.</dd>
<dt><a href="LoaderThrottleSupport.html">Loader Throttle</a></dt>
<dd>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.</dd>
</dl>

View File

@@ -2,20 +2,20 @@
<p>This section includes samples showing the use of the application
package features of the static support library.</p>
<ul>
<li><a href="#MediaRouter">MediaRouter</a></li>
<li><a href="#MediaRouter">Media Router</a></li>
</ul>
<h3 id="MediaRouter">MediaRouter</h3>
<h3 id="MediaRouter">Media Router</h3>
<dl>
<dt><a href="SampleMediaRouteProvider.html">Media Route Provider</a></dt>
<dd>Demonstrates how to implement a MediaRouteProvider to discover,
publish and control custom media routes.</dd>
<dt><a href="SampleMediaRouteProviderService.html">Media Route Provider Service</a></dt>
<dd>Demonstrates how to make a MediaRouteProvider available to all
running applications by registering it as a service.</dd>
<dt><a href="SampleMediaRouterActivity.html">Media Router Activity</a></dt>
<dd>Demonstrates how to use MediaRouter within an Activity to support
remote media playback.</dd>

View File

@@ -0,0 +1,22 @@
<p>This section includes samples showing the use of the view
package features of the static support library.</p>
<ul>
<li><a href="#GridLayout">Grid Layout</a></li>
</ul>
<h3 id="GridLayout">Grid Layout</h3>
<dl>
<dt><a href="GridLayout1.html">Grid Layout Simple Form</a></dt>
<dd>Demonstrates how to use GridLayout to create a simple data entry form.</dd>
<dt><a href="GridLayout2.html">Grid Layout Form (XML)</a></dt>
<dd>Demonstrates how to use GridLayout to create a more complex
data entry form using XML layout resources.</dd>
<dt><a href="GridLayout3.html">Grid Layout Form (Java)</a></dt>
<dd>Demonstrates how to use GridLayout to create a more complex
data entry form programmatically.</dd>
</dl>