Java Code Examples for android.support.v4.app.fragmentmanager#FragmentLifecycleCallbacks

The following examples show how to use android.support.v4.app.fragmentmanager#FragmentLifecycleCallbacks . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivityLifecycle.java    From MVVMArms with Apache License 2.0 6 votes vote down vote up
/**
 * 给每个 Activity 的所有 Fragment 设置监听其生命周期, Activity 可以通过 {@link IActivity#useFragment()}
 * 设置是否使用监听,如果这个 Activity 返回 false 的话,这个 Activity 下面的所有 Fragment 将不能使用 {@link FragmentDelegate}
 *
 * @param activity: Activity
 */
private void registerFragmentCallbacks(Activity activity) {
    boolean useFragment = !(activity instanceof IActivity) || ((IActivity) activity).useFragment();
    if (activity instanceof FragmentActivity && useFragment) {

        if (mFragmentLifecycle == null) {
            mFragmentLifecycle = new FragmentLifecycle();
        }

        ((FragmentActivity) activity).getSupportFragmentManager().registerFragmentLifecycleCallbacks(mFragmentLifecycle, true);

        if (mFragmentLifecycles == null && mExtras.containsKey(ConfigLifecycle.class.getName())) {
            mFragmentLifecycles = new ArrayList<>();
            List<ConfigLifecycle> lifecycles = (List<ConfigLifecycle>) mExtras.get(ConfigLifecycle.class.getName());
            for (ConfigLifecycle lifecycle : lifecycles) {
                lifecycle.injectFragmentLifecycle(mApplication, mFragmentLifecycles);
            }
            mExtras.remove(ConfigLifecycle.class.getName());
        }

        for (FragmentManager.FragmentLifecycleCallbacks fragmentLifecycle : mFragmentLifecycles) {
            ((FragmentActivity) activity).getSupportFragmentManager()
                    .registerFragmentLifecycleCallbacks(fragmentLifecycle, true);
        }
    }
}
 
Example 2
Source File: ActivityLifecycle.java    From Aurora with Apache License 2.0 6 votes vote down vote up
/**
 * 给每个 Activity 的所有 Fragment 设置监听其生命周期, Activity 可以通过 {@link IActivity#useFragment()}
 * 设置是否使用监听,如果这个 Activity 返回 false 的话,这个 Activity 下面的所有 Fragment 将不能使用 {@link FragmentDelegate}
 * 意味着 {@link BaseFragment} 也不能使用
 *
 * @param activity
 */
private void registerFragmentCallbacks(Activity activity) {
    boolean useFragment = activity instanceof IActivity ? ((IActivity) activity).useFragment() : true;
    if (activity instanceof FragmentActivity && useFragment) {

        if (mFragmentLifecycle == null) {
            mFragmentLifecycle = new FragmentLifecycle();
        }

        ((FragmentActivity) activity).getSupportFragmentManager().registerFragmentLifecycleCallbacks(mFragmentLifecycle, true);

        if (mFragmentLifecycles == null && mExtras.containsKey(ConfigModule.class.getName())) {
            mFragmentLifecycles = new ArrayList<>();
            List<ConfigModule> modules = (List<ConfigModule>) mExtras.get(ConfigModule.class.getName());
            for (ConfigModule module : modules) {
                module.injectFragmentLifecycle(mApplication, mFragmentLifecycles);
            }
            mExtras.remove(ConfigModule.class.getName());
        }

        for (FragmentManager.FragmentLifecycleCallbacks fragmentLifecycle : mFragmentLifecycles) {
            ((FragmentActivity) activity).getSupportFragmentManager().registerFragmentLifecycleCallbacks(fragmentLifecycle, true);
        }
    }
}
 
Example 3
Source File: GlobalConfiguration.java    From Hands-Chopping with Apache License 2.0 6 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    //当所有模块集成到宿主 App 时, 在 App 中已经执行了以下代码, 所以不需要再执行
    if (BuildConfig.IS_BUILD_MODULE) {
        lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
            @Override
            public void onFragmentDestroyed(FragmentManager fm, android.support.v4.app.Fragment f) {
                ((RefWatcher) ArmsUtils
                        .obtainAppComponentFromContext(f.getActivity())
                        .extras()
                        .get(RefWatcher.class.getName()))
                        .watch(f);
            }
        });
    }
}
 
Example 4
Source File: GlobalConfiguration.java    From Hands-Chopping with Apache License 2.0 6 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    //当所有模块集成到宿主 App 时, 在 App 中已经执行了以下代码, 所以不需要再执行
    if (BuildConfig.IS_BUILD_MODULE) {
        lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
            @Override
            public void onFragmentDestroyed(FragmentManager fm, android.support.v4.app.Fragment f) {
                ((RefWatcher) ArmsUtils
                        .obtainAppComponentFromContext(f.getActivity())
                        .extras()
                        .get(RefWatcher.class.getName()))
                        .watch(f);
            }
        });
    }
}
 
Example 5
Source File: GlobalConfiguration.java    From Hands-Chopping with Apache License 2.0 6 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    //当所有模块集成到宿主 App 时, 在 App 中已经执行了以下代码, 所以不需要再执行
    if (BuildConfig.IS_BUILD_MODULE) {
        lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
            @Override
            public void onFragmentDestroyed(FragmentManager fm, android.support.v4.app.Fragment f) {
                ((RefWatcher) ArmsUtils
                        .obtainAppComponentFromContext(f.getActivity())
                        .extras()
                        .get(RefWatcher.class.getName()))
                        .watch(f);
            }
        });
    }
}
 
