Skip to content

Commit

Permalink
#8 #7 #6 #2 Support Exit Animations
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-peiming committed Feb 23, 2023
1 parent d620116 commit 2c46e94
Show file tree
Hide file tree
Showing 22 changed files with 614 additions and 407 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.wangpm.enteranimation"
minSdkVersion 19
targetSdkVersion 33
versionCode 1
versionName "1.0"
versionCode 2
versionName "2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AnimActivity"
>
</activity>
</application>

</manifest>
11 changes: 8 additions & 3 deletions app/src/main/java/anim/Anim.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package anim;

import android.graphics.Canvas;
import android.view.View;
import android.util.Log;

import com.wangpm.enteranimation.EnterAnimLayout;

Expand All @@ -13,23 +13,28 @@ public abstract class Anim {
protected float w;
protected float h;
public float totalPaintTime;//控制绘制时间
public boolean isExitAnim = false;

public Anim(EnterAnimLayout view) {
this(view,2000);
}

public Anim(EnterAnimLayout view, float totalPaintTime) {
this(view, totalPaintTime, false);
}

public Anim(EnterAnimLayout view, float totalPaintTime, boolean isExitAnim) {
this.totalPaintTime = totalPaintTime;
this.view = view;
this.view.setAnim(this);
w = view.getWidth();
h = view.getHeight();
this.isExitAnim = isExitAnim;
}

public void startAnimation() {
view.setmIsAnimaionRun(true);
view.setIsAnimationRun(true);
view.setStartTime(System.currentTimeMillis());

view.invalidate();
}
public void startAnimation(long animTime) {
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/anim/AnimBaiYeChuang.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public void handleCanvas(Canvas canvas, float rate) {
float bottom = top + h / lines * rate;
path.addRect(0, top, w, bottom, Path.Direction.CW);
}
canvas.clipPath(path);
if(isExitAnim) {
canvas.clipPath(path, Region.Op.DIFFERENCE);
}else{
canvas.clipPath(path);
}
canvas.save();
}
}
8 changes: 6 additions & 2 deletions app/src/main/java/anim/AnimCaChu.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package anim;

import android.graphics.Canvas;
import android.graphics.Region;
import android.view.View;

import com.wangpm.enteranimation.EnterAnimLayout;
Expand All @@ -18,8 +19,11 @@ public AnimCaChu(EnterAnimLayout view) {
public void handleCanvas(Canvas canvas, float rate) {
float rectTop = (h - h * rate);
//剪切当前需要展示区域的左上右下
canvas.clipRect(0, rectTop, w, h);

if(isExitAnim) {
canvas.clipRect(0, rectTop, w, h, Region.Op.DIFFERENCE);
}else{
canvas.clipRect(0, rectTop, w, h);
}
canvas.save();
}
}
7 changes: 5 additions & 2 deletions app/src/main/java/anim/AnimHeZhuang.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ public void handleCanvas(Canvas canvas, float rate) {
float rectBottom = h - rectTop;

//剪切需要展示的区域
canvas.clipRect(rectLeft, rectTop,rectRight , rectBottom, Region.Op.DIFFERENCE);

if(isExitAnim) {
canvas.clipRect(rectLeft, rectTop,rectRight , rectBottom);
}else{
canvas.clipRect(rectLeft, rectTop,rectRight , rectBottom, Region.Op.DIFFERENCE);
}
canvas.save();
}
}
7 changes: 5 additions & 2 deletions app/src/main/java/anim/AnimJieTi.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ public void handleCanvas(Canvas canvas, float rate) {
float bottom = top + h / lineNum;
path.addRect(left,top,right,bottom, Path.Direction.CW);
}
canvas.clipPath(path);

