android.view.ViewTreeObserver.OnGlobalLayoutListener Java Examples

The following examples show how to use android.view.ViewTreeObserver.OnGlobalLayoutListener. 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: SpotlightView.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void onAttachedToWindow() {
	super.onAttachedToWindow();

	getViewTreeObserver().addOnGlobalLayoutListener(
			new OnGlobalLayoutListener() {
				@SuppressWarnings("deprecation")
				@Override
				public void onGlobalLayout() {
					createShader();
					setMaskScale(1.0f);

					if (mCallback != null) {
						mCallback.onSetupAnimation(SpotlightView.this);
					}

					getViewTreeObserver()
							.removeOnGlobalLayoutListener(this);
				}
			});
}
 
Example #2
Source File: SceneActivity.java    From GestureViews with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    scene = new SceneView(this);
    setContentView(scene);
    getSupportActionBarNotNull().setDisplayHomeAsUpEnabled(true);
    setInfoText(R.string.info_objects_control);

    // Waiting for scene to be laid out before setting up the items
    scene.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            scene.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            showItems();
        }
    });
}
 
Example #3
Source File: PagerSlidingTabStrip.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void notifyDataSetChanged() {
    tabsContainer.removeAllViews();
    tabCount = pager.getAdapter().getCount();
    for (int i = 0; i < tabCount; i++) {
        if (pager.getAdapter() instanceof IconTabProvider) {
            addIconTab(i, ((IconTabProvider) pager.getAdapter()).getPageIconDrawable(i));
        }
    }
    updateTabStyles();
    getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            getViewTreeObserver().removeOnGlobalLayoutListener(this);
            currentPosition = pager.getCurrentItem();
            scrollToChild(currentPosition, 0);
        }
    });
}
 
Example #4
Source File: XListView.java    From Android with MIT License 6 votes vote down vote up
private void initWithContext(Context context) {
  mScroller = new Scroller(context, new DecelerateInterpolator());
  // XListView need the scroll event, and it will dispatch the event to
  // user's listener (as a proxy).
  super.setOnScrollListener(this);

  m_context = context;
  // init header view
  mHeaderView = new XListViewHeader(context);
  mHeaderViewContent = (RelativeLayout) mHeaderView
      .findViewById(R.id.xlistview_header_content);
  addHeaderView(mHeaderView);

  // init header height
  mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(
      new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
          mHeaderViewHeight = mHeaderViewContent.getHeight();
          getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
      });
}
 
Example #5
Source File: VLayoutActivity.java    From vlayout with MIT License 6 votes vote down vote up
public void setListenerToRootView() {
    final View activityRootView = getWindow().getDecorView().findViewById(android.R.id.content);
    activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {

            int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
            if (heightDiff > 100) { // 99% of the time the height diff will be due to a keyboard.
                if (isOpened == false) {
                    //Do two things, make the view top visible and the editText smaller
                }
                isOpened = true;
            } else if (isOpened == true) {
                isOpened = false;
                final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);
                recyclerView.getAdapter().notifyDataSetChanged();
            }
        }
    });
}
 
Example #6
Source File: PullPushLayout.java    From Android-PullPushScrollView with MIT License 6 votes vote down vote up
private void initView() {
   	 mHeader = (ViewGroup) findViewById(R.id.rl_top);
   	 mHeaderChild = mHeader.getChildAt(0);
        mContent = findViewById(R.id.ll_content);

        mHeader.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @SuppressWarnings("deprecation")
            @Override
            public void onGlobalLayout() {
                mHeader.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                range = mHeader.getHeight();
                mHeader.getLayoutParams().height = range;
                mHeaderHeight = range;
            }
        });
	
}
 
Example #7
Source File: ZListView.java    From ZListVIew with Apache License 2.0 6 votes vote down vote up
private void initView(Context context) {

		scroller = new Scroller(context, new DecelerateInterpolator());

		headerView = new ZListViewHeader(context);
		footerView = new ZListViewFooter(context);

		headerViewContent = (RelativeLayout) headerView
				.findViewById(R.id.xlistview_header_content);
		headerView.getViewTreeObserver().addOnGlobalLayoutListener(
				new OnGlobalLayoutListener() {
					@SuppressWarnings("deprecation")
					@Override
					public void onGlobalLayout() {
						headerHeight = headerViewContent.getHeight();
						getViewTreeObserver()
								.removeGlobalOnLayoutListener(this);
					}
				});
		addHeaderView(headerView);

	}
 
