@ -26,10 +26,13 @@ import acr.browser.lightning.R;
@@ -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
@@ -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_GOOGLE SUGGESTIONS = "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
@@ -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
@@ -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
@@ -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 ( ) {
@ -339,6 +354,49 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
@@ -339,6 +354,49 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
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 ) ;
}
private void homePicker ( ) {
final AlertDialog . Builder homePicker = new AlertDialog . Builder ( mActivity ) ;
homePicker . setTitle ( getResources ( ) . getString ( R . string . title_custom_homepage ) ) ;
@ -529,6 +587,9 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
@@ -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
@@ -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 ;
}