Java Code Examples for android.view.View#startAnimation()

The following examples show how to use android.view.View#startAnimation() . These examples are extracted from open source projects. 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 Project: Paginize   File: SquashPageAnimator.java    License: MIT License 6 votes vote down vote up
@Override
public boolean onPopPageAnimation(
    View oldPageView,
    View newPageView,
    AnimationDirection animationDirection) {
  if (animationDirection == AnimationDirection.FROM_LEFT) {
    oldPageView.startAnimation(mShrinkOutFromLeftAnimation);
    if (newPageView != null) {
      newPageView.startAnimation(mExpanndInFromLeftAnimation);
    }

  } else {
    oldPageView.startAnimation(mShrinkOutFromRightAnimation);
    if (newPageView != null) {
      newPageView.startAnimation(mExpandInFromRightAnimation);
    }
  }

  return true;
}
 
Example 2
public static void expand(final View v) {
    v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final int targetHeight = v.getMeasuredHeight();

    // Older versions of android (pre API 21) cancel animations for views with a height of 0.
    v.getLayoutParams().height = 1;
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1
                    ? ViewGroup.LayoutParams.WRAP_CONTENT
                    : (int) (targetHeight * interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}
 
Example 3
Source Project: something.apk   File: PageDividerItem.java    License: MIT License 6 votes vote down vote up
@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.page_divider_page:
            delegate.showPageSelectDialog(pageNumber, maxPage);
            break;
        case R.id.page_divider_refresh:
            delegate.refreshPage(pageNumber);
            RotateAnimation rot = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
            rot.setRepeatMode(Animation.RESTART);
            rot.setRepeatCount(Animation.INFINITE);
            v.startAnimation(rot);
            break;
        case R.id.page_divider_scroll:
            delegate.scrollToTop();
            break;
    }
}
 
