From 9db1a77ac8cae19a3cf97c4d1d165eaae503b1f5 Mon Sep 17 00:00:00 2001 From: wf9a5m75 Date: Thu, 19 Mar 2015 14:20:26 -0700 Subject: [PATCH] Modified #442 --- .../plugin/google/maps/GoogleMaps.java | 57 ++++++------------- src/android/plugin/google/maps/PluginMap.java | 4 +- .../plugin/google/maps/PluginUtil.java | 29 ++++++++++ www/googlemaps-cdv-plugin.js | 5 +- 4 files changed, 49 insertions(+), 46 deletions(-) diff --git a/src/android/plugin/google/maps/GoogleMaps.java b/src/android/plugin/google/maps/GoogleMaps.java index 4b3e63431..ed7b48cc0 100644 --- a/src/android/plugin/google/maps/GoogleMaps.java +++ b/src/android/plugin/google/maps/GoogleMaps.java @@ -68,6 +68,7 @@ import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap.InfoWindowAdapter; import com.google.android.gms.maps.GoogleMap.OnCameraChangeListener; +import com.google.android.gms.maps.GoogleMap.OnIndoorStateChangeListener; import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener; import com.google.android.gms.maps.GoogleMap.OnMapClickListener; import com.google.android.gms.maps.GoogleMap.OnMapLoadedCallback; @@ -84,6 +85,7 @@ import com.google.android.gms.maps.model.CameraPosition.Builder; import com.google.android.gms.maps.model.Circle; import com.google.android.gms.maps.model.GroundOverlay; +import com.google.android.gms.maps.model.IndoorBuilding; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLngBounds; import com.google.android.gms.maps.model.Marker; @@ -91,9 +93,6 @@ import com.google.android.gms.maps.model.PolygonOptions; import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.VisibleRegion; -import com.google.android.gms.maps.model.IndoorBuilding; -import com.google.android.gms.maps.model.IndoorLevel; -import com.google.android.gms.maps.GoogleMap.OnIndoorStateChangeListener; @SuppressWarnings("deprecation") public class GoogleMaps extends CordovaPlugin implements View.OnClickListener, OnMarkerClickListener, @@ -569,6 +568,7 @@ public void onMapReady(GoogleMap googleMap) { map.setOnMarkerClickListener(GoogleMaps.this); map.setOnMarkerDragListener(GoogleMaps.this); map.setOnMyLocationButtonClickListener(GoogleMaps.this); + map.setOnIndoorStateChangeListener(GoogleMaps.this); // Load PluginMap class GoogleMaps.this.loadPlugin("Map"); @@ -915,25 +915,15 @@ private void isAvailable(final JSONArray args, final CallbackContext callbackCon callbackContext.success(); } + @SuppressWarnings("unused") private void getFocusedBuilding(final JSONArray args, final CallbackContext callbackContext) throws JSONException { - IndoorBuilding focusedBuilding = map.getFocusedBuilding(); - JSONObject result = new JSONObject(); - if (focusedBuilding != null) { - JSONArray levels = new JSONArray(); - for(IndoorLevel level : focusedBuilding.getLevels()){ - JSONObject levelInfo = new JSONObject(); - levelInfo.put("name",level.getName()); - levelInfo.put("shortName",level.getShortName()); - levels.put(levelInfo); - } - result.put("activeLevelIndex",focusedBuilding.getActiveLevelIndex()); - result.put("defaultLevelIndex",focusedBuilding.getDefaultLevelIndex()); - result.put("levels",levels); - result.put("underground",focusedBuilding.isUnderground()); - callbackContext.success(result); - } else { - callbackContext.success(-1); - } + IndoorBuilding focusedBuilding = map.getFocusedBuilding(); + if (focusedBuilding != null) { + JSONObject result = PluginUtil.convertIndoorBuildingToJson(focusedBuilding); + callbackContext.success(result); + } else { + callbackContext.success(-1); + } } @SuppressWarnings("unused") @@ -1560,30 +1550,17 @@ public void onCameraChange(CameraPosition position) { @Override public void onIndoorBuildingFocused() { - webView.loadUrl("javascript:plugin.google.maps.Map._onMapEvent('indoor_building_focused')"); + webView.loadUrl("javascript:plugin.google.maps.Map._onMapEvent('indoor_building_focused')"); } @Override public void onIndoorLevelActivated(IndoorBuilding building) { - JSONObject params = new JSONObject(); - String jsonStr = ""; - try { - JSONArray levels = new JSONArray(); - for(IndoorLevel level : building.getLevels()){ - JSONObject levelInfo = new JSONObject(); - levelInfo.put("name",level.getName()); - levelInfo.put("shortName",level.getShortName()); - levels.put(levelInfo); - } - params.put("activeLevelIndex",building.getActiveLevelIndex()); - params.put("defaultLevelIndex",building.getDefaultLevelIndex()); - params.put("levels",levels); - params.put("underground",building.isUnderground()); - jsonStr = params.toString(); - } catch (JSONException e) { - e.printStackTrace(); + String jsonStr = "null"; + JSONObject result = PluginUtil.convertIndoorBuildingToJson(building); + if (result != null) { + jsonStr = result.toString(); } - webView.loadUrl("javascript:plugin.google.maps.Map._onMapEvent('indoor_level_activated', " + jsonStr + ")"); + webView.loadUrl("javascript:plugin.google.maps.Map._onMapEvent('indoor_level_activated', " + jsonStr + ")"); } @Override diff --git a/src/android/plugin/google/maps/PluginMap.java b/src/android/plugin/google/maps/PluginMap.java index ec4b3064c..6ebf33d35 100644 --- a/src/android/plugin/google/maps/PluginMap.java +++ b/src/android/plugin/google/maps/PluginMap.java @@ -297,10 +297,8 @@ private void myMoveCamera(final CameraUpdate cameraUpdate, final CallbackContext private void setMyLocationEnabled(final JSONArray args, final CallbackContext callbackContext) throws JSONException { Boolean isEnabled = false; isEnabled = args.getBoolean(1); - Boolean button = false; - button = args.getBoolean(2); map.setMyLocationEnabled(isEnabled); - map.getUiSettings().setMyLocationButtonEnabled(button); + map.getUiSettings().setMyLocationButtonEnabled(isEnabled); this.sendNoResult(callbackContext); } diff --git a/src/android/plugin/google/maps/PluginUtil.java b/src/android/plugin/google/maps/PluginUtil.java index bd1271d86..722ab739f 100644 --- a/src/android/plugin/google/maps/PluginUtil.java +++ b/src/android/plugin/google/maps/PluginUtil.java @@ -27,6 +27,8 @@ import android.os.Bundle; import android.util.Base64; +import com.google.android.gms.maps.model.IndoorBuilding; +import com.google.android.gms.maps.model.IndoorLevel; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLngBounds; import com.google.android.gms.maps.model.LatLngBounds.Builder; @@ -270,4 +272,31 @@ public static LatLngBounds convertToLatLngBounds(List points) { } return latLngBuilder.build(); } + + + public static JSONObject convertIndoorBuildingToJson(IndoorBuilding indoorBuilding) { + if (indoorBuilding == null) { + return null; + } + JSONObject result = new JSONObject(); + try { + JSONArray levels = new JSONArray(); + for(IndoorLevel level : indoorBuilding.getLevels()){ + JSONObject levelInfo = new JSONObject(); + levelInfo.put("name",level.getName()); + + // TODO Auto-generated catch block + levelInfo.put("shortName",level.getShortName()); + levels.put(levelInfo); + } + result.put("activeLevelIndex",indoorBuilding.getActiveLevelIndex()); + result.put("defaultLevelIndex",indoorBuilding.getDefaultLevelIndex()); + result.put("levels",levels); + result.put("underground",indoorBuilding.isUnderground()); + } catch (JSONException e) { + e.printStackTrace(); + return null; + } + return result; + } } diff --git a/www/googlemaps-cdv-plugin.js b/www/googlemaps-cdv-plugin.js index be2ed6727..99f47e725 100644 --- a/www/googlemaps-cdv-plugin.js +++ b/www/googlemaps-cdv-plugin.js @@ -476,10 +476,9 @@ App.prototype.moveCamera = function(cameraPosition, callback) { }, self.errorHandler, PLUGIN_NAME, 'exec', ['Map.moveCamera', cameraPosition]); }; -App.prototype.setMyLocationEnabled = function(enabled, button) { +App.prototype.setMyLocationEnabled = function(enabled) { enabled = parseBoolean(enabled); - button = parseBoolean(button); - cordova.exec(null, this.errorHandler, PLUGIN_NAME, 'exec', ['Map.setMyLocationEnabled', enabled, button]); + cordova.exec(null, this.errorHandler, PLUGIN_NAME, 'exec', ['Map.setMyLocationEnabled', enabled]); }; App.prototype.setIndoorEnabled = function(enabled) { enabled = parseBoolean(enabled);