| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.preferences; | 5 package org.chromium.chrome.browser.preferences; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.Intent; | 8 import android.content.Intent; |
| 9 import android.content.SharedPreferences; | 9 import android.content.SharedPreferences; |
| 10 import android.content.res.Resources; | 10 import android.content.res.Resources; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 import org.chromium.base.ContextUtils; | 27 import org.chromium.base.ContextUtils; |
| 28 import org.chromium.chrome.R; | 28 import org.chromium.chrome.R; |
| 29 import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; | 29 import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; |
| 30 import org.chromium.chrome.browser.preferences.website.ContentSetting; | 30 import org.chromium.chrome.browser.preferences.website.ContentSetting; |
| 31 import org.chromium.chrome.browser.preferences.website.GeolocationInfo; | 31 import org.chromium.chrome.browser.preferences.website.GeolocationInfo; |
| 32 import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences; | 32 import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences; |
| 33 import org.chromium.chrome.browser.preferences.website.WebsitePreferenceBridge; | 33 import org.chromium.chrome.browser.preferences.website.WebsitePreferenceBridge; |
| 34 import org.chromium.chrome.browser.search_engines.TemplateUrlService; | 34 import org.chromium.chrome.browser.search_engines.TemplateUrlService; |
| 35 import org.chromium.chrome.browser.search_engines.TemplateUrlService.LoadListene
r; | 35 import org.chromium.chrome.browser.search_engines.TemplateUrlService.LoadListene
r; |
| 36 import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl
; | 36 import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl
; |
| 37 import org.chromium.components.location.LocationUtils; | |
| 38 import org.chromium.ui.text.SpanApplier; | 37 import org.chromium.ui.text.SpanApplier; |
| 39 import org.chromium.ui.text.SpanApplier.SpanInfo; | 38 import org.chromium.ui.text.SpanApplier.SpanInfo; |
| 40 | 39 |
| 41 import java.util.List; | 40 import java.util.List; |
| 42 | 41 |
| 43 /** | 42 /** |
| 44 * A custom adapter for listing search engines. | 43 * A custom adapter for listing search engines. |
| 45 */ | 44 */ |
| 46 public class SearchEngineAdapter extends BaseAdapter implements LoadListener, On
ClickListener { | 45 public class SearchEngineAdapter extends BaseAdapter implements LoadListener, On
ClickListener { |
| 47 /** | 46 /** |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 info.setCheckable(true); | 197 info.setCheckable(true); |
| 199 info.setChecked(selected); | 198 info.setChecked(selected); |
| 200 } | 199 } |
| 201 }); | 200 }); |
| 202 | 201 |
| 203 TextView link = (TextView) view.findViewById(R.id.link); | 202 TextView link = (TextView) view.findViewById(R.id.link); |
| 204 link.setVisibility(selected ? View.VISIBLE : View.GONE); | 203 link.setVisibility(selected ? View.VISIBLE : View.GONE); |
| 205 if (selected) { | 204 if (selected) { |
| 206 ForegroundColorSpan linkSpan = new ForegroundColorSpan( | 205 ForegroundColorSpan linkSpan = new ForegroundColorSpan( |
| 207 ApiCompatibilityUtils.getColor(resources, R.color.pref_accen
t_color)); | 206 ApiCompatibilityUtils.getColor(resources, R.color.pref_accen
t_color)); |
| 208 if (LocationUtils.getInstance().isSystemLocationSettingEnabled(mCont
ext)) { | 207 if (LocationSettings.getInstance().isSystemLocationSettingEnabled())
{ |
| 209 String message = mContext.getString( | 208 String message = mContext.getString( |
| 210 locationEnabled(position, true) | 209 locationEnabled(position, true) |
| 211 ? R.string.search_engine_location_allowed | 210 ? R.string.search_engine_location_allowed |
| 212 : R.string.search_engine_location_blocked); | 211 : R.string.search_engine_location_blocked); |
| 213 SpannableString messageWithLink = new SpannableString(message); | 212 SpannableString messageWithLink = new SpannableString(message); |
| 214 messageWithLink.setSpan(linkSpan, 0, messageWithLink.length(), 0
); | 213 messageWithLink.setSpan(linkSpan, 0, messageWithLink.length(), 0
); |
| 215 link.setText(messageWithLink); | 214 link.setText(messageWithLink); |
| 216 } else { | 215 } else { |
| 217 link.setText(SpanApplier.applySpans( | 216 link.setText(SpanApplier.applySpans( |
| 218 mContext.getString(R.string.android_location_off), | 217 mContext.getString(R.string.android_location_off), |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 TemplateUrlService.getInstance().setSearchEngine(toIndex(mSelectedSearch
EnginePosition)); | 263 TemplateUrlService.getInstance().setSearchEngine(toIndex(mSelectedSearch
EnginePosition)); |
| 265 | 264 |
| 266 // Report the change back. | 265 // Report the change back. |
| 267 TemplateUrl templateUrl = mSearchEngines.get(mSelectedSearchEnginePositi
on); | 266 TemplateUrl templateUrl = mSearchEngines.get(mSelectedSearchEnginePositi
on); |
| 268 mCallback.currentSearchEngineDetermined(templateUrl.getShortName()); | 267 mCallback.currentSearchEngineDetermined(templateUrl.getShortName()); |
| 269 | 268 |
| 270 notifyDataSetChanged(); | 269 notifyDataSetChanged(); |
| 271 } | 270 } |
| 272 | 271 |
| 273 private void onLocationLinkClicked() { | 272 private void onLocationLinkClicked() { |
| 274 if (!LocationUtils.getInstance().isSystemLocationSettingEnabled(mContext
)) { | 273 if (!LocationSettings.getInstance().isSystemLocationSettingEnabled()) { |
| 275 mContext.startActivity(LocationUtils.getInstance().getSystemLocation
SettingsIntent()); | 274 mContext.startActivity( |
| 275 LocationSettings.getInstance().getSystemLocationSettingsInte
nt()); |
| 276 } else { | 276 } else { |
| 277 Intent settingsIntent = PreferencesLauncher.createIntentForSettingsP
age( | 277 Intent settingsIntent = PreferencesLauncher.createIntentForSettingsP
age( |
| 278 mContext, SingleWebsitePreferences.class.getName()); | 278 mContext, SingleWebsitePreferences.class.getName()); |
| 279 String url = TemplateUrlService.getInstance().getSearchEngineUrlFrom
TemplateUrl( | 279 String url = TemplateUrlService.getInstance().getSearchEngineUrlFrom
TemplateUrl( |
| 280 toIndex(mSelectedSearchEnginePosition)); | 280 toIndex(mSelectedSearchEnginePosition)); |
| 281 Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsFor
Site(url); | 281 Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsFor
Site(url); |
| 282 fragmentArgs.putBoolean(SingleWebsitePreferences.EXTRA_LOCATION, | 282 fragmentArgs.putBoolean(SingleWebsitePreferences.EXTRA_LOCATION, |
| 283 locationEnabled(mSelectedSearchEnginePosition, true)); | 283 locationEnabled(mSelectedSearchEnginePosition, true)); |
| 284 settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, f
ragmentArgs); | 284 settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, f
ragmentArgs); |
| 285 mContext.startActivity(settingsIntent); | 285 mContext.startActivity(settingsIntent); |
| 286 } | 286 } |
| 287 mCallback.onDismissDialog(); | 287 mCallback.onDismissDialog(); |
| 288 } | 288 } |
| 289 | 289 |
| 290 private boolean locationEnabled(int position, boolean checkGeoHeader) { | 290 private boolean locationEnabled(int position, boolean checkGeoHeader) { |
| 291 if (position == -1) return false; | 291 if (position == -1) return false; |
| 292 | 292 |
| 293 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp
lateUrl( | 293 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp
lateUrl( |
| 294 toIndex(position)); | 294 toIndex(position)); |
| 295 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false)
; | 295 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false)
; |
| 296 ContentSetting locationPermission = locationSettings.getContentSetting()
; | 296 ContentSetting locationPermission = locationSettings.getContentSetting()
; |
| 297 // Handle the case where the geoHeader being sent when no permission has
been specified. | 297 // Handle the case where the geoHeader being sent when no permission has
been specified. |
| 298 if (locationPermission == ContentSetting.ASK && checkGeoHeader) { | 298 if (locationPermission == ContentSetting.ASK && checkGeoHeader) { |
| 299 return GeolocationHeader.isGeoHeaderEnabledForUrl(mContext, url, fal
se); | 299 return GeolocationHeader.isGeoHeaderEnabledForUrl(mContext, url, fal
se); |
| 300 } | 300 } |
| 301 return locationPermission == ContentSetting.ALLOW; | 301 return locationPermission == ContentSetting.ALLOW; |
| 302 } | 302 } |
| 303 } | 303 } |
| OLD | NEW |