Java 类android.view.ViewTreeObserver 实例源码

项目:android-instant-apps    文件:MainActivity.java   
@Override
public void onActivityReenter(int resultCode, Intent data) {
    postponeEnterTransition();
    // Start the postponed transition when the recycler view is ready to be drawn.
    grid.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            grid.getViewTreeObserver().removeOnPreDrawListener(this);
            startPostponedEnterTransition();
            return true;
        }
    });

    if (data == null) {
        return;
    }

    final int selectedItem = data.getIntExtra(IntentUtil.SELECTED_ITEM_POSITION, 0);
    grid.scrollToPosition(selectedItem);

    PhotoViewHolder holder = (PhotoViewHolder) grid.
            findViewHolderForAdapterPosition(selectedItem);
    if (holder == null) {
        Log.w(TAG, "onActivityReenter: Holder is null, remapping cancelled.");
        return;
    }

    DetailSharedElementEnterCallback callback =
            new DetailSharedElementEnterCallback(getIntent());
    callback.setView(holder.itemView);
    setExitSharedElementCallback(callback);

}
项目:GitHub    文件:DeferredRequestCreator.java   
@Override public boolean onPreDraw() {
  ImageView target = this.target.get();
  if (target == null) {
    return true;
  }

  ViewTreeObserver vto = target.getViewTreeObserver();
  if (!vto.isAlive()) {
    return true;
  }

  int width = target.getWidth();
  int height = target.getHeight();

  if (width <= 0 || height <= 0 || target.isLayoutRequested()) {
    return true;
  }

  target.removeOnAttachStateChangeListener(this);
  vto.removeOnPreDrawListener(this);
  this.target.clear();

  this.creator.unfit().resize(width, height).into(target, callback);
  return true;
}
项目:LucaHome-AndroidApplication    文件:MapContentViewBuilder.java   
public void Initialize() {
    _imageView = ((AppCompatActivity) _context).findViewById(R.id.skeletonList_backdrop_image_main);
    ViewTreeObserver imageViewViewTreeObserver = _imageView.getViewTreeObserver();
    imageViewViewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            Logger.getInstance().Debug(TAG, "_imageView imageViewViewTreeObserver onGlobalLayout");
            calculateReferenceSize();
            _imageView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
    });

    _relativeLayoutMapPaint = ((AppCompatActivity) _context).findViewById(R.id.skeletonList_backdrop_relativeLayoutPaint_main);
    ViewTreeObserver relativeLayoutViewTreeObserver = _relativeLayoutMapPaint.getViewTreeObserver();
    relativeLayoutViewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            Logger.getInstance().Debug(TAG, "_relativeLayoutMapPaint relativeLayoutViewTreeObserver onGlobalLayout");
            calculateReferenceSize();
            _relativeLayoutMapPaint.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
    });
}
项目:CustomAndroidOneSheeld    文件:SpeechRecognitionFragment.java   
@Override
public void doOnViewCreated(View v, @Nullable Bundle savedInstanceState) {
    statusCircle = v.findViewById(R.id.statusCircle);
    statusHint = (OneSheeldTextView) v.findViewById(R.id.statusHint);
    rmsIndicator = (TextView) v.findViewById(R.id.rmsLevelIndicator);
    recognizedResult = (OneSheeldTextView) v
            .findViewById(R.id.recognizedResult);
    params = (LayoutParams) rmsIndicator.getLayoutParams();
    statusCircle.getViewTreeObserver().addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {
                    if (stepValue == 0)
                        stepValue = statusCircle.getHeight() / 10;
                }
            });
}
项目:Hotspot-master-devp    文件:MatrixImageView.java   
@Override
public void setImageBitmap(Bitmap bm) {
    // TODO Auto-generated method stub
    super.setImageBitmap(bm);
    //大小为0 表示当前控件大小未测量  设置监听函数  在绘制前赋值
    if(getWidth()==0){
        ViewTreeObserver vto = getViewTreeObserver();
        vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener()
        {
            public boolean onPreDraw()
            {
                initData();
                //赋值结束后,移除该监听函数
                MatrixImageView.this.getViewTreeObserver().removeOnPreDrawListener(this);
                return true;
            }
        });
    }else {
        initData();
    }
}
项目:SimpleUILauncher    文件:FirstFrameAnimatorHelper.java   
public static void initializeDrawListener(View view) {
    if (sGlobalDrawListener != null) {
        view.getViewTreeObserver().removeOnDrawListener(sGlobalDrawListener);
    }
    sGlobalDrawListener = new ViewTreeObserver.OnDrawListener() {
            private long mTime = System.currentTimeMillis();
            public void onDraw() {
                sGlobalFrameCounter++;
                if (DEBUG) {
                    long newTime = System.currentTimeMillis();
                    Log.d("FirstFrameAnimatorHelper", "TICK " + (newTime - mTime));
                    mTime = newTime;
                }
            }
        };
    view.getViewTreeObserver().addOnDrawListener(sGlobalDrawListener);
    sVisible = true;
}
项目:GitHub    文件:MarqueeView.java   
/**
 * 根据字符串,启动翻页公告
 *
 * @param notice       字符串
 * @param inAnimResId  进入动画的resID
 * @param outAnimResID 离开动画的resID
 */
