Example usage for android.view View TRANSLATION_Y

List of usage examples for android.view View TRANSLATION_Y

Introduction

In this page you can find the example usage for android.view View TRANSLATION_Y.

Prototype

Property TRANSLATION_Y

To view the source code for android.view View TRANSLATION_Y.

Click Source Link

Document

A Property wrapper around the translationY functionality handled by the View#setTranslationY(float) and View#getTranslationY() methods.

Usage

From source file:com.bartoszlipinski.viewpropertyobjectanimator.ViewPropertyObjectAnimator.java

public ViewPropertyObjectAnimator translationY(float translationY) {
    animateProperty(View.TRANSLATION_Y, translationY);
    return this;
}

From source file:com.bartoszlipinski.viewpropertyobjectanimator.ViewPropertyObjectAnimator.java

public ViewPropertyObjectAnimator translationYBy(float translationYBy) {
    animatePropertyBy(View.TRANSLATION_Y, translationYBy);
    return this;
}

From source file:com.sysdata.widget.accordion.CollapsedViewHolder.java

private Animator createCollapsingAnimator(ArrowItemViewHolder oldHolder, long duration) {
    final View oldView = oldHolder.itemView;
    final View newView = itemView;
    final Animator boundsAnimator = AnimatorUtils.getBoundsAnimator(newView, oldView, newView)
            .setDuration(duration);/* w  w w.j av  a2  s.  c o  m*/
    boundsAnimator.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    final AnimatorSet animatorSet;
    if (arrow != null) {
        final View oldArrow = oldHolder.arrow;
        final Rect oldArrowRect = new Rect(0, 0, oldArrow.getWidth(), oldArrow.getHeight());
        final Rect newArrowRect = new Rect(0, 0, arrow.getWidth(), arrow.getHeight());
        ((ViewGroup) newView).offsetDescendantRectToMyCoords(arrow, newArrowRect);
        ((ViewGroup) oldView).offsetDescendantRectToMyCoords(oldArrow, oldArrowRect);
        final float arrowTranslationY = oldArrowRect.bottom - newArrowRect.bottom;
        arrow.setTranslationY(arrowTranslationY);
        arrow.setVisibility(View.VISIBLE);

        final Animator arrowAnimation = ObjectAnimator.ofFloat(arrow, View.TRANSLATION_Y, 0f)
                .setDuration(duration);
        arrowAnimation.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

        animatorSet = new AnimatorSet();
        animatorSet.playTogether(boundsAnimator, arrowAnimation);
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                AnimatorUtils.startDrawableAnimation(arrow);
            }
        });
    } else {
        animatorSet = new AnimatorSet();
        animatorSet.playTogether(boundsAnimator);
    }

    return animatorSet;
}

From source file:com.taobao.weex.ui.animation.TransformParser.java

