Skip to content

Commit

Permalink
Merge pull request #1 from felipeerias/haanhvu/issue1491-1-proposed-c…
Browse files Browse the repository at this point in the history
…hanges

Proposed changes
  • Loading branch information
haanhvu authored Nov 18, 2024
2 parents 56ddeb4 + f12332f commit 96e3aeb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 22 deletions.
28 changes: 22 additions & 6 deletions app/src/common/shared/com/igalia/wolvic/browser/SettingsStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ 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;
// We store the width and height but, for simplicity, the UI provides preset values.
public enum WindowSizePreset {
PRESET_0(800, 450),
PRESET_0(WINDOW_WIDTH_DEFAULT, WINDOW_HEIGHT_DEFAULT),
PRESET_1(750, 500),
PRESET_2(825, 550),
PRESET_3(900, 600);
Expand All @@ -118,8 +119,23 @@ public enum WindowSizePreset {
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 static int windowSizeId;
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;
Expand Down Expand Up @@ -501,11 +517,11 @@ public int getWindowHeight() {
mContext.getString(R.string.settings_key_window_height), WINDOW_HEIGHT_DEFAULT);
}

public void setWindowSize(int id) {
WindowSizePreset sizePreset = WindowSizePreset.values()[id];
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), sizePreset.width);
editor.putInt(mContext.getString(R.string.settings_key_window_height), sizePreset.height);
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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,12 @@ 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) / settingStore.getWindowWidth() /
return (WidgetPlacement.floatDimension(aContext, R.dimen.window_world_width) / SettingsStore.WINDOW_WIDTH_DEFAULT /
(settingStore.getDisplayDpi() / 100.0f) / settingStore.getDisplayDensity()) / WORLD_DPI_RATIO;
}

public static float worldToDpRatio(Context aContext){
SettingsStore settingStore = SettingsStore.getInstance(aContext);
return (WidgetPlacement.floatDimension(aContext, R.dimen.window_world_width) / settingStore.getWindowWidth());
return (WidgetPlacement.floatDimension(aContext, R.dimen.window_world_width) / SettingsStore.WINDOW_WIDTH_DEFAULT);
}

public static float viewToWidgetRatio(@NonNull Context context, @NonNull UIWidget widget) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1574,23 +1574,31 @@ public Pair<Float, Float> getMinWorldSize() {
return new Pair<>(minWidth, minHeight);
}

public Pair<Float, Float> 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<Float, Float> getSizeForScale(float aScale, float aAspect) {
Pair<Float, Float> minWorldSize = getMinWorldSize();
Pair<Float, Float> maxWorldSize = getMaxWorldSize();
Pair<Float, Float> defaultWorldSize = getDefaultWorldSize();
Pair<Float,Float> mainAxisMinMax, crossAxisMinMax;
float mainAxisDefault, mainAxisTarget;
float mainCrossAspect;

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;
Expand Down Expand Up @@ -1625,7 +1633,7 @@ public Pair<Float, Float> getMinWorldSize() {
}

private int getWindowWidth(float aWorldWidth) {
return (int) Math.floor(SettingsStore.getInstance(getContext()).getWindowWidth() * aWorldWidth / WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width));
return (int) Math.floor(SettingsStore.WINDOW_WIDTH_DEFAULT * aWorldWidth / WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width));
}

private NavigationBarWidget.NavigationListener mNavigationBarListener = new NavigationBarWidget.NavigationListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,6 @@ void updateMaxWindowScales() {
}

for (WindowWidget window: getCurrentWindows()) {
if (window.getWindowWidth() >= 900 && window.getWindowHeight() >= 600) {
maxScale = 1.0f;
}
window.setMaxWindowScale(maxScale);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ protected void updateUI() {
}
mBinding.windowsSize.setOptions(windowSizePresets.toArray(new String[0]));
mBinding.windowsSize.setOnCheckedChangeListener(mWindowsSizeChangeListener);
setWindowsSize(SettingsStore.windowSizeId, false);
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);
Expand Down Expand Up @@ -177,7 +180,7 @@ public boolean isEditing() {
};

private RadioGroupSetting.OnCheckedChangeListener mWindowsSizeChangeListener = (radioGroup, checkedId, doApply) -> {
setWindowsSize(checkedId, true);
setWindowsSizePreset(checkedId, true);
};

private SwitchSetting.OnCheckedChangeListener mAutoplayListener = (compoundButton, enabled, apply) -> {
Expand Down Expand Up @@ -264,8 +267,8 @@ public boolean isEditing() {
restart = true;
}

if (mBinding.windowsSize.getCheckedRadioButtonId() != 0) {
setWindowsSize(0, 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();
Expand Down Expand Up @@ -429,13 +432,12 @@ private void setMSAAMode(int checkedId, boolean doApply) {
}
}

private void setWindowsSize(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()).setWindowSize(checkedId);
SettingsStore.windowSizeId = checkedId;
SettingsStore.getInstance(getContext()).setWindowSizePreset(checkedId);
}

private boolean setDisplayDensity(float newDensity) {
Expand Down

0 comments on commit 96e3aeb

Please sign in to comment.