-
Notifications
You must be signed in to change notification settings - Fork 106
/
ListingsActivity.java
179 lines (170 loc) · 7.45 KB
/
ListingsActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package io.github.kbiakov.codeviewexample;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import org.jetbrains.annotations.NotNull;
import io.github.kbiakov.codeview.CodeView;
import io.github.kbiakov.codeview.OnCodeLineClickListener;
import io.github.kbiakov.codeview.adapters.CodeWithDiffsAdapter;
import io.github.kbiakov.codeview.adapters.Format;
import io.github.kbiakov.codeview.adapters.Options;
import io.github.kbiakov.codeview.highlight.ColorTheme;
import io.github.kbiakov.codeview.highlight.ColorThemeData;
import io.github.kbiakov.codeview.highlight.Font;
import io.github.kbiakov.codeview.highlight.FontCache;
import io.github.kbiakov.codeview.views.DiffModel;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
public class ListingsActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listings);
final CodeView codeView = (CodeView) findViewById(R.id.code_view);
// /*
// * 1: set code content
// */
//
// // auto language recognition
// codeView.setCode(getString(R.string.listing_js));
//
// // specify language for code listing
// codeView.setCode(getString(R.string.listing_py), "py");
//
// /*
// * 2: working with options
// */
//
// // you can change params as follows (unsafe, initialized view only)
// codeView.getOptions()
// .withCode(R.string.listing_java)
// .withTheme(ColorTheme.MONOKAI);
//
// // short initialization with default params (can be expanded using with() methods)
// codeView.setOptions(Options.Default.get(this)
// .withLanguage("python")
// .withCode(R.string.listing_py)
// .withTheme(ColorTheme.MONOKAI)
// .withFont(Font.Consolas));
//
// // expanded form of initialization
// codeView.setOptions(new Options(
// this, // context
// getString(R.string.listing_js), // code
// "js", // language
// ColorTheme.MONOKAI.theme(), // theme (data)
// FontCache.get(this).getTypeface(this), // font
// Format.Default.getCompact(), // format
// true, // animate on highlight
// true, // shadows visible
// true, // shortcut
// getString(R.string.show_all), // shortcut note
// 10, // max lines
// new OnCodeLineClickListener() { // line click listener
// @Override
// public void onCodeLineClicked(int n, @NotNull String line) {
// Log.i("ListingsActivity", "On " + (n + 1) + " line clicked");
// }
// }));
//
// /*
// * 3: color themes
// */
//
// codeView.getOptions().setTheme(ColorTheme.SOLARIZED_LIGHT);
//
// // custom theme
// ColorThemeData myTheme = ColorTheme.SOLARIZED_LIGHT.theme()
// .withBgContent(android.R.color.black)
// .withNoteColor(android.R.color.white);
//
// codeView.getOptions().setTheme(myTheme);
//
// /*
// * 4: custom adapter with footer views
// */
//
// final CustomAdapter myAdapter = new CustomAdapter(this, getString(R.string.listing_md));
// codeView.setAdapter(myAdapter);
// codeView.getOptions()
// .withLanguage("md")
// .addCodeLineClickListener(new OnCodeLineClickListener() {
// @Override
// public void onCodeLineClicked(int n, @NotNull String line) {
// myAdapter.addFooterEntity(n, new CustomAdapter.CustomModel("Line " + (n + 1), line));
// }
// });
//
// /*
// * 5: diff adapter with footer views
// */
//
// final CodeWithDiffsAdapter diffsAdapter = new CodeWithDiffsAdapter(this);
// codeView.getOptions()
// .withLanguage("python")
// .setCode(getString(R.string.listing_py));
// codeView.updateAdapter(diffsAdapter);
//
// diffsAdapter.addFooterEntity(16, new DiffModel(getString(R.string.py_addition_16), true));
// diffsAdapter.addFooterEntity(11, new DiffModel(getString(R.string.py_deletion_11), false));
//
// /*
// * 6: shortcut adapter with footer views
// */
//
// codeView.getOptions()
// .shortcut(10, "Show all");
// - Playground
codeView.setCode("" +
"package io.github.kbiakov.codeviewexample;\n" +
"\n" +
"import android.os.Bundle;\n" +
"import android.support.annotation.Nullable;\n" +
"import android.support.v7.app.AppCompatActivity;\n" +
"import android.util.Log;\n" +
"\n" +
"import org.jetbrains.annotations.NotNull;\n" +
"\n" +
"import io.github.kbiakov.codeview.CodeView;\n" +
"import io.github.kbiakov.codeview.OnCodeLineClickListener;\n" +
"import io.github.kbiakov.codeview.adapters.CodeWithDiffsAdapter;\n" +
"import io.github.kbiakov.codeview.adapters.Options;\n" +
"import io.github.kbiakov.codeview.highlight.ColorTheme;\n" +
"import io.github.kbiakov.codeview.highlight.ColorThemeData;\n" +
"import io.github.kbiakov.codeview.highlight.Font;\n" +
"import io.github.kbiakov.codeview.highlight.FontCache;\n" +
"import io.github.kbiakov.codeview.views.DiffModel;\n" +
"\n" +
"public class ListingsActivity extends AppCompatActivity {\n" +
"\n" +
" @Override\n" +
" protected void onCreate(@Nullable Bundle savedInstanceState) {\n" +
" super.onCreate(savedInstanceState);\n" +
" setContentView(R.layout.activity_listings);\n" +
"\n" +
" final CodeView codeView = (CodeView) findViewById(R.id.code_view);\n" +
"\n" +
" /*\n" +
" * 1: set code content\n" +
" */\n" +
"\n" +
" // auto language recognition\n" +
" codeView.setCode(getString(R.string.listing_js));\n" +
"\n" +
" // specify language for code listing\n" +
" codeView.setCode(getString(R.string.listing_py), \"py\");" +
" }\n" +
"}", "java");
codeView.updateOptions(new Function1<Options, Unit>() {
@Override
public Unit invoke(Options options) {
options.withFont(Font.Consolas)
.withTheme(ColorTheme.SOLARIZED_LIGHT)
.withShadows()
.setShortcut(false);
return null;
}
});
}
}