Created
November 23, 2017 05:36
-
-
Save nekocode/1442bbc6b43c6128b3abcef007f170e8 to your computer and use it in GitHub Desktop.
Draw animatable drawable to view.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class LoadingView extends View { | |
| private CircularProgressDrawable mDrawable; | |
| public LoadingView(Context pContext) { | |
| super(pContext); | |
| init(); | |
| } | |
| public LoadingView(Context pContext, AttributeSet pAttributeSet) { | |
| super(pContext, pAttributeSet); | |
| init(); | |
| } | |
| public LoadingView(Context pContext, AttributeSet pAttributeSet, int pDefaultStyle) { | |
| super(pContext, pAttributeSet, pDefaultStyle); | |
| init(); | |
| } | |
| private void init() { | |
| mDrawable = new CircularProgressDrawable(getContext()); | |
| mDrawable.setStyle(CircularProgressDrawable.DEFAULT); | |
| mDrawable.setCallback(this); | |
| } | |
| @Override | |
| protected void onVisibilityChanged(View changedView, int visibility) { | |
| super.onVisibilityChanged(changedView, visibility); | |
| if (visibility == VISIBLE) { | |
| mDrawable.start(); | |
| } else { | |
| mDrawable.stop(); | |
| } | |
| } | |
| @Override | |
| protected void onSizeChanged(int w, int h, int oldw, int oldh) { | |
| super.onSizeChanged(w, h, oldw, oldh); | |
| mDrawable.setBounds(0, 0, w, h); | |
| } | |
| @Override | |
| public void draw(Canvas canvas) { | |
| super.draw(canvas); | |
| mDrawable.draw(canvas); | |
| } | |
| @Override | |
| protected boolean verifyDrawable(@NonNull Drawable who) { | |
| return who == mDrawable || super.verifyDrawable(who); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment