summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/values/arrays.xml33
-rw-r--r--res/values/strings.xml7
-rw-r--r--src/com/android/browser/AddBookmarkPage.java110
-rw-r--r--src/com/android/browser/BrowserBookmarksAdapter.java4
4 files changed, 83 insertions, 71 deletions
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
deleted file mode 100644
index 219cc6b..0000000
--- a/res/values/arrays.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- -->
-<resources>
- <string-array name="webstorage_quota_entries">
- <item>No quota allowed</item>
- <item>5 MB</item>
- <item>10 MB</item>
- <item>30 MB</item>
- <item>100 MB</item>
- </string-array>
- <string-array name="webstorage_quota_entries_values">
- <item>0</item>
- <item>5</item>
- <item>10</item>
- <item>30</item>
- <item>100</item>
- </string-array>
-</resources>
-
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2d91d31..86468f1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -158,6 +158,8 @@
<string name="set_as_homepage">Set as homepage</string>
<!-- Toast informing the user that their action to save a bookmark has succeeded -->
<string name="bookmark_saved">Saved to bookmarks.</string>
+ <!-- Toast informing the user that their action to save a bookmark did not succeed -->
+ <string name="bookmark_not_saved">Unable to save bookmark.</string>
<!-- Toast confirming that the homepage has been set -->
<string name="homepage_set">Homepage set.</string>
<!-- Error that appears in the title of Bookmark dialog when user selects OK with empty Name field -->
@@ -514,9 +516,6 @@
<!-- Verb placed in front of a screenshot of a web page that, when clicked,
will add that page to bookmarks -->
<string name="add_bookmark_short">Add</string>
- <!-- Add bookmark dialog sets its title to this if we have no database.
- This is an error case -->
- <string name="no_database">No database!</string>
<!-- This string is for the browser "Go To" UI. -->
<!-- Do not translate. This string is not displayed in UI (no badge is selected for go to). -->
@@ -674,7 +673,7 @@
<item>eBay</item>
<item>http://www.ebay.com/</item>
<item>CNN</item>
- <item>http://www.cnn.com/</item>
+ <item>http://www.cnn.com/index.html</item>
<item>NY Times</item>
<item>http://www.nytimes.com/</item>
<item>ESPN</item>
diff --git a/src/com/android/browser/AddBookmarkPage.java b/src/com/android/browser/AddBookmarkPage.java
index 71bf481..0ded526 100644
--- a/src/com/android/browser/AddBookmarkPage.java
+++ b/src/com/android/browser/AddBookmarkPage.java
@@ -25,6 +25,8 @@ import android.graphics.Bitmap;
import android.net.ParseException;
import android.net.WebAddress;
import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
import android.provider.Browser;
import android.view.View;
import android.view.Window;
@@ -50,12 +52,15 @@ public class AddBookmarkPage extends Activity {
private Bitmap mThumbnail;
private String mOriginalUrl;
+ // Message IDs
+ private static final int SAVE_BOOKMARK = 100;
+
+ private Handler mHandler;
+
private View.OnClickListener mSaveBookmark = new View.OnClickListener() {
public void onClick(View v) {
if (save()) {
finish();
- Toast.makeText(AddBookmarkPage.this, R.string.bookmark_saved,
- Toast.LENGTH_LONG).show();
}
}
};
@@ -94,7 +99,6 @@ public class AddBookmarkPage extends Activity {
mAddress = (EditText) findViewById(R.id.address);
mAddress.setText(url);
-
View.OnClickListener accept = mSaveBookmark;
mButton = (TextView) findViewById(R.id.OK);
mButton.setOnClickListener(accept);
@@ -106,13 +110,59 @@ public class AddBookmarkPage extends Activity {
mButton.requestFocus();
}
}
-
+
+ private void createHandler() {
+ if (mHandler == null) {
+ mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case SAVE_BOOKMARK:
+ // Unbundle bookmark data.
+ Bundle bundle = msg.getData();
+ String title = bundle.getString("title");
+ String url = bundle.getString("url");
+ boolean invalidateThumbnail = bundle.getBoolean("invalidateThumbnail");
+ Bitmap thumbnail = invalidateThumbnail
+ ? null : (Bitmap) bundle.getParcelable("thumbnail");
+ String touchIconUrl = bundle.getString("touchIconUrl");
+
+ // Save to the bookmarks DB.
+ if (updateBookmarksDB(title, url, thumbnail, touchIconUrl)) {
+ Toast.makeText(AddBookmarkPage.this, R.string.bookmark_saved,
+ Toast.LENGTH_LONG).show();
+ } else {
+ Toast.makeText(AddBookmarkPage.this, R.string.bookmark_not_saved,
+ Toast.LENGTH_LONG).show();
+ }
+ break;
+ }
+ }
+ };
+ }
+ }
+
+ private boolean updateBookmarksDB(String title, String url, Bitmap thumbnail, String touchIconUrl) {
+ try {
+ final ContentResolver cr = getContentResolver();
+ Bookmarks.addBookmark(null, cr, url, title, thumbnail, true);
+ if (touchIconUrl != null) {
+ final Cursor c =
+ BrowserBookmarksAdapter.queryBookmarksForUrl(cr, null, url, true);
+ new DownloadTouchIcon(cr, c, url).execute(mTouchIconUrl);
+ }
+ } catch (IllegalStateException e) {
+ return false;
+ }
+ return true;
+ }
+
/**
- * Save the data to the database.
- * Also, change the view to dialog stating
- * that the webpage has been saved.
+ * Parse the data entered in the dialog and post a message to update the bookmarks database.
*/
boolean save() {
+ createHandler();
+
String title = mTitle.getText().toString().trim();
String unfilteredUrl =
BrowserActivity.fixUrl(mAddress.getText().toString());
@@ -150,33 +200,25 @@ public class AddBookmarkPage extends Activity {
mAddress.setError(r.getText(R.string.bookmark_url_not_valid));
return false;
}
- try {
- if (mEditingExisting) {
- mMap.putString("title", title);
- mMap.putString("url", url);
- setResult(RESULT_OK, (new Intent()).setAction(
- getIntent().toString()).putExtras(mMap));
- } else {
- final ContentResolver cr = getContentResolver();
-
- // Only use mThumbnail if url and mOriginalUrl are matches.
- // Otherwise the user edited the url and the thumbnail no longer applies.
- if (url.equals(mOriginalUrl)) {
- Bookmarks.addBookmark(null, cr, url, title, mThumbnail, true);
- } else {
- Bookmarks.addBookmark(null, cr, url, title, null, true);
- }
- if (mTouchIconUrl != null) {
- final Cursor c =
- BrowserBookmarksAdapter.queryBookmarksForUrl(
- cr, null, url, true);
- new DownloadTouchIcon(cr, c, url).execute(mTouchIconUrl);
- }
- setResult(RESULT_OK);
- }
- } catch (IllegalStateException e) {
- setTitle(r.getText(R.string.no_database));
- return false;
+
+ if (mEditingExisting) {
+ mMap.putString("title", title);
+ mMap.putString("url", url);
+ mMap.putBoolean("invalidateThumbnail", !url.equals(mOriginalUrl));
+ setResult(RESULT_OK, (new Intent()).setAction(
+ getIntent().toString()).putExtras(mMap));
+ } else {
+ // Post a message to write to the DB.
+ Bundle bundle = new Bundle();
+ bundle.putString("title", title);
+ bundle.putString("url", url);
+ bundle.putParcelable("thumbnail", mThumbnail);
+ bundle.putBoolean("invalidateThumbnail", !url.equals(mOriginalUrl));
+ bundle.putString("touchIconUrl", mTouchIconUrl);
+ Message msg = Message.obtain(mHandler, SAVE_BOOKMARK);
+ msg.setData(bundle);
+ mHandler.sendMessage(msg);
+ setResult(RESULT_OK);
}
return true;
}
diff --git a/src/com/android/browser/BrowserBookmarksAdapter.java b/src/com/android/browser/BrowserBookmarksAdapter.java
index 8b0fb41..dd56d2f 100644
--- a/src/com/android/browser/BrowserBookmarksAdapter.java
+++ b/src/com/android/browser/BrowserBookmarksAdapter.java
@@ -170,6 +170,10 @@ class BrowserBookmarksAdapter extends BaseAdapter {
getString(Browser.HISTORY_PROJECTION_URL_INDEX))) {
values.put(Browser.BookmarkColumns.URL, url);
}
+
+ if (map.getBoolean("invalidateThumbnail") == true) {
+ values.put(Browser.BookmarkColumns.THUMBNAIL, new byte[0]);
+ }
if (values.size() > 0
&& mContentResolver.update(Browser.BOOKMARKS_URI, values,
"_id = " + id, null) != -1) {