Add alpha animation for ImageView
This commit is contained in:
1 parent
5463aba10e
commit
3575c856b4
5 files changed
+45
-10
No files matched your search
@@ -20,6 +20,8 @@ import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.support.annotation.IntDef;
|
||||
|
||||
import com.hippo.anani.AnimationUtils;
|
||||
import com.hippo.gl.anim.AlphaAnimation;
|
||||
import com.hippo.gl.glrenderer.GLCanvas;
|
||||
import com.hippo.gl.glrenderer.Texture;
|
||||
import com.hippo.gl.view.GLView;
|
||||
@@ -56,6 +58,8 @@ public class ImageView extends GLView {
|
||||
public static final int START_POSITION_BOTTOM_RIGHT = 3;
|
||||
public static final int START_POSITION_CENTER = 4;
|
||||
|
||||
private static final long ALPHA_ANIMATION_DURING = 300L;
|
||||
|
||||
private Texture mTexture;
|
||||
private int mTextureWidth;
|
||||
private int mTextureHeight;
|
||||
@@ -74,6 +78,14 @@ public class ImageView extends GLView {
|
||||
private boolean mScaleOffsetDirty = true;
|
||||
private boolean mPositionInRootDirty = true;
|
||||
|
||||
private final AlphaAnimation mAlphaAnimation;
|
||||
|
||||
public ImageView() {
|
||||
mAlphaAnimation = new AlphaAnimation(0.0f, 1.0f);
|
||||
mAlphaAnimation.setDuration(ALPHA_ANIMATION_DURING);
|
||||
mAlphaAnimation.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR);
|
||||
}
|
||||
|
||||
@Scale
|
||||
public static int sanitizeScaleMode(int scaleMode) {
|
||||
if (scaleMode != SCALE_ORIGIN &&
|
||||
@@ -193,6 +205,11 @@ public class ImageView extends GLView {
|
||||
if (mTextureHeight <= 0) {
|
||||
mTextureHeight = 1;
|
||||
}
|
||||
|
||||
// Start alpha animation
|
||||
if (isAttachedToRoot()) {
|
||||
startAnimation(mAlphaAnimation, true);
|
||||
}
|
||||
} else {
|
||||
mTextureWidth = 1;
|
||||
mTextureHeight = 1;
|
||||
|
||||
@@ -361,20 +361,20 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
|
||||
// Ensure pages
|
||||
if (mCurrent == null) {
|
||||
mCurrent = obtainPage();
|
||||
adapter.bind(mCurrent, index);
|
||||
galleryView.addComponent(mCurrent);
|
||||
adapter.bind(mCurrent, index);
|
||||
}
|
||||
if (mPrevious == null && index > 0) {
|
||||
mPrevious = obtainPage();
|
||||
adapter.bind(mPrevious, index - 1);
|
||||
galleryView.addComponent(mPrevious);
|
||||
adapter.bind(mPrevious, index - 1);
|
||||
} else if (mPrevious != null && index == 0) {
|
||||
removePage(mPrevious);
|
||||
}
|
||||
if (mNext == null && index < size - 1) {
|
||||
mNext = obtainPage();
|
||||
adapter.bind(mNext, index + 1);
|
||||
galleryView.addComponent(mNext);
|
||||
adapter.bind(mNext, index + 1);
|
||||
} else if (mNext != null && index == size - 1) {
|
||||
removePage(mNext);
|
||||
}
|
||||
@@ -480,8 +480,8 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
|
||||
|
||||
if (mIndex > 0) {
|
||||
mPrevious = obtainPage();
|
||||
mAdapter.bind(mPrevious, mIndex - 1);
|
||||
mGalleryView.addComponent(mPrevious);
|
||||
mAdapter.bind(mPrevious, mIndex - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -502,8 +502,8 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
|
||||
|
||||
if (mIndex < size - 1) {
|
||||
mNext = obtainPage();
|
||||
adapter.bind(mNext, mIndex + 1);
|
||||
mGalleryView.addComponent(mNext);
|
||||
adapter.bind(mNext, mIndex + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -192,8 +192,8 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
|
||||
mIndex--;
|
||||
|
||||
GalleryPageView page = obtainPage();
|
||||
mAdapter.bind(page, mIndex);
|
||||
galleryView.addComponent(page);
|
||||
mAdapter.bind(page, mIndex);
|
||||
mPages.add(0, page);
|
||||
|
||||
// Add interval
|
||||
@@ -239,8 +239,8 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
|
||||
pages = null;
|
||||
// New page
|
||||
page = obtainPage();
|
||||
mAdapter.bind(page, index);
|
||||
galleryView.addComponent(page);
|
||||
mAdapter.bind(page, index);
|
||||
mPages.add(page);
|
||||
} else {
|
||||
page = pages.next();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.hippo.gl.glrenderer;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.opengl.GLES20;
|
||||
@@ -838,9 +839,11 @@ public class GLES20Canvas implements GLCanvas {
|
||||
setAlpha(textureAlpha);
|
||||
drawTexture(texture, source, target);
|
||||
|
||||
float colorAlpha = cappedRatio * currentAlpha;
|
||||
setAlpha(colorAlpha);
|
||||
fillRect(target.left, target.top, target.width(), target.height(), toColor);
|
||||
if (0 != Color.alpha(toColor)) {
|
||||
float colorAlpha = cappedRatio * currentAlpha;
|
||||
setAlpha(colorAlpha);
|
||||
fillRect(target.left, target.top, target.width(), target.height(), toColor);
|
||||
}
|
||||
|
||||
restore();
|
||||
}
|
||||
|
||||
@@ -153,6 +153,21 @@ public class GLView implements TouchOwner {
|
||||
private OnClickListener mOnClickListener;
|
||||
private OnLongClickListener mOnLongClickListener;
|
||||
|
||||
public void startAnimation(CanvasAnimation animation, boolean atOnce) {
|
||||
GLRoot root = getGLRoot();
|
||||
if (root == null) throw new IllegalStateException();
|
||||
mAnimation = animation;
|
||||
if (mAnimation != null) {
|
||||
mAnimation.start();
|
||||
if (atOnce) {
|
||||
mAnimation.setStartTime(AnimationTime.get());
|
||||
} else {
|
||||
root.registerLaunchedAnimation(mAnimation);
|
||||
}
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the enabled state of this view.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user