Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed "checked" field in class #13

Merged
merged 1 commit into from
Mar 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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