Convert to AndroidX from support_v4
[fw/altos] / altosdroid / app / src / main / java / org / altusmetrum / AltosDroid / AltosDebug.java
1 /*
2  * Copyright © 2015 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18 package org.altusmetrum.AltosDroid;
19
20 import java.lang.*;
21
22 import android.content.*;
23 import android.util.Log;
24 import android.os.*;
25 import android.content.pm.*;
26
27 public class AltosDebug {
28         // Debugging
29         static final String TAG = "AltosDroid";
30
31         static boolean  D = true;
32
33         static void init(Context context) {
34                 ApplicationInfo app_info = context.getApplicationInfo();
35
36                 if ((app_info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
37                         Log.d(TAG, "Enable debugging\n");
38                         D = true;
39                 } else {
40                         Log.d(TAG, "Disable debugging\n");
41                         D = false;
42                 }
43         }
44
45
46         static void info(String format, Object ... arguments) {
47                 Log.i(TAG, String.format(format, arguments));
48         }
49
50         static void debug(String format, Object ... arguments) {
51                 if (D)
52                         Log.d(TAG, String.format(format, arguments));
53         }
54
55         static void error(String format, Object ... arguments) {
56                 Log.e(TAG, String.format(format, arguments));
57         }
58
59         static void check_ui(String format, Object ... arguments) {
60                 if (Looper.myLooper() == Looper.getMainLooper()) {
61                         Log.e(TAG, String.format("ON UI THREAD " + format, arguments));
62                         for (StackTraceElement el : Thread.currentThread().getStackTrace())
63                                 Log.e(TAG, "\t" + el.toString() + "\n");
64                 }
65         }
66 }