Make custom private page with DDG switch
This commit is contained in:
@@ -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 not shown.
|
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 9.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 33 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user