Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move sound feedback setting to Controllers #1695

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
package com.igalia.wolvic.ui.widgets.settings;

import android.content.Context;
import android.graphics.Point;
import android.view.LayoutInflater;

import androidx.databinding.DataBindingUtil;

import com.igalia.wolvic.R;
import com.igalia.wolvic.audio.AudioEngine;
import com.igalia.wolvic.browser.SettingsStore;
import com.igalia.wolvic.databinding.OptionsControllerBinding;
import com.igalia.wolvic.ui.views.settings.RadioGroupSetting;
import com.igalia.wolvic.ui.views.settings.SwitchSetting;
import com.igalia.wolvic.ui.widgets.WidgetManagerDelegate;
import com.igalia.wolvic.ui.widgets.WidgetPlacement;

class ControllerOptionsView extends SettingsView {

Expand Down Expand Up @@ -55,6 +58,9 @@ protected void updateUI() {
mBinding.scrollDirectionRadio.setOnCheckedChangeListener(mScrollDirectionListener);
setScrollDirection(mBinding.scrollDirectionRadio.getIdForValue(scrollDirection), false);

mBinding.soundEffectSwitch.setOnCheckedChangeListener(mSoundEffectListener);
setSoundEffect(SettingsStore.getInstance(getContext()).isAudioEnabled(), false);

mBinding.hapticFeedbackSwitch.setOnCheckedChangeListener(mHapticFeedbackListener);
setHapticFeedbackEnabled(SettingsStore.getInstance(getContext()).isHapticFeedbackEnabled(), false);

Expand All @@ -79,6 +85,7 @@ private void resetOptions() {
if (!mBinding.scrollDirectionRadio.getValueForId(mBinding.scrollDirectionRadio.getCheckedRadioButtonId()).equals(SettingsStore.SCROLL_DIRECTION_DEFAULT)) {
setScrollDirection(mBinding.scrollDirectionRadio.getIdForValue(SettingsStore.SCROLL_DIRECTION_DEFAULT), true);
}
setSoundEffect(SettingsStore.AUDIO_ENABLED, true);
setHapticFeedbackEnabled(SettingsStore.HAPTIC_FEEDBACK_ENABLED, true);
setPointerMode(SettingsStore.POINTER_MODE_DEFAULT, true);
setHandTrackingEnabled(true, true);
Expand All @@ -105,6 +112,17 @@ private void setScrollDirection(int checkedId, boolean doApply) {
}
}

private void setSoundEffect(boolean value, boolean doApply) {
mBinding.soundEffectSwitch.setOnCheckedChangeListener(null);
mBinding.soundEffectSwitch.setValue(value, false);
mBinding.soundEffectSwitch.setOnCheckedChangeListener(mSoundEffectListener);

if (doApply) {
SettingsStore.getInstance(getContext()).setAudioEnabled(value);
AudioEngine.fromContext(getContext()).setEnabled(value);
}
}

private void setHapticFeedbackEnabled(boolean value, boolean doApply) {
mBinding.hapticFeedbackSwitch.setOnCheckedChangeListener(null);
mBinding.hapticFeedbackSwitch.setValue(value, false);
Expand Down Expand Up @@ -144,6 +162,10 @@ private void setHandTrackingEnabled(boolean value, boolean doApply) {
setScrollDirection(checkedId, doApply);
};

private SwitchSetting.OnCheckedChangeListener mSoundEffectListener = (compoundButton, enabled, apply) -> {
setSoundEffect(enabled, true);
};

private SwitchSetting.OnCheckedChangeListener mHapticFeedbackListener = (compoundButton, enabled, apply) ->
setHapticFeedbackEnabled(enabled, true);

Expand All @@ -166,6 +188,12 @@ private void setHandTrackingEnabled(boolean value, boolean doApply) {
private SwitchSetting.OnCheckedChangeListener mHandtrackingListener = (compoundButton, enabled, apply) ->
setHandTrackingEnabled(enabled, true);

@Override
public Point getDimensions() {
return new Point( WidgetPlacement.dpDimension(getContext(), R.dimen.settings_dialog_width),
WidgetPlacement.dpDimension(getContext(), R.dimen.controller_options_height));
}

@Override
protected SettingViewType getType() {
return SettingViewType.CONTROLLER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import androidx.databinding.DataBindingUtil;

import com.igalia.wolvic.R;
import com.igalia.wolvic.audio.AudioEngine;
import com.igalia.wolvic.browser.SettingsStore;
import com.igalia.wolvic.databinding.OptionsDisplayBinding;
import com.igalia.wolvic.ui.views.settings.RadioGroupSetting;
Expand Down Expand Up @@ -98,9 +97,6 @@ protected void updateUI() {
mBinding.startWithPassthroughSwitch.setVisibility(View.GONE);
}

mBinding.soundEffectSwitch.setOnCheckedChangeListener(mSoundEffectListener);
setSoundEffect(SettingsStore.getInstance(getContext()).isAudioEnabled(), false);

mBinding.latinAutoCompleteSwitch.setOnCheckedChangeListener(mLatinAutoCompleteListener);
setLatinAutoComplete(SettingsStore.getInstance(getContext()).isLatinAutoCompleteEnabled(), false);

Expand Down Expand Up @@ -192,10 +188,6 @@ public boolean isEditing() {
setStartWithPassthrough(value);
};

private SwitchSetting.OnCheckedChangeListener mSoundEffectListener = (compoundButton, enabled, apply) -> {
setSoundEffect(enabled, true);
};

private SwitchSetting.OnCheckedChangeListener mLatinAutoCompleteListener = (compoundButton, enabled, apply) -> {
setLatinAutoComplete(enabled, true);
};
Expand Down Expand Up @@ -285,7 +277,6 @@ public boolean isEditing() {
setAutoplay(SettingsStore.AUTOPLAY_ENABLED, true);
setCurvedDisplay(false, true);
setHeadLock(SettingsStore.HEAD_LOCK_DEFAULT, true);
setSoundEffect(SettingsStore.AUDIO_ENABLED, true);
setLatinAutoComplete(SettingsStore.LATIN_AUTO_COMPLETE_ENABLED, true);
setCenterWindows(SettingsStore.CENTER_WINDOWS_DEFAULT, true);
setWindowDistance(SettingsStore.WINDOW_DISTANCE_DEFAULT, true);
Expand Down Expand Up @@ -365,17 +356,6 @@ private void setHeadLock(boolean value, boolean doApply) {
}
}

private void setSoundEffect(boolean value, boolean doApply) {
mBinding.soundEffectSwitch.setOnCheckedChangeListener(null);
mBinding.soundEffectSwitch.setValue(value, false);
mBinding.soundEffectSwitch.setOnCheckedChangeListener(mSoundEffectListener);

if (doApply) {
SettingsStore.getInstance(getContext()).setAudioEnabled(value);
AudioEngine.fromContext(getContext()).setEnabled(value);
}
}

private void setTabsLocation(int checkedId, boolean doApply) {
mBinding.tabsLocationRadio.setOnCheckedChangeListener(null);
mBinding.tabsLocationRadio.setChecked(checkedId, doApply);
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout/options_controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>
<import type="com.igalia.wolvic.BuildConfig"/>
<import type="android.view.View" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -48,6 +53,13 @@
app:options="@array/developer_options_pointer_modes"
app:values="@array/developer_options_pointer_modes_values" />

<com.igalia.wolvic.ui.views.settings.SwitchSetting
android:id="@+id/soundEffectSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="@{BuildConfig.FLAVOR_backend == &quot;chromium&quot; ? View.VISIBLE : View.GONE}"
app:description="@string/display_options_sound_effect" />

<com.igalia.wolvic.ui.views.settings.SwitchSetting
android:id="@+id/haptic_feedback_switch"
android:layout_width="match_parent"
Expand Down
12 changes: 0 additions & 12 deletions app/src/main/res/layout/options_display.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>
<import type="com.igalia.wolvic.BuildConfig"/>
<import type="android.view.View" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -61,13 +56,6 @@
android:layout_height="wrap_content"
app:description="@string/security_options_autoplay" />

<com.igalia.wolvic.ui.views.settings.SwitchSetting
android:id="@+id/soundEffectSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="@{BuildConfig.FLAVOR_backend == &quot;chromium&quot; ? View.VISIBLE : View.GONE}"
app:description="@string/display_options_sound_effect" />

<com.igalia.wolvic.ui.views.settings.SwitchSetting
android:id="@+id/latinAutoCompleteSwitch"
android:layout_width="match_parent"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/dimen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@
<!-- Language and voice settings -->
<dimen name="language_options_height">400dp</dimen>

<!-- Controller settings -->
<dimen name="controller_options_height">450dp</dimen>

<!-- JS Prompt dialogs -->
<item name="js_prompt_y_distance" format="float" type="dimen">1.2</item>

Expand Down
Loading