#############################################
本文为极度寒冰原创,转载请注明出处
#############################################
最近在android浏览器上做了几个小feature,来分享一下。
这个feature的效果是将网页上面的链接直接长按后可以选择存入书签。
具体实现的code为:
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java index 8341567..fd17a6a 100644 --- a/src/com/android/browser/Controller.java +++ b/src/com/android/browser/Controller.java @@ -481,6 +481,18 @@ public class Controller } }); } + // feature add by chao + private void bookmarks(String url, String title, String src) + { + Intent i = new Intent(mActivity,AddBookmarkPage.class); + i.putExtra(BrowserContract.Bookmarks.URL, url); + i.putExtra(BrowserContract.Bookmarks.TITLE, title); + if(i != null) + { + mActivity.startActivity(i); + } + } + // end private void startHandler() { mHandler = new Handler() { @@ -527,6 +539,11 @@ public class Controller mActivity, url, view.getSettings().getUserAgentString(), null, null, null, view.isPrivateBrowsingEnabled()); break; + //Feature add by chao + case R.id.save_bookmarks_menu_id: + bookmarks(url, title, src); + break; + //end } break; } @@ -1850,6 +1867,7 @@ public class Controller case R.id.open_context_menu_id: case R.id.save_link_context_menu_id: case R.id.copy_link_context_menu_id: + case R.id.save_bookmarks_menu_id: final WebView webView = getCurrentTopWebView(); if (null == webView) { result = false; --- a/res/menu/browsercontext.xml +++ b/res/menu/browsercontext.xml @@ -42,6 +42,10 @@ android:title="@string/contextmenu_openlink_newwindow"/> <item android:id="@+id/save_link_context_menu_id" android:title="@string/contextmenu_savelink"/> + <!--Feature add by chao begin --> + <item android:id="@+id/save_bookmarks_menu_id" + android:title="@string/save_to_bookmarks"/> + <!--Feature add by chao end --> <item android:id="@+id/copy_link_context_menu_id" android:title="@string/contextmenu_copylink"/> </group>