Skip to content

Commit

Permalink
Handle view restoring its state
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibolte committed Aug 7, 2015
1 parent ed6373d commit 85bdae6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.ViewTreeObserver;
Expand Down Expand Up @@ -65,6 +66,14 @@ public void onGlobalLayout() {
});
}

@Override
public void onRestoreInstanceState(Parcelable state) {
super.onRestoreInstanceState(state);

mIntroView.init();
mIntroView.setVisibility(VISIBLE);
}

/**
* MARK: Public methods
*/
Expand Down
22 changes: 16 additions & 6 deletions elasticdownload/src/main/java/is/arontibo/library/IntroView.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ public interface EnterAnimationListener {

public IntroView(Context context, AttributeSet attrs) {
super(context, attrs);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setImageResource(R.drawable.avd_start);
} else {
AnimatedVectorDrawable drawable = AnimatedVectorDrawable.getDrawable(context, R.drawable.avd_start);
setImageDrawable(drawable);
}
init();
}

/**
Expand All @@ -50,6 +45,21 @@ public void setListener(EnterAnimationListener listener) {
* MARK: Public functions
*/

public void init() {
// Reset the image view drawable if needed, we use the transparent color to remove it
setImageResource(android.R.color.transparent);

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setImageResource(R.drawable.avd_start);

Drawable drawable = getDrawable();
drawable.invalidateSelf();
} else {
AnimatedVectorDrawable drawable = AnimatedVectorDrawable.getDrawable(getContext(), R.drawable.avd_start);
setImageDrawable(drawable);
}
}

public void startAnimation() {

Drawable drawable = getDrawable();
Expand Down

0 comments on commit 85bdae6

Please sign in to comment.