@SuppressWarnings("deprecation")
public void startWithText(final String notice, final @AnimRes int inAnimResId, final @AnimRes int outAnimResID) {
    if (TextUtils.isEmpty(notice)) return;
    getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
            startWithFixedWidth(notice, inAnimResId, outAnimResID);
        }
    });
}
项目:GitHub    文件:ViewTarget.java   
void getSize(SizeReadyCallback cb) {
  int currentWidth = getTargetWidth();
  int currentHeight = getTargetHeight();
  if (isViewStateAndSizeValid(currentWidth, currentHeight)) {
    cb.onSizeReady(currentWidth, currentHeight);
    return;
  }

  // We want to notify callbacks in the order they were added and we only expect one or two
  // callbacks to be added a time, so a List is a reasonable choice.
  if (!cbs.contains(cb)) {
    cbs.add(cb);
  }
  if (layoutListener == null) {
    ViewTreeObserver observer = view.getViewTreeObserver();
    layoutListener = new SizeDeterminerLayoutListener(this);
    observer.addOnPreDrawListener(layoutListener);
  }
}
项目:android-project-gallery    文件:PhotoViewAttacher.java   
public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(
            imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }
            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));

    // Finally, update the UI so that we're zoomable
    setZoomable(true);
}
项目:Mire    文件:FragmentAbout.java   
private void introAnimate()
{
       if (introAnimate)
    {
        root.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
        {
            @Override
            public void onGlobalLayout()
            {
                root.getViewTreeObserver().removeOnGlobalLayoutListener(this);

                TransitionHelperAbout.startIntroAnim(root, showShadowListener);
                showShadow();
            }
        });
    }
   }
