diff --git a/android/manifest b/android/manifest index 41316e6a..38d50bfc 100644 --- a/android/manifest +++ b/android/manifest @@ -2,7 +2,7 @@ # this is your module manifest and used by Titanium # during compilation, packaging, distribution, etc. # -version: 5.7.0 +version: 6.0.0 apiversion: 4 architectures: arm64-v8a armeabi-v7a x86 x86_64 description: External version of Map module using native Google Maps library diff --git a/android/src/ti/map/TiUIMapView.java b/android/src/ti/map/TiUIMapView.java index 18a8c558..521a5afc 100644 --- a/android/src/ti/map/TiUIMapView.java +++ b/android/src/ti/map/TiUIMapView.java @@ -17,17 +17,17 @@ import android.graphics.Point; import android.location.Location; import android.os.Build; +import android.os.Bundle; import android.view.MotionEvent; import android.view.SurfaceView; import android.view.View; import android.view.ViewGroup; -import androidx.fragment.app.Fragment; import com.google.android.gms.maps.CameraUpdate; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMapOptions; +import com.google.android.gms.maps.MapView; import com.google.android.gms.maps.OnMapReadyCallback; -import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.Circle; import com.google.android.gms.maps.model.LatLng; @@ -46,14 +46,18 @@ import java.util.HashMap; import org.appcelerator.kroll.KrollDict; import org.appcelerator.kroll.KrollProxy; +import org.appcelerator.kroll.KrollProxyListener; import org.appcelerator.kroll.common.Log; import org.appcelerator.titanium.TiApplication; +import org.appcelerator.titanium.TiBaseActivity; import org.appcelerator.titanium.TiBlob; import org.appcelerator.titanium.TiC; +import org.appcelerator.titanium.TiLifecycle; import org.appcelerator.titanium.io.TiFileFactory; import org.appcelerator.titanium.proxy.TiViewProxy; import org.appcelerator.titanium.util.TiConvert; -import org.appcelerator.titanium.view.TiUIFragment; +import org.appcelerator.titanium.view.TiCompositeLayout; +import org.appcelerator.titanium.view.TiUIView; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -62,12 +66,13 @@ import ti.map.Shape.IShape; import ti.map.Shape.PolylineBoundary; -public class TiUIMapView extends TiUIFragment +public class TiUIMapView extends TiUIView implements GoogleMap.OnMarkerClickListener, GoogleMap.OnMapClickListener, GoogleMap.OnMarkerDragListener, GoogleMap.OnInfoWindowClickListener, GoogleMap.InfoWindowAdapter, GoogleMap.OnMapLongClickListener, GoogleMap.OnMapLoadedCallback, OnMapReadyCallback, GoogleMap.OnCameraMoveStartedListener, GoogleMap.OnCameraMoveListener, GoogleMap.OnCameraIdleListener, GoogleMap.OnMyLocationChangeListener, - ClusterManager.OnClusterClickListener, ClusterManager.OnClusterItemClickListener + ClusterManager.OnClusterClickListener, ClusterManager.OnClusterItemClickListener, + TiLifecycle.OnInstanceStateEvent { public static final String DEFAULT_COLLECTION_ID = "defaultCollection"; @@ -77,8 +82,10 @@ public class TiUIMapView extends TiUIFragment protected boolean preLayout = true; protected boolean liteMode = false; protected LatLngBounds preLayoutUpdateBounds; + private Bundle pendingSavedState; protected ArrayList timarkers; protected AnnotationProxy selectedAnnotation; + private MapView mMapView; private ArrayList currentCircles; private ArrayList currentPolygons; @@ -89,15 +96,46 @@ public class TiUIMapView extends TiUIFragment private MarkerManager mMarkerManager; private MarkerManager.Collection collection; - public TiUIMapView(final TiViewProxy proxy, Activity activity) + public TiUIMapView(TiViewProxy proxy) { - super(proxy, activity); + super(proxy); + GoogleMapOptions options = new GoogleMapOptions(); + Object liteModeValue = proxy.getProperty(MapModule.PROPERTY_LITE_MODE); + if (liteModeValue != null && TiConvert.toBoolean(liteModeValue, false)) { + options.liteMode(true); + } + Object zOrderOnTopValue = proxy.getProperty(MapModule.PROPERTY_ZORDER_ON_TOP); + if (zOrderOnTopValue != null && TiConvert.toBoolean(zOrderOnTopValue, false)) { + options.zOrderOnTop(true); + } + mMapView = new MapView(proxy.getActivity(), options); + mMapView.onCreate(null); + mMapView.onStart(); + mMapView.onResume(); + + mMapView.getMapAsync(this); + + TiCompositeLayout container = new TiCompositeLayout(proxy.getActivity(), proxy) { + @Override + public boolean dispatchTouchEvent(MotionEvent ev) + { + return interceptTouchEvent(ev) || super.dispatchTouchEvent(ev); + } + }; + container.addView(mMapView); + setNativeView(container); + timarkers = new ArrayList(); currentCircles = new ArrayList(); currentPolygons = new ArrayList(); currentPolylines = new ArrayList(); currentImageOverlays = new ArrayList(); proxy.setProperty(MapModule.PROPERTY_INDOOR_ENABLED, true); + + Activity activity = proxy.getActivity(); + if (activity instanceof TiBaseActivity) { + ((TiBaseActivity) activity).addOnInstanceStateEventListener(this); + } } /** @@ -122,30 +160,6 @@ private void setBackgroundTransparent(View v) } } - @Override - protected Fragment createFragment() - { - if (proxy == null) { - Fragment map = SupportMapFragment.newInstance(); - if (map instanceof SupportMapFragment) { - ((SupportMapFragment) map).getMapAsync(this); - } - return map; - } else { - boolean zOrderOnTop = TiConvert.toBoolean(proxy.getProperty(MapModule.PROPERTY_ZORDER_ON_TOP), false); - GoogleMapOptions gOptions = new GoogleMapOptions(); - gOptions.zOrderOnTop(zOrderOnTop); - if (this.liteMode) { - gOptions.liteMode(true); - } - Fragment map = SupportMapFragment.newInstance(gOptions); - if (map instanceof SupportMapFragment) { - ((SupportMapFragment) map).getMapAsync(this); - } - return map; - } - } - protected void processPreloadRoutes() { ArrayList routes = ((ViewProxy) proxy).getPreloadRoutes(); @@ -1311,6 +1325,17 @@ public void release() timarkers.clear(); mClusterManager = null; mMarkerManager = null; + + if (mMapView != null) { + mMapView.onDestroy(); + mMapView = null; + } + + Activity activity = proxy != null ? proxy.getActivity() : null; + if (activity instanceof TiBaseActivity) { + ((TiBaseActivity) activity).removeOnInstanceStateEventListener(this); + } + super.release(); } @@ -1374,7 +1399,6 @@ public void onCameraIdle() // Intercept the touch event to find out the correct clicksource if clicking // on the info window. - @Override protected boolean interceptTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_UP && selectedAnnotation != null) { @@ -1447,4 +1471,70 @@ public boolean onClusterItemClick(TiMarker tiMarker) { return onMarkerClick(tiMarker.getMarker()); } + + public void onResume() + { + if (mMapView != null) { + if (pendingSavedState != null) { + mMapView.onDestroy(); + mMapView.onCreate(pendingSavedState); + mMapView.onStart(); + pendingSavedState = null; + } + mMapView.onResume(); + } + } + + public void onDestroy() + { + if (mMapView != null) { + mMapView.onDestroy(); + } + Activity activity = proxy != null ? proxy.getActivity() : null; + if (activity instanceof TiBaseActivity) { + ((TiBaseActivity) activity).removeOnInstanceStateEventListener(this); + } + } + + public void onStart() + { + if (mMapView != null) { + mMapView.onStart(); + } + } + + public void onPause() + { + if (mMapView != null) { + mMapView.onPause(); + } + } + + public void onStop() + { + if (mMapView != null) { + mMapView.onStop(); + } + } + + public void setSavedInstanceState(Bundle savedState) + { + this.pendingSavedState = savedState; + } + + @Override + public void onSaveInstanceState(Bundle bundle) + { + if (mMapView != null) { + mMapView.onSaveInstanceState(bundle); + } + } + + @Override + public void onRestoreInstanceState(Bundle bundle) + { + if (mMapView != null) { + pendingSavedState = bundle; + } + } } diff --git a/android/src/ti/map/ViewProxy.java b/android/src/ti/map/ViewProxy.java index a09b9faf..d80d2340 100644 --- a/android/src/ti/map/ViewProxy.java +++ b/android/src/ti/map/ViewProxy.java @@ -7,12 +7,11 @@ package ti.map; import android.app.Activity; +import android.os.Bundle; import android.os.Message; import com.google.android.gms.maps.CameraUpdate; import com.google.android.gms.maps.GoogleMap; -import com.google.android.gms.maps.MapView; import com.google.android.gms.maps.model.LatLng; -import com.google.android.gms.maps.model.TileOverlay; import com.google.android.gms.maps.model.TileOverlayOptions; import com.google.maps.android.heatmaps.HeatmapTileProvider; import java.util.ArrayList; @@ -110,7 +109,7 @@ public ViewProxy() @Override public TiUIView createView(Activity activity) { - return new TiUIMapView(this, activity); + return new TiUIMapView(this); } public void clearPreloadObjects() @@ -122,6 +121,66 @@ public void clearPreloadObjects() preloadTileOverlayOptionsList.clear(); } + @Override + public void onCreate(Activity activity, Bundle savedInstanceState) + { + super.onCreate(activity, savedInstanceState); + TiUIView view = peekView(); + if (view instanceof TiUIMapView) { + ((TiUIMapView) view).setSavedInstanceState(savedInstanceState); + } + } + + @Override + public void onDestroy(Activity activity) + { + super.onDestroy(activity); + TiUIView view = peekView(); + if (view instanceof TiUIMapView) { + ((TiUIMapView) view).onDestroy(); + } + } + + @Override + public void onResume(Activity activity) + { + super.onResume(activity); + TiUIView view = peekView(); + if (view instanceof TiUIMapView) { + ((TiUIMapView) view).onResume(); + } + } + + @Override + public void onStart(Activity activity) + { + super.onStart(activity); + TiUIView view = peekView(); + if (view instanceof TiUIMapView) { + ((TiUIMapView) view).onStart(); + } + } + + @Override + public void onPause(Activity activity) + { + super.onPause(activity); + TiUIView view = peekView(); + if (view instanceof TiUIMapView) { + ((TiUIMapView) view).onPause(); + } + } + + @Override + public void onStop(Activity activity) + { + super.onStop(activity); + TiUIView view = peekView(); + if (view instanceof TiUIMapView) { + ((TiUIMapView) view).onStop(); + } + } + @Override public boolean handleMessage(Message msg) {