Java Code Examples for android.view.ViewPropertyAnimator#translationY()

The following examples show how to use android.view.ViewPropertyAnimator#translationY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DialpadView.java    From android-dialer with Apache License 2.0 5 votes vote down vote up
public void animateShow() {
  // This is a hack; without this, the setTranslationY is delayed in being applied, and the
  // numbers appear at their original position (0) momentarily before animating.
  final AnimatorListenerAdapter showListener = new AnimatorListenerAdapter() {};

  for (int i = 0; i < mButtonIds.length; i++) {
    int delay = (int) (getKeyButtonAnimationDelay(mButtonIds[i]) * DELAY_MULTIPLIER);
    int duration = (int) (getKeyButtonAnimationDuration(mButtonIds[i]) * DURATION_MULTIPLIER);
    final DialpadKeyButton dialpadKey = (DialpadKeyButton) findViewById(mButtonIds[i]);

    ViewPropertyAnimator animator = dialpadKey.animate();
    if (mIsLandscape) {
      // Landscape orientation requires translation along the X axis.
      // For RTL locales, ensure we translate negative on the X axis.
      dialpadKey.setTranslationX((mIsRtl ? -1 : 1) * mTranslateDistance);
      animator.translationX(0);
    } else {
      // Portrait orientation requires translation along the Y axis.
      dialpadKey.setTranslationY(mTranslateDistance);
      animator.translationY(0);
    }
    animator
        .setInterpolator(AnimUtils.EASE_OUT_EASE_IN)
        .setStartDelay(delay)
        .setDuration(duration)
        .setListener(showListener)
        .start();
  }
}
 
Example 2
Source File: DropDownItemAnimator.java    From OmegaRecyclerView with MIT License 5 votes vote down vote up
@Override
protected void setupRemoveAnimation(ViewPropertyAnimator animator, final OmegaExpandableRecyclerView.Adapter.ChildViewHolder holder) {
    animator.setStartDelay(COLLAPSE_DELAY);
    long duration = holder.animationHelper.havePendingAdditions() ? COLLAPSE_DURATION_LONG : COLLAPSE_DURATION_SHORT;
    animator.setDuration(duration);

    if (holder.animationHelper.lowerViewHolder == null) {
        animator.translationY(getHiddenOffset(holder));
    } else {
        animator.setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                holder.contentView.setTranslationY(holder.animationHelper.lowerViewHolder.contentView.getTranslationY());
            }
        });
    }

    if (holder.animationHelper.havePendingAdditions()) {
        float deltaHeight = 0f;
        for (RecyclerView.ViewHolder viewHolder : holder.animationHelper.getPendingChanges().additions) {
            if (viewHolder.getAdapterPosition() < holder.animationHelper.visibleAdapterPosition) {
                deltaHeight += viewHolder.itemView.getHeight();
            }
        }
        if (deltaHeight > 0) {
            ((ChildClippingFrameLayout) holder.itemView).animateClipAboveDecreasing(deltaHeight, duration, COLLAPSE_DELAY);
        }
    }
}
 
Example 3
Source File: DropDownItemAnimator.java    From OmegaRecyclerView with MIT License 5 votes vote down vote up
@Override
protected void setupAddAnimation(ViewPropertyAnimator animator, final OmegaExpandableRecyclerView.Adapter.ChildViewHolder holder) {
    animator.setDuration(holder.animationHelper.havePendingRemovals() ? EXPAND_DURATION_LONG : EXPAND_DURATION_SHORT);
    animator.alpha(1f);
    if (holder.animationHelper.upperViewHolder == null) {
        animator.translationY(0f);
    } else {
        animator.setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                holder.contentView.setTranslationY(holder.animationHelper.upperViewHolder.contentView.getTranslationY());
            }
        });
    }
}
 
Example 4
Source File: MaterialIn.java    From Material-In with Apache License 2.0 5 votes vote down vote up
public static void startAnimators(final View view, int startOffsetX, int startOffsetY, long delay) {
    if (view.getVisibility() == View.VISIBLE && view.getAlpha() != 0f) {
        view.clearAnimation();
        view.animate().cancel();
        final Resources res = view.getResources();
        final float endAlpha = view.getAlpha();
        final float endTranslateX = view.getTranslationX();
        final float endTranslateY = view.getTranslationY();
        view.setAlpha(0);
        final Animator fade = ObjectAnimator.ofFloat(view, View.ALPHA, endAlpha);
        fade.setDuration(res.getInteger(R.integer.material_in_fade_anim_duration));
        fade.setInterpolator(new AccelerateInterpolator());
        fade.setStartDelay(delay);
        fade.start();
        ViewPropertyAnimator slide = view.animate();
        if (startOffsetY != 0) {
            view.setTranslationY(startOffsetY);
            slide.translationY(endTranslateY);
        } else {
            view.setTranslationX(startOffsetX);
            slide.translationX(endTranslateX);
        }
        slide.setInterpolator(new DecelerateInterpolator(2));
        slide.setDuration(res.getInteger(R.integer.material_in_slide_anim_duration));
        slide.setStartDelay(delay);
        slide.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationCancel(Animator animation) {
                if (fade.isStarted()) {
                    fade.cancel();
                }
                view.setAlpha(endAlpha);
                view.setTranslationX(endTranslateX);
                view.setTranslationY(endTranslateY);
            }
        });
        slide.start();
    }
}
 
