Merge "Fix preview image alignment issue due to clip padding." into qt-dev

This commit is contained in:
TreeHugger Robot
2019-05-15 22:01:06 +00:00
committed by Android (Google) Code Review
4 changed files with 48 additions and 76 deletions

View File

@@ -15,41 +15,32 @@
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<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="match_parent"
android:orientation="vertical" >
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="@dimen/captioning_preview_height"
android:contentDescription="@null"
android:scaleType="centerCrop"
android:src="@drawable/caption_background"/>
<FrameLayout
android:id="@+id/preview_viewport"
android:id="@+id/preview_window"
android:layout_width="match_parent"
android:layout_height="@dimen/captioning_preview_height" >
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:padding="16dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@null"
android:scaleType="centerCrop"
android:src="@drawable/caption_background" />
<FrameLayout
android:id="@+id/preview_window"
android:layout_width="match_parent"
<com.android.internal.widget.SubtitleView
android:id="@+id/preview_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:padding="16dp" >
<com.android.internal.widget.SubtitleView
android:id="@+id/preview_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/captioning_preview_text" />
</FrameLayout>
android:text="@string/captioning_preview_text"/>
</FrameLayout>
<FrameLayout
android:id="@+id/properties_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</FrameLayout>

View File

@@ -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"

View File

@@ -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" >

View File

@@ -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);
@@ -370,9 +343,9 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
/**
* Unpack the specified color value and update the preferences.
*
* @param color color preference
* @param color color preference
* @param opacity opacity preference
* @param value packed value
* @param value packed value
*/
private void parseColorOpacity(ColorPreference color, ColorPreference opacity, int value) {
final int colorValue;