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

The following examples show how to use android.view.ViewPropertyAnimator#translationX() . 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: 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 3
Source File: g.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public com.nineoldandroids.view.ViewPropertyAnimator translationX(float f)
{
    ViewPropertyAnimator viewpropertyanimator = (ViewPropertyAnimator)b.get();
    if (viewpropertyanimator != null)
    {
        viewpropertyanimator.translationX(f);
    }
    return this;
}
 
Example 4
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 5
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 6
Source File: MainActivity.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
private void updateLocationDrawable() {
    logger.debug("updateLocationDrawable()");
    if (mViews.recordButton.getTag() != mTrackingState) {
        int recordColor = mTrackingState == TRACKING_STATE.TRACKING ? mColorAccent : mColorActionIcon;
        mViews.recordButton.getDrawable().setTint(recordColor);
        mViews.recordButton.setTag(mTrackingState);
    }
    if (mViews.locationButton.getTag() == mLocationState)
        return;
    if (mViews.locationButton.getTag() == LocationState.SEARCHING) {
        mViews.locationButton.clearAnimation();
        mViews.satellites.animate().translationY(-200);
    }
    final ViewPropertyAnimator gaugePanelAnimator = mViews.gaugePanel.animate();
    gaugePanelAnimator.setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (mLocationState == LocationState.NORTH)
                HelperUtils.showTargetedAdvice(MainActivity.this, Configuration.ADVICE_MORE_GAUGES, R.string.advice_more_gauges, mViews.gaugePanel, true);
            //HelperUtils.showAdvice(Configuration.ADVICE_MORE_GAUGES, R.string.advice_more_gauges, mViews.coordinatorLayout);
            if (mLocationState == LocationState.SEARCHING)
                mViews.satellites.animate().translationY(8);
            gaugePanelAnimator.setListener(null);
            updateMapViewArea();
        }
    });
    switch (mLocationState) {
        case DISABLED:
            mNavigationNorthDrawable.setTint(mColorActionIcon);
            mViews.locationButton.setImageDrawable(mNavigationNorthDrawable);
            mCrosshairLayer.setEnabled(true);
            if (mViews.gaugePanel.getWidth() > 0) {
                gaugePanelAnimator.translationX(-mViews.gaugePanel.getWidth());
                mViews.gaugePanel.onVisibilityChanged(false);
            }
            break;
        case SEARCHING:
            mLocationSearchingDrawable.setTint(mColorAccent);
            mViews.locationButton.setImageDrawable(mLocationSearchingDrawable);
            Animation rotation = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
            rotation.setInterpolator(new LinearInterpolator());
            rotation.setRepeatCount(Animation.INFINITE);
            rotation.setDuration(1000);
            mViews.locationButton.startAnimation(rotation);
            if (mViews.gaugePanel.getVisibility() == View.INVISIBLE) {
                mViews.satellites.animate().translationY(8);
            } else {
                gaugePanelAnimator.translationX(-mViews.gaugePanel.getWidth());
                mViews.gaugePanel.onVisibilityChanged(false);
            }
            break;
        case ENABLED:
            mMyLocationDrawable.setTint(mColorActionIcon);
            mViews.locationButton.setImageDrawable(mMyLocationDrawable);
            mCrosshairLayer.setEnabled(true);
            gaugePanelAnimator.translationX(-mViews.gaugePanel.getWidth());
            mViews.gaugePanel.onVisibilityChanged(false);
            break;
        case NORTH:
            mNavigationNorthDrawable.setTint(mColorAccent);
            mViews.locationButton.setImageDrawable(mNavigationNorthDrawable);
            mCrosshairLayer.setEnabled(false);
            gaugePanelAnimator.translationX(0);
            mViews.gaugePanel.onVisibilityChanged(true);
            break;
        case TRACK:
            mNavigationTrackDrawable.setTint(mColorAccent);
            mViews.locationButton.setImageDrawable(mNavigationTrackDrawable);
            mCrosshairLayer.setEnabled(false);
            gaugePanelAnimator.translationX(0);
            mViews.gaugePanel.onVisibilityChanged(true);
    }
    mViews.locationButton.setTag(mLocationState);
    for (WeakReference<LocationStateChangeListener> weakRef : mLocationStateChangeListeners) {
        LocationStateChangeListener locationStateChangeListener = weakRef.get();
        if (locationStateChangeListener != null) {
            locationStateChangeListener.onLocationStateChanged(mLocationState);
        }
    }
}
 
Example 7
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";
}
 
Example 8
Source File: WaveEffect.java    From JazzyListView with Apache License 2.0 4 votes vote down vote up
@Override
public void setupAnimation(View item, int position, int scrollDirection, ViewPropertyAnimator animator) {
    animator.translationX(0);
}
 
Example 9
Source File: ZipperEffect.java    From JazzyListView with Apache License 2.0 4 votes vote down vote up
@Override
public void setupAnimation(View item, int position, int scrollDirection, ViewPropertyAnimator animator) {
    animator.translationX(0);
}