if(isExitAnim) {
canvas.clipPath(path, Region.Op.DIFFERENCE);
}else{
canvas.clipPath(path);
}
canvas.save();
}
}
7 changes: 5 additions & 2 deletions app/src/main/java/anim/AnimLingXing.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ public void handleCanvas(Canvas canvas, float rate) {
path1.lineTo(w/2, h+h/2 - h*rate);
path1.lineTo(w+w/2 -w*rate, h/2);
path1.close();//封闭
canvas.clipPath(path1, Region.Op.DIFFERENCE);

if(isExitAnim) {
canvas.clipPath(path1);
}else{
canvas.clipPath(path1, Region.Op.DIFFERENCE);
}
canvas.save();
}
}
7 changes: 5 additions & 2 deletions app/src/main/java/anim/AnimLunZi.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ public void handleCanvas(Canvas canvas, float rate) {
path1.addArc(oval,270,360*rate);
path1.lineTo(w/2,h/2);
path1.close();//封闭
canvas.clipPath(path1);

if(isExitAnim) {
canvas.clipPath(path1, Region.Op.DIFFERENCE);
}else{
canvas.clipPath(path1);
}
canvas.save();
}
}
6 changes: 5 additions & 1 deletion app/src/main/java/anim/AnimPiLie.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public AnimPiLie(EnterAnimLayout view) {
public void handleCanvas(Canvas canvas, float rate) {
float rectLeft = w / 2 * rate;
float rectRight = w - w / 2 * rate;
canvas.clipRect(rectLeft, 0, rectRight, h, Region.Op.DIFFERENCE);
if(isExitAnim) {
canvas.clipRect(rectLeft, 0, rectRight, h);
}else{
canvas.clipRect(rectLeft, 0, rectRight, h, Region.Op.DIFFERENCE);
}
canvas.save();
}
}
6 changes: 5 additions & 1 deletion app/src/main/java/anim/AnimQiPan.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public void handleCanvas(Canvas canvas, float rate) {
path.addRect(left, top,right,bottom, Path.Direction.CW);
}
}
canvas.clipPath(path);
if(isExitAnim) {
canvas.clipPath(path, Region.Op.DIFFERENCE);
}else{
canvas.clipPath(path);
}
canvas.save();
}
}
8 changes: 5 additions & 3 deletions app/src/main/java/anim/AnimQieRu.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ public AnimQieRu(EnterAnimLayout view) {

@Override
public void handleCanvas(Canvas canvas, float rate) {

canvas.translate(0,h-h*rate);

if(isExitAnim) {
canvas.translate(0,h*rate);
}else{
canvas.translate(0,h-h*rate);
}
canvas.save();
}
}
7 changes: 6 additions & 1 deletion app/src/main/java/anim/AnimShanXingZhanKai.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.Region;
import android.view.View;

import com.wangpm.enteranimation.EnterAnimLayout;
Expand All @@ -26,7 +27,11 @@ public void handleCanvas(Canvas canvas, float rate) {
path1.addArc(oval,270-180*rate,360*rate);
path1.lineTo(w/2,h/2);
path1.close();//封闭
canvas.clipPath(path1);
if(isExitAnim) {
canvas.clipPath(path1, Region.Op.DIFFERENCE);
}else{
canvas.clipPath(path1);
}

canvas.save();
}
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/anim/AnimShiZiXingKuoZhan.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ public void handleCanvas(Canvas canvas, float rate) {
float rectRight1 = w-rectLeft1;
float rectTop1 = 0;
float rectBottom1 = h;
canvas.clipRect(rectLeft, rectTop,rectRight , rectBottom, Region.Op.DIFFERENCE);
canvas.clipRect(rectLeft1, rectTop1,rectRight1 , rectBottom1, Region.Op.DIFFERENCE);

if(isExitAnim) {
canvas.clipRect(rectLeft, rectTop,rectRight , rectBottom);
canvas.clipRect(rectLeft1, rectTop1,rectRight1 , rectBottom1);
}else{
canvas.clipRect(rectLeft, rectTop,rectRight , rectBottom, Region.Op.DIFFERENCE);
canvas.clipRect(rectLeft1, rectTop1,rectRight1 , rectBottom1, Region.Op.DIFFERENCE);
}
canvas.save();
}
}
6 changes: 5 additions & 1 deletion app/src/main/java/anim/AnimSuiJiXianTiao.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ public void handleCanvas(Canvas canvas, float rate) {

//剩余线条数量
restNum = restNum - needNum;
canvas.clipPath(path);
if(isExitAnim) {
canvas.clipPath(path, Region.Op.DIFFERENCE);
}else{
canvas.clipPath(path);
}
canvas.save();
}

Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/anim/AnimXiangNeiRongJie.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ public void handleCanvas(Canvas canvas, float rate) {
}

restNum = restNum - needNum;
canvas.clipPath(path);
if(isExitAnim) {
canvas.clipPath(path, Region.Op.DIFFERENCE);
}else{
canvas.clipPath(path);
}
canvas.save();
}

Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/anim/AnimYuanXingKuoZhan.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public void handleCanvas(Canvas canvas, float rate) {
path1.addOval(oval, Path.Direction.CCW);

path1.close();//封闭
canvas.clipPath(path1, Region.Op.DIFFERENCE);
if(isExitAnim) {
canvas.clipPath(path1);
}else{
canvas.clipPath(path1, Region.Op.DIFFERENCE);
}

canvas.save();
}
Expand Down
Loading

0 comments on commit 2c46e94

Please sign in to comment.