Search in sources :

Example 6 with ViewTreeObserver

use of android.view.ViewTreeObserver in project cw-omnibus by commonsguy.

the class ActivityChooserView method dismissPopup.

/**
     * Dismisses the popup window with activities.
     *
     * @return True if dismissed, false if already dismissed.
     */
public boolean dismissPopup() {
    if (isShowingPopup()) {
        getListPopupWindow().dismiss();
        ViewTreeObserver viewTreeObserver = getViewTreeObserver();
        if (viewTreeObserver.isAlive()) {
            viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
        }
    }
    return true;
}
Also used : ViewTreeObserver(android.view.ViewTreeObserver)

Example 7 with ViewTreeObserver

use of android.view.ViewTreeObserver in project PhotoPicker by donglua.

the class ImagePagerFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.__picker_picker_fragment_image_pager, container, false);
    mViewPager = (ViewPager) rootView.findViewById(R.id.vp_photos);
    mViewPager.setAdapter(mPagerAdapter);
    mViewPager.setCurrentItem(currentItem);
    mViewPager.setOffscreenPageLimit(5);
    // we're recreated automatically by the window manager (e.g., device rotation)
    if (savedInstanceState == null && hasAnim) {
        ViewTreeObserver observer = mViewPager.getViewTreeObserver();
        observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

            @Override
            public boolean onPreDraw() {
                mViewPager.getViewTreeObserver().removeOnPreDrawListener(this);
                // Figure out where the thumbnail and full size versions are, relative
                // to the screen and each other
                int[] screenLocation = new int[2];
                mViewPager.getLocationOnScreen(screenLocation);
                thumbnailLeft = thumbnailLeft - screenLocation[0];
                thumbnailTop = thumbnailTop - screenLocation[1];
                runEnterAnimation();
                return true;
            }
        });
    }
    mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            hasAnim = currentItem == position;
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    return rootView;
}
Also used : View(android.view.View) ViewTreeObserver(android.view.ViewTreeObserver) ViewPager(android.support.v4.view.ViewPager) Nullable(android.support.annotation.Nullable)

Example 8 with ViewTreeObserver

use of android.view.ViewTreeObserver in project Android-ShareEverywhere by dgmltn.

the class ShareView method onDetachedFromWindow.

@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    ActivityChooserModel dataModel = mAdapter.getDataModel();
    if (dataModel != null) {
        try {
            dataModel.unregisterObserver(mModelDataSetObserver);
        } 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 9 with ViewTreeObserver

use of android.view.ViewTreeObserver in project Android-ShareEverywhere by dgmltn.

the class ShareView method dismissPopup.

/**
	 * Dismisses the popup window with activities.
	 *
	 * @return True if dismissed, false if already dismissed.
	 */
public boolean dismissPopup() {
    if (isShowingPopup()) {
        getListPopupWindow().dismiss();
        ViewTreeObserver viewTreeObserver = getViewTreeObserver();
        if (viewTreeObserver.isAlive()) {
            viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
        }
    }
    return true;
}
Also used : ViewTreeObserver(android.view.ViewTreeObserver)

Example 10 with ViewTreeObserver

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

the class DynamicListView method handleCellSwitch.

/**
     * This method determines whether the hover cell has been shifted far enough
     * to invoke a cell swap. If so, then the respective cell swap candidate is
     * determined and the data set is changed. Upon posting a notification of the
     * data set change, a layout is invoked to place the cells in the right place.
     * Using a ViewTreeObserver and a corresponding OnPreDrawListener, we can
     * offset the cell being swapped to where it previously was and then animate it to
     * its new position.
     */
private void handleCellSwitch() {
    final int deltaY = mLastEventY - mDownY;
    int deltaYTotal = mHoverCellOriginalBounds.top + mTotalOffset + deltaY;
    View belowView = getViewForId(mBelowItemId);
    View mobileView = getViewForId(mMobileItemId);
    View aboveView = getViewForId(mAboveItemId);
    boolean isBelow = (belowView != null) && (deltaYTotal > belowView.getTop());
    boolean isAbove = (aboveView != null) && (deltaYTotal < aboveView.getTop());
    if (isBelow || isAbove) {
        final long switchItemId = isBelow ? mBelowItemId : mAboveItemId;
        View switchView = isBelow ? belowView : aboveView;
        final int originalItem = getPositionForView(mobileView);
        if (switchView == null) {
            updateNeighborViewsForId(mMobileItemId);
            return;
        }
        if (getPositionForView(switchView) < getHeaderViewsCount()) {
            return;
        }
        swapElements(originalItem, getPositionForView(switchView));
        BaseAdapter adapter;
        if (getAdapter() instanceof HeaderViewListAdapter) {
            adapter = (BaseAdapter) ((HeaderViewListAdapter) getAdapter()).getWrappedAdapter();
        } else {
            adapter = (BaseAdapter) getAdapter();
        }
        adapter.notifyDataSetChanged();
        mDownY = mLastEventY;
        mDownX = mLastEventX;
        final int switchViewStartTop = switchView.getTop();
        mobileView.setVisibility(View.VISIBLE);
        switchView.setVisibility(View.INVISIBLE);
        updateNeighborViewsForId(mMobileItemId);
        final ViewTreeObserver observer = getViewTreeObserver();
        observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

            public boolean onPreDraw() {
                observer.removeOnPreDrawListener(this);
                View switchView = getViewForId(switchItemId);
                mTotalOffset += deltaY;
                int switchViewNewTop = switchView.getTop();
                int delta = switchViewStartTop - switchViewNewTop;
                ViewHelper.setTranslationY(switchView, delta);
                ObjectAnimator animator = ObjectAnimator.ofFloat(switchView, "translationY", 0);
                animator.setDuration(MOVE_DURATION);
                animator.start();
                return true;
            }
        });
    }
}
Also used : ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) BaseAdapter(android.widget.BaseAdapter) 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)12 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 Paint (android.graphics.Paint)4 Point (android.graphics.Point)4