Brave Account section in Android settings. (#30354)
This commit is contained in:
@@ -203,6 +203,7 @@ brave_java_sources = [
|
||||
"../../brave/android/java/org/chromium/chrome/browser/custom_layout/popup_window_tooltip/ArrowColorDrawable.java",
|
||||
"../../brave/android/java/org/chromium/chrome/browser/custom_layout/popup_window_tooltip/PopupWindowTooltip.java",
|
||||
"../../brave/android/java/org/chromium/chrome/browser/custom_layout/popup_window_tooltip/PopupWindowTooltipUtils.java",
|
||||
"../../brave/android/java/org/chromium/chrome/browser/customtabs/BraveAccountCustomTabActivity.java",
|
||||
"../../brave/android/java/org/chromium/chrome/browser/customtabs/FullScreenCustomTabActivity.java",
|
||||
"../../brave/android/java/org/chromium/chrome/browser/customtabs/FullScreenCustomTabRootUiCoordinator.java",
|
||||
"../../brave/android/java/org/chromium/chrome/browser/customtabs/features/partialcustomtab/BravePartialCustomTabBottomSheetStrategy.java",
|
||||
|
||||
@@ -17,6 +17,14 @@
|
||||
android:name="org.chromium.chrome.browser.BraveRewardsUserWalletActivity"
|
||||
android:theme="@style/BraveTranslucent"/>
|
||||
|
||||
<activity
|
||||
android:name="org.chromium.chrome.browser.customtabs.BraveAccountCustomTabActivity"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|mcc|mnc|screenLayout|smallestScreenSize|uiMode|navigation"
|
||||
android:theme="@style/BraveAccountTheme"
|
||||
android:screenOrientation="sensorPortrait"
|
||||
tools:ignore="LockedOrientationActivity,DiscouragedApi"
|
||||
android:exported="false"/>
|
||||
|
||||
<activity
|
||||
android:name="org.chromium.chrome.browser.customtabs.FullScreenCustomTabActivity"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|mcc|mnc|screenLayout|smallestScreenSize|uiMode|navigation"
|
||||
|
||||
@@ -43,4 +43,5 @@ public abstract class BraveFeatureList {
|
||||
public static final String BRAVE_INCOGNITO_SCREENSHOT = "incognito-screenshot";
|
||||
public static final String BRAVE_NTP_BRANDED_WALLPAPER_SURVEY_PANELIST =
|
||||
"BraveNTPBrandedWallpaperSurveyPanelist";
|
||||
public static final String BRAVE_ACCOUNT = "BraveAccount";
|
||||
}
|
||||
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
/* Copyright (c) 2025 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 https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.chromium.chrome.browser.customtabs;
|
||||
|
||||
import static androidx.browser.customtabs.CustomTabsIntent.COLOR_SCHEME_DARK;
|
||||
import static androidx.browser.customtabs.CustomTabsIntent.COLOR_SCHEME_LIGHT;
|
||||
|
||||
import static org.chromium.ui.base.ViewUtils.dpToPx;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.provider.Browser;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.browser.customtabs.CustomTabsIntent;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import org.chromium.base.IntentUtils;
|
||||
import org.chromium.build.annotations.NullMarked;
|
||||
import org.chromium.chrome.R;
|
||||
import org.chromium.ui.util.ColorUtils;
|
||||
|
||||
@NullMarked
|
||||
public class BraveAccountCustomTabActivity extends CustomTabActivity {
|
||||
private static final int HORIZONTAL_MARGIN_DP = 12;
|
||||
|
||||
@Override
|
||||
public void performPostInflationStartup() {
|
||||
super.performPostInflationStartup();
|
||||
|
||||
// Hide the toolbar container
|
||||
View toolbarContainer = findViewById(R.id.toolbar_container);
|
||||
if (toolbarContainer != null) toolbarContainer.setVisibility(View.GONE);
|
||||
|
||||
TextView title = new TextView(this);
|
||||
title.setText(R.string.prefs_section_brave_account);
|
||||
title.setTextAppearance(R.style.TextAppearance_Headline_Primary);
|
||||
title.setGravity(Gravity.CENTER);
|
||||
FrameLayout.LayoutParams titleParams =
|
||||
new FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
Gravity.CENTER_VERTICAL | Gravity.START);
|
||||
titleParams.setMarginStart(dpToPx(this, HORIZONTAL_MARGIN_DP));
|
||||
title.setLayoutParams(titleParams);
|
||||
|
||||
ImageView closeButton = new ImageView(this);
|
||||
closeButton.setImageResource(R.drawable.btn_close);
|
||||
closeButton.setColorFilter(
|
||||
ContextCompat.getColor(this, R.color.schemes_on_surface),
|
||||
android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
closeButton.setOnClickListener(button -> finish());
|
||||
FrameLayout.LayoutParams closeButtonParams =
|
||||
new FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
Gravity.CENTER_VERTICAL | Gravity.END);
|
||||
closeButtonParams.setMarginEnd(dpToPx(this, HORIZONTAL_MARGIN_DP));
|
||||
closeButton.setLayoutParams(closeButtonParams);
|
||||
|
||||
FrameLayout header = new FrameLayout(this);
|
||||
header.setLayoutParams(
|
||||
new FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT, getActionBarSize(), Gravity.TOP));
|
||||
header.addView(title);
|
||||
header.addView(closeButton);
|
||||
|
||||
getContentView().addView(header);
|
||||
}
|
||||
|
||||
private int getActionBarSize() {
|
||||
TypedValue value = new TypedValue();
|
||||
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, value, true)) {
|
||||
return TypedValue.complexToDimensionPixelSize(
|
||||
value.data, getResources().getDisplayMetrics());
|
||||
}
|
||||
|
||||
return dpToPx(this, 56); // the standard action bar height on phones in portrait
|
||||
}
|
||||
|
||||
public static void show(Activity activity) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("brave://account"));
|
||||
intent.setClassName(activity, BraveAccountCustomTabActivity.class.getName());
|
||||
intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
|
||||
intent.putExtra(
|
||||
CustomTabsIntent.EXTRA_COLOR_SCHEME,
|
||||
ColorUtils.inNightMode(activity) ? COLOR_SCHEME_DARK : COLOR_SCHEME_LIGHT);
|
||||
IntentUtils.addTrustedIntentExtras(intent);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import org.chromium.chrome.R;
|
||||
import org.chromium.chrome.browser.BraveLaunchIntentDispatcher;
|
||||
import org.chromium.chrome.browser.accessibility.settings.BraveAccessibilitySettings;
|
||||
import org.chromium.chrome.browser.brave_leo.BraveLeoPrefUtils;
|
||||
import org.chromium.chrome.browser.customtabs.BraveAccountCustomTabActivity;
|
||||
import org.chromium.chrome.browser.flags.ChromeFeatureList;
|
||||
import org.chromium.chrome.browser.homepage.settings.BraveHomepageSettings;
|
||||
import org.chromium.chrome.browser.notifications.BraveNotificationWarningDialog;
|
||||
@@ -55,6 +56,7 @@ import java.util.HashMap;
|
||||
public abstract class BraveMainPreferencesBase extends BravePreferenceFragment
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
// sections
|
||||
private static final String PREF_BRAVE_ACCOUNT_SECTION = "brave_account_section";
|
||||
private static final String PREF_FEATURES_SECTION = "features_section";
|
||||
private static final String PREF_DISPLAY_SECTION = "display_section";
|
||||
private static final String PREF_GENERAL_SECTION = "general_section";
|
||||
@@ -64,8 +66,8 @@ public abstract class BraveMainPreferencesBase extends BravePreferenceFragment
|
||||
private static final String PREF_ABOUT_SECTION = "about_section";
|
||||
|
||||
// prefs
|
||||
|
||||
private static final String PREF_BRAVE_VPN_CALLOUT = "pref_vpn_callout";
|
||||
private static final String PREF_GET_STARTED = "get_started";
|
||||
private static final String PREF_CLOSING_ALL_TABS_CLOSES_BRAVE =
|
||||
"closing_all_tabs_closes_brave";
|
||||
private static final String PREF_PRIVACY = "privacy";
|
||||
@@ -108,9 +110,11 @@ public abstract class BraveMainPreferencesBase extends BravePreferenceFragment
|
||||
|
||||
// Add brave's additional preferences here because |onCreatePreference| is not called
|
||||
// by subclass (MainPreference::onCreatePreferences()).
|
||||
// But, calling here has same effect because |onCreatePreferences()| is called by onCreate().
|
||||
// But, calling here has same effect because |onCreatePreferences()| is called by
|
||||
// onCreate().
|
||||
SettingsUtils.addPreferencesFromResource(this, R.xml.brave_main_preferences);
|
||||
|
||||
initBraveAccount();
|
||||
overrideChromiumPreferences();
|
||||
initRateBrave();
|
||||
setPreferenceListeners();
|
||||
@@ -267,19 +271,29 @@ public abstract class BraveMainPreferencesBase extends BravePreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
setPreferenceOrder(PREF_FEATURES_SECTION, ++firstSectionOrder);
|
||||
int braveAccountSectionOrder = firstSectionOrder;
|
||||
if (ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_ACCOUNT)) {
|
||||
setPreferenceOrder(PREF_BRAVE_ACCOUNT_SECTION, ++braveAccountSectionOrder);
|
||||
setPreferenceOrder(PREF_GET_STARTED, ++braveAccountSectionOrder);
|
||||
} else {
|
||||
removePreferenceIfPresent(PREF_BRAVE_ACCOUNT_SECTION);
|
||||
removePreferenceIfPresent(PREF_GET_STARTED);
|
||||
}
|
||||
|
||||
setPreferenceOrder(PREF_SHIELDS_AND_PRIVACY, ++firstSectionOrder);
|
||||
setPreferenceOrder(PREF_BRAVE_NEWS_V2, ++firstSectionOrder);
|
||||
int featuresSectionOrder = braveAccountSectionOrder;
|
||||
setPreferenceOrder(PREF_FEATURES_SECTION, ++featuresSectionOrder);
|
||||
|
||||
setPreferenceOrder(PREF_SHIELDS_AND_PRIVACY, ++featuresSectionOrder);
|
||||
setPreferenceOrder(PREF_BRAVE_NEWS_V2, ++featuresSectionOrder);
|
||||
|
||||
if (ChromeFeatureList.isEnabled(BraveFeatureList.NATIVE_BRAVE_WALLET)) {
|
||||
setPreferenceOrder(PREF_BRAVE_WALLET, ++firstSectionOrder);
|
||||
setPreferenceOrder(PREF_BRAVE_WALLET, ++featuresSectionOrder);
|
||||
} else {
|
||||
removePreferenceIfPresent(PREF_BRAVE_WALLET);
|
||||
}
|
||||
|
||||
if (ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_PLAYLIST)) {
|
||||
setPreferenceOrder(PREF_BRAVE_PLAYLIST, ++firstSectionOrder);
|
||||
setPreferenceOrder(PREF_BRAVE_PLAYLIST, ++featuresSectionOrder);
|
||||
} else {
|
||||
removePreferenceIfPresent(PREF_BRAVE_PLAYLIST);
|
||||
}
|
||||
@@ -287,18 +301,18 @@ public abstract class BraveMainPreferencesBase extends BravePreferenceFragment
|
||||
if (getActivity() != null
|
||||
&& !getActivity().isFinishing()
|
||||
&& BraveVpnUtils.isVpnFeatureSupported(getActivity())) {
|
||||
setPreferenceOrder(PREF_BRAVE_VPN, ++firstSectionOrder);
|
||||
setPreferenceOrder(PREF_BRAVE_VPN, ++featuresSectionOrder);
|
||||
} else {
|
||||
removePreferenceIfPresent(PREF_BRAVE_VPN);
|
||||
}
|
||||
|
||||
if (BraveLeoPrefUtils.isLeoEnabled()) {
|
||||
setPreferenceOrder(PREF_BRAVE_LEO, ++firstSectionOrder);
|
||||
setPreferenceOrder(PREF_BRAVE_LEO, ++featuresSectionOrder);
|
||||
} else {
|
||||
removePreferenceIfPresent(PREF_BRAVE_LEO);
|
||||
}
|
||||
|
||||
int generalOrder = firstSectionOrder;
|
||||
int generalOrder = featuresSectionOrder;
|
||||
setPreferenceOrder(PREF_GENERAL_SECTION, ++generalOrder);
|
||||
|
||||
setPreferenceOrder(PREF_BRAVE_SEARCH_ENGINES, ++generalOrder);
|
||||
@@ -444,6 +458,20 @@ public abstract class BraveMainPreferencesBase extends BravePreferenceFragment
|
||||
updateSummary(PREF_BRAVE_STATS, BraveStatsPreferences.getPreferenceSummary());
|
||||
}
|
||||
|
||||
private void initBraveAccount() {
|
||||
Preference getStartedPreference = findPreference(PREF_GET_STARTED);
|
||||
if (getStartedPreference != null) {
|
||||
getStartedPreference.setOnPreferenceClickListener(
|
||||
new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
BraveAccountCustomTabActivity.show(getActivity());
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void overrideChromiumPreferences() {
|
||||
// Replace fragment.
|
||||
Preference shieldsAndPrivacyPreference = findPreference(PREF_SHIELDS_AND_PRIVACY);
|
||||
|
||||
@@ -308,6 +308,10 @@
|
||||
<item name="android:activityCloseExitAnimation">@anim/slide_out_bottom</item>
|
||||
</style>
|
||||
|
||||
<style name="BraveAccountTheme" parent="Theme.Chromium.Activity.Fullscreen">
|
||||
<item name="android:windowAnimationStyle">@style/BottomSheetAnimation</item>
|
||||
</style>
|
||||
|
||||
<style name="BottomSheetActivityTheme" parent="Theme.Chromium.Activity.FakeTranslucent">
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowAnimationStyle">@style/BottomSheetAnimation</item>
|
||||
|
||||
@@ -7,8 +7,17 @@
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orderingFromXml="false">
|
||||
<PreferenceCategory
|
||||
android:key="features_section"
|
||||
android:key="brave_account_section"
|
||||
android:order="1"
|
||||
android:title="@string/prefs_section_brave_account"/>
|
||||
<org.chromium.components.browser_ui.settings.ChromeBasePreference
|
||||
android:key="get_started"
|
||||
android:order="1"
|
||||
android:icon="@drawable/ic_brave"
|
||||
android:title="@string/get_started"/>
|
||||
<PreferenceCategory
|
||||
android:key="features_section"
|
||||
android:order="2"
|
||||
android:title="@string/prefs_section_features"/>
|
||||
<org.chromium.components.browser_ui.settings.ChromeBasePreference
|
||||
android:fragment="org.chromium.chrome.browser.privacy.BravePrivacySettings"
|
||||
|
||||
@@ -474,6 +474,12 @@ This file contains all "about" strings. It is set to NOT be translated, in tran
|
||||
<message name="IDS_PREFS_SUPPORT_SECTION" desc="Title for the support section ">
|
||||
Support
|
||||
</message>
|
||||
<message name="IDS_PREFS_SECTION_BRAVE_ACCOUNT" desc="Title for the Brave Account section in settings">
|
||||
Brave Account
|
||||
</message>
|
||||
<message name="IDS_GET_STARTED" desc="Button text to get started with Brave Account">
|
||||
Get started
|
||||
</message>
|
||||
<message name="IDS_PREFS_SECTION_FEATURES" desc="Title for Brave-specific features section">
|
||||
Features
|
||||
</message>
|
||||
|
||||
@@ -13,10 +13,54 @@
|
||||
#include "content/public/common/url_constants.h"
|
||||
#include "ui/webui/webui_util.h"
|
||||
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
#include <memory>
|
||||
|
||||
#include "base/values.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/browser/web_ui.h"
|
||||
#include "content/public/browser/web_ui_message_handler.h"
|
||||
|
||||
namespace {
|
||||
class BraveAccountUIMessageHandler : public content::WebUIMessageHandler {
|
||||
public:
|
||||
BraveAccountUIMessageHandler() = default;
|
||||
|
||||
BraveAccountUIMessageHandler(const BraveAccountUIMessageHandler&) = delete;
|
||||
BraveAccountUIMessageHandler& operator=(const BraveAccountUIMessageHandler&) =
|
||||
delete;
|
||||
|
||||
~BraveAccountUIMessageHandler() override = default;
|
||||
|
||||
private:
|
||||
// WebUIMessageHandler:
|
||||
void RegisterMessages() override;
|
||||
|
||||
void OnDialogCloseMessage(const base::Value::List& args);
|
||||
};
|
||||
|
||||
void BraveAccountUIMessageHandler::RegisterMessages() {
|
||||
web_ui()->RegisterMessageCallback(
|
||||
"dialogClose",
|
||||
base::BindRepeating(&BraveAccountUIMessageHandler::OnDialogCloseMessage,
|
||||
base::Unretained(this)));
|
||||
}
|
||||
|
||||
void BraveAccountUIMessageHandler::OnDialogCloseMessage(
|
||||
const base::Value::List& args) {
|
||||
web_ui()->GetWebContents()->Close();
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
BraveAccountUI::BraveAccountUI(content::WebUI* web_ui)
|
||||
: BraveAccountUIBase(Profile::FromWebUI(web_ui),
|
||||
base::BindOnce(&webui::SetupWebUIDataSource)),
|
||||
ConstrainedWebDialogUI(web_ui) {}
|
||||
ConstrainedWebDialogUI(web_ui) {
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
web_ui->AddMessageHandler(std::make_unique<BraveAccountUIMessageHandler>());
|
||||
#endif
|
||||
}
|
||||
|
||||
WEB_UI_CONTROLLER_TYPE_IMPL(BraveAccountUI)
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
include_rules = [
|
||||
"+brave/components/ai_chat/core/common/features.h",
|
||||
"+brave/components/brave_account/features.h",
|
||||
"+brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_feature.h",
|
||||
"+brave/components/brave_news/common/features.h",
|
||||
"+brave/components/brave_rewards/core/features.h",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "brave/browser/android/youtube_script_injector/features.h"
|
||||
#include "brave/browser/brave_browser_features.h"
|
||||
#include "brave/components/ai_chat/core/common/features.h"
|
||||
#include "brave/components/brave_account/features.h"
|
||||
#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_feature.h"
|
||||
#include "brave/components/brave_news/common/features.h"
|
||||
#include "brave/components/brave_rewards/core/features.h"
|
||||
@@ -64,7 +65,8 @@
|
||||
&brave_shields::features::kBraveShieldsElementPicker, \
|
||||
&features::kNewAndroidOnboarding, \
|
||||
&brave_ads::kNewTabPageAdFeature, \
|
||||
&ntp_background_images::features::kBraveNTPBrandedWallpaperSurveyPanelist
|
||||
&ntp_background_images::features::kBraveNTPBrandedWallpaperSurveyPanelist, \
|
||||
&brave_account::features::kBraveAccount
|
||||
|
||||
// clang-format on
|
||||
|
||||
|
||||
Reference in New Issue
Block a user