-
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 all 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 |
---|---|---|
|
@@ -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_SPACE_BETWEEN_LINES; | ||
import static com.taboola.sdk4example.MetaConst.ELEMENT_TYPE_BRANDING; | ||
import static com.taboola.sdk4example.MetaConst.NUMBER_OF_LINES; | ||
import static com.taboola.sdk4example.MetaConst.TEXT_FONT_SIZE; | ||
import static com.taboola.sdk4example.MetaConst.TYPEFACE_ARIAL_BOLD; | ||
import static com.taboola.sdk4example.utils.Utils.loadFont; | ||
|
||
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.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(), 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_SPACE_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() | ||
// // Sets the visibility of the call-to-action (CTA) button. | ||
// // The button is visible by default. Pass true to this method to hide it. | ||
// .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_SPACE_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.NUMBER_OF_LINES; | ||
import static com.taboola.sdk4example.MetaConst.TEXT_FONT_SIZE; | ||
import static com.taboola.sdk4example.MetaConst.TYPEFACE_ARIAL_BOLD; | ||
import static com.taboola.sdk4example.utils.Utils.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(), 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_SPACE_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(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.taboola.sdk4example.utils; | ||
|
||
import android.content.res.AssetManager; | ||
import android.graphics.Typeface; | ||
|
||
import androidx.fragment.app.FragmentActivity; | ||
|
||
public class Utils { | ||
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); | ||
} | ||
} |
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