项目:GitHub    文件:ReadEPubActivity.java   
@Override
public void initToolBar() {

    mCommonToolbar.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
                        mCommonToolbar.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        mCommonToolbar.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                    hideToolBarIfVisible();
                }
            });

    showDialog();
}
项目:PlusGram    文件:ProfileActivity.java   
private void fixLayout() {
    if (fragmentView == null) {
        return;
    }
    fragmentView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            if (fragmentView != null) {
                checkListViewScroll();
                needLayout();
                fragmentView.getViewTreeObserver().removeOnPreDrawListener(this);
            }
            return true;
        }
    });
}
项目:diycode    文件:LoginActivity.java   
private void registerKeyboardListener() {
    final View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
    rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            Logger.e("onGlobalLayout");
            if (isKeyboardShown(rootView)) {
                Logger.e("软键盘弹起");
                getViewHolder().get(R.id.span1).setVisibility(View.GONE);
                getViewHolder().get(R.id.span2).setVisibility(View.GONE);
            } else {
                Logger.e("软键盘未弹起");
                getViewHolder().get(R.id.span1).setVisibility(View.INVISIBLE);
                getViewHolder().get(R.id.span2).setVisibility(View.INVISIBLE);
            }
        }
    });
}
项目:MusicX-music-player    文件:ATEUtil.java   
public static void setOverflowButtonColor(@NonNull Activity activity,
                                          @Nullable Toolbar toolbar,
                                          final @ColorInt int color) {
    if (toolbar != null && toolbar.getTag() != null && ATE.IGNORE_TAG.equals(toolbar.getTag()))
        return; // ignore tag was set, don't update the overflow
    final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description);
    final View target = toolbar != null ? toolbar :
            (ViewGroup) activity.getWindow().getDecorView();
    final ViewTreeObserver viewTreeObserver = target.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<>();
            target.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) return;
            final AppCompatImageView overflow = (AppCompatImageView) outViews.get(0);
            overflow.setImageDrawable(TintHelper.createTintedDrawable(overflow.getDrawable(), color));
            removeOnGlobalLayoutListener(target, this);
        }
    });
}
项目:PicShow-zhaipin    文件: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
 */