Example 5
Source File: g.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public com.nineoldandroids.view.ViewPropertyAnimator translationY(float f)
{
    ViewPropertyAnimator viewpropertyanimator = (ViewPropertyAnimator)b.get();
    if (viewpropertyanimator != null)
    {
        viewpropertyanimator.translationY(f);
    }
    return this;
}
 
Example 6
Source File: AnimateableDialogDecorator.java    From AndroidMaterialDialog with Apache License 2.0 4 votes vote down vote up
/**
 * Configures an animator, which should be used to show the dialog using a rectangular reveal
 * animation.
 *
 * @param animatedView
 *         The animated view as an instance of the class {@link View}. The view may not be null
 * @param animation
 *         The animation as an instance of the class {@link RectangleRevealAnimation}. The
 *         animation may not be null
 * @param animator
 *         The animator, which should be configured, as an instance of the class {@link
 *         ViewPropertyAnimator}. The animator may not be null
 */
private void configureShowAnimator(@NonNull final View animatedView,
                                   @NonNull final RectangleRevealAnimation animation,
                                   @NonNull final ViewPropertyAnimator animator) {
    int horizontalWindowInset =
            getDialog().getWindowInsetLeft() + getDialog().getWindowInsetRight();
    int verticalWindowInset =
            getDialog().getWindowInsetTop() + getDialog().getWindowInsetBottom();
    float translationX = 0;
    float translationY = 0;

    if (animation.getX() != null) {
        translationX = animation.getX() - animatedView.getLeft() - horizontalWindowInset;
    }

    if (animation.getY() != null) {
        translationY = animation.getY() - animatedView.getTop() - verticalWindowInset;
    }

    if (animation.getWidth() != null) {
        int viewWidth = animatedView.getWidth() - horizontalWindowInset;
        translationX -= (float) (viewWidth - animation.getWidth()) / 2f;
        animatedView.setScaleX((float) animation.getWidth() / (float) viewWidth);
        animator.scaleX(1);
    }

    if (animation.getHeight() != null) {
        int viewHeight = animatedView.getHeight() - verticalWindowInset;
        translationY -= (float) (viewHeight - animation.getHeight()) / 2f;
        animatedView.setScaleY((float) animation.getHeight() / (float) viewHeight);
        animator.scaleY(1);
    }

    if (animation.getAlpha() != null) {
        animatedView.setAlpha(animation.getAlpha());
        animator.alpha(1);
    }

    if (translationX != 0) {
        animatedView.setTranslationX(translationX);
        animator.translationX(0);
    }

    if (translationY != 0) {
        animatedView.setTranslationY(translationY);
        animator.translationY(0);
    }
}
 
Example 7
Source File: AnimateableDialogDecorator.java    From AndroidMaterialDialog with Apache License 2.0 4 votes vote down vote up
/**
 * Configures an animator, which should be used to hide the dialog using a rectangular reveal
 * animation.
 *
 * @param animatedView
 *         The animated view as an instance of the class {@link View}. The view may not be null
 * @param animation
 *         The animation as an instance of the class {@link RectangleRevealAnimation}. The
 *         animation may not be null
 * @param animator
 *         The animator, which should be configured, as an instance of the class {@link
 *         ViewPropertyAnimator}. The animator may not be null
 */
private void configureHideAnimator(@NonNull final View animatedView,
                                   @NonNull final RectangleRevealAnimation animation,
                                   @NonNull final ViewPropertyAnimator animator) {
    int horizontalWindowInset =
            getDialog().getWindowInsetLeft() + getDialog().getWindowInsetRight();
    int verticalWindowInset =
            getDialog().getWindowInsetTop() + getDialog().getWindowInsetBottom();
    float translationX = 0;
    float translationY = 0;

    if (animation.getX() != null) {
        translationX = animation.getX() - animatedView.getLeft() - horizontalWindowInset;
    }

    if (animation.getY() != null) {
        translationY = animation.getY() - animatedView.getTop() - verticalWindowInset;
    }

    if (animation.getWidth() != null) {
        int viewWidth = animatedView.getWidth() - horizontalWindowInset;
        translationX -= (float) (viewWidth - animation.getWidth()) / 2f;
        animator.scaleX((float) animation.getWidth() / (float) viewWidth);
    }

    if (animation.getHeight() != null) {
        int viewHeight = animatedView.getHeight() - verticalWindowInset;
        translationY -= (float) (viewHeight - animation.getHeight()) / 2f;
        animator.scaleY((float) animation.getHeight() / (float) viewHeight);
    }

    if (animation.getAlpha() != null) {
        animator.alpha(animation.getAlpha());
    }

    if (translationX != 0) {
        animator.translationX(translationX);
    }

    if (translationY != 0) {
        animator.translationY(translationY);
    }
}
 
