Skip to content

Commit e0f9d7f

Browse files
committed
Use WeakReference for view .
1 parent ff0ef67 commit e0f9d7f

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ You can also find iOS version of this [here](https://github.com/ninjaprox/NVActi
2020
Add dependencies in build.gradle.
2121
```groovy
2222
dependencies {
23-
compile 'com.wang.avi:library:1.0.4'
23+
compile 'com.wang.avi:library:1.0.5'
2424
compile 'com.nineoldandroids:library:2.4.0'
2525
}
2626
```

library/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
defaultConfig {
88
minSdkVersion 9
99
targetSdkVersion 23
10-
versionCode 5
11-
versionName "1.0.4"
10+
versionCode 6
11+
versionName "1.0.5"
1212
}
1313
buildTypes {
1414
release {
@@ -26,7 +26,7 @@ dependencies {
2626

2727
ext {
2828
PUBLISH_GROUP_ID = 'com.wang.avi'
29-
PUBLISH_VERSION = '1.0.4'
29+
PUBLISH_VERSION = '1.0.5'
3030
PUBLISH_DES = 'Nice loading animations for Android'
3131
LIB_NAME = 'AVLoadingIndicatorView'
3232

library/src/main/java/com/wang/avi/indicator/BaseIndicatorController.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
import android.graphics.Canvas;
44
import android.graphics.Paint;
5-
import android.util.Log;
65
import android.view.View;
76

87
import com.nineoldandroids.animation.Animator;
98

10-
import java.util.ArrayList;
9+
import java.lang.ref.WeakReference;
1110
import java.util.List;
1211

1312
/**
@@ -16,30 +15,32 @@
1615
public abstract class BaseIndicatorController {
1716

1817

19-
private View mTarget;
18+
private WeakReference<View> mTarget;
2019

2120
private List<Animator> mAnimators;
2221

2322

2423
public void setTarget(View target){
25-
this.mTarget=target;
24+
this.mTarget=new WeakReference<>(target);
2625
}
2726

2827
public View getTarget(){
29-
return mTarget;
28+
return mTarget!=null?mTarget.get():null;
3029
}
3130

3231

3332
public int getWidth(){
34-
return mTarget.getWidth();
33+
return getTarget()!=null?getTarget().getWidth():0;
3534
}
3635

3736
public int getHeight(){
38-
return mTarget.getHeight();
37+
return getTarget()!=null?getTarget().getHeight():0;
3938
}
4039

4140
public void postInvalidate(){
42-
mTarget.postInvalidate();
41+
if (getTarget()!=null){
42+
getTarget().postInvalidate();
43+
}
4344
}
4445

4546
/**

0 commit comments

Comments
 (0)