@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;
}
项目:GitHub    文件:RecyclerAdapter.java   
@Override
public ListViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
  LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
  final View view = inflater.inflate(R.layout.recycler_item, viewGroup, false);
  view.getLayoutParams().width = screenWidth;

  if (actualDimensions == null) {
    view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
      @Override
      public boolean onPreDraw() {
        if (actualDimensions == null) {
          actualDimensions = new int[] { view.getWidth(), view.getHeight() };
        }
        view.getViewTreeObserver().removeOnPreDrawListener(this);
        return true;
      }
    });
  }

  return new ListViewHolder(view);
}
项目:Slide-RSS    文件:MainActivity.java   
private void scrollToTabAfterLayout(final int tabIndex) {
    //from http://stackoverflow.com/a/34780589/3697225
    if (mTabLayout != null) {
        final ViewTreeObserver observer = mTabLayout.getViewTreeObserver();

        if (observer.isAlive()) {
            observer.dispatchOnGlobalLayout(); // In case a previous call is waiting when this call is made
            observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    mTabLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    mTabLayout.getTabAt(tabIndex).select();
                }
            });
        }
    }
}
项目:airgram    文件:ManageSpaceActivity.java   
public void fixLayout() {
    if (!AndroidUtilities.isTablet()) {
        return;
    }
    if (actionBarLayout == null) {
        return;
    }
    actionBarLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            needLayout();
            if (actionBarLayout != null) {
                if (Build.VERSION.SDK_INT < 16) {
                    actionBarLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                    actionBarLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }
            }
        }
    });
}
项目:simple-stack    文件:ViewUtils.java   
public static void waitForMeasure(final View view, final OnMeasuredCallback callback) {
    int width = view.getWidth();
    int height = view.getHeight();

    if(width > 0 && height > 0) {
        callback.onMeasured(view, width, height);
        return;
    }

    view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            final ViewTreeObserver observer = view.getViewTreeObserver();
            if(observer.isAlive()) {
                observer.removeOnPreDrawListener(this);
            }

            callback.onMeasured(view, view.getWidth(), view.getHeight());

            return true;
        }
    });
}
项目:Cable-Android    文件:RecyclerViewFastScroller.java   
public void setRecyclerView(final @NonNull RecyclerView recyclerView) {
  if (this.recyclerView != null) {
    this.recyclerView.removeOnScrollListener(onScrollListener);
  }
  this.recyclerView = recyclerView;
  recyclerView.addOnScrollListener(onScrollListener);
  recyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
    @Override
    public boolean onPreDraw() {
      recyclerView.getViewTreeObserver().removeOnPreDrawListener(this);
      if (handle.isSelected()) return true;
      final int verticalScrollOffset = recyclerView.computeVerticalScrollOffset();
      final int verticalScrollRange = recyclerView.computeVerticalScrollRange();
      float proportion = (float)verticalScrollOffset / ((float)verticalScrollRange - height);
      setBubbleAndHandlePosition(height * proportion);
      return true;
    }
  });
}
项目:XiaoHuaCharge    文件:AddChargeFragment.java   
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    DisplayMetrics metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    final int screenHeight = metrics.heightPixels;

    llBottom.getViewTreeObserver().addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() { //当界面大小变化时,系统就会调用该方法
                    Rect r = new Rect(); //该对象代表一个矩形(rectangle)
                    llBottom.getWindowVisibleDisplayFrame(r); //将当前界面的尺寸传给Rect矩形
                    int deltaHeight = screenHeight - r.bottom;  //弹起键盘时的变化高度,在该场景下其实就是键盘高度。
                    if (deltaHeight > 150) {  //该值是随便写的,认为界面高度变化超过150px就视为键盘弹起。
                        plInput.setVisibility(View.GONE);
                        llSidebar.setVisibility(View.GONE);
                        etDes.setFocusable(true);
                    } else {
                        plInput.setVisibility(View.VISIBLE);
                        llSidebar.setVisibility(View.VISIBLE);
                    }
                }
            });
}
项目:cute-currency-view    文件:CuteCurrencyView.java   
private void animateCharSequence(CharSequence charSequence, TextPaint paint) {
    final View[] viewsToAnimate = new View[charSequence.length()];

    for (int i = 0; i < charSequence.length(); i++) {
        View view = new CharView(getContext(), paint, charSequence.charAt(i));
        viewsToAnimate[i] = view;
        animatedPlaceholder.addView(view);
    }

    viewsToAnimate[0]
            .getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    viewsToAnimate[0].getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    animateCharViews(viewsToAnimate, animatedPlaceholder, actualEditText);
                }
            });
}
项目:AndroidTvDemo    文件:BorderView.java   
public void detachFrom(ViewGroup viewGroup)
{
    try
    {
        if (viewGroup == mViewGroup)
        {
            ViewTreeObserver viewTreeObserver = mViewGroup.getViewTreeObserver();
            viewTreeObserver.removeOnGlobalFocusChangeListener(this);
            viewTreeObserver.removeOnScrollChangedListener(this);
            viewTreeObserver.removeOnGlobalLayoutListener(this);
            viewTreeObserver.removeOnTouchModeChangeListener(this);
            borderEffect.OnDetach(mView, viewGroup);
        }
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }
}
项目:RLibrary    文件:ViewAnimator.java   
public ViewAnimator start() {
    if (prev != null) {
        prev.start();
    } else {
        animatorSet = createAnimatorSet();

        if (waitForThisViewHeight != null) {
            waitForThisViewHeight.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
                @Override
                public boolean onPreDraw() {
                    animatorSet.start();
                    waitForThisViewHeight.getViewTreeObserver().removeOnPreDrawListener(this);
                    return false;
                }
            });
        } else {
            animatorSet.start();
        }
    }
    return this;
}
项目:PlusGram    文件:ChatActivity.java   
@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
    if (holder.itemView instanceof ChatMessageCell) {
        final ChatMessageCell messageCell = (ChatMessageCell) holder.itemView;
        messageCell.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                messageCell.getViewTreeObserver().removeOnPreDrawListener(this);

                int height = chatListView.getMeasuredHeight();
                int top = messageCell.getTop();
                int bottom = messageCell.getBottom();
                int viewTop = top >= 0 ? 0 : -top;
                int viewBottom = messageCell.getMeasuredHeight();
                if (viewBottom > height) {
                    viewBottom = viewTop + height;
                }
                messageCell.setVisiblePart(viewTop, viewBottom - viewTop);

                return true;
            }
        });
        messageCell.setHighlighted(highlightMessageId != Integer.MAX_VALUE && messageCell.getMessageObject().getId() == highlightMessageId);
    }
}
项目:Linphone4Android    文件:ChatFragment.java   
private void addVirtualKeyboardVisiblityListener() {
    keyboardListener = new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
        Rect visibleArea = new Rect();
        getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(visibleArea);

        int heightDiff = getActivity().getWindow().getDecorView().getRootView().getHeight() - (visibleArea.bottom - visibleArea.top);
            if (heightDiff > 200) {
                showKeyboardVisibleMode();
            } else {
                hideKeyboardVisibleMode();
            }
        }
    };
    getActivity().getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(keyboardListener);
}
项目:wangyi-Lyric-Parser    文件:BlockingBlurController.java   
/**
 * Deferring initialization until view is laid out
 */
