Example usage for android.view ViewTreeObserver isAlive

List of usage examples for android.view ViewTreeObserver isAlive

Introduction

In this page you can find the example usage for android.view ViewTreeObserver isAlive.

Prototype

public boolean isAlive() 

Source Link

Document

Indicates whether this ViewTreeObserver is alive.

Usage

From source file:com.github.lakeshire.photoview.PhotoViewAttacher.java

@SuppressWarnings("deprecation")
public void cleanup() {
    if (null == mImageView) {
        return; // cleanup already done
    }/*from  ww  w .  ja va  2 s.  co m*/

    final ImageView imageView = mImageView.get();

    if (null != imageView) {
        // Remove this as a global layout listener
        ViewTreeObserver observer = imageView.getViewTreeObserver();
        if (null != observer && observer.isAlive()) {
            observer.removeGlobalOnLayoutListener(this);
        }

        // Remove the ImageView's reference to this
        imageView.setOnTouchListener(null);

        // make sure a pending fling runnable won't be run
        cancelFling();
    }

    if (null != mGestureDetector) {
        mGestureDetector.setOnDoubleTapListener(null);
    }

    // Clear listeners too
    mMatrixChangeListener = null;
    mPhotoTapListener = null;
    mViewTapListener = null;

    // Finally, clear ImageView
    mImageView = null;
}

From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java

/**
 * Clean-up the resources attached to this object. This needs to be called when the ImageView is
 * no longer used. A good example is from {@link View#onDetachedFromWindow()} or
 * from {@link android.app.Activity#onDestroy()}. This is automatically called if you are using
 *///from   w w w  .  j av a2  s . co m
@SuppressWarnings("deprecation")
public void cleanup() {
    if (null == mImageView) {
        return; // cleanup already done
    }

    final ImageView imageView = mImageView.get();

    if (null != imageView) {
        // Remove this as a global layout listener
        ViewTreeObserver observer = imageView.getViewTreeObserver();
        if (null != observer && observer.isAlive()) {
            observer.removeGlobalOnLayoutListener(this);
        }

        // Remove the ImageView's reference to this
        imageView.setOnTouchListener(null);

        // make sure a pending fling runnable won't be run
        cancelFling();
    }

    if (null != mGestureDetector) {
        mGestureDetector.setOnDoubleTapListener(null);
    }

    // Clear listeners too
    mMatrixChangeListener = null;
    mPhotoTapListener = null;
    mViewTapListener = null;

    // Finally, clear ImageView
    mImageView = null;
}

From source file:com.google.samples.apps.iosched.ui.CurrentSessionActivity.java

@Override
protected void onDestroy() {
    super.onDestroy();
    if (mScrollView == null) {
        return;// w w  w  .  j ava2 s  .c om
    }

    ViewTreeObserver vto = mScrollView.getViewTreeObserver();
    if (vto.isAlive()) {
        vto.removeGlobalOnLayoutListener(mGlobalLayoutListener);
    }
}

From source file:com.google.samples.apps.iosched.ui.SessionDetailFragment.java

private void setupCustomScrolling(View rootView) {
    mScrollView = (ObservableScrollView) rootView.findViewById(R.id.scroll_view);
    mScrollView.addCallbacks(this);
    ViewTreeObserver vto = mScrollView.getViewTreeObserver();
    if (vto.isAlive()) {
        vto.addOnGlobalLayoutListener(mGlobalLayoutListener);
    }//  w w  w.  java  2s. co  m
}

