diff options
author | Jeff Sharkey <jsharkey@android.com> | 2011-08-30 19:59:36 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2011-08-30 20:00:51 -0700 |
commit | 7a7ea2bf2f8d0760cc3f6768b6b4bb0f6f7f0d7d (patch) | |
tree | 3d058685b2cb376691dd1e4cb82015c1d550e89c /src/com/android/settings/widget | |
parent | 9ca0ef5732d2d25f367b5fa01e8b6562f82d788d (diff) | |
download | packages_apps_Settings-7a7ea2bf2f8d0760cc3f6768b6b4bb0f6f7f0d7d.zip packages_apps_Settings-7a7ea2bf2f8d0760cc3f6768b6b4bb0f6f7f0d7d.tar.gz packages_apps_Settings-7a7ea2bf2f8d0760cc3f6768b6b4bb0f6f7f0d7d.tar.bz2 |
Sync asset drop and smoother animation.
Bug: 5233703
Change-Id: I3fa52da71b78dcfa7842047b427c5121d3ac7e68
Diffstat (limited to 'src/com/android/settings/widget')
-rw-r--r-- | src/com/android/settings/widget/AnimatedImageView.java | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/com/android/settings/widget/AnimatedImageView.java b/src/com/android/settings/widget/AnimatedImageView.java new file mode 100644 index 0000000..671d718 --- /dev/null +++ b/src/com/android/settings/widget/AnimatedImageView.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.widget; + +import android.content.Context; +import android.graphics.drawable.AnimatedRotateDrawable; +import android.graphics.drawable.Drawable; +import android.util.AttributeSet; +import android.view.View; +import android.widget.ImageView; + +public class AnimatedImageView extends ImageView { + private AnimatedRotateDrawable mDrawable; + private boolean mAnimating; + + public AnimatedImageView(Context context) { + super(context); + } + + public AnimatedImageView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + private void updateDrawable() { + if (isShown() && mDrawable != null) { + mDrawable.stop(); + } + final Drawable drawable = getDrawable(); + if (drawable instanceof AnimatedRotateDrawable) { + mDrawable = (AnimatedRotateDrawable) drawable; + // TODO: define in drawable xml once we have public attrs. + mDrawable.setFramesCount(56); + mDrawable.setFramesDuration(32); + if (isShown() && mAnimating) { + mDrawable.start(); + } + } else { + mDrawable = null; + } + } + + private void updateAnimating() { + if (mDrawable != null) { + if (isShown() && mAnimating) { + mDrawable.start(); + } else { + mDrawable.stop(); + } + } + } + + @Override + public void setImageDrawable(Drawable drawable) { + super.setImageDrawable(drawable); + updateDrawable(); + } + + @Override + public void setImageResource(int resid) { + super.setImageResource(resid); + updateDrawable(); + } + + @Override + public void onAttachedToWindow() { + super.onAttachedToWindow(); + updateAnimating(); + } + + @Override + public void onDetachedFromWindow() { + super.onDetachedFromWindow(); + updateAnimating(); + } + + public void setAnimating(boolean animating) { + mAnimating = animating; + updateAnimating(); + } + + @Override + protected void onVisibilityChanged(View changedView, int vis) { + super.onVisibilityChanged(changedView, vis); + updateAnimating(); + } +} |