Search in sources :

Example 21 with Fragment

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();
}
Also used : FragmentTransaction(android.app.FragmentTransaction) Fragment(android.app.Fragment)

Example 22 with Fragment

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);
}
Also used : Bundle(android.os.Bundle) Robolectric.setupActivity(org.robolectric.Robolectric.setupActivity) Robolectric.buildActivity(org.robolectric.Robolectric.buildActivity) Activity(android.app.Activity) Intent(android.content.Intent) Fragment(android.app.Fragment) Test(org.junit.Test)

Example 23 with Fragment

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;
    }
}
Also used : Fragment(android.app.Fragment)

Example 24 with 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;
}
Also used : Fragment(android.app.Fragment)

Example 25 with 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);
                }
            }
        }
    }
}
Also used : Bundle(android.os.Bundle) Parcelable(android.os.Parcelable) Fragment(android.app.Fragment)

Aggregations

Fragment (android.app.Fragment)209 FragmentTransaction (android.app.FragmentTransaction)82 FragmentManager (android.app.FragmentManager)51 DialogFragment (android.app.DialogFragment)44 Bundle (android.os.Bundle)22 Intent (android.content.Intent)13 View (android.view.View)13 PreferenceFragment (android.support.v14.preference.PreferenceFragment)12 TextView (android.widget.TextView)8 BizFragment (org.aisen.weibo.sina.ui.fragment.base.BizFragment)8 Uri (android.net.Uri)6 ABaseFragment (org.aisen.android.ui.fragment.ABaseFragment)6 Activity (android.app.Activity)5 PreferenceFragment (android.preference.PreferenceFragment)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ViewGroup (android.view.ViewGroup)3 FrameLayout (android.widget.FrameLayout)3 ContactVcardViewerFragment (com.xabber.android.ui.fragment.ContactVcardViewerFragment)3 Method (java.lang.reflect.Method)3