Skip to content

Commit

Permalink
Merge pull request #13 from etibaldi/feature/fix_checked
Browse files Browse the repository at this point in the history
Removed "checked" field in class
  • Loading branch information
davideas authored Mar 7, 2017
2 parents d3d0d49 + b11da54 commit 0d39054
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions flipview/src/main/java/eu/davidea/flipview/FlipView.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ public void onFlipped(FlipView flipView, boolean checked) {
/**
* Animations attributes
*/
private boolean checked;
private static boolean enableInitialAnimation = true;
private Animation initialLayoutAnimation;
private Animation rearImageAnimation;
Expand Down Expand Up @@ -208,7 +207,7 @@ private void init(AttributeSet attrs) {
TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.FlipView, 0, 0);

// Flags
checked = a.getBoolean(R.styleable.FlipView_checked, false);
boolean checked = a.getBoolean(R.styleable.FlipView_checked, false);
boolean startupAnimation = a.getBoolean(R.styleable.FlipView_enableInitialAnimation, false);
boolean animateDesignChildViewsOnly = a.getBoolean(R.styleable.FlipView_animateDesignLayoutOnly, false);

Expand Down Expand Up @@ -661,7 +660,7 @@ public final void showPrevious(long delay) {
}

public boolean isFlipped() {
return checked;
return getDisplayedChild() > FRONT_VIEW_INDEX;
}

/**
Expand Down Expand Up @@ -703,27 +702,27 @@ public final void flip(final int whichChild, @IntRange(from = 0) long delay) {
if (DEBUG) Log.w(TAG, "Can't flip while view is disabled");
return;
}
final int childIndex = checkIndex(whichChild);
if (DEBUG) {
Log.d(TAG, "Flip! whichChild=" + whichChild + ", previousChild=" + getDisplayedChild() + ", delay=" + delay);
Log.d(TAG, "Flip! whichChild=" + childIndex + ", previousChild=" + getDisplayedChild() + ", delay=" + delay);
}
// Issue #7 - Don't flip if the target child is the one currently displayed
if (whichChild == getDisplayedChild()) {
if (childIndex == getDisplayedChild()) {
if (DEBUG) Log.w(TAG, "Already flipped to same whichChild=" + whichChild);
return;
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
checked = (whichChild == FRONT_VIEW_INDEX || getDisplayedChild() == FRONT_VIEW_INDEX); //It's tricky!
setDisplayedChild(whichChild); //Start main animation
setDisplayedChild(childIndex); //Start main animation
animateRearImageIfNeeded();
mFlippingListener.onFlipped(FlipView.this, checked);
mFlippingListener.onFlipped(FlipView.this, isFlipped());
}
}, delay);
}

private void animateRearImageIfNeeded() {
if (checked && rearImage != null && rearImageAnimation != null) {
if (isFlipped() && rearImage != null && rearImageAnimation != null) {
rearImage.setAlpha(0f); //Alpha 0 and Handler are needed to avoid the glitch of the rear image
new Handler().postDelayed(new Runnable() {
@Override
Expand Down Expand Up @@ -759,7 +758,6 @@ public final void flipSilently(int whichChild) {
Animation outAnimation = super.getOutAnimation();
super.setInAnimation(null);
super.setOutAnimation(null);
checked = (whichChild > FRONT_VIEW_INDEX);
super.setDisplayedChild(whichChild);
super.setInAnimation(inAnimation);
super.setOutAnimation(outAnimation);
Expand Down

0 comments on commit 0d39054

Please sign in to comment.