From source file:com.google.samples.apps.iosched.ui.SessionDetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    UIUtils.tryTranslateHttpIntent(this);
    BeamUtils.tryUpdateIntentFromBeam(this);
    boolean shouldBeFloatingWindow = shouldBeFloatingWindow();
    if (shouldBeFloatingWindow) {
        setupFloatingWindow();/*from   w  w w  . ja va  2s. c o m*/
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_session_detail);

    final Toolbar toolbar = getActionBarToolbar();
    toolbar.setNavigationIcon(shouldBeFloatingWindow ? R.drawable.ic_ab_close : R.drawable.ic_up);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();
        }
    });
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            toolbar.setTitle("");
        }
    });

    if (savedInstanceState == null) {
        Uri sessionUri = getIntent().getData();
        BeamUtils.setBeamSessionUri(this, sessionUri);
    }

    mSessionUri = getIntent().getData();

    if (mSessionUri == null) {
        return;
    }

    mSessionId = ScheduleContract.Sessions.getSessionId(mSessionUri);

    mFABElevation = getResources().getDimensionPixelSize(R.dimen.fab_elevation);
    mMaxHeaderElevation = getResources().getDimensionPixelSize(R.dimen.session_detail_max_header_elevation);

    mTagColorDotSize = getResources().getDimensionPixelSize(R.dimen.tag_color_dot_size);

    mHandler = new Handler();

    if (mSpeakersImageLoader == null) {
        mSpeakersImageLoader = new ImageLoader(this, R.drawable.person_image_empty);
    }
    if (mNoPlaceholderImageLoader == null) {
        mNoPlaceholderImageLoader = new ImageLoader(this);
    }

    mScrollView = (ObservableScrollView) findViewById(R.id.scroll_view);
    mScrollView.addCallbacks(this);
    ViewTreeObserver vto = mScrollView.getViewTreeObserver();
    if (vto.isAlive()) {
        vto.addOnGlobalLayoutListener(mGlobalLayoutListener);
    }

    mScrollViewChild = findViewById(R.id.scroll_view_child);
    mScrollViewChild.setVisibility(View.INVISIBLE);

    mDetailsContainer = findViewById(R.id.details_container);
    mHeaderBox = findViewById(R.id.header_session);
    mTitle = (TextView) findViewById(R.id.session_title);
    mSubtitle = (TextView) findViewById(R.id.session_subtitle);
    mPhotoViewContainer = findViewById(R.id.session_photo_container);
    mPhotoView = (ImageView) findViewById(R.id.session_photo);

    mPlusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button);
    mAbstract = (TextView) findViewById(R.id.session_abstract);
    mRequirements = (TextView) findViewById(R.id.session_requirements);
    mTags = (LinearLayout) findViewById(R.id.session_tags);
    mTagsContainer = (ViewGroup) findViewById(R.id.session_tags_container);

    mAddScheduleButton = (CheckableFrameLayout) findViewById(R.id.add_schedule_button);
    mAddScheduleButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean starred = !mStarred;
            SessionsHelper helper = new SessionsHelper(SessionDetailActivity.this);
            showStarred(starred, true);
            helper.setSessionStarred(mSessionUri, starred, mTitleString);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                mAddScheduleButton.announceForAccessibility(
                        starred ? getString(R.string.session_details_a11y_session_added)
                                : getString(R.string.session_details_a11y_session_removed));
            }

            /* [ANALYTICS:EVENT]
             * TRIGGER:   Add or remove a session from My Schedule.
             * CATEGORY:  'Session'
             * ACTION:    'Starred' or 'Unstarred'
             * LABEL:     Session title/subtitle.
             * [/ANALYTICS]
             */
            AnalyticsManager.sendEvent("Session", starred ? "Starred" : "Unstarred", mTitleString, 0L);
        }
    });

    ViewCompat.setTransitionName(mPhotoView, TRANSITION_NAME_PHOTO);

    LoaderManager manager = getLoaderManager();
    manager.initLoader(SessionsQuery._TOKEN, null, this);
    manager.initLoader(SpeakersQuery._TOKEN, null, this);
    manager.initLoader(TAG_METADATA_TOKEN, null, this);
}

