@Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); switch (item.getItemId()) { case MENU_DELETE: Controller.getInstance().getAdBlockWhiteList().remove(info.position); Controller.getInstance().saveAdBlockWhiteList(); fillData(); return true; default: return super.onContextItemSelected(item); } }
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); int position = ((AdapterContextMenuInfo) menuInfo).position; if (position != -1) { menu.setHeaderTitle(Controller.getInstance().getAdBlockWhiteList().get(position)); } menu.add(0, MENU_DELETE, 0, R.string.AdBlockerWhiteListActivity_DeleteMenu); }
/** Fill the list view. */ private void fillData() { ArrayAdapter<String> adapter = new ArrayAdapter<String>( this, R.layout.adblockerwhitelistrow, R.id.AdBlockerWhiteListRow_Title, Controller.getInstance().getAdBlockWhiteList()); setListAdapter(adapter); setAnimation(); }
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (isExternalApplicationUrl(url)) { mMainActivity.onExternalApplicationUrl(url); return true; } else if (url.startsWith(Constants.URL_ACTION_SEARCH)) { String searchTerm = url.replace(Constants.URL_ACTION_SEARCH, ""); String searchUrl = Controller.getInstance() .getPreferences() .getString(Constants.PREFERENCES_GENERAL_SEARCH_URL, Constants.URL_SEARCH_GOOGLE); String newUrl = String.format(searchUrl, searchTerm); view.loadUrl(newUrl); return true; } else if (view.getHitTestResult() != null && view.getHitTestResult().getType() == HitTestResult.EMAIL_TYPE) { mMainActivity.onMailTo(url); return true; } else { // If the url is not from GWT mobile view, and is in the mobile view url list, then load it // with GWT. if ((!url.startsWith(Constants.URL_GOOGLE_MOBILE_VIEW_NO_FORMAT)) && (UrlUtils.checkInMobileViewUrlList(view.getContext(), url))) { String newUrl = String.format(Constants.URL_GOOGLE_MOBILE_VIEW, url); view.loadUrl(newUrl); return true; } else { ((CustomWebView) view).resetLoadedUrl(); mMainActivity.onUrlLoading(url); return false; } } }
/** Clear the white list. */ private void doClearWhiteList() { Controller.getInstance().getAdBlockWhiteList().clear(); Controller.getInstance().saveAdBlockWhiteList(); fillData(); }
/** * Add a value to the white list. * * @param value The value to add. */ private void doAddToWhiteList(String value) { Controller.getInstance().getAdBlockWhiteList().add(value); Controller.getInstance().saveAdBlockWhiteList(); fillData(); }