List of usage examples for android.animation ObjectAnimator setPropertyName
public void setPropertyName(@NonNull String propertyName)
From source file:Main.java
public static ObjectAnimator ofInt(Object target, String propertyName, int... values) { ObjectAnimator anim = new ObjectAnimator(); anim.setTarget(target);/* ww w . j av a2s .c o m*/ anim.setPropertyName(propertyName); anim.setIntValues(values); cancelOnDestroyActivity(anim); return anim; }
From source file:Main.java
public static ObjectAnimator ofFloat(Object target, String propertyName, float... values) { ObjectAnimator anim = new ObjectAnimator(); anim.setTarget(target);/* w ww . j a v a 2 s . c om*/ anim.setPropertyName(propertyName); anim.setFloatValues(values); cancelOnDestroyActivity(anim); return anim; }
From source file:com.google.android.apps.gutenberg.ScannerActivity.java
private void showCheckinAnimation(Checkin checkin) { if (mLastAnimator != null) { mLastAnimator.cancel();/*from w w w . j a va2s . com*/ } final FrameLayout cover = (FrameLayout) findViewById(R.id.item_cover); cover.setVisibility(View.VISIBLE); final FrameLayout layer = (FrameLayout) findViewById(R.id.animation_layer); final CheckinHolder holder = new CheckinHolder(getLayoutInflater(), layer); FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.CENTER_VERTICAL; holder.setWillAnimate(true); holder.bind(checkin, mImageLoader); holder.itemView.setBackgroundColor(Color.rgb(0xf0, 0xf0, 0xf0)); float elevation = getResources().getDimension(R.dimen.popup_elevation); ViewCompat.setTranslationZ(holder.itemView, elevation); holder.setLines(false, false); layer.addView(holder.itemView, lp); // Interpolator for animators FastOutSlowInInterpolator interpolator = new FastOutSlowInInterpolator(); // Pop-up Animator popUpAnim = AnimatorInflater.loadAnimator(this, R.animator.pop_up); popUpAnim.setTarget(holder.itemView); popUpAnim.setInterpolator(interpolator); popUpAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { holder.animateCheckin(); } }); // Wait ObjectAnimator waitAnim = new ObjectAnimator(); waitAnim.setTarget(holder.itemView); waitAnim.setPropertyName("translationY"); waitAnim.setFloatValues(0.f, 0.f); waitAnim.setDuration(2000); // Slide-down ObjectAnimator slideDownAnim = new ObjectAnimator(); slideDownAnim.setTarget(holder.itemView); slideDownAnim.setPropertyName("translationY"); slideDownAnim.setFloatValues(0.f, calcSlideDistance()); slideDownAnim.setInterpolator(interpolator); // Landing anim ObjectAnimator landingAnim = new ObjectAnimator(); landingAnim.setTarget(holder.itemView); landingAnim.setPropertyName("translationZ"); landingAnim.setFloatValues(elevation, 0.f); landingAnim.setInterpolator(interpolator); landingAnim.setDuration(500); // Play the animators AnimatorSet set = new AnimatorSet(); set.setInterpolator(interpolator); set.playSequentially(popUpAnim, waitAnim, slideDownAnim, landingAnim); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { clean(); } @Override public void onAnimationCancel(Animator animation) { clean(); } private void clean() { mLastAnimator = null; layer.removeAllViews(); cover.setVisibility(View.INVISIBLE); } }); mLastAnimator = set; set.start(); }
From source file:android.support.graphics.drawable.AnimatorInflaterCompat.java
/** * Setup ObjectAnimator's property or values from pathData. * * @param anim The target Animator which will be updated. * @param arrayObjectAnimator TypedArray for the ObjectAnimator. * @param pixelSize The relative pixel size, used to calculate the *///from w ww . jav a2 s . c o m private static void setupObjectAnimator(ValueAnimator anim, TypedArray arrayObjectAnimator, int valueType, float pixelSize, XmlPullParser parser) { ObjectAnimator oa = (ObjectAnimator) anim; String pathData = TypedArrayUtils.getNamedString(arrayObjectAnimator, parser, "pathData", AndroidResources.STYLEABLE_PROPERTY_ANIMATOR_PATH_DATA); // Path can be involved in an ObjectAnimator in the following 3 ways: // 1) Path morphing: the property to be animated is pathData, and valueFrom and valueTo // are both of pathType. valueType = pathType needs to be explicitly defined. // 2) A property in X or Y dimension can be animated along a path: the property needs to be // defined in propertyXName or propertyYName attribute, the path will be defined in the // pathData attribute. valueFrom and valueTo will not be necessary for this animation. // 3) PathInterpolator can also define a path (in pathData) for its interpolation curve. // Here we are dealing with case 2: if (pathData != null) { String propertyXName = TypedArrayUtils.getNamedString(arrayObjectAnimator, parser, "propertyXName", AndroidResources.STYLEABLE_PROPERTY_ANIMATOR_PROPERTY_X_NAME); String propertyYName = TypedArrayUtils.getNamedString(arrayObjectAnimator, parser, "propertyYName", AndroidResources.STYLEABLE_PROPERTY_ANIMATOR_PROPERTY_Y_NAME); if (valueType == VALUE_TYPE_PATH || valueType == VALUE_TYPE_UNDEFINED) { // When pathData is defined, we are in case #2 mentioned above. ValueType can only // be float type, or int type. Otherwise we fallback to default type. valueType = VALUE_TYPE_FLOAT; } if (propertyXName == null && propertyYName == null) { throw new InflateException(arrayObjectAnimator.getPositionDescription() + " propertyXName or propertyYName is needed for PathData"); } else { Path path = PathParser.createPathFromPathData(pathData); setupPathMotion(path, oa, 0.5f * pixelSize, propertyXName, propertyYName); } } else { String propertyName = TypedArrayUtils.getNamedString(arrayObjectAnimator, parser, "propertyName", AndroidResources.STYLEABLE_PROPERTY_ANIMATOR_PROPERTY_NAME); oa.setPropertyName(propertyName); } return; }