Skip to content
Open
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
148 changes: 116 additions & 32 deletions android/src/ti/map/TiUIMapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<TiMarker>, ClusterManager.OnClusterItemClickListener<TiMarker>
ClusterManager.OnClusterClickListener<TiMarker>, ClusterManager.OnClusterItemClickListener<TiMarker>,
TiLifecycle.OnInstanceStateEvent
{

public static final String DEFAULT_COLLECTION_ID = "defaultCollection";
Expand All @@ -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<TiMarker> timarkers;
protected AnnotationProxy selectedAnnotation;
private MapView mMapView;

private ArrayList<CircleProxy> currentCircles;
private ArrayList<PolygonProxy> currentPolygons;
Expand All @@ -89,15 +96,45 @@ 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.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<TiMarker>();
currentCircles = new ArrayList<CircleProxy>();
currentPolygons = new ArrayList<PolygonProxy>();
currentPolylines = new ArrayList<PolylineProxy>();
currentImageOverlays = new ArrayList<ImageOverlayProxy>();
proxy.setProperty(MapModule.PROPERTY_INDOOR_ENABLED, true);

Activity activity = proxy.getActivity();
if (activity instanceof TiBaseActivity) {
((TiBaseActivity) activity).addOnInstanceStateEventListener(this);
}
}

/**
Expand All @@ -122,30 +159,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<RouteProxy> routes = ((ViewProxy) proxy).getPreloadRoutes();
Expand Down Expand Up @@ -1374,7 +1387,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) {
Expand Down Expand Up @@ -1447,4 +1459,76 @@ public boolean onClusterItemClick(TiMarker tiMarker)
{
return onMarkerClick(tiMarker.getMarker());
}

public void onResume()
{
if (mMapView != null) {
if (pendingSavedState != null) {
mMapView.onDestroy();
mMapView.onCreate(pendingSavedState);
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 onLowMemory()
{
if (mMapView != null) {
mMapView.onLowMemory();
}
}

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;
}
}
}
75 changes: 72 additions & 3 deletions android/src/ti/map/ViewProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -110,7 +109,7 @@ public ViewProxy()
@Override
public TiUIView createView(Activity activity)
{
return new TiUIMapView(this, activity);
return new TiUIMapView(this);
}

public void clearPreloadObjects()
Expand All @@ -122,6 +121,76 @@ 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 void onLowMemory(Activity activity)
{
super.onLowMemory(activity);
TiUIView view = peekView();
if (view instanceof TiUIMapView) {
((TiUIMapView) view).onLowMemory();
}
}

@Override
public boolean handleMessage(Message msg)
{
Expand Down
Loading