Skip to content

Commit

Permalink
Merge pull request #130 from hieupham007/timob-19726
Browse files Browse the repository at this point in the history
[TIMOB-19726]: Refactor module to use getMapAsync
  • Loading branch information
ashcoding committed Oct 19, 2015
2 parents 226e9b1 + aba06c6 commit 27d3a27
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
Binary file not shown.
2 changes: 2 additions & 0 deletions android/documentation/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Change Log
<pre>
v2.3.5 Refactor module to use getMapAsync [TIMOB-19726]
v2.3.4 Recompiled map with NDK r10e [TIMOB-19681]
v2.3.3 Update toImage() signature [TIMOB-19314]
Strip down Google Play Services library to include only maps components [TIMOB-18082]

Expand Down
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: 2.3.4
version: 2.3.5
apiversion: 2
architectures: armeabi armeabi-v7a x86
description: External version of Map module to support new Google Map v2 sdk
Expand Down
47 changes: 21 additions & 26 deletions android/src/ti/map/TiUIMapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.Circle;
Expand All @@ -49,7 +50,7 @@

public class TiUIMapView extends TiUIFragment implements GoogleMap.OnMarkerClickListener, GoogleMap.OnMapClickListener,
GoogleMap.OnCameraChangeListener, GoogleMap.OnMarkerDragListener, GoogleMap.OnInfoWindowClickListener, GoogleMap.InfoWindowAdapter,
GoogleMap.OnMapLongClickListener, GoogleMap.OnMapLoadedCallback
GoogleMap.OnMapLongClickListener, GoogleMap.OnMapLoadedCallback, OnMapReadyCallback
{

private static final String TAG = "TiUIMapView";
Expand Down Expand Up @@ -97,13 +98,21 @@ private void setBackgroundTransparent(View v) {
@Override
protected Fragment createFragment() {
if (proxy == null) {
return SupportMapFragment.newInstance();
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);
proxy.getProperty(MapModule.PROPERTY_ZORDER_ON_TOP), false);
GoogleMapOptions gOptions = new GoogleMapOptions();
gOptions.zOrderOnTop(zOrderOnTop);
return SupportMapFragment.newInstance(gOptions);
Fragment map = SupportMapFragment.newInstance(gOptions);
if (map instanceof SupportMapFragment) {
((SupportMapFragment)map).getMapAsync(this);
}
return map;
}
}

Expand Down Expand Up @@ -141,23 +150,8 @@ protected void processPreloadPolylines() {
}

@Override
protected void onViewCreated() {
map = acquireMap();

if (map == null && retries < 10) {
Log.w(TAG, "Cannot load map. Retrying");
sendMessage();
retries++;
return;
}

if (map == null) {
Log.e(TAG, "Unable to load map");
return;
}

//successfully loaded map
retries = 0;
public void onMapReady(GoogleMap gMap) {
map = gMap;

//A workaround for https://code.google.com/p/android/issues/detail?id=11676 pre Jelly Bean.
//This problem doesn't exist on 4.1+ since the map base view changes to TextureView from SurfaceView.
Expand Down Expand Up @@ -186,7 +180,7 @@ protected void onViewCreated() {
public void processProperties(KrollDict d) {
super.processProperties(d);

if (acquireMap() == null) {
if (map == null) {
return;
}
processMapProperties(d);
Expand Down Expand Up @@ -274,10 +268,6 @@ public void propertyChanged(String key, Object oldValue, Object newValue,
}
}

public GoogleMap acquireMap() {
return ((SupportMapFragment) getFragment()).getMap();
}

public GoogleMap getMap() {
return map;
}
Expand Down Expand Up @@ -979,4 +969,9 @@ public void onSnapshotReady(Bitmap snapshot) {
public void onMapLoaded() {
proxy.fireEvent(TiC.EVENT_COMPLETE, null);
}

protected void onViewCreated() {
// keep around for backward compatibility
}

}

0 comments on commit 27d3a27

Please sign in to comment.