use of android.app.Fragment in project platform_frameworks_base by android.
the class PreferenceActivity method switchToHeaderInner.
private void switchToHeaderInner(String fragmentName, Bundle args) {
getFragmentManager().popBackStack(BACK_STACK_PREFS, FragmentManager.POP_BACK_STACK_INCLUSIVE);
if (!isValidFragment(fragmentName)) {
throw new IllegalArgumentException("Invalid fragment for this activity: " + fragmentName);
}
Fragment f = Fragment.instantiate(this, fragmentName, args);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
transaction.replace(com.android.internal.R.id.prefs, f);
transaction.commitAllowingStateLoss();
}
use of android.app.Fragment in project robolectric by robolectric.
the class ShadowActivityTest method canStartActivityFromFragment_withBundle.
@Test
public void canStartActivityFromFragment_withBundle() {
final Activity activity = buildActivity(Activity.class).create().get();
Bundle options = new Bundle();
Intent intent = new Intent(Intent.ACTION_VIEW);
activity.startActivityFromFragment(new Fragment(), intent, 5, options);
ShadowActivity.IntentForResult intentForResult = shadowOf(activity).getNextStartedActivityForResult();
assertThat(intentForResult.intent).isSameAs(intent);
assertThat(intentForResult.options).isSameAs(options);
assertThat(intentForResult.requestCode).isEqualTo(5);
}
use of android.app.Fragment in project android-support-v4-googlemaps by petedoyle.
the class FragmentPagerAdapter method setPrimaryItem.
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
Fragment fragment = (Fragment) object;
if (fragment != mCurrentPrimaryItem) {
if (mCurrentPrimaryItem != null) {
FragmentCompat.setMenuVisibility(mCurrentPrimaryItem, false);
FragmentCompat.setUserVisibleHint(mCurrentPrimaryItem, false);
}
if (fragment != null) {
FragmentCompat.setMenuVisibility(fragment, true);
FragmentCompat.setUserVisibleHint(fragment, true);
}
mCurrentPrimaryItem = fragment;
}
}
use of android.app.Fragment in project android-support-v4-googlemaps by petedoyle.
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 (DEBUG)
Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
if (mSavedState.size() > position) {
Fragment.SavedState fss = mSavedState.get(position);
if (fss != null) {
fragment.setInitialSavedState(fss);
}
}
while (mFragments.size() <= position) {
mFragments.add(null);
}
FragmentCompat.setMenuVisibility(fragment, false);
FragmentCompat.setUserVisibleHint(fragment, false);
mFragments.set(position, fragment);
mCurTransaction.add(container.getId(), fragment);
return fragment;
}
use of android.app.Fragment in project android-support-v4-googlemaps by petedoyle.
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);
}
FragmentCompat.setMenuVisibility(f, false);
mFragments.set(index, f);
} else {
Log.w(TAG, "Bad fragment at key " + key);
}
}
}
}
}
Aggregations