use of com.ramotion.foldingcell.animations.AnimationEndListener in project folding-cell-android by Ramotion.
the class FoldingCell method unfold.
/**
* Unfold cell with (or without) animation
*
* @param skipAnimation if true - change state of cell instantly without animation
*/
public void unfold(boolean skipAnimation) {
if (mUnfolded || mAnimationInProgress)
return;
if (skipAnimation) {
setStateToUnfolded();
return;
}
// get main content parts
final View contentView = getChildAt(0);
if (contentView == null)
return;
final View titleView = getChildAt(1);
if (titleView == null)
return;
// create layout container for animation elements
final LinearLayout foldingLayout = createAndPrepareFoldingContainer();
this.addView(foldingLayout);
// hide title and content views
titleView.setVisibility(GONE);
contentView.setVisibility(GONE);
// take bitmaps from title and content views
Bitmap bitmapFromTitleView = getBitmapFromView(titleView, this.getMeasuredWidth());
Bitmap bitmapFromContentView = getBitmapFromView(contentView, this.getMeasuredWidth());
// calculate heights of animation parts
ArrayList<Integer> heights = calculateHeightsForAnimationParts(titleView.getHeight(), contentView.getHeight(), mAdditionalFlipsCount);
// create list with animation parts for animation
ArrayList<FoldingCellView> foldingCellElements = prepareViewsForAnimation(heights, bitmapFromTitleView, bitmapFromContentView);
// start fold animation with end listener
int childCount = foldingCellElements.size();
int part90degreeAnimationDuration = mAnimationDuration / (childCount * 2);
startUnfoldAnimation(foldingCellElements, foldingLayout, part90degreeAnimationDuration, new AnimationEndListener() {
public void onAnimationEnd(Animation animation) {
contentView.setVisibility(VISIBLE);
foldingLayout.setVisibility(GONE);
FoldingCell.this.removeView(foldingLayout);
FoldingCell.this.mUnfolded = true;
FoldingCell.this.mAnimationInProgress = false;
}
});
startExpandHeightAnimation(heights, part90degreeAnimationDuration * 2);
this.mAnimationInProgress = true;
}
use of com.ramotion.foldingcell.animations.AnimationEndListener in project folding-cell-android by Ramotion.
the class FoldingCell method createAnimationChain.
/**
* Create "animation chain" for selected view from list of animations objects
*
* @param animationList collection with animations
* @param animationObject view for animations
*/
protected void createAnimationChain(final List<Animation> animationList, final View animationObject) {
for (int i = 0; i < animationList.size(); i++) {
Animation animation = animationList.get(i);
if (i + 1 < animationList.size()) {
final int finalI = i;
animation.setAnimationListener(new AnimationEndListener() {
public void onAnimationEnd(Animation animation) {
animationObject.startAnimation(animationList.get(finalI + 1));
}
});
}
}
}
use of com.ramotion.foldingcell.animations.AnimationEndListener in project folding-cell-android by Ramotion.
the class FoldingCell method fold.
/**
* Fold cell with (or without) animation
*
* @param skipAnimation if true - change state of cell instantly without animation
*/
public void fold(boolean skipAnimation) {
if (!mUnfolded || mAnimationInProgress)
return;
if (skipAnimation) {
setStateToFolded();
return;
}
// get basic views
final View contentView = getChildAt(0);
if (contentView == null)
return;
final View titleView = getChildAt(1);
if (titleView == null)
return;
// create empty layout for folding animation
final LinearLayout foldingLayout = createAndPrepareFoldingContainer();
// add that layout to structure
this.addView(foldingLayout);
// make bitmaps from title and content views
Bitmap bitmapFromTitleView = getBitmapFromView(titleView, this.getMeasuredWidth());
Bitmap bitmapFromContentView = getBitmapFromView(contentView, this.getMeasuredWidth());
// hide title and content views
titleView.setVisibility(GONE);
contentView.setVisibility(GONE);
// calculate heights of animation parts
ArrayList<Integer> heights = calculateHeightsForAnimationParts(titleView.getHeight(), contentView.getHeight(), mAdditionalFlipsCount);
// create list with animation parts for animation
ArrayList<FoldingCellView> foldingCellElements = prepareViewsForAnimation(heights, bitmapFromTitleView, bitmapFromContentView);
int childCount = foldingCellElements.size();
int part90degreeAnimationDuration = mAnimationDuration / (childCount * 2);
// start fold animation with end listener
startFoldAnimation(foldingCellElements, foldingLayout, part90degreeAnimationDuration, new AnimationEndListener() {
@Override
public void onAnimationEnd(Animation animation) {
contentView.setVisibility(GONE);
titleView.setVisibility(VISIBLE);
foldingLayout.setVisibility(GONE);
FoldingCell.this.removeView(foldingLayout);
FoldingCell.this.mAnimationInProgress = false;
FoldingCell.this.mUnfolded = false;
}
});
startCollapseHeightAnimation(heights, part90degreeAnimationDuration * 2);
this.mAnimationInProgress = true;
}
Aggregations