<?xml version="1.0" encoding="utf-8"?>
-<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_content_container"
android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:inAnimation="@android:anim/slide_in_left"
- android:outAnimation="@android:anim/slide_out_right" >
+ android:layout_height="fill_parent" >
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
+ <include layout="@layout/list_fragment" android:id="@+id/list_fragment" />
- <include layout="@layout/list_fragment" />
- </LinearLayout>
-
- <LinearLayout
- android:id="@+id/content"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" />
-
-</ViewSwitcher>
\ No newline at end of file
+</LinearLayout>
\ No newline at end of file
package com.koushikdutta.widgets;
+import junit.framework.Assert;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentManager.OnBackStackChangedListener;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
-import android.widget.ViewSwitcher;
public class ListContentFragmentInternal extends BetterListFragmentInternal {
ViewGroup mContent;
}
public boolean isPaged() {
- return mContainer instanceof ViewSwitcher;
+// return mContainer instanceof ViewSwitcher;
+ return mContent == null;
+ }
+
+ int getContentId() {
+ if (isPaged())
+ return R.id.list_content_container;
+ return R.id.content;
}
void setContentNative() {
android.app.Fragment f = (android.app.Fragment)mCurrentContent;
Activity fa = getActivity();
- android.app.FragmentTransaction ft = fa.getFragmentManager().beginTransaction();
- ft.replace(R.id.content, f);
- ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
- if (mContainer instanceof ViewSwitcher) {
- ViewSwitcher switcher = (ViewSwitcher)mContainer;
- if (mContent != switcher.getCurrentView())
- switcher.showNext();
+ final android.app.FragmentManager fm = fa.getFragmentManager();
+ android.app.FragmentTransaction ft = fm.beginTransaction();
+ if (isPaged()) {
+ final int curSize = fm.getBackStackEntryCount();
+ View v = getFragment().getView();
+ Assert.assertNotNull(v);
+ final View l = v.findViewById(R.id.list_fragment);
+ Assert.assertNotNull(l);
+ l.setVisibility(View.GONE);
+ fm.addOnBackStackChangedListener(new android.app.FragmentManager.OnBackStackChangedListener() {
+ @Override
+ public void onBackStackChanged() {
+ if (curSize != fm.getBackStackEntryCount())
+ return;
+ l.setVisibility(View.VISIBLE);
+ fm.removeOnBackStackChangedListener(this);
+ }
+ });
+ ft.addToBackStack("content");
}
+ ft.replace(getContentId(), f, "content");
+ ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
}
if (getActivity() instanceof FragmentActivity) {
Fragment f = (Fragment)mCurrentContent;
FragmentActivity fa = (FragmentActivity)getActivity();
+ final FragmentManager fm = fa.getSupportFragmentManager();
FragmentTransaction ft = fa.getSupportFragmentManager().beginTransaction();
- ft.replace(R.id.content, f);
- ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
- if (mContainer instanceof ViewSwitcher) {
- ViewSwitcher switcher = (ViewSwitcher)mContainer;
- if (mContent != switcher.getCurrentView())
- switcher.showNext();
+ if (isPaged()) {
+ final int curSize = fm.getBackStackEntryCount();
+ View v = getFragment().getView();
+ Assert.assertNotNull(v);
+ final View l = v.findViewById(R.id.list_fragment);
+ Assert.assertNotNull(l);
+ l.setVisibility(View.GONE);
+ fm.addOnBackStackChangedListener(new OnBackStackChangedListener() {
+ @Override
+ public void onBackStackChanged() {
+ if (curSize != fm.getBackStackEntryCount())
+ return;
+ l.setVisibility(View.VISIBLE);
+ fm.removeOnBackStackChangedListener(this);
+ }
+ });
+ ft.addToBackStack("content");
}
+ ft.replace(getContentId(), f, "content");
+ ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
}
else {
getListView().clearChoices();
}
- public void goBackNative() {
- android.app.Fragment f = (android.app.Fragment)mCurrentContent;
- Activity fa = getActivity();
- ((ViewSwitcher)mContainer).showPrevious();
- fa.getFragmentManager().beginTransaction()
- .remove(f)
- .commit();
- mCurrentContent = null;
- }
-
- public boolean onBackPressed() {
- if (mCurrentContent == null)
- return false;
- if (mContainer instanceof ViewSwitcher) {
- if (getActivity() instanceof FragmentActivity) {
- Fragment f = (Fragment)mCurrentContent;
- FragmentActivity fa = (FragmentActivity)getActivity();
- ((ViewSwitcher)mContainer).showPrevious();
- fa.getSupportFragmentManager().beginTransaction()
- .remove(f)
- .commit();
- mCurrentContent = null;
- return true;
- }
- else {
- goBackNative();
- return true;
- }
- }
- return false;
- }
-
@Override
protected int getListItemResource() {
return R.layout.list_item_selectable;
return R.layout.list_content;
}
- public ViewGroup getContent() {
- return mContent;
- }
-
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);