Search in sources :

Example 71 with ViewTreeObserver

use of android.view.ViewTreeObserver in project ActionBarSherlock by JakeWharton.

the class ActivityChooserView method onDetachedFromWindow.

@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    ActivityChooserModel dataModel = mAdapter.getDataModel();
    if (dataModel != null) {
        try {
            dataModel.unregisterObserver(mModelDataSetOberver);
        } catch (IllegalStateException e) {
        //Oh, well... fixes issue #557
        }
    }
    ViewTreeObserver viewTreeObserver = getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
    }
    mIsAttachedToWindow = false;
}
Also used : ViewTreeObserver(android.view.ViewTreeObserver)

Example 72 with ViewTreeObserver

use of android.view.ViewTreeObserver in project UltimateAndroid by cymcsg.

the class FloatingActionButton method toggle.

private void toggle(final boolean visible, final boolean animate, boolean force) {
    if (mVisible != visible || force) {
        mVisible = visible;
        int height = getHeight();
        if (height == 0 && !force) {
            ViewTreeObserver vto = getViewTreeObserver();
            if (vto.isAlive()) {
                vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

                    @Override
                    public boolean onPreDraw() {
                        ViewTreeObserver currentVto = getViewTreeObserver();
                        if (currentVto.isAlive()) {
                            currentVto.removeOnPreDrawListener(this);
                        }
                        toggle(visible, animate, true);
                        return true;
                    }
                });
                return;
            }
        }
        int translationY = visible ? 0 : height + getMarginBottom();
        if (animate) {
            animate().setInterpolator(mInterpolator).setDuration(TRANSLATE_DURATION_MILLIS).translationY(translationY);
        } else {
            setTranslationY(translationY);
        }
    }
}
Also used : ViewTreeObserver(android.view.ViewTreeObserver) SuppressLint(android.annotation.SuppressLint)

Example 73 with ViewTreeObserver

use of android.view.ViewTreeObserver in project android_frameworks_base by DirtyUnicorns.

the class PopupWindow method attachToAnchor.

private void attachToAnchor(View anchor, int xoff, int yoff, int gravity) {
    detachFromAnchor();
    final ViewTreeObserver vto = anchor.getViewTreeObserver();
    if (vto != null) {
        vto.addOnScrollChangedListener(mOnScrollChangedListener);
    }
    final View anchorRoot = anchor.getRootView();
    anchorRoot.addOnAttachStateChangeListener(mOnAnchorRootDetachedListener);
    mAnchor = new WeakReference<>(anchor);
    mAnchorRoot = new WeakReference<>(anchorRoot);
    mIsAnchorRootAttached = anchorRoot.isAttachedToWindow();
    mAnchorXoff = xoff;
    mAnchorYoff = yoff;
    mAnchoredGravity = gravity;
}
Also used : ViewTreeObserver(android.view.ViewTreeObserver) View(android.view.View)

Example 74 with ViewTreeObserver

use of android.view.ViewTreeObserver in project android_frameworks_base by DirtyUnicorns.

the class CropView method moveToLeft.

public void moveToLeft() {
    if (getWidth() == 0 || getHeight() == 0) {
        final ViewTreeObserver observer = getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

            public void onGlobalLayout() {
                moveToLeft();
                getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });
    }
    final RectF edges = mTempEdges;
    getEdgesHelper(edges);
    final float scale = mRenderer.scale;
    mCenterX += Math.ceil(edges.left / scale);
    updateCenter();
}
Also used : RectF(android.graphics.RectF) OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) ViewTreeObserver(android.view.ViewTreeObserver)

Example 75 with ViewTreeObserver

use of android.view.ViewTreeObserver in project android_frameworks_base by DirtyUnicorns.

the class Spinner method onRestoreInstanceState.

@Override
public void onRestoreInstanceState(Parcelable state) {
    SavedState ss = (SavedState) state;
    super.onRestoreInstanceState(ss.getSuperState());
    if (ss.showDropdown) {
        ViewTreeObserver vto = getViewTreeObserver();
        if (vto != null) {
            final OnGlobalLayoutListener listener = new OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {
                    if (!mPopup.isShowing()) {
                        mPopup.show(getTextDirection(), getTextAlignment());
                    }
                    final ViewTreeObserver vto = getViewTreeObserver();
                    if (vto != null) {
                        vto.removeOnGlobalLayoutListener(this);
                    }
                }
            };
            vto.addOnGlobalLayoutListener(listener);
        }
    }
}
Also used : OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) ViewTreeObserver(android.view.ViewTreeObserver)

Aggregations

ViewTreeObserver (android.view.ViewTreeObserver)222 View (android.view.View)56 OnGlobalLayoutListener (android.view.ViewTreeObserver.OnGlobalLayoutListener)25 ImageView (android.widget.ImageView)25 TextView (android.widget.TextView)15 ViewGroup (android.view.ViewGroup)14 SuppressLint (android.annotation.SuppressLint)13 AdapterView (android.widget.AdapterView)12 TypedArray (android.content.res.TypedArray)7 Test (org.junit.Test)7 RectF (android.graphics.RectF)6 DisplayMetrics (android.util.DisplayMetrics)6 ViewParent (android.view.ViewParent)6 LinearLayout (android.widget.LinearLayout)6 ListView (android.widget.ListView)6 Resources (android.content.res.Resources)5 ValueAnimator (android.animation.ValueAnimator)4 TargetApi (android.annotation.TargetApi)4 Activity (android.app.Activity)4 Paint (android.graphics.Paint)4