Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow users to choose window's default size in Display settings. There are four options: 800x450 (default), 750x500, 825x550, 900x600.
  • Loading branch information
haanhvu committed Nov 19, 2024
1 parent 117540c commit eedccaf
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 7 deletions.
44 changes: 42 additions & 2 deletions app/src/common/shared/com/igalia/wolvic/browser/SettingsStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.ColorDrawable;
import android.text.InputType;
import android.text.Spannable;
import android.text.SpannableString;
Expand All @@ -11,6 +12,7 @@
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
Expand Down Expand Up @@ -158,6 +160,10 @@ public int getCheckedRadioButtonId() {
public void setOptions(@NonNull String[] options) {
mRadioGroup.removeAllViews();

if (options.length >= 4) {
mRadioGroup.setOrientation(VERTICAL);
}

for (int i=0; i<options.length; i++) {
SpannableString spannable = new SpannableString(options[i]);
if (mDescriptions != null && mDescriptions[i] != null) {
Expand All @@ -179,6 +185,9 @@ public void setOptions(@NonNull String[] options) {
button.setText(spannable);
button.setSingleLine(false);
button.setLayoutParams(getItemParams(i));
if (mRadioGroup.getOrientation() == VERTICAL) {
button.setPadding(15, 0, 15, 15);
}
mRadioGroup.addView(button);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -1568,28 +1568,37 @@ public Pair<Float, Float> getMaxWorldSize() {
}

public Pair<Float, Float> 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<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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,6 +75,17 @@ protected void updateUI() {
mBinding.msaaRadio.setOnCheckedChangeListener(mMSSAChangeListener);
setMSAAMode(mBinding.msaaRadio.getIdForValue(msaaLevel), false);

List<String> 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);

Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/options_display.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
app:options="@array/developer_options_msaa"
app:values="@array/developer_options_msaa_mode_values" />

<com.igalia.wolvic.ui.views.settings.RadioGroupSetting
android:id="@+id/windows_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:description="Default window's size" />

<com.igalia.wolvic.ui.views.settings.SingleEditSetting
android:id="@+id/homepage_edit"
android:layout_width="match_parent"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/non_L10n.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<string name="settings_key_speech_data_collection" translatable="false">settings_key_speech_data_collection</string>
<string name="settings_key_speech_data_collection_reviewed" translatable="false">settings_key_speech_data_collection_accept</string>
<string name="settings_key_window_distance" translatable="false">settings_window_distance</string>
<string name="settings_key_window_width" translatable="false">settings_window_width</string>
<string name="settings_key_window_height" translatable="false">settings_window_height</string>
<string name="settings_key_user_agent_version" translatable="false">settings_user_agent_version_v2</string>
<string name="settings_key_input_mode" translatable="false">settings_touch_mode</string>
<string name="settings_key_center_windows" translatable="false">settings_center_windows</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,9 @@
<!-- This string is used to label the MSAA radio button that enables two times MSAA in Immersive Mode. -->
<string name="developer_options_msaa_4">4x</string>

<!-- This string is used to label the radio buttons for setting the default size of windows. -->
<string name="window_size_preset">%1$d×%2$d</string>

<!-- This string is used to label a set of radio buttons that allow the user to change the
User-Agent (UA) string of the browser. -->
<string name="developer_options_ua_mode">User-Agent Mode</string>
Expand Down

0 comments on commit eedccaf

Please sign in to comment.