Product-Specific Rendering
GFP SDK provides product-specific values that allow you to render ads in more diverse and sophisticated forms for specific products provided as native ads. These product-specific values include additional text, images, style information, etc., beyond the basic assets (title, body, advertiserName, etc.), making the visual representation of ads richer.
Product-specific values can be received through the GFP manager and are not required. Therefore, ads will display normally even if they are not provided, and there is no disadvantage if you do not apply them. However, if you implement product-specific rendering by referring to this guide, please be sure to receive guidance from the GFP manager on the types of specific values provided for that product and how to use them.
Additional Text and Image Assets
In addition to commonly used assets (title, body, advertiserName, etc.), there may be additional assets provided separately depending on the product.
Product-specific additional assets are not required, so ads will display normally even if they are not provided. There is no disadvantage if you do not apply them, and you can optionally apply them only when needed.
How to register additional text and image assets provided by product.
- extraText: Retrieve text assets through the GfpNativeAd.getExtraText() method, then register them using the GfpNativeAdView.setExtraTextView() method along with the corresponding key.
- extraImage: Retrieve image assets through the GfpNativeAd.getExtraImage() method, then register them using the GfpNativeAdView.setExtraImageView() method along with the corresponding key.
- Kotlin
- Java
// Get extra text assets
// The key is provided through GFP manager
val extraTextKey = "product_name" // Example key from GFP manager
val extraText = nativeAd.getExtraText(extraTextKey)
if (extraText != null) {
val extraTextView: TextView = nativeAdView.findViewById(R.id.extra_text_view)
extraTextView.text = extraText
nativeAdView.setExtraTextView(extraTextKey, extraTextView)
}
// Get extra image assets
// The key is provided through GFP manager
val extraImageKey = "product_image" // Example key from GFP manager
val extraImage = nativeAd.getExtraImage(extraImageKey)
if (extraImage != null) {
val extraImageView: ImageView = nativeAdView.findViewById(R.id.extra_image_view)
extraImage.drawable?.let { drawable ->
extraImageView.setImageDrawable(drawable)
nativeAdView.setExtraImageView(extraImageKey, extraImageView)
}
}
// Get extra text assets
// The key is provided through GFP manager
String extraTextKey = "product_name"; // Example key from GFP manager
String extraText = nativeAd.getExtraText(extraTextKey);
if (extraText != null) {
TextView extraTextView = nativeAdView.findViewById(R.id.extra_text_view);
extraTextView.setText(extraText);
nativeAdView.setExtraTextView(extraTextKey, extraTextView);
}
// Get extra image assets
// The key is provided through GFP manager
String extraImageKey = "product_image"; // Example key from GFP manager
Image extraImage = nativeAd.getExtraImage(extraImageKey);
if (extraImage != null && extraImage.getDrawable() != null) {
ImageView extraImageView = nativeAdView.findViewById(R.id.extra_image_view);
extraImageView.setImageDrawable(extraImage.getDrawable());
nativeAdView.setExtraImageView(extraImageKey, extraImageView);
}
Text Asset Style Information
How to retrieve and apply style information provided by text assets (title, body, advertiserName, etc.). Each text asset can include style information such as background color, border color, bold, and text color.
There are two ways to retrieve text assets:
-
When only text is needed: Use the basic methods.
-
When both text and style information are needed: Use methods with WithOption as a postfix.
The same pattern applies to additional text assets (extraText):
- When only text is needed: GfpNativeAd.getExtraText(key: String)
- When style information is also needed: GfpNativeAd.getExtraTextWithOption(key: String)
All these methods return a nullable LabelOption.
- When LabelOption is not null: It means that text exists for that asset, and the LabelOption.getText() value is always guaranteed.
- When LabelOption is null: It means that text does not exist for that asset.
Each style option value (background color, border color, text color, etc.) provided by LabelOption returns a value only when that option is available, and returns null when it is not available. Therefore, please perform a null check before using each option value and then apply it.
LabelOption provides two types of APIs for each style option:
- API without Context: bgColor, textColor, borderColor, isBold etc. (properties)
- API with Context: getBgColor(Context), getTextColor(Context), getBorderColor(Context), isBold(Context) etc. (functions)
Depending on GfpTheme, different options may be provided for light and dark themes, and this theme branching can only be handled with APIs that take Context as a parameter. Therefore, services using GfpTheme should use APIs that include Context.
- Kotlin
- Java
// Get Context (use Activity or View's context)
val context = nativeAdView.context
// Retrieve and apply style information for Title asset
val titleOption = nativeAd.getTitleWithOption()
if (titleOption != null) {
val titleView: TextView = nativeAdView.findViewById(R.id.ad_title)
titleView.text = titleOption.text
// Apply background color (only when available) - Use Context-based API
titleOption.getBgColor(context)?.let { bgColor ->
titleView.setBackgroundColor(bgColor)
}
// Apply border color (only when available) - Use Context-based API
titleOption.getBorderColor(context)?.let { borderColor ->
titleView.background?.mutate()?.let { drawable ->
if (drawable is GradientDrawable) {
drawable.setStroke(2, borderColor) // 2dp border width
}
}
}
// Apply text color (only when available) - Use Context-based API
titleOption.getTextColor(context)?.let { textColor ->
titleView.setTextColor(textColor)
}
// Apply bold - Use Context-based API
titleOption.isBold(context)?.let { isBold ->
if (isBold) {
titleView.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
}
}
nativeAdView.titleView = titleView
}
// Retrieve and apply style information for Body asset
val bodyOption = nativeAd.getBodyWithOption()
if (bodyOption != null) {
val bodyView: TextView = nativeAdView.findViewById(R.id.ad_body)
bodyView.text = bodyOption.text
bodyOption.getBgColor(context)?.let { bgColor ->
bodyView.setBackgroundColor(bgColor)
}
bodyOption.getTextColor(context)?.let { textColor ->
bodyView.setTextColor(textColor)
}
bodyOption.isBold(context)?.let { isBold ->
if (isBold) {
bodyView.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
}
}
nativeAdView.bodyView = bodyView
}
// Retrieve and apply style information for AdvertiserName asset
val advertiserNameOption = nativeAd.getAdvertiserNameWithOption()
if (advertiserNameOption != null) {
val advertiserNameView: TextView = nativeAdView.findViewById(R.id.ad_advertiser_name)
advertiserNameView.text = advertiserNameOption.text
advertiserNameOption.getBgColor(context)?.let { bgColor ->
advertiserNameView.setBackgroundColor(bgColor)
}
advertiserNameOption.getTextColor(context)?.let { textColor ->
advertiserNameView.setTextColor(textColor)
}
advertiserNameOption.isBold(context)?.let { isBold ->
if (isBold) {
advertiserNameView.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
}
}
nativeAdView.advertiserNameView = advertiserNameView
}
// Retrieve and apply style information for ExtraText asset
// The key is provided through GFP manager
val extraTextKey = "product_name" // Example key from GFP manager
val extraTextOption = nativeAd.getExtraTextWithOption(extraTextKey)
if (extraTextOption != null) {
val extraTextView: TextView = nativeAdView.findViewById(R.id.extra_text_view)
extraTextView.text = extraTextOption.text
extraTextOption.getBgColor(context)?.let { bgColor ->
extraTextView.setBackgroundColor(bgColor)
}
extraTextOption.getTextColor(context)?.let { textColor ->
extraTextView.setTextColor(textColor)
}
extraTextOption.isBold(context)?.let { isBold ->
if (isBold) {
extraTextView.typeface = Typeface.defaultFromStyle(Typeface.BOLD)
}
}
nativeAdView.setExtraTextView(extraTextKey, extraTextView)
}
// Get Context (use Activity or View's context)
Context context = nativeAdView.getContext();
// Retrieve and apply style information for Title asset
LabelOption titleOption = nativeAd.getTitleWithOption();
if (titleOption != null) {
TextView titleView = nativeAdView.findViewById(R.id.ad_title);
titleView.setText(titleOption.getText());
// Apply background color (only when available) - Use Context-based API
Integer bgColor = titleOption.getBgColor(context);
if (bgColor != null) {
titleView.setBackgroundColor(bgColor);
}
// Apply border color (only when available) - Use Context-based API
Integer borderColor = titleOption.getBorderColor(context);
if (borderColor != null) {
Drawable drawable = titleView.getBackground();
if (drawable != null) {
drawable = drawable.mutate();
if (drawable instanceof GradientDrawable) {
((GradientDrawable) drawable).setStroke(2, borderColor); // 2dp border width
}
}
}
// Apply text color (only when available) - Use Context-based API
Integer textColor = titleOption.getTextColor(context);
if (textColor != null) {
titleView.setTextColor(textColor);
}
// Apply bold - Use Context-based API
Boolean isBold = titleOption.isBold(context);
if (isBold != null && isBold) {
titleView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
}
nativeAdView.setTitleView(titleView);
}
// Retrieve and apply style information for Body asset
LabelOption bodyOption = nativeAd.getBodyWithOption();
if (bodyOption != null) {
TextView bodyView = nativeAdView.findViewById(R.id.ad_body);
bodyView.setText(bodyOption.getText());
Integer bgColor = bodyOption.getBgColor(context);
if (bgColor != null) {
bodyView.setBackgroundColor(bgColor);
}
Integer textColor = bodyOption.getTextColor(context);
if (textColor != null) {
bodyView.setTextColor(textColor);
}
Boolean isBold = bodyOption.isBold(context);
if (isBold != null && isBold) {
bodyView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
}
nativeAdView.setBodyView(bodyView);
}
// Retrieve and apply style information for AdvertiserName asset
LabelOption advertiserNameOption = nativeAd.getAdvertiserNameWithOption();
if (advertiserNameOption != null) {
TextView advertiserNameView = nativeAdView.findViewById(R.id.ad_advertiser_name);
advertiserNameView.setText(advertiserNameOption.getText());
Integer bgColor = advertiserNameOption.getBgColor(context);
if (bgColor != null) {
advertiserNameView.setBackgroundColor(bgColor);
}
Integer textColor = advertiserNameOption.getTextColor(context);
if (textColor != null) {
advertiserNameView.setTextColor(textColor);
}
Boolean isBold = advertiserNameOption.isBold(context);
if (isBold != null && isBold) {
advertiserNameView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
}
nativeAdView.setAdvertiserNameView(advertiserNameView);
}
// Retrieve and apply style information for ExtraText asset
// The key is provided through GFP manager
String extraTextKey = "product_name"; // Example key from GFP manager
LabelOption extraTextOption = nativeAd.getExtraTextWithOption(extraTextKey);
if (extraTextOption != null) {
TextView extraTextView = nativeAdView.findViewById(R.id.extra_text_view);
extraTextView.setText(extraTextOption.getText());
Integer bgColor = extraTextOption.getBgColor(context);
if (bgColor != null) {
extraTextView.setBackgroundColor(bgColor);
}
Integer textColor = extraTextOption.getTextColor(context);
if (textColor != null) {
extraTextView.setTextColor(textColor);
}
Boolean isBold = extraTextOption.isBold(context);
if (isBold != null && isBold) {
extraTextView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
}
nativeAdView.setExtraTextView(extraTextKey, extraTextView);
}
GfpNativeAdView Background Color
How to retrieve and apply background color information that can be optionally applied to the entire GfpNativeAdView area.
You can retrieve style information through the GfpNativeAd.getAdStyleOption() method, and get the background color using the AdStyleOption.getBackgroundColor(Context) method.
If background information is not provided for that product, GfpNativeAd.getAdStyleOption() may return null or GfpNativeAd.getAdStyleOption().getBackgroundColor(Context) may return null. Therefore, please perform a null check before applying it.
- Kotlin
- Java
// Get Context (use Activity or View's context)
val context = nativeAdView.context
// Retrieve and apply background color for the entire ad view
val adStyleOption = nativeAd.getAdStyleOption()
adStyleOption?.getBackgroundColor(context)?.let { backgroundColor ->
nativeAdView.setBackgroundColor(backgroundColor)
}
// Get Context (use Activity or View's context)
Context context = nativeAdView.getContext();
// Retrieve and apply background color for the entire ad view
AdStyleOption adStyleOption = nativeAd.getAdStyleOption();
if (adStyleOption != null) {
Integer backgroundColor = adStyleOption.getBackgroundColor(context);
if (backgroundColor != null) {
nativeAdView.setBackgroundColor(backgroundColor);
}
}