Skip to content

Commit

Permalink
1. 优化性能
Browse files Browse the repository at this point in the history
  • Loading branch information
chenBingX committed May 13, 2017
1 parent 231c1f2 commit c368445
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'

// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
#Sat May 13 14:52:09 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
29 changes: 16 additions & 13 deletions library/src/main/java/com/coorchice/library/SuperTextView.java
Expand Up @@ -88,7 +88,7 @@ public class SuperTextView extends TextView {
private boolean cacheRunnableState;
private boolean cacheNeedRunState;
private int frameRate = 60;

private Runnable invalidate;


public SuperTextView(Context context) {
Expand Down Expand Up @@ -627,6 +627,7 @@ public SuperTextView setFrameRate(int frameRate) {
}

public void startAnim() {
checkWhetherNeedInitInvalidate();
needRun = true;
runnable = false;
if (animThread == null) {
Expand All @@ -636,12 +637,9 @@ public void startAnim() {
@Override
public void run() {
while (runnable) {
post(new Runnable() {
@Override
public void run() {
postInvalidate();
}
});
synchronized (invalidate){
post(invalidate);
}
try {
Thread.sleep(1000 / frameRate);
} catch (InterruptedException e) {
Expand All @@ -661,6 +659,17 @@ public void run() {
}
}

private void checkWhetherNeedInitInvalidate() {
if (invalidate == null) {
invalidate = new Runnable() {
@Override
public void run() {
postInvalidate();
}
};
}
}

public void stopAnim() {
runnable = false;
needRun = false;
Expand Down Expand Up @@ -695,12 +704,6 @@ protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
}

@Override
protected void finalize() throws Throwable {
stopAnim();
super.finalize();
}

public static abstract class Adjuster {
private Opportunity opportunity = Opportunity.BEFORE_TEXT;

Expand Down

0 comments on commit c368445

Please sign in to comment.