Example #8
Source File: TabletTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Inflates the content, which is associated with a specific tab.
 *
 * @param tab
 *         The tab, whose content should be inflated, as an instance of the class {@link Tab}.
 *         The tab may not be null
 * @param listener
 *         The layout listener, which should be notified, when the view has been inflated, as an
 *         instance of the type {@link OnGlobalLayoutListener} or null, if no listener should be
 *         notified
 */
private void inflateContent(@NonNull final Tab tab,
                            @Nullable final OnGlobalLayoutListener listener) {
    Pair<View, Boolean> pair = contentViewRecycler.inflate(tab);
    View view = pair.first;

    if (listener != null) {
        boolean inflated = pair.second;

        if (inflated) {
            view.getViewTreeObserver()
                    .addOnGlobalLayoutListener(new LayoutListenerWrapper(view, listener));
        } else {
            listener.onGlobalLayout();
        }
    }
}
 
Example #9
Source File: TabletTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a layout listener, which allows to position the content of a tab, after
 * it has been inflated.
 *
 * @param tab
 *         The tab, whose content has been inflated, as an instance of the class {@link Tab}.
 *         The tab may not be null
 * @return The layout listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createContentLayoutListener(@NonNull final Tab tab) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = contentViewRecycler.getView(tab);

            if (view != null) {
                view.setX(0);
            }
        }

    };
}
 
Example #10
Source File: XListView.java    From Conquer with Apache License 2.0 6 votes vote down vote up
private void initWithContext(Context context) {
	mScroller = new Scroller(context, new DecelerateInterpolator());
	// XListView need the scroll event, and it will dispatch the event to
	// user's listener (as a proxy).
	super.setOnScrollListener(this);

	m_context = context;
	// init header view
	mHeaderView = new XListViewHeader(context);
	mHeaderViewContent = (RelativeLayout) mHeaderView.findViewById(R.id.xlistview_header_content);
	addHeaderView(mHeaderView);

	// init header height
	mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
		@Override
		public void onGlobalLayout() {
			mHeaderViewHeight = mHeaderViewContent.getHeight();
			getViewTreeObserver().removeGlobalOnLayoutListener(this);
		}
	});
}
 
Example #11
Source File: DialogRootView.java    From AndroidMaterialDialog with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a listener, which allows to observe, when the child of the dialog's
 * scroll view has been layouted. If the scroll view's height is greater than necessary, its
 * height is reduced to match the height of its child.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createScrollViewChildLayoutListener() {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View child = scrollView.getChildAt(0);
            int childHeight = child.getHeight();
            int containerHeight = scrollView.getHeight() - scrollView.getPaddingTop() -
                    scrollView.getPaddingBottom();

            if (containerHeight > childHeight) {
                LinearLayout.LayoutParams layoutParams =
                        (LinearLayout.LayoutParams) scrollView.getLayoutParams();
                layoutParams.height = childHeight;
                layoutParams.weight = 0;
                scrollView.requestLayout();
            }

            ViewUtil.removeOnGlobalLayoutListener(child.getViewTreeObserver(), this);
        }

    };
}
 
Example #12
Source File: CropView.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #13
Source File: PhoneTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a layout listener, which allows to adapt the size and position of a tab,
 * once its view has been inflated.
 *
 * @param item
 *         The item, which corresponds to the tab, whose view should be adapted, as an instance
 *         of the class {@link AbstractItem}. The item may not be null
 * @param dragging
 *         True, if the item is currently being dragged, false otherwise
 * @param layoutListener
 *         The layout lister, which should be notified, when the created listener is invoked, as
 *         an instance of the type {@link OnGlobalLayoutListener} or null, if no listener should
 *         be notified
 * @return The layout listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The layout listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createInflateViewLayoutListener(@NonNull final AbstractItem item,
                                                               final boolean dragging,
                                                               @Nullable final OnGlobalLayoutListener layoutListener) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            adaptViewSize(item);
            updateView(item, dragging);

            if (layoutListener != null) {
                layoutListener.onGlobalLayout();
            }
        }

    };
}
 
