Java Code Examples for android.animation.AnimatorSet#setTarget()

The following examples show how to use android.animation.AnimatorSet#setTarget() . 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: PropertyAnimationActivity.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
/**
 * use property animation by xml;
 *
 * @return
 */
private Animator getAnimationByXml() {
    final int height = mPuppet.getLayoutParams().height;
    final int width = mPuppet.getLayoutParams().width;
    AnimatorSet animatorSet = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.animatorset);

    //ValueAnimator usage:add AnimatorUpdateListener;
    ArrayList<Animator> childAnimations = animatorSet.getChildAnimations();
    ((ValueAnimator) childAnimations.get(childAnimations.size() - 1))
            .addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    float animatedValue = (float) valueAnimator.getAnimatedValue();
                    mPuppet.getLayoutParams().height = (int) (height * animatedValue);
                    mPuppet.getLayoutParams().width = (int) (width * animatedValue);
                    mPuppet.requestLayout();
                }
            });

    animatorSet.setTarget(mPuppet);
    return animatorSet;
}
 
Example 2
Source File: FavoriteFragment.java    From memorize with MIT License 6 votes vote down vote up
@Override
public void onClick(View view) {

    AnimatorSet cardLeftIn = (AnimatorSet) AnimatorInflater.loadAnimator(AppMain.getContext(),
            R.animator.flip_left_in);

    if (!mIsBackVisible) {
        mCardFrontLayout.setVisibility(View.INVISIBLE);
        mCardBackLayout.setVisibility(View.VISIBLE);
        cardLeftIn.setTarget(mCardBackLayout);
        cardLeftIn.start();
        mIsBackVisible = true;
    } else {
        mCardBackLayout.setVisibility(View.INVISIBLE);
        mCardFrontLayout.setVisibility(View.VISIBLE);
        cardLeftIn.setTarget(mCardFrontLayout);
        cardLeftIn.start();
        mIsBackVisible = false;
    }
}
 
Example 3
Source File: BubbleTrashLayout.java    From bubbles-for-android with Apache License 2.0 5 votes vote down vote up
private void playAnimation(int animationResourceId) {
    if (!isInEditMode()) {
        AnimatorSet animator = (AnimatorSet) AnimatorInflater
                .loadAnimator(getContext(), animationResourceId);
        animator.setTarget(getChildAt(0));
        animator.start();
    }
}
 
Example 4
Source File: FadeInAnimator.java    From PowerfulRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
protected AnimatorSet generateRemoveAnimator(RecyclerView.ViewHolder holder) {
    View target = holder.itemView;

    AnimatorSet animator = new AnimatorSet();

    animator.playTogether(
            ObjectAnimator.ofFloat(target, "alpha", 1.0f, 0.0f)
    );

    animator.setTarget(target);
    animator.setDuration(getRemoveDuration());

    return animator;
}
 
Example 5
Source File: FavorLayout.java    From MousePaint with MIT License 5 votes vote down vote up
private Animator getAnimator(View target){
    AnimatorSet set = getEnterAnimtor(target);

    ValueAnimator bezierValueAnimator = getBezierValueAnimator(target);

    AnimatorSet finalSet = new AnimatorSet();
    finalSet.playSequentially(set);
    finalSet.playSequentially(set, bezierValueAnimator);
    finalSet.setInterpolator(interpolators[random.nextInt(4)]);
    finalSet.setTarget(target);
    return finalSet;
}
 
Example 6
Source File: BubbleTrashLayout.java    From Andzu with MIT License 5 votes vote down vote up
private void playAnimation(int animationResourceId) {
    if (!isInEditMode()) {
        AnimatorSet animator = (AnimatorSet) AnimatorInflater
                .loadAnimator(getContext(), animationResourceId);
        animator.setTarget(getChildAt(0));
        animator.start();
    }
}
 
