Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db3fca16 authored by Fan Zhang's avatar Fan Zhang
Browse files

Fix preview image alignment issue due to clip padding.

CaptionPropertiesFragment is using a non-standard way to display preview
images. Changed to use LayoutPreference.

Bug: 132797057
Test: visual
Change-Id: I92bfd38e2880226d7385e98ed871dad4e1f30e42
parent b4b77259
Loading
Loading
Loading
Loading
+22 −31
Original line number Diff line number Diff line
@@ -15,19 +15,17 @@
     limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/preview_viewport"
    android:clipToPadding="true"
    android:clipChildren="true"
    android:layout_width="match_parent"
        android:layout_height="@dimen/captioning_preview_height" >
    android:layout_height="wrap_content">

    <ImageView
        android:layout_width="match_parent"
            android:layout_height="match_parent"
        android:layout_height="@dimen/captioning_preview_height"
        android:contentDescription="@null"
        android:scaleType="centerCrop"
        android:src="@drawable/caption_background"/>
@@ -46,10 +44,3 @@
            android:text="@string/captioning_preview_text"/>
    </FrameLayout>
</FrameLayout>

    <FrameLayout
        android:id="@+id/properties_fragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>
+3 −1
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    android:layout_height="wrap_content"
    android:clipChildren="true"
    android:clipToPadding="true">

    <ImageView
        android:id="@+id/video_background"
+6 −0
Original line number Diff line number Diff line
@@ -21,6 +21,12 @@
    android:key="captioning_preference_screen"
    android:title="@string/accessibility_captioning_title" >

    <com.android.settingslib.widget.LayoutPreference
        android:key="caption_preview"
        android:title="@string/summary_placeholder"
        android:layout="@layout/captioning_preview"
        settings:searchable="false"/>

    <PreferenceCategory
        android:key="standard"
        android:title="@string/captioning_standard_options_title" >
+17 −44
Original line number Diff line number Diff line
@@ -22,13 +22,8 @@ import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.preference.PreferenceFrameLayout;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnLayoutChangeListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.accessibility.CaptioningManager;
import android.view.accessibility.CaptioningManager.CaptionStyle;

@@ -46,6 +41,7 @@ import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.ToggleSwitch;
import com.android.settings.widget.ToggleSwitch.OnBeforeCheckedChangeListener;
import com.android.settingslib.accessibility.AccessibilityUtils;
import com.android.settingslib.widget.LayoutPreference;

import java.util.Locale;

@@ -54,6 +50,7 @@ import java.util.Locale;
 */
public class CaptionPropertiesFragment extends SettingsPreferenceFragment
        implements OnPreferenceChangeListener, OnValueChangedListener {
    private static final String PREF_CAPTION_PREVIEW = "caption_preview";
    private static final String PREF_BACKGROUND_COLOR = "captioning_background_color";
    private static final String PREF_BACKGROUND_OPACITY = "captioning_background_opacity";
    private static final String PREF_FOREGROUND_COLOR = "captioning_foreground_color";
@@ -115,43 +112,6 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
        installUpdateListeners();
    }

    @Override
    public View onCreateView(
            LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View rootView = inflater.inflate(R.layout.captioning_preview, container, false);

        // We have to do this now because PreferenceFrameLayout looks at it
        // only when the view is added.
        if (container instanceof PreferenceFrameLayout) {
            ((PreferenceFrameLayout.LayoutParams) rootView.getLayoutParams()).removeBorders = true;
        }

        final View content = super.onCreateView(inflater, container, savedInstanceState);
        ((ViewGroup) rootView.findViewById(R.id.properties_fragment)).addView(
                content, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

        return rootView;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        final boolean enabled = mCaptioningManager.isEnabled();
        mPreviewText = (SubtitleView) view.findViewById(R.id.preview_text);
        mPreviewText.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);

        mPreviewWindow = view.findViewById(R.id.preview_window);
        mPreviewViewport = view.findViewById(R.id.preview_viewport);
        mPreviewViewport.addOnLayoutChangeListener(new OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom,
                    int oldLeft, int oldTop, int oldRight, int oldBottom) {
                refreshPreviewText();
            }
        });
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
@@ -263,6 +223,19 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
    }

    private void initializeAllPreferences() {
        final LayoutPreference captionPreview = findPreference(PREF_CAPTION_PREVIEW);

        final boolean enabled = mCaptioningManager.isEnabled();
        mPreviewText = captionPreview.findViewById(R.id.preview_text);
        mPreviewText.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);

        mPreviewWindow = captionPreview.findViewById(R.id.preview_window);

        mPreviewViewport = captionPreview.findViewById(R.id.preview_viewport);
        mPreviewViewport.addOnLayoutChangeListener(
                (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom)
                        -> refreshPreviewText());

        mLocale = (LocalePreference) findPreference(PREF_LOCALE);
        mFontSize = (ListPreference) findPreference(PREF_FONT_SIZE);