public static Map<Property<View, Float>, Float> parseTransForm(@Nullable String rawTransform, final int width,
        final int height, final int viewportW) {
    if (!TextUtils.isEmpty(rawTransform)) {
        FunctionParser<Property<View, Float>, Float> parser = new FunctionParser<>(rawTransform,
                new FunctionParser.Mapper<Property<View, Float>, Float>() {
                    @Override//from  w  w w .j  a va2 s.com
                    public Map<Property<View, Float>, Float> map(String functionName, List<String> raw) {
                        if (raw != null && !raw.isEmpty()) {
                            if (wxToAndroidMap.containsKey(functionName)) {
                                return convertParam(width, height, viewportW, wxToAndroidMap.get(functionName),
                                        raw);
                            }
                        }
                        return new HashMap<>();
                    }

                    private Map<Property<View, Float>, Float> convertParam(int width, int height, int viewportW,
                            @NonNull List<Property<View, Float>> propertyList, @NonNull List<String> rawValue) {

                        Map<Property<View, Float>, Float> result = WXDataStructureUtil
                                .newHashMapWithExpectedSize(propertyList.size());
                        List<Float> convertedList = new ArrayList<>(propertyList.size());
                        if (propertyList.contains(View.ROTATION) || propertyList.contains(View.ROTATION_X)
                                || propertyList.contains(View.ROTATION_Y)) {
                            convertedList.addAll(parseRotationZ(rawValue));
                        } else if (propertyList.contains(View.TRANSLATION_X)
                                || propertyList.contains(View.TRANSLATION_Y)) {
                            convertedList
                                    .addAll(parseTranslation(propertyList, width, height, rawValue, viewportW));
                        } else if (propertyList.contains(View.SCALE_X) || propertyList.contains(View.SCALE_Y)) {
                            convertedList.addAll(parseScale(propertyList.size(), rawValue));
                        } else if (propertyList.contains(CameraDistanceProperty.getInstance())) {
                            convertedList.add(parseCameraDistance(rawValue));
                        }
                        if (propertyList.size() == convertedList.size()) {
                            for (int i = 0; i < propertyList.size(); i++) {
                                result.put(propertyList.get(i), convertedList.get(i));
                            }
                        }
                        return result;
                    }

                    private List<Float> parseScale(int size, @NonNull List<String> rawValue) {
                        List<Float> convertedList = new ArrayList<>(rawValue.size() * 2);
                        List<Float> rawFloat = new ArrayList<>(rawValue.size());
                        for (String item : rawValue) {
                            rawFloat.add(WXUtils.fastGetFloat(item));
                        }
                        convertedList.addAll(rawFloat);
                        if (size != 1 && rawValue.size() == 1) {
                            convertedList.addAll(rawFloat);
                        }
                        return convertedList;
                    }

                    private @NonNull List<Float> parseRotationZ(@NonNull List<String> rawValue) {
                        List<Float> convertedList = new ArrayList<>(1);
                        int suffix;
                        for (String raw : rawValue) {
                            if ((suffix = raw.lastIndexOf(DEG)) != -1) {
                                convertedList.add(WXUtils.fastGetFloat(raw.substring(0, suffix)));
                            } else {
                                convertedList.add((float) Math.toDegrees(Double.parseDouble(raw)));
                            }
                        }
                        return convertedList;
                    }

                    /**
                     * As "translate(50%, 25%)" or "translate(25px, 30px)" both are valid,
                     * parsing translate is complicated than other method.
                     * Add your waste time here if you try to optimize this method like {@link #parseScale(int, List)}
                     * Time: 0.5h
                     */
                    private List<Float> parseTranslation(List<Property<View, Float>> propertyList, int width,
                            int height, @NonNull List<String> rawValue, int viewportW) {
                        List<Float> convertedList = new ArrayList<>(2);
                        String first = rawValue.get(0);
                        if (propertyList.size() == 1) {
                            parseSingleTranslation(propertyList, width, height, convertedList, first,
                                    viewportW);
                        } else {
                            parseDoubleTranslation(width, height, rawValue, convertedList, first, viewportW);
                        }
                        return convertedList;
                    }

                    private void parseSingleTranslation(List<Property<View, Float>> propertyList, int width,
                            int height, List<Float> convertedList, String first, int viewportW) {
                        if (propertyList.contains(View.TRANSLATION_X)) {
                            convertedList.add(parsePercentOrPx(first, width, viewportW));
                        } else if (propertyList.contains(View.TRANSLATION_Y)) {
                            convertedList.add(parsePercentOrPx(first, height, viewportW));
                        }
                    }

                    private void parseDoubleTranslation(int width, int height, @NonNull List<String> rawValue,
                            List<Float> convertedList, String first, int viewportW) {
                        String second;
                        if (rawValue.size() == 1) {
                            second = first;
                        } else {
                            second = rawValue.get(1);
                        }
                        convertedList.add(parsePercentOrPx(first, width, viewportW));
                        convertedList.add(parsePercentOrPx(second, height, viewportW));
                    }

                    private Float parseCameraDistance(List<String> rawValue) {
                        float ret = Float.MAX_VALUE;
                        if (rawValue.size() == 1) {
                            float value = WXViewUtils.getRealPxByWidth(WXUtils.getFloat(rawValue.get(0)),
                                    viewportW);
                            float scale = WXEnvironment.getApplication().getResources()
                                    .getDisplayMetrics().density;
                            if (!Float.isNaN(value) && value > 0) {
                                ret = value * scale;
                            }
                        }
                        return ret;
                    }
                });
        return parser.parse();
    }
    return new LinkedHashMap<>();
}

From source file:com.artemchep.horario.ui.widgets.ContainersLayout.java

private void animateInFrameDetails() {
    frameDetails.setVisibility(View.VISIBLE);
    ViewUtils.onLaidOut(frameDetails, new Runnable() {
        @Override// w ww .ja  va 2  s  .  c o m
        public void run() {
            ObjectAnimator alpha = ofFloat(frameDetails, View.ALPHA, 0.4f, 1f);
            ObjectAnimator translate = ofFloat(frameDetails, View.TRANSLATION_Y,
                    frameDetails.getHeight() * 0.3f, 0f);

            AnimatorSet set = new AnimatorSet();
            set.playTogether(alpha, translate);
            set.setDuration(ANIM_DURATION);
            set.setInterpolator(new LinearOutSlowInInterpolator());
            set.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    frameMaster.setVisibility(View.GONE);
                }
            });
            set.start();
        }
    });
}

From source file:com.zhihu.android.app.mirror.widget.ArtboardView.java