Example 7
Source File: FadeInAnimator.java    From PowerfulRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
protected AnimatorSet generateAddAnimator(RecyclerView.ViewHolder holder) {
    View target = holder.itemView;

    AnimatorSet animator = new AnimatorSet();

    animator.playTogether(
            ObjectAnimator.ofFloat(target, "alpha", 0.0f, 1.0f)
    );

    animator.setTarget(target);
    animator.setDuration(getAddDuration());

    return animator;
}
 
Example 8
Source File: BubbleLayout.java    From Andzu with MIT License 5 votes vote down vote up
private void playAnimationClickDown() {
    if (!isInEditMode()) {
        AnimatorSet animator = (AnimatorSet) AnimatorInflater
                .loadAnimator(getContext(), R.animator.bubble_down_click_animator);
        animator.setTarget(this);
        animator.start();
    }
}
 
Example 9
Source File: PeriscopeLayout.java    From PeriscopeLayout with Apache License 2.0 5 votes vote down vote up
private AnimatorSet getEnterAnimtor(final View target) {

        ObjectAnimator alpha = ObjectAnimator.ofFloat(target, View.ALPHA, 0.2f, 1f);
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(target, View.SCALE_X, 0.2f, 1f);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(target, View.SCALE_Y, 0.2f, 1f);
        AnimatorSet enter = new AnimatorSet();
        enter.setDuration(500);
        enter.setInterpolator(new LinearInterpolator());
        enter.playTogether(alpha, scaleX, scaleY);
        enter.setTarget(target);
        return enter;
    }
 
Example 10
Source File: PeriscopeLayout.java    From PeriscopeLayout with Apache License 2.0 5 votes vote down vote up
private Animator getAnimator(View target) {
    AnimatorSet set = getEnterAnimtor(target);

    ValueAnimator bezierValueAnimator = getBezierValueAnimator(target);

    AnimatorSet finalSet = new AnimatorSet();
    finalSet.playSequentially(set);
    finalSet.playSequentially(set, bezierValueAnimator);
    finalSet.setInterpolator(interpolators[random.nextInt(4)]);
    finalSet.setTarget(target);
    return finalSet;
}
 
Example 11
Source File: PeriscopeLayout.java    From PeriscopeLayout with Apache License 2.0 5 votes vote down vote up
private AnimatorSet getEnterAnimtor(final View target) {

        ObjectAnimator alpha = ObjectAnimator.ofFloat(target, View.ALPHA, 0.2f, 1f);
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(target, View.SCALE_X, 0.2f, 1f);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(target, View.SCALE_Y, 0.2f, 1f);
        AnimatorSet enter = new AnimatorSet();
        enter.setDuration(500);
        enter.setInterpolator(new LinearInterpolator());
        enter.playTogether(alpha, scaleX, scaleY);
        enter.setTarget(target);
        return enter;
    }
 
Example 12
Source File: MusicalNoteLayout.java    From TikTok with Apache License 2.0 5 votes vote down vote up
private Animator getFinalAnimator(View target) {
    AnimatorSet set = getEnterAnimator(target);
    ValueAnimator bezierValueAnimator = getBezierValueAnimator(target);
    AnimatorSet finalSet = new AnimatorSet();
    finalSet.playTogether(set, bezierValueAnimator);
    finalSet.setInterpolator(new AccelerateInterpolator());
    finalSet.setTarget(target);
    return finalSet;
}
 
Example 13
Source File: FlowLikeView.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 开始动画处理
 * @param target 动画作用 View
 */
private void startAnimation(View target) {
    // 进入动画
    AnimatorSet enterAnimator = generateEnterAnimation(target);
    // 路径动画
    ValueAnimator curveAnimator = generateCurveAnimation(target);

    // 设置动画集合, 先执行进入动画, 最后再执行运动曲线动画
    AnimatorSet finalAnimatorSet = new AnimatorSet();
    finalAnimatorSet.setTarget(target);
    finalAnimatorSet.playSequentially(enterAnimator, curveAnimator);
    finalAnimatorSet.addListener(new AnimationEndListener(target));
    finalAnimatorSet.start();
}
 
Example 14
Source File: FlowLikeView.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 生成进入动画
 * @param target 动画作用 View
 * @return 动画集合
 */
