Java Code Examples for androidx.lifecycle.Lifecycle#Event

The following examples show how to use androidx.lifecycle.Lifecycle#Event . 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: DifferentPackagesDerived1_LifecycleAdapter.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void callMethods(LifecycleOwner owner, Lifecycle.Event event, boolean onAny,
    MethodCallsLogger logger) {
  boolean hasLogger = logger != null;
  if (onAny) {
    return;
  }
  if (event == Lifecycle.Event.ON_STOP) {
    if (!hasLogger || logger.approveCall("onStop", 2)) {
      DifferentPackagesBase1_LifecycleAdapter.__synthetic_onStop(mReceiver,owner);
    }
    if (!hasLogger || logger.approveCall("onStop2", 2)) {
      mReceiver.onStop2(owner);
    }
    return;
  }
}
 
Example 2
Source File: DerivedFromJar1_LifecycleAdapter.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void callMethods(LifecycleOwner owner, Lifecycle.Event event, boolean onAny,
        MethodCallsLogger logger) {
    boolean hasLogger = logger != null;
    if (onAny) {
        return;
    }
    if (event == Lifecycle.Event.ON_STOP) {
        if (!hasLogger || logger.approveCall("doOnStop", 1)) {
            mReceiver.doOnStop();
        }
        return;
    }
    if (event == Lifecycle.Event.ON_START) {
        if (!hasLogger || logger.approveCall("doAnother", 1)) {
            mReceiver.doAnother();
        }
        return;
    }
}
 
Example 3
Source File: OnAnyMethod_LifecycleAdapter.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void callMethods(LifecycleOwner owner, Lifecycle.Event event, boolean onAny,
    MethodCallsLogger logger) {
  boolean hasLogger = logger != null;
  if (onAny) {
    if (!hasLogger || logger.approveCall("any", 2)) {
      mReceiver.any(owner);
    }
    if (!hasLogger || logger.approveCall("any", 4)) {
      mReceiver.any(owner,event);
    }
    return;
  }
  if (event == Lifecycle.Event.ON_STOP) {
    if (!hasLogger || logger.approveCall("onStop", 2)) {
      mReceiver.onStop(owner);
    }
    return;
  }
}
 
Example 4
Source File: MVVMActivity.java    From AndroidQuick with MIT License 6 votes vote down vote up
@Override
protected void initViewsAndEvents(Bundle savedInstanceState) {
    LifecycleProvider<Lifecycle.Event> lifecycleProvider = AndroidLifecycle.createLifecycleProvider(this);
    viewModel1 = ViewModelProviders.of(this, new MVVMFactory1(new MVVMRepository1(), lifecycleProvider)).get(MVVMViewModel1.class);

    viewModel1.getData().observe(this, new Observer<List<String>>() {
        @Override
        public void onChanged(@Nullable List<String> s) {
            mTextView1.setText("size is " + s.size());
        }
    });

    viewModel2 = ViewModelProviders.of(this, new MVVMFactory2(new MVVMRepository2(lifecycleProvider))).get(MVVMViewModel2.class);

    viewModel2.getTestData().observe(this, new Observer<List<NameBean>>() {
        @Override
        public void onChanged(@Nullable List<NameBean> nameBeans) {
            mTextView2.setText("size is " + nameBeans.size());
        }
    });
}
 
Example 5
Source File: DifferentPackagesBase1_LifecycleAdapter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void callMethods(LifecycleOwner owner, Lifecycle.Event event, boolean onAny,
    MethodCallsLogger logger) {
  boolean hasLogger = logger != null;
  if (onAny) {
    return;
  }
  if (event == Lifecycle.Event.ON_STOP) {
    if (!hasLogger || logger.approveCall("onStop", 2)) {
      mReceiver.onStop(owner);
    }
    return;
  }
}
 
Example 6
Source File: InterfaceOk2Interface_LifecycleAdapter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void callMethods(LifecycleOwner owner, Lifecycle.Event event, boolean onAny,
    MethodCallsLogger logger) {
  boolean hasLogger = logger != null;
  if (onAny) {
    return;
  }
  if (event == Lifecycle.Event.ON_STOP) {
    if (!hasLogger || logger.approveCall("onStop2", 2)) {
      mReceiver.onStop2(owner);
    }
    return;
  }
}
 
Example 7
Source File: InheritanceOk3Base_LifecycleAdapter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void callMethods(LifecycleOwner owner, Lifecycle.Event event, boolean onAny,
    MethodCallsLogger logger) {
  boolean hasLogger = logger != null;
  if (onAny) {
    return;
  }
  if (event == Lifecycle.Event.ON_STOP) {
    if (!hasLogger || logger.approveCall("onStop", 2)) {
      mReceiver.onStop(owner);
    }
    return;
  }
}
 
Example 8
Source File: InheritanceOk2Base_LifecycleAdapter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void callMethods(LifecycleOwner owner, Lifecycle.Event event, boolean onAny,
    MethodCallsLogger logger) {
  boolean hasLogger = logger != null;
  if (onAny) {
    return;
  }
  if (event == Lifecycle.Event.ON_STOP) {
    if (!hasLogger || logger.approveCall("onStop", 2)) {
      mReceiver.onStop(owner);
    }
    return;
  }
}
 
Example 9
Source File: InterfaceOk2Base_LifecycleAdapter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void callMethods(LifecycleOwner owner, Lifecycle.Event event, boolean onAny,
    MethodCallsLogger logger) {
  boolean hasLogger = logger != null;
  if (onAny) {
    return;
  }
  if (event == Lifecycle.Event.ON_STOP) {
    if (!hasLogger || logger.approveCall("onStop1", 2)) {
      mReceiver.onStop1(owner);
    }
    return;
  }
}
 
