Example usage for android.animation ObjectAnimator ofFloat

List of usage examples for android.animation ObjectAnimator ofFloat

Introduction

In this page you can find the example usage for android.animation ObjectAnimator ofFloat.

Prototype

public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> xProperty, Property<T, Float> yProperty,
        Path path) 

Source Link

Document

Constructs and returns an ObjectAnimator that animates coordinates along a Path using two properties.

Usage

From source file:com.panahit.ui.IntroActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Theme_TMessages);/*from   www .  java  2  s. co m*/
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    if (AndroidUtilities.isTablet()) {
        setContentView(R.layout.intro_layout_tablet);
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.intro_layout);
    }

    if (LocaleController.isRTL) {
        icons = new int[] { R.drawable.intro7, R.drawable.intro6, R.drawable.intro5, R.drawable.intro4,
                R.drawable.intro3, R.drawable.intro2, R.drawable.intro1 };
        titles = new int[] { R.string.Page7Title, R.string.Page6Title, R.string.Page5Title, R.string.Page4Title,
                R.string.Page3Title, R.string.Page2Title, R.string.Page1Title };
        messages = new int[] { R.string.Page7Message, R.string.Page6Message, R.string.Page5Message,
                R.string.Page4Message, R.string.Page3Message, R.string.Page2Message, R.string.Page1Message };
    } else {
        icons = new int[] { R.drawable.intro1, R.drawable.intro2, R.drawable.intro3, R.drawable.intro4,
                R.drawable.intro5, R.drawable.intro6, R.drawable.intro7 };
        titles = new int[] { R.string.Page1Title, R.string.Page2Title, R.string.Page3Title, R.string.Page4Title,
                R.string.Page5Title, R.string.Page6Title, R.string.Page7Title };
        messages = new int[] { R.string.Page1Message, R.string.Page2Message, R.string.Page3Message,
                R.string.Page4Message, R.string.Page5Message, R.string.Page6Message, R.string.Page7Message };
    }
    viewPager = (ViewPager) findViewById(R.id.intro_view_pager);
    TextView startMessagingButton = (TextView) findViewById(R.id.start_messaging_button);
    startMessagingButton
            .setText(LocaleController.getString("StartMessaging", R.string.StartMessaging).toUpperCase());
    if (Build.VERSION.SDK_INT >= 21) {
        StateListAnimator animator = new StateListAnimator();
        animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator
                .ofFloat(startMessagingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4))
                .setDuration(200));
        animator.addState(new int[] {}, ObjectAnimator
                .ofFloat(startMessagingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2))
                .setDuration(200));
        startMessagingButton.setStateListAnimator(animator);
    }
    topImage1 = (ImageView) findViewById(R.id.icon_image1);
    topImage2 = (ImageView) findViewById(R.id.icon_image2);
    bottomPages = (ViewGroup) findViewById(R.id.bottom_pages);
    topImage2.setVisibility(View.GONE);
    viewPager.setAdapter(new IntroAdapter());
    viewPager.setPageMargin(0);
    viewPager.setOffscreenPageLimit(1);
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int i) {

        }

        @Override
        public void onPageScrollStateChanged(int i) {
            if (i == ViewPager.SCROLL_STATE_IDLE || i == ViewPager.SCROLL_STATE_SETTLING) {
                if (lastPage != viewPager.getCurrentItem()) {
                    lastPage = viewPager.getCurrentItem();

                    final ImageView fadeoutImage;
                    final ImageView fadeinImage;
                    if (topImage1.getVisibility() == View.VISIBLE) {
                        fadeoutImage = topImage1;
                        fadeinImage = topImage2;

                    } else {
                        fadeoutImage = topImage2;
                        fadeinImage = topImage1;
                    }

                    fadeinImage.bringToFront();
                    fadeinImage.setImageResource(icons[lastPage]);
                    fadeinImage.clearAnimation();
                    fadeoutImage.clearAnimation();

                    Animation outAnimation = AnimationUtils.loadAnimation(IntroActivity.this,
                            R.anim.icon_anim_fade_out);
                    outAnimation.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            fadeoutImage.setVisibility(View.GONE);
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });

                    Animation inAnimation = AnimationUtils.loadAnimation(IntroActivity.this,
                            R.anim.icon_anim_fade_in);
                    inAnimation.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {
                            fadeinImage.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });

                    fadeoutImage.startAnimation(outAnimation);
                    fadeinImage.startAnimation(inAnimation);
                }
            }
        }
    });

    startMessagingButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (startPressed) {
                return;
            }
            startPressed = true;
            Intent intent2 = new Intent(IntroActivity.this, LaunchActivity.class);
            intent2.putExtra("fromIntro", true);
            startActivity(intent2);
            finish();
        }
    });
    if (BuildVars.DEBUG_VERSION) {
        startMessagingButton.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                ConnectionsManager.getInstance().switchBackend();
                return true;
            }
        });
    }

    justCreated = true;
}

