Search in sources :

Example 31 with FragmentManager

use of android.support.v4.app.FragmentManager in project Fragmentation by YoKeyword.

the class SupportFragment method dispatchSupportVisible.

private void dispatchSupportVisible(boolean visible) {
    mIsSupportVisible = visible;
    if (!mNeedDispatch) {
        mNeedDispatch = true;
    } else {
        FragmentManager fragmentManager = getChildFragmentManager();
        if (fragmentManager != null) {
            List<Fragment> childFragments = fragmentManager.getFragments();
            if (childFragments != null) {
                for (Fragment child : childFragments) {
                    if (child instanceof SupportFragment && !child.isHidden() && child.getUserVisibleHint()) {
                        ((SupportFragment) child).dispatchSupportVisible(visible);
                    }
                }
            }
        }
    }
    if (visible) {
        if (mIsFirstVisible) {
            mIsFirstVisible = false;
            onLazyInitView(mSaveInstanceState);
            dispatchFragmentLifecycle(LifecycleHelper.LIFECYLCE_ONLAZYINITVIEW, null, false);
        }
        onSupportVisible();
        if (_mActivity != null) {
            _mActivity.setFragmentClickable(true);
        }
        dispatchFragmentLifecycle(LifecycleHelper.LIFECYLCE_ONSUPPORTVISIBLE, null, true);
    } else {
        onSupportInvisible();
        dispatchFragmentLifecycle(LifecycleHelper.LIFECYLCE_ONSUPPORTINVISIBLE, null, false);
    }
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) Fragment(android.support.v4.app.Fragment)

Example 32 with FragmentManager

use of android.support.v4.app.FragmentManager in project Android-Developers-Samples by johnjohndoe.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    FragmentManager fm = getSupportFragmentManager();
    BatchStepSensorFragment fragment = (BatchStepSensorFragment) fm.findFragmentByTag(FRAGTAG);
    if (fragment == null) {
        FragmentTransaction transaction = fm.beginTransaction();
        fragment = new BatchStepSensorFragment();
        transaction.add(fragment, FRAGTAG);
        transaction.commit();
    }
    // Use fragment as click listener for cards, but must implement correct interface
    if (!(fragment instanceof OnCardClickListener)) {
        throw new ClassCastException("BatchStepSensorFragment must " + "implement OnCardClickListener interface.");
    }
    OnCardClickListener clickListener = (OnCardClickListener) fm.findFragmentByTag(FRAGTAG);
    mRetentionFragment = (StreamRetentionFragment) fm.findFragmentByTag(RETENTION_TAG);
    if (mRetentionFragment == null) {
        mRetentionFragment = new StreamRetentionFragment();
        fm.beginTransaction().add(mRetentionFragment, RETENTION_TAG).commit();
    } else {
        // If the retention fragment already existed, we need to pull some state.
        // pull state out
        CardStreamState state = mRetentionFragment.getCardStream();
        // dump it in CardStreamFragment.
        mCardStreamFragment = (CardStreamFragment) fm.findFragmentById(R.id.fragment_cardstream);
        mCardStreamFragment.restoreState(state, clickListener);
    }
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction) CardStreamState(com.example.android.batchstepsensor.cardstream.CardStreamState) StreamRetentionFragment(com.example.android.batchstepsensor.cardstream.StreamRetentionFragment) OnCardClickListener(com.example.android.batchstepsensor.cardstream.OnCardClickListener)

Example 33 with FragmentManager

use of android.support.v4.app.FragmentManager in project nucleus by konmik.

the class FragmentStackTest method testFindCallback.

@UiThreadTest
public void testFindCallback() throws Exception {
    FragmentManager manager = activity.getSupportFragmentManager();
    FragmentStack stack = new FragmentStack(activity, manager, CONTAINER_ID);
    TestFragmentC fragment = new TestFragmentC();
    stack.push(fragment);
    TestFragment2 fragment2 = new TestFragment2();
    stack.push(fragment2);
    assertEquals(fragment, stack.findCallback(fragment2, TestCallback.class));
    assertEquals(activity, stack.findCallback(fragment2, Activity.class));
    assertNull(stack.findCallback(fragment2, String.class));
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) TestActivity(nucleus.example.TestActivity) Activity(android.app.Activity) UiThreadTest(android.test.UiThreadTest)

Example 34 with FragmentManager

use of android.support.v4.app.FragmentManager in project nucleus by konmik.

the class FragmentStackTest method testBack.

@UiThreadTest
public void testBack() throws Exception {
    FragmentManager manager = activity.getSupportFragmentManager();
    FragmentStack stack = new FragmentStack(activity, manager, CONTAINER_ID);
    assertFalse(stack.back());
    stack.push(new TestFragment1());
    assertEquals(1, stack.size());
    assertFalse(stack.back());
    stack.push(new TestFragment1());
    assertEquals(2, stack.size());
    assertTrue(stack.back());
    assertEquals(1, stack.size());
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) UiThreadTest(android.test.UiThreadTest)

Example 35 with FragmentManager

use of android.support.v4.app.FragmentManager in project Android-ObservableScrollView by ksoichiro.

the class FragmentActionBarControlListViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fragmentactionbarcontrol);
    FragmentManager fm = getSupportFragmentManager();
    if (fm.findFragmentByTag(FragmentTransitionDefaultFragment.FRAGMENT_TAG) == null) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(R.id.container, new FragmentActionBarControlListViewFragment(), FragmentActionBarControlListViewFragment.FRAGMENT_TAG);
        ft.commit();
        fm.executePendingTransactions();
    }
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction)

Aggregations

FragmentManager (android.support.v4.app.FragmentManager)265 FragmentTransaction (android.support.v4.app.FragmentTransaction)98 Fragment (android.support.v4.app.Fragment)76 View (android.view.View)46 TextView (android.widget.TextView)34 OnClickListener (android.view.View.OnClickListener)24 Bundle (android.os.Bundle)23 Intent (android.content.Intent)20 ImageView (android.widget.ImageView)15 ScrollView (android.widget.ScrollView)14 DialogFragment (android.support.v4.app.DialogFragment)13 ListFragment (android.support.v4.app.ListFragment)12 Button (android.widget.Button)11 FragmentActivity (android.support.v4.app.FragmentActivity)6 ArrayList (java.util.ArrayList)6 ViewPager (android.support.v4.view.ViewPager)5 UiThreadTest (android.test.UiThreadTest)5 BackStackEntry (android.support.v4.app.FragmentManager.BackStackEntry)4 AppCompatActivity (android.support.v7.app.AppCompatActivity)4 Time (android.text.format.Time)4