Example #14
Source File: PhoneTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a layout listener, which allows to position a tab, which is a neighbor of
 * the currently selected tab, when swiping horizontally.
 *
 * @param neighbor
 *         The tab item, which corresponds to the neighboring tab, as an instance of the class
 *         {@link TabItem}. The tab item may not be null
 * @param dragDistance
 *         The distance of the swipe gesture in pixels as a {@link Float} value
 * @return The layout listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The layout listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createSwipeNeighborLayoutListener(
        @NonNull final TabItem neighbor, final float dragDistance) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            float position;

            if (dragDistance > 0) {
                position = -getTabSwitcher().getWidth() + dragDistance - swipedTabDistance;
            } else {
                position = getTabSwitcher().getWidth() + dragDistance + swipedTabDistance;
            }

            getArithmetics().setPosition(Axis.X_AXIS, neighbor, position);
        }

    };
}
 
Example #15
Source File: MyHorizontalScrollView.java    From KickAssSlidingMenu with Apache License 2.0 6 votes vote down vote up
/**
 * @param children
 *            The child Views to add to parent.
 * @param scrollToViewIdx
 *            The index of the View to scroll to after initialisation.
 * @param sizeCallback
 *            A SizeCallback to interact with the HSV.
 */
public void initViews(View[] children, int scrollToViewIdx, SizeCallback sizeCallback) {
    // A ViewGroup MUST be the only child of the HSV
    ViewGroup parent = (ViewGroup) getChildAt(0);

    // Add all the children, but add them invisible so that the layouts are calculated, but you can't see the Views
    for (int i = 0; i < children.length; i++) {
        children[i].setVisibility(View.INVISIBLE);
        parent.addView(children[i]);
    }

    // Add a layout listener to this HSV
    // This listener is responsible for arranging the child views.
    OnGlobalLayoutListener listener = new MyOnGlobalLayoutListener(parent, children, scrollToViewIdx, sizeCallback);
    getViewTreeObserver().addOnGlobalLayoutListener(listener);
}
 
Example #16
Source File: FeedListFragment.java    From umeng_community_android with MIT License 6 votes vote down vote up
private void addOnGlobalLayoutListener(final int position) {
        mOnGlobalLayoutListener = new OnGlobalLayoutListener() {

            @SuppressWarnings("deprecation")
            @Override
            public void onGlobalLayout() {
//                int count = mFeedsListView.getHeaderViewsCount();
//                int headerheight = 0;
//                if (count > 0) {
//                    for (int i = 0; i < count; i++) {
//                        View view = mFeedsListView.getChildAt(i);
//                        headerheight += view.getHeight();
//                    }
//                }
//                mFeedsListView.setSelectionFromTop(position - 1, headerheight);
                mRootView.getRootView().getViewTreeObserver()
                        .removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
            }
        };
        mRootView.getRootView().getViewTreeObserver()
                .addOnGlobalLayoutListener(mOnGlobalLayoutListener);
    }
 
Example #17
Source File: MeasureUtils.java    From zone-sdk with MIT License 6 votes vote down vote up
/**
 * <br>调用时机:可见性 或者 布局状态改变的时候 如果view背景换了 那么一定invalited那么布局状态一定改变了
 * <br>Register a callback to be invoked when the global layout state or the visibility of views within the view tree changes
 *
 * @param v
 * @param gs 枚举表示 测量后是否移除此监听 目的是:为了防止被多次调用 (用完就移除     除非特殊一直想监听)
 */
public static void measure(final View v, final ListenerState gs, final OnMeasureListener oml) {
    ViewTreeObserver vto = v.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            int height = v.getMeasuredHeight();
            int width = v.getMeasuredWidth();
            if (oml != null) {
                oml.measureResult(v, width, height);
            }
            switch (gs) {
                case MEASURE_REMOVE:
                    v.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    break;
                case MEASURE_CONTINUE:
                    break;
                default:
                    break;
            }
        }
    });
}
 
