Add support for duck suggestions to preference manager
This commit is contained in:
parent
7cc5e584d5
commit
3e676920e1
@ -26,10 +26,13 @@ import acr.browser.lightning.R;
|
||||
import acr.browser.lightning.constant.Constants;
|
||||
import acr.browser.lightning.dialog.BrowserDialog;
|
||||
import acr.browser.lightning.download.DownloadHandler;
|
||||
import acr.browser.lightning.preference.PreferenceManager;
|
||||
import acr.browser.lightning.utils.ProxyUtils;
|
||||
import acr.browser.lightning.utils.ThemeUtils;
|
||||
import acr.browser.lightning.utils.Utils;
|
||||
|
||||
import static acr.browser.lightning.preference.PreferenceManager.*;
|
||||
|
||||
public class GeneralSettingsFragment extends LightningPreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String SETTINGS_PROXY = "proxy";
|
||||
@ -42,11 +45,11 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
private static final String SETTINGS_DOWNLOAD = "download";
|
||||
private static final String SETTINGS_HOME = "home";
|
||||
private static final String SETTINGS_SEARCHENGINE = "search";
|
||||
private static final String SETTINGS_GOOGLESUGGESTIONS = "google_suggestions";
|
||||
private static final String SETTINGS_SUGGESTIONS = "suggestions_choice";
|
||||
private Activity mActivity;
|
||||
private static final int API = android.os.Build.VERSION.SDK_INT;
|
||||
private CharSequence[] mProxyChoices;
|
||||
private Preference proxy, useragent, downloadloc, home, searchengine;
|
||||
private Preference proxy, useragent, downloadloc, home, searchengine, searchsSuggestions;
|
||||
private String mDownloadLocation;
|
||||
private int mAgentChoice;
|
||||
private String mHomepage;
|
||||
@ -68,25 +71,25 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
downloadloc = findPreference(SETTINGS_DOWNLOAD);
|
||||
home = findPreference(SETTINGS_HOME);
|
||||
searchengine = findPreference(SETTINGS_SEARCHENGINE);
|
||||
searchsSuggestions = findPreference(SETTINGS_SUGGESTIONS);
|
||||
|
||||
CheckBoxPreference cbFlash = (CheckBoxPreference) findPreference(SETTINGS_FLASH);
|
||||
CheckBoxPreference cbAds = (CheckBoxPreference) findPreference(SETTINGS_ADS);
|
||||
CheckBoxPreference cbImages = (CheckBoxPreference) findPreference(SETTINGS_IMAGES);
|
||||
CheckBoxPreference cbJsScript = (CheckBoxPreference) findPreference(SETTINGS_JAVASCRIPT);
|
||||
CheckBoxPreference cbColorMode = (CheckBoxPreference) findPreference(SETTINGS_COLORMODE);
|
||||
CheckBoxPreference cbgooglesuggest = (CheckBoxPreference) findPreference(SETTINGS_GOOGLESUGGESTIONS);
|
||||
|
||||
proxy.setOnPreferenceClickListener(this);
|
||||
useragent.setOnPreferenceClickListener(this);
|
||||
downloadloc.setOnPreferenceClickListener(this);
|
||||
home.setOnPreferenceClickListener(this);
|
||||
searchsSuggestions.setOnPreferenceClickListener(this);
|
||||
searchengine.setOnPreferenceClickListener(this);
|
||||
cbFlash.setOnPreferenceChangeListener(this);
|
||||
cbAds.setOnPreferenceChangeListener(this);
|
||||
cbImages.setOnPreferenceChangeListener(this);
|
||||
cbJsScript.setOnPreferenceChangeListener(this);
|
||||
cbColorMode.setOnPreferenceChangeListener(this);
|
||||
cbgooglesuggest.setOnPreferenceChangeListener(this);
|
||||
|
||||
mAgentChoice = mPreferenceManager.getUserAgentChoice();
|
||||
mHomepage = mPreferenceManager.getHomepage();
|
||||
@ -108,6 +111,19 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
|
||||
downloadloc.setSummary(mDownloadLocation);
|
||||
|
||||
switch (mPreferenceManager.getSearchSuggestionChoice()) {
|
||||
case SUGGESTION_GOOGLE:
|
||||
searchsSuggestions.setSummary(R.string.powered_by_google);
|
||||
break;
|
||||
case SUGGESTION_DUCK:
|
||||
searchsSuggestions.setSummary(R.string.powered_by_duck);
|
||||
break;
|
||||
case SUGGESTION_NONE:
|
||||
searchsSuggestions.setSummary(R.string.search_suggestions_off);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (mHomepage.contains("about:home")) {
|
||||
home.setSummary(getResources().getString(R.string.action_homepage));
|
||||
} else if (mHomepage.contains("about:blank")) {
|
||||
@ -144,7 +160,6 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
cbFlash.setChecked(flashNum > 0);
|
||||
cbAds.setChecked(Constants.FULL_VERSION && mPreferenceManager.getAdBlockEnabled());
|
||||
cbColorMode.setChecked(mPreferenceManager.getColorModeEnabled());
|
||||
cbgooglesuggest.setChecked(mPreferenceManager.getGoogleSearchSuggestionsEnabled());
|
||||
}
|
||||
|
||||
private void searchUrlPicker() {
|
||||
@ -155,15 +170,15 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
getSearchUrl.setText(mSearchUrl);
|
||||
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();
|
||||
mPreferenceManager.setSearchUrl(text);
|
||||
searchengine.setSummary(getResources().getString(R.string.custom_url) + ": "
|
||||
+ text);
|
||||
}
|
||||
});
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String text = getSearchUrl.getText().toString();
|
||||
mPreferenceManager.setSearchUrl(text);
|
||||
searchengine.setSummary(getResources().getString(R.string.custom_url) + ": "
|
||||
+ text);
|
||||
}
|
||||
});
|
||||
Dialog dialog = urlPicker.show();
|
||||
BrowserDialog.setDialogSize(mActivity, dialog);
|
||||
}
|
||||
@ -172,22 +187,22 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
||||
builder.setTitle(mActivity.getResources().getString(R.string.title_flash));
|
||||
builder.setMessage(getResources().getString(R.string.flash))
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(getResources().getString(R.string.action_manual),
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
mPreferenceManager.setFlashSupport(1);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(getResources().getString(R.string.action_auto),
|
||||
new DialogInterface.OnClickListener() {
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(getResources().getString(R.string.action_manual),
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
mPreferenceManager.setFlashSupport(1);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(getResources().getString(R.string.action_auto),
|
||||
new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mPreferenceManager.setFlashSupport(2);
|
||||
}
|
||||
}).setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mPreferenceManager.setFlashSupport(2);
|
||||
}
|
||||
}).setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
@ -204,13 +219,13 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
|
||||
picker.setTitle(getResources().getString(R.string.http_proxy));
|
||||
picker.setSingleChoiceItems(mProxyChoices, mPreferenceManager.getProxyChoice(),
|
||||
new DialogInterface.OnClickListener() {
|
||||
new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
setProxyChoice(which);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
setProxyChoice(which);
|
||||
}
|
||||
});
|
||||
picker.setPositiveButton(getResources().getString(R.string.action_ok), null);
|
||||
Dialog dialog = picker.show();
|
||||
BrowserDialog.setDialogSize(mActivity, dialog);
|
||||
@ -251,25 +266,25 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
eProxyPort.setText(Integer.toString(mPreferenceManager.getProxyPort()));
|
||||
|
||||
Dialog dialog = new AlertDialog.Builder(mActivity)
|
||||
.setTitle(R.string.manual_proxy)
|
||||
.setView(v)
|
||||
.setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
String proxyHost = eProxyHost.getText().toString();
|
||||
int proxyPort;
|
||||
try {
|
||||
// Try/Catch in case the user types an empty string or a number
|
||||
// larger than max integer
|
||||
proxyPort = Integer.parseInt(eProxyPort.getText().toString());
|
||||
} catch (NumberFormatException ignored) {
|
||||
proxyPort = mPreferenceManager.getProxyPort();
|
||||
}
|
||||
mPreferenceManager.setProxyHost(proxyHost);
|
||||
mPreferenceManager.setProxyPort(proxyPort);
|
||||
proxy.setSummary(proxyHost + ':' + proxyPort);
|
||||
.setTitle(R.string.manual_proxy)
|
||||
.setView(v)
|
||||
.setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
String proxyHost = eProxyHost.getText().toString();
|
||||
int proxyPort;
|
||||
try {
|
||||
// Try/Catch in case the user types an empty string or a number
|
||||
// larger than max integer
|
||||
proxyPort = Integer.parseInt(eProxyPort.getText().toString());
|
||||
} catch (NumberFormatException ignored) {
|
||||
proxyPort = mPreferenceManager.getProxyPort();
|
||||
}
|
||||
}).show();
|
||||
mPreferenceManager.setProxyHost(proxyHost);
|
||||
mPreferenceManager.setProxyPort(proxyPort);
|
||||
proxy.setSummary(proxyHost + ':' + proxyPort);
|
||||
}
|
||||
}).show();
|
||||
BrowserDialog.setDialogSize(mActivity, dialog);
|
||||
}
|
||||
|
||||
@ -277,9 +292,9 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
|
||||
picker.setTitle(getResources().getString(R.string.title_search_engine));
|
||||
CharSequence[] chars = {getResources().getString(R.string.custom_url), "Google",
|
||||
"Ask", "Bing", "Yahoo", "StartPage", "StartPage (Mobile)",
|
||||
"DuckDuckGo (Privacy)", "DuckDuckGo Lite (Privacy)", "Baidu (Chinese)",
|
||||
"Yandex (Russian)"};
|
||||
"Ask", "Bing", "Yahoo", "StartPage", "StartPage (Mobile)",
|
||||
"DuckDuckGo (Privacy)", "DuckDuckGo Lite (Privacy)", "Baidu (Chinese)",
|
||||
"Yandex (Russian)"};
|
||||
|
||||
int n = mPreferenceManager.getSearchChoice();
|
||||
|
||||
@ -312,28 +327,71 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
}
|
||||
|
||||
picker.setSingleChoiceItems(R.array.homepage, n - 1,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which + 1) {
|
||||
case 1:
|
||||
mPreferenceManager.setHomepage("about:home");
|
||||
home.setSummary(getResources().getString(R.string.action_homepage));
|
||||
break;
|
||||
case 2:
|
||||
mPreferenceManager.setHomepage("about:blank");
|
||||
home.setSummary(getResources().getString(R.string.action_blank));
|
||||
break;
|
||||
case 3:
|
||||
mPreferenceManager.setHomepage("about:bookmarks");
|
||||
home.setSummary(getResources().getString(R.string.action_bookmarks));
|
||||
break;
|
||||
case 4:
|
||||
homePicker();
|
||||
break;
|
||||
}
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which + 1) {
|
||||
case 1:
|
||||
mPreferenceManager.setHomepage("about:home");
|
||||
home.setSummary(getResources().getString(R.string.action_homepage));
|
||||
break;
|
||||
case 2:
|
||||
mPreferenceManager.setHomepage("about:blank");
|
||||
home.setSummary(getResources().getString(R.string.action_blank));
|
||||
break;
|
||||
case 3:
|
||||
mPreferenceManager.setHomepage("about:bookmarks");
|
||||
home.setSummary(getResources().getString(R.string.action_bookmarks));
|
||||
break;
|
||||
case 4:
|
||||
homePicker();
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
picker.setPositiveButton(getResources().getString(R.string.action_ok), null);
|
||||
Dialog dialog = picker.show();
|
||||
BrowserDialog.setDialogSize(mActivity, dialog);
|
||||
}
|
||||
|
||||
private void suggestionsDialog() {
|
||||
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
|
||||
picker.setTitle(getResources().getString(R.string.search_suggestions));
|
||||
|
||||
int currentChoice = 2;
|
||||
|
||||
switch (mPreferenceManager.getSearchSuggestionChoice()) {
|
||||
case SUGGESTION_GOOGLE:
|
||||
currentChoice = 0;
|
||||
break;
|
||||
case SUGGESTION_DUCK:
|
||||
currentChoice = 1;
|
||||
break;
|
||||
case SUGGESTION_NONE:
|
||||
currentChoice = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
picker.setSingleChoiceItems(R.array.suggestions, currentChoice,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case 0:
|
||||
mPreferenceManager.setSearchSuggestionChoice(Suggestion.SUGGESTION_GOOGLE);
|
||||
searchsSuggestions.setSummary(R.string.powered_by_google);
|
||||
break;
|
||||
case 1:
|
||||
mPreferenceManager.setSearchSuggestionChoice(Suggestion.SUGGESTION_DUCK);
|
||||
searchsSuggestions.setSummary(R.string.powered_by_duck);
|
||||
break;
|
||||
case 2:
|
||||
mPreferenceManager.setSearchSuggestionChoice(Suggestion.SUGGESTION_NONE);
|
||||
searchsSuggestions.setSummary(R.string.search_suggestions_off);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
picker.setPositiveButton(getResources().getString(R.string.action_ok), null);
|
||||
Dialog dialog = picker.show();
|
||||
BrowserDialog.setDialogSize(mActivity, dialog);
|
||||
@ -352,14 +410,14 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
}
|
||||
homePicker.setView(getHome);
|
||||
homePicker.setPositiveButton(getResources().getString(R.string.action_ok),
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String text = getHome.getText().toString();
|
||||
mPreferenceManager.setHomepage(text);
|
||||
home.setSummary(text);
|
||||
}
|
||||
});
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String text = getHome.getText().toString();
|
||||
mPreferenceManager.setHomepage(text);
|
||||
home.setSummary(text);
|
||||
}
|
||||
});
|
||||
Dialog dialog = homePicker.show();
|
||||
BrowserDialog.setDialogSize(mActivity, dialog);
|
||||
}
|
||||
@ -376,20 +434,20 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
}
|
||||
|
||||
picker.setSingleChoiceItems(R.array.download_folder, n,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case 0:
|
||||
mPreferenceManager.setDownloadDirectory(DownloadHandler.DEFAULT_DOWNLOAD_PATH);
|
||||
downloadloc.setSummary(DownloadHandler.DEFAULT_DOWNLOAD_PATH);
|
||||
break;
|
||||
case 1:
|
||||
downPicker();
|
||||
break;
|
||||
}
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case 0:
|
||||
mPreferenceManager.setDownloadDirectory(DownloadHandler.DEFAULT_DOWNLOAD_PATH);
|
||||
downloadloc.setSummary(DownloadHandler.DEFAULT_DOWNLOAD_PATH);
|
||||
break;
|
||||
case 1:
|
||||
downPicker();
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
picker.setPositiveButton(getResources().getString(R.string.action_ok), null);
|
||||
Dialog dialog = picker.show();
|
||||
BrowserDialog.setDialogSize(mActivity, dialog);
|
||||
@ -400,27 +458,27 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
agentPicker.setTitle(getResources().getString(R.string.title_user_agent));
|
||||
mAgentChoice = mPreferenceManager.getUserAgentChoice();
|
||||
agentPicker.setSingleChoiceItems(R.array.user_agent, mAgentChoice - 1,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mPreferenceManager.setUserAgentChoice(which + 1);
|
||||
switch (which + 1) {
|
||||
case 1:
|
||||
useragent.setSummary(getResources().getString(R.string.agent_default));
|
||||
break;
|
||||
case 2:
|
||||
useragent.setSummary(getResources().getString(R.string.agent_desktop));
|
||||
break;
|
||||
case 3:
|
||||
useragent.setSummary(getResources().getString(R.string.agent_mobile));
|
||||
break;
|
||||
case 4:
|
||||
useragent.setSummary(getResources().getString(R.string.agent_custom));
|
||||
agentPicker();
|
||||
break;
|
||||
}
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mPreferenceManager.setUserAgentChoice(which + 1);
|
||||
switch (which + 1) {
|
||||
case 1:
|
||||
useragent.setSummary(getResources().getString(R.string.agent_default));
|
||||
break;
|
||||
case 2:
|
||||
useragent.setSummary(getResources().getString(R.string.agent_desktop));
|
||||
break;
|
||||
case 3:
|
||||
useragent.setSummary(getResources().getString(R.string.agent_mobile));
|
||||
break;
|
||||
case 4:
|
||||
useragent.setSummary(getResources().getString(R.string.agent_custom));
|
||||
agentPicker();
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
agentPicker.setPositiveButton(getResources().getString(R.string.action_ok), null);
|
||||
Dialog dialog = agentPicker.show();
|
||||
BrowserDialog.setDialogSize(mActivity, dialog);
|
||||
@ -432,14 +490,14 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
final EditText getAgent = new EditText(mActivity);
|
||||
agentStringPicker.setView(getAgent);
|
||||
agentStringPicker.setPositiveButton(getResources().getString(R.string.action_ok),
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String text = getAgent.getText().toString();
|
||||
mPreferenceManager.setUserAgentString(text);
|
||||
useragent.setSummary(getResources().getString(R.string.agent_custom));
|
||||
}
|
||||
});
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String text = getAgent.getText().toString();
|
||||
mPreferenceManager.setUserAgentString(text);
|
||||
useragent.setSummary(getResources().getString(R.string.agent_custom));
|
||||
}
|
||||
});
|
||||
Dialog dialog = agentStringPicker.show();
|
||||
BrowserDialog.setDialogSize(mActivity, dialog);
|
||||
}
|
||||
@ -450,7 +508,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
downLocationPicker.setTitle(getResources().getString(R.string.title_download_location));
|
||||
final EditText getDownload = new EditText(mActivity);
|
||||
getDownload.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
getDownload.setText(mPreferenceManager.getDownloadDirectory());
|
||||
final int errorColor = ContextCompat.getColor(getActivity(), R.color.error_red);
|
||||
final int regularColor = ThemeUtils.getTextColor(getActivity());
|
||||
@ -461,15 +519,15 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
layout.addView(getDownload);
|
||||
downLocationPicker.setView(layout);
|
||||
downLocationPicker.setPositiveButton(getResources().getString(R.string.action_ok),
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String text = getDownload.getText().toString();
|
||||
text = DownloadHandler.addNecessarySlashes(text);
|
||||
mPreferenceManager.setDownloadDirectory(text);
|
||||
downloadloc.setSummary(text);
|
||||
}
|
||||
});
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String text = getDownload.getText().toString();
|
||||
text = DownloadHandler.addNecessarySlashes(text);
|
||||
mPreferenceManager.setDownloadDirectory(text);
|
||||
downloadloc.setSummary(text);
|
||||
}
|
||||
});
|
||||
Dialog dialog = downLocationPicker.show();
|
||||
BrowserDialog.setDialogSize(mActivity, dialog);
|
||||
}
|
||||
@ -529,6 +587,9 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
case SETTINGS_SEARCHENGINE:
|
||||
searchDialog();
|
||||
return true;
|
||||
case SETTINGS_SUGGESTIONS:
|
||||
suggestionsDialog();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -566,9 +627,6 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
||||
case SETTINGS_COLORMODE:
|
||||
mPreferenceManager.setColorModeEnabled(checked);
|
||||
return true;
|
||||
case SETTINGS_GOOGLESUGGESTIONS:
|
||||
mPreferenceManager.setGoogleSearchSuggestionsEnabled(checked);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -2,9 +2,14 @@ package acr.browser.lightning.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@ -38,7 +43,6 @@ public class PreferenceManager {
|
||||
public static final String USE_WIDE_VIEWPORT = "wideviewport";
|
||||
public static final String USER_AGENT = "agentchoose";
|
||||
public static final String USER_AGENT_STRING = "userAgentString";
|
||||
public static final String GOOGLE_SEARCH_SUGGESTIONS = "GoogleSearchSuggestions";
|
||||
public static final String CLEAR_HISTORY_EXIT = "clearHistoryExit";
|
||||
public static final String CLEAR_COOKIES_EXIT = "clearCookiesExit";
|
||||
public static final String SAVE_URL = "saveUrl";
|
||||
@ -55,6 +59,7 @@ public class PreferenceManager {
|
||||
public static final String DO_NOT_TRACK = "doNotTrack";
|
||||
public static final String IDENTIFYING_HEADERS = "removeIdentifyingHeaders";
|
||||
public static final String SWAP_BOOKMARKS_AND_TABS = "swapBookmarksAndTabs";
|
||||
public static final String SEARCH_SUGGESTIONS = "searchSuggestions";
|
||||
|
||||
public static final String USE_PROXY = "useProxy";
|
||||
public static final String PROXY_CHOICE = "proxyChoice";
|
||||
@ -66,6 +71,12 @@ public class PreferenceManager {
|
||||
public static final String LEAK_CANARY = "leakCanary";
|
||||
}
|
||||
|
||||
public enum Suggestion {
|
||||
SUGGESTION_GOOGLE,
|
||||
SUGGESTION_DUCK,
|
||||
SUGGESTION_NONE
|
||||
}
|
||||
|
||||
@NonNull private final SharedPreferences mPrefs;
|
||||
|
||||
private static final String PREFERENCES = "settings";
|
||||
@ -75,6 +86,19 @@ public class PreferenceManager {
|
||||
mPrefs = context.getSharedPreferences(PREFERENCES, 0);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Suggestion getSearchSuggestionChoice() {
|
||||
try {
|
||||
return Suggestion.valueOf(mPrefs.getString(Name.SEARCH_SUGGESTIONS, Suggestion.SUGGESTION_GOOGLE.name()));
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
return Suggestion.SUGGESTION_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
public void setSearchSuggestionChoice(@NonNull Suggestion suggestion) {
|
||||
putString(Name.SEARCH_SUGGESTIONS, suggestion.name());
|
||||
}
|
||||
|
||||
public boolean getBookmarksAndTabsSwapped() {
|
||||
return mPrefs.getBoolean(Name.SWAP_BOOKMARKS_AND_TABS, false);
|
||||
}
|
||||
@ -140,10 +164,6 @@ public class PreferenceManager {
|
||||
return mPrefs.getBoolean(Name.FULL_SCREEN, false);
|
||||
}
|
||||
|
||||
public boolean getGoogleSearchSuggestionsEnabled() {
|
||||
return mPrefs.getBoolean(Name.GOOGLE_SEARCH_SUGGESTIONS, true);
|
||||
}
|
||||
|
||||
public boolean getHideStatusBarEnabled() {
|
||||
return mPrefs.getBoolean(Name.HIDE_STATUS_BAR, false);
|
||||
}
|
||||
@ -354,10 +374,6 @@ public class PreferenceManager {
|
||||
putBoolean(Name.FULL_SCREEN, enable);
|
||||
}
|
||||
|
||||
public void setGoogleSearchSuggestionsEnabled(boolean enabled) {
|
||||
putBoolean(Name.GOOGLE_SEARCH_SUGGESTIONS, enabled);
|
||||
}
|
||||
|
||||
public void setHideStatusBarEnabled(boolean enable) {
|
||||
putBoolean(Name.HIDE_STATUS_BAR, enable);
|
||||
}
|
||||
|
@ -83,6 +83,11 @@ public final class DuckSuggestionsTask {
|
||||
return sLanguage;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static String getQueryUrl(@NonNull String query) {
|
||||
return "https://duckduckgo.com/ac/?q=" + query;
|
||||
}
|
||||
|
||||
void run() {
|
||||
List<HistoryItem> filter = new ArrayList<>(5);
|
||||
try {
|
||||
@ -135,7 +140,8 @@ public final class DuckSuggestionsTask {
|
||||
*/
|
||||
@NonNull
|
||||
private static File downloadSuggestionsForQuery(@NonNull String query, String language, @NonNull Application app) {
|
||||
File cacheFile = new File(app.getCacheDir(), query.hashCode() + Suggestions.CACHE_FILE_TYPE);
|
||||
String queryUrl = getQueryUrl(query);
|
||||
File cacheFile = new File(app.getCacheDir(), queryUrl.hashCode() + Suggestions.CACHE_FILE_TYPE);
|
||||
if (System.currentTimeMillis() - INTERVAL_DAY < cacheFile.lastModified()) {
|
||||
return cacheFile;
|
||||
}
|
||||
@ -145,7 +151,7 @@ public final class DuckSuggestionsTask {
|
||||
InputStream in = null;
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
URL url = new URL("https://duckduckgo.com/ac/?q=" + query);
|
||||
URL url = new URL(queryUrl);
|
||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||
connection.setDoInput(true);
|
||||
connection.setRequestProperty("Accept-Encoding", "gzip");
|
||||
|
@ -70,6 +70,12 @@ public class GoogleSuggestionsTask {
|
||||
return sLanguage;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static String getQueryUrl(@NonNull String query, @NonNull String language) {
|
||||
return "https://suggestqueries.google.com/complete/search?output=toolbar&hl="
|
||||
+ language + "&q=" + query;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static synchronized XmlPullParser getParser() throws XmlPullParserException {
|
||||
if (sXpp == null) {
|
||||
@ -135,7 +141,8 @@ public class GoogleSuggestionsTask {
|
||||
*/
|
||||
@NonNull
|
||||
private static File downloadSuggestionsForQuery(@NonNull String query, String language, @NonNull Application app) {
|
||||
File cacheFile = new File(app.getCacheDir(), query.hashCode() + Suggestions.CACHE_FILE_TYPE);
|
||||
String queryUrl = getQueryUrl(query, language);
|
||||
File cacheFile = new File(app.getCacheDir(), queryUrl.hashCode() + Suggestions.CACHE_FILE_TYPE);
|
||||
if (System.currentTimeMillis() - INTERVAL_DAY < cacheFile.lastModified()) {
|
||||
return cacheFile;
|
||||
}
|
||||
@ -147,8 +154,7 @@ public class GoogleSuggestionsTask {
|
||||
try {
|
||||
// Old API that doesn't support HTTPS
|
||||
// http://google.com/complete/search?q= + query + &output=toolbar&hl= + language
|
||||
URL url = new URL("https://suggestqueries.google.com/complete/search?output=toolbar&hl="
|
||||
+ language + "&q=" + query);
|
||||
URL url = new URL(queryUrl);
|
||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||
connection.setDoInput(true);
|
||||
connection.setRequestProperty("Accept-Encoding", "gzip");
|
||||
|
@ -70,9 +70,9 @@ public class Suggestions extends BaseAdapter implements Filterable {
|
||||
private final List<HistoryItem> mAllBookmarks = new ArrayList<>(5);
|
||||
|
||||
private final boolean mDarkTheme;
|
||||
private boolean mUseGoogle = true;
|
||||
private boolean mIsIncognito = true;
|
||||
@NonNull private final Context mContext;
|
||||
PreferenceManager.Suggestion mSuggestionChoice;
|
||||
|
||||
public Suggestions(@NonNull Context context, boolean dark, boolean incognito) {
|
||||
super();
|
||||
@ -81,7 +81,7 @@ public class Suggestions extends BaseAdapter implements Filterable {
|
||||
mDarkTheme = dark || incognito;
|
||||
mIsIncognito = incognito;
|
||||
|
||||
mUseGoogle = mPreferenceManager.getGoogleSearchSuggestionsEnabled();
|
||||
refreshPreferences();
|
||||
|
||||
refreshBookmarks();
|
||||
|
||||
@ -91,7 +91,7 @@ public class Suggestions extends BaseAdapter implements Filterable {
|
||||
}
|
||||
|
||||
public void refreshPreferences() {
|
||||
mUseGoogle = mPreferenceManager.getGoogleSearchSuggestionsEnabled();
|
||||
mSuggestionChoice = mPreferenceManager.getSearchSuggestionChoice();
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
@ -286,7 +286,19 @@ public class Suggestions extends BaseAdapter implements Filterable {
|
||||
|
||||
@NonNull
|
||||
private Observable<List<HistoryItem>> getSuggestionsForQuery(@NonNull final String query) {
|
||||
return SuggestionsManager.getObservable(query, mContext, SuggestionsManager.Source.GOOGLE);
|
||||
if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_GOOGLE) {
|
||||
return SuggestionsManager.getObservable(query, mContext, SuggestionsManager.Source.GOOGLE);
|
||||
} else if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_DUCK) {
|
||||
return SuggestionsManager.getObservable(query, mContext, SuggestionsManager.Source.DUCK);
|
||||
} else {
|
||||
return Observable.create(new Action<List<HistoryItem>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Subscriber<List<HistoryItem>> subscriber) {
|
||||
//TODO add an Observable.empty() method to generate an empty Observable
|
||||
subscriber.onComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@ -302,7 +314,7 @@ public class Suggestions extends BaseAdapter implements Filterable {
|
||||
}
|
||||
|
||||
private boolean shouldRequestNetwork() {
|
||||
return mUseGoogle && !mIsIncognito;
|
||||
return !mIsIncognito && mSuggestionChoice != PreferenceManager.Suggestion.SUGGESTION_NONE;
|
||||
}
|
||||
|
||||
private static class SearchFilter extends Filter {
|
||||
|
@ -132,7 +132,7 @@
|
||||
<string name="title_sign_in">Anmelden</string>
|
||||
<string name="hint_username">Benutzername</string>
|
||||
<string name="hint_password">Passwort</string>
|
||||
<string name="google_suggestions">Suchvorschläge</string>
|
||||
<string name="search_suggestions">Suchvorschläge</string>
|
||||
<string name="powered_by_google">Unterstützt durch Google</string>
|
||||
<string name="use_tor_prompt">Orbot ist installiert. Soll Tor verwendet werden?</string>
|
||||
<string name="install_orbot">Um Tor verwenden zu können, muss Orbot installiert sein!</string>
|
||||
|
@ -115,7 +115,7 @@
|
||||
<string name="title_sign_in">Iniciar sesión</string>
|
||||
<string name="hint_username">Usuario</string>
|
||||
<string name="hint_password">Contraseña</string>
|
||||
<string name="google_suggestions">Sugerencias de búsqueda</string>
|
||||
<string name="search_suggestions">Sugerencias de búsqueda</string>
|
||||
<string name="powered_by_google">Proporcionadas por Google</string>
|
||||
<string name="use_tor_prompt">Parece que tienes Orbot instalado. ¿Quieres usar Tor?</string>
|
||||
<string name="install_orbot">Por favor, instala Orbot para usar Tor.</string>
|
||||
|
@ -142,7 +142,7 @@
|
||||
<string name="title_sign_in">Connexion</string>
|
||||
<string name="hint_username">Nom d\'utilisateur</string>
|
||||
<string name="hint_password">Mot de passe</string>
|
||||
<string name="google_suggestions">Suggestions de recherche</string>
|
||||
<string name="search_suggestions">Suggestions de recherche</string>
|
||||
<string name="powered_by_google">Proposé par Google</string>
|
||||
<string name="http_proxy">Proxy HTTP</string>
|
||||
<string-array name="proxy_choices_array">
|
||||
|
@ -116,7 +116,7 @@
|
||||
<string name="title_sign_in">Εγγραφή</string>
|
||||
<string name="hint_username">Όνομα χρήστη</string>
|
||||
<string name="hint_password">Κώδικός</string>
|
||||
<string name="google_suggestions">Προτάσεις αναζήτησης</string>
|
||||
<string name="search_suggestions">Προτάσεις αναζήτησης</string>
|
||||
<string name="powered_by_google">Powered by Google</string>
|
||||
<string name="use_tor_prompt">Φαίνεται οτι έχετε εγκατεστημένο το Orbot. Θα θέλατε να χρησιμοποιήσετε το Tor?</string>
|
||||
<string name="install_orbot">Παρακαλώ εγκαταστήστε το Orbot για να χρησιμοποιήσετε το Tor.</string>
|
||||
|
@ -132,7 +132,7 @@
|
||||
<string name="title_sign_in">Bejelentkezés</string>
|
||||
<string name="hint_username">Felhasználónév</string>
|
||||
<string name="hint_password">Jelszó</string>
|
||||
<string name="google_suggestions">Keresési javaslatok</string>
|
||||
<string name="search_suggestions">Keresési javaslatok</string>
|
||||
<string name="powered_by_google">A Google támogatásával</string>
|
||||
<string name="use_tor_prompt">Úgy tűnik, hogy önnek telepítve van az Orbot.Szeretné használni Tor-t?</string>
|
||||
<string name="install_orbot">Kérjük telepítse az Orbot-ot annak érdekében, hogy működjön a proxy a Tor-ral.</string>
|
||||
|
@ -132,7 +132,7 @@
|
||||
<string name="title_sign_in">Registrati</string>
|
||||
<string name="hint_username">Username</string>
|
||||
<string name="hint_password">Password</string>
|
||||
<string name="google_suggestions">Suggerimenti di ricerca</string>
|
||||
<string name="search_suggestions">Suggerimenti di ricerca</string>
|
||||
<string name="powered_by_google">Powered by Google</string>
|
||||
<string name="http_proxy">HTTP Proxy</string>
|
||||
<string-array name="proxy_choices_array">
|
||||
|
@ -129,7 +129,7 @@
|
||||
<string name="title_sign_in">サインイン</string>
|
||||
<string name="hint_username">ユーザー名</string>
|
||||
<string name="hint_password">パスワード</string>
|
||||
<string name="google_suggestions">検索候補を表示する</string>
|
||||
<string name="search_suggestions">検索候補を表示する</string>
|
||||
<string name="powered_by_google">Powered by Google</string>
|
||||
<string name="use_tor_prompt">Orbotがインストールされています。Torを使用しますか?</string>
|
||||
<string name="install_orbot">Torでプロキシを有効にするにはOrbotをインストールしてください</string>
|
||||
|
@ -115,7 +115,7 @@
|
||||
<string name="title_sign_in">로그인</string>
|
||||
<string name="hint_username">사용자 이름</string>
|
||||
<string name="hint_password">암호</string>
|
||||
<string name="google_suggestions">검색 제안</string>
|
||||
<string name="search_suggestions">검색 제안</string>
|
||||
<string name="powered_by_google">Google이 제공함</string>
|
||||
<string name="use_tor_prompt">Orbot이 설치되어 있습니다. Tor를 사용할까요?</string>
|
||||
<string name="install_orbot">Tor를 사용하려면 Orbot을 설치하세요.</string>
|
||||
|
@ -125,7 +125,7 @@
|
||||
<string name="title_sign_in">Zaloguj się</string>
|
||||
<string name="hint_username">Nazwa użytkownika</string>
|
||||
<string name="hint_password">Hasło</string>
|
||||
<string name="google_suggestions">Podpowiedzi wyszukiwania</string>
|
||||
<string name="search_suggestions">Podpowiedzi wyszukiwania</string>
|
||||
<string name="powered_by_google">Dostarczane przez Google</string>
|
||||
<string name="http_proxy">Konfiguracja serwera proxy</string>
|
||||
<string-array name="proxy_choices_array">
|
||||
|
@ -131,7 +131,7 @@
|
||||
<string name="title_sign_in">Iniciar sessão</string>
|
||||
<string name="hint_username">Utilizador</string>
|
||||
<string name="hint_password">Palavra-passe</string>
|
||||
<string name="google_suggestions">Sugestões de pesquisa</string>
|
||||
<string name="search_suggestions">Sugestões de pesquisa</string>
|
||||
<string name="powered_by_google">Disponibilizado por Google</string>
|
||||
<string name="http_proxy">Proxy HTTP</string>
|
||||
<string-array name="proxy_choices_array">
|
||||
|
@ -115,7 +115,7 @@
|
||||
<string name="title_sign_in">Вход</string>
|
||||
<string name="hint_username">Имя пользователя</string>
|
||||
<string name="hint_password">Пароль</string>
|
||||
<string name="google_suggestions">Подсказки поиска</string>
|
||||
<string name="search_suggestions">Подсказки поиска</string>
|
||||
<string name="powered_by_google">Используя Google</string>
|
||||
<string name="use_tor_prompt">Похоже, установлен Orbot. Вы хотите использовать Tor?</string>
|
||||
<string name="install_orbot">Пожалуйста, установите Orbot для проксирования через Tor.</string>
|
||||
|
@ -142,7 +142,7 @@
|
||||
<string name="title_sign_in">Пријава</string>
|
||||
<string name="hint_username">Корисничко име</string>
|
||||
<string name="hint_password">Лозинка</string>
|
||||
<string name="google_suggestions">Предлози претраге</string>
|
||||
<string name="search_suggestions">Предлози претраге</string>
|
||||
<string name="powered_by_google">Погоњено Гуглом</string>
|
||||
<string name="http_proxy">ХТТП прокси</string>
|
||||
<string-array name="proxy_choices_array">
|
||||
|
@ -116,7 +116,7 @@
|
||||
<string name="title_sign_in">Giriş Yap</string>
|
||||
<string name="hint_username">Kullanıcı adı</string>
|
||||
<string name="hint_password">Parola</string>
|
||||
<string name="google_suggestions">Önerilenleri ara</string>
|
||||
<string name="search_suggestions">Önerilenleri ara</string>
|
||||
<string name="powered_by_google">Powered by Google</string>
|
||||
<string name="use_tor_prompt">Cihazında Orbot yüklü görünüyor. Tor kullanmak ister misin?</string>
|
||||
<string name="install_orbot">Tor proxy ağı ile gezinmek için Orbot yüklemelisin.</string>
|
||||
|
@ -116,7 +116,7 @@
|
||||
<string name="title_sign_in">登录</string>
|
||||
<string name="hint_username">用户名</string>
|
||||
<string name="hint_password">密码</string>
|
||||
<string name="google_suggestions">搜索建议</string>
|
||||
<string name="search_suggestions">搜索建议</string>
|
||||
<string name="powered_by_google">由 Google 提供支持</string>
|
||||
<string name="use_tor_prompt">看起来你已经安装了 Orbot. 你想要使用 Tor 吗?</string>
|
||||
<string name="install_orbot">请安装 Orbot 以便通过 Tor 全使用代理。</string>
|
||||
|
@ -18,6 +18,12 @@
|
||||
<item>@string/action_bookmarks</item>
|
||||
<item>@string/action_webpage</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="suggestions">
|
||||
<item>@string/powered_by_google</item>
|
||||
<item>@string/powered_by_duck</item>
|
||||
<item>@string/search_suggestions_off</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="text_size">
|
||||
<item>@string/size_largest</item>
|
||||
|
@ -144,8 +144,10 @@
|
||||
<string name="title_sign_in">Sign In</string>
|
||||
<string name="hint_username">Username</string>
|
||||
<string name="hint_password">Password</string>
|
||||
<string name="google_suggestions">Search Suggestions</string>
|
||||
<string name="search_suggestions">Search Suggestions</string>
|
||||
<string name="powered_by_google">Powered by Google</string>
|
||||
<string name="powered_by_duck">Powered by DuckDuckGo</string>
|
||||
<string name="search_suggestions_off">No search suggestions</string>
|
||||
<string name="http_proxy">HTTP Proxy</string>
|
||||
<string-array name="proxy_choices_array">
|
||||
<item>None</item>
|
||||
|
@ -37,10 +37,8 @@
|
||||
<Preference
|
||||
android:key="search"
|
||||
android:title="@string/search" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="google_suggestions"
|
||||
android:title="@string/google_suggestions"
|
||||
android:summary="@string/powered_by_google" />
|
||||
<Preference
|
||||
android:key="suggestions_choice"
|
||||
android:title="@string/search_suggestions" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user