private AnimatorSet generateEnterAnimation(View target) {
    ObjectAnimator alpha = ObjectAnimator.ofFloat(target, "alpha", 0.2f, 1f);
    ObjectAnimator scaleX = ObjectAnimator.ofFloat(target, "scaleX", 0.5f, 1f);
    ObjectAnimator scaleY = ObjectAnimator.ofFloat(target, "scaleY", 0.5f, 1f);
    AnimatorSet enterAnimation = new AnimatorSet();
    enterAnimation.playTogether(alpha, scaleX, scaleY);
    enterAnimation.setDuration(10);
    enterAnimation.setTarget(target);
    return enterAnimation;
}
 
Example 15
Source File: ElectricFanLoadingRenderer.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
private Animator getAnimator(LeafHolder target, RectF leafFlyRect, float progress) {
    ValueAnimator bezierValueAnimator = getBezierValueAnimator(target, leafFlyRect, progress);

    AnimatorSet finalSet = new AnimatorSet();
    finalSet.playSequentially(bezierValueAnimator);
    finalSet.setInterpolator(INTERPOLATORS[mRandom.nextInt(INTERPOLATORS.length)]);
    finalSet.setTarget(target);
    return finalSet;
}
 
Example 16
Source File: AnimationActivity.java    From kstyle with Apache License 2.0 5 votes vote down vote up
public void onAnimatorSetTest(View view) {
    // 获取屏幕宽度
    int maxWidth = getWindowManager().getDefaultDisplay().getWidth();
    ViewWrapper wrapper = new ViewWrapper(view, maxWidth);
    AnimatorSet animatorSet = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.animator_set);
    animatorSet.setTarget(wrapper);
    animatorSet.start();
}
 
Example 17
Source File: LiveObjectDetectionActivity.java    From mlkit-material-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  searchEngine = new SearchEngine(getApplicationContext());

  setContentView(R.layout.activity_live_object);
  preview = findViewById(R.id.camera_preview);
  graphicOverlay = findViewById(R.id.camera_preview_graphic_overlay);
  graphicOverlay.setOnClickListener(this);
  cameraSource = new CameraSource(graphicOverlay);

  promptChip = findViewById(R.id.bottom_prompt_chip);
  promptChipAnimator =
      (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.bottom_prompt_chip_enter);
  promptChipAnimator.setTarget(promptChip);

  searchButton = findViewById(R.id.product_search_button);
  searchButton.setOnClickListener(this);
  searchButtonAnimator =
      (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.search_button_enter);
  searchButtonAnimator.setTarget(searchButton);

  searchProgressBar = findViewById(R.id.search_progress_bar);

  setUpBottomSheet();

  findViewById(R.id.close_button).setOnClickListener(this);
  flashButton = findViewById(R.id.flash_button);
  flashButton.setOnClickListener(this);
  settingsButton = findViewById(R.id.settings_button);
  settingsButton.setOnClickListener(this);

  setUpWorkflowModel();
}
 
Example 18
Source File: CommonUtils.java    From Yuan-WanAndroid with Apache License 2.0 4 votes vote down vote up
public static void collectAnimator(Context context, View view){
    AnimatorSet animatorSet = (AnimatorSet) AnimatorInflater.loadAnimator(context, R.animator.collect_anim);
    animatorSet.setTarget(view);
    animatorSet.start();
}
 
