Skip to content
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

InApp Button stroke width is customizable #235

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.urbanairship.Fonts;
import com.urbanairship.UALog;
import com.urbanairship.automation.R;
import com.urbanairship.iam.ButtonInfo;
import com.urbanairship.iam.MediaInfo;
import com.urbanairship.iam.TextInfo;
Expand Down Expand Up @@ -57,7 +58,6 @@
public class InAppViewUtils {

private static final float PRESSED_ALPHA_PERCENT = .2f;
private static final int DEFAULT_STROKE_WIDTH_DPS = 2;
private static final float DEFAULT_BORDER_RADIUS = 0;

/**
Expand All @@ -66,8 +66,9 @@ public class InAppViewUtils {
* @param button The button view.
* @param buttonInfo The button info.
* @param borderRadiusFlag The border radius flag.
* @param strokeWidthInDps The stroke width in dps.
*/
public static void applyButtonInfo(@NonNull Button button, @NonNull ButtonInfo buttonInfo, @BorderRadius.BorderRadiusFlag int borderRadiusFlag) {
public static void applyButtonInfo(@NonNull Button button, @NonNull ButtonInfo buttonInfo, @BorderRadius.BorderRadiusFlag int borderRadiusFlag, int strokeWidthInDps) {
applyButtonTextInfo(button, buttonInfo.getLabel());

int textColor = buttonInfo.getLabel().getColor() == null ? button.getCurrentTextColor() : buttonInfo.getLabel().getColor();
Expand All @@ -82,12 +83,24 @@ public static void applyButtonInfo(@NonNull Button button, @NonNull ButtonInfo b
.setBorderRadius(borderRadius, borderRadiusFlag)
.setPressedColor(pressedColor)
.setStrokeColor(strokeColor)
.setStrokeWidth(DEFAULT_STROKE_WIDTH_DPS)
.setStrokeWidth(strokeWidthInDps)
.build();

ViewCompat.setBackground(button, background);
}

/**
* Applies button info to a button.
*
* @param button The button view.
* @param buttonInfo The button info.
* @param borderRadiusFlag The border radius flag.
*/
public static void applyButtonInfo(@NonNull Button button, @NonNull ButtonInfo buttonInfo, @BorderRadius.BorderRadiusFlag int borderRadiusFlag) {
int strokeWidth = button.getContext().getResources().getInteger(R.integer.ua_iam_button_stroke_width_dps);
applyButtonInfo(button, buttonInfo, borderRadiusFlag, strokeWidth);
}

/**
* Applies text info to a text view with a center gravity.
*
Expand Down
2 changes: 2 additions & 0 deletions urbanairship-automation/src/main/res/values/config_iam.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

<bool name="ua_iam_modal_allow_fullscreen_display">true</bool>
<bool name="ua_iam_html_allow_fullscreen_display">true</bool>

<integer name="ua_iam_button_stroke_width_dps">2</integer>
</resources>
Loading