Example 8
Source File: OverviewCardTransform.java    From StackOverView with MIT License 4 votes vote down vote up
/** Applies this transform to a view. */
public void applyToTaskView(View v, int duration, Interpolator interp, boolean allowLayers,
        boolean allowShadows, ValueAnimator.AnimatorUpdateListener updateCallback) {
    // Check to see if any properties have changed, and update the task view
    if (duration > 0) {
        ViewPropertyAnimator anim = v.animate();
        boolean requiresLayers = false;

        // Animate to the final state
        if (hasTranslationYChangedFrom(v.getTranslationY())) {
            anim.translationY(translationY);
        }
        if (hasScaleChangedFrom(v.getScaleX())) {
            anim.scaleX(scale)
                .scaleY(scale);
            requiresLayers = true;
        }
        if (hasAlphaChangedFrom(v.getAlpha())) {
            // Use layers if we animate alpha
            anim.alpha(alpha);
            requiresLayers = true;
        }
        if (requiresLayers && allowLayers) {
            anim.withLayer();
        }
        anim.setStartDelay(startDelay)
                .setDuration(duration)
                .setInterpolator(interp)
                .start();
    } else {
        // Set the changed properties
        if (hasTranslationYChangedFrom(v.getTranslationY())) {
            v.setTranslationY(translationY);
        }
        if (hasScaleChangedFrom(v.getScaleX())) {
            v.setScaleX(scale);
            v.setScaleY(scale);
        }
        if (hasAlphaChangedFrom(v.getAlpha())) {
            v.setAlpha(alpha);
        }
    }
}
 
Example 9
Source File: OverlayServiceCommon.java    From heads-up with GNU General Public License v3.0 4 votes vote down vote up
private void doFinish(final int doDismiss) { // 0=ikke fjern 1=fjern 2=åpnet
    Mlog.v(logTag + "DoFinish", doDismiss);
    handler.removeCallbacks(closeTimer);

    // Integrate with Voiceify
    if (doDismiss == 1 || doDismiss == 2) {
        PackageManager packageManager = getPackageManager();
        Intent intent = new Intent("codes.simen.notificationspeaker.STOP_READING");
        intent.putExtra("packageName", packageName);
        intent.putExtra("tag", tag);
        intent.putExtra("id", id);
        intent.setPackage("codes.simen.notificationspeaker");
        try {
            ResolveInfo resolveInfo= packageManager.resolveService(intent, 0);
            if (resolveInfo.serviceInfo != null) {
                Mlog.d(logTag, "Voiceify found and resolved");
                startService(intent);
            }
        } catch (NullPointerException ignored) {} // Don't panic! We'll survive without Voiceify
    }

    if (Build.VERSION.SDK_INT >= 12) {
        try {
            View self = layout.findViewById(R.id.notificationbg);
            ViewPropertyAnimator animator = self.animate()
                    .setDuration(300)
                    .alpha(0.0f)
                    .setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            layout.setVisibility(View.GONE);
                            if (doDismiss == 1)
                                doDismiss(true);
                            else if (doDismiss == 2)
                                doDismiss(false);
                            else {
                                if (wLock != null && wLock.isHeld())
                                    wLock.release();
                                stopSelf();
                            }
                        }
                    });
            if (doDismiss == 1) animator.translationX(-400);
            else if (doDismiss == 0)
                switch (position) {
                    case 2:
                    case 1:
                        animator.translationY(-300);
                        break;
                    case -1:
                        animator.translationY(300);
                        break;
                }
        } catch (Exception e) {
            reportError(e, "", getApplicationContext());
            e.printStackTrace();
            layout.setVisibility(View.GONE);
            if (doDismiss == 1)
                doDismiss(true);
            else if (doDismiss == 2)
                doDismiss(false);
            else {
                if (wLock != null && wLock.isHeld())
                    wLock.release();
                stopSelf();
            }
        }
    } else {
        layout.setVisibility(View.GONE);
        if (doDismiss == 1)
            doDismiss(true);
        else if (doDismiss == 2)
            doDismiss(false);
        else {
            if (wLock != null && wLock.isHeld())
                wLock.release();
            stopSelf();
        }
    }
    prevPackageName = "0";
}