am 21beb13: Swap the title and subtitle of browser suggestions, so the w
Merge commit '21beb13181eb2b04a0356c77e0c737ea7acdad71'
* commit '21beb13181eb2b04a0356c77e0c737ea7acdad71':
Swap the title and subtitle of browser suggestions, so the webpage title
diff --git a/src/com/android/browser/BrowserProvider.java b/src/com/android/browser/BrowserProvider.java
index 8c30873..96bfad6 100644
--- a/src/com/android/browser/BrowserProvider.java
+++ b/src/com/android/browser/BrowserProvider.java
@@ -36,6 +36,7 @@
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 String[] getColumnNames() {
return COLUMNS;
}
-
+
@Override
public String getString(int columnIndex) {
if ((mPos != -1 && mHistoryCursor != null)) {
@@ -350,18 +351,18 @@
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 @@
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