use of android.app.Fragment in project AppIntro by apl-devs.
the class FragmentStatePagerAdapter method destroyItem.
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
Fragment fragment = (Fragment) object;
if (mCurTransaction == null) {
mCurTransaction = mFragmentManager.beginTransaction();
}
while (mSavedState.size() <= position) {
mSavedState.add(null);
}
mSavedState.set(position, fragment.isAdded() ? mFragmentManager.saveFragmentInstanceState(fragment) : null);
mFragments.set(position, null);
mCurTransaction.remove(fragment);
}
use of android.app.Fragment in project AppIntro by apl-devs.
the class FragmentStatePagerAdapter method instantiateItem.
@Override
public Object instantiateItem(ViewGroup container, int position) {
// taken care of restoring the fragments we previously had instantiated.
if (mFragments.size() > position) {
Fragment f = mFragments.get(position);
if (f != null) {
return f;
}
}
if (mCurTransaction == null) {
mCurTransaction = mFragmentManager.beginTransaction();
}
Fragment fragment = getItem(position);
if (mSavedState.size() > position) {
Fragment.SavedState fss = mSavedState.get(position);
if (fss != null) {
fragment.setInitialSavedState(fss);
}
}
while (mFragments.size() <= position) {
mFragments.add(null);
}
fragment.setMenuVisibility(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
fragment.setUserVisibleHint(false);
}
mFragments.set(position, fragment);
mCurTransaction.add(container.getId(), fragment);
return fragment;
}
use of android.app.Fragment in project AppIntro by apl-devs.
the class FragmentStatePagerAdapter method restoreState.
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
if (state != null) {
Bundle bundle = (Bundle) state;
bundle.setClassLoader(loader);
Parcelable[] fss = bundle.getParcelableArray("states");
mSavedState.clear();
mFragments.clear();
if (fss != null) {
for (int i = 0; i < fss.length; i++) {
mSavedState.add((Fragment.SavedState) fss[i]);
}
}
Iterable<String> keys = bundle.keySet();
for (String key : keys) {
if (key.startsWith("f")) {
int index = Integer.parseInt(key.substring(1));
Fragment f = mFragmentManager.getFragment(bundle, key);
if (f != null) {
while (mFragments.size() <= index) {
mFragments.add(null);
}
f.setMenuVisibility(false);
mFragments.set(index, f);
}
}
}
}
}
use of android.app.Fragment in project AppIntro by apl-devs.
the class FragmentStatePagerAdapter method saveState.
@Override
public Parcelable saveState() {
Bundle state = null;
if (mSavedState.size() > 0) {
state = new Bundle();
Fragment.SavedState[] fss = new Fragment.SavedState[mSavedState.size()];
mSavedState.toArray(fss);
state.putParcelableArray("states", fss);
}
for (int i = 0; i < mFragments.size(); i++) {
Fragment f = mFragments.get(i);
if (f != null && f.isAdded()) {
if (state == null) {
state = new Bundle();
}
String key = "f" + i;
mFragmentManager.putFragment(state, key, f);
}
}
return state;
}
use of android.app.Fragment in project coursera-android by aporter.
the class DialtactsActivity method addSearchFragment.
/**
* Add search fragment. Note this is called during onLayout, so there's some restrictions,
* such as executePendingTransaction can't be used in it.
*/
private void addSearchFragment() {
// changes.
if (mSearchFragment != null)
return;
final FragmentTransaction ft = getFragmentManager().beginTransaction();
final Fragment searchFragment = new PhoneNumberPickerFragment();
searchFragment.setUserVisibleHint(false);
ft.add(R.id.dialtacts_frame, searchFragment);
ft.hide(searchFragment);
ft.commitAllowingStateLoss();
}
Aggregations