private void onActionRelease() {
    if (mCallback != null && Math.abs(mDragDistance) > mDragDismissDistance) {
        mCallback.onDragDismiss(this, mIsDragDown);
    } else {//from   w w  w. ja v a 2  s .co m
        if (mTransYAnim != null && mTransYAnim.isRunning()) {
            mTransYAnim.cancel();
        }

        mTransYAnim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, getTranslationY(), 0.0F);
        mTransYAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float dragTo = (Float) animation.getAnimatedValue();
                if (mCallback != null) {
                    mCallback.onDrag(ArtboardView.this, mDragDismissDistance, dragTo);
                }
            }
        });
        mTransYAnim.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
        mTransYAnim.setInterpolator(PathInterpolatorCompat.create(0.4F, 0.0F, 0.2F, 1.0F));
        mTransYAnim.start();
    }
}

From source file:com.telenav.expandablepager.SlidingContainer.java

/**
 * Animate translationY to the next stopValue
 * @param amount translationY amount/*from   w ww  .  jav  a 2  s . c  o m*/
 * @param duration animation duration
 * @param interpolator  animation interpolator
 */
private void animate(final float amount, int duration, Interpolator interpolator) {
    ObjectAnimator oa = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, amount).setDuration(duration);
    oa.setInterpolator(interpolator);
    oa.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            notifySlideEvent(Math.round(((Float) animation.getAnimatedValue())));
        }
    });
    oa.addListener(new CustomAnimationListener() {
        @Override
        public void onAnimationEnd(Animator animator) {
            onSettled(stopValueIndex);
        }
    });
    oa.start();
}

From source file:com.artemchep.horario.ui.widgets.ContainersLayout.java

private void animateOutFrameDetails() {
    ViewUtils.onLaidOut(frameDetails, new Runnable() {
        @Override/*from w  w w .j  a va2  s  .  co  m*/
        public void run() {
            if (!frameDetails.isShown()) {
                return;
            }
            ObjectAnimator alpha = ObjectAnimator.ofFloat(frameDetails, View.ALPHA, 1f, 0f);
            ObjectAnimator translate = ofFloat(frameDetails, View.TRANSLATION_Y, 0f,
                    frameDetails.getHeight() * 0.3f);

            AnimatorSet set = new AnimatorSet();
            set.playTogether(alpha, translate);
            set.setDuration(ANIM_DURATION);
            set.setInterpolator(new FastOutLinearInInterpolator());
            set.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    frameDetails.setAlpha(1f);
                    frameDetails.setTranslationY(0);
                    frameDetails.setVisibility(View.GONE);
                }
            });
            set.start();
        }
    });
}

From source file:com.sysdata.widget.accordion.ExpandedViewHolder.java

private Animator createExpandingAnimator(ArrowItemViewHolder oldHolder, long duration) {
    final View oldView = oldHolder.itemView;
    final View newView = itemView;
    final Animator boundsAnimator = AnimatorUtils.getBoundsAnimator(newView, oldView, newView);
    boundsAnimator.setDuration(duration);
    boundsAnimator.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    final Animator backgroundAnimator = ObjectAnimator.ofPropertyValuesHolder(newView,
            PropertyValuesHolder.ofInt(AnimatorUtils.BACKGROUND_ALPHA, 0, 255));
    backgroundAnimator.setDuration(duration);

    final AnimatorSet animatorSet;
    if (arrow != null) {
        final View oldArrow = oldHolder.arrow;
        final Rect oldArrowRect = new Rect(0, 0, oldArrow.getWidth(), oldArrow.getHeight());
        final Rect newArrowRect = new Rect(0, 0, arrow.getWidth(), arrow.getHeight());
        ((ViewGroup) newView).offsetDescendantRectToMyCoords(arrow, newArrowRect);
        ((ViewGroup) oldView).offsetDescendantRectToMyCoords(oldArrow, oldArrowRect);
        final float arrowTranslationY = oldArrowRect.bottom - newArrowRect.bottom;

        arrow.setTranslationY(arrowTranslationY);
        arrow.setVisibility(View.VISIBLE);

        final Animator arrowAnimation = ObjectAnimator.ofFloat(arrow, View.TRANSLATION_Y, 0f)
                .setDuration(duration);/* www .  j  a  v  a2 s.  c o m*/
        arrowAnimation.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

        animatorSet = new AnimatorSet();
        animatorSet.playTogether(backgroundAnimator, boundsAnimator, arrowAnimation);
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                AnimatorUtils.startDrawableAnimation(arrow);
            }
        });
    } else {
        animatorSet = new AnimatorSet();
        animatorSet.playTogether(backgroundAnimator, boundsAnimator);
    }

    return animatorSet;
}

From source file:com.hannesdorfmann.FeedAdapter.java

