Commit 06faec94 authored by Natalie Chouinard's avatar Natalie Chouinard Committed by Commit Bot

Migrate About Chrome settings page

Migrate the About Chrome settings page to the Preference Support
Library. This is the first page migrated, so it includes the
initial set of necessary styles, layouts, and special handling
code to support both Framework and Support Library Preferences
simultaneously. These layouts and styles will be expanded
incrementally as we migrate more complex settings pages.

The net effect of this migration is expected to be a reduction in
method count and binary size, but first CLs will cause increases.

Bug: 966075
Binary-Size: New pref support library usage
Change-Id: I714e7bed76c715357c1055a0f7d4a07211029c29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1614475
Commit-Queue: Natalie Chouinard <chouinard@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665251}
parent 9841fcd5
...@@ -121,6 +121,7 @@ android_resources("chrome_app_java_resources") { ...@@ -121,6 +121,7 @@ android_resources("chrome_app_java_resources") {
"//third_party/android_deps:android_support_v7_appcompat_java", "//third_party/android_deps:android_support_v7_appcompat_java",
"//third_party/android_deps:com_android_support_design_java", "//third_party/android_deps:com_android_support_design_java",
"//third_party/android_deps:com_android_support_gridlayout_v7_java", "//third_party/android_deps:com_android_support_gridlayout_v7_java",
"//third_party/android_deps:com_android_support_preference_v7_java",
"//third_party/android_deps:com_android_support_recyclerview_v7_java", "//third_party/android_deps:com_android_support_recyclerview_v7_java",
] ]
custom_package = "org.chromium.chrome" custom_package = "org.chromium.chrome"
...@@ -818,6 +819,7 @@ android_library("chrome_test_java") { ...@@ -818,6 +819,7 @@ android_library("chrome_test_java") {
"//third_party/android_deps:android_arch_lifecycle_common_java", "//third_party/android_deps:android_arch_lifecycle_common_java",
"//third_party/android_deps:android_support_v7_appcompat_java", "//third_party/android_deps:android_support_v7_appcompat_java",
"//third_party/android_deps:com_android_support_design_java", "//third_party/android_deps:com_android_support_design_java",
"//third_party/android_deps:com_android_support_preference_v7_java",
"//third_party/android_deps:com_android_support_recyclerview_v7_java", "//third_party/android_deps:com_android_support_recyclerview_v7_java",
"//third_party/android_deps:com_android_support_support_annotations_java", "//third_party/android_deps:com_android_support_support_annotations_java",
"//third_party/android_deps:com_google_ar_core_java", "//third_party/android_deps:com_google_ar_core_java",
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<!-- KitKat Preference Fragments should have a slightly inset divider to match the system
preferences styling. On Lollipop+, the ?android:attr/listDivider (which extends edge-to-edge)
can be used. -->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="@dimen/pref_list_padding_kitkat"
android:insetRight="@dimen/pref_list_padding_kitkat">
<shape>
<solid android:color="@color/divider_bg_color" />
<size
android:width="1dp"
android:height="1dp" />
</shape>
</inset>
\ No newline at end of file
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
style="@style/PreferenceLayout" style="@style/PreferenceLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<!-- TODO(chouinard): For now this supports simple text-only preferences, but more children will be
added to this layout in the near future as we migrate more complex preferences. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/PreferenceLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:background="?android:attr/selectableItemBackground"
android:focusable="true"
android:baselineAligned="false">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView android:id="@android:id/title"
style="@style/PreferenceTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:id="@android:id/summary"
style="@style/PreferenceSummary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:layout_alignStart="@android:id/title" />
</RelativeLayout>
</LinearLayout>
...@@ -155,6 +155,7 @@ ...@@ -155,6 +155,7 @@
<item name="android:textAppearanceSmall">@style/TextAppearance.BlackBody</item> <item name="android:textAppearanceSmall">@style/TextAppearance.BlackBody</item>
<item name="android:preferenceCategoryStyle">@style/PreferenceCategory</item> <item name="android:preferenceCategoryStyle">@style/PreferenceCategory</item>
<item name="android:windowContentOverlay">@null</item> <item name="android:windowContentOverlay">@null</item>
<item name="preferenceTheme">@style/Theme.Chromium.PreferenceTheme</item>
</style> </style>
<style name="Theme.Chromium.Preferences.ManageSpace"> <style name="Theme.Chromium.Preferences.ManageSpace">
...@@ -241,6 +242,25 @@ ...@@ -241,6 +242,25 @@
<style name="OverflowMenuThemeOverlay" parent="Base.OverflowMenuThemeOverlay" /> <style name="OverflowMenuThemeOverlay" parent="Base.OverflowMenuThemeOverlay" />
<!-- Preferences styles --> <!-- Preferences styles -->
<style name="Theme.Chromium.PreferenceTheme">
<item name="preferenceStyle">@style/Theme.Chromium.PreferenceItem</item>
<item name="preferenceFragmentCompatStyle">@style/Theme.Chromium.PreferenceFragment</item>
<item name="preferenceFragmentListStyle">@style/Theme.Chromium.PreferenceFragmentList</item>
</style>
<style name="Theme.Chromium.PreferenceFragment">
<item name="android:divider">@drawable/list_divider_compat</item>
</style>
<style name="Theme.Chromium.PreferenceItem">
<item name="android:layout">@layout/preference_compat</item>
</style>
<style name="Theme.Chromium.PreferenceFragmentList">
<item name="android:paddingStart">@dimen/pref_list_padding_kitkat</item>
<item name="android:paddingEnd">@dimen/pref_list_padding_kitkat</item>
</style>
<style name="PreferenceActionBarModern" parent="@style/Widget.AppCompat.Light.ActionBar.Solid"> <style name="PreferenceActionBarModern" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="titleTextStyle">@style/TextAppearance.BlackHeadline</item> <item name="titleTextStyle">@style/TextAppearance.BlackHeadline</item>
</style> </style>
...@@ -266,7 +286,7 @@ ...@@ -266,7 +286,7 @@
<style name="PreferenceTitle"> <style name="PreferenceTitle">
<item name="android:ellipsize">end</item> <item name="android:ellipsize">end</item>
<item name="android:singleLine">true</item> <item name="android:singleLine">true</item>
<item name="android:textAppearance">?android:attr/textAppearanceMedium</item> <item name="android:textAppearance">@style/TextAppearance.PreferenceMediumText</item>
</style> </style>
<style name="PreferenceSummary"> <style name="PreferenceSummary">
<item name="android:textAppearance">@style/TextAppearance.BlackBody</item> <item name="android:textAppearance">@style/TextAppearance.BlackBody</item>
......
...@@ -22,7 +22,18 @@ ...@@ -22,7 +22,18 @@
<!-- Overriding alertDialogTheme pre-v21 with our custom AlertDialog theme causes bad visual <!-- Overriding alertDialogTheme pre-v21 with our custom AlertDialog theme causes bad visual
states on ListPreference because we don't use the support library ListPreference. --> states on ListPreference because we don't use the support library ListPreference. -->
<item name="android:alertDialogTheme">@style/Theme.Chromium.AlertDialog</item> <item name="android:alertDialogTheme">@style/Theme.Chromium.AlertDialog</item>
<item name="preferenceTheme">@style/Theme.Chromium.PreferenceTheme</item>
</style> </style>
<style name="Theme.Chromium.PreferenceFragment">
<item name="android:divider">?android:attr/listDivider</item>
</style>
<style name="Theme.Chromium.PreferenceFragmentList">
<item name="android:paddingStart">0dp</item>
<item name="android:paddingEnd">0dp</item>
</style>
<style name="PreferenceCategoryWithButtonStyle"> <style name="PreferenceCategoryWithButtonStyle">
<item name="android:paddingStart">?android:attr/listPreferredItemPaddingStart</item> <item name="android:paddingStart">?android:attr/listPreferredItemPaddingStart</item>
<item name="android:paddingEnd">4dp</item> <item name="android:paddingEnd">4dp</item>
......
...@@ -482,6 +482,7 @@ ...@@ -482,6 +482,7 @@
<dimen name="pref_autofill_touch_target_padding">15dp</dimen> <dimen name="pref_autofill_touch_target_padding">15dp</dimen>
<dimen name="pref_icon_padding">4.6dp</dimen> <dimen name="pref_icon_padding">4.6dp</dimen>
<dimen name="pref_list_padding_kitkat">16dp</dimen>
<dimen name="pref_spinner_padding_end">8dp</dimen> <dimen name="pref_spinner_padding_end">8dp</dimen>
<dimen name="pref_languages_padding">16dp</dimen> <dimen name="pref_languages_padding">16dp</dimen>
......
...@@ -3,15 +3,15 @@ ...@@ -3,15 +3,15 @@
Use of this source code is governed by a BSD-style license that can be Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. --> found in the LICENSE file. -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference <android.support.v7.preference.Preference
android:key="application_version" android:key="application_version"
android:title="@string/application_version_title" /> android:title="@string/application_version_title" />
<org.chromium.chrome.browser.preferences.AboutChromePreferenceOSVersion <org.chromium.chrome.browser.preferences.AboutChromePreferenceOSVersion
android:key="os_version" android:key="os_version"
android:title="@string/os_version_title" /> android:title="@string/os_version_title" />
<Preference <android.support.v7.preference.Preference
android:fragment="org.chromium.chrome.browser.preferences.LegalInformationPreferences" android:fragment="org.chromium.chrome.browser.preferences.LegalInformationPreferences"
android:key="legal_information" android:key="legal_information"
android:title="@string/legal_information_title" /> android:title="@string/legal_information_title" />
</PreferenceScreen> </android.support.v7.preference.PreferenceScreen>
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
package org.chromium.chrome.browser.preferences; package org.chromium.chrome.browser.preferences;
import android.content.Context; import android.content.Context;
import android.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
...@@ -26,11 +27,11 @@ public class AboutChromePreferenceOSVersion extends Preference { ...@@ -26,11 +27,11 @@ public class AboutChromePreferenceOSVersion extends Preference {
} }
@Override @Override
protected void onBindView(View view) { public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindView(view); super.onBindViewHolder(holder);
// Show additional information only if the OS version is not supported. // Show additional information only if the OS version is not supported.
if (VersionNumberGetter.isCurrentOsVersionSupported()) return; if (VersionNumberGetter.isCurrentOsVersionSupported()) return;
view.findViewById(R.id.os_deprecation_warning).setVisibility(View.VISIBLE); holder.findViewById(R.id.os_deprecation_warning).setVisibility(View.VISIBLE);
} }
} }
...@@ -8,8 +8,8 @@ import android.content.Context; ...@@ -8,8 +8,8 @@ import android.content.Context;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference; import android.support.v7.preference.Preference;
import android.preference.PreferenceFragment; import android.support.v7.preference.PreferenceFragmentCompat;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -24,7 +24,7 @@ import java.util.Calendar; ...@@ -24,7 +24,7 @@ import java.util.Calendar;
* Settings fragment that displays information about Chrome. * Settings fragment that displays information about Chrome.
*/ */
public class AboutChromePreferences public class AboutChromePreferences
extends PreferenceFragment implements Preference.OnPreferenceClickListener { extends PreferenceFragmentCompat implements Preference.OnPreferenceClickListener {
private static final int TAPS_FOR_DEVELOPER_PREFERENCES = 7; private static final int TAPS_FOR_DEVELOPER_PREFERENCES = 7;
private static final String PREF_APPLICATION_VERSION = "application_version"; private static final String PREF_APPLICATION_VERSION = "application_version";
...@@ -46,8 +46,7 @@ public class AboutChromePreferences ...@@ -46,8 +46,7 @@ public class AboutChromePreferences
private Toast mToast; private Toast mToast;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreatePreferences(Bundle bundle, String s) {
super.onCreate(savedInstanceState);
getActivity().setTitle(R.string.prefs_about_chrome); getActivity().setTitle(R.string.prefs_about_chrome);
PreferenceUtils.addPreferencesFromResource(this, R.xml.about_chrome_preferences); PreferenceUtils.addPreferencesFromResource(this, R.xml.about_chrome_preferences);
......
...@@ -14,6 +14,7 @@ import android.support.annotation.DrawableRes; ...@@ -14,6 +14,7 @@ import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.annotation.XmlRes; import android.support.annotation.XmlRes;
import android.support.v7.content.res.AppCompatResources; import android.support.v7.content.res.AppCompatResources;
import android.support.v7.preference.PreferenceFragmentCompat;
import android.support.v7.widget.ActionMenuView; import android.support.v7.widget.ActionMenuView;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -31,7 +32,10 @@ public class PreferenceUtils { ...@@ -31,7 +32,10 @@ public class PreferenceUtils {
* A helper that is used to load preferences from XML resources without causing a * A helper that is used to load preferences from XML resources without causing a
* StrictModeViolation. See http://crbug.com/692125. * StrictModeViolation. See http://crbug.com/692125.
* *
* @param preferenceFragment A PreferenceFragment. * TODO(crbug.com/967022): Once all {@link PreferenceFragment}s are migrated to the Support
* Library {@link PreferenceFragmentCompat}s, remove this method in favor of the below method.
*
* @param preferenceFragment A Framework {@link PreferenceFragment}.
* @param preferencesResId The id of the XML resource to add to the PreferenceFragment. * @param preferencesResId The id of the XML resource to add to the PreferenceFragment.
*/ */
public static void addPreferencesFromResource( public static void addPreferencesFromResource(
...@@ -44,6 +48,23 @@ public class PreferenceUtils { ...@@ -44,6 +48,23 @@ public class PreferenceUtils {
} }
} }
/**
* A helper that is used to load preferences from XML resources without causing a
* StrictModeViolation. See http://crbug.com/692125.
*
* @param preferenceFragment A Support Library {@link PreferenceFragmentCompat}.
* @param preferencesResId The id of the XML resource to add to the PreferenceFragment.
*/
public static void addPreferencesFromResource(
PreferenceFragmentCompat preferenceFragment, @XmlRes int preferencesResId) {
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
preferenceFragment.addPreferencesFromResource(preferencesResId);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
/** /**
* Returns a view tree observer to show the shadow if and only if the view is scrolled. * Returns a view tree observer to show the shadow if and only if the view is scrolled.
* @param view The view whose scroll will be detected to determine the shadow's visibility. * @param view The view whose scroll will be detected to determine the shadow's visibility.
......
...@@ -21,6 +21,8 @@ import android.preference.Preference; ...@@ -21,6 +21,8 @@ import android.preference.Preference;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.preference.PreferenceFragment.OnPreferenceStartFragmentCallback; import android.preference.PreferenceFragment.OnPreferenceStartFragmentCallback;
import android.support.graphics.drawable.VectorDrawableCompat; import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v7.preference.PreferenceFragmentCompat;
import android.support.v7.widget.RecyclerView;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
...@@ -52,8 +54,9 @@ import org.chromium.chrome.browser.profiles.ProfileManagerUtils; ...@@ -52,8 +54,9 @@ import org.chromium.chrome.browser.profiles.ProfileManagerUtils;
* 2) an OnScrollChangedListener to the main content's view's view tree observer via * 2) an OnScrollChangedListener to the main content's view's view tree observer via
* PreferenceUtils.getShowShadowOnScrollListener(...). * PreferenceUtils.getShowShadowOnScrollListener(...).
*/ */
public class Preferences public class Preferences extends ChromeBaseAppCompatActivity
extends ChromeBaseAppCompatActivity implements OnPreferenceStartFragmentCallback { implements OnPreferenceStartFragmentCallback,
PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
/** /**
* Preference fragments may implement this interface to intercept "Back" button taps in this * Preference fragments may implement this interface to intercept "Back" button taps in this
* activity. * activity.
...@@ -115,10 +118,22 @@ public class Preferences ...@@ -115,10 +118,22 @@ public class Preferences
// recreated and super.onCreate() has already recreated the fragment. // recreated and super.onCreate() has already recreated the fragment.
if (savedInstanceState == null) { if (savedInstanceState == null) {
if (initialFragment == null) initialFragment = MainPreferences.class.getName(); if (initialFragment == null) initialFragment = MainPreferences.class.getName();
Fragment fragment = Fragment.instantiate(this, initialFragment, initialArguments);
getFragmentManager().beginTransaction() if (isCompat(initialFragment)) {
.replace(android.R.id.content, fragment) android.support.v4.app.Fragment fragment =
.commit(); android.support.v4.app.Fragment.instantiate(
this, initialFragment, initialArguments);
getSupportFragmentManager()
.beginTransaction()
.replace(android.R.id.content, fragment)
.commit();
} else {
Fragment fragment = Fragment.instantiate(this, initialFragment, initialArguments);
getFragmentManager()
.beginTransaction()
.replace(android.R.id.content, fragment)
.commit();
}
} }
if (ApiCompatibilityUtils.checkPermission( if (ApiCompatibilityUtils.checkPermission(
...@@ -130,18 +145,45 @@ public class Preferences ...@@ -130,18 +145,45 @@ public class Preferences
if (nfcAdapter != null) nfcAdapter.setNdefPushMessage(null, this); if (nfcAdapter != null) nfcAdapter.setNdefPushMessage(null, this);
} }
Resources res = getResources(); Resources res = getResources();
ApiCompatibilityUtils.setTaskDescription(this, res.getString(R.string.app_name), ApiCompatibilityUtils.setTaskDescription(this, res.getString(R.string.app_name),
BitmapFactory.decodeResource(res, R.mipmap.app_icon), BitmapFactory.decodeResource(res, R.mipmap.app_icon),
ApiCompatibilityUtils.getColor(res, R.color.default_primary_color)); ApiCompatibilityUtils.getColor(res, R.color.default_primary_color));
} }
/**
* Given a Fragment class name (as a string), determine whether it is a Support Library Fragment
* class, as opposed to a Framework Fragment.
*
* TODO(crbug.com/967022): Remove this method once all fragments are migrated to the Support
* Library.
*
* @param fragmentClass The fully qualified class name of a Fragment.
* @return Whether the class represents a Support Library Fragment.
*/
private boolean isCompat(String fragmentClass) {
try {
return android.support.v4.app.Fragment.class.isAssignableFrom(
Class.forName(fragmentClass));
} catch (ClassNotFoundException e) {
return false;
}
}
// OnPreferenceStartFragmentCallback: // OnPreferenceStartFragmentCallback:
@Override @Override
public boolean onPreferenceStartFragment(PreferenceFragment preferenceFragment, // TODO(crbug.com/967022): Remove this method once all fragments are migrated to the Support
Preference preference) { // Library.
public boolean onPreferenceStartFragment(
PreferenceFragment preferenceFragment, Preference preference) {
startFragment(preference.getFragment(), preference.getExtras());
return true;
}
@Override
public boolean onPreferenceStartFragment(
PreferenceFragmentCompat caller, android.support.v7.preference.Preference preference) {
startFragment(preference.getFragment(), preference.getExtras()); startFragment(preference.getFragment(), preference.getExtras());
return true; return true;
} }
...@@ -164,16 +206,20 @@ public class Preferences ...@@ -164,16 +206,20 @@ public class Preferences
public void onAttachedToWindow() { public void onAttachedToWindow() {
super.onAttachedToWindow(); super.onAttachedToWindow();
Fragment fragment = getMainFragment(); Fragment fragment = getMainFragment();
if (fragment == null) {
onAttachedToWindowCompat();
return;
}
if (fragment.getView() == null
|| fragment.getView().findViewById(android.R.id.list) == null) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (fragment instanceof PreferenceFragment && fragment.getView() != null) { if (fragment instanceof PreferenceFragment && fragment.getView() != null) {
// Set list view padding to 0 so dividers are the full width of the screen. // Set list view padding to 0 so dividers are the full width of the screen.
fragment.getView().findViewById(android.R.id.list).setPadding(0, 0, 0, 0); fragment.getView().findViewById(android.R.id.list).setPadding(0, 0, 0, 0);
} }
} }
if (fragment == null || fragment.getView() == null
|| fragment.getView().findViewById(android.R.id.list) == null) {
return;
}
View contentView = fragment.getActivity().findViewById(android.R.id.content); View contentView = fragment.getActivity().findViewById(android.R.id.content);
if (contentView == null || !(contentView instanceof FrameLayout)) { if (contentView == null || !(contentView instanceof FrameLayout)) {
return; return;
...@@ -187,6 +233,36 @@ public class Preferences ...@@ -187,6 +233,36 @@ public class Preferences
listView, inflatedView.findViewById(R.id.shadow))); listView, inflatedView.findViewById(R.id.shadow)));
} }
/**
* This method performs similar actions to {@link #onAttachedToWindow()}, but modified for the
* case where the main fragment is a Support Library fragment.
*
* Differences include:
* * List ID reference is R.id.list instead of android.R.id.list.
* * The {@link ListView} is now a {@link RecyclerView}.
*
* TODO(crbug.com/967022): Once all fragments are migrated to the Support Library, replace
* {@link #onAttachedToWindow()} with this method body.
*/
public void onAttachedToWindowCompat() {
super.onAttachedToWindow();
android.support.v4.app.Fragment fragment = getMainFragmentCompat();
if (fragment == null || fragment.getView() == null
|| fragment.getView().findViewById(R.id.list) == null) {
return;
}
View contentView = fragment.getActivity().findViewById(android.R.id.content);
if (contentView == null || !(contentView instanceof FrameLayout)) {
return;
}
View inflatedView = View.inflate(getApplicationContext(),
R.layout.preferences_action_bar_shadow, (ViewGroup) contentView);
RecyclerView recyclerView = fragment.getView().findViewById(R.id.list);
recyclerView.getViewTreeObserver().addOnScrollChangedListener(
PreferenceUtils.getShowShadowOnScrollListener(
recyclerView, inflatedView.findViewById(R.id.shadow)));
}
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
...@@ -229,13 +305,29 @@ public class Preferences ...@@ -229,13 +305,29 @@ public class Preferences
} }
/** /**
* Returns the fragment showing as this activity's main content, typically a PreferenceFragment. * Returns the fragment showing as this activity's main content, typically a {@link
* This does not include DialogFragments or other Fragments shown on top of the main content. * PreferenceFragment}. This does not include {@link android.app.DialogFragment}s or other
* {@link Fragment}s shown on top of the main content.
*
* This method only returns Framework {@link Fragment}s. If the main fragment is a Support
* Library fragment (of type {@link android.support.v4.app.Fragment}), this method returns null.
*
* TODO(crbug.com/967022): Remove this method once all fragments are migrated to the Support
* Library.
*/ */
private Fragment getMainFragment() { private Fragment getMainFragment() {
return getFragmentManager().findFragmentById(android.R.id.content); return getFragmentManager().findFragmentById(android.R.id.content);
} }
/**
* This method should be called to retrieve the activity's main content if {@link
* #getMainFragment()} returned null, which may indicate that the main fragment is a Support
* Library fragment.
*/
private android.support.v4.app.Fragment getMainFragmentCompat() {
return getSupportFragmentManager().findFragmentById(android.R.id.content);
}
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment