Skip to content

Commit efd457b

Browse files
committed
更新demo
1 parent c3e24a7 commit efd457b

4 files changed

Lines changed: 28 additions & 30 deletions

File tree

app/build.gradle

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@ android {
2020
}
2121

2222
dependencies {
23-
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
24-
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
25-
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
23+
2624
compile fileTree(dir: 'libs', include: ['*.jar'])
27-
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1', {
28-
exclude group: 'com.android.support', module: 'support-annotations'
29-
})
25+
3026
compile 'com.android.support:appcompat-v7:23.1.1'
3127
testCompile 'junit:junit:4.12'
3228
compile project(path: ':randomtextviewlibrary')

app/src/main/java/com/example/liangmutian/randomtextview/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void start(View v) {
3535
}
3636

3737
public void start2(View v) {
38-
mRandomTextView.setText("909878");
38+
mRandomTextView.setText("912111");
3939
pianyiliang[0] = 7;
4040
pianyiliang[1] = 6;
4141
pianyiliang[2] = 12;

app/src/main/java/com/example/liangmutian/randomtextview/MyApplication.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import android.app.Application;
44

5-
import com.squareup.leakcanary.LeakCanary;
65

76
/**
87
* Created by wuduogen838 on 16/11/30.
@@ -13,11 +12,6 @@ public class MyApplication extends Application {
1312
@Override
1413
public void onCreate() {
1514
super.onCreate();
16-
if (LeakCanary.isInAnalyzerProcess(this)) {
17-
// This process is dedicated to LeakCanary for heap analysis.
18-
// You should not init your app in this process.
19-
return;
20-
}
21-
LeakCanary.install(this);
15+
2216
}
2317
}

randomtextviewlibrary/src/main/java/com/example/liangmutian/randomtextviewlibrary/RandomTextView.java

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ public class RandomTextView extends TextView {
5959
private int measuredHeight;
6060

6161

62-
63-
6462
public RandomTextView(Context context) {
6563
super(context);
6664
}
@@ -122,18 +120,27 @@ protected void onDraw(Canvas canvas) {
122120
super.onDraw(canvas);
123121
p = getPaint();
124122
Paint.FontMetricsInt fontMetrics = p.getFontMetricsInt();
125-
measuredHeight=getMeasuredHeight();
126-
Log.d("EEEEEEE", "onDraw: "+measuredHeight);
123+
measuredHeight = getMeasuredHeight();
124+
Log.d("EEEEEEE", "onDraw: " + measuredHeight);
127125
baseline = (measuredHeight - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top;
128126
float[] widths = new float[4];
129127
p.getTextWidths("9999", widths);
130128
f0 = widths[0];
131129
invalidate();
132130
}
133131
drawNumber(canvas);
132+
// if (auto) {
133+
// for (int j = 0; j < numLength; j++) {
134+
//
135+
// pianyiliangSum[j] -= pianyilianglist[j];
136+
// postInvalidateDelayed(17);
137+
// }
134138

139+
140+
// }
135141
}
136142

143+
137144
//绘制
138145
private void drawNumber(Canvas canvas) {
139146

@@ -160,8 +167,8 @@ private void drawNumber(Canvas canvas) {
160167
}
161168
if (overLine[j] == 0)
162169

163-
drawText(canvas,setBack(arrayListText.get(j), maxLine - i - 1) + "", 0 + f0 * j,
164-
i * baseline + pianyiliangSum[j], p);
170+
drawText(canvas, setBack(arrayListText.get(j), maxLine - i - 1) + "", 0 + f0 * j,
171+
i * baseline + pianyiliangSum[j], p);
165172

166173
//canvas.drawText(setBack(arrayListText.get(j), maxLine - i - 1) + "", 0 + f0 * j,
167174
// i * baseline + pianyiliangSum[j], p);
@@ -171,9 +178,9 @@ private void drawNumber(Canvas canvas) {
171178
if (overLine[j] == 1) {
172179
overLine[j]++;
173180

174-
drawText(canvas,arrayListText.get(j) + "", 0 + f0 * j,
175-
baseline, p);
176-
// canvas.drawText(arrayListText.get(j) + "", 0 + f0 * j,
181+
drawText(canvas, arrayListText.get(j) + "", 0 + f0 * j,
182+
baseline, p);
183+
// canvas.drawText(arrayListText.get(j) + "", 0 + f0 * j,
177184
// baseline, p);
178185
}
179186

@@ -239,8 +246,9 @@ private ArrayList<Integer> getList(String s) {
239246

240247

241248
private static final Handler handler = new Handler();
242-
public void destroy (){
243-
auto=false;
249+
250+
public void destroy() {
251+
auto = false;
244252
handler.removeCallbacks(task);
245253

246254
}
@@ -256,22 +264,22 @@ public void run() {
256264
pianyiliangSum[j] -= pianyilianglist[j];
257265

258266
}
267+
259268
invalidate();
260269
}
261270

262271
}
263272
};
264273

265274

266-
private void drawText(Canvas mCanvas,String text,float x,float y,Paint p){
275+
private void drawText(Canvas mCanvas, String text, float x, float y, Paint p) {
267276

268-
if (y>=-measuredHeight&&y<=2*measuredHeight)
277+
if (y >= -measuredHeight && y <= 2 * measuredHeight)
269278

270-
mCanvas.drawText(text + "", x,
271-
y, p);
279+
mCanvas.drawText(text + "", x,
280+
y, p);
272281
else return;
273282
}
274283

275284

276-
277285
}

0 commit comments

Comments
 (0)