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; |
11 import android.os.Build; | 11 import android.os.Build; |
12 import android.os.Bundle; | 12 import android.os.Bundle; |
13 import android.text.SpannableString; | 13 import android.text.SpannableString; |
14 import android.text.style.ForegroundColorSpan; | 14 import android.text.style.ForegroundColorSpan; |
15 import android.view.LayoutInflater; | 15 import android.view.LayoutInflater; |
16 import android.view.View; | 16 import android.view.View; |
17 import android.view.View.AccessibilityDelegate; | 17 import android.view.View.AccessibilityDelegate; |
18 import android.view.View.OnClickListener; | 18 import android.view.View.OnClickListener; |
19 import android.view.ViewGroup; | 19 import android.view.ViewGroup; |
20 import android.view.accessibility.AccessibilityEvent; | 20 import android.view.accessibility.AccessibilityEvent; |
21 import android.view.accessibility.AccessibilityNodeInfo; | 21 import android.view.accessibility.AccessibilityNodeInfo; |
22 import android.widget.BaseAdapter; | 22 import android.widget.BaseAdapter; |
23 import android.widget.RadioButton; | 23 import android.widget.RadioButton; |
24 import android.widget.TextView; | 24 import android.widget.TextView; |
25 | 25 |
26 import org.chromium.base.ApiCompatibilityUtils; | 26 import org.chromium.base.ApiCompatibilityUtils; |
27 import org.chromium.base.ContextUtils; | 27 import org.chromium.base.ContextUtils; |
| 28 import org.chromium.base.LocationUtils; |
28 import org.chromium.chrome.R; | 29 import org.chromium.chrome.R; |
29 import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; | 30 import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; |
30 import org.chromium.chrome.browser.preferences.website.ContentSetting; | 31 import org.chromium.chrome.browser.preferences.website.ContentSetting; |
31 import org.chromium.chrome.browser.preferences.website.GeolocationInfo; | 32 import org.chromium.chrome.browser.preferences.website.GeolocationInfo; |
32 import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences; | 33 import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences; |
33 import org.chromium.chrome.browser.preferences.website.WebsitePreferenceBridge; | 34 import org.chromium.chrome.browser.preferences.website.WebsitePreferenceBridge; |
34 import org.chromium.chrome.browser.search_engines.TemplateUrlService; | 35 import org.chromium.chrome.browser.search_engines.TemplateUrlService; |
35 import org.chromium.chrome.browser.search_engines.TemplateUrlService.LoadListene
r; | 36 import org.chromium.chrome.browser.search_engines.TemplateUrlService.LoadListene
r; |
36 import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl
; | 37 import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl
; |
37 import org.chromium.ui.text.SpanApplier; | 38 import org.chromium.ui.text.SpanApplier; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 info.setCheckable(true); | 198 info.setCheckable(true); |
198 info.setChecked(selected); | 199 info.setChecked(selected); |
199 } | 200 } |
200 }); | 201 }); |
201 | 202 |
202 TextView link = (TextView) view.findViewById(R.id.link); | 203 TextView link = (TextView) view.findViewById(R.id.link); |
203 link.setVisibility(selected ? View.VISIBLE : View.GONE); | 204 link.setVisibility(selected ? View.VISIBLE : View.GONE); |
204 if (selected) { | 205 if (selected) { |
205 ForegroundColorSpan linkSpan = new ForegroundColorSpan( | 206 ForegroundColorSpan linkSpan = new ForegroundColorSpan( |
206 ApiCompatibilityUtils.getColor(resources, R.color.pref_accen
t_color)); | 207 ApiCompatibilityUtils.getColor(resources, R.color.pref_accen
t_color)); |
207 if (LocationSettings.getInstance().isSystemLocationSettingEnabled())
{ | 208 if (LocationUtils.getInstance().isSystemLocationSettingEnabled(mCont
ext)) { |
208 String message = mContext.getString( | 209 String message = mContext.getString( |
209 locationEnabled(position, true) | 210 locationEnabled(position, true) |
210 ? R.string.search_engine_location_allowed | 211 ? R.string.search_engine_location_allowed |
211 : R.string.search_engine_location_blocked); | 212 : R.string.search_engine_location_blocked); |
212 SpannableString messageWithLink = new SpannableString(message); | 213 SpannableString messageWithLink = new SpannableString(message); |
213 messageWithLink.setSpan(linkSpan, 0, messageWithLink.length(), 0
); | 214 messageWithLink.setSpan(linkSpan, 0, messageWithLink.length(), 0
); |
214 link.setText(messageWithLink); | 215 link.setText(messageWithLink); |
215 } else { | 216 } else { |
216 link.setText(SpanApplier.applySpans( | 217 link.setText(SpanApplier.applySpans( |
217 mContext.getString(R.string.android_location_off), | 218 mContext.getString(R.string.android_location_off), |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 TemplateUrlService.getInstance().setSearchEngine(toIndex(mSelectedSearch
EnginePosition)); | 264 TemplateUrlService.getInstance().setSearchEngine(toIndex(mSelectedSearch
EnginePosition)); |
264 | 265 |
265 // Report the change back. | 266 // Report the change back. |
266 TemplateUrl templateUrl = mSearchEngines.get(mSelectedSearchEnginePositi
on); | 267 TemplateUrl templateUrl = mSearchEngines.get(mSelectedSearchEnginePositi
on); |
267 mCallback.currentSearchEngineDetermined(templateUrl.getShortName()); | 268 mCallback.currentSearchEngineDetermined(templateUrl.getShortName()); |
268 | 269 |
269 notifyDataSetChanged(); | 270 notifyDataSetChanged(); |
270 } | 271 } |
271 | 272 |
272 private void onLocationLinkClicked() { | 273 private void onLocationLinkClicked() { |
273 if (!LocationSettings.getInstance().isSystemLocationSettingEnabled()) { | 274 if (!LocationUtils.getInstance().isSystemLocationSettingEnabled(mContext
)) { |
274 mContext.startActivity( | 275 mContext.startActivity( |
275 LocationSettings.getInstance().getSystemLocationSettingsInte
nt()); | 276 LocationUtils.getInstance().getSystemLocationSettingsIntent(
)); |
276 } else { | 277 } else { |
277 Intent settingsIntent = PreferencesLauncher.createIntentForSettingsP
age( | 278 Intent settingsIntent = PreferencesLauncher.createIntentForSettingsP
age( |
278 mContext, SingleWebsitePreferences.class.getName()); | 279 mContext, SingleWebsitePreferences.class.getName()); |
279 String url = TemplateUrlService.getInstance().getSearchEngineUrlFrom
TemplateUrl( | 280 String url = TemplateUrlService.getInstance().getSearchEngineUrlFrom
TemplateUrl( |
280 toIndex(mSelectedSearchEnginePosition)); | 281 toIndex(mSelectedSearchEnginePosition)); |
281 Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsFor
Site(url); | 282 Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsFor
Site(url); |
282 fragmentArgs.putBoolean(SingleWebsitePreferences.EXTRA_LOCATION, | 283 fragmentArgs.putBoolean(SingleWebsitePreferences.EXTRA_LOCATION, |
283 locationEnabled(mSelectedSearchEnginePosition, true)); | 284 locationEnabled(mSelectedSearchEnginePosition, true)); |
284 settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, f
ragmentArgs); | 285 settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, f
ragmentArgs); |
285 mContext.startActivity(settingsIntent); | 286 mContext.startActivity(settingsIntent); |
286 } | 287 } |
287 mCallback.onDismissDialog(); | 288 mCallback.onDismissDialog(); |
288 } | 289 } |
289 | 290 |
290 private boolean locationEnabled(int position, boolean checkGeoHeader) { | 291 private boolean locationEnabled(int position, boolean checkGeoHeader) { |
291 if (position == -1) return false; | 292 if (position == -1) return false; |
292 | 293 |
293 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp
lateUrl( | 294 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp
lateUrl( |
294 toIndex(position)); | 295 toIndex(position)); |
295 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false)
; | 296 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false)
; |
296 ContentSetting locationPermission = locationSettings.getContentSetting()
; | 297 ContentSetting locationPermission = locationSettings.getContentSetting()
; |
297 // Handle the case where the geoHeader being sent when no permission has
been specified. | 298 // Handle the case where the geoHeader being sent when no permission has
been specified. |
298 if (locationPermission == ContentSetting.ASK && checkGeoHeader) { | 299 if (locationPermission == ContentSetting.ASK && checkGeoHeader) { |
299 return GeolocationHeader.isGeoHeaderEnabledForUrl(mContext, url, fal
se); | 300 return GeolocationHeader.isGeoHeaderEnabledForUrl(mContext, url, fal
se); |
300 } | 301 } |
301 return locationPermission == ContentSetting.ALLOW; | 302 return locationPermission == ContentSetting.ALLOW; |
302 } | 303 } |
303 } | 304 } |
OLD | NEW |