/** * 交换item,并且控制item之间的显示与隐藏效果 * * @param moveX * @param moveY */ private void onSwapItem(int moveX, int moveY) { // 获取我们手指移动到的那个item的position final int tempPosition = pointToPosition(moveX, moveY); // 假如tempPosition 改变了并且tempPosition不等�?-1,则进行交�? if (tempPosition != mDragPosition && tempPosition != AdapterView.INVALID_POSITION && mAnimationEnd) { mDragAdapter.reorderItems(mDragPosition, tempPosition); mDragAdapter.setHideItem(tempPosition); final ViewTreeObserver observer = getViewTreeObserver(); observer.addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { observer.removeOnPreDrawListener(this); animateReorder(mDragPosition, tempPosition); mDragPosition = tempPosition; return true; } }); } }
private void prepareSharedElementTransition(TransitionState state, View sceneRoot, Object sharedElementTransition, Fragment inFragment, Fragment outFragment, boolean isBack, ArrayList<View> sharedElementTargets) { final View view = sceneRoot; final Object obj = sharedElementTransition; final ArrayList<View> arrayList = sharedElementTargets; final TransitionState transitionState = state; final boolean z = isBack; final Fragment fragment = inFragment; final Fragment fragment2 = outFragment; sceneRoot.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { public boolean onPreDraw() { view.getViewTreeObserver().removeOnPreDrawListener(this); if (obj != null) { FragmentTransitionCompat21.removeTargets(obj, arrayList); arrayList.clear(); ArrayMap<String, View> namedViews = BackStackRecord.this.mapSharedElementsIn(transitionState, z, fragment); FragmentTransitionCompat21.setSharedElementTargets(obj, transitionState.nonExistentView, namedViews, arrayList); BackStackRecord.this.setEpicenterIn(namedViews, transitionState); BackStackRecord.this.callSharedElementEnd(transitionState, fragment, fragment2, z, namedViews); } return true; } }); }
public ViewAnimator start() { if (this.prev != null) { this.prev.start(); } else { this.animatorSet = createAnimatorSet(); if (this.waitForThisViewHeight != null) { this.waitForThisViewHeight.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { public boolean onPreDraw() { ViewAnimator.this.animatorSet.start(); ViewAnimator.this.waitForThisViewHeight.getViewTreeObserver() .removeOnPreDrawListener(this); return false; } }); } else { this.animatorSet.start(); } } return this; }
private void initbg() { setGravity(Gravity.CENTER); getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @SuppressWarnings("deprecation") @Override public boolean onPreDraw() { if (!initBgFlag) { DragPointView.this.setBackgroundDrawable(createStateListDrawable( (getHeight() > getWidth() ? getHeight() : getWidth()) / 2, backgroundColor)); initBgFlag = true; return false; } return true; } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SetupAnimationHelper.initialize(this); setContentView(R.layout.activity_setup); mFragmentTransitionDuration = getResources().getInteger( R.integer.setup_fragment_transition_duration); // Show initial fragment only when the saved state is not restored, because the last // fragment is restored if savesInstanceState is not null. if (savedInstanceState == null) { // This is the workaround to show the first fragment with delay to show the fragment // enter transition. See http://b/26255145 getWindow().getDecorView().getViewTreeObserver().addOnPreDrawListener( new OnPreDrawListener() { @Override public boolean onPreDraw() { getWindow().getDecorView().getViewTreeObserver() .removeOnPreDrawListener(this); showInitialFragment(); return true; } }); } else { mShowInitialFragment = false; } }
private void load(final ImageView imageView) { if (imageView.getHeight() == 0) { // wait for layout, same as glide SizeDeterminer does imageView.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { imageView.getViewTreeObserver().removeOnPreDrawListener(this); load(imageView); // call the same method, but we can be sure now getHeight() is a value return true; } }); } else { Glide .with(imageView.getContext()) .load("whatever") .fitCenter() .override(Target.SIZE_ORIGINAL, imageView.getHeight()) .into(imageView); } }
public BallView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub final ViewTreeObserver view=this.getViewTreeObserver(); view.addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { BallView.this.getViewTreeObserver().removeOnPreDrawListener(this); mViewHeight = BallView.this.getLayoutParams().height; mViewWidth = BallView.this.getLayoutParams().width; play(); return true; } }); }
protected void onFinishInflate() { super.onFinishInflate(); getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { public final boolean onPreDraw() { if (EditorialDescriptionSection.this.isExpansionNotNeeded()) { EditorialDescriptionSection.this.mFooterLabel.setVisibility(8); } for (;;) { EditorialDescriptionSection.this.getViewTreeObserver().removeOnPreDrawListener(this); return true; EditorialDescriptionSection.this.mFooterLabel.setVisibility(0); } } }); }
public void onAttachedToWindow() { super.onAttachedToWindow(); resetTouchBehaviors(); if (this.mNeedsPreDrawListener) { if (this.mOnPreDrawListener == null) { this.mOnPreDrawListener = new OnPreDrawListener(); } getViewTreeObserver().addOnPreDrawListener(this.mOnPreDrawListener); } if ((this.mLastInsets == null) && (ViewCompat.getFitsSystemWindows(this))) { ViewCompat.requestApplyInsets(this); } this.mIsAttachedToWindow = true; }
private void initViews() { mWelcomeImg.getViewTreeObserver().addOnPreDrawListener( new OnPreDrawListener() { @Override public boolean onPreDraw() { mWelcomeImg.getViewTreeObserver() .removeOnPreDrawListener(this); // 加载背景图构建Bitmap mWelcomeImg.buildDrawingCache(); // 获取ImageView缓存的Bitmap Bitmap bmp = mWelcomeImg.getDrawingCache(); // 在异步任务中执行模糊 new BlurTask().execute(bmp); return true; } }); }
@Override public void run() { for (final View view : mViews) { // Immediately count down for any views that already have a size if (view.getHeight() > 0 || view.getWidth() > 0) { countDown(); continue; } // For views that didn't have a size, listen (once) for a preDraw. Note // that this doesn't leak because the ViewTreeObserver gets detached when // the view is no longer part of the view hierarchy. view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { view.getViewTreeObserver().removeOnPreDrawListener(this); countDown(); return true; } }); } }
/** * Ensures the tab at the given position is visible. If we are not restoring tabs and * shouldAnimate == true, the tab will animate to be visible, if it is not already visible. */ private void ensurePositionIsVisible(final int position, final boolean shouldAnimate) { // We just want to move the strip to the right position // when restoring tabs on startup. if (isRestoringTabs || !shouldAnimate) { setSelection(position); return; } getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { getViewTreeObserver().removeOnPreDrawListener(this); smoothScrollToPosition(position); return true; } }); }
public void setLevelBorder(ⅹ paramⅹ) { final ArrayList localArrayList = ɫ.ˊ(new ArrayList(paramⅹ.ⁱ.values())); getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { public final boolean onPreDraw() { ProfilePictureWithLevel.this.getViewTreeObserver().removeOnPreDrawListener(this); if (localArrayList.size() <= 0) ProfilePictureWithLevel.this.setBorderColor(ProfilePictureWithLevel.this.getResources().getColor(2131230745)); else ((ImageView)ProfilePictureWithLevel.this.findViewById(2131296844)).setImageBitmap(ProfilePictureWithLevel.ˊ(ProfilePictureWithLevel.this, localArrayList)); return true; } }); }
/** * * @param context * @param gender * 性别 0代表女 1代表男 * @param than * 百分比 */ public TriangleView(Context context, int gender, int than) { super(context); tag = get(lenght); this.gender = gender; ratio = than; this.than = (int) ((100.0f - than) / (100.0f / tag[lenght - 1])); setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); this.getViewTreeObserver().addOnPreDrawListener( new OnPreDrawListener() { public boolean onPreDraw() { init(); getViewTreeObserver().removeOnPreDrawListener(this); return false; } }); }
public void init() { paint = new Paint(); paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL_AND_STROKE); paintWhite = new Paint(); paintWhite.setAntiAlias(true); paintWhite.setColor(0xffffffff); paintWhite.setStyle(Paint.Style.FILL_AND_STROKE); bitmapRefreshPaint = new Paint(); bitmapRefreshPaint.setAntiAlias(true); setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); this.getViewTreeObserver().addOnPreDrawListener(// 绘制完毕 new OnPreDrawListener() { public boolean onPreDraw() { Init(); getViewTreeObserver().removeOnPreDrawListener(this); return false; } }); }
public UEFontAwesomeDrawable(Context context, final View view, String text, int color) { this.text = Html.fromHtml(text).toString(); mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); mTextPaint.setTypeface(typeface); mTextPaint.setDither(true); mTextPaint.setColor(color); mTextPaint.setTextAlign(Paint.Align.CENTER); mTextPaint.measureText(text); view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { width = view.getWidth(); height = view.getHeight(); mTextPaint.setTextSize(Math.min(width, height)); view.getViewTreeObserver().removeOnPreDrawListener(this); return false; } }); }
@SuppressLint("ClickableViewAccessibility") private void init(){ setColumnCount(4); try{ setBackgroundColor(((ColorDrawable) getBackground()).getColor()); }catch(Exception e){ setBackgroundColor(DEFAULT_BACKGROUND); } setOnTouchListener(onTouchListener); getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { int w = getWidth(); int h = getHeight(); cardSize = (Math.min(w, h) - cardDistance)/4; initCards(); startGame(); getViewTreeObserver().removeOnPreDrawListener(this); return false; } }); }
@SuppressLint("ClickableViewAccessibility") @SuppressWarnings("deprecation") public void init(){ setOnTouchListener(this); HEIGHT = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight(); getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { DP = UEMethod.dp2px(getContext(), 1); LayoutParams params = getLayoutParams(); if (getHeight() >= HEIGHT - DP * 72) { params.height = 30 * DP; } params.width = (int) (params.height * 2.5); setLayoutParams(params); getViewTreeObserver().removeOnPreDrawListener(this); return false; } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_knobview); findViewById(R.id.knob1).getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { View v = findViewById(R.id.knob1); v.getViewTreeObserver().removeOnPreDrawListener(this); int width = v.getWidth(); int height = v.getHeight(); v.getLayoutParams().width = Math.min(width, height); v.getLayoutParams().height = Math.min(width, height); v.requestLayout(); return false; } }); }
public void setText(CharSequence charSequence) { textContent = charSequence; textView.setText(charSequence.toString()); ViewTreeObserver viewTreeObserver = textView.getViewTreeObserver(); viewTreeObserver.addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { if (!isInitTextView) { return true; } textLines = textView.getLineCount(); isExpandNeeded = textLines > expandLines; isInitTextView = false; if (isExpandNeeded) { isShrink = true; doAnimation(textLines, expandLines, WHAT_ANIMATION_END); } else { isShrink = false; doNotExpand(); } return true; } }); if (!isInitTextView) { textLines = textView.getLineCount(); } }
private void applyBlur(final ImageView iv) { iv.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener(this) { final /* synthetic */ StarRankActivity this$0; public boolean onPreDraw() { iv.getViewTreeObserver().removeOnPreDrawListener(this); iv.buildDrawingCache(); BlurUtils.star_blur(this.this$0.mContext, iv.getDrawingCache(), this.this$0.mZoomImg); return true; } }); }
private void applyBlur(final ImageView iv) { iv.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener(this) { final /* synthetic */ StarActivity this$0; public boolean onPreDraw() { iv.getViewTreeObserver().removeOnPreDrawListener(this); iv.buildDrawingCache(); BlurUtils.star_blur(this.this$0.mContext, iv.getDrawingCache(), this.this$0.mZoomImg); return true; } }); }
private void excludeHiddenFragmentsAfterEnter(View sceneRoot, TransitionState state, int containerId, Object transition) { final View view = sceneRoot; final TransitionState transitionState = state; final int i = containerId; final Object obj = transition; sceneRoot.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { public boolean onPreDraw() { view.getViewTreeObserver().removeOnPreDrawListener(this); BackStackRecord.this.excludeHiddenFragments(transitionState, i, obj); return true; } }); }
public static void execOnViewPreDraw(final View view, final Runnable runnable) { if (view != null && runnable != null) { view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { view.getViewTreeObserver().removeOnPreDrawListener(this); runnable.run(); return true; } }); } }
private void onUiReady() { imageView.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { imageView.getViewTreeObserver().removeOnPreDrawListener(this); prepareScene(); runEnterAnimation(); return true; } }); }
/** * 交换item,并且控制item之间的显示与隐藏效果 * * @param moveX * @param moveY */ private void onSwapItem(int moveX, int moveY) { // 获取我们手指移动到的那个item的position final int tempPosition = pointToPosition(moveX, moveY); // 假如tempPosition 改变了并且tempPosition不等于-1,则进行交换 if (tempPosition != mDragPosition && tempPosition != AdapterView.INVALID_POSITION && mAnimationEnd) { mDragAdapter.reorderItems(mDragPosition, tempPosition); mDragAdapter.setHideItem(tempPosition); final ViewTreeObserver observer = getViewTreeObserver(); observer.addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { observer.removeOnPreDrawListener(this); animateReorder(mDragPosition, tempPosition); mDragPosition = tempPosition; return true; } }); } }
public static void cleanupTransitions(View sceneRoot, View nonExistentView, Object enterTransitionObject, ArrayList<View> enteringViews, Object exitTransitionObject, ArrayList<View> exitingViews, Object sharedElementTransitionObject, ArrayList<View> sharedElementTargets, Object overallTransitionObject, ArrayList<View> hiddenViews, Map<String, View> renamedViews) { final Transition enterTransition = (Transition) enterTransitionObject; final Transition exitTransition = (Transition) exitTransitionObject; final Transition sharedElementTransition = (Transition) sharedElementTransitionObject; final Transition overallTransition = (Transition) overallTransitionObject; if (overallTransition != null) { final View view = sceneRoot; final ArrayList<View> arrayList = enteringViews; final ArrayList<View> arrayList2 = exitingViews; final ArrayList<View> arrayList3 = sharedElementTargets; final Map<String, View> map = renamedViews; final ArrayList<View> arrayList4 = hiddenViews; final View view2 = nonExistentView; sceneRoot.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { public boolean onPreDraw() { view.getViewTreeObserver().removeOnPreDrawListener(this); if (enterTransition != null) { FragmentTransitionCompat21.removeTargets(enterTransition, arrayList); } if (exitTransition != null) { FragmentTransitionCompat21.removeTargets(exitTransition, arrayList2); } if (sharedElementTransition != null) { FragmentTransitionCompat21.removeTargets(sharedElementTransition, arrayList3); } for (Entry<String, View> entry : map.entrySet()) { ((View) entry.getValue()).setTransitionName((String) entry.getKey()); } int numViews = arrayList4.size(); for (int i = 0; i < numViews; i++) { overallTransition.excludeTarget((View) arrayList4.get(i), false); } overallTransition.excludeTarget(view2, false); return true; } }); } }
private void ensurePreDrawListener() { if (this.mPreDrawListener == null) { this.mPreDrawListener = new OnPreDrawListener() { public boolean onPreDraw() { FloatingActionButtonImpl.this.onPreDraw(); return true; } }; } }
/** * Runs a piece of code just before the next draw, after layout and measurement * * @param view The view depend on * @param drawNextFrame Whether to draw next frame * @param runnable The executed runnable instance */ private void doOnPreDraw(final View view, final boolean drawNextFrame, final Runnable runnable) { final OnPreDrawListener listener = new OnPreDrawListener() { @Override public boolean onPreDraw() { view.getViewTreeObserver().removeOnPreDrawListener(this); runnable.run(); return drawNextFrame; } }; view.getViewTreeObserver().addOnPreDrawListener(listener); }
public void gridviewInit() { adapter = new GridAdapter(this); adapter.setSelectedPosition(0); int size = 0; if (bmp.size() < 6) { size = bmp.size() + 1; } else { size = bmp.size(); } LayoutParams params = gridview.getLayoutParams(); final int width = size * (int) (dp * 9.4f); params.width = width; gridview.setLayoutParams(params); gridview.setColumnWidth((int) (dp * 9.4f)); gridview.setStretchMode(GridView.NO_STRETCH); gridview.setNumColumns(size); gridview.setAdapter(adapter); gridview.setOnItemClickListener(this); selectimg_horizontalScrollView.getViewTreeObserver() .addOnPreDrawListener(// 绘制完毕 new OnPreDrawListener() { public boolean onPreDraw() { selectimg_horizontalScrollView.scrollTo(width, 0); selectimg_horizontalScrollView .getViewTreeObserver() .removeOnPreDrawListener(this); return false; } }); }
@CallSuper @Override public boolean onLayoutChild(CoordinatorLayout parent, final View child, int layoutDirection) { if (!ViewCompat.isLaidOut(child)) { final ExpandableWidget dep = findExpandableWidget(parent, child); if (dep != null && didStateChange(dep.isExpanded())) { currentState = dep.isExpanded() ? STATE_EXPANDED : STATE_COLLAPSED; @State final int expectedState = currentState; child .getViewTreeObserver() .addOnPreDrawListener( new OnPreDrawListener() { @Override public boolean onPreDraw() { child.getViewTreeObserver().removeOnPreDrawListener(this); // Proceed only if the state did not change while we're waiting for pre-draw. if (currentState == expectedState) { onExpandedStateChange((View) dep, child, dep.isExpanded(), false); } return false; } }); } } return false; }