|
3 | 3 | import android.app.Application; |
4 | 4 | import android.content.Context; |
5 | 5 | import android.graphics.Bitmap; |
| 6 | +import android.graphics.BitmapFactory; |
6 | 7 | import android.net.Uri; |
7 | 8 | import android.util.Log; |
8 | 9 |
|
|
26 | 27 | import org.json.JSONObject; |
27 | 28 |
|
28 | 29 | import java.io.File; |
| 30 | +import java.io.IOException; |
| 31 | +import java.io.InputStream; |
29 | 32 | import java.lang.reflect.Method; |
30 | 33 | import java.util.HashMap; |
31 | 34 | import java.util.List; |
32 | 35 | import java.util.Locale; |
33 | 36 | import java.util.Map; |
34 | 37 | import java.util.concurrent.Callable; |
35 | 38 |
|
| 39 | +import io.flutter.FlutterInjector; |
36 | 40 | import io.flutter.plugin.common.BinaryMessenger; |
| 41 | +import io.flutter.embedding.engine.loader.FlutterLoader; |
37 | 42 |
|
38 | 43 | public class InstabugApi implements InstabugPigeon.InstabugHostApi { |
39 | 44 | private final String TAG = InstabugApi.class.getName(); |
@@ -269,6 +274,43 @@ public void reportScreenChange(@NonNull String screenName) { |
269 | 274 | } |
270 | 275 | } |
271 | 276 |
|
| 277 | + private Bitmap getBitmapForAsset(String assetName) { |
| 278 | + try { |
| 279 | + FlutterLoader loader = FlutterInjector.instance().flutterLoader(); |
| 280 | + String key = loader.getLookupKeyForAsset(assetName); |
| 281 | + InputStream stream = context.getAssets().open(key); |
| 282 | + return BitmapFactory.decodeStream(stream); |
| 283 | + } catch (IOException exception) { |
| 284 | + return null; |
| 285 | + } |
| 286 | + } |
| 287 | + |
| 288 | + @Override |
| 289 | + public void setCustomBrandingImage(@NonNull String light, @NonNull String dark) { |
| 290 | + try { |
| 291 | + Bitmap lightLogoVariant = getBitmapForAsset(light); |
| 292 | + Bitmap darkLogoVariant = getBitmapForAsset(dark); |
| 293 | + |
| 294 | + if (lightLogoVariant == null) { |
| 295 | + lightLogoVariant = darkLogoVariant; |
| 296 | + } |
| 297 | + if (darkLogoVariant == null) { |
| 298 | + darkLogoVariant = lightLogoVariant; |
| 299 | + } |
| 300 | + if (lightLogoVariant == null) { |
| 301 | + throw new Exception("Couldn't find the light or dark logo images"); |
| 302 | + } |
| 303 | + |
| 304 | + Method method = Reflection.getMethod(Class.forName("com.instabug.library.Instabug"), "setCustomBrandingImage", Bitmap.class, Bitmap.class); |
| 305 | + |
| 306 | + if (method != null) { |
| 307 | + method.invoke(null, lightLogoVariant, darkLogoVariant); |
| 308 | + } |
| 309 | + } catch (Exception e) { |
| 310 | + e.printStackTrace(); |
| 311 | + } |
| 312 | + } |
| 313 | + |
272 | 314 | @Override |
273 | 315 | public void addFileAttachmentWithURL(@NonNull String filePath, @NonNull String fileName) { |
274 | 316 | final File file = new File(filePath); |
|
0 commit comments