Example #18
Source File: PagerSlidingTabStrip.java    From Cotable with Apache License 2.0 6 votes vote down vote up
public void notifyDataSetChanged() {
    tabsContainer.removeAllViews();
    tabCount = pager.getAdapter().getCount();
    for (int i = 0; i < tabCount; i++)
        addTabView(i, pager.getAdapter().getPageTitle(i).toString());

    getViewTreeObserver().addOnGlobalLayoutListener(
            new OnGlobalLayoutListener() {

                @SuppressWarnings("deprecation")
                @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
                @Override
                public void onGlobalLayout() {
                    if (Build.VERSION.SDK_INT < 16)
                        getViewTreeObserver().removeGlobalOnLayoutListener(
                                this);
                    else
                        getViewTreeObserver().removeOnGlobalLayoutListener(
                                this);
                    currentPosition = pager.getCurrentItem();
                    setChooseTabViewTextColor(currentPosition);
                    scrollToChild(currentPosition, 0);
                }
            });
}
 
Example #19
Source File: WallpaperPickerActivity.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
private void initializeScrollForRtl() {
    final HorizontalScrollView scroll =
            (HorizontalScrollView) findViewById(R.id.wallpaper_scroll_container);

    if (scroll.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
        final ViewTreeObserver observer = scroll.getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            public void onGlobalLayout() {
                LinearLayout masterWallpaperList =
                        (LinearLayout) findViewById(R.id.master_wallpaper_list);
                scroll.scrollTo(masterWallpaperList.getWidth(), 0);
                scroll.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });
    }
}
 
Example #20
Source File: PullToRefreshSwipeMenuListView.java    From Android-PullToRefresh-SwipeMenuListView-Sample with MIT License 6 votes vote down vote up
private void init(Context context) {
	mScroller = new Scroller(context, new DecelerateInterpolator());
	super.setOnScrollListener(this);
	// init header view
	mHeaderView = new PullToRefreshListHeader(context);
	mHeaderViewContent = (RelativeLayout) mHeaderView.findViewById(R.id.xlistview_header_content);
	mHeaderTimeView = (TextView) mHeaderView.findViewById(R.id.xlistview_header_time);
	addHeaderView(mHeaderView);

	// init footer view
	mFooterView = new PullToRefreshListFooter(context);

	// init header height
	mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
		@Override
		public void onGlobalLayout() {
			mHeaderViewHeight = mHeaderViewContent.getHeight();
			getViewTreeObserver().removeGlobalOnLayoutListener(this);
		}
	});
	MAX_X = dp2px(MAX_X);
	MAX_Y = dp2px(MAX_Y);
	mTouchState = TOUCH_STATE_NONE;
}
 
Example #21
Source File: MapWidget.java    From mappwidget with Apache License 2.0 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right,
		int bottom) {
	super.onLayout(changed, left, top, right, bottom);

	if (requestCenterMap) {
		requestCenterMap = false;

		final ViewTreeObserver observer = this.getViewTreeObserver();
		if (observer.isAlive()) {
			observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
				@Override
				public void onGlobalLayout() {
					doCorrectPosition(true, false);
					jumpTo(getOriginalMapWidth() / 2,
							getOriginalMapHeight() / 2);

					observer.removeGlobalOnLayoutListener(this);
				}
			});
		}
	} else {
		doCorrectPosition(false, false);
	}
}
 
Example #22
Source File: KeyboardUtils.java    From AndroidUtilCode with Apache License 2.0 6 votes vote down vote up
/**
 * Fix the bug of 5497 in Android.
 * <p>It will clean the adjustResize</p>
 *
 * @param window The window.
 */
public static void fixAndroidBug5497(@NonNull final Window window) {
    int softInputMode = window.getAttributes().softInputMode;
    window.setSoftInputMode(softInputMode & ~WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    final FrameLayout contentView = window.findViewById(android.R.id.content);
    final View contentViewChild = contentView.getChildAt(0);
    final int paddingBottom = contentViewChild.getPaddingBottom();
    final int[] contentViewInvisibleHeightPre5497 = {getContentViewInvisibleHeight(window)};
    contentView.getViewTreeObserver()
            .addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    int height = getContentViewInvisibleHeight(window);
                    if (contentViewInvisibleHeightPre5497[0] != height) {
                        contentViewChild.setPadding(
                                contentViewChild.getPaddingLeft(),
                                contentViewChild.getPaddingTop(),
                                contentViewChild.getPaddingRight(),
                                paddingBottom + getDecorViewInvisibleHeight(window)
                        );
                        contentViewInvisibleHeightPre5497[0] = height;
                    }
                }
            });
}
 
