Update SI banner

This commit is contained in:
Deep
2020-05-23 18:22:11 -04:00
parent f1c6b8784e
commit 5bf703a3fb
6 changed files with 279 additions and 303 deletions
@@ -51,7 +51,7 @@ import org.chromium.chrome.browser.ntp_background_images.util.NTPUtil;
import static org.chromium.ui.base.ViewUtils.dpToPx;
public class RewardsBottomSheetDialogFragment extends BottomSheetDialogFragment{
public class RewardsBottomSheetDialogFragment extends BottomSheetDialogFragment {
private static final String BRAVE_TERMS_PAGE = "https://basicattentiontoken.org/user-terms-of-service/";
private static final String BRAVE_REWARDS_LEARN_MORE = "https://brave.com/faq-rewards";
@@ -65,12 +65,12 @@ public class RewardsBottomSheetDialogFragment extends BottomSheetDialogFragment{
@Nullable
@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
if (getArguments()!=null) {
ntpType = getArguments().getInt(SponsoredImageUtil.NTP_TYPE,1);
}
return inflater.inflate(R.layout.ntp_bottom_sheet, container,false);
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
if (getArguments() != null) {
ntpType = getArguments().getInt(SponsoredImageUtil.NTP_TYPE, 1);
}
return inflater.inflate(R.layout.ntp_bottom_sheet, container, false);
}
@Override
@@ -84,7 +84,7 @@ public class RewardsBottomSheetDialogFragment extends BottomSheetDialogFragment{
super.onConfigurationChanged(newConfig);
boolean isTablet = DeviceFormFactor.isNonMultiDisplayContextOnTablet(getActivity());
if(isTablet || (!isTablet && newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)) {
if (isTablet || (!isTablet && newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)) {
getDialog().getWindow().setLayout(dpToPx(getActivity(), 400), -1);
} else {
getDialog().getWindow().setLayout(-1, -1);
@@ -98,7 +98,7 @@ public class RewardsBottomSheetDialogFragment extends BottomSheetDialogFragment{
newTabPageListener.updateInteractableFlag(false);
boolean isTablet = DeviceFormFactor.isNonMultiDisplayContextOnTablet(getActivity());
if(isTablet || (!isTablet && ConfigurationUtils.isLandscape(getActivity()))) {
if (isTablet || (!isTablet && ConfigurationUtils.isLandscape(getActivity()))) {
getDialog().getWindow().setLayout(dpToPx(getActivity(), 400), -1);
} else {
getDialog().getWindow().setLayout(-1, -1);
@@ -124,14 +124,22 @@ public class RewardsBottomSheetDialogFragment extends BottomSheetDialogFragment{
});
ImageView btnClose = view.findViewById(R.id.ntp_bottom_sheet_close);
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
Button turnOnAdsButton = view.findViewById(R.id.btn_turn_on_ads);
TextView bottomSheetTitleText = view.findViewById(R.id.ntp_bottom_sheet_title);
TextView bottomSheetText = view.findViewById(R.id.ntp_bottom_sheet_text);
TextView bottomSheetTosText = view.findViewById(R.id.ntp_bottom_sheet_tos_text);
TextView learnMoreText = view.findViewById(R.id.learn_more_text);
TextView hideSponsoredImagesText = view.findViewById(R.id.hide_sponsored_images_text);
if (btnClose != null) {
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
}
if (turnOnAdsButton != null) {
turnOnAdsButton.setOnClickListener(new View.OnClickListener() {
@Override
@@ -142,20 +150,8 @@ public class RewardsBottomSheetDialogFragment extends BottomSheetDialogFragment{
});
}
Button turnOnRewardsButton = view.findViewById(R.id.btn_turn_on_rewards);
if (turnOnRewardsButton != null) {
turnOnRewardsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
turnOnRewards();
dismiss();
}
});
}
Button learnMoreButton = view.findViewById(R.id.btn_learn_more);
if (learnMoreButton != null) {
learnMoreButton.setOnClickListener(new View.OnClickListener() {
if (learnMoreText != null) {
learnMoreText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NTPUtil.openUrlInSameTab(BRAVE_REWARDS_LEARN_MORE);
@@ -164,126 +160,48 @@ public class RewardsBottomSheetDialogFragment extends BottomSheetDialogFragment{
});
}
TextView bottomSheetTitleText= view.findViewById(R.id.ntp_bottom_sheet_title);
TextView bottomSheetText= view.findViewById(R.id.ntp_bottom_sheet_text);
if (hideSponsoredImagesText != null) {
hideSponsoredImagesText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hideSponsoredImages();
dismiss();
}
});
}
switch (ntpType) {
case SponsoredImageUtil.BR_OFF:
bottomSheetTitleText.setText(getResources().getString(R.string.turn_on_brave_ads_to_claim));
turnOnRewardsButton.setVisibility(View.VISIBLE);
learnMoreButton.setVisibility(View.VISIBLE);
String brOffText = String.format(getResources().getString(R.string.ntp_tos_text), getResources().getString(R.string.terms_of_service), getResources().getString(R.string.hide_sponsored_images));
int termsOfServiceIndex = brOffText.indexOf(getResources().getString(R.string.terms_of_service));
Spanned brOffTextSpanned = BraveRewardsHelper.spannedFromHtmlString(brOffText);
SpannableString brOffTextSS = new SpannableString(brOffTextSpanned.toString());
case SponsoredImageUtil.BR_ON_ADS_OFF:
bottomSheetTitleText.setText(getResources().getString(R.string.earn_tokens_for_viewing_title));
turnOnAdsButton.setVisibility(View.VISIBLE);
ClickableSpan tosClickableSpan = new ClickableSpan() {
@Override
public void onClick(@NonNull View textView) {
CustomTabActivity.showInfoPage(getActivity(), BRAVE_TERMS_PAGE);
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
};
bottomSheetTosText.setVisibility(View.VISIBLE);
String tosText = String.format(getResources().getString(R.string.ntp_tos_text), getResources().getString(R.string.terms_of_service));
int termsOfServiceIndex = tosText.indexOf(getResources().getString(R.string.terms_of_service));
Spanned tosTextSpanned = BraveRewardsHelper.spannedFromHtmlString(tosText);
SpannableString tosTextSS = new SpannableString(tosTextSpanned.toString());
ClickableSpan brOffHideSponsoredImagesClickableSpan = new ClickableSpan() {
@Override
public void onClick(@NonNull View textView) {
hideSponsoredImages();
dismiss();
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
};
ClickableSpan tosClickableSpan = new ClickableSpan() {
@Override
public void onClick(@NonNull View textView) {
CustomTabActivity.showInfoPage(getActivity(), BRAVE_TERMS_PAGE);
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
};
brOffTextSS.setSpan(tosClickableSpan, termsOfServiceIndex, termsOfServiceIndex + getResources().getString(R.string.terms_of_service).length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
brOffTextSS.setSpan(brOffHideSponsoredImagesClickableSpan, (brOffTextSS.length()-1) - getResources().getString(R.string.hide_sponsored_images).length() , brOffTextSS.length()-1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ForegroundColorSpan brOffForegroundSpan = new ForegroundColorSpan(getResources().getColor(R.color.brave_theme_color));
ForegroundColorSpan brOffForegroundSpan2 = new ForegroundColorSpan(getResources().getColor(R.color.brave_theme_color));
brOffTextSS.setSpan(brOffForegroundSpan, termsOfServiceIndex, termsOfServiceIndex + getResources().getString(R.string.terms_of_service).length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
brOffTextSS.setSpan(brOffForegroundSpan2, (brOffTextSS.length()-1) - getResources().getString(R.string.hide_sponsored_images).length() , brOffTextSS.length()-1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
bottomSheetText.setMovementMethod(LinkMovementMethod.getInstance());
bottomSheetText.setText(brOffTextSS);
break;
case SponsoredImageUtil.BR_ON_ADS_OFF:
bottomSheetTitleText.setText(getResources().getString(R.string.turn_on_brave_ads_to_claim));
turnOnAdsButton.setVisibility(View.VISIBLE);
String brOnAdsOffText = String.format( getResources().getString(R.string.br_on_ads_on_text2), getResources().getString(R.string.hide_sponsored_images));
Spanned brOnAdsOffSpanned = BraveRewardsHelper.spannedFromHtmlString(brOnAdsOffText);
SpannableString brOnAdsOffSS = new SpannableString(brOnAdsOffSpanned.toString());
ClickableSpan brOnAdsOffHideSponsoredImagesClickableSpan = new ClickableSpan() {
@Override
public void onClick(@NonNull View textView) {
hideSponsoredImages();
dismiss();
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
};
brOnAdsOffSS.setSpan(brOnAdsOffHideSponsoredImagesClickableSpan, (brOnAdsOffSS.length()-1) - getResources().getString(R.string.hide_sponsored_images).length() , brOnAdsOffSS.length()-1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ForegroundColorSpan brOnAdsOffForegroundSpan = new ForegroundColorSpan(getResources().getColor(R.color.brave_theme_color));
brOnAdsOffSS.setSpan(brOnAdsOffForegroundSpan, (brOnAdsOffSS.length()-1) - getResources().getString(R.string.hide_sponsored_images).length() , brOnAdsOffSS.length()-1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
bottomSheetText.setMovementMethod(LinkMovementMethod.getInstance());
bottomSheetText.setText(brOnAdsOffSS);
break;
case SponsoredImageUtil.BR_ON_ADS_ON:
bottomSheetTitleText.setText(getResources().getString(R.string.you_are_getting_paid));
String brOnAdsOnText = String.format(getResources().getString(R.string.br_on_ads_on_text), getResources().getString(R.string.learn_more), getResources().getString(R.string.hide_sponsored_images));
Spanned brOnAdsOnSpanned = BraveRewardsHelper.spannedFromHtmlString(brOnAdsOnText);
SpannableString brOnAdsOnSS = new SpannableString(brOnAdsOnSpanned.toString());
ClickableSpan learnMoreClickableSpan = new ClickableSpan() {
@Override
public void onClick(@NonNull View textView) {
NTPUtil.openUrlInSameTab(BRAVE_REWARDS_LEARN_MORE);
dismiss();
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
};
ClickableSpan brOnAdsOnHideSponsoredImagesClickableSpan = new ClickableSpan() {
@Override
public void onClick(@NonNull View textView) {
hideSponsoredImages();
dismiss();
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
};
brOnAdsOnSS.setSpan(learnMoreClickableSpan, 0, getResources().getString(R.string.learn_more).length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
brOnAdsOnSS.setSpan(brOnAdsOnHideSponsoredImagesClickableSpan, (brOnAdsOnSS.length()-1) - getResources().getString(R.string.hide_sponsored_images).length() , brOnAdsOnSS.length()-1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ForegroundColorSpan brOnAdsOnForegroundSpan = new ForegroundColorSpan(getResources().getColor(R.color.brave_theme_color));
ForegroundColorSpan brOnAdsOnForegroundSpan2 = new ForegroundColorSpan(getResources().getColor(R.color.brave_theme_color));
brOnAdsOnSS.setSpan(brOnAdsOnForegroundSpan, 0, getResources().getString(R.string.learn_more).length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
brOnAdsOnSS.setSpan(brOnAdsOnForegroundSpan2, (brOnAdsOnSS.length()-1) - getResources().getString(R.string.hide_sponsored_images).length() , brOnAdsOnSS.length()-1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
bottomSheetText.setMovementMethod(LinkMovementMethod.getInstance());
bottomSheetText.setText(brOnAdsOnSS);
break;
tosTextSS.setSpan(tosClickableSpan, termsOfServiceIndex, termsOfServiceIndex + getResources().getString(R.string.terms_of_service).length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ForegroundColorSpan brOffForegroundSpan = new ForegroundColorSpan(getResources().getColor(R.color.brave_theme_color));
tosTextSS.setSpan(brOffForegroundSpan, termsOfServiceIndex, termsOfServiceIndex + getResources().getString(R.string.terms_of_service).length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
bottomSheetTosText.setMovementMethod(LinkMovementMethod.getInstance());
bottomSheetTosText.setText(tosTextSS);
break;
case SponsoredImageUtil.BR_ON_ADS_ON:
bottomSheetTitleText.setText(getResources().getString(R.string.you_are_earning_tokens2));
break;
}
}
@@ -303,7 +221,7 @@ public class RewardsBottomSheetDialogFragment extends BottomSheetDialogFragment{
private void reloadTab() {
ChromeTabbedActivity chromeTabbedActivity = BraveRewardsHelper.getChromeTabbedActivity();
if(chromeTabbedActivity != null) {
if (chromeTabbedActivity != null) {
Tab currentTab = chromeTabbedActivity.getActivityTab();
SponsoredTab sponsoredTab = TabAttributes.from(currentTab).get(String.valueOf(((TabImpl)currentTab).getId()));
sponsoredTab.setNTPImage(SponsoredImageUtil.getBackgroundImage());
@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.ntp_background_images.util;
import android.os.Bundle;
import android.os.Build;
import android.support.annotation.NonNull;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -20,6 +21,12 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Button;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.TextPaint;
import android.os.Handler;
import android.net.Uri;
import java.io.IOException;
@@ -58,23 +65,23 @@ import org.chromium.chrome.browser.ntp_background_images.RewardsBottomSheetDialo
import static org.chromium.ui.base.ViewUtils.dpToPx;
public class NTPUtil {
private static final int BOTTOM_TOOLBAR_HEIGHT = 56;
private static final int BOTTOM_TOOLBAR_HEIGHT = 56;
private static final String REMOVED_SITES = "removed_sites";
public static HashMap<String,SoftReference<Bitmap>> imageCache =
new HashMap<String,SoftReference<Bitmap>>();
public static HashMap<String, SoftReference<Bitmap>> imageCache =
new HashMap<String, SoftReference<Bitmap>>();
public static void turnOnAds() {
BraveAdsNativeHelper.nativeSetAdsEnabled(Profile.getLastUsedProfile());
}
public static void updateOrientedUI(Context context, ViewGroup view) {
LinearLayout parentLayout= (LinearLayout)view.findViewById(R.id.parent_layout);
LinearLayout parentLayout = (LinearLayout)view.findViewById(R.id.parent_layout);
ViewGroup mainLayout = view.findViewById(R.id.ntp_main_layout);
ViewGroup imageCreditLayout = view.findViewById(R.id.image_credit_layout);
ImageView sponsoredLogo = (ImageView)view.findViewById(R.id.sponsored_logo);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(dpToPx(context,170), dpToPx(context,170));
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(dpToPx(context, 170), dpToPx(context, 170));
boolean isTablet = DeviceFormFactor.isNonMultiDisplayContextOnTablet(context);
@@ -89,7 +96,7 @@ public class NTPUtil {
parentLayout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams mainLayoutLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,0);
LinearLayout.LayoutParams mainLayoutLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0);
mainLayoutLayoutParams.weight = 1f;
mainLayout.setLayoutParams(mainLayoutLayoutParams);
@@ -113,7 +120,7 @@ public class NTPUtil {
imageCreditLayoutParams.weight = 0.4f;
imageCreditLayout.setLayoutParams(imageCreditLayoutParams);
layoutParams.setMargins(dpToPx(context,32), 0, 0, 0);
layoutParams.setMargins(dpToPx(context, 32), 0, 0, 0);
layoutParams.gravity = Gravity.BOTTOM | Gravity.START;
sponsoredLogo.setLayoutParams(layoutParams);
}
@@ -127,7 +134,7 @@ public class NTPUtil {
parentLayout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams mainLayoutLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,0);
LinearLayout.LayoutParams mainLayoutLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0);
mainLayoutLayoutParams.weight = 1f;
mainLayout.setLayoutParams(mainLayoutLayoutParams);
@@ -147,16 +154,16 @@ public class NTPUtil {
if (ntpImage instanceof Wallpaper) {
return SponsoredImageUtil.BR_ON_ADS_ON;
}
} else if(BraveAdsNativeHelper.nativeIsLocaleValid(Profile.getLastUsedProfile())) {
} else if (BraveAdsNativeHelper.nativeIsLocaleValid(Profile.getLastUsedProfile())) {
if (ntpImage instanceof Wallpaper) {
return SponsoredImageUtil.BR_ON_ADS_OFF ;
} else {
return SponsoredImageUtil.BR_ON_ADS_OFF_BG_IMAGE;
return SponsoredImageUtil.BR_INVALID_OPTION;
}
}
} else {
if (ntpImage instanceof Wallpaper && !mBraveRewardsNativeWorker.IsCreateWalletInProcess()) {
return SponsoredImageUtil.BR_OFF;
return SponsoredImageUtil.BR_INVALID_OPTION;
}
}
}
@@ -171,10 +178,10 @@ public class NTPUtil {
handler.postDelayed(new Runnable() {
@Override
public void run() {
BackgroundImagesPreferences.setOnPreferenceValue(BackgroundImagesPreferences.PREF_SHOW_NON_DISTRUPTIVE_BANNER,false);
BackgroundImagesPreferences.setOnPreferenceValue(BackgroundImagesPreferences.PREF_SHOW_NON_DISTRUPTIVE_BANNER, false);
boolean isTablet = DeviceFormFactor.isNonMultiDisplayContextOnTablet(chromeActivity);
if(isTablet || (!isTablet && ConfigurationUtils.isLandscape(chromeActivity))) {
if (isTablet || (!isTablet && ConfigurationUtils.isLandscape(chromeActivity))) {
FrameLayout.LayoutParams nonDistruptiveBannerLayoutParams = new FrameLayout.LayoutParams(dpToPx(chromeActivity, 400), FrameLayout.LayoutParams.WRAP_CONTENT);
nonDistruptiveBannerLayoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
nonDistruptiveBannerLayout.setLayoutParams(nonDistruptiveBannerLayoutParams);
@@ -187,7 +194,6 @@ public class NTPUtil {
TextView bannerHeader = nonDistruptiveBannerLayout.findViewById(R.id.ntp_banner_header);
TextView bannerText = nonDistruptiveBannerLayout.findViewById(R.id.ntp_banner_text);
TextView learnMoreText = nonDistruptiveBannerLayout.findViewById(R.id.ntp_banner_learn_more_text);
Button turnOnAdsButton = nonDistruptiveBannerLayout.findViewById(R.id.btn_turn_on_ads);
ImageView bannerClose = nonDistruptiveBannerLayout.findViewById(R.id.ntp_banner_close);
bannerClose.setOnClickListener(new View.OnClickListener() {
@@ -198,23 +204,6 @@ public class NTPUtil {
}
});
learnMoreText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
nonDistruptiveBannerLayout.setVisibility(View.GONE);
RewardsBottomSheetDialogFragment rewardsBottomSheetDialogFragment = RewardsBottomSheetDialogFragment.newInstance();
Bundle bundle = new Bundle();
bundle.putInt(SponsoredImageUtil.NTP_TYPE, ntpType);
rewardsBottomSheetDialogFragment.setArguments(bundle);
rewardsBottomSheetDialogFragment.setNewTabPageListener(newTabPageListener);
rewardsBottomSheetDialogFragment.show(chromeActivity.getSupportFragmentManager(), "rewards_bottom_sheet_dialog_fragment");
rewardsBottomSheetDialogFragment.setCancelable(false);
sponsoredTab.updateBannerPref();
}
});
turnOnAdsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -225,28 +214,69 @@ public class NTPUtil {
}
});
switch(ntpType) {
case SponsoredImageUtil.BR_OFF:
bannerText.setText(chromeActivity.getResources().getString(R.string.get_paid_to_see_image));
learnMoreText.setVisibility(View.VISIBLE);
break;
case SponsoredImageUtil.BR_ON_ADS_OFF:
bannerText.setText(chromeActivity.getResources().getString(R.string.get_paid_to_see_image));
learnMoreText.setVisibility(View.VISIBLE);
break;
case SponsoredImageUtil.BR_ON_ADS_OFF_BG_IMAGE:
bannerText.setText(chromeActivity.getResources().getString(R.string.you_can_support_creators));
turnOnAdsButton.setVisibility(View.VISIBLE);
break;
case SponsoredImageUtil.BR_ON_ADS_ON:
bannerText.setText(chromeActivity.getResources().getString(R.string.you_are_getting_paid));
learnMoreText.setVisibility(View.VISIBLE);
break;
switch (ntpType) {
case SponsoredImageUtil.BR_OFF:
bannerText.setText(chromeActivity.getResources().getString(R.string.get_paid_to_see_image));
break;
case SponsoredImageUtil.BR_ON_ADS_OFF:
bannerText.setMovementMethod(LinkMovementMethod.getInstance());
bannerText.setText(getBannerText(chromeActivity, ntpType, nonDistruptiveBannerLayout, sponsoredTab, newTabPageListener));
break;
case SponsoredImageUtil.BR_ON_ADS_OFF_BG_IMAGE:
bannerText.setText(chromeActivity.getResources().getString(R.string.you_can_support_creators));
turnOnAdsButton.setVisibility(View.VISIBLE);
break;
case SponsoredImageUtil.BR_ON_ADS_ON:
bannerText.setMovementMethod(LinkMovementMethod.getInstance());
bannerText.setText(getBannerText(chromeActivity, ntpType, nonDistruptiveBannerLayout, sponsoredTab, newTabPageListener));
break;
}
}
}, 1500);
}
private static SpannableString getBannerText(ChromeActivity chromeActivity, int ntpType,
View bannerLayout, SponsoredTab sponsoredTab, NewTabPageListener newTabPageListener) {
String bannerText = "";
if (ntpType == SponsoredImageUtil.BR_ON_ADS_ON) {
bannerText = String.format(chromeActivity.getResources().getString(R.string.you_are_earning_tokens),
chromeActivity.getResources().getString(R.string.learn_more));
} else if (ntpType == SponsoredImageUtil.BR_ON_ADS_OFF) {
bannerText = String.format(chromeActivity.getResources().getString(R.string.earn_tokens_for_viewing),
chromeActivity.getResources().getString(R.string.learn_more));
}
int learnMoreIndex = bannerText.indexOf(chromeActivity.getResources().getString(R.string.learn_more));
Spanned learnMoreSpanned = BraveRewardsHelper.spannedFromHtmlString(bannerText);
SpannableString learnMoreTextSS = new SpannableString(learnMoreSpanned.toString());
ClickableSpan learnMoreClickableSpan = new ClickableSpan() {
@Override
public void onClick(@NonNull View textView) {
bannerLayout.setVisibility(View.GONE);
RewardsBottomSheetDialogFragment rewardsBottomSheetDialogFragment = RewardsBottomSheetDialogFragment.newInstance();
Bundle bundle = new Bundle();
bundle.putInt(SponsoredImageUtil.NTP_TYPE, ntpType);
rewardsBottomSheetDialogFragment.setArguments(bundle);
rewardsBottomSheetDialogFragment.setNewTabPageListener(newTabPageListener);
rewardsBottomSheetDialogFragment.show(chromeActivity.getSupportFragmentManager(), "rewards_bottom_sheet_dialog_fragment");
rewardsBottomSheetDialogFragment.setCancelable(false);
sponsoredTab.updateBannerPref();
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
};
learnMoreTextSS.setSpan(learnMoreClickableSpan, learnMoreIndex, learnMoreIndex + chromeActivity.getResources().getString(R.string.learn_more).length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ForegroundColorSpan brOffForegroundSpan = new ForegroundColorSpan(chromeActivity.getResources().getColor(R.color.brave_theme_color));
learnMoreTextSS.setSpan(brOffForegroundSpan, learnMoreIndex, learnMoreIndex + chromeActivity.getResources().getString(R.string.learn_more).length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return learnMoreTextSS;
}
public static Bitmap getWallpaperBitmap(NTPImage ntpImage, int layoutWidth, int layoutHeight) {
Context mContext = ContextUtils.getApplicationContext();
@@ -263,24 +293,24 @@ public class NTPUtil {
Wallpaper mWallpaper = (Wallpaper) ntpImage;
InputStream inputStream = null;
try {
Uri imageFileUri = Uri.parse("file://"+mWallpaper.getImagePath());
Uri imageFileUri = Uri.parse("file://" + mWallpaper.getImagePath());
inputStream = mContext.getContentResolver().openInputStream(imageFileUri);
imageBitmap = BitmapFactory.decodeStream(inputStream, null, options);
inputStream.close();
} catch(IOException exc) {
} catch (IOException exc) {
Log.e("NTP", exc.getMessage());
} finally {
try {
if (inputStream != null) {
inputStream.close();
try {
if (inputStream != null) {
inputStream.close();
}
} catch (IOException exception) {
Log.e("NTP", exception.getMessage());
return null;
}
} catch (IOException exception) {
Log.e("NTP", exception.getMessage());
return null;
}
}
centerPointX = mWallpaper.getFocalPointX() == 0 ? (imageBitmap.getWidth()/2) : mWallpaper.getFocalPointX();
centerPointY = mWallpaper.getFocalPointY() == 0 ? (imageBitmap.getHeight()/2) : mWallpaper.getFocalPointY();
centerPointX = mWallpaper.getFocalPointX() == 0 ? (imageBitmap.getWidth() / 2) : mWallpaper.getFocalPointX();
centerPointY = mWallpaper.getFocalPointY() == 0 ? (imageBitmap.getHeight() / 2) : mWallpaper.getFocalPointY();
} else {
BackgroundImage mBackgroundImage = (BackgroundImage) ntpImage;
imageBitmap = BitmapFactory.decodeResource(mContext.getResources(), mBackgroundImage.getImageDrawable(), options);
@@ -320,7 +350,7 @@ public class NTPUtil {
startX = newImageWidth - layoutWidth;
}
int startY = (newImageHeight - layoutHeight)/2;
int startY = (newImageHeight - layoutHeight) / 2;
if (centerPointY > 0) {
float centerRatioY = centerPointY / imageHeight;
newImageWidth = layoutWidth;
@@ -358,11 +388,11 @@ public class NTPUtil {
InputStream inputStream = null;
Bitmap topSiteIcon = null;
try {
Uri imageFileUri = Uri.parse("file://"+ iconPath);
Uri imageFileUri = Uri.parse("file://" + iconPath);
inputStream = mContext.getContentResolver().openInputStream(imageFileUri);
topSiteIcon = BitmapFactory.decodeStream(inputStream);
inputStream.close();
} catch(IOException exc) {
} catch (IOException exc) {
Log.e("NTP", exc.getMessage());
topSiteIcon = null;
} finally {
@@ -396,7 +426,7 @@ public class NTPUtil {
if (!urlSet.contains(url)) {
urlSet.add(url);
}
SharedPreferences mSharedPreferences = ContextUtils.getAppSharedPreferences();
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
sharedPreferencesEditor.putStringSet(REMOVED_SITES, urlSet);
@@ -404,20 +434,20 @@ public class NTPUtil {
}
public static boolean shouldEnableNTPFeature(boolean isMoreTabs) {
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.M
|| (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !isMoreTabs)) {
return true;
}
return false;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M
|| (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !isMoreTabs)) {
return true;
}
return false;
}
public static NTPImage getNTPImage(NTPBackgroundImagesBridge mNTPBackgroundImagesBridge) {
Wallpaper mWallpaper = mNTPBackgroundImagesBridge.getCurrentWallpaper();
if (mWallpaper != null) {
return mWallpaper;
} else {
return SponsoredImageUtil.getBackgroundImage();
}
Wallpaper mWallpaper = mNTPBackgroundImagesBridge.getCurrentWallpaper();
if (mWallpaper != null) {
return mWallpaper;
} else {
return SponsoredImageUtil.getBackgroundImage();
}
}
public static boolean isReferralEnabled() {
@@ -429,14 +459,14 @@ public class NTPUtil {
public static void openNewTab(boolean isIncognito, String url) {
ChromeTabbedActivity chromeTabbedActivity = BraveRewardsHelper.getChromeTabbedActivity();
if(chromeTabbedActivity != null) {
if (chromeTabbedActivity != null) {
chromeTabbedActivity.getTabCreator(isIncognito).launchUrl(url, TabLaunchType.FROM_CHROME_UI);
}
}
public static void openUrlInSameTab(String url) {
ChromeTabbedActivity chromeTabbedActivity = BraveRewardsHelper.getChromeTabbedActivity();
if(chromeTabbedActivity != null) {
if (chromeTabbedActivity != null) {
LoadUrlParams loadUrlParams = new LoadUrlParams(url);
chromeTabbedActivity.getActivityTab().loadUrl(loadUrlParams);
}
+86 -46
View File
@@ -9,11 +9,10 @@
android:id="@+id/ntp_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="400dp"
android:padding="16dp">
android:maxWidth="400dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@@ -25,7 +24,7 @@
android:drawableStart="@drawable/btn_bat"
android:drawablePadding="8dp"
android:textSize="20sp"
android:layout_marginBottom="16dp"
android:layout_margin="16dp"
android:textColor="@android:color/black"
android:text="@string/brave_ui_brave_rewards"/>
@@ -35,63 +34,103 @@
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="16sp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:textColor="@android:color/black"
android:layout_marginBottom="16dp"/>
<Button
android:id="@+id/btn_turn_on_ads"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:background="@drawable/blue_rounded_button"
android:text="@string/im_ready_to_earn"
android:textAllCaps="false"
android:textSize="16sp"
android:padding="8dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:textColor="@android:color/white"
android:visibility="gone"
style="?android:attr/borderlessButtonStyle"/>
<TextView
android:id="@+id/ntp_bottom_sheet_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="@android:color/black"
android:text="@string/sponsored_images_bottom_sheet_text"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"/>
<Button
android:id="@+id/btn_turn_on_ads"
<TextView
android:id="@+id/ntp_bottom_sheet_tos_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_vertical"
android:background="@drawable/blue_rounded_button"
android:layout_marginBottom="8dp"
android:text="@string/turn_on_brave_ads"
android:textAllCaps="false"
android:textSize="16sp"
android:padding="8dp"
android:drawableStart="@drawable/coins"
android:drawablePadding="8dp"
android:textColor="@android:color/white"
android:visibility="gone"
style="?android:attr/borderlessButtonStyle"/>
<Button
android:id="@+id/btn_turn_on_rewards"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_vertical"
android:background="@drawable/blue_rounded_button"
android:layout_marginBottom="4dp"
android:text="@string/turn_on_rewards"
android:textAllCaps="false"
android:textSize="16sp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:textColor="@android:color/white"
android:visibility="gone"
style="?android:attr/borderlessButtonStyle"/>
<Button
android:id="@+id/btn_learn_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@android:color/transparent"
android:text="@string/learn_more"
android:textAllCaps="false"
android:textSize="12sp"
android:visibility="gone"
android:textColor="@android:color/black"
android:textSize="16sp"/>
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:alpha="0.5"
android:background="@color/section_divider_color"/>
<TextView
android:id="@+id/learn_more_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_gravity="center_vertical"
android:text="@string/learn_more_about_sponsored_images"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:alpha="0.5"
android:background="@color/section_divider_color"/>
<TextView
android:id="@+id/hide_sponsored_images_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_gravity="center_vertical"
android:text="@string/hide_sponsored_images"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:alpha="0.5"
android:background="@color/section_divider_color"/>
</LinearLayout>
</LinearLayout>
@@ -99,6 +138,7 @@
android:id="@+id/ntp_bottom_sheet_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:contentDescription="@null"
android:layout_gravity="end|top"
android:src="@drawable/btn_close"/>
@@ -47,16 +47,6 @@
android:textSize="14sp"
android:textColor="@android:color/white"/>
<TextView
android:id="@+id/ntp_banner_learn_more_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:layout_marginBottom="8dp"
android:text="@string/learn_more"
android:textColor="@color/brave_theme_color"
android:visibility="gone"/>
<Button
android:id="@+id/btn_turn_on_ads"
android:layout_width="wrap_content"
+1
View File
@@ -76,4 +76,5 @@
<color name="user_wallet_dimmed_note">#E6E3F4</color>
<color name="qr_button_color">@android:color/white</color>
<color name="section_divider_color">#c8c7cc</color>
</resources>
@@ -888,20 +888,11 @@ until they verify, or until 90 days have passed.
<message name="IDS_PHOTO_BY" desc="Text for image credit for background images on NTP">
Photo by <ph name="PHOTO_BY">%1$s</ph>
</message>
<message name="IDS_GET_PAID_TO_SEE_ADS">
Get paid to see this background image.
</message>
<message name="IDS_NTP_BRAVE_REWARDS_OFF_TEXT" desc="Text on NTP banner when brave rewrads is off ">
You&apos;ll receive 70% of the ad revenue for this private sponsorship which can be used to support web content creators. Turn on Brave Rewards to claim your share.
</message>
<message name="IDS_TURN_ON_REWARDS" desc="Text for turn on rewards button">
Turn on Rewards
</message>
<message name="IDS_TURN_ON_BRAVE_ADS" desc="Text for turn on brave ads button">
Turn on Brave Ads
</message>
<message name="IDS_NTP_TOS_TEXT" desc="Text for term of service on NTP">
By turning on Rewards, you agree to the <ph name="TERMS_OF_SERVICE">%1$s</ph>. You can also choose to <ph name="HIDE_SPONSORED_IMAGES">%2$s</ph>.
By tapping Earn &amp; Give, you agree to the <ph name="TERMS_OF_SERVICE">%1$s</ph>.
</message>
<message name="IDS_GET_PAID_TO_SEE_IMAGE" desc="Text description for NTP banner.">
Get paid to see this background image.
@@ -912,18 +903,6 @@ until they verify, or until 90 days have passed.
<message name="IDS_YOU_CAN_SUPPORT_CREATORS" desc="Text description for banner on NTP.">
You can support web creators with tokens.\nEarn tokens by viewing privacy-respecting ads.
</message>
<message name="IDS_YOU_ARE_GETTING_PAID" desc="Text title for NTP banner.">
Youre getting paid to see this background image.
</message>
<message name="IDS_BR_ON_ADS_ON_TEXT" desc="Text description for NTP banner.">
<ph name="LEARN_MORE">%1$s</ph> about sponsored images in Brave Rewards. You can also choose to <ph name="HIDE_SPONSORED_IMAGES">%2$s</ph>.
</message>
<message name="IDS_BR_ON_ADS_ON_TEXT2" desc="Text description for NTP banner.">
You can also choose to <ph name="HIDE_SPONSORED_IMAGES">%1$s</ph>.
</message>
<message name="IDS_TURN_ON_BRAVE_ADS_TO_CLAIM" desc="Text description for NTP banner.">
Get paid to see this background image. Turn on Brave Ads to claim your share.
</message>
<message name="IDS_PREFS_USE_CUSTOM_TABS" desc="Title for closing all tabs closes brave in controls section">
Open tabs in Custom Tabs
</message>
@@ -1020,9 +999,6 @@ until they verify, or until 90 days have passed.
<message name="IDS_BRAVE_DEFAULT" desc="Text for brave default settings option.">
Brave Default
</message>
<message name="IDS_SHARE_BRAVE_WITH_YOUR_FRIENDS" desc="Title text for share dialog.">
Share Brave with your friends!
</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_GENERAL_GRANT_ERROR_TITLE" desc="">
Oops, something is wrong. Please try again later.
</message>
@@ -1053,6 +1029,27 @@ until they verify, or until 90 days have passed.
<message name="IDS_RATE_FEEDBACK_HINT" desc="Text for rate feedback hint.">
Let us know know how we can improve
</message>
<message name="IDS_EARN_TOKENS_FOR_VIEWING" desc="Text for brave rewards banner.">
Earn tokens for viewing this image and pay it forward to creators. <ph name="LEARN_MORE">%1$s</ph>
</message>
<message name="IDS_EARN_TOKENS_FOR_VIEWING_TITLE" desc="Title for brave rewards banner.">
Earn tokens for viewing this image. Turn on Earn &amp; Give to claim your share.
</message>
<message name="IDS_YOU_ARE_EARNING_TOKENS" desc="Title for brave rewards banner.">
You're earning tokens for viewing this image.\n<ph name="LEARN_MORE">%1$s</ph>
</message>
<message name="IDS_YOU_ARE_EARNING_TOKENS2" desc="Title for brave rewards banner.">
You're earning tokens for viewing this image.
</message>
<message name="IDS_IM_READY_TO_EARN" desc="Title for brave rewards bottom sheet action.">
I'm ready to Earn &amp; Give
</message>
<message name="IDS_LEARN_MORE_ABOUT_SPONSORED_IMAGES" desc="Title for brave rewards bottom sheet.">
Learn more about sponsored images
</message>
<message name="IDS_SPONSORED_IMAGES_BOTTOM_SHEET_TEXT" desc="Text for SI bottom sheet.">
For every sponsored image you view, you receive 70% of the revenue in tokens. With Brave Ads, you're always in control of the ads you see.
</message>
</messages>
</release>
</grit>