Example 4
public static void expand(final View v) {
    v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    final int targtetHeight = v.getMeasuredHeight();

    v.getLayoutParams().height = 0;
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation()
    {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1
                    ? LayoutParams.WRAP_CONTENT
                    : (int)(targtetHeight * interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration(500);
    v.startAnimation(a);
}
 
Example 5
Source Project: opentasks   File: ViewTaskFragment.java    License: Apache License 2.0 5 votes vote down vote up
private void animate(View v, int duration, int visibility)
{
    AlphaAnimation alphaAnimation = (visibility == View.VISIBLE) ? new AlphaAnimation(0f, 1f) : new AlphaAnimation(1f, 0f);
    alphaAnimation.setDuration(duration);
    alphaAnimation.setFillAfter(true);
    v.startAnimation(alphaAnimation);
}
 
Example 6
private void animateButtonIn(View button, int delay) {
  AnimationSet animation = new AnimationSet(true);
  Animation scale = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
                                       Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.0f);

  animation.addAnimation(scale);
  animation.setInterpolator(new OvershootInterpolator(1));
  animation.setDuration(ANIMATION_DURATION);
  animation.setStartOffset(delay);
  button.startAnimation(animation);
}
 
Example 7
protected void setAnimation(View viewToAnimate, int position) {
    if (position > lastPosition) {
        Animation animation = AnimationUtils.loadAnimation(viewToAnimate.getContext(), R
                .anim.item_bottom_in);
        viewToAnimate.startAnimation(animation);
        lastPosition = position;
    }
}
 
Example 8
private void fillUp(int pos, int nextBottom, boolean isAnim) {
    int end = 0;

    while (nextBottom > end && pos >= 0) {
        View child = makeAndAddView(pos, nextBottom, false, mListPadding.left, false);
        nextBottom = child.getTop() - mDividerHeight;
        if (isAnim && mItemAnimForTopIn != 0 && child.getVisibility() == View.VISIBLE) {
            child.startAnimation(AnimationUtils.loadAnimation(getContext(), mItemAnimForTopIn));
        }
        pos--;
    }
    mFirstPosition = pos + 1;
}
 
Example 9
Source Project: BaseProject   File: ExpandableLayout.java    License: Apache License 2.0 5 votes vote down vote up
private void collapse(final View v)
{
    final int initialHeight = v.getMeasuredHeight();
    animation = new Animation()
    {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if(interpolatedTime == 1)
            {
                v.setVisibility(View.GONE);
                isOpened = false;
            }
            else{
                v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    animation.setDuration(duration);
    v.startAnimation(animation);
}
 
Example 10
Source Project: AndroidHeros   File: MainActivity.java    License: MIT License 5 votes vote down vote up
public void btnScaleSelf(View view) {
    ScaleAnimation sa = new ScaleAnimation(0, 1, 0, 1,
            Animation.RELATIVE_TO_SELF, 0.5F,
            Animation.RELATIVE_TO_SELF, 0.5F);
    sa.setDuration(1000);
    view.startAnimation(sa);
}
 
Example 11
Source Project: Gallery   File: VersionDiffUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void scaleY(View view, float f) {
    if (view == null)
        return;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        view.setScaleY(f);
    } else {
        ScaleAnimation animation =new ScaleAnimation(f, f, f, f, 
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
        animation.setDuration(0);
        animation.setFillAfter(true);
        view.startAnimation(animation);
    }
}
 
Example 12
Source Project: 1Rramp-Android   File: ViewExpanderCollapser.java    License: MIT License 5 votes vote down vote up
public static void expand(final View v) {

    v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final int targetHeight = v.getMeasuredHeight();

    // Older versions of android (pre API 21) cancel animations for views with a height of 0.
    v.getLayoutParams().height = 1;
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
      @Override
      public boolean willChangeBounds() {
        return true;
      }      @Override
      protected void applyTransformation(float interpolatedTime, Transformation t) {
        v.getLayoutParams().height = interpolatedTime == 1
          ? ViewGroup.LayoutParams.WRAP_CONTENT
          : (int) (targetHeight * interpolatedTime);
        v.requestLayout();
      }


    };

    // 1dp/ms
    a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
    a.setInterpolator(new AccelerateInterpolator(3f));
    v.startAnimation(a);
  }
 
Example 13
private void setAnimation(View viewToAnimate, int position) {
    if (position > lastPosition) {
        Animation animation = AnimationUtils.loadAnimation(viewToAnimate.getContext(), R
                .anim.item_bottom_in);
        viewToAnimate.startAnimation(animation);
        lastPosition = position;
    }
}
 
Example 14
Source Project: TLint   File: AbstractShowState.java    License: Apache License 2.0 5 votes vote down vote up
protected void showViewById(int viewId, boolean animate) {
    View content = mFragmentView.findViewById(viewId);
    if (animate) {
        mAnimationIn.reset();
        content.startAnimation(mAnimationIn);
    } else {
        content.clearAnimation();
    }
    content.setVisibility(View.VISIBLE);
}
 
Example 15
Source Project: AndroidEmptyLayout   File: EmptyLayout.java    License: Apache License 2.0 4 votes vote down vote up
private void changeEmptyType() {

        setDefaultValues();
        refreshMessages();

        // insert views in the root view
        if (!mViewsAdded) {
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            lp.addRule(RelativeLayout.CENTER_IN_PARENT);
            mEmptyRelativeLayout = new RelativeLayout(getContext());
            mEmptyRelativeLayout.setGravity(Gravity.CENTER);
            mEmptyRelativeLayout.setLayoutParams(lp);
            if (mEmptyView!=null) mEmptyRelativeLayout.addView(mEmptyView);
            if (mLoadingView!=null) mEmptyRelativeLayout.addView(mLoadingView);
            if (mErrorView!=null) mEmptyRelativeLayout.addView(mErrorView);
            mViewsAdded = true;
            mEmptyRelativeLayout.setVisibility(VISIBLE);
            addView(mEmptyRelativeLayout);
        }


        // change empty type
            View loadingAnimationView = null;
            if (mLoadingAnimationViewId > 0) loadingAnimationView = findViewById(mLoadingAnimationViewId);
            switch (mEmptyType) {
                case TYPE_EMPTY:
                    if (mEmptyView!=null) mEmptyView.setVisibility(View.VISIBLE);
                    if (mErrorView!=null) mErrorView.setVisibility(View.GONE);
                    if (mLoadingView!=null) {
                        mLoadingView.setVisibility(View.GONE);
                        if (loadingAnimationView!=null && loadingAnimationView.getAnimation()!=null) loadingAnimationView.getAnimation().cancel();
                    }
                    break;
                case TYPE_ERROR:
                    if (mEmptyView!=null) mEmptyView.setVisibility(View.GONE);
                    if (mErrorView!=null) mErrorView.setVisibility(View.VISIBLE);
                    if (mLoadingView!=null) {
                        mLoadingView.setVisibility(View.GONE);
                        if (loadingAnimationView!=null && loadingAnimationView.getAnimation()!=null) loadingAnimationView.getAnimation().cancel();
                    }
                    break;
                case TYPE_LOADING:
                    if (mEmptyView!=null) mEmptyView.setVisibility(View.GONE);
                    if (mErrorView!=null) mErrorView.setVisibility(View.GONE);
                    if (mLoadingView!=null) {
                        mLoadingView.setVisibility(View.VISIBLE);
                        if (mLoadingAnimation != null && loadingAnimationView!=null) {
                            loadingAnimationView.startAnimation(mLoadingAnimation);
                        }
                        else if (loadingAnimationView!=null) {
                            loadingAnimationView.startAnimation(getRotateAnimation());
                        }
                    }
                    break;
                default:
                    break;
            }
    }
 
Example 16
Source Project: weather   File: ViewAnimation.java    License: Apache License 2.0 4 votes vote down vote up
public static void expand(final View v) {
  Animation a = expandAction(v);
  v.startAnimation(a);
}
 
Example 17
/**
 * Assign a "slide in from left" animation to the given view
 * @param view The view which we want to slide
 * @param duration the duration of the animation in milliseconds
 */
public static void setSlideInFromLeftAnimation(View view, long duration){
    Animation slide = AnimationUtils.loadAnimation(view.getContext(), R.anim.slide_in_from_left);
    slide.setDuration(duration);
    view.startAnimation(slide);
}
 
Example 18
Source Project: MongoExplorer   File: MultiPaneActivity.java    License: MIT License 4 votes vote down vote up
private void animateFromRightPaneOffscreen(View view) {
	Animation animation = new LeftMarginAnimation(view, mLeftPaneWidth, mScreenWidth+1);
	view.startAnimation(animation);
}
 
Example 19
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	SearchResult option = getItem(position);
	if (convertView == null) {
		convertView = LayoutInflater.from(getContext()).inflate(
				R.layout.search_option, parent, false);

		if (animate) {
			Animation anim = AnimationUtils.loadAnimation(context,
					R.anim.anim_down);
			anim.setDuration(400);
			convertView.startAnimation(anim);
			if (count == this.getCount()) {
				animate = false;
			}
			count++;
		}
	}

	View border = convertView.findViewById(R.id.border);
	if (position == 0) {
		border.setVisibility(View.VISIBLE);
	} else {
		border.setVisibility(View.GONE);
	}
	final TextView title = (TextView) convertView
			.findViewById(R.id.title);
	title.setText(option.title);
	ImageView icon = (ImageView) convertView.findViewById(R.id.icon);
	if (option.icon != null) {
		icon.setImageDrawable(option.icon);
	} else {
		icon.setImageResource(option.drawableResId);
	}
	ImageView up = (ImageView) convertView.findViewById(R.id.up);
	up.setOnClickListener(new OnClickListener() {

		@Override
		public void onClick(View v) {
			setSearchString(title.getText().toString());
			search.setSelection(search.getText().length());
		}

	});

	return convertView;
}
 
Example 20
private void setFadeAnimation(View view) {
    AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f);
    anim.setDuration(FADE_DURATION_MS);
    view.startAnimation(anim);
}