-
Notifications
You must be signed in to change notification settings - Fork 892
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
200 additions
and
10 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
92 changes: 92 additions & 0 deletions
92
android/java/org/chromium/chrome/browser/ntp/BraveDuckDuckGoOfferView.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,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; | ||
} | ||
} |
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
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> |
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
12 changes: 12 additions & 0 deletions
12
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,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> |
This file was deleted.
Oops, something went wrong.