Example 10
Source File: MVPDialogFragment.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
private void onLifecycleOwnerStateChanged(@NonNull LifecycleOwner source,
                                          @NonNull Lifecycle.Event event) {
    switch (event) {
        case ON_CREATE:
            mViewHolder.setView(this);
            break;
        case ON_DESTROY:
            mViewHolder.setView(null);
            source.getLifecycle().removeObserver(mLifecycleEventObserver);
            break;
    }
}
 
Example 11
Source File: MVPFragment.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
private void onLifecycleOwnerStateChanged(@NonNull LifecycleOwner source,
                                          @NonNull Lifecycle.Event event) {
    switch (event) {
        case ON_CREATE:
            mViewHolder.setView(this);
            break;
        case ON_DESTROY:
            mViewHolder.setView(null);
            source.getLifecycle().removeObserver(mLifecycleEventObserver);
            break;
    }
}
 
Example 12
Source File: BasePresenter.java    From AndroidQuick with MIT License 5 votes vote down vote up
protected LifecycleProvider<Lifecycle.Event> getLifecycleProvider() {
    LifecycleProvider<Lifecycle.Event> lifecycleProvider = null;
    if (null != getView()) {
        lifecycleProvider = AndroidLifecycle.createLifecycleProvider((LifecycleOwner) getView());
    }
    return lifecycleProvider;
}
 
Example 13
Source File: AndroidLifecycle.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
void onEvent(LifecycleOwner owner, Lifecycle.Event event) {
    lifecycleSubject.onNext(event);
    if (event == Lifecycle.Event.ON_DESTROY) {
        owner.getLifecycle().removeObserver(this);
    }
}
 
Example 14
Source File: Interface2_LifecycleAdapter.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void callMethods(LifecycleOwner source, Lifecycle.Event event, boolean onAny,
        MethodCallsLogger logger) {

}
 
Example 15
Source File: UpdateModelDelegate.java    From AndroidAnimationExercise with Apache License 2.0 4 votes vote down vote up
public static void saveLifeCycleData(Activity activity, Lifecycle.Event event) {

        if (mActivityRepository == null) {
            throw new RuntimeException("please call init first");
        }

        String name = activity.getClass().getCanonicalName();
//        Log.e("room", "name ==" + name);
//        Log.e("room", "event ==" + event.name());

        Disposable d = Observable.create((ObservableOnSubscribe<ActModel>) emitter -> {
            ActModel actModel = mActivityRepository.getActivityByName(name);
            if (actModel == null) {
                actModel = new ActModel();
                actModel.setName(name);
            }

            emitter.onNext(actModel);
            emitter.onComplete();

        })

                .subscribeOn(Schedulers.io())
                .map(actModel -> {
                    int count;
                    switch (event) {
                        case ON_CREATE:
                            count = actModel.getOnActivityCreateCount();
                            actModel.setOnActivityCreateCount(++count);
                            return actModel;
                        case ON_START:
                            count = actModel.getOnActivityStartedCount();
                            actModel.setOnActivityStartedCount(++count);
                            return actModel;
                        case ON_RESUME:
                            count = actModel.getOnActivityResumedCount();
                            actModel.setOnActivityResumedCount(++count);
                            return actModel;
                        case ON_PAUSE:
                            count = actModel.getOnActivityPausedCount();
                            actModel.setOnActivityPausedCount(++count);
                            return actModel;
                        case ON_STOP:
                            count = actModel.getOnActivityStoppedCount();
                            actModel.setOnActivityPausedCount(++count);
                            return actModel;
                        case ON_DESTROY:
                            count = actModel.getOnActivityDestroyedCount();
                            actModel.setOnActivityDestroyedCount(++count);
                            return actModel;
                        default:
                            count = actModel.getOnActivitySaveInstanceStateCount();
                            actModel.setOnActivitySaveInstanceStateCount(++count);
                            return actModel;

                    }
                })
                .subscribe(actModel -> {
//                            Log.e("room", "start insert : " + actModel.toString());
                            mActivityRepository.insert(actModel);
                        },
                        throwable -> {
//                            Log.e("room", "wrong with " + throwable.getMessage());
                            throwable.printStackTrace();
                        });

    }
 
Example 16
Source File: MVVMFactory1.java    From AndroidQuick with MIT License 4 votes vote down vote up
public MVVMFactory1(MVVMRepository1 repository, LifecycleProvider<Lifecycle.Event> activityEventLifecycleProvider) {
    mActivityEventLifecycleProvider = activityEventLifecycleProvider;
    mRepository = repository;
}
 
Example 17
Source File: FragmentLifecycleActivity.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public List<Lifecycle.Event> getLoggedEvents() {
    return mLoggedEvents;
}
 
Example 18
Source File: MutableLiveQueue.java    From mobius with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
void onAny(LifecycleOwner source, Lifecycle.Event event) {
  onLifecycleChanged(event);
}
 
Example 19
Source File: AbstractPowerMenu.java    From PowerMenu with Apache License 2.0 2 votes vote down vote up
/**
 * gets initialize rule by {@link Lifecycle.Event}.
 *
 * @return {@link Lifecycle.Event}.
 */
private Lifecycle.Event getInitializeRule() {
  return this.initializeRule;
}
 
Example 20
Source File: AbstractPowerMenu.java    From PowerMenu with Apache License 2.0 2 votes vote down vote up
/**
 * sets initialize rule by {@link Lifecycle.Event}.
 *
 * <p>There are three events(ON_CREATE, ON_START, ON_RESUME) working by lifecycle.
 *
 * @param event {@link Lifecycle.Event}.
 */
private void setInitializeRule(@NonNull Lifecycle.Event event) {
  this.initializeRule = event;
}