-
Notifications
You must be signed in to change notification settings - Fork 0
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
MOB-3869-Add a sample screen to example app of API customization #6
base: MOB-3712-example_app_for_meta_integration
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,11 @@ public class MetaConst { | |
public static final String DEFAULT_LAYOUT_KEY = "default"; | ||
public static final String TEST_LAYOUT_IMAGE_LINK_TYPE = "image_link"; | ||
public static final String TEST_LAYOUT_CAROUSEL_TYPE = "carousel"; | ||
// UI customization | ||
public static final String ELEMENT_TYPE_BRANDING = "branding"; | ||
public static final String DARK_NODE = "darkMode"; | ||
public static final String FONT_TYPEFACE_ARIAL_BOLD = "arial_bold"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DanielFrTB - No need to write typeface and font. Choose one and stick to it. |
||
public static final int TEXT_FONT_SIZE = 20; | ||
public static final int NUMBER_OF_LINES = 2; | ||
public static final float AMOUNT_OF_LINES_BETWEEN_LINES = 0.5f; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DanielFrTB - I think the name of this constant is wrong, |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.taboola.sdk4example; | ||
|
||
import android.content.res.AssetManager; | ||
import android.graphics.Typeface; | ||
|
||
import androidx.fragment.app.FragmentActivity; | ||
|
||
public class MetaUtils { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DanielFrTB - There is no logic that is specific to Meta here. Consider renaming. Maybe there is another already present utility class that you can add this method to. |
||
private static final String FONTS_PATH = "fonts/"; | ||
private static final String FONT_SUFFIX = ".ttf"; | ||
|
||
public static Typeface loadFont(FragmentActivity activity, String fontName) { | ||
AssetManager assets = activity.getAssets(); | ||
return Typeface.createFromAsset(assets, FONTS_PATH + fontName + FONT_SUFFIX); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,9 @@ | |
import com.taboola.sdk4example.sdk_classic.FeedWithMiddleArticleInsideScrollViewFragment; | ||
import com.taboola.sdk4example.sdk_classic.MetaAdCarouselFragment; | ||
import com.taboola.sdk4example.sdk_classic.MetaAdInsideScrollViewFragment; | ||
import com.taboola.sdk4example.sdk_classic.MetaAdUICustomization; | ||
import com.taboola.sdk4example.sdk_classic.MetaClassicUnitFragment; | ||
import com.taboola.sdk4example.sdk_classic.MetaClassicUnitFragmentUICustomization; | ||
import com.taboola.sdk4example.sdk_classic.OCClickHandlerFragment; | ||
import com.taboola.sdk4example.sdk_classic.PullToRefreshFragment; | ||
import com.taboola.sdk4example.sdk_classic.RecyclerViewPreloadFragment; | ||
|
@@ -68,6 +70,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat | |
addButton(getString(R.string.std_feed_lazy_loading_rv), R.id.std_feed_lazy_loading_rv, viewGroup); | ||
addButton(getString(R.string.std_mid_article_with_feed_dark_mode_rv), R.id.std_mid_article_with_feed_dark_mode_rv, viewGroup); | ||
addButton(getString(R.string.std_meta), R.id.std_meta_ad, viewGroup); | ||
addButton(getString(R.string.std_meta_ad_UI_customization), R.id.std_meta_ad_UI_customization, viewGroup); | ||
addButton(getString(R.string.std_meta_tbl_classic_unit_ad_UI_customization), R.id.std_meta_tbl_classic_unit_ad_UI_customization, viewGroup); | ||
addButton(getString(R.string.std_meta_classic_unit), R.id.std_meta_classic_unit, viewGroup); | ||
addButton(getString(R.string.std_meta_carousel), R.id.std_meta_carousel, viewGroup); | ||
} | ||
|
@@ -115,6 +119,12 @@ public void onClick(View v) { | |
case R.id.std_meta_classic_unit: | ||
fragmentToOpen = new MetaClassicUnitFragment(); | ||
break; | ||
case R.id.std_meta_ad_UI_customization: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DanielFrTB - What is the difference between these two screens? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tomer-br-taboola |
||
fragmentToOpen = new MetaAdUICustomization(); | ||
break; | ||
case R.id.std_meta_tbl_classic_unit_ad_UI_customization: | ||
fragmentToOpen = new MetaClassicUnitFragmentUICustomization(); | ||
break; | ||
case R.id.std_meta_carousel: | ||
fragmentToOpen = new MetaAdCarouselFragment(); | ||
break; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package com.taboola.sdk4example.sdk_classic; | ||
|
||
import static com.taboola.sdk4example.Const.META_WIDGET_MODE; | ||
import static com.taboola.sdk4example.Const.META_WIDGET_PLACEMENT_NAME; | ||
import static com.taboola.sdk4example.MetaConst.AMOUNT_OF_LINES_BETWEEN_LINES; | ||
import static com.taboola.sdk4example.MetaConst.ELEMENT_TYPE_BRANDING; | ||
import static com.taboola.sdk4example.MetaConst.FONT_TYPEFACE_ARIAL_BOLD; | ||
import static com.taboola.sdk4example.MetaConst.NUMBER_OF_LINES; | ||
import static com.taboola.sdk4example.MetaConst.TEXT_FONT_SIZE; | ||
import static com.taboola.sdk4example.MetaUtils.loadFont; | ||
|
||
import android.content.res.AssetManager; | ||
import android.graphics.Color; | ||
import android.graphics.Typeface; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import androidx.annotation.Nullable; | ||
import androidx.fragment.app.FragmentActivity; | ||
|
||
import com.facebook.ads.NativeAdLayout; | ||
import com.taboola.android.TBLClassicPage; | ||
import com.taboola.android.TBLClassicUnit; | ||
import com.taboola.android.TBLPublisherInfo; | ||
import com.taboola.android.Taboola; | ||
import com.taboola.android.annotations.TBL_PLACEMENT_TYPE; | ||
import com.taboola.android.listeners.TBLClassicListener; | ||
|
||
import com.taboola.android.utils.style_properties.TBLTitleStylePropertiesBuilder; | ||
import com.taboola.android.utils.style_properties.TBLUiStyleProperties; | ||
import com.taboola.android.utils.style_properties.TBLCallToActionButtonStylePropertiesBuilder; | ||
import com.taboola.sdk4example.Const; | ||
import com.taboola.sdk4example.MetaConst; | ||
import com.taboola.sdk4example.R; | ||
import com.taboola.sdk4example.tabs.BaseTaboolaFragment; | ||
import com.taboola.android.utils.style_properties.TBLTextStylePropertiesBuilder; | ||
|
||
import java.util.HashMap; | ||
|
||
public class MetaAdUICustomization extends BaseTaboolaFragment { | ||
|
||
|
||
private static final String TAG = MetaAdUICustomization.class.getSimpleName(); | ||
|
||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, | ||
@Nullable ViewGroup container, | ||
@Nullable Bundle savedInstanceState) { | ||
Taboola.init(new TBLPublisherInfo(MetaConst.META_PUBLISHER_NAME)); | ||
View rootView = inflater.inflate(R.layout.fragment_meta_ad_classic_unit, null); | ||
NativeAdLayout adContainerTop = rootView.findViewById(R.id.native_ad_container_top); | ||
|
||
Taboola.setGlobalExtraProperties(new HashMap<String, String>() {{ | ||
put(MetaConst.AUDIENCE_NETWORK_APPLICATION_ID_KEY, MetaConst.AUDIENCE_NETWORK_APP_ID); | ||
put(MetaConst.ENABLE_META_DEMAND_DEBUG_KEY, "true"); | ||
}}); | ||
|
||
setupAndLoadTaboolaAd(adContainerTop); | ||
return rootView; | ||
} | ||
|
||
|
||
private void setupAndLoadTaboolaAd(NativeAdLayout adContainer) { | ||
TBLClassicPage tblClassicPage = Taboola.getClassicPage(Const.PAGE_URL, Const.PAGE_TYPE); | ||
TBLClassicUnit tblClassicUnit = tblClassicPage.build(getContext(), META_WIDGET_PLACEMENT_NAME, META_WIDGET_MODE, TBL_PLACEMENT_TYPE.PAGE_MIDDLE, new TBLClassicListener() { | ||
@Override | ||
public boolean onItemClick(String placementName, String itemId, String clickUrl, boolean isOrganic, String customData) { | ||
Log.d(TAG, "onItemClick"); | ||
return super.onItemClick(placementName, itemId, clickUrl, isOrganic, customData); | ||
} | ||
|
||
@Override | ||
public void onAdReceiveSuccess() { | ||
super.onAdReceiveSuccess(); | ||
Log.d(TAG, "onAdReceiveSuccess"); | ||
} | ||
|
||
@Override | ||
public void onAdReceiveFail(String error) { | ||
super.onAdReceiveFail(error); | ||
Log.d(TAG, "onAdReceiveFail " + error); | ||
} | ||
}); | ||
tblClassicUnit.setUnitExtraProperties(new HashMap<String, String>() {{ | ||
put(MetaConst.AUDIENCE_NETWORK_PLACEMENT_ID_KEY, MetaConst.AUDIENCE_NETWORK_PLACEMENT_ID); | ||
}}); | ||
Typeface font = loadFont(getActivity(), FONT_TYPEFACE_ARIAL_BOLD); | ||
|
||
// Create custom style properties for the branding | ||
TBLUiStyleProperties brandingStyleProperties = new TBLTextStylePropertiesBuilder(ELEMENT_TYPE_BRANDING) | ||
DanielFrTB marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.setFontLightColor(R.color.design_default_color_error) | ||
.setFontDarkColor(R.color.colorPrimary) | ||
.setFontSize(TEXT_FONT_SIZE) | ||
.setTypeface(font) | ||
.build(); | ||
|
||
// Create custom style properties for the title | ||
TBLUiStyleProperties titleStyleProperties = new TBLTitleStylePropertiesBuilder() | ||
.setAmountOfSpaceBetweenLines(AMOUNT_OF_LINES_BETWEEN_LINES) | ||
.setLines(NUMBER_OF_LINES) | ||
.setFontLightColor(Color.RED) | ||
.setFontSize(TEXT_FONT_SIZE) | ||
.setFontDarkColor(Color.BLUE) | ||
.setTypeface(font) | ||
.build(); | ||
|
||
// Create custom style properties for the call to action button | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DanielFrTB - Why is this code commented out? As mentioned in my previous comment, show the option to publisher that is NOT the default (meaning, hide the CTA). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tomer-br-taboola |
||
TBLUiStyleProperties ctaStyleProperties = new TBLCallToActionButtonStylePropertiesBuilder() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DanielFrTB - Since the default setting for the CTA button is to be visible, what is the point of showing this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tomer-br-taboola I can remove if needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DanielFrTB - If you want to display all the APIs we have, choose an option that shows to publishers how it works. This way, publishers might think they need to do this (even though they don't since the default is to show the CTA button). |
||
// Set the visibility of the call to action, the CTA button will be displayed by default if | ||
// you want to hide it you need to pass true to the setVisibility method | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DanielFrTB - Please re-read the comment here. It is misleading. |
||
.setVisibility(true) | ||
.build(); | ||
|
||
// Set the custom UI properties to the Meta native Ad | ||
tblClassicUnit.setNativeUI(MetaConst.DEFAULT_LAYOUT_KEY, brandingStyleProperties, titleStyleProperties, ctaStyleProperties); | ||
adContainer.addView(tblClassicUnit); | ||
tblClassicUnit.fetchContent(); | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package com.taboola.sdk4example.sdk_classic; | ||
|
||
import static com.taboola.sdk4example.Const.META_FEED_MODE; | ||
import static com.taboola.sdk4example.Const.META_FEED_PLACEMENT_NAME; | ||
import static com.taboola.sdk4example.Const.META_WIDGET_MODE; | ||
import static com.taboola.sdk4example.Const.META_WIDGET_PLACEMENT_NAME; | ||
import static com.taboola.sdk4example.MetaConst.AMOUNT_OF_LINES_BETWEEN_LINES; | ||
import static com.taboola.sdk4example.MetaConst.DARK_NODE; | ||
import static com.taboola.sdk4example.MetaConst.ELEMENT_TYPE_BRANDING; | ||
import static com.taboola.sdk4example.MetaConst.FONT_TYPEFACE_ARIAL_BOLD; | ||
import static com.taboola.sdk4example.MetaConst.NUMBER_OF_LINES; | ||
import static com.taboola.sdk4example.MetaConst.TEXT_FONT_SIZE; | ||
import static com.taboola.sdk4example.MetaUtils.loadFont; | ||
|
||
import android.content.res.Configuration; | ||
import android.graphics.Color; | ||
import android.graphics.Typeface; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import com.facebook.ads.NativeAdLayout; | ||
import com.taboola.android.MetaPlacementProperties; | ||
import com.taboola.android.TBLClassicPage; | ||
import com.taboola.android.TBLMetaClassicUnit; | ||
import com.taboola.android.TBLPublisherInfo; | ||
import com.taboola.android.Taboola; | ||
import com.taboola.android.annotations.TBL_PLACEMENT_TYPE; | ||
import com.taboola.android.listeners.TBLClassicListener; | ||
import com.taboola.android.utils.style_properties.TBLCallToActionButtonStylePropertiesBuilder; | ||
import com.taboola.android.utils.style_properties.TBLTextStylePropertiesBuilder; | ||
import com.taboola.android.utils.style_properties.TBLTitleStylePropertiesBuilder; | ||
import com.taboola.android.utils.style_properties.TBLUiStyleProperties; | ||
import com.taboola.sdk4example.Const; | ||
import com.taboola.sdk4example.MetaConst; | ||
import com.taboola.sdk4example.R; | ||
import com.taboola.sdk4example.tabs.BaseTaboolaFragment; | ||
|
||
import java.util.HashMap; | ||
|
||
public class MetaClassicUnitFragmentUICustomization extends BaseTaboolaFragment { | ||
|
||
private static final String TAG = MetaClassicUnitFragmentUICustomization.class.getSimpleName(); | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, | ||
@Nullable ViewGroup container, | ||
@Nullable Bundle savedInstanceState) { | ||
int isOSDarkMode = | ||
getContext().getResources().getConfiguration().uiMode & | ||
Configuration.UI_MODE_NIGHT_MASK; | ||
Taboola.init(new TBLPublisherInfo(MetaConst.META_PUBLISHER_NAME)); | ||
View rootView = inflater.inflate(R.layout.fragment_meta_ad_classic_unit, null); | ||
NativeAdLayout adContainerTop = rootView.findViewById(R.id.native_ad_container_top); | ||
|
||
Taboola.setGlobalExtraProperties(new HashMap<String, String>() {{ | ||
put(MetaConst.AUDIENCE_NETWORK_APPLICATION_ID_KEY, MetaConst.AUDIENCE_NETWORK_APP_ID); | ||
put(MetaConst.ENABLE_META_DEMAND_DEBUG_KEY, "true"); | ||
if (isOSDarkMode == Configuration.UI_MODE_NIGHT_YES) { | ||
put(DARK_NODE, "true"); | ||
} | ||
}}); | ||
|
||
setupAndLoadTaboolaAd(adContainerTop); | ||
return rootView; | ||
} | ||
|
||
|
||
private void setupAndLoadTaboolaAd(NativeAdLayout adContainer) { | ||
TBLClassicPage tblClassicPage = Taboola.getClassicPage(Const.PAGE_URL, Const.PAGE_TYPE); | ||
MetaPlacementProperties metaPlacementProperties = new MetaPlacementProperties(META_WIDGET_PLACEMENT_NAME, META_WIDGET_MODE); | ||
TBLMetaClassicUnit tblMetaClassicUnit = tblClassicPage.buildWithMeta(getContext(), META_FEED_PLACEMENT_NAME, META_FEED_MODE, TBL_PLACEMENT_TYPE.PAGE_MIDDLE, metaPlacementProperties, new TBLClassicListener() { | ||
@Override | ||
public boolean onItemClick(String placementName, String itemId, String clickUrl, boolean isOrganic, String customData) { | ||
Log.d(TAG, "onItemClick"); | ||
return super.onItemClick(placementName, itemId, clickUrl, isOrganic, customData); | ||
} | ||
|
||
@Override | ||
public void onAdReceiveSuccess() { | ||
super.onAdReceiveSuccess(); | ||
Log.d(TAG, "onAdReceiveSuccess"); | ||
} | ||
|
||
@Override | ||
public void onAdReceiveFail(String error) { | ||
super.onAdReceiveFail(error); | ||
Log.d(TAG, "onAdReceiveFail " + error); | ||
} | ||
|
||
@Override | ||
public void onResize(int height) { | ||
super.onResize(height); | ||
Log.d(TAG, "onResize"); | ||
} | ||
}); | ||
tblMetaClassicUnit.setMetaAdTypeForDebug(MetaConst.TEST_LAYOUT_IMAGE_LINK_TYPE); | ||
tblMetaClassicUnit.setUnitExtraProperties(new HashMap<String, String>() {{ | ||
put(MetaConst.AUDIENCE_NETWORK_PLACEMENT_ID_KEY, MetaConst.AUDIENCE_NETWORK_PLACEMENT_ID); | ||
}}); | ||
|
||
Typeface font = loadFont(getActivity(), FONT_TYPEFACE_ARIAL_BOLD); | ||
|
||
// Create custom style properties for the branding | ||
TBLUiStyleProperties brandingStyleProperties = new TBLTextStylePropertiesBuilder(ELEMENT_TYPE_BRANDING) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DanielFrTB - Comments from the previous screen also apply here. |
||
.setFontLightColor(R.color.design_default_color_error) | ||
.setFontDarkColor(R.color.colorPrimary) | ||
.setFontSize(TEXT_FONT_SIZE) | ||
.setTypeface(font) | ||
.build(); | ||
|
||
// Create custom style properties for the title | ||
TBLUiStyleProperties titleStyleProperties = new TBLTitleStylePropertiesBuilder() | ||
.setAmountOfSpaceBetweenLines(AMOUNT_OF_LINES_BETWEEN_LINES) | ||
.setLines(NUMBER_OF_LINES) | ||
.setFontLightColor(Color.RED) | ||
.setFontSize(TEXT_FONT_SIZE) | ||
.setFontDarkColor(Color.BLUE) | ||
.setTypeface(font) | ||
.build(); | ||
|
||
// Create custom style properties for the call to action button | ||
TBLUiStyleProperties ctaStyleProperties = new TBLCallToActionButtonStylePropertiesBuilder() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DanielFrTB - Here you didn't apply any changes. |
||
// Set the visibility of the call to action, the CTA button will be displayed by default if | ||
// you want to hide it you need to pass true to the setVisibility method | ||
.setVisibility(true) | ||
.build(); | ||
|
||
// Set the custom UI properties to the Meta native Ad | ||
tblMetaClassicUnit.setMetaNativeUI(MetaConst.DEFAULT_LAYOUT_KEY, brandingStyleProperties, titleStyleProperties, ctaStyleProperties); | ||
adContainer.addView(tblMetaClassicUnit); | ||
tblMetaClassicUnit.fetchContent(); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanielFrTB - Why is the dark mode key part of the UI Customizations here and not in the Kotlin part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tomer-br-taboola aligned