List of usage examples for android.view ViewParent getChildVisibleRect
public boolean getChildVisibleRect(View child, Rect r, android.graphics.Point offset);
From source file:org.chromium.chrome.browser.ntp.cards.ImpressionTracker.java
@Override public boolean onPreDraw() { ViewParent parent = mView.getParent(); if (parent != null) { Rect rect = new Rect(0, 0, mView.getWidth(), mView.getHeight()); parent.getChildVisibleRect(mView, rect, null); // Track impression if at least one third of the view is visible. if (rect.height() >= mView.getHeight() / 3) { mTriggered = true;//from w w w . jav a 2s . c o m mListener.onImpression(); } } // Proceed with the current drawing pass. return true; }
From source file:org.appcelerator.titanium.view.TiUIView.java
/** * Animates the view if there are pending animations. *///from ww w. j ava 2s. c om public void animate() { if (nativeView == null) { return; } // Pre-honeycomb, if one animation clobbers another you get a problem whereby the background of the // animated view's parent (or the grandparent) bleeds through. It seems to improve if you cancel and clear // the older animation. So here we cancel and clear, then re-queue the desired animation. if (Build.VERSION.SDK_INT < TiC.API_LEVEL_HONEYCOMB) { Animation currentAnimation = nativeView.getAnimation(); if (currentAnimation != null && currentAnimation.hasStarted() && !currentAnimation.hasEnded()) { // Cancel existing animation and // re-queue desired animation. currentAnimation.cancel(); nativeView.clearAnimation(); proxy.handlePendingAnimation(true); return; } } TiAnimationBuilder builder = proxy.getPendingAnimation(); if (builder == null) { return; } proxy.clearAnimation(builder); AnimationSet as = builder.render(proxy, nativeView); // If a view is "visible" but not currently seen (such as because it's covered or // its position is currently set to be fully outside its parent's region), // then Android might not animate it immediately because by default it animates // "on first frame" and apparently "first frame" won't happen right away if the // view has no visible rectangle on screen. In that case invalidate its parent, which will // kick off the pending animation. boolean invalidateParent = false; ViewParent viewParent = nativeView.getParent(); if (this.visibility == View.VISIBLE && viewParent instanceof View) { int width = nativeView.getWidth(); int height = nativeView.getHeight(); if (width == 0 || height == 0) { // Could be animating from nothing to something invalidateParent = true; } else { Rect r = new Rect(0, 0, width, height); Point p = new Point(0, 0); invalidateParent = !(viewParent.getChildVisibleRect(nativeView, r, p)); } } Log.d(TAG, "starting animation: " + as, Log.DEBUG_MODE); nativeView.startAnimation(as); if (invalidateParent) { ((View) viewParent).postInvalidate(); } }