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.VisibleForTesting; | |
29 import org.chromium.base.metrics.RecordUserAction; | |
28 import org.chromium.chrome.R; | 30 import org.chromium.chrome.R; |
31 import org.chromium.chrome.browser.locale.LocaleManager; | |
29 import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; | 32 import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; |
30 import org.chromium.chrome.browser.preferences.website.ContentSetting; | 33 import org.chromium.chrome.browser.preferences.website.ContentSetting; |
31 import org.chromium.chrome.browser.preferences.website.GeolocationInfo; | 34 import org.chromium.chrome.browser.preferences.website.GeolocationInfo; |
32 import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences; | 35 import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences; |
33 import org.chromium.chrome.browser.preferences.website.WebsitePreferenceBridge; | 36 import org.chromium.chrome.browser.preferences.website.WebsitePreferenceBridge; |
34 import org.chromium.chrome.browser.search_engines.TemplateUrlService; | 37 import org.chromium.chrome.browser.search_engines.TemplateUrlService; |
35 import org.chromium.chrome.browser.search_engines.TemplateUrlService.LoadListene r; | 38 import org.chromium.chrome.browser.search_engines.TemplateUrlService.LoadListene r; |
36 import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl ; | 39 import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl ; |
37 import org.chromium.components.location.LocationUtils; | 40 import org.chromium.components.location.LocationUtils; |
38 import org.chromium.ui.text.SpanApplier; | 41 import org.chromium.ui.text.SpanApplier; |
39 import org.chromium.ui.text.SpanApplier.SpanInfo; | 42 import org.chromium.ui.text.SpanApplier.SpanInfo; |
40 | 43 |
44 import java.util.ArrayList; | |
41 import java.util.List; | 45 import java.util.List; |
42 | 46 |
43 /** | 47 /** |
44 * A custom adapter for listing search engines. | 48 * A custom adapter for listing search engines. |
45 */ | 49 */ |
46 public class SearchEngineAdapter extends BaseAdapter implements LoadListener, On ClickListener { | 50 public class SearchEngineAdapter extends BaseAdapter implements LoadListener, On ClickListener { |
51 private static final int VIEW_TYPE_ITEM = 0; | |
52 private static final int VIEW_TYPE_DIVIDER = 1; | |
53 private static final int VIEW_TYPE_COUNT = 2; | |
54 | |
47 /** | 55 /** |
48 * A callback for reporting progress to the owner. | 56 * The current context. |
gone
2016/11/29 18:43:11
nit: You can save some room using the inline synta
ltian
2016/11/30 06:36:17
Done.
| |
49 */ | 57 */ |
50 public interface SelectSearchEngineCallback { | |
51 /** | |
52 * Called when the search engine data has loaded and we've determined th e currently active | |
53 * one. | |
54 * @param name Provides the name of it (with a simplified URL in parenth esis). | |
55 */ | |
56 void currentSearchEngineDetermined(int selectedIndex); | |
57 } | |
58 | |
59 // The current context. | |
60 private Context mContext; | 58 private Context mContext; |
61 | 59 |
62 // The layout inflater to use for the custom views. | 60 /** |
61 * The layout inflater to use for the custom views. | |
62 */ | |
63 private LayoutInflater mLayoutInflater; | 63 private LayoutInflater mLayoutInflater; |
64 | 64 |
65 // The callback to use for notifying caller of progress. | 65 /** |
66 private SelectSearchEngineCallback mCallback; | 66 * The list of prepopluated and default search engines. |
67 */ | |
68 private List<TemplateUrl> mPrepopulatedSearchEngines = new ArrayList<>(); | |
67 | 69 |
68 // The list of available search engines. | 70 /** |
69 private List<TemplateUrl> mSearchEngines; | 71 * The list of recently visited search engines. |
70 // The position (index into mSearchEngines) of the currently selected search engine. Can be -1 | 72 */ |
71 // if current search engine is managed and set to something other than the p re-populated values. | 73 private List<TemplateUrl> mRecentSearchEngines = new ArrayList<>(); |
74 | |
75 /** | |
76 * The position (index into mPrepopulatedSearchEngines) of the currently sel ected search engine. | |
77 * Can be -1 if current search engine is managed and set to something other than the | |
78 * pre-populated values. | |
79 */ | |
72 private int mSelectedSearchEnginePosition = -1; | 80 private int mSelectedSearchEnginePosition = -1; |
73 | 81 |
74 // The position of the default search engine before user's action. | 82 /** |
83 * The position of the default search engine before user's action. | |
84 */ | |
75 private int mInitialEnginePosition = -1; | 85 private int mInitialEnginePosition = -1; |
76 | 86 |
77 /** | 87 /** |
78 * Construct a SearchEngineAdapter. | 88 * Construct a SearchEngineAdapter. |
79 * @param context The current context. | 89 * @param context The current context. |
80 * @param callback The callback to use to communicate back. | |
81 */ | 90 */ |
82 public SearchEngineAdapter(Context context, SelectSearchEngineCallback callb ack) { | 91 public SearchEngineAdapter(Context context) { |
83 mContext = context; | 92 mContext = context; |
84 mLayoutInflater = (LayoutInflater) mContext.getSystemService( | 93 mLayoutInflater = (LayoutInflater) mContext.getSystemService( |
85 Context.LAYOUT_INFLATER_SERVICE); | 94 Context.LAYOUT_INFLATER_SERVICE); |
86 mCallback = callback; | |
87 | 95 |
88 initEntries(); | 96 initEntries(); |
89 } | 97 } |
90 | 98 |
91 /** | |
92 * @return The index of the selected engine before user's action. | |
93 */ | |
94 public int getInitialSearchEnginePosition() { | |
95 return mInitialEnginePosition; | |
96 } | |
97 | |
98 // Used for testing. | 99 // Used for testing. |
gone
2016/11/29 18:43:11
You can toss the comment now.
ltian
2016/11/30 06:36:17
Done.
| |
99 | 100 @VisibleForTesting |
100 String getValueForTesting() { | 101 String getValueForTesting() { |
101 return Integer.toString(mSelectedSearchEnginePosition); | 102 return Integer.toString(mSelectedSearchEnginePosition); |
102 } | 103 } |
103 | 104 |
104 void setValueForTesting(String value) { | 105 @VisibleForTesting |
105 searchEngineSelected(Integer.parseInt(value)); | 106 String setValueForTesting(String value) { |
107 return searchEngineSelected(Integer.parseInt(value)); | |
108 } | |
109 | |
110 @VisibleForTesting | |
111 String getKeywordForTesting(int index) { | |
112 return toKeyword(index); | |
106 } | 113 } |
107 | 114 |
108 /** | 115 /** |
109 * Initialize the search engine list. | 116 * Initialize the search engine list. |
110 */ | 117 */ |
111 private void initEntries() { | 118 private void initEntries() { |
112 TemplateUrlService templateUrlService = TemplateUrlService.getInstance() ; | 119 TemplateUrlService templateUrlService = TemplateUrlService.getInstance() ; |
113 if (!templateUrlService.isLoaded()) { | 120 if (!templateUrlService.isLoaded()) { |
114 templateUrlService.registerLoadListener(this); | 121 templateUrlService.registerLoadListener(this); |
115 templateUrlService.load(); | 122 templateUrlService.load(); |
116 return; // Flow continues in onTemplateUrlServiceLoaded below. | 123 return; // Flow continues in onTemplateUrlServiceLoaded below. |
117 } | 124 } |
118 | 125 |
119 // Fetch all the search engine info and the currently active one. | 126 int defaultSearchEngineIndex = templateUrlService.getDefaultSearchEngine Index(); |
120 mSearchEngines = templateUrlService.getLocalizedSearchEngines(); | 127 for (TemplateUrl templateUrl : templateUrlService.getSearchEngines()) { |
121 int searchEngineIndex = templateUrlService.getDefaultSearchEngineIndex() ; | 128 if (templateUrl.getType() == TemplateUrlService.TYPE_PREPOPULATED |
122 // Convert the TemplateUrl index into an index into mSearchEngines. | 129 || templateUrl.getType() == TemplateUrlService.TYPE_DEFAULT) { |
130 mPrepopulatedSearchEngines.add(templateUrl); | |
131 } else { | |
132 mRecentSearchEngines.add(templateUrl); | |
133 } | |
134 } | |
135 | |
136 // Convert the TemplateUrl index into an index of mSearchEngines. | |
123 mSelectedSearchEnginePosition = -1; | 137 mSelectedSearchEnginePosition = -1; |
124 for (int i = 0; i < mSearchEngines.size(); ++i) { | 138 for (int i = 0; i < mPrepopulatedSearchEngines.size(); ++i) { |
125 if (mSearchEngines.get(i).getIndex() == searchEngineIndex) { | 139 if (mPrepopulatedSearchEngines.get(i).getIndex() == defaultSearchEng ineIndex) { |
126 mSelectedSearchEnginePosition = i; | 140 mSelectedSearchEnginePosition = i; |
127 } | 141 } |
128 } | 142 } |
143 | |
144 for (int i = 0; i < mRecentSearchEngines.size(); ++i) { | |
145 if (mRecentSearchEngines.get(i).getIndex() == defaultSearchEngineInd ex) { | |
146 // Add one to offset the title for the recent search engine list . | |
147 mSelectedSearchEnginePosition = i + computeStartIndexForRecentSe archEngines(); | |
148 } | |
149 } | |
150 | |
129 mInitialEnginePosition = mSelectedSearchEnginePosition; | 151 mInitialEnginePosition = mSelectedSearchEnginePosition; |
130 | 152 |
131 // Report back what is selected. | 153 TemplateUrlService.getInstance().setSearchEngine(toKeyword(mSelectedSear chEnginePosition)); |
132 mCallback.currentSearchEngineDetermined(toIndex(mSelectedSearchEnginePos ition)); | |
133 } | 154 } |
134 | 155 |
135 private int toIndex(int position) { | 156 private String toKeyword(int position) { |
136 return mSearchEngines.get(position).getIndex(); | 157 if (position < mPrepopulatedSearchEngines.size()) { |
158 return mPrepopulatedSearchEngines.get(position).getKeyword(); | |
159 } else { | |
160 position -= computeStartIndexForRecentSearchEngines(); | |
161 return mRecentSearchEngines.get(position).getKeyword(); | |
162 } | |
137 } | 163 } |
138 | 164 |
139 // BaseAdapter: | 165 // BaseAdapter: |
140 | 166 |
141 @Override | 167 @Override |
142 public int getCount() { | 168 public int getCount() { |
143 return mSearchEngines == null ? 0 : mSearchEngines.size(); | 169 return mPrepopulatedSearchEngines == null |
170 ? 0 | |
171 : mPrepopulatedSearchEngines.size() + mRecentSearchEngines.size( ) + 1; | |
gone
2016/11/29 18:43:10
nit: I'd just put "? 0" and ": everything else" on
Peter Kasting
2016/11/29 20:47:44
(Note that clang-format for C++ code will force th
gone
2016/11/29 21:19:47
clang-format makes a couple of strange decisions f
ltian
2016/11/30 06:36:17
Yeah, git cl format puts "? 0" in a separate line
ltian
2016/11/30 06:36:17
Done.
| |
172 } | |
173 | |
174 @Override | |
175 public int getViewTypeCount() { | |
176 return VIEW_TYPE_COUNT; | |
144 } | 177 } |
145 | 178 |
146 @Override | 179 @Override |
147 public Object getItem(int pos) { | 180 public Object getItem(int pos) { |
148 TemplateUrl templateUrl = mSearchEngines.get(pos); | 181 if (pos < mPrepopulatedSearchEngines.size()) { |
149 return templateUrl.getShortName(); | 182 return mPrepopulatedSearchEngines.get(pos); |
183 } else if (pos > mPrepopulatedSearchEngines.size()) { | |
184 pos -= computeStartIndexForRecentSearchEngines(); | |
185 return mRecentSearchEngines.get(pos); | |
186 } | |
187 return null; | |
150 } | 188 } |
151 | 189 |
152 @Override | 190 @Override |
153 public long getItemId(int position) { | 191 public long getItemId(int position) { |
154 return position; | 192 return position; |
155 } | 193 } |
156 | 194 |
157 @Override | 195 @Override |
196 public int getItemViewType(int position) { | |
197 if (position == mPrepopulatedSearchEngines.size()) { | |
198 return VIEW_TYPE_DIVIDER; | |
199 } else { | |
200 return VIEW_TYPE_ITEM; | |
201 } | |
202 } | |
203 | |
204 @Override | |
158 public View getView(int position, View convertView, ViewGroup parent) { | 205 public View getView(int position, View convertView, ViewGroup parent) { |
159 View view = convertView; | 206 View view = convertView; |
207 TemplateUrl templateUrl = (TemplateUrl) getItem(position); | |
208 int itemViewType = getItemViewType(position); | |
160 if (convertView == null) { | 209 if (convertView == null) { |
161 view = mLayoutInflater.inflate(R.layout.search_engine, null); | 210 view = mLayoutInflater.inflate(itemViewType == VIEW_TYPE_DIVIDER |
211 ? R.layout.search_engine_recent_title : R.layout.search_engi ne, null); | |
212 } | |
213 if (itemViewType == VIEW_TYPE_DIVIDER) { | |
214 return view; | |
162 } | 215 } |
163 | 216 |
164 view.setOnClickListener(this); | 217 view.setOnClickListener(this); |
165 view.setTag(position); | 218 view.setTag(position); |
166 | 219 |
167 // TODO(finnur): There's a tinting bug in the AppCompat lib (see http:// crbug.com/474695), | 220 // TODO(finnur): There's a tinting bug in the AppCompat lib (see http:// crbug.com/474695), |
168 // which causes the first radiobox to always appear selected, even if it is not. It is being | 221 // which causes the first radiobox to always appear selected, even if it is not. It is being |
169 // addressed, but in the meantime we should use the native RadioButton i nstead. | 222 // addressed, but in the meantime we should use the native RadioButton i nstead. |
170 RadioButton radioButton = (RadioButton) view.findViewById(R.id.radiobutt on); | 223 RadioButton radioButton = (RadioButton) view.findViewById(R.id.radiobutt on); |
171 // On Lollipop this removes the redundant animation ring on selection bu t on older versions | 224 // On Lollipop this removes the redundant animation ring on selection bu t on older versions |
172 // it would cause the radio button to disappear. | 225 // it would cause the radio button to disappear. |
173 // TODO(finnur): Remove the encompassing if statement once we go back to using the AppCompat | 226 // TODO(finnur): Remove the encompassing if statement once we go back to using the AppCompat |
174 // control. | 227 // control. |
175 final boolean selected = position == mSelectedSearchEnginePosition; | 228 final boolean selected = position == mSelectedSearchEnginePosition; |
176 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | 229 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
177 radioButton.setBackgroundResource(0); | 230 radioButton.setBackgroundResource(0); |
178 } | 231 } |
179 radioButton.setChecked(selected); | 232 radioButton.setChecked(selected); |
180 | 233 |
181 TextView description = (TextView) view.findViewById(R.id.description); | 234 TextView description = (TextView) view.findViewById(R.id.name); |
182 TemplateUrl templateUrl = mSearchEngines.get(position); | |
183 Resources resources = mContext.getResources(); | 235 Resources resources = mContext.getResources(); |
184 description.setText(templateUrl.getShortName()); | 236 description.setText(templateUrl.getShortName()); |
185 | 237 |
238 TextView url = (TextView) view.findViewById(R.id.url); | |
239 url.setText(templateUrl.getUrl()); | |
240 if (templateUrl.getType() == TemplateUrlService.TYPE_PREPOPULATED | |
241 || templateUrl.getType() == TemplateUrlService.TYPE_DEFAULT | |
242 || templateUrl.getUrl().length() == 0) { | |
243 url.setVisibility(View.GONE); | |
244 } | |
245 | |
186 // To improve the explore-by-touch experience, the radio button is hidde n from accessibility | 246 // To improve the explore-by-touch experience, the radio button is hidde n from accessibility |
187 // and instead, "checked" or "not checked" is read along with the search engine's name, e.g. | 247 // and instead, "checked" or "not checked" is read along with the search engine's name, e.g. |
188 // "google.com checked" or "google.com not checked". | 248 // "google.com checked" or "google.com not checked". |
189 radioButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILIT Y_NO); | 249 radioButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILIT Y_NO); |
190 description.setAccessibilityDelegate(new AccessibilityDelegate() { | 250 description.setAccessibilityDelegate(new AccessibilityDelegate() { |
191 @Override | 251 @Override |
192 public void onInitializeAccessibilityEvent(View host, AccessibilityE vent event) { | 252 public void onInitializeAccessibilityEvent(View host, AccessibilityE vent event) { |
193 super.onInitializeAccessibilityEvent(host, event); | 253 super.onInitializeAccessibilityEvent(host, event); |
194 event.setChecked(selected); | 254 event.setChecked(selected); |
195 } | 255 } |
196 | 256 |
197 @Override | 257 @Override |
198 public void onInitializeAccessibilityNodeInfo(View host, Accessibili tyNodeInfo info) { | 258 public void onInitializeAccessibilityNodeInfo(View host, Accessibili tyNodeInfo info) { |
199 super.onInitializeAccessibilityNodeInfo(host, info); | 259 super.onInitializeAccessibilityNodeInfo(host, info); |
200 info.setCheckable(true); | 260 info.setCheckable(true); |
201 info.setChecked(selected); | 261 info.setChecked(selected); |
202 } | 262 } |
203 }); | 263 }); |
204 | 264 |
205 TextView link = (TextView) view.findViewById(R.id.link); | 265 TextView link = (TextView) view.findViewById(R.id.location_permission); |
206 link.setVisibility(selected ? View.VISIBLE : View.GONE); | 266 link.setVisibility(selected ? View.VISIBLE : View.GONE); |
207 if (selected) { | 267 if (selected) { |
208 if (getLocationPermissionType(position, true) == ContentSetting.ASK) { | 268 if (getLocationPermissionType(position, true) == ContentSetting.ASK) { |
209 link.setVisibility(View.GONE); | 269 link.setVisibility(View.GONE); |
210 } else { | 270 } else { |
211 ForegroundColorSpan linkSpan = new ForegroundColorSpan( | 271 ForegroundColorSpan linkSpan = new ForegroundColorSpan( |
212 ApiCompatibilityUtils.getColor(resources, R.color.pref_a ccent_color)); | 272 ApiCompatibilityUtils.getColor(resources, R.color.pref_a ccent_color)); |
213 if (LocationUtils.getInstance().isSystemLocationSettingEnabled() ) { | 273 if (LocationUtils.getInstance().isSystemLocationSettingEnabled() ) { |
214 String message = mContext.getString( | 274 String message = mContext.getString( |
215 locationEnabled(position, true) | 275 locationEnabled(position, true) |
(...skipping 28 matching lines...) Expand all Loading... | |
244 | 304 |
245 @Override | 305 @Override |
246 public void onClick(View view) { | 306 public void onClick(View view) { |
247 if (view.getTag() == null) { | 307 if (view.getTag() == null) { |
248 onLocationLinkClicked(); | 308 onLocationLinkClicked(); |
249 } else { | 309 } else { |
250 searchEngineSelected((int) view.getTag()); | 310 searchEngineSelected((int) view.getTag()); |
251 } | 311 } |
252 } | 312 } |
253 | 313 |
254 private void searchEngineSelected(int position) { | 314 private String searchEngineSelected(int position) { |
255 // First clean up any automatically added permissions (if any) for the p reviously selected | 315 // First clean up any automatically added permissions (if any) for the p reviously selected |
256 // search engine. | 316 // search engine. |
257 SharedPreferences sharedPreferences = | 317 SharedPreferences sharedPreferences = |
258 ContextUtils.getAppSharedPreferences(); | 318 ContextUtils.getAppSharedPreferences(); |
259 if (sharedPreferences.getBoolean(PrefServiceBridge.LOCATION_AUTO_ALLOWED , false)) { | 319 if (sharedPreferences.getBoolean(PrefServiceBridge.LOCATION_AUTO_ALLOWED , false)) { |
260 if (locationEnabled(mSelectedSearchEnginePosition, false)) { | 320 if (locationEnabled(mSelectedSearchEnginePosition, false)) { |
261 String url = TemplateUrlService.getInstance().getSearchEngineUrl FromTemplateUrl( | 321 String url = TemplateUrlService.getInstance().getSearchEngineUrl FromTemplateUrl( |
262 toIndex(mSelectedSearchEnginePosition)); | 322 toKeyword(mSelectedSearchEnginePosition)); |
263 WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin( | 323 WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin( |
264 url, url, ContentSetting.DEFAULT.toInt(), false); | 324 url, url, ContentSetting.DEFAULT.toInt(), false); |
265 } | 325 } |
266 sharedPreferences.edit().remove(PrefServiceBridge.LOCATION_AUTO_ALLO WED).apply(); | 326 sharedPreferences.edit().remove(PrefServiceBridge.LOCATION_AUTO_ALLO WED).apply(); |
267 } | 327 } |
268 | 328 |
269 // Record the change in search engine. | 329 // Record the change in search engine. |
270 mSelectedSearchEnginePosition = position; | 330 mSelectedSearchEnginePosition = position; |
271 | 331 |
272 // Report the change back. | 332 String keyword = toKeyword(mSelectedSearchEnginePosition); |
273 mCallback.currentSearchEngineDetermined(toIndex(mSelectedSearchEnginePos ition)); | 333 TemplateUrlService.getInstance().setSearchEngine(keyword); |
274 | 334 |
335 // If the user has manually set the default search engine, disable auto switching. | |
336 boolean manualSwitch = mSelectedSearchEnginePosition != mInitialEnginePo sition; | |
337 if (manualSwitch) { | |
338 RecordUserAction.record("SearchEngine_ManualChange"); | |
339 LocaleManager.getInstance().setSearchEngineAutoSwitch(false); | |
340 } | |
275 notifyDataSetChanged(); | 341 notifyDataSetChanged(); |
342 return keyword; | |
276 } | 343 } |
277 | 344 |
278 private void onLocationLinkClicked() { | 345 private void onLocationLinkClicked() { |
279 if (!LocationUtils.getInstance().isSystemLocationSettingEnabled()) { | 346 if (!LocationUtils.getInstance().isSystemLocationSettingEnabled()) { |
280 mContext.startActivity(LocationUtils.getInstance().getSystemLocation SettingsIntent()); | 347 mContext.startActivity(LocationUtils.getInstance().getSystemLocation SettingsIntent()); |
281 } else { | 348 } else { |
282 Intent settingsIntent = PreferencesLauncher.createIntentForSettingsP age( | 349 Intent settingsIntent = PreferencesLauncher.createIntentForSettingsP age( |
283 mContext, SingleWebsitePreferences.class.getName()); | 350 mContext, SingleWebsitePreferences.class.getName()); |
284 String url = TemplateUrlService.getInstance().getSearchEngineUrlFrom TemplateUrl( | 351 String url = TemplateUrlService.getInstance().getSearchEngineUrlFrom TemplateUrl( |
285 toIndex(mSelectedSearchEnginePosition)); | 352 toKeyword(mSelectedSearchEnginePosition)); |
286 Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsFor Site(url); | 353 Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsFor Site(url); |
287 fragmentArgs.putBoolean(SingleWebsitePreferences.EXTRA_LOCATION, | 354 fragmentArgs.putBoolean(SingleWebsitePreferences.EXTRA_LOCATION, |
288 locationEnabled(mSelectedSearchEnginePosition, true)); | 355 locationEnabled(mSelectedSearchEnginePosition, true)); |
289 settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, f ragmentArgs); | 356 settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, f ragmentArgs); |
290 mContext.startActivity(settingsIntent); | 357 mContext.startActivity(settingsIntent); |
291 } | 358 } |
292 } | 359 } |
293 | 360 |
294 private ContentSetting getLocationPermissionType(int position, boolean check GeoHeader) { | 361 private ContentSetting getLocationPermissionType(int position, boolean check GeoHeader) { |
295 if (position == -1) { | 362 if (position == -1) { |
296 return ContentSetting.BLOCK; | 363 return ContentSetting.BLOCK; |
297 } | 364 } |
298 | 365 |
299 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp lateUrl( | 366 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp lateUrl( |
300 toIndex(position)); | 367 toKeyword(position)); |
301 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false) ; | 368 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false) ; |
302 ContentSetting locationPermission = locationSettings.getContentSetting() ; | 369 ContentSetting locationPermission = locationSettings.getContentSetting() ; |
303 if (locationPermission == ContentSetting.ASK) { | 370 if (locationPermission == ContentSetting.ASK) { |
304 // Handle the case where the geoHeader being sent when no permission has been specified. | 371 // Handle the case where the geoHeader being sent when no permission has been specified. |
305 if (checkGeoHeader && GeolocationHeader.isGeoHeaderEnabledForUrl( | 372 if (checkGeoHeader && GeolocationHeader.isGeoHeaderEnabledForUrl( |
306 mContext, url, false)) { | 373 mContext, url, false)) { |
307 locationPermission = ContentSetting.ALLOW; | 374 locationPermission = ContentSetting.ALLOW; |
308 } | 375 } |
309 } | 376 } |
310 return locationPermission; | 377 return locationPermission; |
311 } | 378 } |
312 | 379 |
313 private boolean locationEnabled(int position, boolean checkGeoHeader) { | 380 private boolean locationEnabled(int position, boolean checkGeoHeader) { |
314 return getLocationPermissionType(position, checkGeoHeader) == ContentSet ting.ALLOW; | 381 return getLocationPermissionType(position, checkGeoHeader) == ContentSet ting.ALLOW; |
315 } | 382 } |
316 | 383 |
384 public int computeStartIndexForRecentSearchEngines() { | |
gone
2016/11/29 18:43:11
Make it private or add a javadoc
ltian
2016/11/30 06:36:17
Done.
| |
385 return mPrepopulatedSearchEngines.size() + 1; | |
386 } | |
387 | |
317 } | 388 } |
OLD | NEW |