Skip to content

Commit adf21ca

Browse files
author
Mohamed Sobhy
committed
Use Instabug v2.1 and show how to use CapturableView
1 parent e15b47b commit adf21ca

File tree

5 files changed

+71
-13
lines changed

5 files changed

+71
-13
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,38 @@ Using Instabug is as easy as "Get ready, Get set, Go".
2828

2929
Grab your desired flavour via Gradle:
3030
```groovy
31-
compile 'com.instabug.library:instabug:2.0'
31+
compile 'com.instabug.library:instabug:2.1'
3232
```
3333
or
3434
```groovy
35-
compile 'com.instabug.library:instabugcompat:2.0'
35+
compile 'com.instabug.library:instabugcompat:2.1'
3636
```
3737
or
3838
```groovy
39-
compile 'com.instabug.library:instabugabs:2.0'
39+
compile 'com.instabug.library:instabugabs:2.1'
4040
```
4141
or via Maven: (if you're that kind of person :bowtie:)
4242
```xml
4343
<dependency>
4444
<groupId>com.instabug.library</groupId>
4545
<artifactId>instabug</artifactId>
46-
<version>2.0</version>
46+
<version>2.1</version>
4747
</dependency>
4848
```
4949
or
5050
```xml
5151
<dependency>
5252
<groupId>com.instabug.library</groupId>
5353
<artifactId>instabugcompat</artifactId>
54-
<version>2.0</version>
54+
<version>2.1</version>
5555
</dependency>
5656
```
5757
or
5858
```xml
5959
<dependency>
6060
<groupId>com.instabug.library</groupId>
6161
<artifactId>instabugabs</artifactId>
62-
<version>2.0</version>
62+
<version>2.1</version>
6363
</dependency>
6464
```
6565

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies {
3434
compile 'com.android.support:appcompat-v7:23.1.1'
3535
// TODO if you use a lower version than 8.4.0 you should uncomment the exclude line to avoid errors
3636
compile 'com.google.android.gms:play-services:8.4.0'
37-
compile('com.instabug.library:instabugcompat:2.0.1') {
37+
compile('com.instabug.library:instabug:2.1') {
3838
exclude module: 'appcompat-v7'
3939
// TODO uncomment next line if you're facing compilation issue in build.gradle about gms different versions
4040
// exclude group: 'com.google.android.gms'

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
android:name="com.google.android.gms.version"
3232
android:value="@integer/google_play_services_version"/>
3333
<meta-data
34-
android:name="com.google.android.maps.v2.API_KEY"
35-
android:value="AIzaSyAnraFz6auzHcIwsedNn--l1-XBk3Oh-gQ"/>
34+
android:name="com.google.android.geo.API_KEY"
35+
android:value="AIzaSyD1NsFNyD12H_4lzgzth7lUxUAbZzyKEL4"/>
3636

3737
<activity android:name=".ui.activities.OpenGLActivity"/>
3838
</application>

app/src/main/java/com/example/instabug/ui/activities/GoogleMapsActivity.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.support.v7.app.AppCompatActivity;
55

66
import com.example.instabug.R;
7+
import com.example.instabug.ui.views.CustomGoogleMap;
78
import com.google.android.gms.maps.GoogleMap;
89
import com.google.android.gms.maps.SupportMapFragment;
910
import com.google.android.gms.maps.model.LatLng;
@@ -13,6 +14,7 @@
1314
public class GoogleMapsActivity extends AppCompatActivity {
1415

1516
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
17+
private CustomGoogleMap customGoogleMap;
1618

1719
@Override
1820
protected void onCreate(Bundle savedInstanceState) {
@@ -42,15 +44,15 @@ protected void onResume() {
4244
* stopped or paused), {@link #onCreate(Bundle)} may not be called again so we should call this
4345
* method in {@link #onResume()} to guarantee that it will be called.
4446
*/
45-
4647
private void setUpMapIfNeeded() {
4748
// Do a null check to confirm that we have not already instantiated the map.
4849
if (mMap == null) {
4950
// Try to obtain the map from the SupportMapFragment.
5051
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
5152
.getMap();
53+
customGoogleMap = new CustomGoogleMap(getSupportFragmentManager().findFragmentById(R.id.map).getView(), mMap);
5254
// TODO add this so that instabug recognizes you have a map and show it in the screenshot
53-
Instabug.addMapView(getSupportFragmentManager().findFragmentById(R.id.map).getView(), mMap);
55+
Instabug.addCapturableView(customGoogleMap);
5456

5557
// Check if we were successful in obtaining the map.
5658
if (mMap != null) {
@@ -65,9 +67,7 @@ private void setUpMapIfNeeded() {
6567
* <p/>
6668
* This should only be called once and when we are sure that {@link #mMap} is not null.
6769
*/
68-
6970
private void setUpMap() {
7071
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
7172
}
72-
7373
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.example.instabug.ui.views;
2+
3+
import android.graphics.Bitmap;
4+
import android.support.annotation.Size;
5+
import android.view.View;
6+
7+
import com.google.android.gms.maps.GoogleMap;
8+
import com.instabug.library.internal.layer.CapturableView;
9+
10+
/**
11+
* @author mSobhy
12+
*/
13+
public class CustomGoogleMap implements CapturableView {
14+
15+
private View mapFragment;
16+
private GoogleMap googleMap;
17+
18+
public CustomGoogleMap(View mapFragment, GoogleMap googleMap) {
19+
this.mapFragment = mapFragment;
20+
this.googleMap = googleMap;
21+
}
22+
23+
@Override
24+
public void snapshot(final SnapshotPreparationCallback snapshotPreparationCallback) {
25+
googleMap.snapshot(new GoogleMap.SnapshotReadyCallback() {
26+
@Override
27+
public void onSnapshotReady(Bitmap bitmap) {
28+
// Bitmap manipulatedBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
29+
// for (int i = 0; i < bitmap.getWidth(); i++) {
30+
// for (int j = 0; j < bitmap.getHeight(); j++) {
31+
// int p = bitmap.getPixel(i, j);
32+
// int r = Color.red(p);
33+
// int g = Color.green(p);
34+
// int b = Color.blue(p);
35+
// int alpha = Color.alpha(p);
36+
//
37+
// r = 0;
38+
// g = 0;
39+
// b = b + 150;
40+
// alpha = 0;
41+
// manipulatedBitmap.setPixel(i, j, Color.argb(Color.alpha(p), r, g, b));
42+
// }
43+
// }
44+
snapshotPreparationCallback.onSnapshotReady(bitmap);
45+
}
46+
});
47+
}
48+
49+
@Override
50+
public boolean isVisible() {
51+
return mapFragment.getVisibility() == View.VISIBLE;
52+
}
53+
54+
@Override
55+
public void getLocationOnScreen(@Size(2) int[] location) {
56+
mapFragment.getLocationOnScreen(location);
57+
}
58+
}

0 commit comments

Comments
 (0)