-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make custom private page with DDG switch
- Loading branch information
Showing
13 changed files
with
223 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
android/java/org/chromium/chrome/browser/ntp/BraveIncognitoNewTabPageView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* 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 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 BraveIncognitoNewTabPageView extends IncognitoNewTabPageView { | ||
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 BraveIncognitoNewTabPageView(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; | ||
} | ||
} |
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
patches/chrome-android-java-res-layout-new_tab_page_incognito.xml.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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..2003f8ad6712db98e235d75ed763f3e703863540 100644 | ||
--- a/chrome/android/java/res/layout/new_tab_page_incognito.xml | ||
+++ b/chrome/android/java/res/layout/new_tab_page_incognito.xml | ||
@@ -3,7 +3,7 @@ | ||
Use of this source code is governed by a BSD-style license that can be | ||
found in the LICENSE file. --> | ||
|
||
-<org.chromium.chrome.browser.ntp.IncognitoNewTabPageView | ||
+<org.chromium.chrome.browser.ntp.BraveIncognitoNewTabPageView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/ntp_content" | ||
@@ -82,8 +82,10 @@ | ||
android:textAppearance="@style/TextAppearance.IncognitoNewTabLearnMoreLinkModern" | ||
android:lineSpacingExtra="@dimen/md_incognito_ntp_line_spacing" /> | ||
|
||
+ <include layout="@layout/brave_ddg_offer_link" android:layout_height="wrap_content" android:layout_width="match_parent" /> | ||
+ | ||
</LinearLayout> | ||
|
||
</org.chromium.chrome.browser.ntp.NewTabPageScrollView> | ||
|
||
-</org.chromium.chrome.browser.ntp.IncognitoNewTabPageView> | ||
+</org.chromium.chrome.browser.ntp.BraveIncognitoNewTabPageView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
diff --git a/chrome/android/java/res/values-v17/styles.xml b/chrome/android/java/res/values-v17/styles.xml | ||
index 5b41c992fb2b17c1b8a8a06ecc09460c4190fa86..b4a36c8d48dcc89a1dd0e9c661f4d3eedc757ed8 100644 | ||
index 5b41c992fb2b17c1b8a8a06ecc09460c4190fa86..bdd0835c783ae2316ab9530f90419c62a390d855 100644 | ||
--- a/chrome/android/java/res/values-v17/styles.xml | ||
+++ b/chrome/android/java/res/values-v17/styles.xml | ||
@@ -995,4 +995,5 @@ | ||
<item name="android:textAlignment">viewStart</item> | ||
<item name="android:textAppearance">@style/TextAppearance.BlackTitle1</item> | ||
</style> | ||
+ <style name="BraveSwitchTheme"> <item name="colorControlActivated">#fb542b</item> </style> | ||
+ <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> |
22 changes: 22 additions & 0 deletions
22
...es/chrome-android-java-src-org-chromium-chrome-browser-ntp-IncognitoNewTabPage.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/IncognitoNewTabPage.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/IncognitoNewTabPage.java | ||
index 5273ff0bf0ced1788d003b4823283dc4358d5ced..1a73b31cff37f9a54bd8f4403c9ecb1169227496 100644 | ||
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/IncognitoNewTabPage.java | ||
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/IncognitoNewTabPage.java | ||
@@ -33,7 +33,7 @@ public class IncognitoNewTabPage | ||
private Activity mActivity; | ||
|
||
private String mTitle; | ||
- protected IncognitoNewTabPageView mIncognitoNewTabPageView; | ||
+ protected BraveIncognitoNewTabPageView mIncognitoNewTabPageView; | ||
|
||
private boolean mIsLoaded; | ||
|
||
@@ -92,7 +92,7 @@ public class IncognitoNewTabPage | ||
|
||
LayoutInflater inflater = LayoutInflater.from(activity); | ||
mIncognitoNewTabPageView = | ||
- (IncognitoNewTabPageView) inflater.inflate(R.layout.new_tab_page_incognito, null); | ||
+ (BraveIncognitoNewTabPageView) inflater.inflate(R.layout.new_tab_page_incognito, null); | ||
mIncognitoNewTabPageView.initialize(mIncognitoNewTabPageManager); | ||
mIncognitoNewTabPageView.setNavigationDelegate(host.createHistoryNavigationDelegate()); | ||
|