Commit 7ac50770 authored by Natalie Chouinard's avatar Natalie Chouinard Committed by Commit Bot

[Preferences] Use getListView() over R.id.list

The usage of R.id.list here causes problems when updating support
library version. Switch to the PreferenceFragmentCompat.getListView()
method instead.

Also add some clarification about when to use
getShowShadowOnScrollListener in preference fragments, and document the
lack of such listener on SearchEnginePreference with a TODO.

Bug: 987748
Change-Id: Ieb76455e6744ec1ed0f300c8fe0914ed630e3562
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1725099Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Natalie Chouinard <chouinard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682333}
parent e5a1aeda
...@@ -24,8 +24,6 @@ import android.util.Log; ...@@ -24,8 +24,6 @@ import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
...@@ -40,12 +38,13 @@ import org.chromium.chrome.browser.profiles.ProfileManagerUtils; ...@@ -40,12 +38,13 @@ import org.chromium.chrome.browser.profiles.ProfileManagerUtils;
/** /**
* The Chrome settings activity. * The Chrome settings activity.
* *
* This activity displays a single Fragment, typically a PreferenceFragment. As the user navigates * This activity displays a single {@link Fragment}, typically a {@link PreferenceFragmentCompat}.
* through settings, a separate Preferences activity is created for each screen. Thus each fragment * As the user navigates through settings, a separate Preferences activity is created for each
* may freely modify its activity's action bar or title. This mimics the behavior of * screen. Thus each fragment may freely modify its activity's action bar or title. This mimics the
* android.preference.PreferenceActivity. * behavior of {@link android.preference.PreferenceActivity}.
* *
* If the preference overrides the root layout (e.g. {@link HomepageEditor}), add the following: * If the main fragment is not an instance of {@link PreferenceFragmentCompat} (e.g. {@link
* HomepageEditor}) or overrides {@link PreferenceFragmentCompat}'s layout, add the following:
* 1) preferences_action_bar_shadow.xml to the custom XML hierarchy and * 1) preferences_action_bar_shadow.xml to the custom XML hierarchy and
* 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(...).
...@@ -162,18 +161,22 @@ public class Preferences extends ChromeBaseAppCompatActivity ...@@ -162,18 +161,22 @@ public class Preferences extends ChromeBaseAppCompatActivity
@Override @Override
public void onAttachedToWindow() { public void onAttachedToWindow() {
super.onAttachedToWindow(); super.onAttachedToWindow();
Fragment fragment = getMainFragment(); Fragment fragment = getMainFragment();
if (fragment == null || fragment.getView() == null if (!(fragment instanceof PreferenceFragmentCompat)) {
|| fragment.getView().findViewById(R.id.list) == null) {
return; return;
} }
View contentView = fragment.getActivity().findViewById(android.R.id.content);
if (contentView == null || !(contentView instanceof FrameLayout)) { RecyclerView recyclerView = ((PreferenceFragmentCompat) fragment).getListView();
if (recyclerView == null) {
return; return;
} }
View inflatedView = View.inflate(getApplicationContext(),
R.layout.preferences_action_bar_shadow, (ViewGroup) contentView); // Append action bar shadow to layout.
RecyclerView recyclerView = fragment.getView().findViewById(R.id.list); View inflatedView = getLayoutInflater().inflate(
R.layout.preferences_action_bar_shadow, findViewById(android.R.id.content));
// Display shadow on scroll.
recyclerView.getViewTreeObserver().addOnScrollChangedListener( recyclerView.getViewTreeObserver().addOnScrollChangedListener(
PreferenceUtils.getShowShadowOnScrollListener( PreferenceUtils.getShowShadowOnScrollListener(
recyclerView, inflatedView.findViewById(R.id.shadow))); recyclerView, inflatedView.findViewById(R.id.shadow)));
......
...@@ -13,8 +13,10 @@ import org.chromium.base.VisibleForTesting; ...@@ -13,8 +13,10 @@ import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R; import org.chromium.chrome.R;
/** /**
* A preference fragment for selecting a default search engine. * A preference fragment for selecting a default search engine.
*/ *
* TODO(crbug.com/988877): Add on scroll shadow to action bar.
*/
public class SearchEnginePreference extends ListFragment { public class SearchEnginePreference extends ListFragment {
private SearchEngineAdapter mSearchEngineAdapter; private SearchEngineAdapter mSearchEngineAdapter;
......
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