From source file:com.goftagram.telegram.ui.IntroActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Theme_TMessages);//from   w  ww  . jav a  2s.  c om
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    if (AndroidUtilities.isTablet()) {
        setContentView(R.layout.intro_layout_tablet);
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.intro_layout);
    }

    if (LocaleController.isRTL) {
        icons = new int[] { R.drawable.intro7, R.drawable.intro6, R.drawable.intro5, R.drawable.intro4,
                R.drawable.intro3, R.drawable.intro2, R.drawable.intro1 };
        titles = new int[] { R.string.Page7Title, R.string.Page6Title, R.string.Page5Title, R.string.Page4Title,
                R.string.Page3Title, R.string.Page2Title, R.string.Page1Title };
        messages = new int[] { R.string.Page7Message, R.string.Page6Message, R.string.Page5Message,
                R.string.Page4Message, R.string.Page3Message, R.string.Page2Message, R.string.Page1Message };
    } else {
        icons = new int[] { R.drawable.intro1, R.drawable.intro2, R.drawable.intro3, R.drawable.intro4,
                R.drawable.intro5, R.drawable.intro6, R.drawable.intro7 };
        titles = new int[] { R.string.Page1Title, R.string.Page2Title, R.string.Page3Title, R.string.Page4Title,
                R.string.Page5Title, R.string.Page6Title, R.string.Page7Title };
        messages = new int[] { R.string.Page1Message, R.string.Page2Message, R.string.Page3Message,
                R.string.Page4Message, R.string.Page5Message, R.string.Page6Message, R.string.Page7Message };
    }
    viewPager = (ViewPager) findViewById(R.id.intro_view_pager);
    TextView startMessagingButton = (TextView) findViewById(R.id.start_messaging_button);
    startMessagingButton
            .setText(LocaleController.getString("StartMessaging", R.string.StartMessaging).toUpperCase());
    if (Build.VERSION.SDK_INT >= 21) {
        StateListAnimator animator = new StateListAnimator();
        animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator
                .ofFloat(startMessagingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4))
                .setDuration(200));
        animator.addState(new int[] {}, ObjectAnimator
                .ofFloat(startMessagingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2))
                .setDuration(200));
        startMessagingButton.setStateListAnimator(animator);
    }
    topImage1 = (ImageView) findViewById(R.id.icon_image1);
    topImage2 = (ImageView) findViewById(R.id.icon_image2);
    bottomPages = (ViewGroup) findViewById(R.id.bottom_pages);
    topImage2.setVisibility(View.GONE);
    viewPager.setAdapter(new IntroAdapter());
    viewPager.setPageMargin(0);
    viewPager.setOffscreenPageLimit(1);
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int i) {

        }

        @Override
        public void onPageScrollStateChanged(int i) {
            if (i == ViewPager.SCROLL_STATE_IDLE || i == ViewPager.SCROLL_STATE_SETTLING) {
                if (lastPage != viewPager.getCurrentItem()) {
                    lastPage = viewPager.getCurrentItem();

                    final ImageView fadeoutImage;
                    final ImageView fadeinImage;
                    if (topImage1.getVisibility() == View.VISIBLE) {
                        fadeoutImage = topImage1;
                        fadeinImage = topImage2;

                    } else {
                        fadeoutImage = topImage2;
                        fadeinImage = topImage1;
                    }

                    fadeinImage.bringToFront();
                    fadeinImage.setImageResource(icons[lastPage]);
                    fadeinImage.clearAnimation();
                    fadeoutImage.clearAnimation();

                    Animation outAnimation = AnimationUtils.loadAnimation(IntroActivity.this,
                            R.anim.icon_anim_fade_out);
                    outAnimation.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            fadeoutImage.setVisibility(View.GONE);
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });

                    Animation inAnimation = AnimationUtils.loadAnimation(IntroActivity.this,
                            R.anim.icon_anim_fade_in);
                    inAnimation.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {
                            fadeinImage.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });

                    fadeoutImage.startAnimation(outAnimation);
                    fadeinImage.startAnimation(inAnimation);
                }
            }
        }
    });

    startMessagingButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (startPressed) {
                return;
            }
            startPressed = true;
            Intent intent2 = new Intent(IntroActivity.this, LaunchActivity.class);
            intent2.putExtra("fromIntro", true);
            startActivity(intent2);
            finish();
        }
    });
    if (BuildConfig.DEBUG) {
        startMessagingButton.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                ConnectionsManager.getInstance().switchBackend();
                return true;
            }
        });
    }

    justCreated = true;
}

