Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make custom private page with DDG switch #3509

Merged
merged 1 commit into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions android/brave_java_sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ brave_java_sources = [
"../../brave/android/java/org/chromium/chrome/browser/appmenu/BraveShieldsMenuHandler.java",
"../../brave/android/java/org/chromium/chrome/browser/appmenu/BraveShieldsMenuObserver.java",
"../../brave/android/java/org/chromium/chrome/browser/document/BraveLauncherActivity.java",
"../../brave/android/java/org/chromium/chrome/browser/ntp/BraveDuckDuckGoOfferView.java",
"../../brave/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java",
"../../brave/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageView.java",
"../../brave/android/java/org/chromium/chrome/browser/partnercustomizations/CloseBraveManager.java",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* Copyright (c) 2019 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.ntp;

import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.BraveSearchEngineUtils;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
import org.chromium.components.search_engines.TemplateUrl;

import java.util.List;

public class BraveDuckDuckGoOfferView extends LinearLayout {
public static String DDG_SEARCH_ENGINE_SHORT_NAME = "DuckDuckGo";
public static String PREF_DDG_OFFER_SHOWN = "brave_ddg_offer_shown";

private Context mContext;
private View mDDGOfferLink;

public BraveDuckDuckGoOfferView(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
}

@Override
protected void onFinishInflate() {
super.onFinishInflate();

mDDGOfferLink = findViewById(R.id.ddg_offer_link);
mDDGOfferLink.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showDDGOffer(true);
}
});

showDDGOffer(false);
}

private void showDDGOffer(boolean forceShow) {
if (BraveSearchEngineUtils.getDSEShortName(true).equals(DDG_SEARCH_ENGINE_SHORT_NAME)) {
mDDGOfferLink.setVisibility(View.GONE);
return;
}
if (!forceShow
&& ContextUtils.getAppSharedPreferences().getBoolean(PREF_DDG_OFFER_SHOWN, false)) {
return;
}
ContextUtils.getAppSharedPreferences()
.edit()
.putBoolean(PREF_DDG_OFFER_SHOWN, true)
.apply();
new AlertDialog.Builder(mContext, R.style.BraveDialogTheme)
.setView(R.layout.ddg_offer_layout)
.setPositiveButton(R.string.ddg_offer_positive,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
TemplateUrl templateUrl =
getTemplateUrlByShortName(DDG_SEARCH_ENGINE_SHORT_NAME);
if (templateUrl != null) {
BraveSearchEngineUtils.setDSEPrefs(templateUrl, true);
BraveSearchEngineUtils.updateActiveDSE(true);
}
mDDGOfferLink.setVisibility(View.GONE);
}
})
.setNegativeButton(R.string.ddg_offer_negative, null)
.show();
}

private TemplateUrl getTemplateUrlByShortName(String name) {
List<TemplateUrl> templateUrls = TemplateUrlServiceFactory.get().getTemplateUrls();
for (int index = 0; index < templateUrls.size(); ++index) {
TemplateUrl templateUrl = templateUrls.get(index);
if (templateUrl.getShortName().equals(name)) {
return templateUrl;
}
}
return null;
}
}
Binary file added android/java/res/drawable-hdpi/duckduckgo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/java/res/drawable-mdpi/duckduckgo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/java/res/drawable-xhdpi/duckduckgo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/java/res/drawable-xxhdpi/duckduckgo.png
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.
27 changes: 27 additions & 0 deletions android/java/res/layout/brave_ddg_offer_link.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2019 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/. -->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/ddg_offer_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/ddg_offer_link"
android:textColor="@color/modern_grey_400"
android:drawableStart="@drawable/duckduckgo"
android:drawablePadding="15dp"
android:layout_marginTop="15dp"
android:textSize="28sp"
android:scaleX="0.5"
android:scaleY="0.5" />

</LinearLayout>
40 changes: 40 additions & 0 deletions android/java/res/layout/ddg_offer_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ImageView android:id="@+id/ddg_logo"
android:scaleType="fitCenter"
android:src="@drawable/duckduckgo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:layout_gravity="center_horizontal"
android:paddingTop="15dip"
android:paddingStart="15dip"
android:paddingEnd="15dip" />

<TextView android:id="@+id/ddg_offer_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ddg_offer_title"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:paddingTop="15dip"
android:paddingStart="15dip"
android:paddingEnd="15dip"
android:textSize="22sp"
android:textStyle="bold" />

<TextView android:id="@+id/ddg_offer_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ddg_offer_text"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:paddingTop="15dip"
android:paddingStart="15dip"
android:paddingEnd="15dip" />

</LinearLayout>
13 changes: 13 additions & 0 deletions android/java/res/values/brave_styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->

<resources xmlns:tools="http://schemas.android.com/tools">
<style name="BraveSwitchTheme">
<item name="colorControlActivated">#fb542b</item>
</style>
<style name="BraveDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="windowNoTitle">true</item>
</style>
</resources>
15 changes: 15 additions & 0 deletions android/java/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,21 @@ This file contains all "about" strings. It is set to NOT be translated, in tran
<message name="IDS_MENU_BRAVE_REWARDS" desc="Title for brave rewards menu item">
Brave Rewards
</message>
<message name="IDS_DDG_OFFER_TITLE" desc="Title for DDG offer.">
Private search with DuckDuckGo?
</message>
<message name="IDS_DDG_OFFER_TEXT" desc="Text for DDG offer.">
With private search, Brave will use DuckDuckGo to answer your searches while you are in this private tab. DuckDuckGo is a search engine that does not track your search history, enabling you to search privately.
</message>
<message name="IDS_DDG_OFFER_POSITIVE" desc="Positive button text for DDG offer.">
Yes
</message>
<message name="IDS_DDG_OFFER_NEGATIVE" desc="Negative button text for DDG offer.">
No
</message>
<message name="IDS_DDG_OFFER_LINK" desc="Text for DDG offer link.">
Learn about private search with DuckDuckGo
</message>
</messages>
</release>
</grit>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/chrome/android/java/res/layout/new_tab_page_incognito.xml b/chrome/android/java/res/layout/new_tab_page_incognito.xml
index b294fa17a33e3c089babc00ca4d17b2a62a9e8f3..26efb010768cc6cf6f0ab64c7c3fbc57a54e65e4 100644
--- a/chrome/android/java/res/layout/new_tab_page_incognito.xml
+++ b/chrome/android/java/res/layout/new_tab_page_incognito.xml
@@ -82,6 +82,7 @@
android:textAppearance="@style/TextAppearance.IncognitoNewTabLearnMoreLinkModern"
android:lineSpacingExtra="@dimen/md_incognito_ntp_line_spacing" />

+ <org.chromium.chrome.browser.ntp.BraveDuckDuckGoOfferView android:id="@+id/brave_duck_duck_go_offer_view" android:layout_width="match_parent" android:layout_height="match_parent" > <include layout="@layout/brave_ddg_offer_link" /> </org.chromium.chrome.browser.ntp.BraveDuckDuckGoOfferView>
</LinearLayout>

</org.chromium.chrome.browser.ntp.NewTabPageScrollView>
10 changes: 0 additions & 10 deletions patches/chrome-android-java-res-values-styles.xml.patch

This file was deleted.