Enable setting home page from bookmarks/history.
Fix for issue 1482954: Longpress on bookmark or history should set homepage
[1/1]. Add a string for set homepage. Add the option in both the context menu
for the browser history and for browser bookmarks. In BrowserHistoryPage and
BrowserBookmarksPage handle the new option by setting the new homepage.
diff --git a/res/menu/bookmarkscontext.xml b/res/menu/bookmarkscontext.xml
index b43e242..ba5d1dc 100644
--- a/res/menu/bookmarkscontext.xml
+++ b/res/menu/bookmarkscontext.xml
@@ -34,5 +34,7 @@
android:title="@string/contextmenu_copylink"/>
<item android:id="@+id/delete_context_menu_id"
android:title="@string/remove_bookmark"/>
+ <item android:id="@+id/homepage_context_menu_id"
+ android:title="@string/set_as_homepage"/>
</group>
</menu>
diff --git a/res/menu/historycontext.xml b/res/menu/historycontext.xml
index dfda010..5306396 100644
--- a/res/menu/historycontext.xml
+++ b/res/menu/historycontext.xml
@@ -26,5 +26,7 @@
<item android:id="@+id/copy_context_menu_id"
android:title="@string/contextmenu_copylink"/>
<item android:id="@+id/delete_context_menu_id"
- android:title="@string/remove_history_item"/>
+ android:title="@string/remove_history_item"/>
+ <item android:id="@+id/homepage_context_menu_id"
+ android:title="@string/set_as_homepage"/>
</menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f778c76..95c85f8 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -143,8 +143,12 @@
<string name="remove_bookmark">Delete bookmark</string>
<!-- Menu item to remove the currently highlighted history entry from the list of previously visited sites -->
<string name="remove_history_item">Remove from history</string>
+ <!-- Context menu item for setting the bookmark/history item as the homepage -->
+ <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 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 -->
<string name="bookmark_needs_title">"Bookmark must have a name."</string>
<!-- Error that appears in the title of Bookmark dialog when user selects OK with empty Location field -->
diff --git a/src/com/android/browser/BrowserBookmarksPage.java b/src/com/android/browser/BrowserBookmarksPage.java
index dd34c14..45fca87 100644
--- a/src/com/android/browser/BrowserBookmarksPage.java
+++ b/src/com/android/browser/BrowserBookmarksPage.java
@@ -44,6 +44,7 @@
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView;
import android.widget.ListView;
+import android.widget.Toast;
/**
* View showing the user's bookmarks in the browser.
@@ -107,7 +108,13 @@
break;
case R.id.copy_url_context_menu_id:
copy(getUrl(i.position));
-
+ break;
+ case R.id.homepage_context_menu_id:
+ BrowserSettings.getInstance().setHomePage(this,
+ getUrl(i.position));
+ Toast.makeText(this, R.string.homepage_set,
+ Toast.LENGTH_LONG).show();
+ break;
default:
return super.onContextItemSelected(item);
}
diff --git a/src/com/android/browser/BrowserHistoryPage.java b/src/com/android/browser/BrowserHistoryPage.java
index 2b781a1..e333416 100644
--- a/src/com/android/browser/BrowserHistoryPage.java
+++ b/src/com/android/browser/BrowserHistoryPage.java
@@ -49,6 +49,7 @@
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.TextView;
+import android.widget.Toast;
import java.util.List;
import java.util.Vector;
@@ -222,6 +223,11 @@
Browser.deleteFromHistory(getContentResolver(), url);
mAdapter.refreshData();
return true;
+ case R.id.homepage_context_menu_id:
+ BrowserSettings.getInstance().setHomePage(this, url);
+ Toast.makeText(this, R.string.homepage_set,
+ Toast.LENGTH_LONG).show();
+ return true;
default:
break;
}