diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/browser/AddBookmarkPage.java | 100 | ||||
-rw-r--r-- | src/com/android/browser/BrowserActivity.java | 96 | ||||
-rw-r--r-- | src/com/android/browser/SaveToHomescreenDialog.java | 127 | ||||
-rw-r--r-- | src/com/android/browser/TitleBar.java | 3 | ||||
-rw-r--r-- | src/com/android/browser/TitleBarXLarge.java | 3 |
5 files changed, 101 insertions, 228 deletions
diff --git a/src/com/android/browser/AddBookmarkPage.java b/src/com/android/browser/AddBookmarkPage.java index 9e5b349..fc480ee 100644 --- a/src/com/android/browser/AddBookmarkPage.java +++ b/src/com/android/browser/AddBookmarkPage.java @@ -42,6 +42,7 @@ import android.provider.BrowserContract; import android.text.TextUtils; import android.view.KeyEvent; import android.view.LayoutInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.Window; @@ -52,6 +53,7 @@ import android.widget.AdapterView; import android.widget.CursorAdapter; import android.widget.EditText; import android.widget.ListView; +import android.widget.PopupMenu; import android.widget.TextView; import android.widget.Toast; @@ -63,7 +65,7 @@ import java.util.Stack; public class AddBookmarkPage extends Activity implements View.OnClickListener, TextView.OnEditorActionListener, AdapterView.OnItemClickListener, LoaderManager.LoaderCallbacks<Cursor>, - BreadCrumbView.Controller { + BreadCrumbView.Controller, PopupMenu.OnMenuItemClickListener { public static final long DEFAULT_FOLDER_ID = -1; @@ -84,7 +86,6 @@ public class AddBookmarkPage extends Activity private boolean mEditingExisting; private Bundle mMap; private String mTouchIconUrl; - private Bitmap mThumbnail; private String mOriginalUrl; private TextView mFolder; private View mDefaultView; @@ -98,6 +99,7 @@ public class AddBookmarkPage extends Activity private TextView mFakeTitle; private View mCrumbHolder; private ListView mListView; + private boolean mSaveToHomeScreen; private static class Folder { String Name; @@ -110,6 +112,7 @@ public class AddBookmarkPage extends Activity // Message IDs private static final int SAVE_BOOKMARK = 100; + private static final int TOUCH_ICON_DOWNLOADED = 101; private Handler mHandler; @@ -207,6 +210,7 @@ public class AddBookmarkPage extends Activity completeOrCancelFolderNaming(false); } else { // User has selected a folder. Go back to the opening page + mSaveToHomeScreen = false; switchToDefaultView(true); } } else if (save()) { @@ -221,7 +225,14 @@ public class AddBookmarkPage extends Activity finish(); } } else if (v == mFolder) { - switchToFolderSelector(); + // FIXME: We want to use mFolder as an anchor, but cannot until we + // fix the issue that the PopupMenu will not extend past the edge of + // the dialog. + PopupMenu popup = new PopupMenu(this, mFakeTitle); + popup.getMenuInflater().inflate(R.menu.folder_choice, + popup.getMenu()); + popup.setOnMenuItemClickListener(this); + popup.show(); } else if (v == mAddNewFolder) { mFolderNamer.setVisibility(View.VISIBLE); mFolderNamer.setText(R.string.new_folder); @@ -234,6 +245,28 @@ public class AddBookmarkPage extends Activity } } + @Override + public boolean onMenuItemClick(MenuItem item) { + switch(item.getItemId()) { + case R.id.bookmarks: + mCurrentFolder = getBookmarksBarId(this); + mFolder.setText(item.getTitle()); + mSaveToHomeScreen = false; + break; + case R.id.home_screen: + // Create a short cut to the home screen + mSaveToHomeScreen = true; + mFolder.setText(item.getTitle()); + break; + case R.id.other: + switchToFolderSelector(); + break; + default: + return false; + } + return true; + } + // Refresh the ListView to hide or show the empty view, as necessary. // Should be called after mFolderNamer is shown or hidden. private void updateList() { @@ -462,7 +495,6 @@ public class AddBookmarkPage extends Activity title = mMap.getString("title"); url = mOriginalUrl = mMap.getString("url"); mTouchIconUrl = mMap.getString("touch_icon_url"); - mThumbnail = (Bitmap) mMap.getParcelable("thumbnail"); mCurrentFolder = mMap.getLong(BrowserContract.Bookmarks.PARENT, DEFAULT_FOLDER_ID); } if (mCurrentFolder == DEFAULT_FOLDER_ID) { @@ -609,6 +641,14 @@ public class AddBookmarkPage extends Activity Toast.LENGTH_LONG).show(); } break; + case TOUCH_ICON_DOWNLOADED: + Bundle b = msg.getData(); + sendBroadcast(BookmarkUtils.createAddToHomeIntent( + AddBookmarkPage.this, b.getString("url"), + b.getString("title"), + (Bitmap) b.getParcelable("touchIcon"), + (Bitmap) b.getParcelable("favicon"))); + break; } } }; @@ -671,27 +711,59 @@ public class AddBookmarkPage extends Activity return false; } + if (mSaveToHomeScreen) { + mEditingExisting = false; + } + + boolean urlUnmodified = url.equals(mOriginalUrl); + if (mEditingExisting) { mMap.putString("title", title); mMap.putString("url", url); - mMap.putBoolean("invalidateThumbnail", !url.equals(mOriginalUrl)); + mMap.putBoolean("invalidateThumbnail", !urlUnmodified); // FIXME: This does not work yet mMap.putLong(BrowserContract.Bookmarks.PARENT, mCurrentFolder); setResult(RESULT_OK, (new Intent()).setAction( getIntent().toString()).putExtras(mMap)); } else { - // Post a message to write to the DB. + Bitmap thumbnail; + Bitmap favicon; + if (urlUnmodified) { + thumbnail = (Bitmap) mMap.getParcelable("thumbnail"); + favicon = (Bitmap) mMap.getParcelable("favicon"); + } else { + thumbnail = null; + favicon = null; + } + 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); - // Start a new thread so as to not slow down the UI - Thread t = new Thread(new SaveBookmarkRunnable(getApplicationContext(), msg)); - t.start(); + bundle.putParcelable("favicon", favicon); + + if (mSaveToHomeScreen) { + if (mTouchIconUrl != null && urlUnmodified) { + Message msg = Message.obtain(mHandler, + TOUCH_ICON_DOWNLOADED); + msg.setData(bundle); + DownloadTouchIcon icon = new DownloadTouchIcon(this, msg, + mMap.getString("user_agent")); + icon.execute(mTouchIconUrl); + } else { + sendBroadcast(BookmarkUtils.createAddToHomeIntent(this, url, + title, null /*touchIcon*/, favicon)); + } + } else { + bundle.putParcelable("thumbnail", thumbnail); + bundle.putBoolean("invalidateThumbnail", !urlUnmodified); + bundle.putString("touchIconUrl", mTouchIconUrl); + // Post a message to write to the DB. + Message msg = Message.obtain(mHandler, SAVE_BOOKMARK); + msg.setData(bundle); + // Start a new thread so as to not slow down the UI + Thread t = new Thread(new SaveBookmarkRunnable(getApplicationContext(), msg)); + t.start(); + } setResult(RESULT_OK); LogTag.logBookmarkAdded(url, "bookmarkview"); } diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java index 9683b31..bd50a77 100644 --- a/src/com/android/browser/BrowserActivity.java +++ b/src/com/android/browser/BrowserActivity.java @@ -103,11 +103,11 @@ import android.webkit.ValueCallback; import android.webkit.WebChromeClient; import android.webkit.WebHistoryItem; import android.webkit.WebIconDatabase; +import android.webkit.WebSettings; import android.webkit.WebView; import android.widget.EditText; import android.widget.FrameLayout; import android.widget.LinearLayout; -import android.widget.PopupMenu; import android.widget.TextView; import android.widget.Toast; @@ -130,7 +130,7 @@ import java.util.regex.Pattern; public class BrowserActivity extends Activity implements View.OnCreateContextMenuListener, DownloadListener, - PopupMenu.OnMenuItemClickListener, BookmarksHistoryCallbacks { + BookmarksHistoryCallbacks { /* Define some aliases to make these debugging flags easier to refer to. * This file imports android.provider.Browser, so we can't just refer to "Browser.DEBUG". @@ -1490,9 +1490,17 @@ public class BrowserActivity extends Activity WebView w = getTopWindow(); i.putExtra("url", w.getUrl()); i.putExtra("title", w.getTitle()); - i.putExtra("touch_icon_url", w.getTouchIconUrl()); + String touchIconUrl = w.getTouchIconUrl(); + if (touchIconUrl != null) { + i.putExtra("touch_icon_url", touchIconUrl); + WebSettings settings = w.getSettings(); + if (settings != null) { + i.putExtra("user_agent", settings.getUserAgentString()); + } + } i.putExtra("thumbnail", createScreenshot(w, getDesiredThumbnailWidth(this), getDesiredThumbnailHeight(this))); + i.putExtra("favicon", w.getFavicon()); i.putExtra(BrowserContract.Bookmarks.PARENT, folderId); // Put the dialog at the upper right of the screen, covering the @@ -2296,8 +2304,6 @@ public class BrowserActivity extends Activity static final int UPDATE_BOOKMARK_THUMBNAIL = 108; - private static final int TOUCH_ICON_DOWNLOADED = 109; - private static final int OPEN_BOOKMARKS = 201; // Private handler for handling javascript and saving passwords @@ -2373,14 +2379,6 @@ public class BrowserActivity extends Activity updateScreenshot(view); } break; - - case TOUCH_ICON_DOWNLOADED: - Bundle b = msg.getData(); - showSaveToHomescreenDialog(b.getString("url"), - b.getString("title"), - (Bitmap) b.getParcelable("touchIcon"), - (Bitmap) b.getParcelable("favicon")); - break; } } }; @@ -3806,52 +3804,6 @@ public class BrowserActivity extends Activity startActivity(intent); } - /* package */ void promptAddOrInstallBookmark(View anchor) { - PopupMenu popup = new PopupMenu(this, anchor); - popup.getMenuInflater().inflate(R.menu.bookmark_shortcut, popup.getMenu()); - popup.setOnMenuItemClickListener(this); - popup.show(); - } - - /** - * popup menu item click listener - * @param item - */ - public boolean onMenuItemClick(MenuItem item) { - switch(item.getItemId()) { - case R.id.add_bookmark_menu_id: - bookmarkCurrentPage(AddBookmarkPage.DEFAULT_FOLDER_ID); - return true; - case R.id.shortcut_to_home_menu_id: - Tab current = mTabControl.getCurrentTab(); - current.populatePickerData(); - String touchIconUrl = mTabControl.getCurrentWebView().getTouchIconUrl(); - if (touchIconUrl != null) { - // Download the touch icon for this site then save - // it to the - // homescreen. - Bundle b = new Bundle(); - b.putString("url", current.getUrl()); - b.putString("title", current.getTitle()); - b.putParcelable("favicon", current.getFavicon()); - Message msg = mHandler.obtainMessage(TOUCH_ICON_DOWNLOADED); - msg.setData(b); - new DownloadTouchIcon(BrowserActivity.this, msg, - mTabControl.getCurrentWebView().getSettings().getUserAgentString()) - .execute(touchIconUrl); - } else { - // add to homescreen, can do it immediately as there - // is no touch - // icon. - showSaveToHomescreenDialog( - current.getUrl(), current.getTitle(), null, current.getFavicon()); - } - return true; - default: - return false; - } - } - /* package */Dialog makeAddOrInstallDialog() { final Tab current = mTabControl.getCurrentTab(); Resources resources = getResources(); @@ -3918,32 +3870,6 @@ public class BrowserActivity extends Activity mContentView.addView(mComboView, COVER_SCREEN_PARAMS); } - private void showSaveToHomescreenDialog(String url, String title, Bitmap touchIcon, - Bitmap favicon) { - Intent intent = new Intent(this, SaveToHomescreenDialog.class); - - // Just in case the user tries to save before a page finishes loading - // so the current history item, and therefore the page, is null. - if (null == url) { - url = mLastEnteredUrl; - // This can happen. - if (null == url) { - url = mSettings.getHomePage(); - } - } - - // In case the web page has not yet received its associated title. - if (title == null) { - title = url; - } - - intent.putExtra("title", title); - intent.putExtra("url", url); - intent.putExtra("favicon", favicon); - intent.putExtra("touchIcon", touchIcon); - startActivity(intent); - } - // Called when loading from context menu or LOAD_URL message private void loadUrlFromContext(WebView view, String url) { // In case the user enters nothing. diff --git a/src/com/android/browser/SaveToHomescreenDialog.java b/src/com/android/browser/SaveToHomescreenDialog.java deleted file mode 100644 index 15f0aea..0000000 --- a/src/com/android/browser/SaveToHomescreenDialog.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2010 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. - */ - -package com.android.browser; - -import android.app.Activity; -import android.content.ComponentName; -import android.content.ContentResolver; -import android.content.Intent; -import android.content.res.Resources; -import android.database.Cursor; -import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; -import android.net.ParseException; -import android.net.Uri; -import android.net.WebAddress; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.provider.Browser; -import android.util.Log; -import android.view.View; -import android.view.Window; -import android.widget.Button; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.TextView; -import android.widget.Toast; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Date; - -public class SaveToHomescreenDialog extends Activity { - - private EditText mTitle; - private String mUrl; - private Bitmap mFavicon; - private Bitmap mTouchIcon; - - private View.OnClickListener mOk = new View.OnClickListener() { - public void onClick(View v) { - if (save()) { - finish(); - } - } - }; - - private View.OnClickListener mCancel = new View.OnClickListener() { - public void onClick(View v) { - finish(); - } - }; - - protected void onCreate(Bundle icicle) { - super.onCreate(icicle); - requestWindowFeature(Window.FEATURE_LEFT_ICON); - setContentView(R.layout.browser_add_bookmark_const_url); - setTitle(R.string.create_shortcut_bookmark); - getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, - R.drawable.ic_list_bookmark); - - String title = null; - String url = null; - Bundle map = getIntent().getExtras(); - if (map != null) { - title = map.getString("title"); - } - - mUrl = map.getString("url"); - mFavicon = (Bitmap)map.getParcelable("favicon"); - mTouchIcon = (Bitmap)map.getParcelable("touchIcon"); - - Bitmap icon = BookmarkUtils.createIcon(this, mTouchIcon, mFavicon, - BookmarkUtils.BookmarkIconType.ICON_HOME_SHORTCUT); - getWindow().setFeatureDrawable(Window.FEATURE_LEFT_ICON, new BitmapDrawable(icon)); - - mTitle = (EditText) findViewById(R.id.title); - mTitle.setText(title); - - Button okButton = (Button) findViewById(R.id.OK); - okButton.setOnClickListener(mOk); - - Button cancelButton = (Button) findViewById(R.id.cancel); - cancelButton.setOnClickListener(mCancel); - - if (!getWindow().getDecorView().isInTouchMode()) { - okButton.requestFocus(); - } - } - - /** - * Parse the data entered in the dialog and send an intent to create an - * icon on the homescreen. - */ - private boolean save() { - String title = mTitle.getText().toString().trim(); - String unfilteredUrl = BrowserActivity.fixUrl(mUrl); - if (title.length() == 0) { - mTitle.setError(getResources().getText(R.string.bookmark_needs_title)); - return false; - } - - String url = unfilteredUrl.trim(); - - sendBroadcast(BookmarkUtils.createAddToHomeIntent(this, url, title, - mTouchIcon, mFavicon)); - setResult(RESULT_OK); - return true; - } -} diff --git a/src/com/android/browser/TitleBar.java b/src/com/android/browser/TitleBar.java index bbb55ad..035dc34 100644 --- a/src/com/android/browser/TitleBar.java +++ b/src/com/android/browser/TitleBar.java @@ -205,7 +205,8 @@ public class TitleBar extends TitleBarBase { } else if (mInLoad) { mBrowserActivity.stopLoading(); } else { - mBrowserActivity.promptAddOrInstallBookmark(button); + mBrowserActivity.bookmarkCurrentPage( + AddBookmarkPage.DEFAULT_FOLDER_ID); } button.setPressed(false); } else if (mTitleBg.isPressed()) { diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java index 7310f75..b87ea78 100644 --- a/src/com/android/browser/TitleBarXLarge.java +++ b/src/com/android/browser/TitleBarXLarge.java @@ -127,7 +127,8 @@ public class TitleBarXLarge extends TitleBarBase } else if (mForwardButton == v) { mBrowserActivity.getTopWindow().goForward(); } else if (mStar == v) { - mBrowserActivity.promptAddOrInstallBookmark(mStar); + mBrowserActivity.bookmarkCurrentPage( + AddBookmarkPage.DEFAULT_FOLDER_ID); } else if (mAllButton == v) { mBrowserActivity.bookmarksOrHistoryPicker(false); } else if (mSearchButton == v) { |