List of usage examples for android.view ViewGroup offsetDescendantRectToMyCoords
public final void offsetDescendantRectToMyCoords(View descendant, Rect rect)
From source file:Main.java
/** * Returns the descendant's frame relative to the parent. Applies conversion if views are * between the descendant and the parent. * * @param parent the returned frame will be relative to this view * @param descendant any view underneath the parent view. * @return the descendant's frame in parent view coordinates *//*w w w. jav a2s . c om*/ public static Rect convertedRectForDescendant(ViewGroup parent, View descendant) { Rect result = new Rect(0, 0, descendant.getWidth(), descendant.getHeight()); // alternately: descendant.getDrawingRect() ? parent.offsetDescendantRectToMyCoords(descendant, result); return result; }
From source file:android.support.v17.leanback.widget.AbstractMediaItemPresenter.java
/** * Each media item row can have multiple focusable elements; the details on the left and a set * of optional custom actions on the right. * The selector is a highlight that moves to highlight to cover whichever views is in focus. * * @param selectorView the selector view used to highlight an individual element within a row. * @param focusChangedView The component within the media row whose focus got changed. * @param layoutAnimator the ValueAnimator producing animation frames for the selector's width * and x-translation, generated by this method and stored for the each * {@link ViewHolder}. * @param isDetails Whether the changed-focused view is for a media item details (true) or * an action (false)./*from w w w . j a va 2 s. c o m*/ */ private static ValueAnimator updateSelector(final View selectorView, View focusChangedView, ValueAnimator layoutAnimator, boolean isDetails) { int animationDuration = focusChangedView.getContext().getResources() .getInteger(android.R.integer.config_shortAnimTime); DecelerateInterpolator interpolator = new DecelerateInterpolator(); int layoutDirection = ViewCompat.getLayoutDirection(selectorView); if (!focusChangedView.hasFocus()) { // if neither of the details or action views are in focus (ie. another row is in focus), // animate the selector out. selectorView.animate().cancel(); selectorView.animate().alpha(0f).setDuration(animationDuration).setInterpolator(interpolator).start(); // keep existing layout animator return layoutAnimator; } else { // cancel existing layout animator if (layoutAnimator != null) { layoutAnimator.cancel(); layoutAnimator = null; } float currentAlpha = selectorView.getAlpha(); selectorView.animate().alpha(1f).setDuration(animationDuration).setInterpolator(interpolator).start(); final ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) selectorView.getLayoutParams(); ViewGroup rootView = (ViewGroup) selectorView.getParent(); sTempRect.set(0, 0, focusChangedView.getWidth(), focusChangedView.getHeight()); rootView.offsetDescendantRectToMyCoords(focusChangedView, sTempRect); if (isDetails) { if (layoutDirection == View.LAYOUT_DIRECTION_RTL) { sTempRect.right += rootView.getHeight(); sTempRect.left -= rootView.getHeight() / 2; } else { sTempRect.left -= rootView.getHeight(); sTempRect.right += rootView.getHeight() / 2; } } final int targetLeft = sTempRect.left; final int targetWidth = sTempRect.width(); final float deltaWidth = lp.width - targetWidth; final float deltaLeft = lp.leftMargin - targetLeft; if (deltaLeft == 0f && deltaWidth == 0f) { // no change needed } else if (currentAlpha == 0f) { // change selector to the proper width and marginLeft without animation. lp.width = targetWidth; lp.leftMargin = targetLeft; selectorView.requestLayout(); } else { // animate the selector to the proper width and marginLeft. layoutAnimator = ValueAnimator.ofFloat(0f, 1f); layoutAnimator.setDuration(animationDuration); layoutAnimator.setInterpolator(interpolator); layoutAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // Set width to the proper width for this animation step. float fractionToEnd = 1f - valueAnimator.getAnimatedFraction(); lp.leftMargin = Math.round(targetLeft + deltaLeft * fractionToEnd); lp.width = Math.round(targetWidth + deltaWidth * fractionToEnd); selectorView.requestLayout(); } }); layoutAnimator.start(); } return layoutAnimator; } }
From source file:com.rbware.github.androidcouchpotato.widget.AbstractMediaItemPresenter.java
/** * Each media item row can have multiple focusable elements; the details on the left and a set * of optional custom actions on the right. * The selector is a highlight that moves to highlight to cover whichever views is in focus. * * @param selectorView the selector view used to highlight an individual element within a row. * @param focusChangedView The component within the media row whose focus got changed. * @param layoutAnimator the ValueAnimator producing animation frames for the selector's width * and x-translation, generated by this method and stored for the each * {@link ViewHolder}. * @param isDetails Whether the changed-focused view is for a media item details (true) or * an action (false)./*from w w w . j a va 2 s. co m*/ */ static ValueAnimator updateSelector(final View selectorView, View focusChangedView, ValueAnimator layoutAnimator, boolean isDetails) { int animationDuration = focusChangedView.getContext().getResources() .getInteger(android.R.integer.config_shortAnimTime); DecelerateInterpolator interpolator = new DecelerateInterpolator(); int layoutDirection = ViewCompat.getLayoutDirection(selectorView); if (!focusChangedView.hasFocus()) { // if neither of the details or action views are in focus (ie. another row is in focus), // animate the selector out. selectorView.animate().cancel(); selectorView.animate().alpha(0f).setDuration(animationDuration).setInterpolator(interpolator).start(); // keep existing layout animator return layoutAnimator; } else { // cancel existing layout animator if (layoutAnimator != null) { layoutAnimator.cancel(); layoutAnimator = null; } float currentAlpha = selectorView.getAlpha(); selectorView.animate().alpha(1f).setDuration(animationDuration).setInterpolator(interpolator).start(); final ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) selectorView.getLayoutParams(); ViewGroup rootView = (ViewGroup) selectorView.getParent(); sTempRect.set(0, 0, focusChangedView.getWidth(), focusChangedView.getHeight()); rootView.offsetDescendantRectToMyCoords(focusChangedView, sTempRect); if (isDetails) { if (layoutDirection == View.LAYOUT_DIRECTION_RTL) { sTempRect.right += rootView.getHeight(); sTempRect.left -= rootView.getHeight() / 2; } else { sTempRect.left -= rootView.getHeight(); sTempRect.right += rootView.getHeight() / 2; } } final int targetLeft = sTempRect.left; final int targetWidth = sTempRect.width(); final float deltaWidth = lp.width - targetWidth; final float deltaLeft = lp.leftMargin - targetLeft; if (deltaLeft == 0f && deltaWidth == 0f) { // no change needed } else if (currentAlpha == 0f) { // change selector to the proper width and marginLeft without animation. lp.width = targetWidth; lp.leftMargin = targetLeft; selectorView.requestLayout(); } else { // animate the selector to the proper width and marginLeft. layoutAnimator = ValueAnimator.ofFloat(0f, 1f); layoutAnimator.setDuration(animationDuration); layoutAnimator.setInterpolator(interpolator); layoutAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // Set width to the proper width for this animation step. float fractionToEnd = 1f - valueAnimator.getAnimatedFraction(); lp.leftMargin = Math.round(targetLeft + deltaLeft * fractionToEnd); lp.width = Math.round(targetWidth + deltaWidth * fractionToEnd); selectorView.requestLayout(); } }); layoutAnimator.start(); } return layoutAnimator; } }
From source file:android.support.v17.leanback.widget.HorizontalHoverCardSwitcher.java
/** * Select a childView inside a grid view and create/bind a corresponding hover card view * for the object./*from www . j ava2 s .c o m*/ */ public void select(HorizontalGridView gridView, View childView, Object object) { ViewGroup parent = getParentViewGroup(); gridView.getViewSelectedOffsets(childView, mTmpOffsets); mTmpRect.set(0, 0, childView.getWidth(), childView.getHeight()); parent.offsetDescendantRectToMyCoords(childView, mTmpRect); mCardLeft = mTmpRect.left - mTmpOffsets[0]; mCardRight = mTmpRect.right - mTmpOffsets[0]; select(object); }
From source file:com.android.deskclock.alarms.AlarmActivity.java
private Animator getAlertAnimator(final View source, final int titleResId, final String infoText, final String accessibilityText, final int revealColor, final int backgroundColor) { final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content); final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth()); containerView.offsetDescendantRectToMyCoords(source, sourceBounds); final int centerX = sourceBounds.centerX(); final int centerY = sourceBounds.centerY(); final int xMax = Math.max(centerX, containerView.getWidth() - centerX); final int yMax = Math.max(centerY, containerView.getHeight() - centerY); final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f; final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax); final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY) .setFillColor(revealColor);// ww w. j a v a 2s .c o m containerView.addView(revealView); // TODO: Fade out source icon over the reveal (like LOLLIPOP version). final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius, endRadius); revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS); revealAnimator.setInterpolator(REVEAL_INTERPOLATOR); revealAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { mAlertView.setVisibility(View.VISIBLE); mAlertTitleView.setText(titleResId); if (infoText != null) { mAlertInfoView.setText(infoText); mAlertInfoView.setVisibility(View.VISIBLE); } mContentView.setVisibility(View.GONE); getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor)); } }); final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS); fadeAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { containerView.removeView(revealView); } }); final AnimatorSet alertAnimator = new AnimatorSet(); alertAnimator.play(revealAnimator).before(fadeAnimator); alertAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { mAlertView.announceForAccessibility(accessibilityText); mHandler.postDelayed(new Runnable() { @Override public void run() { finish(); } }, ALERT_DISMISS_DELAY_MILLIS); } }); return alertAnimator; }
From source file:com.onyx.deskclock.deskclock.alarms.AlarmActivity.java
private Animator getAlertAnimator(final View source, final int titleResId, final String infoText, final String accessibilityText, final int revealColor, final int backgroundColor) { final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content); final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth()); containerView.offsetDescendantRectToMyCoords(source, sourceBounds); final int centerX = sourceBounds.centerX(); final int centerY = sourceBounds.centerY(); final int xMax = Math.max(centerX, containerView.getWidth() - centerX); final int yMax = Math.max(centerY, containerView.getHeight() - centerY); final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f; final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax); final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY) .setFillColor(revealColor);/*from ww w.j a v a2 s. co m*/ containerView.addView(revealView); // TODO: Fade out source icon over the reveal (like LOLLIPOP version). final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius, endRadius); revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS); revealAnimator.setInterpolator(REVEAL_INTERPOLATOR); revealAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { mAlertView.setVisibility(View.VISIBLE); mAlertTitleView.setText(titleResId); if (infoText != null) { mAlertInfoView.setText(infoText); mAlertInfoView.setVisibility(View.VISIBLE); } mContentView.setVisibility(View.GONE); getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor)); } }); final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS); fadeAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { containerView.removeView(revealView); } }); final AnimatorSet alertAnimator = new AnimatorSet(); alertAnimator.play(revealAnimator).before(fadeAnimator); alertAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { if (Build.VERSION.SDK_INT >= 16) { mAlertView.announceForAccessibility(accessibilityText); } mHandler.postDelayed(new Runnable() { @Override public void run() { finish(); } }, ALERT_DISMISS_DELAY_MILLIS); } }); return alertAnimator; }
From source file:com.android.deskclock.timer.TimerFullScreenFragment.java
private Animator getRevealAnimator(View source, int revealColor) { final ViewGroup containerView = (ViewGroup) source.getRootView().findViewById(android.R.id.content); final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth()); containerView.offsetDescendantRectToMyCoords(source, sourceBounds); final int centerX = sourceBounds.centerX(); final int centerY = sourceBounds.centerY(); final int xMax = Math.max(centerX, containerView.getWidth() - centerX); final int yMax = Math.max(centerY, containerView.getHeight() - centerY); final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f; final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax); final CircleView revealView = new CircleView(source.getContext()).setCenterX(centerX).setCenterY(centerY) .setFillColor(revealColor);//from ww w .j a va 2s . co m containerView.addView(revealView); final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius, endRadius); revealAnimator.setInterpolator(PathInterpolatorCompat.create(0.0f, 0.0f, 0.2f, 1.0f)); final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); fadeAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { containerView.removeView(revealView); } }); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(TimerFragment.ANIMATION_TIME_MILLIS); animatorSet.playSequentially(revealAnimator, fadeAnimator); return revealAnimator; }
From source file:Main.java
private static void expandInner(final View view, final View parentView, final ViewGroup rootContainer, final int targtetHeight) { setHeight(view, 0);/*ww w .j a va 2 s . c om*/ view.setVisibility(View.VISIBLE); final Animation animation = new Animation() { private final Rect rect = new Rect(); private final Rect parentVisibleRect = new Rect(); ViewTreeObserver.OnGlobalLayoutListener globalLayoutListener; private final Runnable checkViewRunnable = new Runnable() { @Override public void run() { checkForViewInsideVisibleArea(); } }; @Override protected void applyTransformation(float interpolatedTime, Transformation t) { int neededHeight = interpolatedTime == 1 ? LayoutParams.WRAP_CONTENT : (int) (targtetHeight * interpolatedTime); setHeight(view, neededHeight); final ViewTreeObserver viewTreeObserver = view.getViewTreeObserver(); if (globalLayoutListener == null) { globalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (globalLayoutListener == null) { removeGlobalLayoutListener(viewTreeObserver, this); } checkForViewInsideVisibleArea(); } }; viewTreeObserver.addOnGlobalLayoutListener(globalLayoutListener); } if (globalLayoutListener != null && interpolatedTime == 1) { runInUIThread(checkViewRunnable); globalLayoutListener = null; } view.requestLayout(); } @Override public boolean willChangeBounds() { return true; } private void checkForViewInsideVisibleArea() { if (rootContainer.indexOfChild(parentView) == -1) { return; } parentVisibleRect.left = 0; parentVisibleRect.top = 0; parentVisibleRect.right = parentView.getWidth(); parentVisibleRect.bottom = parentView.getHeight(); rootContainer.offsetDescendantRectToMyCoords(parentView, parentVisibleRect); if (parentVisibleRect.top < 0 || parentVisibleRect.bottom > rootContainer.getHeight()) { rect.left = parentView.getLeft(); rect.top = parentView.getTop(); rect.right = parentView.getRight(); rect.bottom = parentView.getBottom(); parentView.requestRectangleOnScreen(rect, true); } } }; animation.setDuration(ANIMATION_DURATION); view.startAnimation(animation); }