Skip to content

Commit

Permalink
Remove Brave logo for > android 9 devices and update existing chnages
Browse files Browse the repository at this point in the history
Refactor the changes and add comments

Improve formatting and comments
  • Loading branch information
deeppandya committed Jan 16, 2025
1 parent 47a7ce3 commit fe7033f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.animation.LayoutTransition;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.RemoteException;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -56,18 +55,23 @@
import java.util.Locale;

/**
* This is on boarding activity
* */
* Activity that handles the first run onboarding experience for new Brave browser installations.
* Extends FirstRunActivityBase to provide onboarding flows for: - Setting Brave as default browser
* - Configuring privacy and analytics preferences (P3A and crash reporting) - Accepting terms of
* service The activity guides users through a series of steps using animations and clear UI
* elements to explain Brave's key features and privacy-focused approach.
*/
public class WelcomeOnboardingActivity extends FirstRunActivityBase {
// mInitializeViewsDone and mInvokePostWorkAtInitializeViews are accessed
// from the same thread, so no need to use extra locks
private static final String P3A_URL =
"https://support.brave.com/hc/en-us/articles/9140465918093-What-is-P3A-in-Brave";

private static final String TAG = "WelcomeOnboarding";

// mInitializeViewsDone and mInvokePostWorkAtInitializeViews are accessed
// from the same thread, so no need to use extra locks
private boolean mInitializeViewsDone;
private boolean mInvokePostWorkAtInitializeViews;

private boolean mIsTablet;
private BraveFirstRunFlowSequencer mFirstRunFlowSequencer;
private int mCurrentStep = -1;
Expand All @@ -79,29 +83,37 @@ public class WelcomeOnboardingActivity extends FirstRunActivityBase {
private ImageView mIvBrave;
private ImageView mIvArrowDown;
private LinearLayout mLayoutCard;
private TextView mTvWelcome;
private TextView mTvCard;
private TextView mTvDefault;
private Button mBtnPositive;
private Button mBtnNegative;
private CheckBox mCheckboxCrash;
private CheckBox mCheckboxP3a;

/**
* Initializes the views and sets up the onboarding activity UI. This method handles the initial
* setup of the welcome onboarding screen, including loading the layout, initializing views and
* click listeners, and performing first-run setup tasks.
*/
private void initializeViews() {
assert !mInitializeViewsDone;

setContentView(R.layout.activity_welcome_onboarding);

mIsTablet = DeviceFormFactor.isNonMultiDisplayContextOnTablet(this);

initViews();

onClickViews();

mInitializeViewsDone = true;

if (mInvokePostWorkAtInitializeViews) {
finishNativeInitializationPostWork();
}

checkReferral();

maybeUpdateFirstRunDefaultValues();
}

Expand Down Expand Up @@ -162,7 +174,6 @@ private void initViews() {
mIvBrave = findViewById(R.id.iv_brave);
mIvArrowDown = findViewById(R.id.iv_arrow_down);
mLayoutCard = findViewById(R.id.layout_card);
mTvWelcome = findViewById(R.id.tv_welcome);
mTvCard = findViewById(R.id.tv_card);
mTvDefault = findViewById(R.id.tv_default);
mCheckboxCrash = findViewById(R.id.checkbox_crash);
Expand Down Expand Up @@ -207,7 +218,7 @@ private void onClickViews() {
if (mBtnPositive != null) {
mBtnPositive.setOnClickListener(
view -> {
if (mCurrentStep == 1 && !isDefaultBrowser()) {
if (mCurrentStep == 0 && !isDefaultBrowser()) {
setDefaultBrowserAndProceedToNextStep();
} else {
nextOnboardingStep();
Expand Down Expand Up @@ -255,65 +266,34 @@ private void nextOnboardingStep() {

mCurrentStep++;
if (mCurrentStep == 0) {
showIntroPage();
} else if (mCurrentStep == 1) {
if (!BraveSetDefaultBrowserUtils.supportsDefaultRoleManager()) {
mIvBrave.setVisibility(View.VISIBLE);
showBrowserSelectionPage();
} else if (!isDefaultBrowser()) {
setDefaultBrowserAndProceedToNextStep();
} else {
nextOnboardingStep();
}
} else if (mCurrentStep == getAnalyticsConsentPageStep()) {
mIvBrave.setVisibility(View.VISIBLE);
showAnalyticsConsentPage();
} else {
OnboardingPrefManager.getInstance().setP3aOnboardingShown(true);
OnboardingPrefManager.getInstance().setOnboardingSearchBoxTooltip(true);

FirstRunStatus.setFirstRunFlowComplete(true);

ChromeSharedPreferences.getInstance()
.writeBoolean(ChromePreferenceKeys.FIRST_RUN_CACHED_TOS_ACCEPTED, true);
FirstRunUtils.setEulaAccepted();

finish();
sendFirstRunCompletePendingIntent();
}
}

private int getAnalyticsConsentPageStep() {
return 2;
}

private void showIntroPage() {
int margin = mIsTablet ? 100 : 0;
setLeafAnimation(mVLeafAlignTop, mIvLeafTop, 1f, margin, true);
setLeafAnimation(mVLeafAlignBottom, mIvLeafBottom, 1f, margin, false);
if (mTvWelcome != null) {
mTvWelcome
.animate()
.alpha(1f)
.setDuration(200)
.withEndAction(() -> mTvWelcome.setVisibility(View.VISIBLE));
}
if (mIvBrave != null) {
mIvBrave.animate().scaleX(0.8f).scaleY(0.8f).setDuration(1000);
}
new Handler()
.postDelayed(
new Runnable() {
@Override
public void run() {
if (mTvWelcome != null) {
mTvWelcome
.animate()
.translationYBy(
-dpToPx(WelcomeOnboardingActivity.this, 20))
.setDuration(3000)
.start();
}
}
},
200);

nextOnboardingStep();
return 1;
}

private void showBrowserSelectionPage() {
Expand All @@ -329,9 +309,6 @@ private void showBrowserSelectionPage() {
mBtnNegative.setVisibility(View.GONE);
}
}
if (mTvWelcome != null) {
mTvWelcome.setVisibility(View.GONE);
}
if (mLayoutCard != null) {
mLayoutCard.setVisibility(View.VISIBLE);
}
Expand Down Expand Up @@ -375,24 +352,30 @@ private void showAnalyticsConsentPage() {
mBtnNegative.setVisibility(View.VISIBLE);
}

// Handle crash reporting consent based on installation status
if (PackageUtils.isFirstInstall(this)
&& !OnboardingPrefManager.getInstance().isP3aCrashReportingMessageShown()) {
// For first time installs, enable crash reporting by default
if (mCheckboxCrash != null) {
mCheckboxCrash.setChecked(true);
}
// Update metrics reporting consent
UmaSessionStats.changeMetricsReportingConsent(
true, ChangeMetricsReportingStateCalledFrom.UI_FIRST_RUN);
// Mark crash reporting message as shown
OnboardingPrefManager.getInstance().setP3aCrashReportingMessageShown(true);
} else {
// For existing installations, restore previous crash reporting preference
boolean isCrashReporting = false;
try {
// Get current crash reporting permission status
isCrashReporting =
PrivacyPreferencesManagerImpl.getInstance()
.isUsageAndCrashReportingPermittedByUser();

} catch (Exception e) {
Log.e(TAG, "isCrashReportingOnboarding: " + e.getMessage());
}
// Update checkbox to match current preference
if (mCheckboxCrash != null) {
mCheckboxCrash.setChecked(isCrashReporting);
}
Expand Down
12 changes: 1 addition & 11 deletions android/java/res/layout/activity_welcome_onboarding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,6 @@
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">

<TextView
android:id="@+id/tv_welcome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="24sp"
android:alpha="0"
android:visibility="gone"
android:textColor="@color/onboarding_welcome_text_color"
android:text="@string/welcome_to_brave"/>

<LinearLayout
android:id="@+id/layout_card"
Expand Down Expand Up @@ -182,6 +171,7 @@
android:adjustViewBounds="true"
android:layout_gravity="center_horizontal"
android:contentDescription="@null"
android:visibility="gone"
android:src="@drawable/ic_brave_onboarding"/>

</LinearLayout>
Expand Down
3 changes: 0 additions & 3 deletions browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,6 @@ This file contains all "about" strings. It is set to NOT be translated, in tran
</message>

<!-- Onboarding strings -->
<message name="IDS_WELCOME_TO_BRAVE" desc="Text for welcome onboarding">
Welcome to Brave
</message>
<message name="IDS_PRIVACY_ONBOARDING" desc="Text for privacy onboarding">
Privacy. Made simple.
</message>
Expand Down

0 comments on commit fe7033f

Please sign in to comment.