use of com.ramotion.foldingcell.views.FoldingCellView 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.views.FoldingCellView in project folding-cell-android by Ramotion.
the class FoldingCell method prepareViewsForAnimation.
/**
* Create and prepare list of FoldingCellViews with different bitmap parts for fold animation
*
* @param titleViewBitmap bitmap from title view
* @param contentViewBitmap bitmap from content view
* @return list of FoldingCellViews with bitmap parts
*/
protected ArrayList<FoldingCellView> prepareViewsForAnimation(ArrayList<Integer> viewHeights, Bitmap titleViewBitmap, Bitmap contentViewBitmap) {
if (viewHeights == null || viewHeights.isEmpty())
throw new IllegalStateException("ViewHeights array must be not null and not empty");
ArrayList<FoldingCellView> partsList = new ArrayList<>();
int partWidth = titleViewBitmap.getWidth();
int yOffset = 0;
for (int i = 0; i < viewHeights.size(); i++) {
int partHeight = viewHeights.get(i);
Bitmap partBitmap = Bitmap.createBitmap(partWidth, partHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(partBitmap);
Rect srcRect = new Rect(0, yOffset, partWidth, yOffset + partHeight);
Rect destRect = new Rect(0, 0, partWidth, partHeight);
canvas.drawBitmap(contentViewBitmap, srcRect, destRect, null);
ImageView backView = createImageViewFromBitmap(partBitmap);
ImageView frontView = null;
if (i < viewHeights.size() - 1) {
frontView = (i == 0) ? createImageViewFromBitmap(titleViewBitmap) : createBackSideView(viewHeights.get(i + 1));
}
partsList.add(new FoldingCellView(frontView, backView, getContext()));
yOffset = yOffset + partHeight;
}
return partsList;
}
use of com.ramotion.foldingcell.views.FoldingCellView in project folding-cell-android by Ramotion.
the class FoldingCell method startFoldAnimation.
/**
* Start fold animation
*
* @param foldingCellElements ordered list with animation parts from top to bottom
* @param foldingLayout prepared layout for animation parts
* @param part90degreeAnimationDuration animation duration for 90 degree rotation
* @param animationEndListener animation end callback
*/
protected void startFoldAnimation(ArrayList<FoldingCellView> foldingCellElements, ViewGroup foldingLayout, int part90degreeAnimationDuration, AnimationEndListener animationEndListener) {
for (FoldingCellView foldingCellElement : foldingCellElements) foldingLayout.addView(foldingCellElement);
Collections.reverse(foldingCellElements);
int nextDelay = 0;
for (int i = 0; i < foldingCellElements.size(); i++) {
FoldingCellView cell = foldingCellElements.get(i);
cell.setVisibility(VISIBLE);
// not FIRST(BOTTOM) element - animate front view
if (i != 0) {
FoldAnimation foldAnimation = new FoldAnimation(FoldAnimation.FoldAnimationMode.UNFOLD_UP, mCameraHeight, part90degreeAnimationDuration).withStartOffset(nextDelay).withInterpolator(new DecelerateInterpolator());
// if last(top) element - add end listener
if (i == foldingCellElements.size() - 1) {
foldAnimation.setAnimationListener(animationEndListener);
}
cell.animateFrontView(foldAnimation);
nextDelay = nextDelay + part90degreeAnimationDuration;
}
// if not last(top) element - animate whole view
if (i != foldingCellElements.size() - 1) {
cell.startAnimation(new FoldAnimation(FoldAnimation.FoldAnimationMode.FOLD_UP, mCameraHeight, part90degreeAnimationDuration).withStartOffset(nextDelay).withInterpolator(new DecelerateInterpolator()));
nextDelay = nextDelay + part90degreeAnimationDuration;
}
}
}
use of com.ramotion.foldingcell.views.FoldingCellView in project folding-cell-android by Ramotion.
the class FoldingCell method startUnfoldAnimation.
/**
* Start unfold animation
*
* @param foldingCellElements ordered list with animation parts from top to bottom
* @param foldingLayout prepared layout for animation parts
* @param part90degreeAnimationDuration animation duration for 90 degree rotation
* @param animationEndListener animation end callback
*/
protected void startUnfoldAnimation(ArrayList<FoldingCellView> foldingCellElements, ViewGroup foldingLayout, int part90degreeAnimationDuration, AnimationEndListener animationEndListener) {
int nextDelay = 0;
for (int i = 0; i < foldingCellElements.size(); i++) {
FoldingCellView cell = foldingCellElements.get(i);
cell.setVisibility(VISIBLE);
foldingLayout.addView(cell);
// if not first(top) element - animate whole view
if (i != 0) {
FoldAnimation foldAnimation = new FoldAnimation(FoldAnimation.FoldAnimationMode.UNFOLD_DOWN, mCameraHeight, part90degreeAnimationDuration).withStartOffset(nextDelay).withInterpolator(new DecelerateInterpolator());
// if last(bottom) element - add end listener
if (i == foldingCellElements.size() - 1) {
foldAnimation.setAnimationListener(animationEndListener);
}
nextDelay = nextDelay + part90degreeAnimationDuration;
cell.startAnimation(foldAnimation);
}
// not last(bottom) element - animate front view
if (i != foldingCellElements.size() - 1) {
cell.animateFrontView(new FoldAnimation(FoldAnimation.FoldAnimationMode.FOLD_DOWN, mCameraHeight, part90degreeAnimationDuration).withStartOffset(nextDelay).withInterpolator(new DecelerateInterpolator()));
nextDelay = nextDelay + part90degreeAnimationDuration;
}
}
}
use of com.ramotion.foldingcell.views.FoldingCellView 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