Skip to content

Commit

Permalink
Merge pull request #6243 from brave/search-update-1.12.x
Browse files Browse the repository at this point in the history
Search update 1.12.x (uplift to 1.12.x)
  • Loading branch information
kjozwiak authored Aug 4, 2020
2 parents 18b327c + 00b3f14 commit 3634a8e
Show file tree
Hide file tree
Showing 23 changed files with 960 additions and 211 deletions.
6 changes: 6 additions & 0 deletions android/brave_java_resources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ brave_java_resources = [
"java/res/drawable/enable_rewards_button.xml",
"java/res/drawable/shields_tooltip_background.xml",
"java/res/drawable/sync_icon.xml",
"java/res/drawable/ic_yahoo.xml",
"java/res/drawable-hdpi/check.png",
"java/res/drawable-hdpi/btn_bookmark.png",
"java/res/drawable-hdpi/arrow_forward.png",
Expand Down Expand Up @@ -138,6 +139,7 @@ brave_java_resources = [
"java/res/drawable-hdpi/add_funds.png",
"java/res/drawable-hdpi/incognito_simple.png",
"java/res/drawable-hdpi/search_engine_google.png",
"java/res/drawable-hdpi/search_engine_yahoo.png",
"java/res/drawable-hdpi/uphold_green.png",
"java/res/drawable-hdpi/btn_mic.png",
"java/res/drawable-hdpi/btn_star_filled.png",
Expand Down Expand Up @@ -245,6 +247,7 @@ brave_java_resources = [
"java/res/drawable-mdpi/add_funds.png",
"java/res/drawable-mdpi/incognito_simple.png",
"java/res/drawable-mdpi/search_engine_google.png",
"java/res/drawable-mdpi/search_engine_yahoo.png",
"java/res/drawable-mdpi/uphold_green.png",
"java/res/drawable-mdpi/btn_mic.png",
"java/res/drawable-mdpi/btn_star_filled.png",
Expand Down Expand Up @@ -395,6 +398,7 @@ brave_java_resources = [
"java/res/drawable-xhdpi/add_funds.png",
"java/res/drawable-xhdpi/incognito_simple.png",
"java/res/drawable-xhdpi/search_engine_google.png",
"java/res/drawable-xhdpi/search_engine_yahoo.png",
"java/res/drawable-xhdpi/uphold_green.png",
"java/res/drawable-xhdpi/btn_mic.png",
"java/res/drawable-xhdpi/btn_star_filled.png",
Expand Down Expand Up @@ -500,6 +504,7 @@ brave_java_resources = [
"java/res/drawable-xxhdpi/add_funds.png",
"java/res/drawable-xxhdpi/incognito_simple.png",
"java/res/drawable-xxhdpi/search_engine_google.png",
"java/res/drawable-xxhdpi/search_engine_yahoo.png",
"java/res/drawable-xxhdpi/uphold_green.png",
"java/res/drawable-xxhdpi/btn_mic.png",
"java/res/drawable-xxhdpi/btn_star_filled.png",
Expand Down Expand Up @@ -625,6 +630,7 @@ brave_java_resources = [
"java/res/drawable-xxxhdpi/bat_unverified.png",
"java/res/drawable-xxxhdpi/share_icon.png",
"java/res/drawable-xxxhdpi/omnibox_https_valid.png",
"java/res/drawable-xxxhdpi/search_engine_yahoo.png",
"java/res/layout/brave_shields_ads_tracking_switcher.xml",
"java/res/layout/web_notification_icon_frame_brave.xml",
"java/res/layout/brave_sync_layout.xml",
Expand Down
1 change: 1 addition & 0 deletions android/brave_java_sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ brave_java_sources = [
"../../brave/android/java/org/chromium/chrome/browser/qrreader/BarcodeTrackerFactory.java",
"../../brave/android/java/org/chromium/chrome/browser/qrreader/CameraSource.java",
"../../brave/android/java/org/chromium/chrome/browser/qrreader/CameraSourcePreview.java",
"../../brave/android/java/org/chromium/chrome/browser/search_engines/settings/BraveBaseSearchEngineAdapter.java",
"../../brave/android/java/org/chromium/chrome/browser/settings/AppearancePreferences.java",
"../../brave/android/java/org/chromium/chrome/browser/settings/BackgroundImagesPreferences.java",
"../../brave/android/java/org/chromium/chrome/browser/settings/BackgroundVideoPlaybackPreference.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class OnboardingPrefManager {
private static final String QWANT = "Qwant";
private static final String BING = "Bing";
private static final String STARTPAGE = "StartPage";
private static final String YAHOO = "Yahoo";

private OnboardingPrefManager() {
mSharedPreferences = ContextUtils.getAppSharedPreferences();
Expand Down Expand Up @@ -163,6 +164,7 @@ public void onboardingNotification(Context context) {
new HashMap<String, SearchEngineEnum>() {
{
put(GOOGLE, SearchEngineEnum.GOOGLE);
put(YAHOO, SearchEngineEnum.YAHOO);
put(DUCKDUCKGO, SearchEngineEnum.DUCKDUCKGO);
put(DUCKDUCKGOLITE, SearchEngineEnum.DUCKDUCKGOLITE);
put(QWANT, SearchEngineEnum.QWANT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public enum SearchEngineEnum {
GOOGLE(R.drawable.search_engine_google, SearchEngineEnumConstants.SEARCH_GOOGLE_ID),
YAHOO(R.drawable.search_engine_yahoo, SearchEngineEnumConstants.SEARCH_YAHOO_ID),
DUCKDUCKGO(R.drawable.search_engine_duckduckgo, SearchEngineEnumConstants.SEARCH_DUCKDUCKGO_ID),
DUCKDUCKGOLITE(R.drawable.search_engine_duckduckgo_lite,
SearchEngineEnumConstants.SEARCH_DUCKDUCKGO_LITE_ID),
Expand Down Expand Up @@ -41,5 +42,6 @@ interface SearchEngineEnumConstants {
static final int SEARCH_QWANT_ID = 3;
static final int SEARCH_BING_ID = 4;
static final int SEARCH_STARTPAGE_ID = 5;
static final int SEARCH_YAHOO_ID = 6;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.chromium.chrome.browser.search_engines.settings;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import org.chromium.components.search_engines.TemplateUrl;
import org.chromium.chrome.browser.search_engines.settings.SearchEngineAdapter;

import java.util.Iterator;
import java.util.List;

public class BraveBaseSearchEngineAdapter extends BaseAdapter {
public BraveBaseSearchEngineAdapter() {
}

// BaseAdapter:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return convertView;
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public Object getItem(int pos) {
return null;
}

@Override
public int getCount() {
return 0;
}

public static void sortAndFilterUnnecessaryTemplateUrl(
List<TemplateUrl> templateUrls, TemplateUrl defaultSearchEngine) {
int recentEngineNum = 0;
long displayTime = System.currentTimeMillis() - SearchEngineAdapter.MAX_DISPLAY_TIME_SPAN_MS;
Iterator<TemplateUrl> iterator = templateUrls.iterator();
while (iterator.hasNext()) {
TemplateUrl templateUrl = iterator.next();
if (getSearchEngineSourceType(templateUrl, defaultSearchEngine)
!= SearchEngineAdapter.TemplateUrlSourceType.RECENT) {
continue;
}
if (recentEngineNum < SearchEngineAdapter.MAX_RECENT_ENGINE_NUM
&& templateUrl.getLastVisitedTime() > displayTime) {
recentEngineNum++;
} else {
iterator.remove();
}
}
}

public static @SearchEngineAdapter.TemplateUrlSourceType int getSearchEngineSourceType(
TemplateUrl templateUrl, TemplateUrl defaultSearchEngine) {
if (templateUrl.getIsPrepopulated()) {
return SearchEngineAdapter.TemplateUrlSourceType.PREPOPULATED;
} else if (templateUrl.equals(defaultSearchEngine)) {
return SearchEngineAdapter.TemplateUrlSourceType.DEFAULT;
} else {
return SearchEngineAdapter.TemplateUrlSourceType.RECENT;
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions android/java/res/drawable/ic_yahoo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<vector android:height="24dp" android:viewportHeight="256"
android:viewportWidth="256" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#6001D2" android:pathData="M0,0h256v256h-256z"/>
<path android:fillColor="#ffffff" android:pathData="M82,175L49,95V91.5L51,89.5H75.5L78,91.5L80,93L98,137L115,95L116.5,91.5L119.5,89.5H144.5L146.5,91.5V95L104.5,198L103,200L101,201H75.5L73.5,200V198L82,177V175Z"/>
<path android:fillColor="#ffffff" android:pathData="M149.5,120L174.5,59L176.5,56L179,55H204L206,57V59.5L181,121L179,123L176.5,124.5H151.5L149.5,122.5V120Z"/>
<path android:fillColor="#ffffff" android:pathData="M156,154m-19.5,0a19.5,19.5 0,1 1,39 0a19.5,19.5 0,1 1,-39 0"/>
</vector>
123 changes: 56 additions & 67 deletions android/java/res/layout/fragment_search_engine_onboarding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,89 +5,78 @@
You can obtain one at http://mozilla.org/MPL/2.0/.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/onboarding_black">
android:background="@color/onboarding_bg_color">

<LinearLayout
android:id="@+id/search_engine_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:paddingTop="48dp"
android:background="@color/onboarding_bg_color"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/choose_default_search_engine"
android:lineSpacingMultiplier="1.2"
android:layout_marginTop="20dp"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:textSize="20sp"
android:textColor="@color/onboarding_text_color"
android:textStyle="bold" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<LinearLayout
android:id="@+id/search_engine_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="16dp"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:lineSpacingMultiplier="1.2"
android:text="@string/search_engine_text"
android:textColor="@color/onboarding_text_color"
android:textSize="@dimen/onboarding_text_size" />
android:paddingTop="48dp"
android:orientation="vertical">

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingStart="16dp"
android:paddingEnd="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/choose_default_search_engine"
android:lineSpacingMultiplier="1.2"
android:layout_marginTop="20dp"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:textSize="20sp"
android:textColor="@color/onboarding_text_color"
android:textStyle="bold" />

<RadioGroup
android:id="@+id/radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"/>

</ScrollView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/search_engine_text"
android:lineSpacingMultiplier="1.2"
android:layout_marginTop="20dp"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:textSize="14sp"
android:textColor="@color/onboarding_text_color"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/search_engine_text"
android:lineSpacingMultiplier="1.2"
android:layout_marginTop="20dp"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:textSize="14sp"
android:textColor="@color/onboarding_text_color"/>
<Button
android:id="@+id/btn_save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="32dp"
android:background="@drawable/orange_rounded_button"
android:text="@string/save"
android:textAllCaps="false"
android:textColor="@android:color/white"
android:textSize="@dimen/onboarding_text_size"
style="?android:attr/borderlessButtonStyle"/>

<Button
android:id="@+id/btn_save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="32dp"
android:background="@drawable/orange_rounded_button"
android:text="@string/save"
android:textAllCaps="false"
android:textColor="@android:color/white"
android:textSize="@dimen/onboarding_text_size"
style="?android:attr/borderlessButtonStyle"/>
</LinearLayout>

</LinearLayout>

</LinearLayout>
</ScrollView>
4 changes: 3 additions & 1 deletion browser/search_engines/search_engine_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ void RecordSearchEngineP3A(const GURL& search_engine_url,
answer = SearchEngineP3A::kBing;
} else if (type == SEARCH_ENGINE_QWANT) {
answer = SearchEngineP3A::kQwant;
} else if (type == SEARCH_ENGINE_YAHOO) {
answer = SearchEngineP3A::kYahoo;
} else if (type == SEARCH_ENGINE_OTHER) {
if (base::EndsWith(search_engine_url.host(), "startpage.com",
base::CompareCase::INSENSITIVE_ASCII)) {
answer = SearchEngineP3A::kStartpage;
}
}

UMA_HISTOGRAM_ENUMERATION("Brave.Search.DefaultEngine", answer);
UMA_HISTOGRAM_ENUMERATION("Brave.Search.DefaultEngine.2", answer);
}

} // namespace
Expand Down
5 changes: 3 additions & 2 deletions browser/search_engines/search_engine_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "url/gurl.h"

// Exposed for tests.
constexpr char kDefaultSearchEngineMetric[] = "Brave.Search.DefaultEngine";
constexpr char kDefaultSearchEngineMetric[] = "Brave.Search.DefaultEngine.2";

// Note: append-only enumeration! Never remove any existing values, as this enum
// is used to bucket a UMA histogram, and removing values breaks that.
Expand All @@ -27,7 +27,8 @@ enum class SearchEngineP3A {
kStartpage,
kBing,
kQwant,
kMaxValue = kQwant,
kYahoo,
kMaxValue = kYahoo,
};

class SearchEngineTrackerFactory : public BrowserContextKeyedServiceFactory {
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ This file contains all "about" strings. It is set to NOT be translated, in tran
Choose default search engine
</message>
<message name="IDS_SEARCH_ENGINE_TEXT" desc="Text for search engine page for onboarding">
For a more private search experience, try DuckDuckGo.
You can always change your preference later in app settings.
</message>
<message name="IDS_SAVE" desc="Text for save button">
Save
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static ClassVisitor createAdapter(ClassVisitor chain) {
chain = new BraveFeedSurfaceCoordinatorClassAdapter(chain);
chain = new BraveNewTabPageClassAdapter(chain);
chain = new BraveEditUrlSuggestionProcessorClassAdapter(chain);
chain = new BraveSearchEngineAdapterClassAdapter(chain);
return chain;
}
}
Loading

0 comments on commit 3634a8e

Please sign in to comment.