-
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.
Merge pull request #7550 from brave/add_p3a_ui_android
Add p3a UI android
- Loading branch information
Showing
19 changed files
with
661 additions
and
107 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
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
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
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: 0 additions & 91 deletions
91
android/java/org/chromium/chrome/browser/informers/BraveP3AInformers.java
This file was deleted.
Oops, something went wrong.
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
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
110 changes: 110 additions & 0 deletions
110
android/java/org/chromium/chrome/browser/onboarding/P3aOnboardingActivity.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,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() {} | ||
} |
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,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> |
Oops, something went wrong.