Java 类android.arch.lifecycle.LifecycleObserver 实例源码

项目:Kickback    文件:KickbackBoxGenerator.java   
public TypeSpec generate() {
    return TypeSpec.classBuilder(getClassName())
            .addJavadoc("Generated by Kickback. (https://github.com/skydoves/Kickback).\n")
            .addModifiers(Modifier.PUBLIC)
            .addSuperinterface(LifecycleObserver.class)
            .addFields(getKickbackFields())
            .addMethods(getSetterMethodSpecs())
            .addMethods(getGetterMethodSpecs())
            .addMethods(getFreeMethodSpecs())
            .addMethod(getBoxNameSpec())
            .addMethods(getElementNameListSpecs())
            .addMethod(getFreeAllSpec())
            .addMethod(setLifecycleObserverSpec())
            .addMethod(getLifecycleObserverSpec())
            .build();
}
项目:delern    文件:PerfEventTracker.java   
/**
 * Like {@link #trackEvent(Event, Context, Bundle)}, but also starts a performance Trace.
 *
 * @param event     {@link #trackEvent(Event, Context, Bundle)}
 * @param context   {@link #trackEvent(Event, Context, Bundle)}
 * @param bundle    {@link #trackEvent(Event, Context, Bundle)}
 * @param container lifecycle to attach Trace to (onDestroy will stop the trace).
 */
public static void trackEventStart(@NonNull final Event event, @NonNull final Context context,
                                   @Nullable final Bundle bundle,
                                   @Nullable final LifecycleOwner container) {
    trackEvent(event, context, bundle);
    if (sRunningEvents.containsKey(event)) {
        LOGGER.error("Event {} triggered while performance counting for it was already in " +
                "progress! Finishing now", event, new Throwable());
        trackEventFinish(event);
    }

    Trace t = FirebasePerformance.startTrace(event.track());
    sRunningEvents.put(event, t);
    t.start();

    if (container != null) {
        // Container can be null if we test cross-activity lifecycle
        container.getLifecycle().addObserver(new LifecycleObserver() {
            @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
            public void stopTrace() {
                trackEventFinish(event);
            }
        });
    }
}
项目:MoligyMvpArms    文件:BasePresenter.java   
@Override
public void onStart() {
    //将 LifecycleObserver 注册给 LifecycleOwner 后 @OnLifecycleEvent 才可以正常使用
    if (mRootView != null && mRootView instanceof LifecycleOwner) {
        ((LifecycleOwner) mRootView).getLifecycle().addObserver(this);
        if (mModel!= null && mModel instanceof LifecycleObserver){
            ((LifecycleOwner) mRootView).getLifecycle().addObserver((LifecycleObserver) mModel);
        }
    }
    if (useEventBus())//如果要使用 Eventbus 请将此方法返回 true
        EventBus.getDefault().register(this);//注册 Eventbus
}
项目:LifecycleAware    文件:LifecycleObserverGenerator.java   
@Override
public TypeSpec defineClass() {
    return TypeSpec.classBuilder(producer.getClassName(annotatedElement))
            .addSuperinterface(LifecycleObserver.class)
            .addField(LifecycleAwareObserver.class, FIELD_OBSERVER, Modifier.PRIVATE)
            .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
            .build();
}
项目:Aurora    文件:BasePresenter.java   
@Override
public void onStart() {
    //将 LifecycleObserver 注册给 LifecycleOwner 后 @OnLifecycleEvent 才可以正常使用
    if (mRootView != null && mRootView instanceof LifecycleOwner) {
        ((LifecycleOwner) mRootView).getLifecycle().addObserver(this);
        if (mModel!= null && mModel instanceof LifecycleObserver){
            ((LifecycleOwner) mRootView).getLifecycle().addObserver((LifecycleObserver) mModel);
        }
    }
    if (useEventBus())//如果要使用 Eventbus 请将此方法返回 true
        EventBus.getDefault().register(this);//注册 Eventbus
}
项目:homunculus    文件:ContextScope.java   
/**
 * Creates a new scope for the given lifecycle owner (e.g. a Fragment or an Activity).
 * Note: The lifetime is
 * attached to the {@link android.arch.lifecycle.Lifecycle} AND the parent scope. So the returned
 * scope is destroyed if either of them is destroyed.
 */
