Guest User

Untitled

a guest
Jul 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. public class MarkerSize {
  2. /**
  3. * Convert a SVG into a BitmapDescriptor for map marker
  4. *
  5. * @param context The main Activity
  6. * @param vectorResId The ID of the SVG
  7. * @return The map marker as a BitmapDesriptor
  8.  
  9. */
  10.  
  11. public BitmapDescriptor bitmapDescriptorFromVector ( Context context, int vectorResId ) {
  12. try {
  13. Drawable vectorDrawable = ContextCompat.getDrawable(context, vectorResId);
  14.  
  15. vectorDrawable.setBounds(0,
  16. 0,
  17. vectorDrawable.getIntrinsicWidth(),
  18. vectorDrawable.getIntrinsicHeight());
  19. Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
  20. vectorDrawable.getIntrinsicHeight(),
  21. Bitmap.Config.ARGB_8888);
  22. Canvas canvas = new Canvas(bitmap);
  23. vectorDrawable.draw(canvas);
  24. BitmapDescriptor bp= BitmapDescriptorFactory.fromBitmap(bitmap);
  25. return bp;
  26. }catch ( Resources.NotFoundException e ){
  27. return null;
  28. }
  29. }
  30.  
  31. /**
  32. * Change the size of the marker
  33. * @param context MapsActivity
  34. * @param iconName The name of the SVG file
  35. * @param width The desired width for the icon
  36. * @param height The desired heigh for the icon
  37. * @return A Bitmap representation of the SVG
  38. */
  39. public Bitmap resizeMapIcons (Context context, String iconName, int width, int height ) {
  40. Bitmap imageBitmap = BitmapFactory.decodeResource (context.getResources (),
  41. context.getResources ().getIdentifier
  42. (iconName,
  43. "drawable",
  44. context.getPackageName ()));
  45. Bitmap resizedBitmap = Bitmap.createScaledBitmap (imageBitmap, width, height, false);
  46. return resizedBitmap;
  47. }
  48. }
  49.  
  50. @RunWith(JUnit4.class)
  51. @SmallTest
  52. public class testMarkersmethods {
  53.  
  54. MapViewFragment mapViewFragment;
  55. private int VECTORID= R.drawable.ic_dest_pin;
  56. Context context=InstrumentationRegistry.getTargetContext();
  57. MarkerSize markerSize=new MarkerSize();
  58. BitmapDescriptor bitmapDescriptorrr ;
  59.  
  60. @Test
  61. public void test_bitMapfromVector(){
  62. if(context!=null) {
  63. BitmapDescriptor bitmapDescriptor = markerSize.bitmapDescriptorFromVector(context, VECTORID);
  64. Assert.assertNotNull(bitmapDescriptor);
  65. Assert.assertEquals(bitmapDescriptorrr, bitmapDescriptor);
  66. }
  67. }
  68. }
  69.  
  70. java.lang.NullPointerException: IBitmapDescriptorFactory is not initialized
  71. at com.google.android.gms.common.internal.Preconditions.checkNotNull(Unknown Source:8)
  72. at com.google.android.gms.maps.model.BitmapDescriptorFactory.zzf(Unknown Source:4)
  73. at com.google.android.gms.maps.model.BitmapDescriptorFactory.fromBitmap(Unknown Source:2)
  74. at algorithm.MarkerSize.bitmapDescriptorFromVector(MarkerSize.java:38)
  75. at com.example.giheok.streetview.testMarkersmethods.test_bitMapfromVector(testMarkersmethods.java:33)
  76. at java.lang.reflect.Method.invoke(Native Method)
  77. at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
  78. at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  79. at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
  80. at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  81. at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
  82. at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
  83. at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
  84. at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  85. at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  86. at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  87. at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  88. at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  89. at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  90. at org.junit.runners.Suite.runChild(Suite.java:128)
  91. at org.junit.runners.Suite.runChild(Suite.java:27)
  92. at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  93. at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  94. at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  95. at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  96. at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  97. at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  98. at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
  99. at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
  100. at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
  101. at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:384)
  102. at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145)
Add Comment
Please, Sign In to add comment