From source file:com.ncode.android.apps.schedo.ui.EventDetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    UIUtils.tryTranslateHttpIntent(this);
    BeamUtils.tryUpdateIntentFromBeam(this);
    boolean shouldBeFloatingWindow = shouldBeFloatingWindow();
    if (shouldBeFloatingWindow) {
        setupFloatingWindow();/*  w  ww  .j  a  v a 2  s. c o  m*/
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_session_detail);

    final Toolbar toolbar = getActionBarToolbar();
    toolbar.setNavigationIcon(shouldBeFloatingWindow ? R.drawable.ic_ab_close : R.drawable.ic_up);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();
        }
    });
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            toolbar.setTitle("");
        }
    });

    if (savedInstanceState == null) {
        Uri sessionUri = getIntent().getData();
        BeamUtils.setBeamSessionUri(this, sessionUri);
    }

    mSessionUri = getIntent().getData();

    if (mSessionUri == null) {
        return;
    }

    mSessionId = ScheduleContract.Sessions.getSessionId(mSessionUri);

    mFABElevation = getResources().getDimensionPixelSize(R.dimen.fab_elevation);
    mMaxHeaderElevation = getResources().getDimensionPixelSize(R.dimen.session_detail_max_header_elevation);

    mTagColorDotSize = getResources().getDimensionPixelSize(R.dimen.tag_color_dot_size);

    mHandler = new Handler();

    if (mSpeakersImageLoader == null) {
        mSpeakersImageLoader = new ImageLoader(this, R.drawable.person_image_empty);
    }
    if (mNoPlaceholderImageLoader == null) {
        mNoPlaceholderImageLoader = new ImageLoader(this);
    }

    mScrollView = (ObservableScrollView) findViewById(R.id.scroll_view);
    mScrollView.addCallbacks(this);
    ViewTreeObserver vto = mScrollView.getViewTreeObserver();
    if (vto.isAlive()) {
        vto.addOnGlobalLayoutListener(mGlobalLayoutListener);
    }

    mScrollViewChild = findViewById(R.id.scroll_view_child);
    mScrollViewChild.setVisibility(View.INVISIBLE);

    mDetailsContainer = findViewById(R.id.details_container);
    mHeaderBox = findViewById(R.id.header_session);
    mTitle = (TextView) findViewById(R.id.session_title);
    mSubtitle = (TextView) findViewById(R.id.session_subtitle);
    mPhotoViewContainer = findViewById(R.id.session_photo_container);
    mPhotoView = (ImageView) findViewById(R.id.session_photo);

    mPlusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button);
    mAbstract = (TextView) findViewById(R.id.session_abstract);
    mRequirements = (TextView) findViewById(R.id.session_requirements);
    mTags = (LinearLayout) findViewById(R.id.session_tags);
    mTagsContainer = (ViewGroup) findViewById(R.id.session_tags_container);

    mAddScheduleButton = (CheckableFrameLayout) findViewById(R.id.add_schedule_button);
    mAddScheduleButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean starred = !mStarred;
            SessionsHelper helper = new SessionsHelper(EventDetailActivity.this);
            showStarred(starred, true);
            helper.setSessionStarred(mSessionUri, starred, mTitleString);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                mAddScheduleButton.announceForAccessibility(
                        starred ? getString(R.string.session_details_a11y_session_added)
                                : getString(R.string.session_details_a11y_session_removed));
            }

            /* [ANALYTICS:EVENT]
             * TRIGGER:   Add or remove a session from My Schedule.
             * CATEGORY:  'Session'
             * ACTION:    'Starred' or 'Unstarred'
             * LABEL:     Session title/subtitle.
             * [/ANALYTICS]
             */
            AnalyticsManager.sendEvent("Session", starred ? "Starred" : "Unstarred", mTitleString, 0L);
        }
    });

    ViewCompat.setTransitionName(mPhotoView, TRANSITION_NAME_PHOTO);

    LoaderManager manager = getLoaderManager();
    manager.initLoader(SessionsQuery._TOKEN, null, this);
    manager.initLoader(SpeakersQuery._TOKEN, null, this);
    manager.initLoader(TAG_METADATA_TOKEN, null, this);
}

