Java Code Examples for android.view.View#OnAttachStateChangeListener

The following examples show how to use android.view.View#OnAttachStateChangeListener . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public void onAttachedToRecyclerView(final RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    this.recyclerView = recyclerView;
    recyclerViewAttachStateChangeListener = new View.OnAttachStateChangeListener() {
        @Override
        public void onViewAttachedToWindow(View v) {
        }

        @Override
        public void onViewDetachedFromWindow(View v) {
            clear();
            recyclerView.removeOnAttachStateChangeListener(recyclerViewAttachStateChangeListener);
        }
    };
    recyclerView.addOnAttachStateChangeListener(recyclerViewAttachStateChangeListener);
    for (LocalAdapter<?> localAdapter : localAdapters) {
        localAdapter.onAttachedToRecyclerView(recyclerView);
    }
}
 
Example 2
Source Project: coordinators   File: Coordinators.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Attempts to bind a view to a {@link Coordinator}.
 *
 * Immediately calls provider to obtain a Coordinator for the view. If a non-null Coordinator is
 * returned, that Coordinator is permanently bound to the View.
 */
public static void bind(@NonNull View view, @NonNull CoordinatorProvider provider) {
  final Coordinator coordinator = provider.provideCoordinator(view);
  if (coordinator == null) {
    return;
  }

  View.OnAttachStateChangeListener binding = new Binding(coordinator, view);
  view.addOnAttachStateChangeListener(binding);
  // Sometimes we missed the first attach because the child's already been added.
  // Sometimes we didn't. The binding keeps track to avoid double attachment of the Coordinator,
  // and to guard against attachment to two different views simultaneously.
  if (isAttachedToWindow(view)) {
    binding.onViewAttachedToWindow(view);
  }
}
 
Example 3
public View.OnAttachStateChangeListener getOnAttachStateChangeListener() {
    return mOnAttachStateChangeListener;
}
 
Example 4
public void setOnAttachStateChangeListener(View.OnAttachStateChangeListener listener) {
    this.mOnAttachStateChangeListener = listener;
}
 
Example 5
Source Project: RxLifecycle   File: TestUtil.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Manually retrieve the view's attach state change listeners of an event. Robolectric
 * doesn't currently support manually firing these, and it would seem the events are not called
 * in normal Robolectric usage either.
 *
 * @param view View with listeners to notify
 */
static CopyOnWriteArrayList<View.OnAttachStateChangeListener> getAttachStateChangeListeners(View view) {
    Object listenerInfo = ReflectionHelpers.callInstanceMethod(view, "getListenerInfo");
    return ReflectionHelpers.getField(listenerInfo, "mOnAttachStateChangeListeners");
}