55 | * string will be logged in the console on a new line as following:
56 | *
249 | * string will be logged in the console on a new line as following:
250 | *
57 | * {@code HH:mm:ss > string}
58 | *
59 | */
60 | protected void log(String string) {
61 | if (mDevToolFragment != null)
62 | mDevToolFragment.log(string);
63 | }
64 |
65 | /**
66 | * Calling this method will clear the console.
67 | */
68 | protected void clear() {
69 | if (mDevToolFragment != null)
70 | mDevToolFragment.clear();
71 | }
72 |
73 | /*package*/ void setDevToolFragment(DevToolFragment devToolFragment) {
74 | this.mDevToolFragment = devToolFragment;
75 | }
76 |
77 | public static class Clear extends DebugFunction {
78 | public Clear(String title) {
79 | super(title);
80 | }
81 |
82 | @Override
83 | public String call() throws Exception {
84 | clear();
85 | return null;
86 | }
87 | }
88 |
89 | /**
90 | * This is a sample function to dump shared preferences
91 | */
92 | public static class DumpSharedPreferences extends DebugFunction {
93 | private String FILE_NAME;
94 | private int mode = Context.MODE_PRIVATE;
95 |
96 | private DumpSharedPreferences() {
97 | }
98 |
99 | /**
100 | * Constructor
101 | *
102 | * @param title the title of the function
103 | * @param fileName the name of your shared preference file
104 | * @param mode the file creation mode. By default {@link android.content.Context#MODE_PRIVATE Context.MODE_PRIVATE}
105 | */
106 | public DumpSharedPreferences(String title, String fileName, int mode) {
107 | super(title);
108 | this.FILE_NAME = fileName;
109 | this.mode = mode;
110 | }
111 |
112 | /**
113 | * Constructor
114 | *
115 | * @param title the title of the function
116 | * @param fileName the name of your shared preference file
117 | */
118 | public DumpSharedPreferences(String title, String fileName) {
119 | super(title);
120 | this.FILE_NAME = fileName;
121 | }
122 |
123 | /**
124 | * Constructor
125 | *
126 | * @param fileName the name of your shared preference file
127 | * @param mode the file creation mode. By default {@link android.content.Context#MODE_PRIVATE Context.MODE_PRIVATE}
128 | */
129 | public DumpSharedPreferences(String fileName, int mode) {
130 | this.FILE_NAME = fileName;
131 | this.mode = mode;
132 | }
133 |
134 | /**
135 | * Constructor
136 | *
137 | * @param fileName the name of your shared preference file
138 | */
139 | public DumpSharedPreferences(String fileName) {
140 | this.FILE_NAME = fileName;
141 | }
142 |
143 | @Override
144 | public String call() throws Exception {
145 | return dumpSharedPreferences(this.getContext());
146 | }
147 |
148 | private String dumpSharedPreferences(Context context) {
149 | SharedPreferences preferences = context.getSharedPreferences(FILE_NAME, mode);
150 | java.util.Map
251 | * {@code HH:mm:ss > string}
252 | */
253 | public void log(final String string) {
254 | final StringBuilder sb = new StringBuilder(mConsole.getText());
255 | sb.append("\n");
256 | sb.append(getCurrentTime()).append(" > ");
257 | sb.append(string);
258 | write(sb.toString());
259 | }
260 |
261 | /**
262 | * Call this function at runtime if you want to clear the console.
263 | */
264 | public void clear() {
265 | mConsole.setText("");
266 | softLog("ready.");
267 | }
268 |
269 | private void softLog(String string) {
270 | final StringBuilder sb = new StringBuilder(mConsole.getText());
271 | sb.append(getCurrentTime()).append(" > ");
272 | sb.append(string);
273 | write(sb.toString());
274 | }
275 |
276 | private void write(final String string) {
277 | mConsole.setText(string);
278 | mConsole.post(new Runnable() {
279 | @Override
280 | public void run() {
281 | mConsole.requestLayout();
282 | if (mConsoleContainer != null) {
283 | mConsoleContainer.post(new Runnable() {
284 | @Override
285 | public void run() {
286 | mConsoleContainer.fullScroll(ScrollView.FOCUS_DOWN);
287 | mConsoleContainer.requestLayout();
288 | }
289 | });
290 | }
291 | }
292 | });
293 | }
294 |
295 |
296 | /**
297 | * Add a function to the list. This will add a button as well when calling {@code build()}
298 | *
299 | * @param function must implement {@link DebugFunction}.
300 | */
301 | public void addFunction(DebugFunction function) {
302 | this.mFunctions.add(function);
303 | }
304 |
305 | /**
306 | * Set the function list. This will corresponding buttons when calling {@code build()}
307 | *
308 | * @param functions must be a List of {@link DebugFunction}.
309 | */
310 | public void setFunctionList(List