Skip to content

Commit

Permalink
Compatibility with older Cordova-Android versions
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Jan 6, 2016
1 parent 9a1b86e commit 3a17738
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,25 @@ iOS and Android are fully supported.

### iOS

<img src="screenshots/ios/ios-marker-amsterdam.png" width="235"/>&nbsp;
<img src="screenshots/ios/ios-location-benelux.png" width="235"/>&nbsp;
<img src="screenshots/ios/ios-location-europe-dark-boxed.png" width="235"/>
<img src="https://raw.githubusercontent.com/Telerik-Verified-Plugins/Mapbox/master/screenshots/ios/ios-marker-amsterdam.png" width="235"/>&nbsp;
<img src="https://raw.githubusercontent.com/Telerik-Verified-Plugins/Mapbox/master/screenshots/ios/ios-location-benelux.png" width="235"/>&nbsp;
<img src="https://raw.githubusercontent.com/Telerik-Verified-Plugins/Mapbox/master/screenshots/ios/ios-location-europe-dark-boxed.png" width="235"/>

### Android

<img src="screenshots/android/android-marker-amsterdam.png" width="400"/>
<img src="https://raw.githubusercontent.com/Telerik-Verified-Plugins/Mapbox/master/screenshots/android/android-marker-amsterdam.png" width="400"/>


## 3. Installation

npm (latest stable)
```
$ cordova plugin add cordova-plugin-mapbox --variable ACCESS_TOKEN=your.access.token
```

Github master (lastest develop)
```
$ cordova plugin add https://github.com/Telerik-Verified-Plugins/Mapbox --variable ACCESS_TOKEN=your.access.token
$ cordova prepare
```

Mapbox.js is brought in automatically. There is no need to change or add anything in your html.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.1.1",
"version": "1.1.2",
"name": "cordova-plugin-mapbox",
"cordova_name": "Mapbox",
"description": "Need native maps? Look no further!",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-mapbox"
version="1.1.1">
version="1.1.2">

<name>Mapbox</name>

Expand Down
32 changes: 23 additions & 9 deletions src/android/Mapbox.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import android.Manifest;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
Expand Down Expand Up @@ -362,17 +361,32 @@ private static String getStyle(final String requested) {
}
}

private boolean permissionGranted(String... types) {
if (Build.VERSION.SDK_INT < 23) {
return true;
}
for (final String type : types) {
if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(this.cordova.getActivity(), type)) {
return false;
}
}
return true;
}

protected void showUserLocation() {
if (cordova.hasPermission(COARSE_LOCATION) && cordova.hasPermission(FINE_LOCATION)) {
if (permissionGranted(COARSE_LOCATION, FINE_LOCATION)) {
mapView.setMyLocationEnabled(showUserLocation);
} else {
getLocationPermission(LOCATION_REQ_CODE);
requestPermission(COARSE_LOCATION, FINE_LOCATION);
}
}

protected void getLocationPermission(int requestCode) {
String[] permissions = { FINE_LOCATION, COARSE_LOCATION };
cordova.requestPermissions(this, requestCode, permissions);

private void requestPermission(String... types) {
ActivityCompat.requestPermissions(
this.cordova.getActivity(),
types,
LOCATION_REQ_CODE);
}

public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException {
Expand Down

0 comments on commit 3a17738

Please sign in to comment.