Example 6
Source File: ExpressPaymentFragment.java    From px-android with MIT License 5 votes vote down vote up
private void registerFragmentLifecycleCallbacks() {
    final FragmentManager manager = getFragmentManager();
    fragmentLifecycleCallbacks = new FragmentManager.FragmentLifecycleCallbacks() {
        @Override
        public void onFragmentAttached(@NonNull final FragmentManager fm, @NonNull final Fragment fragment,
            @NonNull final Context context) {
            if (fragment instanceof OfflineMethodsFragment) {
                presenter.onOtherPaymentMethodClickableStateChanged(false);
            }
            super.onFragmentAttached(fm, fragment, context);
        }

        @Override
        public void onFragmentDetached(@NonNull final FragmentManager fm, @NonNull final Fragment fragment) {
            if (fragment instanceof ExpressPaymentFragment) {
                fm.unregisterFragmentLifecycleCallbacks(this);
            } else if (fragment instanceof OfflineMethodsFragment) {
                bottomSheet.setVisibility(GONE);
                presenter.onOtherPaymentMethodClickableStateChanged(true);
            }
            super.onFragmentDetached(fm, fragment);
        }
    };

    if (manager != null) {
        manager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false);
    }
}
 
Example 7
Source File: GlobalConfiguration.java    From Hands-Chopping with Apache License 2.0 5 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
        @Override
        public void onFragmentDestroyed(FragmentManager fm, Fragment f) {
            ((RefWatcher) ArmsUtils
                    .obtainAppComponentFromContext(f.getActivity())
                    .extras()
                    .get(RefWatcher.class.getName()))
                    .watch(f);
        }
    });
}
 
Example 8
Source File: GlobalConfiguration.java    From Hands-Chopping with Apache License 2.0 5 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {

        @Override
        public void onFragmentCreated(FragmentManager fm, Fragment f, Bundle savedInstanceState) {
            // 在配置变化的时候将这个 Fragment 保存下来,在 Activity 由于配置变化重建是重复利用已经创建的Fragment。
            // https://developer.android.com/reference/android/app/Fragment.html?hl=zh-cn#setRetainInstance(boolean)
            // 在 Activity 中绑定少量的 Fragment 建议这样做,如果需要绑定较多的 Fragment 不建议设置此参数,如 ViewPager 需要展示较多 Fragment
            f.setRetainInstance(true);
        }
    });
}
 
Example 9
Source File: GlobalConfiguration.java    From TikTok with Apache License 2.0 5 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
        @Override
        public void onFragmentDestroyed(FragmentManager fm, Fragment f) {
            ((RefWatcher) ArmsUtils
                    .obtainAppComponentFromContext(f.getActivity())
                    .extras()
                    .get(RefWatcher.class.getName()))
                    .watch(f);
        }
    });
}
 
Example 10
Source File: GlobalConfiguration.java    From lifecycle-component with Apache License 2.0 5 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    lifecycles.add(new FragmentManager.FragmentLifecycleCallbacks() {
        @Override
        public void onFragmentDestroyed(FragmentManager fm, Fragment f) {
            ((RefWatcher) ArmsUtils
                    .obtainAppComponentFromContext(f.getActivity())
                    .extras()
                    .get(RefWatcher.class.getName()))
                    .watch(f);
        }
    });
}
 
Example 11
Source File: AppModule.java    From TikTok with Apache License 2.0 4 votes vote down vote up
@Singleton
@Provides
static List<FragmentManager.FragmentLifecycleCallbacks> provideFragmentLifecycles() {
    return new ArrayList<>();
}
 
Example 12
Source File: GlobalConfiguration.java    From lifecycle-component with Apache License 2.0 4 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    lifecycles.add(new FragmentLifecycleCallbacksImpl());
}
 
Example 13
Source File: GlobalConfiguration.java    From lifecycle-component with Apache License 2.0 4 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
}
 
Example 14
Source File: GlobalConfiguration.java    From LQRBiliBlili with MIT License 4 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    //向Fragment的生命周期中注入一些自定义逻辑
}
 
Example 15
Source File: GlobalConfiguration.java    From lifecycle-component with Apache License 2.0 4 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
}
 
Example 16
Source File: GlobalConfiguration.java    From lifecycle-component with Apache License 2.0 4 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
}
 
Example 17
Source File: Config.java    From TikTok with Apache License 2.0 2 votes vote down vote up
@Override
public void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {

}
 
Example 18
Source File: ConfigModule.java    From TikTok with Apache License 2.0 2 votes vote down vote up
/**
 * 使用{@link FragmentManager.FragmentLifecycleCallbacks}在Fragment的生命周期中注入一些操作
 *
 * @param context
 * @param lifecycles
 */
void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles);
 
Example 19
Source File: ConfigModule.java    From Aurora with Apache License 2.0 2 votes vote down vote up
/**
 * 使用{@link FragmentManager.FragmentLifecycleCallbacks}在Fragment的生命周期中注入一些操作
 *
 * @param context
 * @param lifecycles
 */
void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles);
 
Example 20
Source File: ConfigLifecycle.java    From MVVMArms with Apache License 2.0 2 votes vote down vote up
/**
 * 使用 {@link FragmentManager.FragmentLifecycleCallbacks} 在 Fragment 的生命周期中注入一些操作
 *
 * @param context:    Context
 * @param lifecycles: List<FragmentManager.FragmentLifecycleCallbacks>
 */
void injectFragmentLifecycle(Context context, List<FragmentManager.FragmentLifecycleCallbacks> lifecycles);