resolved conflicts for merge of ce28e097 to master

Change-Id: Iced68c2dbae177b59aa6f3862868e68836be2afd
This commit is contained in:
Dianne Hackborn
2011-06-13 17:21:25 -07:00
25 changed files with 1582 additions and 8 deletions

View File

@@ -78,6 +78,11 @@ public class ActionBarTabs extends Activity {
* 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;

View File

@@ -0,0 +1,116 @@
/*
* 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.apis.app;
import com.example.android.apis.R;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.widget.Toast;
/**
* This demonstrates the use of action bar tabs and how they interact
* with other action bar features.
*/
public class FragmentTabs extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
bar.addTab(bar.newTab()
.setText("Simple")
.setTabListener(new TabListener<FragmentStack.CountingFragment>(
this, "simple", FragmentStack.CountingFragment.class)));
bar.addTab(bar.newTab()
.setText("Contacts")
.setTabListener(new TabListener<LoaderCursor.CursorLoaderListFragment>(
this, "contacts", LoaderCursor.CursorLoaderListFragment.class)));
bar.addTab(bar.newTab()
.setText("Apps")
.setTabListener(new TabListener<LoaderCustom.AppListFragment>(
this, "apps", LoaderCustom.AppListFragment.class)));
bar.addTab(bar.newTab()
.setText("Throttle")
.setTabListener(new TabListener<LoaderThrottle.ThrottledLoaderListFragment>(
this, "throttle", LoaderThrottle.ThrottledLoaderListFragment.class)));
if (savedInstanceState != null) {
bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("tab", getActionBar().getSelectedNavigationIndex());
}
public static class TabListener<T extends Fragment> implements ActionBar.TabListener {
private final Activity mActivity;
private final String mTag;
private final Class<T> mClass;
private final Bundle mArgs;
private Fragment mFragment;
public TabListener(Activity activity, String tag, Class<T> clz) {
this(activity, tag, clz, null);
}
public TabListener(Activity activity, String tag, Class<T> clz, Bundle args) {
mActivity = activity;
mTag = tag;
mClass = clz;
mArgs = args;
// Check to see if we already have a fragment for this tab, probably
// from a previously saved state. If so, deactivate it, because our
// initial state is that a tab isn't shown.
mFragment = mActivity.getFragmentManager().findFragmentByTag(mTag);
if (mFragment != null && !mFragment.isDetached()) {
FragmentTransaction ft = mActivity.getFragmentManager().beginTransaction();
ft.detach(mFragment);
ft.commit();
}
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (mFragment == null) {
mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
ft.add(android.R.id.content, mFragment, mTag);
} else {
ft.attach(mFragment);
}
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
if (mFragment != null) {
ft.detach(mFragment);
}
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
Toast.makeText(mActivity, "Reselected!", Toast.LENGTH_SHORT).show();
}
}
}

View File

@@ -159,7 +159,11 @@ public class LoaderCursor extends Activity {
mAdapter.swapCursor(data);
// The list should now be shown.
setListShown(true);
if (isResumed()) {
setListShown(true);
} else {
setListShownNoAnimation(true);
}
}
public void onLoaderReset(Loader<Cursor> loader) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 The Android Open Source Project
* 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.
@@ -466,7 +466,11 @@ public class LoaderCustom extends Activity {
mAdapter.setData(data);
// The list should now be shown.
setListShown(true);
if (isResumed()) {
setListShown(true);
} else {
setListShownNoAnimation(true);
}
}
@Override public void onLoaderReset(Loader<List<AppEntry>> loader) {

View File

@@ -409,6 +409,9 @@ public class LoaderThrottle extends Activity {
new int[] { android.R.id.text1 }, 0);
setListAdapter(mAdapter);
// Start out with a progress indicator.
setListShown(false);
// Prepare the loader. Either re-connect with an existing one,
// or start a new one.
getLoaderManager().initLoader(0, null, this);
@@ -492,6 +495,13 @@ public class LoaderThrottle extends Activity {
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
mAdapter.swapCursor(data);
// The list should now be shown.
if (isResumed()) {
setListShown(true);
} else {
setListShownNoAnimation(true);
}
}
public void onLoaderReset(Loader<Cursor> loader) {

View File

@@ -134,6 +134,10 @@
<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 implementing ActionBar tabs by switching between
Fragments.</dd>
</dl>
@@ -145,9 +149,10 @@ menu. This demo is for informative purposes only; see Usage for an example of us
Action Bar in a more idiomatic manner.</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.</dd>
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="ActionBarUsage.html">Action Bar Usage</a></dt>
<dd>Demonstrates imple usage of the Action Bar, including a SearchView as an action item. The
<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>
@@ -162,6 +167,10 @@ Mechanics.</dd>
<dd>Demonstrates use of LoaderManager to perform a query for a Cursor that
populates a ListFragment.</dd>
<dt><a href="LoaderCustom.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="LoaderThrottle.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