public static Scope createScope(@Nullable Scope parent, LifecycleOwner lifecycleOwner) {
    Scope scope = new Scope(lifecycleOwner.toString(), parent);
    lifecycleOwner.getLifecycle().addObserver(new LifecycleObserver() {
        @OnLifecycleEvent(Event.ON_DESTROY)
        void onDestroy() {
            scope.destroy();
        }
    });
    if (lifecycleOwner instanceof Context) {
        scope.put(Android.NAME_CONTEXT, lifecycleOwner);
    }
    return scope;
}
项目:Kickback    文件:KickbackBoxGenerator.java   
private MethodSpec getLifecycleObserverSpec() {
    return MethodSpec.methodBuilder("getLifecycleObserver")
            .addModifiers(Modifier.PUBLIC)
            .returns(LifecycleObserver.class)
            .addStatement("return this")
            .build();
}
项目:GmArchMvvm    文件:BaseActivity.java   
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //Set the DataBinding
    mBinding = DataBindingUtil.setContentView(this, initView(savedInstanceState));
    initData(savedInstanceState);
    if (mViewModel != null) {
        getLifecycle().addObserver((LifecycleObserver) mViewModel);
    }
}
项目:GmArchMvvm    文件:BaseActivity.java   
@Override
protected void onDestroy() {
    super.onDestroy();
    this.mBinding = null;
    this.mViewModelFactory = null;
    //Removed LifecycleObserver
    if (mViewModel != null) {
        getLifecycle().removeObserver((LifecycleObserver) mViewModel);
    }
    this.mViewModel = null;
}
项目:GmArchMvvm    文件:BaseFragment.java   
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    mRootView = initView(inflater, container, savedInstanceState);
    if (mViewModel != null) {
        getLifecycle().addObserver((LifecycleObserver) mViewModel);
    }
    //Visible, and is the first time to load
    if (mVisible && mFirst) {
        onFragmentVisibleChange(true);
    }
    return mRootView;
}
项目:GmArchMvvm    文件:BaseFragment.java   
@Override
public void onDestroy() {
    super.onDestroy();
    this.mBinding = null;
    this.mRootView = null;
    this.mViewModelFactory = null;
    //Removed LifecycleObserver
    if (mViewModel != null) {
        getLifecycle().removeObserver((LifecycleObserver) mViewModel);
    }
    this.mViewModel = null;
}
项目:MVVMArms    文件:BaseActivity.java   
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //设置DataBinding
    mBinding = DataBindingUtil.setContentView(this, initView(savedInstanceState));
    initData(savedInstanceState);
    if (mViewModel != null) {
        getLifecycle().addObserver((LifecycleObserver) mViewModel);
    }
}
项目:MVVMArms    文件:BaseActivity.java   
@Override
protected void onDestroy() {
    super.onDestroy();
    this.mBinding = null;
    this.mViewModelFactory = null;
    //移除LifecycleObserver
    if (mViewModel != null) {
        getLifecycle().removeObserver((LifecycleObserver) mViewModel);
    }
    this.mViewModel = null;
}
项目:MVVMArms    文件:BaseFragment.java   
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    mRootView = initView(inflater, container, savedInstanceState);
    if (mViewModel != null) {
        getLifecycle().addObserver((LifecycleObserver) mViewModel);
    }
    //可见,并且是首次加载
    if (mVisible && mFirst) {
        onFragmentVisibleChange(true);
    }
    return mRootView;
}
项目:MVVMArms    文件:BaseFragment.java   
@Override
public void onDestroy() {
    super.onDestroy();
    this.mBinding = null;
    this.mRootView = null;
    this.mViewModelFactory = null;
    //移除LifecycleObserver
    if (mViewModel != null) {
        getLifecycle().removeObserver((LifecycleObserver) mViewModel);
    }
    this.mViewModel = null;
}
项目:delern    文件:AbstractActivity.java   
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getLifecycle().addObserver(new LifecycleObserver() {
        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
        public void cleanDisposables() {
            getLifecycle().removeObserver(this);
            mDisposeOnDestroy.dispose();
        }
    });
}
项目:MVPArms    文件:BasePresenter.java   
@Override
public void onStart() {
    //将 LifecycleObserver 注册给 LifecycleOwner 后 @OnLifecycleEvent 才可以正常使用
    if (mRootView != null && mRootView instanceof LifecycleOwner) {
        ((LifecycleOwner) mRootView).getLifecycle().addObserver(this);
        if (mModel!= null && mModel instanceof LifecycleObserver){
            ((LifecycleOwner) mRootView).getLifecycle().addObserver((LifecycleObserver) mModel);
        }
    }
    if (useEventBus())//如果要使用 Eventbus 请将此方法返回 true
        EventBus.getDefault().register(this);//注册 Eventbus
}
项目:rapid-io-android    文件:LiveDataTest.java   
@Override
public void addObserver(LifecycleObserver observer) {
}
项目:rapid-io-android    文件:LiveDataTest.java   
@Override
public void removeObserver(LifecycleObserver observer) {

}