Skip to content

Commit 050e99f

Browse files
committed
Use a custom annotation interface for scroll direction
It's safer and improves the understandability of the code. The new definitions replaced the old DEFAULT value by NATURAL which matches what we show in the UI. There is still the need for an invalid value (-1 in this case) because we apply caching and we need to know whether the value has been initialized.
1 parent 06a0a86 commit 050e99f

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

app/src/common/shared/com/igalia/wolvic/VRBrowserActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ void handleScrollEvent(final int aHandle, final int aDevice, final float aX, fin
12211221
return;
12221222
}
12231223
}
1224-
float scrollDirection = mSettings.getScrollDirection() == 0 ? 1.0f : -1.0f;
1224+
float scrollDirection = mSettings.getScrollDirection() == SettingsStore.SCROLL_DIRECTION_NATURAL ? 1.0f : -1.0f;
12251225
MotionEventGenerator.dispatchScroll(widget, aDevice, true,aX * scrollDirection, aY * scrollDirection);
12261226
});
12271227
}

app/src/common/shared/com/igalia/wolvic/browser/SettingsStore.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ SettingsStore getInstance(final @NonNull Context aContext) {
8383
public static final int WINDOW_SELECTION_METHOD_CLICK = 0;
8484
public static final int WINDOW_SELECTION_METHOD_HOVER = 1;
8585

86+
// Keep in sync with developer_options_pointer_scroll_direction_values array in option_values.xml
87+
@IntDef(value = {SCROLL_DIRECTION_INVALID, SCROLL_DIRECTION_NATURAL, SCROLL_DIRECTION_REVERSED})
88+
public @interface ScrollDirection {}
89+
public static final int SCROLL_DIRECTION_INVALID = -1;
90+
public static final int SCROLL_DIRECTION_NATURAL = 0;
91+
public static final int SCROLL_DIRECTION_REVERSED = 1;
92+
8693
private Context mContext;
8794
private SharedPreferences mPrefs;
8895
private SettingsViewModel mSettingsViewModel;
@@ -151,7 +158,6 @@ public static WindowSizePreset fromValues(int width, int height) {
151158

152159
public final static @WindowSelectionMethod int WINDOW_SELECTION_METHOD_DEFAULT = WINDOW_SELECTION_METHOD_HOVER;
153160
public final static int POINTER_COLOR_DEFAULT_DEFAULT = Color.parseColor("#FFFFFF");
154-
public final static int SCROLL_DIRECTION_DEFAULT = 0;
155161
public final static String ENV_DEFAULT = "cyberpunk";
156162
public final static int MSAA_DEFAULT_LEVEL = 1;
157163
public final static boolean AUDIO_ENABLED = BuildConfig.FLAVOR_backend == "chromium";
@@ -193,7 +199,7 @@ public static WindowSizePreset fromValues(int width, int height) {
193199
public final static boolean CRASH_REPORTING_DEFAULT = false;
194200
public final static boolean TELEMETRY_DEFAULT = true;
195201

196-
private int mCachedScrollDirection = -1;
202+
private @ScrollDirection int mCachedScrollDirection = SCROLL_DIRECTION_INVALID;
197203

198204
private boolean mDisableLayers = false;
199205
public void setDisableLayers(final boolean aDisableLayers) {
@@ -669,9 +675,10 @@ public void setPointerColor(int color) {
669675
editor.apply();
670676
}
671677

678+
@ScrollDirection
672679
public int getScrollDirection() {
673-
if (mCachedScrollDirection < 0) {
674-
mCachedScrollDirection = mPrefs.getInt(mContext.getString(R.string.settings_key_scroll_direction), SCROLL_DIRECTION_DEFAULT);
680+
if (mCachedScrollDirection == SCROLL_DIRECTION_INVALID) {
681+
mCachedScrollDirection = mPrefs.getInt(mContext.getString(R.string.settings_key_scroll_direction), SCROLL_DIRECTION_NATURAL);
675682
}
676683
return mCachedScrollDirection;
677684
}

app/src/common/shared/com/igalia/wolvic/ui/widgets/settings/ControllerOptionsView.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ private void resetOptions() {
9393
if (!mBinding.pointerColorRadio.getValueForId(mBinding.pointerColorRadio.getCheckedRadioButtonId()).equals(SettingsStore.POINTER_COLOR_DEFAULT_DEFAULT)) {
9494
setPointerColor(mBinding.pointerColorRadio.getIdForValue(SettingsStore.POINTER_COLOR_DEFAULT_DEFAULT), true);
9595
}
96-
if (!mBinding.scrollDirectionRadio.getValueForId(mBinding.scrollDirectionRadio.getCheckedRadioButtonId()).equals(SettingsStore.SCROLL_DIRECTION_DEFAULT)) {
97-
setScrollDirection(mBinding.scrollDirectionRadio.getIdForValue(SettingsStore.SCROLL_DIRECTION_DEFAULT), true);
96+
if (!mBinding.scrollDirectionRadio.getValueForId(mBinding.scrollDirectionRadio.getCheckedRadioButtonId()).equals(SettingsStore.SCROLL_DIRECTION_NATURAL)) {
97+
setScrollDirection(mBinding.scrollDirectionRadio.getIdForValue(SettingsStore.SCROLL_DIRECTION_NATURAL), true);
9898
}
9999
setSoundEffect(SettingsStore.AUDIO_ENABLED, true);
100100
setHapticFeedbackEnabled(SettingsStore.HAPTIC_FEEDBACK_ENABLED, true);

0 commit comments

Comments
 (0)