private void deferBitmapCreation() {
    blurView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                blurView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                legacyRemoveOnGlobalLayoutListener();
            }

            int measuredWidth = blurView.getMeasuredWidth();
            int measuredHeight = blurView.getMeasuredHeight();

            init(measuredWidth, measuredHeight);
        }

        @SuppressWarnings("deprecation")
        private void legacyRemoveOnGlobalLayoutListener() {
            blurView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
    });
}
项目:OffsetAnimator    文件:Scene.java   
private void scheduleInit(final View rootView) {
    rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            //layout is ready
            //this might be called after on resume, so all initialization that depends on views measures should be done here
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                rootView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
            initializer.init();
            initialized = true;
        }
    });
}
项目:CameraFragment    文件:ImageLoader.java   
public void into(final ImageView target) {
    ViewTreeObserver viewTreeObserver = target.getViewTreeObserver();
    viewTreeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        public boolean onPreDraw() {
            target.getViewTreeObserver().removeOnPreDrawListener(this);

            new ImageLoaderThread(target, url).start();

            return true;
        }
    });
}
项目:SquareLayout    文件:SquarePercentRelativeLayout.java   
/**
 * Callback method to be invoked when the view tree is about to be drawn.
 * At this point, all views in the tree have been measured and given a frame.
 * So calculate the bounds before rendering the layout.
 */
private void init() {
    this.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {

            if (getWidth() != getHeight()) {
                //Get the smaller dimension of height and width
                int squareSize = Math.min(getWidth(), getHeight());

                //Set the dimensions to a Square
                ViewGroup.LayoutParams lp = getLayoutParams();
                lp.width = squareSize;
                lp.height = squareSize;
                requestLayout();
                return false;
            }
            return true;

        }
    });
}
项目:BookReader-master    文件:ReadEPubActivity.java   
@Override
public void initToolBar() {

    mCommonToolbar.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
                        mCommonToolbar.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        mCommonToolbar.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                    hideToolBarIfVisible();
                }
            });

    showDialog();
}
项目:exciting-app    文件:AbsHListView.java   
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    final ViewTreeObserver treeObserver = getViewTreeObserver();
    treeObserver.addOnTouchModeChangeListener(this);

    if (mAdapter != null && mDataSetObserver == null) {
        mDataSetObserver = new AdapterDataSetObserver();
        mAdapter.registerDataSetObserver(mDataSetObserver);

        // Data may have changed while we were detached. Refresh.
        mDataChanged = true;
        mOldItemCount = mItemCount;
        mItemCount = mAdapter.getCount();
    }
    mIsAttached = true;
}
项目:PlusGram    文件:ManageSpaceActivity.java   
public void fixLayout() {
    if (!AndroidUtilities.isTablet()) {
        return;
    }
    if (actionBarLayout == null) {
        return;
    }
    actionBarLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            needLayout();
            if (actionBarLayout != null) {
                if (Build.VERSION.SDK_INT < 16) {
                    actionBarLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                    actionBarLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }
            }
        }
    });
}
项目:QiangHongBao    文件:BottomBarBadge.java   
private void wrapTabAndBadgeInSameContainer(final BottomBarTab tab) {
    ViewGroup tabContainer = (ViewGroup) tab.getParent();
    tabContainer.removeView(tab);

    final FrameLayout badgeContainer = new FrameLayout(getContext());
    badgeContainer.setLayoutParams(new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    badgeContainer.addView(tab);
    badgeContainer.addView(this);

    tabContainer.addView(badgeContainer, tab.getIndexInTabContainer());

    badgeContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            badgeContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            adjustPositionAndSize(tab);
        }
    });
}
项目:dynamic-stack-adapter    文件:DynamicStackAdapter.java   
protected DynamicStackAdapter(final RecyclerView container, Class<VH> holderClass) {
    dataSet = new ArrayList<>();
    this.container = container;
    this.holderClass = holderClass;

    callback = new SimpleItemTouchHelperCallback();
    callback.setAdapter(this);

    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
    itemTouchHelper.attachToRecyclerView(container);

    expandedNotSuitableItems = new ArrayList<>();

    container.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            parentHeight = (container.getHeight() - marginPixels);
            minHeightPX = (int) (parentHeight / (float) maxItems);
        }
    });
}
项目:BarChart    文件:BarChart.java   
/**
 * @param isHeightRequested
 * @param view
 * @param listener
 */