From source file:com.google.samples.apps.iosched.ui.CurrentSessionActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    UIUtils.tryTranslateHttpIntent(this);
    BeamUtils.tryUpdateIntentFromBeam(this);
    boolean shouldBeFloatingWindow = false;
    if (shouldBeFloatingWindow) {
        setupFloatingWindow();/*  www . j a  v  a 2 s.co  m*/
    }
    super.onCreate(savedInstanceState);
    mSessionId = getCurrentSessionId();
    if (mSessionId == null) {
        complainMissingCurrentTalkId();
    } else {
        setContentView(R.layout.activity_current_session);

        final Toolbar toolbar = getActionBarToolbar();
        toolbar.setNavigationIcon(shouldBeFloatingWindow ? R.drawable.ic_ab_close : R.drawable.ic_up);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                toolbar.setTitle("");
            }
        });

        mSessionUri = ScheduleContract.Sessions.buildSessionUri(mSessionId);

        mFABElevation = getResources().getDimensionPixelSize(R.dimen.fab_elevation);
        mMaxHeaderElevation = getResources().getDimensionPixelSize(R.dimen.session_detail_max_header_elevation);

        mTagColorDotSize = getResources().getDimensionPixelSize(R.dimen.tag_color_dot_size);

        mHandler = new Handler();

        if (mSpeakersImageLoader == null) {
            mSpeakersImageLoader = new ImageLoader(this, R.drawable.person_image_empty);
        }
        if (mNoPlaceholderImageLoader == null) {
            mNoPlaceholderImageLoader = new ImageLoader(this);
        }

        mScrollView = (ObservableScrollView) findViewById(R.id.scroll_view);
        mScrollView.addCallbacks(this);
        ViewTreeObserver vto = mScrollView.getViewTreeObserver();
        if (vto.isAlive()) {
            vto.addOnGlobalLayoutListener(mGlobalLayoutListener);
        }

        mScrollViewChild = findViewById(R.id.scroll_view_child);
        mScrollViewChild.setVisibility(View.INVISIBLE);

        mDetailsContainer = findViewById(R.id.details_container);
        mHeaderBox = findViewById(R.id.header_session);
        mTitle = (TextView) findViewById(R.id.session_title);
        mSubtitle = (TextView) findViewById(R.id.session_subtitle);
        mPhotoViewContainer = findViewById(R.id.session_photo_container);
        mPhotoView = (ImageView) findViewById(R.id.session_photo);

        mPlusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button);
        mAbstract = (TextView) findViewById(R.id.session_abstract);
        mRequirements = (TextView) findViewById(R.id.session_requirements);
        mTags = (LinearLayout) findViewById(R.id.session_tags);
        mTagsContainer = (ViewGroup) findViewById(R.id.session_tags_container);

        mAddScheduleButton = (CheckableFrameLayout) findViewById(R.id.add_schedule_button);
        mAddScheduleButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                boolean starred = !mStarred;
                SessionsHelper helper = new SessionsHelper(CurrentSessionActivity.this);
                showStarred(starred, true);
                helper.setSessionStarred(mSessionUri, starred, mTitleString);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    mAddScheduleButton.announceForAccessibility(
                            starred ? getString(R.string.session_details_a11y_session_added)
                                    : getString(R.string.session_details_a11y_session_removed));
                }

                /* [ANALYTICS:EVENT]
                 * TRIGGER:   Add or remove a session from My Schedule.
                 * CATEGORY:  'Session'
                 * ACTION:    'Starred' or 'Unstarred'
                 * LABEL:     Session title/subtitle.
                 * [/ANALYTICS]
                 */
                AnalyticsManager.sendEvent("Session", starred ? "Starred" : "Unstarred", mTitleString, 0L);
            }
        });

        ViewCompat.setTransitionName(mPhotoView, TRANSITION_NAME_PHOTO);

        LoaderManager manager = getLoaderManager();
        manager.initLoader(SessionsQuery._TOKEN, null, this);
        manager.initLoader(SpeakersQuery._TOKEN, null, this);
        manager.initLoader(TAG_METADATA_TOKEN, null, this);
    }
}

