Use my own reveal stuff
This commit is contained in:
1 parent
e6367055fb
commit
19ebd4c28f
10 files changed
+229
-774
No files matched your search
@@ -38,6 +38,7 @@ import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.reveal.ViewAnimationUtils;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.LinearDividerItemDecoration;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
@@ -63,9 +64,6 @@ import com.hippo.yorozuya.LayoutUtils;
|
||||
import com.hippo.yorozuya.SimpleAnimatorListener;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import io.codetail.animation.SupportAnimator;
|
||||
import io.codetail.animation.ViewAnimationUtils;
|
||||
|
||||
public final class GalleryCommentsScene extends ToolbarScene
|
||||
implements EasyRecyclerView.OnItemClickListener,
|
||||
EasyRecyclerView.OnItemLongClickListener, View.OnClickListener {
|
||||
@@ -276,12 +274,11 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
mEditPanel.setVisibility(View.VISIBLE);
|
||||
int halfW = mEditPanel.getWidth() / 2;
|
||||
int halfH = mEditPanel.getHeight() / 2;
|
||||
SupportAnimator animator = ViewAnimationUtils.createCircularReveal(mEditPanel, halfW, halfH, 0,
|
||||
(float) Math.hypot(halfW, halfH));
|
||||
animator.setDuration(300L);
|
||||
animator.addListener(new SupportAnimator.SimpleAnimatorListener() {
|
||||
Animator animator = ViewAnimationUtils.createCircularReveal(mEditPanel, halfW, halfH, 0,
|
||||
(float) Math.hypot(halfW, halfH)).setDuration(300L);
|
||||
animator.addListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationEnd() {
|
||||
public void onAnimationEnd(Animator a) {
|
||||
mInAnimation = false;
|
||||
}
|
||||
});
|
||||
@@ -311,12 +308,11 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
mInAnimation = true;
|
||||
int halfW = mEditPanel.getWidth() / 2;
|
||||
int halfH = mEditPanel.getHeight() / 2;
|
||||
SupportAnimator animator = ViewAnimationUtils.createCircularReveal(mEditPanel, halfW, halfH,
|
||||
(float) Math.hypot(halfW, halfH), 0.0f);
|
||||
animator.setDuration(300L);
|
||||
animator.addListener(new SupportAnimator.SimpleAnimatorListener() {
|
||||
Animator animator = ViewAnimationUtils.createCircularReveal(mEditPanel, halfW, halfH,
|
||||
(float) Math.hypot(halfW, halfH), 0.0f).setDuration(300L);
|
||||
animator.addListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationEnd() {
|
||||
public void onAnimationEnd(Animator a) {
|
||||
mEditPanel.setVisibility(View.GONE);
|
||||
mFab.setVisibility(View.VISIBLE);
|
||||
int fabStartX = mEditPanel.getLeft() + (mEditPanel.getWidth() / 2) - (mFab.getWidth() / 2);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* 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.hippo.reveal;
|
||||
|
||||
public interface Reveal {
|
||||
|
||||
void setRevealEnable(boolean enable);
|
||||
|
||||
void setReveal(int centerX, int centerY, float radius);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* 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.hippo.reveal;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Path;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
public class RevealLinearLayout extends LinearLayout implements Reveal {
|
||||
|
||||
private final Path mRevealPath = new Path();
|
||||
private boolean mReveal;
|
||||
private int mCenterX;
|
||||
private int mCenterY;
|
||||
private float mRadius;
|
||||
|
||||
public RevealLinearLayout(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public RevealLinearLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public RevealLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (!ViewAnimationUtils.API_SUPPORT_CIRCULAR_REVEAL) {
|
||||
setWillNotDraw(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRevealEnable(boolean enable) {
|
||||
mReveal = enable;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReveal(int centerX, int centerY, float radius) {
|
||||
mCenterX = centerX;
|
||||
mCenterY = centerY;
|
||||
mRadius = radius;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
boolean reveal = mReveal;
|
||||
int saveCount = 0;
|
||||
|
||||
if (reveal) {
|
||||
saveCount = canvas.save();
|
||||
Path path = mRevealPath;
|
||||
path.reset();
|
||||
path.addCircle(mCenterX, mCenterY, mRadius, Path.Direction.CW);
|
||||
canvas.clipPath(path);
|
||||
}
|
||||
|
||||
super.draw(canvas);
|
||||
|
||||
if (reveal) {
|
||||
canvas.restoreToCount(saveCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* 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.hippo.reveal;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.TargetApi;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.yorozuya.SimpleAnimatorListener;
|
||||
|
||||
public final class ViewAnimationUtils {
|
||||
private ViewAnimationUtils() {}
|
||||
|
||||
public static final boolean API_SUPPORT_CIRCULAR_REVEAL =
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
||||
// http://developer.android.com/guide/topics/graphics/hardware-accel.html#unsupported
|
||||
public static final boolean API_SUPPORT_CANVAS_CLIP_PATH =
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public static Animator createCircularReveal(View view,
|
||||
int centerX, int centerY, float startRadius, float endRadius) {
|
||||
if (API_SUPPORT_CIRCULAR_REVEAL) {
|
||||
return android.view.ViewAnimationUtils.createCircularReveal(
|
||||
view, centerX, centerY, startRadius, endRadius);
|
||||
} else if (view instanceof Reveal){
|
||||
return createRevealAnimator((Reveal) view, centerX, centerY,
|
||||
startRadius, endRadius);
|
||||
} else {
|
||||
throw new IllegalStateException("Only View implements CircularReveal or" +
|
||||
" api >= 21 can create circular reveal");
|
||||
}
|
||||
}
|
||||
|
||||
private static Animator createRevealAnimator(Reveal reveal, int centerX, int centerY,
|
||||
float startRadius, float endRadius) {
|
||||
ValueAnimator animator = ValueAnimator.ofFloat(startRadius, endRadius);
|
||||
animator.addUpdateListener(new RevealAnimatorUpdateListener(reveal, centerX, centerY));
|
||||
animator.addListener(new RevealAnimatorListener(reveal));
|
||||
return animator;
|
||||
}
|
||||
|
||||
private static class RevealAnimatorUpdateListener
|
||||
implements ValueAnimator.AnimatorUpdateListener {
|
||||
|
||||
private final Reveal mReveal;
|
||||
private final int mCenterX;
|
||||
private final int mCenterY;
|
||||
|
||||
public RevealAnimatorUpdateListener(Reveal reveal, int centerX, int centerY) {
|
||||
mReveal = reveal;
|
||||
mCenterX = centerX;
|
||||
mCenterY = centerY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
Object value = animation.getAnimatedValue();
|
||||
if (value instanceof Float) {
|
||||
mReveal.setReveal(mCenterX, mCenterY, (Float) value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class RevealAnimatorListener extends SimpleAnimatorListener {
|
||||
|
||||
private final Reveal mReveal;
|
||||
private final View mView;
|
||||
|
||||
public RevealAnimatorListener(Reveal reveal) {
|
||||
mReveal = reveal;
|
||||
mView = (View) reveal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
if (!API_SUPPORT_CANVAS_CLIP_PATH) {
|
||||
mView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
}
|
||||
mReveal.setRevealEnable(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mReveal.setRevealEnable(false);
|
||||
if (!API_SUPPORT_CANVAS_CLIP_PATH) {
|
||||
mView.setLayerType(View.LAYER_TYPE_NONE, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user