private void getDimension(final boolean isHeightRequested, final View view, final DimensionReceivedCallback listener) {
    view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            System.out.println("Got the dimesion request onGlobalLayout");
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }

            if (isHeightRequested) {
                listener.onDimensionReceived(view.getHeight());
            } else {
                listener.onDimensionReceived(view.getWidth());
            }
        }
    });
}
项目:LEDView    文件:LEDView.java   
private void init(){

        mHolder = getHolder();
        mHolder.addCallback(this);
        mThread = new HandlerThread("led-looper");
        mThread.start();
        mHandler = new Handler(mThread.getLooper());

        mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);


        getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                mLEDHight = getWidth();
                mLEDWidth = getHeight();
                Log.d("scott","   led size " + " h : " + mLEDHight + "   w : " + mLEDWidth);
                getViewTreeObserver().removeOnPreDrawListener(this);
                return false;
            }
        });
    }
项目:ShimmerLayout    文件:ShimmerLayout.java   
public void startShimmerAnimation() {
    if (isAnimationStarted) {
        return;
    }

    if (getWidth() == 0) {
        startAnimationGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                removeGlobalLayoutListener(this);
                startShimmerAnimation();
            }
        };

        getViewTreeObserver().addOnGlobalLayoutListener(startAnimationGlobalLayoutListener);

        return;
    }

    Animator animator = getShimmerAnimation();
    animator.start();
    isAnimationStarted = true;
}
项目:ZeroKit-Android-Sample    文件:SignInActivity.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getComponent().inject(this);
    binding = DataBindingUtil.setContentView(this, R.layout.activity_signin);
    binding.setViewmodel(viewModel);
    binding.container.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            binding.bottomBar.post(new Runnable() {
                @Override
                public void run() {
                    binding.bottomBar.setVisibility(binding.container.getRootView().getHeight() - binding.container.getHeight() > dpToPx(SignInActivity.this, 200) ? View.GONE : View.VISIBLE);
                }
            });
        }
    });
}
项目:WeiXinRecordedDemo    文件:EditVideoActivity.java   
/**
 * 弹出键盘
 */
public void popupEditText(){

    isFirstShowEditText = true;
    et_tag.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if(isFirstShowEditText) {
                isFirstShowEditText = false;
                et_tag.setFocusable(true);
                et_tag.setFocusableInTouchMode(true);
                et_tag.requestFocus();
                isFirstShowEditText = !manager.showSoftInput(et_tag, 0);
            }
        }
    });
}