Index: chrome/android/java/src/org/chromium/chrome/browser/search_engines/TemplateUrlService.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/search_engines/TemplateUrlService.java b/chrome/android/java/src/org/chromium/chrome/browser/search_engines/TemplateUrlService.java |
index d467dba6f03c1fddf21d0fa6d7936f59be6475dd..d354d37fe0cc332417c1e486ea8e24e1a4f27d3c 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/search_engines/TemplateUrlService.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/search_engines/TemplateUrlService.java |
@@ -12,6 +12,8 @@ import org.chromium.base.annotations.CalledByNative; |
import java.util.ArrayList; |
import java.util.List; |
+import java.util.regex.Matcher; |
+import java.util.regex.Pattern; |
/** |
* Android wrapper of the TemplateUrlService which provides access from the Java |
@@ -42,21 +44,48 @@ public class TemplateUrlService { |
} |
/** |
+ * Type to sort & display different layouts for different type of search engines. |
+ */ |
+ public enum TemplateUrlType { |
Ian Wen
2016/09/27 04:42:00
Let's use ints instead of enums. https://developer
ltian
2016/09/28 19:19:47
Done.
|
+ PREPOPULATED, |
+ /** |
+ * Type for default search engine which is not prepopulated. This is needed because |
+ * if a custom search engine is set as default, it will move to default list. |
+ */ |
+ DEFAULT, |
+ /** |
+ * Type to identify divdier view. |
+ */ |
+ DIVIDER, |
Ian Wen
2016/09/27 04:42:00
Remove DIVIDER
ltian
2016/09/28 19:19:47
Done.
|
+ CUSTOM |
Ian Wen
2016/09/27 04:42:00
I wouldn't use the term "custom" here, as the list
ltian
2016/09/28 19:19:46
Done.
|
+ } |
+ |
+ /** |
* Represents search engine with its index. |
*/ |
- public static class TemplateUrl { |
+ public static class TemplateUrl implements Comparable<TemplateUrl> { |
private final int mIndex; |
private final String mShortName; |
- private boolean mIsPrepopulated; |
+ private final String mUrl; |
+ private final boolean mIsPrepopulated; |
+ private TemplateUrlType mTemplateUrlType; |
@CalledByNative("TemplateUrl") |
- public static TemplateUrl create(int id, String shortName, boolean isPrepopulated) { |
- return new TemplateUrl(id, shortName, isPrepopulated); |
+ public static TemplateUrl create( |
+ int id, String shortName, String url, boolean isPrepopulated) { |
+ return new TemplateUrl(id, shortName, url, isPrepopulated); |
} |
- public TemplateUrl(int index, String shortName, boolean isPrepopulated) { |
+ public TemplateUrl(int index, String shortName, String url, boolean isPrepopulated) { |
mIndex = index; |
mShortName = shortName; |
+ Pattern pattern = Pattern.compile("[^/]+.com"); |
+ Matcher m = pattern.matcher(url); |
+ if (!m.find()) { |
+ mUrl = ""; |
+ } else { |
+ mUrl = m.group(0); |
+ } |
mIsPrepopulated = isPrepopulated; |
} |
@@ -68,6 +97,22 @@ public class TemplateUrlService { |
return mShortName; |
} |
+ public String getUrl() { |
+ return mUrl; |
+ } |
+ |
+ public boolean getIsPrepopulated() { |
Ian Wen
2016/09/27 04:42:00
Instead of creating this method, you could create
ltian
2016/09/28 19:19:47
Done.
|
+ return mIsPrepopulated; |
+ } |
+ |
+ public void setTemplateUrlType(TemplateUrlType templateUrlType) { |
+ mTemplateUrlType = templateUrlType; |
+ } |
+ |
+ public TemplateUrlType getTemplateUrlType() { |
+ return mTemplateUrlType; |
+ } |
+ |
@Override |
public int hashCode() { |
final int prime = 31; |
@@ -84,6 +129,11 @@ public class TemplateUrlService { |
return mIndex == otherTemplateUrl.mIndex |
&& TextUtils.equals(mShortName, otherTemplateUrl.mShortName); |
} |
+ |
+ @Override |
+ public int compareTo(TemplateUrl templateUrl) { |
Ian Wen
2016/09/27 04:42:00
Q: why adding this?
ltian
2016/09/28 19:19:47
Done.
|
+ return mTemplateUrlType.compareTo(templateUrl.getTemplateUrlType()); |
+ } |
} |
private static TemplateUrlService sService; |
@@ -130,7 +180,7 @@ public class TemplateUrlService { |
List<TemplateUrl> templateUrls = new ArrayList<TemplateUrl>(templateUrlCount); |
for (int i = 0; i < templateUrlCount; i++) { |
TemplateUrl templateUrl = nativeGetTemplateUrlAt(mNativeTemplateUrlServiceAndroid, i); |
- if (templateUrl != null && templateUrl.mIsPrepopulated) { |
+ if (templateUrl != null) { |
templateUrls.add(templateUrl); |
} |
} |