diff --git a/app/src/main/java/com/github/cvzi/screenshottile/App.java b/app/src/main/java/com/github/cvzi/screenshottile/App.java index 992427796..ac308fbe0 100644 --- a/app/src/main/java/com/github/cvzi/screenshottile/App.java +++ b/app/src/main/java/com/github/cvzi/screenshottile/App.java @@ -47,15 +47,22 @@ public class App extends Application { private static App instance; private static Intent screenshotPermission = null; private static OnAcquireScreenshotPermissionListener onAcquireScreenshotPermissionListener = null; - private static Boolean checkAccessibilityServiceOnCollapse = true; + private static boolean checkAccessibilityServiceOnCollapse = true; private static MediaProjection mediaProjection = null; private static volatile boolean receiverRegistered = false; - private static NotificationActionReceiver notificationActionReceiver; private final Handler handler = new Handler(Looper.getMainLooper()); private PrefManager prefManager; private Runnable screenshotRunnable; private WeakReference lastScreenshot = null; + public App() { + setInstance(this); + } + + private static void setInstance(App app) { + instance = app; + } + public static App getInstance() { return instance; } @@ -69,7 +76,8 @@ public static Intent getScreenshotPermission() { * * @return last bitmap or null */ - public @Nullable Bitmap getLastScreenshot() { + public @Nullable + Bitmap getLastScreenshot() { if (lastScreenshot != null) { Bitmap tmp = lastScreenshot.get(); lastScreenshot = null; @@ -80,11 +88,12 @@ public static Intent getScreenshotPermission() { /** * Set the last bitmap + * * @param lastScreenshot The last bitmap or null to remove reference */ public void setLastScreenshot(@Nullable Bitmap lastScreenshot) { if (lastScreenshot != null) { - this.lastScreenshot = new WeakReference(lastScreenshot); + this.lastScreenshot = new WeakReference<>(lastScreenshot); } else { this.lastScreenshot = null; } @@ -122,7 +131,7 @@ public static void registerNotificationReceiver() { return; } - notificationActionReceiver = new NotificationActionReceiver(); + NotificationActionReceiver notificationActionReceiver = new NotificationActionReceiver(); notificationActionReceiver.registerReceiver(App.getInstance()); receiverRegistered = true; @@ -217,11 +226,11 @@ public static void openScreenshotPermissionRequester(Context context) { /** * Open new activity that asks for the storage permission (and also notifications permission - * since Android 13 Tirmamisu). + * since Android 13 Tiramisu). * * @param context Context */ - public static void requestStoragePermission(Context context, Boolean screenshot) { + public static void requestStoragePermission(Context context, boolean screenshot) { final Intent intent = new Intent(context, AcquireScreenshotPermission.class); intent.addFlags(FLAG_ACTIVITY_NEW_TASK); intent.putExtra(AcquireScreenshotPermission.EXTRA_REQUEST_PERMISSION_STORAGE, true); @@ -229,18 +238,17 @@ public static void requestStoragePermission(Context context, Boolean screenshot) context.startActivity(intent); } - public static Boolean checkAccessibilityServiceOnCollapse() { + public static boolean checkAccessibilityServiceOnCollapse() { return checkAccessibilityServiceOnCollapse; } - public static void checkAccessibilityServiceOnCollapse(Boolean checkAccessibilityServiceOnCollapse) { + public static void checkAccessibilityServiceOnCollapse(boolean checkAccessibilityServiceOnCollapse) { App.checkAccessibilityServiceOnCollapse = checkAccessibilityServiceOnCollapse; } @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); - instance = this; } @Override @@ -357,8 +365,8 @@ private void screenshotShowCountdown(Context context) { try { tileService.startActivityAndCollapse(intent); startActivityAndCollapseSucceeded = true; - } catch (NullPointerException e) { - startActivityAndCollapseSucceeded = false; + // skipcq + } catch (NullPointerException ignored) { } } @@ -375,7 +383,7 @@ private void screenshotShowCountdown(Context context) { } } - private void screenshotHiddenCountdown(Context context, Boolean now, Boolean alreadyCollapsed) { + private void screenshotHiddenCountdown(Context context, boolean now, boolean alreadyCollapsed) { int delay = prefManager.getDelay(); if (now) { delay = 0; @@ -390,6 +398,7 @@ private void screenshotHiddenCountdown(Context context, Boolean now, Boolean alr try { tileService.startActivityAndCollapse(intent); startActivityAndCollapseSucceeded = true; + // skipcq } catch (NullPointerException e) { Log.e(TAG, "screenshotHiddenCountdown() tileService was null"); } @@ -412,6 +421,7 @@ private void screenshotHiddenCountdown(Context context, Boolean now, Boolean alr intent.setFlags(FLAG_ACTIVITY_NEW_TASK); try { tileService.startActivityAndCollapse(intent); + // skipcq } catch (NullPointerException e) { context.startActivity(intent); } @@ -463,6 +473,7 @@ public void startActivityAndCollapse(Context context, Intent intent) { } else { context.startActivity(intent); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { + // skipcq context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); } }