Example #23
Source File: KeyboardUtils.java    From AndroidUtilCode with Apache License 2.0 6 votes vote down vote up
/**
 * Register soft input changed listener.
 *
 * @param window   The window.
 * @param listener The soft input changed listener.
 */
public static void registerSoftInputChangedListener(@NonNull final Window window,
                                                    @NonNull final OnSoftInputChangedListener listener) {
    final int flags = window.getAttributes().flags;
    if ((flags & WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) != 0) {
        window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }
    final FrameLayout contentView = window.findViewById(android.R.id.content);
    final int[] decorViewInvisibleHeightPre = {getDecorViewInvisibleHeight(window)};
    OnGlobalLayoutListener onGlobalLayoutListener = new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            int height = getDecorViewInvisibleHeight(window);
            if (decorViewInvisibleHeightPre[0] != height) {
                listener.onSoftInputChanged(height);
                decorViewInvisibleHeightPre[0] = height;
            }
        }
    };
    contentView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener);
    contentView.setTag(TAG_ON_GLOBAL_LAYOUT_LISTENER, onGlobalLayoutListener);
}
 
Example #24
Source File: PhoneTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a layout listener, which allows to adapt the bottom margin of a tab, once
 * its view has been inflated.
 *
 * @param item
 *         The item, which corresponds to the tab, whose view should be adapted, as an instance
 *         of the class {@link AbstractItem}. The item may not be null
 * @return The layout listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The layout listener may not be null
 */
private OnGlobalLayoutListener createBottomMarginLayoutListener(
        @NonNull final AbstractItem item) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = item.getView();

            if (tabViewBottomMargin == -1) {
                tabViewBottomMargin = calculateBottomMargin(item);
            }

            FrameLayout.LayoutParams layoutParams =
                    (FrameLayout.LayoutParams) view.getLayoutParams();
            layoutParams.bottomMargin = tabViewBottomMargin;
            view.setLayoutParams(layoutParams);
        }

    };
}
 
Example #25
Source File: PullToRefreshListView.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
private void initWithContext(Context context, AttributeSet attrs) {
    ScrollUtils.disableOVER_SCROLL_NEVER(this);

    mScroller = new Scroller(context, new DecelerateInterpolator());
    // PullToRefreshListView need the scroll event, and it will dispatch the
    // event to
    // user's listener (as a proxy).
    super.setOnScrollListener(this);

    // init header view
    mHeaderView = new PullToRefreshListViewHeader(context, attrs);
    mHeaderViewContent = (RelativeLayout) mHeaderView
            .findViewById(R.id.pulltorefresh_listview_header_content);
    mHeaderTimeView = (TextView) mHeaderView
            .findViewById(R.id.pulltorefresh_listview_header_time);
    addHeaderView(mHeaderView);

    // init footer view
    mFooterView = new PullToRefreshListViewFooter(context, attrs);

    // init header height
    mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(
            new OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    mHeaderViewHeight = mHeaderViewContent.getHeight();
                    getViewTreeObserver()
                            .removeGlobalOnLayoutListener(this);
                }
            });

    setPullRefreshEnable(mEnablePullRefresh);
    setPullLoadEnable(mEnablePullRefresh);
}
 
