summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike LeBeau <mlebeau@android.com>2009-05-13 14:57:50 -0700
committerMike LeBeau <mlebeau@android.com>2009-05-13 14:59:04 -0700
commit21beb13181eb2b04a0356c77e0c737ea7acdad71 (patch)
tree831a861e073d1352c2f47f4a4dd66ca44b3d0975
parent910ac1a8b53218984608d0d4ebde767f2c6c7f63 (diff)
downloadpackages_apps_Browser-21beb13181eb2b04a0356c77e0c737ea7acdad71.zip
packages_apps_Browser-21beb13181eb2b04a0356c77e0c737ea7acdad71.tar.gz
packages_apps_Browser-21beb13181eb2b04a0356c77e0c737ea7acdad71.tar.bz2
Swap the title and subtitle of browser suggestions, so the webpage title
shows as the first line and the url shows as the second line. Preceding "http://" is stripped from urls. If the first line would be empty or whitespace, the second line is promoted to the first line. This affects suggestions both for the browser and for global search. I thought this looked a lot better so ran it by Leland and he's cool with this. I went ahead and reused the raw int values being used for column indices and such, but this is bad. You guys should really consider making this code a little safer/cleaner. :)
-rw-r--r--src/com/android/browser/BrowserProvider.java53
1 files changed, 48 insertions, 5 deletions
diff --git a/src/com/android/browser/BrowserProvider.java b/src/com/android/browser/BrowserProvider.java
index 3a00ffa..6d54099 100644
--- a/src/com/android/browser/BrowserProvider.java
+++ b/src/com/android/browser/BrowserProvider.java
@@ -36,6 +36,7 @@ import android.net.Uri;
import android.preference.PreferenceManager;
import android.provider.Browser;
import android.server.search.SearchableInfo;
+import android.text.TextUtils;
import android.text.util.Regex;
import android.util.Log;
@@ -329,7 +330,7 @@ public class BrowserProvider extends ContentProvider {
public String[] getColumnNames() {
return COLUMNS;
}
-
+
@Override
public String getString(int columnIndex) {
if ((mPos != -1 && mHistoryCursor != null)) {
@@ -350,18 +351,18 @@ public class BrowserProvider extends ContentProvider {
case SUGGEST_COLUMN_TEXT_1_ID:
if (mHistoryCount > mPos) {
- return mHistoryCursor.getString(1);
+ return getTitle(mHistoryCursor);
} else if (!mBeyondCursor) {
- return mSuggestCursor.getString(1);
+ return getTitle(mSuggestCursor);
} else {
return mString;
}
case SUGGEST_COLUMN_TEXT_2_ID:
if (mHistoryCount > mPos) {
- return mHistoryCursor.getString(2);
+ return getSubtitle(mHistoryCursor);
} else if (!mBeyondCursor) {
- return mSuggestCursor.getString(2);
+ return getSubtitle(mSuggestCursor);
} else {
return getContext().getString(R.string.search_google);
}
@@ -460,6 +461,48 @@ public class BrowserProvider extends ContentProvider {
mSuggestCursor = null;
}
}
+
+ /**
+ * Provides the title (text line 1) for a browser suggestion, which should be the
+ * webpage title. If the webpage title is empty, returns the stripped url instead.
+ *
+ * @param cursor a history cursor or suggest cursor
+ * @return the title string to use
+ */
+ private String getTitle(Cursor cursor) {
+ String title = cursor.getString(2 /* webpage title */);
+ if (TextUtils.isEmpty(title) || TextUtils.getTrimmedLength(title) == 0) {
+ title = stripUrl(cursor.getString(1 /* url */));
+ }
+ return title;
+ }
+
+ /**
+ * Provides the subtitle (text line 2) for a browser suggestion, which should be the
+ * webpage url. If the webpage title is empty, then the url should go in the title
+ * instead, and the subtitle should be empty, so this would return null.
+ *
+ * @param cursor a history cursor or suggest cursor
+ * @return the subtitle string to use, or null if none
+ */
+ private String getSubtitle(Cursor cursor) {
+ String title = cursor.getString(2 /* webpage title */);
+ if (TextUtils.isEmpty(title) || TextUtils.getTrimmedLength(title) == 0) {
+ return null;
+ } else {
+ return stripUrl(cursor.getString(1 /* url */));
+ }
+ }
+
+ /**
+ * Strips "http://" from the beginning of a url.
+ */
+ private String stripUrl(String url) {
+ if (url.startsWith("http://")) {
+ url = url.substring(7);
+ }
+ return url;
+ }
}
@Override