| 18 | import com.google.gson.Gson; |
| 19 | |
| 20 | public class App extends Application implements Application.ActivityLifecycleCallbacks { |
| 21 | |
| 22 | private static volatile App instance; |
| 23 | |
| 24 | private final Handler handler; |
| 25 | private final Gson gson; |
| 26 | private final long time; |
| 27 | |
| 28 | private Activity activity; |
| 29 | private Hook hook; |
| 30 | |
| 31 | public App() { |
| 32 | instance = this; |
| 33 | gson = new Gson(); |
| 34 | time = System.currentTimeMillis(); |
| 35 | handler = HandlerCompat.createAsync(Looper.getMainLooper()); |
| 36 | } |
| 37 | |
| 38 | public static App get() { |
| 39 | return instance; |
| 40 | } |
| 41 | |
| 42 | public static Gson gson() { |
| 43 | return get().gson; |
| 44 | } |
| 45 | |
| 46 | public static long time() { |
| 47 | return get().time; |
| 48 | } |
| 49 | |
| 50 | public static Activity activity() { |
| 51 | return get().activity; |
| 52 | } |
| 53 | |
| 54 | public static void post(Runnable runnable) { |
| 55 | get().handler.post(runnable); |
| 56 | } |
| 57 | |
| 58 | public static void post(Runnable runnable, long delayMillis) { |
| 59 | get().handler.removeCallbacks(runnable); |
| 60 | if (delayMillis >= 0) get().handler.postDelayed(runnable, delayMillis); |
| 61 | } |
| 62 | |
| 63 | public static void removeCallbacks(Runnable runnable) { |
| 64 | get().handler.removeCallbacks(runnable); |
| 65 | } |
| 66 | |
| 67 | public static void removeCallbacks(Runnable... runnable) { |
| 68 | for (Runnable r : runnable) get().handler.removeCallbacks(r); |
| 69 | } |
| 70 | |
| 71 | public void setHook(Hook hook) { |
| 72 | this.hook = hook; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | protected void attachBaseContext(Context base) { |
| 77 | super.attachBaseContext(base); |
nothing calls this directly
no outgoing calls
no test coverage detected