Example usage for android.view View removeOnAttachStateChangeListener

List of usage examples for android.view View removeOnAttachStateChangeListener

Introduction

In this page you can find the example usage for android.view View removeOnAttachStateChangeListener.

Prototype

public void removeOnAttachStateChangeListener(OnAttachStateChangeListener listener) 

Source Link

Document

Remove a listener for attach state changes.

Usage

From source file:com.google.samples.apps.ourstreets.fragment.GalleryFragment.java

/**
 * Add animation safety by making sure that the fragment currently is attached.
 *//*w  w  w.j  a  va2 s  .c  om*/
private void safelyAnimateProgressToContent() {
    if (mGalleryContent.isAttachedToWindow()) {
        animateProgressToContent();
    } else {
        mGalleryContent.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
            @Override
            public void onViewAttachedToWindow(View v) {
                v.removeOnAttachStateChangeListener(this);
                animateProgressToContent();
            }

            @Override
            public void onViewDetachedFromWindow(View v) {
                v.removeOnAttachStateChangeListener(this);
            }
        });
    }
}

From source file:com.nile.kmooc.view.custom.popup.menu.MenuPopupHelper.java

@Override
public void onViewDetachedFromWindow(View v) {
    if (mTreeObserver != null) {
        if (!mTreeObserver.isAlive())
            mTreeObserver = v.getViewTreeObserver();
        mTreeObserver.removeGlobalOnLayoutListener(this);
    }/*from  w  w w. j  a  v a 2  s. co  m*/
    v.removeOnAttachStateChangeListener(this);
}

From source file:nuclei.ui.LoadingManager.java

void showLoading(final Integer id, final View view, final boolean immediate) {
    if (mActivity != null)
        mActivity.runOnUiThread(new Runnable() {
            @Override//from   w w  w .  j ava 2  s .c  o  m
            public void run() {
                if (mLoadingTokens.contains(id)) {
                    if (mLoadingView == null && ViewCompat.isAttachedToWindow(view)) {
                        mLoadingView = LoadingView.make(mActivity, view, immediate);
                    } else if (mLoadingView == null) {
                        view.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
                            @Override
                            public void onViewAttachedToWindow(View v) {
                                showLoading(id, view, immediate);
                                view.removeOnAttachStateChangeListener(this);
                            }

                            @Override
                            public void onViewDetachedFromWindow(View v) {
                                view.removeOnAttachStateChangeListener(this);
                            }
                        });
                    }
                }
            }
        });
}

From source file:com.facebook.react.ReactInstanceManager.java

/**
 * Use this method when the activity resumes.
 *///from   ww w  . jav  a2 s.c  o  m
@ThreadConfined(UI)
public void onHostResume(Activity activity) {
    UiThreadUtil.assertOnUiThread();

    mCurrentActivity = activity;

    if (mUseDeveloperSupport) {
        // Resume can be called from one of two different states:
        // a) when activity was paused
        // b) when activity has just been created
        // In case of (a) the activity is attached to window and it is ok to add new views to it or
        // open dialogs. In case of (b) there is often a slight delay before such a thing happens.
        // As dev support manager can add views or open dialogs immediately after it gets enabled
        // (e.g. in the case when JS bundle is being fetched in background) we only want to enable
        // it once we know for sure the current activity is attached.

        // We check if activity is attached to window by checking if decor view is attached
        final View decorView = mCurrentActivity.getWindow().getDecorView();
        if (!ViewCompat.isAttachedToWindow(decorView)) {
            decorView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
                @Override
                public void onViewAttachedToWindow(View v) {
                    // we can drop listener now that we know the view is attached
                    decorView.removeOnAttachStateChangeListener(this);
                    mDevSupportManager.setDevSupportEnabled(true);
                }

                @Override
                public void onViewDetachedFromWindow(View v) {
                    // do nothing
                }
            });
        } else {
            // activity is attached to window, we can enable dev support immediately
            mDevSupportManager.setDevSupportEnabled(true);
        }
    }

    moveToResumedLifecycleState(false);
}