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

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

Issue 1109263004: Fix padding and touch effects in search engine dialog. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 initEntries(); 82 initEntries();
83 } 83 }
84 84
85 // Used for testing. 85 // Used for testing.
86 86
87 String getValueForTesting() { 87 String getValueForTesting() {
88 return Integer.toString(mSelectedSearchEnginePosition); 88 return Integer.toString(mSelectedSearchEnginePosition);
89 } 89 }
90 90
91 void setValueForTesting(String value) { 91 void setValueForTesting(String value) {
92 radioButtonClicked(Integer.parseInt(value)); 92 searchEngineSelected(Integer.parseInt(value));
93 } 93 }
94 94
95 /** 95 /**
96 * Initialize the search engine list. 96 * Initialize the search engine list.
97 */ 97 */
98 private void initEntries() { 98 private void initEntries() {
99 TemplateUrlService templateUrlService = TemplateUrlService.getInstance() ; 99 TemplateUrlService templateUrlService = TemplateUrlService.getInstance() ;
100 if (!templateUrlService.isLoaded()) { 100 if (!templateUrlService.isLoaded()) {
101 templateUrlService.registerLoadListener(this); 101 templateUrlService.registerLoadListener(this);
102 templateUrlService.load(); 102 templateUrlService.load();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 return position; 157 return position;
158 } 158 }
159 159
160 @Override 160 @Override
161 public View getView(int position, View convertView, ViewGroup parent) { 161 public View getView(int position, View convertView, ViewGroup parent) {
162 View view = convertView; 162 View view = convertView;
163 if (convertView == null) { 163 if (convertView == null) {
164 view = mLayoutInflater.inflate(R.layout.search_engine, null); 164 view = mLayoutInflater.inflate(R.layout.search_engine, null);
165 } 165 }
166 166
167 view.setOnClickListener(this);
168 view.setTag(position);
169
167 RadioButton radioButton = (RadioButton) view.findViewById(R.id.radiobutt on); 170 RadioButton radioButton = (RadioButton) view.findViewById(R.id.radiobutt on);
171 boolean selected = position == mSelectedSearchEnginePosition;
172 radioButton.setChecked(selected);
173
168 TextView description = (TextView) view.findViewById(R.id.description); 174 TextView description = (TextView) view.findViewById(R.id.description);
169 TextView link = (TextView) view.findViewById(R.id.link);
170
171 TemplateUrl templateUrl = mSearchEngines.get(position); 175 TemplateUrl templateUrl = mSearchEngines.get(position);
172 Resources resources = mContext.getResources(); 176 Resources resources = mContext.getResources();
177 description.setText(getSearchEngineNameAndDomain(resources, templateUrl) );
173 178
174 boolean selected = position == mSelectedSearchEnginePosition; 179 TextView link = (TextView) view.findViewById(R.id.link);
175 radioButton.setChecked(selected);
176 radioButton.setOnClickListener(this);
177 radioButton.setTag(position);
178
179 description.setText(getSearchEngineNameAndDomain(resources, templateUrl) );
180 description.setOnClickListener(this);
181 description.setTag(position);
Finnur 2015/04/29 09:55:13 Just to confirm... clicking on the description sti
newt (away) 2015/04/29 17:33:05 Yes. Click events are first sent to the deepest vi
182
183 link.setVisibility(selected ? View.VISIBLE : View.GONE); 180 link.setVisibility(selected ? View.VISIBLE : View.GONE);
184 if (selected) { 181 if (selected) {
185 ForegroundColorSpan linkSpan = new ForegroundColorSpan( 182 ForegroundColorSpan linkSpan = new ForegroundColorSpan(
186 resources.getColor(R.color.pref_accent_color)); 183 resources.getColor(R.color.pref_accent_color));
187 if (LocationSettings.getInstance().isSystemLocationSettingEnabled()) { 184 if (LocationSettings.getInstance().isSystemLocationSettingEnabled()) {
188 String message = mContext.getString( 185 String message = mContext.getString(
189 locationEnabled(position) 186 locationEnabled(position)
190 ? R.string.search_engine_location_allowed 187 ? R.string.search_engine_location_allowed
191 : R.string.search_engine_location_blocked); 188 : R.string.search_engine_location_blocked);
192 SpannableString messageWithLink = new SpannableString(message); 189 SpannableString messageWithLink = new SpannableString(message);
(...skipping 19 matching lines...) Expand all
212 initEntries(); 209 initEntries();
213 } 210 }
214 211
215 // OnClickListener: 212 // OnClickListener:
216 213
217 @Override 214 @Override
218 public void onClick(View view) { 215 public void onClick(View view) {
219 if (view.getTag() == null) { 216 if (view.getTag() == null) {
220 onLocationLinkClicked(); 217 onLocationLinkClicked();
221 } else { 218 } else {
222 radioButtonClicked((int) view.getTag()); 219 searchEngineSelected((int) view.getTag());
223 } 220 }
224 } 221 }
225 222
226 private void radioButtonClicked(int position) { 223 private void searchEngineSelected(int position) {
227 // First clean up any automatically added permissions (if any) for the p reviously selected 224 // First clean up any automatically added permissions (if any) for the p reviously selected
228 // search engine. 225 // search engine.
229 SharedPreferences sharedPreferences = 226 SharedPreferences sharedPreferences =
230 PreferenceManager.getDefaultSharedPreferences(mContext); 227 PreferenceManager.getDefaultSharedPreferences(mContext);
231 if (sharedPreferences.getBoolean(PrefServiceBridge.LOCATION_AUTO_ALLOWED , false)) { 228 if (sharedPreferences.getBoolean(PrefServiceBridge.LOCATION_AUTO_ALLOWED , false)) {
232 if (locationEnabled(mSelectedSearchEnginePosition)) { 229 if (locationEnabled(mSelectedSearchEnginePosition)) {
233 TemplateUrl templateUrl = mSearchEngines.get(mSelectedSearchEngi nePosition);
newt (away) 2015/04/29 00:02:25 dead code
234
235 String url = TemplateUrlService.getInstance().getSearchEngineUrl FromTemplateUrl( 230 String url = TemplateUrlService.getInstance().getSearchEngineUrl FromTemplateUrl(
236 toIndex(mSelectedSearchEnginePosition)); 231 toIndex(mSelectedSearchEnginePosition));
237 WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin( 232 WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin(
238 url, url, ContentSetting.DEFAULT.toInt()); 233 url, url, ContentSetting.DEFAULT.toInt());
239 } 234 }
240 sharedPreferences.edit().remove(PrefServiceBridge.LOCATION_AUTO_ALLO WED).apply(); 235 sharedPreferences.edit().remove(PrefServiceBridge.LOCATION_AUTO_ALLO WED).apply();
241 } 236 }
242 237
243 // Record the change in search engine. 238 // Record the change in search engine.
244 mSelectedSearchEnginePosition = position; 239 mSelectedSearchEnginePosition = position;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 private boolean locationEnabled(int position) { 272 private boolean locationEnabled(int position) {
278 if (position == -1) return false; 273 if (position == -1) return false;
279 274
280 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp lateUrl( 275 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp lateUrl(
281 toIndex(position)); 276 toIndex(position));
282 GeolocationInfo locationSettings = new GeolocationInfo(url, null); 277 GeolocationInfo locationSettings = new GeolocationInfo(url, null);
283 ContentSetting locationPermission = locationSettings.getContentSetting() ; 278 ContentSetting locationPermission = locationSettings.getContentSetting() ;
284 return locationPermission == ContentSetting.ALLOW; 279 return locationPermission == ContentSetting.ALLOW;
285 } 280 }
286 } 281 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698