Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/SearchEngineAdapter.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/SearchEngineAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/SearchEngineAdapter.java |
| index 792ea9b31ae8182bf99982129943194274e2f44c..611f5067a1263b80b38ea343307355fbc3eaf047 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/SearchEngineAdapter.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/SearchEngineAdapter.java |
| @@ -40,6 +40,7 @@ import org.chromium.ui.text.SpanApplier.SpanInfo; |
| import java.util.List; |
| + |
| /** |
| * A custom adapter for listing search engines. |
| */ |
| @@ -205,23 +206,27 @@ public class SearchEngineAdapter extends BaseAdapter implements LoadListener, On |
| TextView link = (TextView) view.findViewById(R.id.link); |
| link.setVisibility(selected ? View.VISIBLE : View.GONE); |
| if (selected) { |
| - ForegroundColorSpan linkSpan = new ForegroundColorSpan( |
| - ApiCompatibilityUtils.getColor(resources, R.color.pref_accent_color)); |
| - if (LocationUtils.getInstance().isSystemLocationSettingEnabled()) { |
| - String message = mContext.getString( |
| - locationEnabled(position, true) |
| - ? R.string.search_engine_location_allowed |
| - : R.string.search_engine_location_blocked); |
| - SpannableString messageWithLink = new SpannableString(message); |
| - messageWithLink.setSpan(linkSpan, 0, messageWithLink.length(), 0); |
| - link.setText(messageWithLink); |
| + if (!shouldShowLocationInfo(position)) { |
| + link.setVisibility(View.GONE); |
| } else { |
| - link.setText(SpanApplier.applySpans( |
| - mContext.getString(R.string.android_location_off), |
| - new SpanInfo("<link>", "</link>", linkSpan))); |
| + ForegroundColorSpan linkSpan = new ForegroundColorSpan( |
| + ApiCompatibilityUtils.getColor(resources, R.color.pref_accent_color)); |
| + if (LocationUtils.getInstance().isSystemLocationSettingEnabled()) { |
|
Peter Kasting
2016/11/17 23:12:05
Is this condition, in this nested case, still what
ltian
2016/11/18 00:17:36
That part is necessary. Here the "system location"
Peter Kasting
2016/11/18 00:24:47
Right, that was the UI I figured was here.
I gues
|
| + String message = mContext.getString( |
| + locationEnabled(position, true) |
| + ? R.string.search_engine_location_allowed |
| + : R.string.search_engine_location_blocked); |
| + SpannableString messageWithLink = new SpannableString(message); |
| + messageWithLink.setSpan(linkSpan, 0, messageWithLink.length(), 0); |
| + link.setText(messageWithLink); |
| + } else { |
| + link.setText(SpanApplier.applySpans( |
| + mContext.getString(R.string.android_location_off), |
| + new SpanInfo("<link>", "</link>", linkSpan))); |
| + } |
| + |
| + link.setOnClickListener(this); |
| } |
| - |
| - link.setOnClickListener(this); |
| } |
| return view; |
| @@ -300,4 +305,15 @@ public class SearchEngineAdapter extends BaseAdapter implements LoadListener, On |
| } |
| return locationPermission == ContentSetting.ALLOW; |
| } |
| + |
| + private boolean shouldShowLocationInfo(int position) { |
| + String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemplateUrl( |
| + toIndex(position)); |
| + GeolocationInfo locationSettings = new GeolocationInfo(url, null, false); |
| + ContentSetting locationPermission = locationSettings.getContentSetting(); |
|
Peter Kasting
2016/11/17 23:12:05
This code seems like it partially duplicates locat
ltian
2016/11/18 00:17:36
I thought about it before but the two functions lo
Peter Kasting
2016/11/18 00:24:47
I think we want something like the following (over
|
| + // For Google search engine, if location permission is granted for the whole app, |
| + // even its own location permission is unset, its location permission is still granted. |
| + return locationPermission != ContentSetting.ASK |
| + || GeolocationHeader.isGeoHeaderEnabledForUrl(mContext, url, false); |
| + } |
| } |