Add option to allow empty home screen pages

This commit is contained in:
Patryk Michalik
2021-03-11 18:59:14 +01:00
parent cfd14e9b9e
commit 2e1b4f1b39
7 changed files with 48 additions and 0 deletions

View File

@@ -42,6 +42,7 @@ import android.app.WallpaperManager;
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetProviderInfo;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Point;
@@ -117,6 +118,8 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.function.Predicate;
import ch.deletescape.lawnchair.sharedprefs.LawnchairPreferences;
/**
* The workspace is a wide area with a wallpaper and a finite number of pages.
* Each page contains a number of icons, folders or widgets the user can
@@ -255,6 +258,9 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
private final StatsLogManager mStatsLogManager;
// Lawnchair: Create boolean to indicate if empty pages are allowed.
Boolean emptyScreensAllowed;
/**
* Used to inflate the Workspace from XML.
*
@@ -288,6 +294,12 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
setMotionEventSplittingEnabled(true);
setOnTouchListener(new WorkspaceTouchListener(mLauncher, this));
mStatsLogManager = StatsLogManager.newInstance(context);
// Lawnchair: Get instance of `SharedPreferences`, assign value to `emptyScreensAllowed`.
SharedPreferences prefs = LawnchairPreferences.Companion.getInstance(getContext());
if (prefs != null) {
emptyScreensAllowed = prefs.getBoolean(LawnchairPreferences.ALLOW_EMPTY_PAGES, false);
}
}
@Override
@@ -621,6 +633,12 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
}
if (hasExtraEmptyScreen() || mScreenOrder.size() == 0) return;
// Lawnchair: Stop execution if empty pages are allowed.
if (emptyScreensAllowed) {
return;
}
int finalScreenId = mScreenOrder.get(mScreenOrder.size() - 1);
CellLayout finalScreen = mWorkspaceScreens.get(finalScreenId);
@@ -741,6 +759,11 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
return;
}
// Lawnchair: Stop execution if empty pages are allowed.
if (emptyScreensAllowed) {
return;
}
if (isPageInTransition()) {
mStripScreensOnPageStopMoving = true;
return;