diff options
author | Ben Murdoch <benm@google.com> | 2010-07-06 16:30:38 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-07-09 13:54:14 +0100 |
commit | eecb4e6cb64af03aad3f9facdbf6fd7190091b41 (patch) | |
tree | 4ca0e78bd031a7d64cc5fc3161dad4d15d01722f /src/com/android/browser/SaveToHomescreenDialog.java | |
parent | 6af492aeddda96c749142885e3b49455aa336309 (diff) | |
download | packages_apps_Browser-eecb4e6cb64af03aad3f9facdbf6fd7190091b41.zip packages_apps_Browser-eecb4e6cb64af03aad3f9facdbf6fd7190091b41.tar.gz packages_apps_Browser-eecb4e6cb64af03aad3f9facdbf6fd7190091b41.tar.bz2 |
Improve the visibility and discoverability of the "add shortcut
to home" functionality in the Browser.
When the user selects the bookmark button adjacent to the URL bar
they will be prompted to either add a new bookmark for the current
page or add a shortcut to the current page to their homescreen,
rather than being taken to the bookmark management activity. The
bookmarks button on the options menu will still take the user
directly to the bookmark management activity.
Bug: b/2794945
Change-Id: I07190250379f1d6e2fe6b8ea280317949cd58b15
Diffstat (limited to 'src/com/android/browser/SaveToHomescreenDialog.java')
-rw-r--r-- | src/com/android/browser/SaveToHomescreenDialog.java | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/src/com/android/browser/SaveToHomescreenDialog.java b/src/com/android/browser/SaveToHomescreenDialog.java new file mode 100644 index 0000000..15f0aea --- /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; + } +} |