Java Code Examples for android.view.ViewTreeObserver.OnPreDrawListener

The following are top voted examples for showing how to use android.view.ViewTreeObserver.OnPreDrawListener. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: PaoMovie   File: DragGridView.java   View source code 6 votes vote down vote up
/**
 * 交换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;
			}
		});

	}
}
 
Example 2
Project: letv   File: BackStackRecord.java   View source code 6 votes vote down vote up
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;
        }
    });
}
 
Example 3
Project: boohee_v5.6   File: ViewAnimator.java   View source code 6 votes vote down vote up
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;
}
 
Example 4
Project: sealtalk-android-master   File: DragPointView.java   View source code 6 votes vote down vote up
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;
        }
    });
}
 
Example 5
Project: rongyunDemo   File: DragPointView.java   View source code 6 votes vote down vote up
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;
        }
    });
}
 
Example 6
Project: RongCloudJcenter   File: DragPointView.java   View source code 6 votes vote down vote up
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;
        }
    });
}
 
Example 7
Project: android_packages_apps_tv   File: SetupActivity.java   View source code 6 votes vote down vote up
@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;
    }
}
 
Example 8
Project: glide-support   File: TestFragment.java   View source code 6 votes vote down vote up
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);
	}
}
 
Example 9
Project: sealtalk-android   File: DragPointView.java   View source code 6 votes vote down vote up
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;
        }
    });
}
 
Example 10
Project: MyStudyHelper   File: BallView.java   View source code 6 votes vote down vote up
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; 
		}
	});

}
 
Example 11
Project: FMTech   File: EditorialDescriptionSection.java   View source code 6 votes vote down vote up
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);
      }
    }
  });
}
 
Example 12
Project: FMTech   File: CoordinatorLayout.java   View source code 6 votes vote down vote up
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;
}
 
Example 13
Project: BeautyGallery   File: WelcomeActivity.java   View source code 6 votes vote down vote up
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;
				}
			});
}
 
Example 14
Project: Fabric-Example-App-Android   File: MraidController.java   View source code 6 votes vote down vote up
@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;
            }
        });
    }
}
 
Example 15
Project: mc_backup   File: TabStripView.java   View source code 6 votes vote down vote up
/**
 * 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;
        }
    });
}
 
Example 16
Project: QuizUpWinner   File: ProfilePictureWithLevel.java   View source code 6 votes vote down vote up
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;
    }
  });
}
 
Example 17
Project: UltimateAndroid   File: TriangleView.java   View source code 6 votes vote down vote up
/**
 * 
 * @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;
				}
			});
}
 
Example 18
Project: UltimateAndroid   File: RotaryView.java   View source code 6 votes vote down vote up
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;
				}
			});
}
 
Example 19
Project: UltimateAndroid   File: TriangleView.java   View source code 6 votes vote down vote up
/**
 * 
 * @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;
				}
			});
}
 
Example 20
Project: UltimateAndroid   File: RotaryView.java   View source code 6 votes vote down vote up
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;
				}
			});
}
 
Example 21
Project: Auie   File: UEFontAwesome.java   View source code 6 votes vote down vote up
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;
		}
	});
}
 
Example 22
Project: Auie   File: UI2048GameView.java   View source code 6 votes vote down vote up
@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;
		}
	});
}
 
Example 23
Project: Auie   File: UISwitchButton.java   View source code 6 votes vote down vote up
@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;
		}
	});
}
 
Example 24
Project: WidgyWidgets   File: KnobViewActivity.java   View source code 6 votes vote down vote up
@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;
		}
	});
}
 
Example 25
Project: qvod   File: TextViewExpandableAnimation.java   View source code 5 votes vote down vote up
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();
        }

    }
 
Example 26
Project: letv   File: StarRankActivity.java   View source code 5 votes vote down vote up
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;
        }
    });
}
 
Example 27
Project: letv   File: StarActivity.java   View source code 5 votes vote down vote up
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;
        }
    });
}
 
Example 28
Project: letv   File: BackStackRecord.java   View source code 5 votes vote down vote up
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;
        }
    });
}
 
Example 29
Project: fragmentnav   File: Androids.java   View source code 5 votes vote down vote up
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;
            }
        });
    }
}
 
Example 30
Project: fragmentnav   File: Androids.java   View source code 5 votes vote down vote up
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;
            }
        });
    }
}
 
Example 31
Project: FragmentRigger   File: SharedTargetFragment.java   View source code 5 votes vote down vote up
private void onUiReady() {
  imageView.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
    @Override
    public boolean onPreDraw() {
      imageView.getViewTreeObserver().removeOnPreDrawListener(this);
      prepareScene();
      runEnterAnimation();
      return true;
    }
  });
}
 
Example 32
Project: OSchina_resources_android   File: KJDragGridView.java   View source code 5 votes vote down vote up
/**
 * 交换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;
            }
        });

    }
}
 
Example 33
Project: boohee_v5.6   File: BackStackRecord.java   View source code 5 votes vote down vote up
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;
        }
    });
}
 
Example 34
Project: boohee_v5.6   File: BackStackRecord.java   View source code 5 votes vote down vote up
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;
        }
    });
}
 
Example 35
Project: boohee_v5.6   File: FragmentTransitionCompat21.java   View source code 5 votes vote down vote up
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;
            }
        });
    }
}
 
Example 36
Project: boohee_v5.6   File: FloatingActionButtonImpl.java   View source code 5 votes vote down vote up
private void ensurePreDrawListener() {
    if (this.mPreDrawListener == null) {
        this.mPreDrawListener = new OnPreDrawListener() {
            public boolean onPreDraw() {
                FloatingActionButtonImpl.this.onPreDraw();
                return true;
            }
        };
    }
}
 
Example 37
Project: FMRadio   File: FmScroller.java   View source code 5 votes vote down vote up
/**
 * 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);
}
 
Example 38
Project: TAG   File: PublishActivity.java   View source code 5 votes vote down vote up
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;
						}
					});
}
 
Example 39
Project: YingBeautyNote   File: HTQDragGridView.java   View source code 5 votes vote down vote up
/**
 * 交换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;
            }
        });

    }
}
 
Example 40
Project: material-components-android   File: ExpandableBehavior.java   View source code 5 votes vote down vote up
@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;
}