Example #26
Source File: PullToRefreshSwipeMenuListView.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
	//mScroller = new Scroller(context, new DecelerateInterpolator());
	mScroller = ScrollerCompat.create(context,new DecelerateInterpolator());
	super.setOnScrollListener(this);
	// init header view
	mHeaderView = new PullToRefreshListHeader(context);
	mHeaderViewContent = (RelativeLayout) mHeaderView.findViewById(R.id.xlistview_header_content);
	mHeaderTimeView = (TextView) mHeaderView.findViewById(R.id.xlistview_header_time);
	addHeaderView(mHeaderView);

	// init footer view
	mFooterView = new PullToRefreshListFooter(context);

	// init header height
	mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
		@SuppressWarnings("deprecation")
		@Override
		public void onGlobalLayout() {
			mHeaderViewHeight = mHeaderViewContent.getHeight();
			if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
				getViewTreeObserver().removeOnGlobalLayoutListener(this);
			}else{
				getViewTreeObserver().removeGlobalOnLayoutListener(this);
			}
		}
	});
	MAX_X = dp2px(MAX_X);
	MAX_Y = dp2px(MAX_Y);
	mTouchState = TOUCH_STATE_NONE;
}
 
Example #27
Source File: DisplayUtil.java    From youqu_master with Apache License 2.0 5 votes vote down vote up
/**
 * 直接获取控件的宽、高
 * @param view
 * @return int[]
 */
public static int[] getWidgetWH(final View view){
    ViewTreeObserver vto2 = view.getViewTreeObserver();
    vto2.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
        	view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
    });
	return new int[]{view.getWidth(),view.getHeight()};
}
 
Example #28
Source File: TabPagerIndicator.java    From ViewPagerTabIndicator with Artistic License 2.0 5 votes vote down vote up
public void notifyDataSetChanged() {
    //先移除掉所有的View ,防止重复添加
    tabsContainer.removeAllViews();

    tabCount = pager.getAdapter().getCount();

    for (int i = 0; i < tabCount; i++) {
        //区分是文字还是Icon的导航
        if (pager.getAdapter() instanceof IconTabProvider) {
            addIconTab(i, ((IconTabProvider) pager.getAdapter()).getPageIconResId(i));
        } else {
            addTextTab(i, pager.getAdapter().getPageTitle(i).toString());
        }

    }

    updateTabStyles();

    getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @SuppressWarnings("deprecation")
        @SuppressLint("NewApi")
        @Override
        public void onGlobalLayout() {

            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }

            currentPosition = pager.getCurrentItem();
            scrollToChild(currentPosition, 0);

        }
    });

}
 
Example #29
Source File: PagerSlidingTabStrip.java    From Android-Chat-Widget with Apache License 2.0 5 votes vote down vote up
public void notifyDataSetChanged() {

		tabsContainer.removeAllViews();

		tabCount = pager.getAdapter().getCount();

		for (int i = 0; i < tabCount; i++) {

			if (pager.getAdapter() instanceof IconTabProvider) {
				addIconTab(i, ((IconTabProvider) pager.getAdapter()).getPageIconResId(i));
			} else {
				addTextTab(i, pager.getAdapter().getPageTitle(i).toString());
			}

		}

		updateTabStyles();

		getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

			@SuppressWarnings("deprecation")
			@SuppressLint("NewApi")
			@Override
			public void onGlobalLayout() {

				if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
					getViewTreeObserver().removeGlobalOnLayoutListener(this);
				} else {
					getViewTreeObserver().removeOnGlobalLayoutListener(this);
				}

				currentPosition = pager.getCurrentItem();
				scrollToChild(currentPosition, 0);
			}
		});

	}
 
Example #30
Source File: PagerSlidingTabStrip.java    From MagicHeaderViewPager with Apache License 2.0 5 votes vote down vote up
public void notifyDataSetChanged() {

		tabsContainer.removeAllViews();

		tabCount = pager.getAdapter().getCount();

		for (int i = 0; i < tabCount; i++) {

			if (pager.getAdapter() instanceof IconTabProvider) {
				addIconTab(i, ((IconTabProvider) pager.getAdapter()).getPageIconResId(i));
			} else {
				addTextTab(i, pager.getAdapter().getPageTitle(i).toString());
			}

		}

		updateTabStyles();

		getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

			@SuppressWarnings("deprecation")
			@SuppressLint("NewApi")
			@Override
			public void onGlobalLayout() {

				if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
					getViewTreeObserver().removeGlobalOnLayoutListener(this);
				} else {
					getViewTreeObserver().removeOnGlobalLayoutListener(this);
				}

				currentPosition = pager.getCurrentItem();
				scrollToChild(currentPosition, 0);
			}
		});

	}