Skip to content

Commit

Permalink
Merge branch 'main' of github.com:cvzi/ScreenshotTile
Browse files Browse the repository at this point in the history
  • Loading branch information
cvzi committed Dec 2, 2022
2 parents c5162a7 + 6b288c2 commit 41e4cd0
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions app/src/main/java/com/github/cvzi/screenshottile/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bitmap> lastScreenshot = null;

public App() {
setInstance(this);
}

private static void setInstance(App app) {
instance = app;
}

public static App getInstance() {
return instance;
}
Expand All @@ -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;
Expand All @@ -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<Bitmap>(lastScreenshot);
this.lastScreenshot = new WeakReference<>(lastScreenshot);
} else {
this.lastScreenshot = null;
}
Expand Down Expand Up @@ -122,7 +131,7 @@ public static void registerNotificationReceiver() {
return;
}

notificationActionReceiver = new NotificationActionReceiver();
NotificationActionReceiver notificationActionReceiver = new NotificationActionReceiver();
notificationActionReceiver.registerReceiver(App.getInstance());

receiverRegistered = true;
Expand Down Expand Up @@ -217,30 +226,29 @@ 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);
intent.putExtra(AcquireScreenshotPermission.EXTRA_TAKE_SCREENSHOT_AFTER, 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
Expand Down Expand Up @@ -357,8 +365,8 @@ private void screenshotShowCountdown(Context context) {
try {
tileService.startActivityAndCollapse(intent);
startActivityAndCollapseSucceeded = true;
} catch (NullPointerException e) {
startActivityAndCollapseSucceeded = false;
// skipcq
} catch (NullPointerException ignored) {
}
}

Expand All @@ -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;
Expand All @@ -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");
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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));
}
}
Expand Down

0 comments on commit 41e4cd0

Please sign in to comment.