增加添加到主页
This commit is contained in:
@@ -25,6 +25,8 @@ import android.view.View;
|
||||
import android.view.View.OnCreateContextMenuListener;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
@@ -112,7 +114,7 @@ public class FavoriteActivity extends Activity {
|
||||
String title = ((TextView) info.targetView.findViewById(R.id.title)).getText().toString();
|
||||
menu.setHeaderIcon(R.drawable.link);
|
||||
menu.setHeaderTitle(title);
|
||||
String[] sm = { "在新窗口中打开", "复制链接", "分享", "修改", "删除" };
|
||||
String[] sm = { "在新窗口中打开", "复制链接", "分享", "修改", "删除", "添加到主页" };
|
||||
for (int i=0; i<sm.length; i++) {
|
||||
menu.add(0, i, i, sm[i]);
|
||||
}
|
||||
@@ -408,6 +410,15 @@ public class FavoriteActivity extends Activity {
|
||||
} else
|
||||
Toast.makeText(getApplicationContext(), "删除失败", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case 5:
|
||||
WebView webView = new WebView(FavoriteActivity.this);
|
||||
WebSettings webSettings = webView.getSettings();
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
webSettings.setDomStorageEnabled(true);
|
||||
webView.loadUrl("file:///android_asset/home.htm");
|
||||
String js = "javascript:window.onload=function(){var json=JSON.parse(localStorage.webfav);for(var i=0;i<json.length;i++){if(json[i].website=='" + url + "'){alert('网址已经存在!');return;}}json.push({title: '" + title + "',website:'" + url + "'});localStorage.webfav=JSON.stringify(json);}";
|
||||
webView.loadUrl(js);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user