diff --git a/app/src/common/shared/com/igalia/wolvic/browser/SettingsStore.java b/app/src/common/shared/com/igalia/wolvic/browser/SettingsStore.java index cb609ba28d..897eb24509 100644 --- a/app/src/common/shared/com/igalia/wolvic/browser/SettingsStore.java +++ b/app/src/common/shared/com/igalia/wolvic/browser/SettingsStore.java @@ -105,6 +105,36 @@ SettingsStore getInstance(final @NonNull Context aContext) { // The maximum size is computed so the resulting texture fits within 2560x2560. public final static int MAX_WINDOW_WIDTH_DEFAULT = 1200; public final static int MAX_WINDOW_HEIGHT_DEFAULT = 800; + public enum WindowSizePreset { + PRESET_0(WINDOW_WIDTH_DEFAULT, WINDOW_HEIGHT_DEFAULT), + PRESET_1(750, 500), + PRESET_2(825, 550), + PRESET_3(900, 600); + + public final int width; + public final int height; + + WindowSizePreset(int width, int height) { + this.width = width; + this.height = height; + } + public static WindowSizePreset fromId(int id) { + if (id >= 0 && id < values().length) { + return values()[id]; + } else { + return WINDOW_SIZE_PRESET_DEFAULT; + } + } + public static WindowSizePreset fromValues(int width, int height) { + for (WindowSizePreset preset : values()) { + if (preset.width == width && preset.height == height) { + return preset; + } + } + return WINDOW_SIZE_PRESET_DEFAULT; + } + } + public final static WindowSizePreset WINDOW_SIZE_PRESET_DEFAULT = WindowSizePreset.PRESET_0; public final static int POINTER_COLOR_DEFAULT_DEFAULT = Color.parseColor("#FFFFFF"); public final static int SCROLL_DIRECTION_DEFAULT = 0; @@ -477,11 +507,21 @@ public void setDisplayDensity(float aDensity) { } public int getWindowWidth() { - return WINDOW_WIDTH_DEFAULT; + return mPrefs.getInt( + mContext.getString(R.string.settings_key_window_width), WINDOW_WIDTH_DEFAULT); } public int getWindowHeight() { - return WINDOW_HEIGHT_DEFAULT; + return mPrefs.getInt( + mContext.getString(R.string.settings_key_window_height), WINDOW_HEIGHT_DEFAULT); + } + + public void setWindowSizePreset(int presetId) { + WindowSizePreset preset = WindowSizePreset.fromId(presetId); + SharedPreferences.Editor editor = mPrefs.edit(); + editor.putInt(mContext.getString(R.string.settings_key_window_width), preset.width); + editor.putInt(mContext.getString(R.string.settings_key_window_height), preset.height); + editor.commit(); } public float getWindowAspect() { diff --git a/app/src/common/shared/com/igalia/wolvic/ui/views/library/BookmarksView.java b/app/src/common/shared/com/igalia/wolvic/ui/views/library/BookmarksView.java index 55b4f50188..75e7c5691b 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/views/library/BookmarksView.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/views/library/BookmarksView.java @@ -429,7 +429,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto protected void updateLayout() { post(() -> { double width = Math.ceil(getWidth()/getContext().getResources().getDisplayMetrics().density); - boolean isNarrow = width < SettingsStore.WINDOW_WIDTH_DEFAULT; + boolean isNarrow = width < SettingsStore.getInstance(getContext()).getWindowWidth(); if (isNarrow != mViewModel.getIsNarrow().getValue().get()) { mBookmarkAdapter.setNarrow(isNarrow); diff --git a/app/src/common/shared/com/igalia/wolvic/ui/views/library/DownloadsView.java b/app/src/common/shared/com/igalia/wolvic/ui/views/library/DownloadsView.java index 2016cef247..5df65c1893 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/views/library/DownloadsView.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/views/library/DownloadsView.java @@ -297,7 +297,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto protected void updateLayout() { post(() -> { double width = Math.ceil(getWidth() / getContext().getResources().getDisplayMetrics().density); - boolean isNarrow = width < SettingsStore.WINDOW_WIDTH_DEFAULT; + boolean isNarrow = width < SettingsStore.getInstance(getContext()).getWindowWidth(); if (isNarrow != mViewModel.getIsNarrow().getValue().get()) { mDownloadsAdapter.setNarrow(isNarrow); diff --git a/app/src/common/shared/com/igalia/wolvic/ui/views/library/HistoryView.java b/app/src/common/shared/com/igalia/wolvic/ui/views/library/HistoryView.java index e660e96098..66f5299523 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/views/library/HistoryView.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/views/library/HistoryView.java @@ -467,7 +467,7 @@ private void showHistory(List historyItems) { protected void updateLayout() { post(() -> { double width = Math.ceil(getWidth() / getContext().getResources().getDisplayMetrics().density); - boolean isNarrow = width < SettingsStore.WINDOW_WIDTH_DEFAULT; + boolean isNarrow = width < SettingsStore.getInstance(getContext()).getWindowWidth(); if (isNarrow != mViewModel.getIsNarrow().getValue().get()) { mHistoryAdapter.setNarrow(isNarrow); diff --git a/app/src/common/shared/com/igalia/wolvic/ui/views/library/WebAppsView.java b/app/src/common/shared/com/igalia/wolvic/ui/views/library/WebAppsView.java index 1eeca3cb67..2755ec0084 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/views/library/WebAppsView.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/views/library/WebAppsView.java @@ -163,7 +163,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto protected void updateLayout() { post(() -> { double width = Math.ceil(getWidth() / getContext().getResources().getDisplayMetrics().density); - boolean isNarrow = width < SettingsStore.WINDOW_WIDTH_DEFAULT; + boolean isNarrow = width < SettingsStore.getInstance(getContext()).getWindowWidth(); if (isNarrow != mViewModel.getIsNarrow().getValue().get()) { mWebAppsAdapter.setNarrow(isNarrow); diff --git a/app/src/common/shared/com/igalia/wolvic/ui/widgets/WidgetPlacement.java b/app/src/common/shared/com/igalia/wolvic/ui/widgets/WidgetPlacement.java index 4f5101190b..d835440dc4 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/widgets/WidgetPlacement.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/widgets/WidgetPlacement.java @@ -214,7 +214,7 @@ public static float worldToWidgetRatio(@NonNull UIWidget widget) { public static float worldToWindowRatio(Context aContext){ SettingsStore settingStore = SettingsStore.getInstance(aContext); - return (WidgetPlacement.floatDimension(aContext, R.dimen.window_world_width) / SettingsStore.WINDOW_WIDTH_DEFAULT / + return (WidgetPlacement.floatDimension(aContext, R.dimen.window_world_width) / SettingsStore.WINDOW_WIDTH_DEFAULT / (settingStore.getDisplayDpi() / 100.0f) / settingStore.getDisplayDensity()) / WORLD_DPI_RATIO; } diff --git a/app/src/common/shared/com/igalia/wolvic/ui/widgets/WindowWidget.java b/app/src/common/shared/com/igalia/wolvic/ui/widgets/WindowWidget.java index ba3db0c8cc..439939db8a 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/widgets/WindowWidget.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/widgets/WindowWidget.java @@ -1050,7 +1050,7 @@ public void centerFrontWindowIfNeeded() { // default position mWidgetPlacement.translationY = WidgetPlacement.unitFromMeters(getContext(), R.dimen.window_world_y); // center vertically relative to the default position - mWidgetPlacement.translationY += (SettingsStore.WINDOW_HEIGHT_DEFAULT - mWidgetPlacement.height) / 2.0f; + mWidgetPlacement.translationY += (SettingsStore.getInstance(getContext()).getWindowHeight() - mWidgetPlacement.height) / 2.0f; mWidgetManager.updateWidget(this); mWidgetManager.updateVisibleWidgets(); } @@ -1568,14 +1568,23 @@ public Pair getMaxWorldSize() { } public Pair getMinWorldSize() { + SettingsStore settings = SettingsStore.getInstance(getContext()); float minWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width) * MIN_SCALE; - float minHeight = minWidth * SettingsStore.WINDOW_HEIGHT_DEFAULT / SettingsStore.WINDOW_WIDTH_DEFAULT; + float minHeight = minWidth * settings.getWindowHeight() / settings.getWindowWidth(); return new Pair<>(minWidth, minHeight); } + public Pair getDefaultWorldSize() { + SettingsStore settings = SettingsStore.getInstance(getContext()); + float defaultWidth = settings.getWindowWidth() * WidgetPlacement.worldToDpRatio(getContext()); + float defaultHeight = settings.getWindowHeight() * WidgetPlacement.worldToDpRatio(getContext()); + return new Pair<>(defaultWidth, defaultHeight); + } + public @NonNull Pair getSizeForScale(float aScale, float aAspect) { Pair minWorldSize = getMinWorldSize(); Pair maxWorldSize = getMaxWorldSize(); + Pair defaultWorldSize = getDefaultWorldSize(); Pair mainAxisMinMax, crossAxisMinMax; float mainAxisDefault, mainAxisTarget; float mainCrossAspect; @@ -1583,13 +1592,13 @@ public Pair getMinWorldSize() { boolean isHorizontal = aAspect >= 1.0; if (isHorizontal) { // horizontal orientation - mainAxisDefault = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width); + mainAxisDefault = defaultWorldSize.first; mainAxisMinMax = Pair.create(minWorldSize.first, maxWorldSize.first); crossAxisMinMax = Pair.create(minWorldSize.second, maxWorldSize.second); mainCrossAspect = aAspect; } else { // vertical orientation - mainAxisDefault = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width) * aAspect; + mainAxisDefault = defaultWorldSize.second; mainAxisMinMax = Pair.create(minWorldSize.second, maxWorldSize.second); crossAxisMinMax = Pair.create(minWorldSize.first, maxWorldSize.first); mainCrossAspect = 1 / aAspect; diff --git a/app/src/common/shared/com/igalia/wolvic/ui/widgets/Windows.java b/app/src/common/shared/com/igalia/wolvic/ui/widgets/Windows.java index 9a9e4ea841..32ac6f07aa 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/widgets/Windows.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/widgets/Windows.java @@ -905,7 +905,7 @@ private void placeWindow(@NonNull WindowWidget aWindow, WindowPlacement aPositio placement.translationY = WidgetPlacement.unitFromMeters(mContext, R.dimen.window_world_y); if (centerWindow) { // center the window vertically relative to its default position - placement.translationY += (SettingsStore.WINDOW_HEIGHT_DEFAULT - placement.height) / 2.0f; + placement.translationY += (SettingsStore.getInstance(mContext).getWindowHeight() - placement.height) / 2.0f; } placement.translationZ = WidgetPlacement.getWindowWorldZMeters(mContext); break; diff --git a/app/src/common/shared/com/igalia/wolvic/ui/widgets/settings/DisplayOptionsView.java b/app/src/common/shared/com/igalia/wolvic/ui/widgets/settings/DisplayOptionsView.java index ddcf3c920b..d2225602ab 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/widgets/settings/DisplayOptionsView.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/widgets/settings/DisplayOptionsView.java @@ -22,6 +22,9 @@ import com.igalia.wolvic.ui.widgets.WidgetManagerDelegate; import com.igalia.wolvic.ui.widgets.WidgetPlacement; +import java.util.ArrayList; +import java.util.List; + class DisplayOptionsView extends SettingsView { private OptionsDisplayBinding mBinding; @@ -72,6 +75,17 @@ protected void updateUI() { mBinding.msaaRadio.setOnCheckedChangeListener(mMSSAChangeListener); setMSAAMode(mBinding.msaaRadio.getIdForValue(msaaLevel), false); + List windowSizePresets = new ArrayList<>(); + for (SettingsStore.WindowSizePreset preset : SettingsStore.WindowSizePreset.values()) { + windowSizePresets.add(getContext().getString(R.string.window_size_preset, preset.width, preset.height)); + } + mBinding.windowsSize.setOptions(windowSizePresets.toArray(new String[0])); + mBinding.windowsSize.setOnCheckedChangeListener(mWindowsSizeChangeListener); + int windowWidth = SettingsStore.getInstance(getContext()).getWindowWidth(); + int windowHeight = SettingsStore.getInstance(getContext()).getWindowHeight(); + SettingsStore.WindowSizePreset windowSizePreset = SettingsStore.WindowSizePreset.fromValues(windowWidth, windowHeight); + setWindowsSizePreset(windowSizePreset.ordinal(), false); + mBinding.autoplaySwitch.setOnCheckedChangeListener(mAutoplayListener); setAutoplay(SettingsStore.getInstance(getContext()).isAutoplayEnabled(), false); @@ -165,6 +179,10 @@ public boolean isEditing() { setMSAAMode(checkedId, true); }; + private RadioGroupSetting.OnCheckedChangeListener mWindowsSizeChangeListener = (radioGroup, checkedId, doApply) -> { + setWindowsSizePreset(checkedId, true); + }; + private SwitchSetting.OnCheckedChangeListener mAutoplayListener = (compoundButton, enabled, apply) -> { setAutoplay(enabled, true); }; @@ -249,6 +267,10 @@ public boolean isEditing() { restart = true; } + if (mBinding.windowsSize.getCheckedRadioButtonId() != SettingsStore.WINDOW_SIZE_PRESET_DEFAULT.ordinal()) { + setWindowsSizePreset(SettingsStore.WINDOW_SIZE_PRESET_DEFAULT.ordinal(), true); + } + float prevDensity = SettingsStore.getInstance(getContext()).getDisplayDensity(); restart = restart | setDisplayDensity(SettingsStore.DISPLAY_DENSITY_DEFAULT); int prevDpi = SettingsStore.getInstance(getContext()).getDisplayDpi(); @@ -410,6 +432,14 @@ private void setMSAAMode(int checkedId, boolean doApply) { } } + private void setWindowsSizePreset(int checkedId, boolean doApply) { + mBinding.windowsSize.setOnCheckedChangeListener(null); + mBinding.windowsSize.setChecked(checkedId, doApply); + mBinding.windowsSize.setOnCheckedChangeListener(mWindowsSizeChangeListener); + + SettingsStore.getInstance(getContext()).setWindowSizePreset(checkedId); + } + private boolean setDisplayDensity(float newDensity) { mBinding.densityEdit.setOnClickListener(null); boolean restart = false; diff --git a/app/src/main/res/layout/options_display.xml b/app/src/main/res/layout/options_display.xml index d6e8de6dbd..f259e51c8f 100644 --- a/app/src/main/res/layout/options_display.xml +++ b/app/src/main/res/layout/options_display.xml @@ -90,6 +90,12 @@ app:options="@array/developer_options_msaa" app:values="@array/developer_options_msaa_mode_values" /> + + settings_key_speech_data_collection settings_key_speech_data_collection_accept settings_window_distance + settings_window_width + settings_window_height settings_user_agent_version_v2 settings_touch_mode settings_center_windows diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f7d2fbdfe1..25f697d473 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -607,6 +607,9 @@ 4x + + %1$d×%2$d + User-Agent Mode