From source file:cn.tan.lib.widget.DrawShadowFrameLayout.java

public void setShadowVisible(boolean shadowVisible, boolean animate) {
    this.mShadowVisible = shadowVisible;
    if (mAnimator != null) {
        mAnimator.cancel();// w  ww . j  a v  a2s .  c  o m
        mAnimator = null;
    }

    if (animate && mShadowDrawable != null) {
        mAnimator = ObjectAnimator.ofFloat(this, SHADOW_ALPHA, shadowVisible ? 0f : 1f,
                shadowVisible ? 1f : 0f);
        mAnimator.setDuration(1000);
        mAnimator.start();
    }

    ViewCompat.postInvalidateOnAnimation(this);
    setWillNotDraw(!mShadowVisible || mShadowDrawable == null);
}

From source file:com.microsoft.mimickeralarm.mimics.ProgressButton.java

public ProgressButton(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFocusable(true);/*from   w w  w .j a  v  a  2 s .  com*/
    setScaleType(ScaleType.CENTER_INSIDE);

    sYellow = ContextCompat.getColor(context, R.color.yellow3);
    sBlue = ContextCompat.getColor(context, R.color.blue);
    sGrey = ContextCompat.getColor(context, R.color.grey);
    sWhite = ContextCompat.getColor(context, R.color.white);
    mMicrophoneIcon = ((BitmapDrawable) ContextCompat.getDrawable(context, android.R.drawable.ic_btn_speak_now))
            .getBitmap();
    mCameraIcon = ((BitmapDrawable) ContextCompat.getDrawable(context, android.R.drawable.ic_menu_camera))
            .getBitmap();

    mBrush = new Paint(Paint.ANTI_ALIAS_FLAG);

    mLoadingAnimation = ObjectAnimator.ofFloat(this, "loadingAnimationProgress", 0f, 360f);
    mLoadingAnimation.setDuration(LOADING_ANIMATION_DURATION);
    mLoadingAnimation.setRepeatCount(ObjectAnimator.INFINITE);

    mPressedAnimation = ObjectAnimator.ofFloat(this, "radius", 0f, 0f);
    mPressedAnimation.setDuration(PRESSED_ANIMATION_DURATION);
    mPressedAnimation.setInterpolator(new DecelerateInterpolator());
}

