From 45b598b4a03a2955204d7a3942946c5a63eb8be9 Mon Sep 17 00:00:00 2001 From: fnord Date: Thu, 6 Mar 2014 23:28:54 -0600 Subject: [PATCH] New "Custom URL" option for search engine. Allow stuff like 'http://yubnub.org/parser/parse?command=' or 'http://mypersonalserver.net/woot.cgi?whatever=' * Pops up txt dialog when selected, initial default same as builtin google url * Default remains '1' (builtin google url) --- res/values/strings.xml | 1 + .../barebones/activities/BrowserActivity.java | 6 +++ .../activities/IncognitoModeActivity.java | 7 +++ .../activities/SettingsActivity.java | 43 +++++++++++++++++-- 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index aef7080..abe5155 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -67,6 +67,7 @@ (Websites may look weird) Search Engine Search + Custom URL Use wide viewport Load pages in overview mode Restore lost tabs on start diff --git a/src/acr/browser/barebones/activities/BrowserActivity.java b/src/acr/browser/barebones/activities/BrowserActivity.java index 312c561..b83ef68 100644 --- a/src/acr/browser/barebones/activities/BrowserActivity.java +++ b/src/acr/browser/barebones/activities/BrowserActivity.java @@ -1563,6 +1563,12 @@ public class BrowserActivity extends Activity implements OnTouchListener { defaultUser = user; // setting mobile user // agent switch (settings.getInt("search", 1)) { + case 0: + mSearch = settings.getString("searchurl", FinalVariables.GOOGLE_SEARCH); + if(!mSearch.startsWith("http://") && ! mSearch.startsWith("https://") ) { + mSearch = FinalVariables.GOOGLE_SEARCH; + } + break; case 1: mSearch = FinalVariables.GOOGLE_SEARCH; break; diff --git a/src/acr/browser/barebones/activities/IncognitoModeActivity.java b/src/acr/browser/barebones/activities/IncognitoModeActivity.java index 7b2fa71..34e8585 100644 --- a/src/acr/browser/barebones/activities/IncognitoModeActivity.java +++ b/src/acr/browser/barebones/activities/IncognitoModeActivity.java @@ -1536,6 +1536,13 @@ public class IncognitoModeActivity extends Activity implements OnTouchListener { defaultUser = user; // setting mobile user // agent switch (settings.getInt("search", 1)) { + case 0: + SEARCH = settings.getString("searchurl", FinalVariables.GOOGLE_SEARCH); + if(!SEARCH.startsWith("http://") && ! SEARCH.startsWith("https://") ) { + SEARCH = FinalVariables.GOOGLE_SEARCH; + } + break; + case 1: SEARCH = FinalVariables.GOOGLE_SEARCH; break; diff --git a/src/acr/browser/barebones/activities/SettingsActivity.java b/src/acr/browser/barebones/activities/SettingsActivity.java index 9a2c1d5..62a6092 100644 --- a/src/acr/browser/barebones/activities/SettingsActivity.java +++ b/src/acr/browser/barebones/activities/SettingsActivity.java @@ -38,6 +38,7 @@ public class SettingsActivity extends Activity { static SharedPreferences.Editor mEditPrefs; static int agentChoice; static String homepage; + static String searchurl; static TextView agentText; static String agent; static TextView download; @@ -74,6 +75,9 @@ public class SettingsActivity extends Activity { searchText = (TextView) findViewById(R.id.searchText); switch (settings.getInt("search", 1)) { + case 0: + searchText.setText("Custom URL"); + break; case 1: searchText.setText("Google"); break; @@ -226,20 +230,24 @@ public class SettingsActivity extends Activity { SettingsActivity.this); picker.setTitle(getResources().getString( R.string.title_search_engine)); - CharSequence[] chars = { "Google", "Bing", "Yahoo", + CharSequence[] chars = { getResources().getString(R.string.custom_url), + "Google", "Bing", "Yahoo", "StartPage", "DuckDuckGo (Privacy)" , "Baidu (Chinese)", "Yandex (Russian)", "DuckDuckGo Lite (Privacy)"}; int n = settings.getInt("search", 1); - picker.setSingleChoiceItems(chars, n - 1, + picker.setSingleChoiceItems(chars, n, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - mEditPrefs.putInt("search", which + 1); + mEditPrefs.putInt("search", which); mEditPrefs.commit(); - switch (which + 1) { + switch (which) { + case 0: + searchUrlPicker(); + break; case 1: searchText.setText("Google"); break; @@ -282,6 +290,33 @@ public class SettingsActivity extends Activity { }); } + public void searchUrlPicker() { + final AlertDialog.Builder urlPicker = new AlertDialog.Builder( + SettingsActivity.this); + + urlPicker.setTitle(getResources().getString( + R.string.custom_url)); + final EditText getSearchUrl = new EditText(SettingsActivity.this); + + searchurl = settings.getString("searchurl", FinalVariables.GOOGLE_SEARCH); + getSearchUrl.setText(searchurl); + urlPicker.setView(getSearchUrl); + urlPicker.setPositiveButton( + getResources().getString(R.string.action_ok), + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + String text = getSearchUrl.getText().toString(); + mEditPrefs.putString("searchurl", text); + mEditPrefs.commit(); + searchText.setText( getResources().getString(R.string.custom_url) + ": " + text); + } + }); + urlPicker.show(); + } + + public void clickListenerForCheckBoxes(RelativeLayout one, RelativeLayout two, RelativeLayout three, final CheckBox loc, final CheckBox full, final CheckBox flash) {