Example 19
Source File: BezierAnimView.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
private void buildAnimViewWithDrawableResAndStart() {
        //构造出 动画的承载体View,并添加进本容器View
        IBezierAnimControler animControler = this.animControler;
        View theHoldAnimView = null;
        if (animControler != null) {
            theHoldAnimView = animControler.provideHoldAnimView(this);
//            if (theHoldAnimView instanceof ImageView) {
//                ((ImageView) theHoldAnimView).setImageResource(willAnimDrawableRes);
//            }
        }
        if (theHoldAnimView == null) {
            ImageView holdAnimView = new ImageView(getContext());
            holdAnimView.setImageResource(willAnimDrawableRes);
            theHoldAnimView = holdAnimView;
        }

        ViewGroup.LayoutParams vlp = theHoldAnimView.getLayoutParams();
        addView(theHoldAnimView, vlp != null ? vlp : flp4ChildView);

        //构造初始化 show出的动画,如果有的话
        Animator animatorOfAnimViewBorn = null;
        if (animControler != null) {
            animatorOfAnimViewBorn = animControler.provideFirstShowAnimator(this, theHoldAnimView);
        }

        if (animatorOfAnimViewBorn == null && isWillUseDefFirstShowAnimator) {
            animatorOfAnimViewBorn = buildDefBornViewAnimator(theHoldAnimView, durationOfAnimViewBorn);
        }
        //贝塞尔曲线动画
        ValueAnimator bezierAnimator = buildBezierAnimator(theHoldAnimView);

        //动画合集
        AnimatorSet wholeAnimatorSet = new AnimatorSet();
        AnimatorSet.Builder animsBuilder = wholeAnimatorSet.play(bezierAnimator);
        //是否有提供和贝塞尔曲线动画一起执行的动画
        Animator willPlayWithBezierAnim = null;
        if (animControler != null) {
            willPlayWithBezierAnim = animControler.provideAnimatorPlayWithBezierAnim(this, theHoldAnimView);
            if (willPlayWithBezierAnim != null) {
                //执行时间一定要和贝塞尔曲线动画 执行时间一致
                willPlayWithBezierAnim.setDuration(this.beziaAnimatorDuration);
                animsBuilder.with(willPlayWithBezierAnim);
            }
        }
        //是否要在初始展示的动画之后再执行贝塞尔曲线动画
        if (animatorOfAnimViewBorn != null) {
            animsBuilder.after(animatorOfAnimViewBorn);
        }
        wholeAnimatorSet.setTarget(theHoldAnimView);
        wholeAnimatorSet.start();
    }
 
Example 20
Source File: StaticObjectDetectionActivity.java    From mlkit-material-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onSearchCompleted(DetectedObject object, List<Product> productList) {
  Log.d(TAG, "Search completed for object index: " + object.getObjectIndex());
  searchedObjectMap.put(
      object.getObjectIndex(), new SearchedObject(getResources(), object, productList));
  if (searchedObjectMap.size() < detectedObjectNum) {
    // Hold off showing the result until the search of all detected objects completes.
    return;
  }

  showBottomPromptChip(getString(R.string.static_image_prompt_detected_results));
  loadingView.setVisibility(View.GONE);
  previewCardCarousel.setAdapter(
      new PreviewCardAdapter(ImmutableList.copyOf(searchedObjectMap.values()), this));
  previewCardCarousel.addOnScrollListener(
      new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
          Log.d(TAG, "New card scroll state: " + newState);
          if (newState == RecyclerView.SCROLL_STATE_IDLE) {
            for (int i = 0; i < recyclerView.getChildCount(); i++) {
              View childView = recyclerView.getChildAt(i);
              if (childView.getX() >= 0) {
                int cardIndex = recyclerView.getChildAdapterPosition(childView);
                if (cardIndex != currentSelectedObjectIndex) {
                  selectNewObject(cardIndex);
                }
                break;
              }
            }
          }
        }
      });

  for (SearchedObject searchedObject : searchedObjectMap.values()) {
    StaticObjectDotView dotView = createDotView(searchedObject);
    dotView.setOnClickListener(
        v -> {
          if (searchedObject.getObjectIndex() == currentSelectedObjectIndex) {
            showSearchResults(searchedObject);
          } else {
            selectNewObject(searchedObject.getObjectIndex());
            showSearchResults(searchedObject);
            previewCardCarousel.smoothScrollToPosition(searchedObject.getObjectIndex());
          }
        });

    dotViewContainer.addView(dotView);
    AnimatorSet animatorSet =
        ((AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.static_image_dot_enter));
    animatorSet.setTarget(dotView);
    animatorSet.start();
  }
}