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

add p3a UI android (Uplift to 1.19.x) #7563

Closed
wants to merge 6 commits into from
Closed
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
7 changes: 7 additions & 0 deletions android/brave_java_resources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ brave_java_resources = [
"java/res/drawable/brave_badge_rewards_background_small.xml",
"java/res/drawable/brave_badge_shields_background_large.xml",
"java/res/drawable/brave_badge_shields_background_small.xml",
"java/res/drawable/brave_checkbox.xml",
"java/res/drawable/brave_gradient_shadow.xml",
"java/res/drawable/brave_modern_toolbar_text_box_background.xml",
"java/res/drawable/brave_rewards_circle.xml",
Expand Down Expand Up @@ -646,8 +647,11 @@ brave_java_resources = [
"java/res/drawable/ic_back.xml",
"java/res/drawable/ic_bat.xml",
"java/res/drawable/ic_binance.xml",
"java/res/drawable/ic_brave_logo.xml",
"java/res/drawable/ic_brave_rewards_widget.xml",
"java/res/drawable/ic_btc.xml",
"java/res/drawable/ic_checkbox_filled.xml",
"java/res/drawable/ic_checkbox_outline.xml",
"java/res/drawable/ic_chevron_left.xml",
"java/res/drawable/ic_chevron_right.xml",
"java/res/drawable/ic_clock.xml",
Expand All @@ -668,6 +672,8 @@ brave_java_resources = [
"java/res/drawable/ic_polygon_1.xml",
"java/res/drawable/ic_shield_done_filled.xml",
"java/res/drawable/ic_sort.xml",
"java/res/drawable/ic_spot_graphic.xml",
"java/res/drawable/ic_spot_graphic_dark.xml",
"java/res/drawable/ic_stats_icon.xml",
"java/res/drawable/ic_thank_you.xml",
"java/res/drawable/ic_toggle_down.xml",
Expand Down Expand Up @@ -710,6 +716,7 @@ brave_java_resources = [
"java/res/layout-land/verify_wallet_activity.xml",
"java/res/layout/activity_ntp_widget_stack.xml",
"java/res/layout/activity_onboarding.xml",
"java/res/layout/activity_p3a_onboarding.xml",
"java/res/layout/binance_deposit_item.xml",
"java/res/layout/binance_deposit_layout.xml",
"java/res/layout/binance_spinner_dropdown_item.xml",
Expand Down
2 changes: 1 addition & 1 deletion android/brave_java_sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ brave_java_sources = [
"../../brave/android/java/org/chromium/chrome/browser/help/BraveHelpAndFeedback.java",
"../../brave/android/java/org/chromium/chrome/browser/homepage/BraveHomepageManager.java",
"../../brave/android/java/org/chromium/chrome/browser/homepage/settings/BraveHomepageSettings.java",
"../../brave/android/java/org/chromium/chrome/browser/informers/BraveP3AInformers.java",
"../../brave/android/java/org/chromium/chrome/browser/language/settings/BraveLanguageSettings.java",
"../../brave/android/java/org/chromium/chrome/browser/local_database/BraveStatsTable.java",
"../../brave/android/java/org/chromium/chrome/browser/local_database/DatabaseHelper.java",
Expand Down Expand Up @@ -98,6 +97,7 @@ brave_java_sources = [
"../../brave/android/java/org/chromium/chrome/browser/onboarding/OnboardingActivity.java",
"../../brave/android/java/org/chromium/chrome/browser/onboarding/OnboardingPrefManager.java",
"../../brave/android/java/org/chromium/chrome/browser/onboarding/OnboardingViewPagerAdapter.java",
"../../brave/android/java/org/chromium/chrome/browser/onboarding/P3aOnboardingActivity.java",
"../../brave/android/java/org/chromium/chrome/browser/onboarding/SearchActivity.java",
"../../brave/android/java/org/chromium/chrome/browser/onboarding/SearchEngineEnum.java",
"../../brave/android/java/org/chromium/chrome/browser/onboarding/SearchEngineOnboardingFragment.java",
Expand Down
7 changes: 5 additions & 2 deletions android/java/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
<activity
android:name="org.chromium.chrome.browser.onboarding.SearchActivity"
android:theme="@style/Theme.Chromium.Activity.Fullscreen"
android:screenOrientation="sensorPortrait">
android:screenOrientation="sensorPortrait"/>

</activity>
<activity
android:name="org.chromium.chrome.browser.onboarding.P3aOnboardingActivity"
android:theme="@style/Theme.Chromium.Activity.Fullscreen"
android:screenOrientation="sensorPortrait"/>

<activity
android:name="org.chromium.chrome.browser.ntp.widget.NTPWidgetStackActivity"
Expand Down
23 changes: 7 additions & 16 deletions android/java/org/chromium/chrome/browser/app/BraveActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
import org.chromium.chrome.browser.brave_stats.BraveStatsUtil;
import org.chromium.chrome.browser.dependency_injection.ChromeActivityComponent;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.informers.BraveP3AInformers;
import org.chromium.chrome.browser.notifications.BraveSetDefaultBrowserNotificationService;
import org.chromium.chrome.browser.notifications.retention.RetentionNotificationUtil;
import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.onboarding.OnboardingActivity;
import org.chromium.chrome.browser.onboarding.OnboardingPrefManager;
import org.chromium.chrome.browser.onboarding.P3aOnboardingActivity;
import org.chromium.chrome.browser.onboarding.v2.HighlightDialogFragment;
import org.chromium.chrome.browser.preferences.BravePrefServiceBridge;
import org.chromium.chrome.browser.preferences.BravePreferenceKeys;
Expand Down Expand Up @@ -108,6 +108,7 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
public static final String REWARDS_LEARN_MORE_URL = "https://brave.com/faq-rewards/#unclaimed-funds";
public static final String BRAVE_TERMS_PAGE =
"https://basicattentiontoken.org/user-terms-of-service/";
public static final String P3A_URL = "https://brave.com/p3a";
public static final String BRAVE_PRIVACY_POLICY = "https://brave.com/privacy/#rewards";
private static final String PREF_CLOSE_TABS_ON_EXIT = "close_tabs_on_exit";
public static final String OPEN_URL = "open_url";
Expand Down Expand Up @@ -298,21 +299,11 @@ public void finishNativeInitialization() {
}
BraveSyncReflectionUtils.showInformers();

if (BraveConfig.P3A_ENABLED) {
// // P3A informer should be shown not for the updated users only
// if (!PackageUtils.isFirstInstall(this)) {
// BraveP3AInformers.show();
// } else {
// // On the first run P3A is must be set from the onboarding wizard
// }
// Uncomment ^ when onboarding UI step will be ready for P3A

// Until we don't have P3A onboarding, P3A will be disabled,
// but available for activating through settings
if (!BravePrefServiceBridge.getInstance().hasPathP3AEnabled()) {
BravePrefServiceBridge.getInstance().setP3AEnabled(false);
}
// Remove lines above ^ when onboarding UI step will be ready for P3A
if (BraveConfig.P3A_ENABLED
&& !OnboardingPrefManager.getInstance().isP3aOnboardingShown()) {
Intent p3aOnboardingIntent = new Intent(this, P3aOnboardingActivity.class);
p3aOnboardingIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(p3aOnboardingIntent);
}

if (!OnboardingPrefManager.getInstance().isOneTimeNotificationStarted()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ protected void onAttachedToWindow() {
checkAndShowNTPImage(false);
mNTPBackgroundImagesBridge.addObserver(mNTPBackgroundImageServiceObserver);
if (PackageUtils.isFirstInstall(mActivity)
&& !OnboardingPrefManager.getInstance().isNewOnboardingShown()) {
&& !OnboardingPrefManager.getInstance().isNewOnboardingShown()
&& OnboardingPrefManager.getInstance().isP3aOnboardingShown()) {
((BraveActivity)mActivity).showOnboardingV2(false);
}
if (OnboardingPrefManager.getInstance().isFromNotification() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/
public class OnboardingPrefManager {
private static final String PREF_ONBOARDING = "onboarding";
private static final String PREF_P3A_ONBOARDING = "p3a_onboarding";
private static final String PREF_CROSS_PROMO_MODAL = "cross_promo_modal";
private static final String PREF_ONBOARDING_V2 = "onboarding_v2";
private static final String PREF_NEXT_ONBOARDING_DATE = "next_onboarding_date";
Expand Down Expand Up @@ -101,6 +102,22 @@ public void setOnboardingShown(boolean isShown) {
sharedPreferencesEditor.apply();
}

/**
* Returns the user preference for whether the onboarding is shown.
*/
public boolean isP3aOnboardingShown() {
return mSharedPreferences.getBoolean(PREF_P3A_ONBOARDING, false);
}

/**
* Sets the user preference for whether the onboarding is shown.
*/
public void setP3aOnboardingShown(boolean isShown) {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
sharedPreferencesEditor.putBoolean(PREF_P3A_ONBOARDING, isShown);
sharedPreferencesEditor.apply();
}

/**
* Returns the user preference for whether the onboarding is shown.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* Copyright (c) 2021 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.onboarding;

import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import org.chromium.chrome.R;
import org.chromium.chrome.browser.BraveRewardsHelper;
import org.chromium.chrome.browser.app.BraveActivity;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.night_mode.GlobalNightModeStateProviderHolder;
import org.chromium.chrome.browser.onboarding.OnboardingPrefManager;
import org.chromium.chrome.browser.preferences.BravePrefServiceBridge;
import org.chromium.chrome.browser.util.PackageUtils;

public class P3aOnboardingActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_p3a_onboarding);
OnboardingPrefManager.getInstance().setP3aOnboardingShown(true);

boolean isFirstInstall = PackageUtils.isFirstInstall(this);

TextView p3aOnboardingTitle = findViewById(R.id.p3a_onboarding_title);
p3aOnboardingTitle.setText(isFirstInstall
? getResources().getString(R.string.p3a_onboarding_title_text_1)
: getResources().getString(R.string.p3a_onboarding_title_text_2));
CheckBox p3aOnboardingCheckbox = findViewById(R.id.p3a_onboarding_checkbox);
ImageView p3aOnboardingImg = findViewById(R.id.p3a_onboarding_img);
p3aOnboardingImg.setImageResource(isFirstInstall
? R.drawable.ic_brave_logo
: (GlobalNightModeStateProviderHolder.getInstance().isInNightMode()
? R.drawable.ic_spot_graphic_dark
: R.drawable.ic_spot_graphic));
TextView p3aOnboardingText = findViewById(R.id.p3a_onboarding_text);
Button btnContinue = findViewById(R.id.btn_continue);
btnContinue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
BravePrefServiceBridge.getInstance().setP3AEnabled(
p3aOnboardingCheckbox.isChecked());
BravePrefServiceBridge.getInstance().setP3ANoticeAcknowledged(true);
if (PackageUtils.isFirstInstall(P3aOnboardingActivity.this)
&& !OnboardingPrefManager.getInstance().isNewOnboardingShown()
&& BraveActivity.getBraveActivity() != null) {
BraveActivity.getBraveActivity().showOnboardingV2(false);
}
finish();
}
});

String productAnalysisString =
String.format(getResources().getString(R.string.p3a_onboarding_checkbox_text,
getResources().getString(R.string.private_product_analysis_text)));
int productAnalysisIndex = productAnalysisString.indexOf(
getResources().getString(R.string.private_product_analysis_text));
Spanned productAnalysisSpanned =
BraveRewardsHelper.spannedFromHtmlString(productAnalysisString);
SpannableString productAnalysisTextSS =
new SpannableString(productAnalysisSpanned.toString());

ClickableSpan productAnalysisClickableSpan = new ClickableSpan() {
@Override
public void onClick(@NonNull View textView) {
CustomTabActivity.showInfoPage(P3aOnboardingActivity.this, BraveActivity.P3A_URL);
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
};

productAnalysisTextSS.setSpan(productAnalysisClickableSpan, productAnalysisIndex,
productAnalysisIndex
+ getResources().getString(R.string.private_product_analysis_text).length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
productAnalysisTextSS.setSpan(
new ForegroundColorSpan(getResources().getColor(R.color.brave_blue_tint_color)),
productAnalysisIndex,
productAnalysisIndex
+ getResources().getString(R.string.private_product_analysis_text).length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
p3aOnboardingText.setMovementMethod(LinkMovementMethod.getInstance());
p3aOnboardingText.setText(productAnalysisTextSS);
}

@Override
public void onBackPressed() {}
}
9 changes: 9 additions & 0 deletions android/java/res/drawable/brave_checkbox.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_checked="true"
android:drawable="@drawable/ic_checkbox_filled" />
<item
android:state_checked="false"
android:drawable="@drawable/ic_checkbox_outline" />
</selector>
Loading