From source file:MainActivity.java

private void zoomFromThumbnail(final ImageView imageViewThumb) {
    if (mCurrentAnimator != null) {
        mCurrentAnimator.cancel();/* ww w .j a v a2s  . co  m*/
    }

    final Rect startBounds = new Rect();
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();

    imageViewThumb.getGlobalVisibleRect(startBounds);
    findViewById(R.id.frameLayout).getGlobalVisibleRect(finalBounds, globalOffset);
    mImageViewExpanded
            .setImageBitmap(loadSampledResource(R.drawable.image, finalBounds.height(), finalBounds.width()));

    startBounds.offset(-globalOffset.x, -globalOffset.y);
    finalBounds.offset(-globalOffset.x, -globalOffset.y);

    float startScale;
    if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width()
            / startBounds.height()) {
        startScale = (float) startBounds.height() / finalBounds.height();
        float startWidth = startScale * finalBounds.width();
        float deltaWidth = (startWidth - startBounds.width()) / 2;
        startBounds.left -= deltaWidth;
        startBounds.right += deltaWidth;
    } else {
        startScale = (float) startBounds.width() / finalBounds.width();
        float startHeight = startScale * finalBounds.height();
        float deltaHeight = (startHeight - startBounds.height()) / 2;
        startBounds.top -= deltaHeight;
        startBounds.bottom += deltaHeight;
    }

    imageViewThumb.setVisibility(View.GONE);
    mImageViewExpanded.setVisibility(View.VISIBLE);
    mImageViewExpanded.setPivotX(0f);
    mImageViewExpanded.setPivotY(0f);

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(ObjectAnimator.ofFloat(mImageViewExpanded, View.X, startBounds.left, finalBounds.left))
            .with(ObjectAnimator.ofFloat(mImageViewExpanded, View.Y, startBounds.top, finalBounds.top))
            .with(ObjectAnimator.ofFloat(mImageViewExpanded, View.SCALE_X, startScale, 1f))
            .with(ObjectAnimator.ofFloat(mImageViewExpanded, View.SCALE_Y, startScale, 1f));
    animatorSet.setDuration(1000);
    animatorSet.setInterpolator(new AccelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCurrentAnimator = null;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mCurrentAnimator = null;
        }
    });
    animatorSet.start();
    mCurrentAnimator = animatorSet;
}

From source file:com.example.google.maps.folding_map.MainActivity.java

public void animateFold() {
    ObjectAnimator animator = ObjectAnimator.ofFloat(mFoldingLayout, "foldFactor",
            mFoldingLayout.getFoldFactor(), 1);
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.setRepeatCount(1);//from  w w  w  . jav a 2s .com
    animator.setDuration(FOLD_ANIMATION_DURATION);
    animator.setInterpolator(new AccelerateInterpolator());
    animator.start();
}

From source file:com.flexible.flexibleadapter.helpers.AnimatorHelper.java

/**
 * Item will flip from {@code 0.0f} to {@code 1.0f}.
 *
 * @param animators user defined list of animators
 * @param view      itemView to animate/*from   w  w  w.ja  v a  2 s  .  co m*/
 * @since 5.0.0-rc1
 */
public static void flipAnimator(@NonNull List<Animator> animators, @NonNull View view) {
    alphaAnimator(animators, view, 0f);
    animators.add(ObjectAnimator.ofFloat(view, "scaleY", 0f, 1f));
    if (FlexibleAdapter.DEBUG)
        Log.v(TAG, " Added FLIP Animator");
}

From source file:com.example.android.tryanimationt.TryAnimationFragment.java

