Java Code Examples for android.view.View#OnAttachStateChangeListener

The following examples show how to use android.view.View#OnAttachStateChangeListener . 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: CompositeRecyclerAdapter.java    From recyclerview-adapters with Apache License 2.0 6 votes vote down vote up
@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 File: Coordinators.java    From coordinators with 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
Source File: PeriodicTableApplication.java    From android-periodic-table with GNU General Public License v3.0 4 votes vote down vote up
public View.OnAttachStateChangeListener getOnAttachStateChangeListener() {
    return mOnAttachStateChangeListener;
}
 
Example 4
Source File: PeriodicTableApplication.java    From android-periodic-table with GNU General Public License v3.0 4 votes vote down vote up
public void setOnAttachStateChangeListener(View.OnAttachStateChangeListener listener) {
    this.mOnAttachStateChangeListener = listener;
}
 
Example 5
Source File: TestUtil.java    From RxLifecycle with 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");
}