Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/SearchEngineAdapter.java

Issue 2038753004: Add a LocationUtils class to give all Chromium Android code access to location helpers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Adjust DEPS. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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;
37 import org.chromium.ui.text.SpanApplier; 38 import org.chromium.ui.text.SpanApplier;
38 import org.chromium.ui.text.SpanApplier.SpanInfo; 39 import org.chromium.ui.text.SpanApplier.SpanInfo;
39 40
40 import java.util.List; 41 import java.util.List;
41 42
42 /** 43 /**
43 * A custom adapter for listing search engines. 44 * A custom adapter for listing search engines.
44 */ 45 */
45 public class SearchEngineAdapter extends BaseAdapter implements LoadListener, On ClickListener { 46 public class SearchEngineAdapter extends BaseAdapter implements LoadListener, On ClickListener {
46 /** 47 /**
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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(LocationUtils.getInstance().getSystemLocation SettingsIntent());
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698