diff options
| author | Leon Scroggins <scroggo@google.com> | 2010-12-03 15:31:56 -0500 |
|---|---|---|
| committer | Leon Scroggins <scroggo@google.com> | 2010-12-06 12:00:04 -0500 |
| commit | 4cd97793901e8f5681cf642d0b2684697964a37a (patch) | |
| tree | 6693ad6ec9e8da58050cc32ee45191538eef5b69 /src/com/android | |
| parent | d957a52dfb61ef3056e6225301ebbba622352d1a (diff) | |
| download | packages_apps_Browser-4cd97793901e8f5681cf642d0b2684697964a37a.tar.gz packages_apps_Browser-4cd97793901e8f5681cf642d0b2684697964a37a.tar.bz2 packages_apps_Browser-4cd97793901e8f5681cf642d0b2684697964a37a.zip | |
Show a highlighted star for bookmarked pages.
Bug:3222677
Change-Id: Ifeb6e7a922c0defb1e4a88ded0c188b97e0a4a56
Diffstat (limited to 'src/com/android')
| -rw-r--r-- | src/com/android/browser/BaseUi.java | 10 | ||||
| -rw-r--r-- | src/com/android/browser/Controller.java | 5 | ||||
| -rw-r--r-- | src/com/android/browser/Tab.java | 47 | ||||
| -rw-r--r-- | src/com/android/browser/TitleBarXLarge.java | 31 | ||||
| -rw-r--r-- | src/com/android/browser/UI.java | 1 | ||||
| -rw-r--r-- | src/com/android/browser/WebViewController.java | 2 |
6 files changed, 93 insertions, 3 deletions
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java index f5851df66..c4f3bd541 100644 --- a/src/com/android/browser/BaseUi.java +++ b/src/com/android/browser/BaseUi.java @@ -256,6 +256,15 @@ public class BaseUi implements UI, WebViewFactory { } @Override + public void bookmarkedStatusHasChanged(Tab tab) { + if (tab.inForeground() && mXLargeScreenSize) { + boolean isBookmark = tab.isBookmarkedSite(); + ((TitleBarXLarge) mTitleBar).setCurrentUrlIsBookmark(isBookmark); + ((TitleBarXLarge) mFakeTitleBar).setCurrentUrlIsBookmark(isBookmark); + } + } + + @Override public void onPageFinished(Tab tab, String url) { if (mXLargeScreenSize) { mTabBar.onPageFinished(tab); @@ -336,6 +345,7 @@ public class BaseUi implements UI, WebViewFactory { // Request focus on the top window. mTabBar.onSetActiveTab(tab); } + bookmarkedStatusHasChanged(tab); resetTitleIconAndProgress(tab); updateLockIconToLatest(tab); tab.getTopWindow().requestFocus(); diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java index 5642d4d3c..7acdfe56e 100644 --- a/src/com/android/browser/Controller.java +++ b/src/com/android/browser/Controller.java @@ -1026,6 +1026,11 @@ public class Controller } } + @Override + public void bookmarkedStatusHasChanged(Tab tab) { + mUi.bookmarkedStatusHasChanged(tab); + } + // end WebViewController protected void pageUp() { diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java index 8a3bc2748..3e79edbcb 100644 --- a/src/com/android/browser/Tab.java +++ b/src/com/android/browser/Tab.java @@ -25,12 +25,16 @@ import android.content.ContentResolver; import android.content.DialogInterface; import android.content.DialogInterface.OnCancelListener; import android.content.Intent; +import android.database.Cursor; +import android.database.sqlite.SQLiteException; import android.graphics.Bitmap; import android.net.Uri; import android.net.http.SslError; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Message; import android.os.SystemClock; +import android.provider.BrowserContract; import android.speech.RecognizerResultsIntent; import android.util.Log; import android.view.KeyEvent; @@ -144,6 +148,14 @@ class Tab { Bitmap mFavicon; } + // Whether or not the currently shown page is a bookmarked site. Will be + // out of date when loading a new page until the mBookmarkAsyncTask returns. + private boolean mIsBookmarkedSite; + // Used to determine whether the current site is bookmarked. + private AsyncTask<Void, Void, Boolean> mBookmarkAsyncTask; + + public boolean isBookmarkedSite() { return mIsBookmarkedSite; } + // Used for saving and restoring each Tab static final String WEBVIEW = "webview"; static final String NUMTABS = "numTabs"; @@ -488,9 +500,42 @@ class Tab { } } - // finally update the UI in the activity if it is in the foreground mWebViewController.onPageStarted(Tab.this, view, url, favicon); + + final String urlInQuestion = url; + if (mBookmarkAsyncTask != null) { + mBookmarkAsyncTask.cancel(true); + } + mBookmarkAsyncTask = new AsyncTask<Void, Void, Boolean>() { + @Override + protected Boolean doInBackground(Void... unused) { + // Check to see if the site is bookmarked + Cursor cursor = null; + try { + cursor = mActivity.getContentResolver().query( + BrowserContract.Bookmarks.CONTENT_URI, + new String[] { BrowserContract.Bookmarks.URL }, + BrowserContract.Bookmarks.URL + " == ?", + new String[] { urlInQuestion }, + null); + return cursor.moveToFirst(); + } catch (SQLiteException e) { + Log.e(LOGTAG, "Error checking for bookmark: " + e); + return false; + } finally { + if (cursor != null) cursor.close(); + } + } + @Override + protected void onPostExecute(Boolean isBookmarked) { + if (this == mBookmarkAsyncTask) { + mIsBookmarkedSite = isBookmarked; + mWebViewController.bookmarkedStatusHasChanged(Tab.this); + } + } + }; + mBookmarkAsyncTask.execute(); } @Override diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java index 0aa09db48..cd3b23050 100644 --- a/src/com/android/browser/TitleBarXLarge.java +++ b/src/com/android/browser/TitleBarXLarge.java @@ -26,9 +26,11 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.text.TextUtils; +import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; +import android.widget.CheckBox; import android.widget.ImageView; import android.widget.TextView; @@ -48,7 +50,7 @@ public class TitleBarXLarge extends TitleBarBase private View mContainer; private View mBackButton; private View mForwardButton; - private View mStar; + private CheckBox mStar; private View mSearchButton; private View mFocusContainer; private View mUnfocusContainer; @@ -82,7 +84,7 @@ public class TitleBarXLarge extends TitleBarBase // back/forward. Probably should be done inside onPageStarted. mBackButton = findViewById(R.id.back); mForwardButton = findViewById(R.id.forward); - mStar = findViewById(R.id.star); + mStar = (CheckBox) findViewById(R.id.star); mStopButton = (ImageView) findViewById(R.id.stop); mSearchButton = findViewById(R.id.search); mLockIcon = (ImageView) findViewById(R.id.lock); @@ -106,6 +108,10 @@ public class TitleBarXLarge extends TitleBarBase mUnfocusContainer.setOnClickListener(this); } + public void setCurrentUrlIsBookmark(boolean isBookmark) { + mStar.setChecked(isBookmark); + } + @Override public void onClick(View v) { if (mUnfocusContainer == v) { @@ -237,4 +243,25 @@ public class TitleBarXLarge extends TitleBarBase mUrlUnfocused.setText(title); } + /** + * Custom CheckBox which does not toggle when pressed. Used by mStar. + */ + public static class CustomCheck extends CheckBox { + public CustomCheck(Context context) { + super(context); + } + + public CustomCheck(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public CustomCheck(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + public void toggle() { + // Do nothing + } + } } diff --git a/src/com/android/browser/UI.java b/src/com/android/browser/UI.java index e7f67f2ad..2bfec4409 100644 --- a/src/com/android/browser/UI.java +++ b/src/com/android/browser/UI.java @@ -130,4 +130,5 @@ public interface UI extends ScrollListener { View getVideoLoadingProgressView(); + void bookmarkedStatusHasChanged(Tab tab); } diff --git a/src/com/android/browser/WebViewController.java b/src/com/android/browser/WebViewController.java index 11a695980..894bbec6f 100644 --- a/src/com/android/browser/WebViewController.java +++ b/src/com/android/browser/WebViewController.java @@ -107,4 +107,6 @@ public interface WebViewController { void setupAutoFill(Message message); + void bookmarkedStatusHasChanged(Tab tab); + } |
