From d7569da2079c3e3b8786fbd29eb40a4a2af4b2a8 Mon Sep 17 00:00:00 2001 From: siankatabg Date: Mon, 20 Dec 2021 15:08:13 +0200 Subject: [PATCH] Add subtitles font size and background switch Added five font sizes to choose from (XLarge, Large, Normal, Small, XSmall) Added an option to disable the subtitles black background and the shadow color was changed to black from transparent, that adds slight shadow to the text which is much needed for when the black background is disabled, but not really visible when enabled. --- .../androidtv/preference/UserPreferences.kt | 10 ++++++ .../preference/constant/SubtitlesSize.kt | 36 +++++++++++++++++++ .../CustomPlaybackOverlayFragment.java | 30 ++++++++++++++-- .../ui/preference/category/playback.kt | 12 +++++++ app/src/main/res/values/strings.xml | 8 +++++ 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/org/jellyfin/androidtv/preference/constant/SubtitlesSize.kt diff --git a/app/src/main/java/org/jellyfin/androidtv/preference/UserPreferences.kt b/app/src/main/java/org/jellyfin/androidtv/preference/UserPreferences.kt index 8e064b2e90..578a93704a 100644 --- a/app/src/main/java/org/jellyfin/androidtv/preference/UserPreferences.kt +++ b/app/src/main/java/org/jellyfin/androidtv/preference/UserPreferences.kt @@ -180,6 +180,16 @@ class UserPreferences(context: Context) : SharedPreferenceStore( * Enable series thumbnails in home screen rows */ var seriesThumbnailsEnabled = Preference.boolean("pref_enable_series_thumbnails", true) + + /** + * Enable subtitles background + */ + var subtitlesBackgroundEnabled = Preference.boolean("pref_enable_subtitles_background", true) + + /** + * Set default subtitles font size + */ + var defaultSubtitlesSize = Preference.enum("pref_subtitles_size", SubtitlesSize.SUBS_SIZE_NORMAL) } init { diff --git a/app/src/main/java/org/jellyfin/androidtv/preference/constant/SubtitlesSize.kt b/app/src/main/java/org/jellyfin/androidtv/preference/constant/SubtitlesSize.kt new file mode 100644 index 0000000000..9597ac24a8 --- /dev/null +++ b/app/src/main/java/org/jellyfin/androidtv/preference/constant/SubtitlesSize.kt @@ -0,0 +1,36 @@ +package org.jellyfin.androidtv.preference.constant + +import org.jellyfin.androidtv.R +import org.jellyfin.androidtv.ui.preference.dsl.EnumDisplayOptions + +enum class SubtitlesSize { + /** + * Sets the subtitles size to huge. + */ + @EnumDisplayOptions(R.string.subs_size_xlarge) + SUBS_SIZE_XLARGE, + + /** + * Sets the subtitles size to big. + */ + @EnumDisplayOptions(R.string.subs_size_large) + SUBS_SIZE_LARGE, + + /** + * Sets the subtitles size to normal. + */ + @EnumDisplayOptions(R.string.subs_size_normal) + SUBS_SIZE_NORMAL, + + /** + * Sets the subtitles size to small. + */ + @EnumDisplayOptions(R.string.subs_size_small) + SUBS_SIZE_SMALL, + + /** + * Sets the subtitles size to xsmall. + */ + @EnumDisplayOptions(R.string.subs_size_xsmall) + SUBS_SIZE_XSMALL +} \ No newline at end of file diff --git a/app/src/main/java/org/jellyfin/androidtv/ui/playback/CustomPlaybackOverlayFragment.java b/app/src/main/java/org/jellyfin/androidtv/ui/playback/CustomPlaybackOverlayFragment.java index 9efc4a67bd..8b9ac75eef 100644 --- a/app/src/main/java/org/jellyfin/androidtv/ui/playback/CustomPlaybackOverlayFragment.java +++ b/app/src/main/java/org/jellyfin/androidtv/ui/playback/CustomPlaybackOverlayFragment.java @@ -47,6 +47,8 @@ import org.jellyfin.androidtv.R; import org.jellyfin.androidtv.TvApp; import org.jellyfin.androidtv.constant.CustomMessage; +import org.jellyfin.androidtv.preference.UserPreferences; +import org.jellyfin.androidtv.preference.constant.SubtitlesSize; import org.jellyfin.androidtv.data.model.DataRefreshService; import org.jellyfin.androidtv.databinding.OverlayTvGuideBinding; import org.jellyfin.androidtv.databinding.VlcPlayerInterfaceBinding; @@ -255,9 +257,29 @@ public void onActivityCreated(Bundle savedInstanceState) { //manual subtitles // This configuration is required for the PaddedLineBackgroundSpan to work - binding.subtitlesText.setShadowLayer(SUBTITLE_PADDING, 0, 0, Color.TRANSPARENT); + binding.subtitlesText.setShadowLayer(SUBTITLE_PADDING, 0, 0, Color.BLACK); binding.subtitlesText.setPadding(SUBTITLE_PADDING, 0, SUBTITLE_PADDING, 0); + // Subtitles font size configuration + SubtitlesSize subtitlesSize = KoinJavaComponent.get(UserPreferences.class).get(UserPreferences.Companion.getDefaultSubtitlesSize()); + switch (subtitlesSize) { + case SUBS_SIZE_XLARGE: + binding.subtitlesText.setTextSize(36); + break; + case SUBS_SIZE_LARGE: + binding.subtitlesText.setTextSize(32); + break; + case SUBS_SIZE_NORMAL: + binding.subtitlesText.setTextSize(28); + break; + case SUBS_SIZE_SMALL: + binding.subtitlesText.setTextSize(24); + break; + case SUBS_SIZE_XSMALL: + binding.subtitlesText.setTextSize(20); + break; + } + //pre-load animations fadeOut = AnimationUtils.loadAnimation(requireContext(), R.anim.abc_fade_out); fadeOut.setAnimationListener(hideAnimationListener); @@ -1461,6 +1483,10 @@ private void renderSubtitles(@Nullable final String text) { clearSubtitles(); return; } + + // Subtitles background switch + boolean subtitlesBackgroundEnabled = KoinJavaComponent.get(UserPreferences.class).get(UserPreferences.Companion.getSubtitlesBackgroundEnabled()); + requireActivity().runOnUiThread(() -> { // Encode whitespace as html entities final String htmlText = text @@ -1469,7 +1495,7 @@ private void renderSubtitles(@Nullable final String text) { final SpannableString span = new SpannableString(TextUtilsKt.toHtmlSpanned(htmlText)); span.setSpan(new ForegroundColorSpan(Color.WHITE), 0, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - span.setSpan(new PaddedLineBackgroundSpan(ContextCompat.getColor(requireContext(), R.color.black_opaque), SUBTITLE_PADDING), 0, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + span.setSpan(new PaddedLineBackgroundSpan(ContextCompat.getColor(requireContext(), subtitlesBackgroundEnabled ? R.color.black_opaque : R.color.transparent), SUBTITLE_PADDING), 0, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); binding.subtitlesText.setText(span); binding.subtitlesText.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/org/jellyfin/androidtv/ui/preference/category/playback.kt b/app/src/main/java/org/jellyfin/androidtv/ui/preference/category/playback.kt index e19ffa797d..2995a3899d 100644 --- a/app/src/main/java/org/jellyfin/androidtv/ui/preference/category/playback.kt +++ b/app/src/main/java/org/jellyfin/androidtv/ui/preference/category/playback.kt @@ -7,6 +7,7 @@ import org.jellyfin.androidtv.preference.UserPreferences import org.jellyfin.androidtv.preference.constant.AudioBehavior import org.jellyfin.androidtv.preference.constant.NextUpBehavior import org.jellyfin.androidtv.preference.constant.PreferredVideoPlayer +import org.jellyfin.androidtv.preference.constant.SubtitlesSize import org.jellyfin.androidtv.ui.preference.custom.DurationSeekBarPreference import org.jellyfin.androidtv.ui.preference.dsl.* import org.jellyfin.androidtv.util.DeviceUtils @@ -148,4 +149,15 @@ fun OptionsScreen.playbackCategory( } depends { userPreferences[UserPreferences.videoPlayer] == PreferredVideoPlayer.EXTERNAL } } + + checkbox { + setTitle(R.string.pref_subtitles_background_title) + setContent(R.string.pref_subtitles_background_summary) + bind(userPreferences, UserPreferences.subtitlesBackgroundEnabled) + } + + enum { + setTitle(R.string.pref_subtitles_size) + bind(userPreferences, UserPreferences.defaultSubtitlesSize) + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 76db8c3445..b6e1da107c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -464,4 +464,12 @@ Home section %1$d Search Jellyfin Media + Subtitles background + Show a black background behind the subtitles + XLarge + Lanrge + Normal + Small + XSmall + Subtitles font size