From source file:com.saarang.samples.apps.iosched.ui.SessionDetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    UIUtils.tryTranslateHttpIntent(this);
    BeamUtils.tryUpdateIntentFromBeam(this);
    boolean shouldBeFloatingWindow = shouldBeFloatingWindow();
    if (shouldBeFloatingWindow) {
        setupFloatingWindow();/*from www.j a va  2s . c om*/
    }

    super.onCreate(savedInstanceState);
    setContentView(com.saarang.samples.apps.iosched.R.layout.activity_session_detail);

    final Toolbar toolbar = getActionBarToolbar();
    toolbar.setNavigationIcon(shouldBeFloatingWindow ? com.saarang.samples.apps.iosched.R.drawable.ic_ab_close
            : com.saarang.samples.apps.iosched.R.drawable.ic_up);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();
        }
    });
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            toolbar.setTitle("");
        }
    });

    if (savedInstanceState == null) {
        Uri sessionUri = getIntent().getData();
        BeamUtils.setBeamSessionUri(this, sessionUri);
    }

    mSessionUri = getIntent().getData();

    if (mSessionUri == null) {
        return;
    }

    mSessionId = ScheduleContract.Sessions.getSessionId(mSessionUri);

    mFABElevation = getResources()
            .getDimensionPixelSize(com.saarang.samples.apps.iosched.R.dimen.fab_elevation);
    mMaxHeaderElevation = getResources().getDimensionPixelSize(
            com.saarang.samples.apps.iosched.R.dimen.session_detail_max_header_elevation);

    mTagColorDotSize = getResources()
            .getDimensionPixelSize(com.saarang.samples.apps.iosched.R.dimen.tag_color_dot_size);

    mHandler = new Handler();

    if (mSpeakersImageLoader == null) {
        mSpeakersImageLoader = new ImageLoader(this,
                com.saarang.samples.apps.iosched.R.drawable.person_image_empty);
    }
    if (mNoPlaceholderImageLoader == null) {
        mNoPlaceholderImageLoader = new ImageLoader(this);
    }

    mScrollView = (ObservableScrollView) findViewById(com.saarang.samples.apps.iosched.R.id.scroll_view);
    mScrollView.addCallbacks(this);
    ViewTreeObserver vto = mScrollView.getViewTreeObserver();
    if (vto.isAlive()) {
        vto.addOnGlobalLayoutListener(mGlobalLayoutListener);
    }

    mScrollViewChild = findViewById(com.saarang.samples.apps.iosched.R.id.scroll_view_child);
    mScrollViewChild.setVisibility(View.INVISIBLE);

    mDetailsContainer = findViewById(com.saarang.samples.apps.iosched.R.id.details_container);
    mHeaderBox = findViewById(com.saarang.samples.apps.iosched.R.id.header_session);
    mTitle = (TextView) findViewById(com.saarang.samples.apps.iosched.R.id.session_title);
    mSubtitle = (TextView) findViewById(com.saarang.samples.apps.iosched.R.id.session_subtitle);
    mPhotoViewContainer = findViewById(com.saarang.samples.apps.iosched.R.id.session_photo_container);
    mPhotoView = (ImageView) findViewById(com.saarang.samples.apps.iosched.R.id.session_photo);

    mPlusOneButton = (PlusOneButton) findViewById(com.saarang.samples.apps.iosched.R.id.plus_one_button);
    mAbstract = (TextView) findViewById(com.saarang.samples.apps.iosched.R.id.session_abstract);
    mRequirements = (TextView) findViewById(com.saarang.samples.apps.iosched.R.id.session_requirements);
    mTags = (LinearLayout) findViewById(com.saarang.samples.apps.iosched.R.id.session_tags);
    mTagsContainer = (ViewGroup) findViewById(com.saarang.samples.apps.iosched.R.id.session_tags_container);

    mAddScheduleButton = (CheckableFrameLayout) findViewById(
            com.saarang.samples.apps.iosched.R.id.add_schedule_button);
    mAddScheduleButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean starred = !mStarred;
            SessionsHelper helper = new SessionsHelper(SessionDetailActivity.this);
            showStarred(starred, true);
            helper.setSessionStarred(mSessionUri, starred, mTitleString);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                mAddScheduleButton.announceForAccessibility(starred
                        ? getString(
                                com.saarang.samples.apps.iosched.R.string.session_details_a11y_session_added)
                        : getString(
                                com.saarang.samples.apps.iosched.R.string.session_details_a11y_session_removed));
            }

            /* [ANALYTICS:EVENT]
             * TRIGGER:   Add or remove a session from My Schedule.
             * CATEGORY:  'Session'
             * ACTION:    'Starred' or 'Unstarred'
             * LABEL:     Session title/subtitle.
             * [/ANALYTICS]
             */
            AnalyticsManager.sendEvent("Session", starred ? "Starred" : "Unstarred", mTitleString, 0L);
        }
    });

    ViewCompat.setTransitionName(mPhotoView, TRANSITION_NAME_PHOTO);

    LoaderManager manager = getLoaderManager();
    manager.initLoader(SessionsQuery._TOKEN, null, this);
    manager.initLoader(SpeakersQuery._TOKEN, null, this);
    manager.initLoader(TAG_METADATA_TOKEN, null, this);
}

From source file:de.dreier.mytargets.views.MaterialTapTargetPrompt.java

/**
 * Adds layout listener to view parent to capture layout changes.
 *///from ww  w .  java 2 s .  c o m
private void addGlobalLayoutListener() {
    final ViewTreeObserver viewTreeObserver = getParentView().getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.addOnGlobalLayoutListener(mGlobalLayoutListener);
    }
}

From source file:de.dreier.mytargets.views.MaterialTapTargetPrompt.java

/**
 * Removes global layout listener added in {@link #addGlobalLayoutListener()}.
 *///from  www.  j av a 2  s  . c om
private void removeGlobalLayoutListener() {
    final ViewTreeObserver viewTreeObserver = getParentView().getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            viewTreeObserver.removeOnGlobalLayoutListener(mGlobalLayoutListener);
        } else {
            //noinspection deprecation
            viewTreeObserver.removeGlobalOnLayoutListener(mGlobalLayoutListener);
        }
    }
}