Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab41253

Browse files
committed
做了一些优化
1 parent ca40905 commit ab41253

File tree

9 files changed

+268
-226
lines changed

9 files changed

+268
-226
lines changed

app/src/main/java/com/zzhoujay/markdowndemo/MainActivity.java

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.zzhoujay.markdown.MarkDown;
1212

1313
import java.io.InputStream;
14+
import android.widget.*;
1415

1516
public class MainActivity extends AppCompatActivity {
1617

@@ -31,35 +32,12 @@ protected void onCreate(Bundle savedInstanceState) {
3132
assert textView != null;
3233
textView.setMovementMethod(LinkMovementMethod.getInstance());
3334

34-
// textView.post(new Runnable() {
35-
// @Override
36-
// public void run() {
37-
// SpannableStringBuilder sb = new SpannableStringBuilder();
38-
// sb.append("hello world zzhoujay");
39-
// StyleSpan styleSpan = new StyleSpan(Typeface.ITALIC);
40-
// StyleSpan styleSpan1 = new StyleSpan(Typeface.BOLD);
41-
// sb.setSpan(styleSpan,0,sb.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
42-
// sb.setSpan(styleSpan1,4,10,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
43-
// textView.setText(sb);
44-
// }
45-
// });
46-
47-
4835
final InputStream stream = getResources().openRawResource(R.raw.tt);
49-
// BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream));
50-
// final StringBuilder sb = new StringBuilder();
51-
// String line;
52-
// try {
53-
// while ((line = bufferedReader.readLine()) != null) {
54-
// sb.append(line).append('\n');
55-
// }
56-
// } catch (IOException e) {
57-
// e.printStackTrace();
58-
// }
5936

6037
textView.post(new Runnable() {
6138
@Override
6239
public void run() {
40+
long time=System.nanoTime();
6341
Spanned spanned = MarkDown.fromMarkdown(stream, new Html.ImageGetter() {
6442
@Override
6543
public Drawable getDrawable(String source) {
@@ -68,36 +46,10 @@ public Drawable getDrawable(String source) {
6846
return drawable;
6947
}
7048
}, textView);
49+
long useTime=System.nanoTime()-time;
50+
Toast.makeText(getApplicationContext(),"use time:"+useTime,Toast.LENGTH_LONG).show();
7151
textView.setText(spanned);
72-
// MarkDownParser markDownParser = new MarkDownParser(stream, new StyleBuilderImpl(textView, new Html.ImageGetter() {
73-
// @Override
74-
// public Drawable getDrawable(String source) {
75-
// Drawable drawable = getResources().getDrawable(R.mipmap.ic_launcher);
76-
// drawable.setBounds(0,0,400,400);
77-
// return drawable;
78-
// }
79-
// }));
80-
// try {
81-
// textView.setText(markDownParser.parser());
82-
// } catch (IOException e) {
83-
// e.printStackTrace();
84-
// }
85-
8652
}
8753
});
88-
89-
//
90-
// Pattern pattern = Pattern.compile("#\\s+(.*)");
91-
// String test = "# hello";
92-
// SpannableStringBuilder builder = new SpannableStringBuilder(test);
93-
// style.setSpan(new ForegroundColorSpan(Color.RED), 1, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
94-
// Matcher matcher = pattern.matcher(style);
95-
// if (matcher.find()) {
96-
// Log.i("find", matcher.group(1));
97-
// System.out.println(matcher.group(1));
98-
// } else {
99-
// Log.i("find", matcher.group(1));
100-
// System.out.println("gg");
101-
// }
10254
}
10355
}

app/src/main/res/raw/tt.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
hello
2-
code
1+
title
2+
==
33

4-
5-
6-
7-
8-
9-
10-
11-
12-
13-
zz
14-
gg
4+
> > hello
5+
> > ==
6+
> > my god

0 commit comments

Comments
 (0)