summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/browser')
-rw-r--r--src/com/android/browser/AddBookmarkPage.java57
-rw-r--r--src/com/android/browser/BrowserActivity.java79
-rw-r--r--src/com/android/browser/SaveToHomescreenDialog.java127
-rw-r--r--src/com/android/browser/TitleBar.java2
-rw-r--r--src/com/android/browser/TitleBarXLarge.java4
5 files changed, 255 insertions, 14 deletions
diff --git a/src/com/android/browser/AddBookmarkPage.java b/src/com/android/browser/AddBookmarkPage.java
index 1104d5e25..104a495cc 100644
--- a/src/com/android/browser/AddBookmarkPage.java
+++ b/src/com/android/browser/AddBookmarkPage.java
@@ -51,6 +51,7 @@ public class AddBookmarkPage extends Activity {
private String mTouchIconUrl;
private Bitmap mThumbnail;
private String mOriginalUrl;
+ private boolean mIsUrlEditable = true;
// Message IDs
private static final int SAVE_BOOKMARK = 100;
@@ -74,13 +75,24 @@ public class AddBookmarkPage extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_LEFT_ICON);
- setContentView(R.layout.browser_add_bookmark);
+
+ mMap = getIntent().getExtras();
+ if (mMap != null) {
+ mIsUrlEditable = mMap.getBoolean("url_editable", true);
+ }
+
+ if (mIsUrlEditable) {
+ setContentView(R.layout.browser_add_bookmark);
+ } else {
+ setContentView(R.layout.browser_add_bookmark_const_url);
+ }
+
setTitle(R.string.save_to_bookmarks);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_list_bookmark);
String title = null;
String url = null;
- mMap = getIntent().getExtras();
+
if (mMap != null) {
Bundle b = mMap.getBundle("bookmark");
if (b != null) {
@@ -96,8 +108,11 @@ public class AddBookmarkPage extends Activity {
mTitle = (EditText) findViewById(R.id.title);
mTitle.setText(title);
- mAddress = (EditText) findViewById(R.id.address);
- mAddress.setText(url);
+
+ if (mIsUrlEditable) {
+ mAddress = (EditText) findViewById(R.id.address);
+ mAddress.setText(url);
+ }
View.OnClickListener accept = mSaveBookmark;
mButton = (TextView) findViewById(R.id.OK);
@@ -173,8 +188,14 @@ public class AddBookmarkPage extends Activity {
createHandler();
String title = mTitle.getText().toString().trim();
- String unfilteredUrl =
- BrowserActivity.fixUrl(mAddress.getText().toString());
+ String unfilteredUrl;
+ if (mIsUrlEditable) {
+ unfilteredUrl =
+ BrowserActivity.fixUrl(mAddress.getText().toString());
+ } else {
+ unfilteredUrl = mOriginalUrl;
+ }
+
boolean emptyTitle = title.length() == 0;
boolean emptyUrl = unfilteredUrl.trim().length() == 0;
Resources r = getResources();
@@ -183,9 +204,15 @@ public class AddBookmarkPage extends Activity {
mTitle.setError(r.getText(R.string.bookmark_needs_title));
}
if (emptyUrl) {
- mAddress.setError(r.getText(R.string.bookmark_needs_url));
+ if (mIsUrlEditable) {
+ mAddress.setError(r.getText(R.string.bookmark_needs_url));
+ } else {
+ Toast.makeText(AddBookmarkPage.this, R.string.bookmark_needs_url,
+ Toast.LENGTH_LONG).show();
+ }
+ return false;
}
- return false;
+
}
String url = unfilteredUrl.trim();
try {
@@ -200,7 +227,12 @@ public class AddBookmarkPage extends Activity {
// can't save their bookmark. If it was null, we'll assume
// they meant http when we parse it in the WebAddress class.
if (scheme != null) {
- mAddress.setError(r.getText(R.string.bookmark_cannot_save_url));
+ if (mIsUrlEditable) {
+ mAddress.setError(r.getText(R.string.bookmark_cannot_save_url));
+ } else {
+ Toast.makeText(AddBookmarkPage.this, R.string.bookmark_cannot_save_url,
+ Toast.LENGTH_LONG).show();
+ }
return false;
}
WebAddress address;
@@ -216,7 +248,12 @@ public class AddBookmarkPage extends Activity {
}
}
} catch (URISyntaxException e) {
- mAddress.setError(r.getText(R.string.bookmark_url_not_valid));
+ if (mIsUrlEditable) {
+ mAddress.setError(r.getText(R.string.bookmark_url_not_valid));
+ } else {
+ Toast.makeText(AddBookmarkPage.this, R.string.bookmark_url_not_valid,
+ Toast.LENGTH_LONG).show();
+ }
return false;
}
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index c7abad162..aeb8c460d 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -1487,6 +1487,7 @@ public class BrowserActivity extends Activity
i.putExtra("touch_icon_url", w.getTouchIconUrl());
i.putExtra("thumbnail", createScreenshot(w, getDesiredThumbnailWidth(this),
getDesiredThumbnailHeight(this)));
+ i.putExtra("url_editable", false);
startActivity(i);
}
@@ -2287,6 +2288,8 @@ public class BrowserActivity extends Activity
static final int UPDATE_BOOKMARK_THUMBNAIL = 108;
+ private static final int TOUCH_ICON_DOWNLOADED = 109;
+
// Private handler for handling javascript and saving passwords
private Handler mHandler = new Handler() {
@@ -2357,6 +2360,14 @@ 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;
}
}
};
@@ -3728,6 +3739,47 @@ public class BrowserActivity extends Activity
}
+ /* package*/ void promptAddOrInstallBookmark() {
+ final Tab current = mTabControl.getCurrentTab();
+ Resources resources = getResources();
+ CharSequence[] choices = {
+ resources.getString(R.string.save_to_bookmarks),
+ resources.getString(R.string.create_shortcut_bookmark)
+ };
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.add_new_bookmark);
+ builder.setItems(choices, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int item) {
+ if (item == 0) {
+ bookmarkCurrentPage();
+ } else if (item == 1) {
+ 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(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());
+ }
+ }
+ }
+ });
+ builder.create().show();
+ }
+
/**
* Open the Go page.
* @param startWithHistory If true, open starting on the history tab.
@@ -3771,6 +3823,33 @@ public class BrowserActivity extends Activity
startActivityForResult(intent, COMBO_PAGE);
}
+ 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
new file mode 100644
index 000000000..15f0aeafc
--- /dev/null
+++ b/src/com/android/browser/SaveToHomescreenDialog.java
@@ -0,0 +1,127 @@
+/*
+ * 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 4e76334f8..f45025dd6 100644
--- a/src/com/android/browser/TitleBar.java
+++ b/src/com/android/browser/TitleBar.java
@@ -205,7 +205,7 @@ public class TitleBar extends TitleBarBase {
} else if (mInLoad) {
mBrowserActivity.stopLoading();
} else {
- mBrowserActivity.bookmarksOrHistoryPicker(false);
+ mBrowserActivity.promptAddOrInstallBookmark();
}
button.setPressed(false);
} else if (mTitleBg.isPressed()) {
diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java
index 76f57d00b..0d799a8b4 100644
--- a/src/com/android/browser/TitleBarXLarge.java
+++ b/src/com/android/browser/TitleBarXLarge.java
@@ -94,9 +94,7 @@ public class TitleBarXLarge extends TitleBarBase {
} else if (mForwardButton == v) {
mBrowserActivity.getTopWindow().goForward();
} else if (mStar == v) {
- // FIXME: Show a menu with option to bookmark or
- // save to home page
- mBrowserActivity.bookmarkCurrentPage();
+ mBrowserActivity.promptAddOrInstallBookmark();
} else if (mMenu == v) {
mBrowserActivity.openOptionsMenu();
} else if (mStopButton == v) {