private void bindDesignerNewsStory(final Story story, final DesignerNewsStoryHolder holder) {
    holder.title.setText(story.title);/*from   w  w  w.j av a2s .  c o  m*/
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CustomTabActivityHelper.openCustomTab(host,
                    DesignerNewsStory.getCustomTabIntent(host, story, null).build(), Uri.parse(story.url));
        }
    });
    holder.comments.setText(String.valueOf(story.comment_count));
    holder.comments.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View commentsView) {
            final Intent intent = new Intent();
            intent.setClass(host, DesignerNewsStory.class);
            intent.putExtra(DesignerNewsStory.EXTRA_STORY, story);
            final ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host,
                    Pair.create(holder.itemView, host.getString(R.string.transition_story_title_background)),
                    Pair.create(holder.itemView, host.getString(R.string.transition_story_background)));
            host.startActivity(intent, options.toBundle());
        }
    });
    if (pocketIsInstalled) {
        holder.pocket.setImageAlpha(178); // grumble... no xml setter, grumble...
        holder.pocket.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View view) {
                final ImageButton pocketButton = (ImageButton) view;
                // actually add to pocket
                PocketUtils.addToPocket(host, story.url);

                // setup for anim
                holder.itemView.setHasTransientState(true);
                ((ViewGroup) pocketButton.getParent().getParent()).setClipChildren(false);
                final int initialLeft = pocketButton.getLeft();
                final int initialTop = pocketButton.getTop();
                final int translatedLeft = (holder.itemView.getWidth() - pocketButton.getWidth()) / 2;
                final int translatedTop = initialTop
                        - ((holder.itemView.getHeight() - pocketButton.getHeight()) / 2);
                final ArcMotion arc = new ArcMotion();

                // animate the title & pocket icon up, scale the pocket icon up
                PropertyValuesHolder pvhTitleUp = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y,
                        -(holder.itemView.getHeight() / 5));
                PropertyValuesHolder pvhTitleFade = PropertyValuesHolder.ofFloat(View.ALPHA, 0.54f);
                Animator titleMoveFadeOut = ObjectAnimator.ofPropertyValuesHolder(holder.title, pvhTitleUp,
                        pvhTitleFade);

                Animator pocketMoveUp = ObjectAnimator.ofFloat(pocketButton, View.TRANSLATION_X,
                        View.TRANSLATION_Y,
                        arc.getPath(initialLeft, initialTop, translatedLeft, translatedTop));
                PropertyValuesHolder pvhPocketScaleUpX = PropertyValuesHolder.ofFloat(View.SCALE_X, 3f);
                PropertyValuesHolder pvhPocketScaleUpY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 3f);
                Animator pocketScaleUp = ObjectAnimator.ofPropertyValuesHolder(pocketButton, pvhPocketScaleUpX,
                        pvhPocketScaleUpY);
                ObjectAnimator pocketFadeUp = ObjectAnimator.ofInt(pocketButton, ViewUtils.IMAGE_ALPHA, 255);

                AnimatorSet up = new AnimatorSet();
                up.playTogether(titleMoveFadeOut, pocketMoveUp, pocketScaleUp, pocketFadeUp);
                up.setDuration(300);
                up.setInterpolator(
                        AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in));

                // animate everything back into place
                PropertyValuesHolder pvhTitleMoveUp = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, 0f);
                PropertyValuesHolder pvhTitleFadeUp = PropertyValuesHolder.ofFloat(View.ALPHA, 1f);
                Animator titleMoveFadeIn = ObjectAnimator.ofPropertyValuesHolder(holder.title, pvhTitleMoveUp,
                        pvhTitleFadeUp);
                Animator pocketMoveDown = ObjectAnimator.ofFloat(pocketButton, View.TRANSLATION_X,
                        View.TRANSLATION_Y, arc.getPath(translatedLeft, translatedTop, 0, 0));
                PropertyValuesHolder pvhPocketScaleDownX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1f);
                PropertyValuesHolder pvhPocketScaleDownY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1f);
                Animator pvhPocketScaleDown = ObjectAnimator.ofPropertyValuesHolder(pocketButton,
                        pvhPocketScaleDownX, pvhPocketScaleDownY);
                ObjectAnimator pocketFadeDown = ObjectAnimator.ofInt(pocketButton, ViewUtils.IMAGE_ALPHA, 138);

                AnimatorSet down = new AnimatorSet();
                down.playTogether(titleMoveFadeIn, pocketMoveDown, pvhPocketScaleDown, pocketFadeDown);
                down.setDuration(300);
                down.setInterpolator(
                        AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in));
                down.setStartDelay(500);

                // play it
                AnimatorSet upDown = new AnimatorSet();
                upDown.playSequentially(up, down);

                // clean up
                upDown.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        ((ViewGroup) pocketButton.getParent().getParent()).setClipChildren(true);
                        holder.itemView.setHasTransientState(false);
                    }
                });
                upDown.start();
            }
        });
    }
}