void animButtons(ImageButton bt, boolean in, int animTime, int delay) {

    //delay = 0;/*from  w  w  w . ja  va  2s .c  o m*/

    float rotateStart, rotateEnd;
    float scaleXStart, scaleXEnd;
    float scaleYStart, scaleYEnd;
    float transitionXStart, transitionXEnd;
    float transitionYStart, transitionYEnd;

    if (in) {
        rotateStart = 0;
        rotateEnd = 359;
        scaleXStart = 0.66f;
        scaleXEnd = 1;
        scaleYStart = 0.66f;
        scaleYEnd = 1;
        transitionXStart = 60;
        transitionXEnd = 0;
        transitionYStart = 10;
        transitionYEnd = 0;

    } else {
        rotateStart = 359;
        rotateEnd = 0;
        scaleXStart = 1;
        scaleXEnd = 0.66f;
        scaleYStart = 1;
        scaleYEnd = 0.66f;
        transitionXStart = 0;
        transitionXEnd = 60;
        transitionYStart = 0;
        transitionYEnd = 10;
    }
    bt.setTranslationX(transitionXStart);
    bt.setTranslationY(transitionYStart);

    AnimatorSet animSet = new AnimatorSet();
    ObjectAnimator animRotate = ObjectAnimator.ofFloat(bt, "rotation", rotateStart, rotateEnd);
    animRotate.setDuration(animTime);

    ObjectAnimator animScaleX = ObjectAnimator.ofFloat(bt, "scaleX", scaleXStart, scaleXEnd);
    animScaleX.setDuration(animTime);
    animScaleX.setStartDelay(Math.round(delay * 0.66));
    ObjectAnimator animScaleY = ObjectAnimator.ofFloat(bt, "scaleY", scaleYStart, scaleYEnd);
    animScaleY.setDuration(animTime);
    animScaleY.setStartDelay(Math.round(delay * 0.66));

    ObjectAnimator animTrx = ObjectAnimator.ofFloat(bt, "translationX", transitionXStart, transitionXEnd);
    animTrx.setDuration(animTime);
    animTrx.setStartDelay(delay);
    ObjectAnimator animTry = ObjectAnimator.ofFloat(bt, "translationY", transitionYStart, transitionYEnd);
    animTry.setDuration(animTime);
    animTry.setStartDelay(delay);

    animSet.setInterpolator(new BounceInterpolator());
    animSet.playTogether(animRotate, animScaleX, animScaleY, animTrx, animTry);

    animSet.start();
}

From source file:com.metinkale.prayerapp.compass._2D.Frag2D.java

public void hide() {
    mHidden = true;//  w w  w  . j a va  2s  . c  om
    mCompassView.post(new Runnable() {
        @Override
        public void run() {
            ObjectAnimator scaleX = ObjectAnimator.ofFloat(mCompassView, "scaleX", 1, 0);
            ObjectAnimator scaleY = ObjectAnimator.ofFloat(mCompassView, "scaleY", 1, 0);

            ObjectAnimator scaleX2 = ObjectAnimator.ofFloat(mInfo, "scaleX", 1, 0);
            ObjectAnimator scaleY2 = ObjectAnimator.ofFloat(mInfo, "scaleY", 1, 0);

            AnimatorSet animSetXY = new AnimatorSet();
            animSetXY.playTogether(scaleX, scaleY, scaleX2, scaleY2);
            animSetXY.setInterpolator(accelerateInterpolator);
            animSetXY.setDuration(300);
            animSetXY.start();
        }
    });

}

From source file:com.mac.SafeWalk.WelcomeActivity.java

public void animate(ImageView dot) {
    if (dot != null) {
        Log.w("WelcomeActivity", "setting up animation");
        ObjectAnimator appear = ObjectAnimator.ofFloat(dot, "alpha", 0f, 1f);
        appear.setRepeatCount(2);/*  www.ja  v  a2 s .c o  m*/
        appear.setDuration(2000);
        appear.start();
        ObjectAnimator translation = ObjectAnimator.ofFloat(dot, "translationX", 0, -400f);
        translation.setDuration(2000);
        translation.setRepeatCount(2);
        translation.start();
        Log.w("WelcomeActivity", "starting animation");
    }
}