mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-30 21:55:31 +00:00
Bug 1200367 - saved searches should have an opt-out pref in settings.r=liuche
This commit is contained in:
parent
e1f1409f3d
commit
98127aeb6e
@ -7,12 +7,14 @@ package org.mozilla.gecko.home;
|
||||
|
||||
import org.mozilla.gecko.AppConstants;
|
||||
import org.mozilla.gecko.db.BrowserContract.SearchHistory;
|
||||
import org.mozilla.gecko.GeckoSharedPrefs;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.Telemetry;
|
||||
import org.mozilla.gecko.TelemetryContract;
|
||||
import org.mozilla.gecko.home.BrowserSearch.OnEditSuggestionListener;
|
||||
import org.mozilla.gecko.home.BrowserSearch.OnSearchListener;
|
||||
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
|
||||
import org.mozilla.gecko.preferences.GeckoPreferences;
|
||||
import org.mozilla.gecko.util.StringUtils;
|
||||
import org.mozilla.gecko.util.HardwareUtils;
|
||||
import org.mozilla.gecko.widget.AnimatedHeightLayout;
|
||||
@ -22,6 +24,7 @@ import org.mozilla.gecko.widget.FlowLayout;
|
||||
import android.database.Cursor;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
@ -218,6 +221,14 @@ class SearchEngineRow extends AnimatedHeightLayout {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays search suggestions from previous searches.
|
||||
*
|
||||
* @param c The Cursor to iterate over for saved search suggestion to display
|
||||
* @param suggestionCounter global index of where to start adding suggestion "buttons" in the search engine row
|
||||
* @param animate whether or not to animate suggestions for visual polish
|
||||
* @param recycledSuggestionCount How many suggestion "button" views we could recycle from previous calls
|
||||
*/
|
||||
private void updateFromSavedSearches(Cursor c, boolean animate, int suggestionCounter, int recycledSuggestionCount) {
|
||||
if (c == null) {
|
||||
return;
|
||||
@ -241,7 +252,13 @@ class SearchEngineRow extends AnimatedHeightLayout {
|
||||
hideRecycledSuggestions(suggestionCounter, recycledSuggestionCount);
|
||||
}
|
||||
|
||||
private Cursor getSavedSearches(String searchTerm, boolean isTablet) {
|
||||
/**
|
||||
* Gets matching suggestions from search history.
|
||||
*
|
||||
* @param searchTerm the string with which to look for matches in the saved searches
|
||||
* @return matching prior searches that contain searchTerm
|
||||
*/
|
||||
private Cursor getSavedSearches(String searchTerm) {
|
||||
if (!AppConstants.NIGHTLY_BUILD) {
|
||||
return null;
|
||||
}
|
||||
@ -250,20 +267,28 @@ class SearchEngineRow extends AnimatedHeightLayout {
|
||||
String[] columns = new String[] { SearchHistory.QUERY };
|
||||
String actualQuery = SearchHistory.QUERY + " LIKE ?";
|
||||
String[] queryArgs = new String[] { '%' + searchTerm + '%' };
|
||||
final int limit = isTablet ? TABLET_MAX : PHONE_MAX;
|
||||
final int limit = HardwareUtils.isTablet() ? TABLET_MAX : PHONE_MAX;
|
||||
|
||||
String sortOrderAndLimit = SearchHistory.DATE +" DESC LIMIT "+limit;
|
||||
return cr.query(SearchHistory.CONTENT_URI, columns, actualQuery, queryArgs, sortOrderAndLimit);
|
||||
}
|
||||
|
||||
private int updateFromSearchEngine(boolean animate, int recycledSuggestionCount, boolean isTablet, int savedCount) {
|
||||
/**
|
||||
* Displays suggestions supplied by the search engine, relative to number of suggestions from search history.
|
||||
*
|
||||
* @param animate whether or not to animate suggestions for visual polish
|
||||
* @param recycledSuggestionCount How many suggestion "button" views we could recycle from previous calls
|
||||
* @param savedCount how many saved searches this searchTerm has
|
||||
* @return the global count of how many suggestions have been bound/shown in the search engine row
|
||||
*/
|
||||
private int updateFromSearchEngine(boolean animate, int recycledSuggestionCount, int savedCount) {
|
||||
|
||||
// Remove this default limit value in Bug 1201325
|
||||
int limit = TABLET_MAX;
|
||||
if (AppConstants.NIGHTLY_BUILD) {
|
||||
limit = isTablet ? TABLET_MAX : PHONE_MAX;
|
||||
limit = HardwareUtils.isTablet() ? TABLET_MAX : PHONE_MAX;
|
||||
// If there are less than max saved searches on phones, fill the space with more search engine suggestions
|
||||
if (!isTablet && savedCount < PHONE_MAX) {
|
||||
if (!HardwareUtils.isTablet() && savedCount < PHONE_MAX) {
|
||||
limit += PHONE_MAX - savedCount;
|
||||
}
|
||||
}
|
||||
@ -288,32 +313,58 @@ class SearchEngineRow extends AnimatedHeightLayout {
|
||||
return suggestionCounter;
|
||||
}
|
||||
|
||||
public void updateSuggestions(boolean suggestionsEnabled, SearchEngine searchEngine, String searchTerm, boolean animate) {
|
||||
// Update search engine reference. Even if the user has not seen the prompt, we need to set the engine for the mSearchTerm suggestion
|
||||
/**
|
||||
* Updates the whole suggestions UI, the search engine UI, suggestions from the default search engine,
|
||||
* and suggestions from search history.
|
||||
*
|
||||
* This can be called before the opt-in permission prompt is shown or set.
|
||||
* Even if both suggestion types are disabled, we need to update the search engine, its image, and the content description.
|
||||
*
|
||||
* @param searchSuggestionsEnabled whether or not suggestions from the default search engine are enabled
|
||||
* @param searchEngine the search engine to use throughout the SearchEngineRow class
|
||||
* @param searchTerm the text from the url to get suggestions on
|
||||
* @param animate whether or not to use animations
|
||||
**/
|
||||
public void updateSuggestions(boolean searchSuggestionsEnabled, SearchEngine searchEngine, String searchTerm, boolean animate) {
|
||||
mSearchEngine = searchEngine;
|
||||
// Set the search engine icon (e.g., Google) for the row.
|
||||
mIconView.updateAndScaleImage(mSearchEngine.getIcon(), mSearchEngine.getEngineIdentifier());
|
||||
// Set the initial content description.
|
||||
setDescriptionOnSuggestion(mUserEnteredTextView, mUserEnteredTextView.getText().toString());
|
||||
// This can be called before the opt-in permission prompt is shown or set. Check first.
|
||||
if (suggestionsEnabled) {
|
||||
final int recycledSuggestionCount = mSuggestionView.getChildCount();
|
||||
if (AppConstants.NIGHTLY_BUILD) {
|
||||
|
||||
final boolean isTablet = HardwareUtils.isTablet();
|
||||
final Cursor c = getSavedSearches(searchTerm, isTablet);
|
||||
try {
|
||||
final int savedSearchCount = (c != null) ? c.getCount(): 0;
|
||||
final int suggestionViewCount = updateFromSearchEngine(animate, recycledSuggestionCount, isTablet, savedSearchCount);
|
||||
updateFromSavedSearches(c, animate, suggestionViewCount, recycledSuggestionCount);
|
||||
} finally {
|
||||
if (c != null) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
updateFromSearchEngine(animate, recycledSuggestionCount, true, 0);
|
||||
if (!AppConstants.NIGHTLY_BUILD) {
|
||||
if (searchSuggestionsEnabled) {
|
||||
updateFromSearchEngine(animate, mSuggestionView.getChildCount(), 0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final int recycledSuggestionCount = mSuggestionView.getChildCount();
|
||||
final SharedPreferences prefs = GeckoSharedPrefs.forApp(getContext());
|
||||
final boolean savedSearchesEnabled = prefs.getBoolean(GeckoPreferences.PREFS_HISTORY_SAVED_SEARCH, true);
|
||||
|
||||
if (searchSuggestionsEnabled && savedSearchesEnabled) {
|
||||
final Cursor c = getSavedSearches(searchTerm);
|
||||
try {
|
||||
final int savedSearchCount = (c != null) ? c.getCount() : 0;
|
||||
final int suggestionViewCount = updateFromSearchEngine(animate, recycledSuggestionCount, savedSearchCount);
|
||||
updateFromSavedSearches(c, animate, suggestionViewCount, recycledSuggestionCount);
|
||||
} finally {
|
||||
if (c != null) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
} else if (savedSearchesEnabled) {
|
||||
final Cursor c = getSavedSearches(searchTerm);
|
||||
try {
|
||||
updateFromSavedSearches(c, animate, 0, recycledSuggestionCount);
|
||||
} finally {
|
||||
if (c != null) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
} else if (searchSuggestionsEnabled) {
|
||||
updateFromSearchEngine(animate, recycledSuggestionCount, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -290,6 +290,7 @@ size. -->
|
||||
<!ENTITY pref_sync "Sync">
|
||||
<!ENTITY pref_sync_summary2 "Sync your tabs, bookmarks, logins, history">
|
||||
<!ENTITY pref_search_suggestions "Show search suggestions">
|
||||
<!ENTITY pref_history_search_suggestions "Show search history">
|
||||
<!ENTITY pref_import_android "Import from Android">
|
||||
<!ENTITY pref_import_android_summary "Import bookmarks and history from the native browser">
|
||||
<!ENTITY pref_private_data_history2 "Browsing history">
|
||||
|
@ -137,6 +137,7 @@ OnSharedPreferenceChangeListener
|
||||
private static final String PREFS_TRACKING_PROTECTION_LEARN_MORE = NON_PREF_PREFIX + "trackingprotection.learn_more";
|
||||
private static final String PREFS_CATEGORY_PRIVATE_DATA = NON_PREF_PREFIX + "category_private_data";
|
||||
public static final String PREFS_HOMEPAGE = NON_PREF_PREFIX + "homepage";
|
||||
public static final String PREFS_HISTORY_SAVED_SEARCH = NON_PREF_PREFIX + "search.search_history.enabled";
|
||||
|
||||
private static final String ACTION_STUMBLER_UPLOAD_PREF = AppConstants.ANDROID_PACKAGE_NAME + ".STUMBLER_PREF";
|
||||
|
||||
@ -755,6 +756,13 @@ OnSharedPreferenceChangeListener
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
} else if (PREFS_HISTORY_SAVED_SEARCH.equals(key)) {
|
||||
// Remove settings UI if not on Nightly
|
||||
if (!AppConstants.NIGHTLY_BUILD) {
|
||||
preferences.removePreference(pref);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
} else if (PREFS_TELEMETRY_ENABLED.equals(key)) {
|
||||
if (!AppConstants.MOZ_TELEMETRY_REPORTING) {
|
||||
preferences.removePreference(pref);
|
||||
|
@ -13,6 +13,11 @@
|
||||
android:defaultValue="false"
|
||||
android:persistent="false" />
|
||||
|
||||
<CheckBoxPreference android:key="android.not_a_preference.search.search_history.enabled"
|
||||
android:title="@string/pref_history_search_suggestions"
|
||||
android:defaultValue="true"
|
||||
android:persistent="true" />
|
||||
|
||||
<org.mozilla.gecko.preferences.SearchPreferenceCategory
|
||||
android:title="@string/pref_category_installed_search_engines"/>
|
||||
|
||||
|
@ -13,6 +13,11 @@
|
||||
android:defaultValue="false"
|
||||
android:persistent="false" />
|
||||
|
||||
<CheckBoxPreference android:key="android.not_a_preference.search.search_history.enabled"
|
||||
android:title="@string/pref_history_search_suggestions"
|
||||
android:defaultValue="true"
|
||||
android:persistent="true" />
|
||||
|
||||
<org.mozilla.gecko.preferences.SearchPreferenceCategory
|
||||
android:title="@string/pref_category_installed_search_engines"/>
|
||||
|
||||
|
@ -248,6 +248,7 @@
|
||||
<string name="pref_sync">&pref_sync;</string>
|
||||
<string name="pref_sync_summary">&pref_sync_summary2;</string>
|
||||
<string name="pref_search_suggestions">&pref_search_suggestions;</string>
|
||||
<string name="pref_history_search_suggestions">&pref_history_search_suggestions;</string>
|
||||
<string name="pref_private_data_history2">&pref_private_data_history2;</string>
|
||||
<string name="pref_private_data_searchHistory">&pref_private_data_searchHistory;</string>
|
||||
<string name="pref_private_data_formdata2">&pref_private_data_formdata2;</string>
|
||||
|
Loading…
Reference in New Issue
Block a user