|
5 | 5 | import android.graphics.Bitmap;
|
6 | 6 | import android.graphics.BitmapFactory;
|
7 | 7 | import android.net.Uri;
|
| 8 | +import android.graphics.Typeface; |
8 | 9 | import android.util.Log;
|
9 | 10 |
|
10 | 11 | import androidx.annotation.NonNull;
|
@@ -196,7 +197,6 @@ public void setWelcomeMessageMode(@NonNull String mode) {
|
196 | 197 |
|
197 | 198 | @Override
|
198 | 199 | public void setPrimaryColor(@NonNull Long color) {
|
199 |
| - Instabug.setPrimaryColor(color.intValue()); |
200 | 200 | }
|
201 | 201 |
|
202 | 202 | @Override
|
@@ -248,20 +248,7 @@ public void run() {
|
248 | 248 | );
|
249 | 249 | }
|
250 | 250 |
|
251 |
| - @Override |
252 |
| - public void addExperiments(@NonNull List<String> experiments) { |
253 |
| - Instabug.addExperiments(experiments); |
254 |
| - } |
255 | 251 |
|
256 |
| - @Override |
257 |
| - public void removeExperiments(@NonNull List<String> experiments) { |
258 |
| - Instabug.removeExperiments(experiments); |
259 |
| - } |
260 |
| - |
261 |
| - @Override |
262 |
| - public void clearAllExperiments() { |
263 |
| - Instabug.clearAllExperiments(); |
264 |
| - } |
265 | 252 |
|
266 | 253 | @Override
|
267 | 254 | public void addFeatureFlags(@NonNull Map<String, String> featureFlags) {
|
@@ -529,4 +516,168 @@ public void setNetworkLogBodyEnabled(@NonNull Boolean isEnabled) {
|
529 | 516 | e.printStackTrace();
|
530 | 517 | }
|
531 | 518 | }
|
| 519 | + |
| 520 | + @Override |
| 521 | + public void setTheme(@NonNull Map<String, Object> themeConfig) { |
| 522 | + try { |
| 523 | + Log.d(TAG, "setTheme called with config: " + themeConfig.toString()); |
| 524 | + |
| 525 | + com.instabug.library.model.IBGTheme.Builder builder = new com.instabug.library.model.IBGTheme.Builder(); |
| 526 | + |
| 527 | + if (themeConfig.containsKey("primaryColor")) { |
| 528 | + builder.setPrimaryColor(getColor(themeConfig, "primaryColor")); |
| 529 | + } |
| 530 | + if (themeConfig.containsKey("secondaryTextColor")) { |
| 531 | + builder.setSecondaryTextColor(getColor(themeConfig, "secondaryTextColor")); |
| 532 | + } |
| 533 | + if (themeConfig.containsKey("primaryTextColor")) { |
| 534 | + builder.setPrimaryTextColor(getColor(themeConfig, "primaryTextColor")); |
| 535 | + } |
| 536 | + if (themeConfig.containsKey("titleTextColor")) { |
| 537 | + builder.setTitleTextColor(getColor(themeConfig, "titleTextColor")); |
| 538 | + } |
| 539 | + if (themeConfig.containsKey("backgroundColor")) { |
| 540 | + builder.setBackgroundColor(getColor(themeConfig, "backgroundColor")); |
| 541 | + } |
| 542 | + |
| 543 | + if (themeConfig.containsKey("primaryTextStyle")) { |
| 544 | + builder.setPrimaryTextStyle(getTextStyle(themeConfig, "primaryTextStyle")); |
| 545 | + } |
| 546 | + if (themeConfig.containsKey("secondaryTextStyle")) { |
| 547 | + builder.setSecondaryTextStyle(getTextStyle(themeConfig, "secondaryTextStyle")); |
| 548 | + } |
| 549 | + if (themeConfig.containsKey("ctaTextStyle")) { |
| 550 | + builder.setCtaTextStyle(getTextStyle(themeConfig, "ctaTextStyle")); |
| 551 | + } |
| 552 | + |
| 553 | + setFontIfPresent(themeConfig, builder, "primaryFontPath", "primaryFontAsset", "primary"); |
| 554 | + setFontIfPresent(themeConfig, builder, "secondaryFontPath", "secondaryFontAsset", "secondary"); |
| 555 | + setFontIfPresent(themeConfig, builder, "ctaFontPath", "ctaFontAsset", "CTA"); |
| 556 | + |
| 557 | + com.instabug.library.model.IBGTheme theme = builder.build(); |
| 558 | + Instabug.setTheme(theme); |
| 559 | + Log.d(TAG, "Theme applied successfully"); |
| 560 | + |
| 561 | + } catch (Exception e) { |
| 562 | + Log.e(TAG, "Error in setTheme: " + e.getMessage()); |
| 563 | + e.printStackTrace(); |
| 564 | + } |
| 565 | + } |
| 566 | + |
| 567 | + |
| 568 | + |
| 569 | + /** |
| 570 | + * Retrieves a color value from the Map. |
| 571 | + * |
| 572 | + * @param map The Map object. |
| 573 | + * @param key The key to look for. |
| 574 | + * @return The parsed color as an integer, or black if missing or invalid. |
| 575 | + */ |
| 576 | + private int getColor(Map<String, Object> map, String key) { |
| 577 | + try { |
| 578 | + if (map != null && map.containsKey(key) && map.get(key) != null) { |
| 579 | + String colorString = (String) map.get(key); |
| 580 | + return android.graphics.Color.parseColor(colorString); |
| 581 | + } |
| 582 | + } catch (Exception e) { |
| 583 | + e.printStackTrace(); |
| 584 | + } |
| 585 | + return android.graphics.Color.BLACK; |
| 586 | + } |
| 587 | + |
| 588 | + /** |
| 589 | + * Retrieves a text style from the Map. |
| 590 | + * |
| 591 | + * @param map The Map object. |
| 592 | + * @param key The key to look for. |
| 593 | + * @return The corresponding Typeface style, or Typeface.NORMAL if missing or invalid. |
| 594 | + */ |
| 595 | + private int getTextStyle(Map<String, Object> map, String key) { |
| 596 | + try { |
| 597 | + if (map != null && map.containsKey(key) && map.get(key) != null) { |
| 598 | + String style = (String) map.get(key); |
| 599 | + switch (style.toLowerCase()) { |
| 600 | + case "bold": |
| 601 | + return Typeface.BOLD; |
| 602 | + case "italic": |
| 603 | + return Typeface.ITALIC; |
| 604 | + case "bold_italic": |
| 605 | + return Typeface.BOLD_ITALIC; |
| 606 | + case "normal": |
| 607 | + default: |
| 608 | + return Typeface.NORMAL; |
| 609 | + } |
| 610 | + } |
| 611 | + } catch (Exception e) { |
| 612 | + e.printStackTrace(); |
| 613 | + } |
| 614 | + return Typeface.NORMAL; |
| 615 | + } |
| 616 | + |
| 617 | + /** |
| 618 | + * Sets a font on the theme builder if the font configuration is present in the theme config. |
| 619 | + * |
| 620 | + * @param themeConfig The theme configuration map |
| 621 | + * @param builder The theme builder |
| 622 | + * @param fileKey The key for font file path |
| 623 | + * @param assetKey The key for font asset path |
| 624 | + * @param fontType The type of font (for logging purposes) |
| 625 | + */ |
| 626 | + private void setFontIfPresent(Map<String, Object> themeConfig, com.instabug.library.model.IBGTheme.Builder builder, |
| 627 | + String fileKey, String assetKey, String fontType) { |
| 628 | + if (themeConfig.containsKey(fileKey) || themeConfig.containsKey(assetKey)) { |
| 629 | + Typeface typeface = getTypeface(themeConfig, fileKey, assetKey); |
| 630 | + if (typeface != null) { |
| 631 | + switch (fontType) { |
| 632 | + case "primary": |
| 633 | + builder.setPrimaryTextFont(typeface); |
| 634 | + break; |
| 635 | + case "secondary": |
| 636 | + builder.setSecondaryTextFont(typeface); |
| 637 | + break; |
| 638 | + case "CTA": |
| 639 | + builder.setCtaTextFont(typeface); |
| 640 | + break; |
| 641 | + } |
| 642 | + } |
| 643 | + } |
| 644 | + } |
| 645 | + |
| 646 | + private Typeface getTypeface(Map<String, Object> map, String fileKey, String assetKey) { |
| 647 | + String fontName = null; |
| 648 | + |
| 649 | + if (assetKey != null && map.containsKey(assetKey) && map.get(assetKey) != null) { |
| 650 | + fontName = (String) map.get(assetKey); |
| 651 | + } else if (fileKey != null && map.containsKey(fileKey) && map.get(fileKey) != null) { |
| 652 | + fontName = (String) map.get(fileKey); |
| 653 | + } |
| 654 | + |
| 655 | + if (fontName == null) { |
| 656 | + return Typeface.DEFAULT; |
| 657 | + } |
| 658 | + |
| 659 | + try { |
| 660 | + String assetPath = "fonts/" + fontName; |
| 661 | + return Typeface.createFromAsset(context.getAssets(), assetPath); |
| 662 | + } catch (Exception e) { |
| 663 | + try { |
| 664 | + return Typeface.create(fontName, Typeface.NORMAL); |
| 665 | + } catch (Exception e2) { |
| 666 | + return Typeface.DEFAULT; |
| 667 | + } |
| 668 | + } |
| 669 | + } |
| 670 | + /** |
| 671 | + * Enables or disables displaying in full-screen mode, hiding the status and navigation bars. |
| 672 | + * @param isEnabled A boolean to enable/disable setFullscreen. |
| 673 | + */ |
| 674 | + @Override |
| 675 | + public void setFullscreen(@NonNull final Boolean isEnabled) { |
| 676 | + try { |
| 677 | + Instabug.setFullscreen(isEnabled); |
| 678 | + } catch (Exception e) { |
| 679 | + e.printStackTrace(); |
| 680 | + } |
| 681 | + } |
| 682 | + |
532 | 683 | }
|
0 commit comments