Smaller fixes to Maps API

- Add support for getMapAsync in MapFragment
- Add support for remote and vector resources
This commit is contained in:
Marvin W 2016-03-14 19:11:53 +01:00
parent 2e8857258c
commit 51b8d384a1
4 changed files with 98 additions and 38 deletions

View File

@ -253,7 +253,7 @@ public class GoogleMapImpl extends IGoogleMapDelegate.Stub
try { try {
onCameraChangeListener.onCameraChange(cameraPosition); onCameraChangeListener.onCameraChange(cameraPosition);
} catch (RemoteException e) { } catch (RemoteException e) {
e.printStackTrace(); Log.w(TAG, e);
} }
} }
} }
@ -485,53 +485,58 @@ public class GoogleMapImpl extends IGoogleMapDelegate.Stub
@Override @Override
public void setOnCameraChangeListener(IOnCameraChangeListener listener) throws RemoteException { public void setOnCameraChangeListener(IOnCameraChangeListener listener) throws RemoteException {
Log.d(TAG, "setOnCameraChangeListener");
this.onCameraChangeListener = listener; this.onCameraChangeListener = listener;
} }
@Override @Override
public void setOnMapClickListener(IOnMapClickListener listener) throws RemoteException { public void setOnMapClickListener(IOnMapClickListener listener) throws RemoteException {
Log.d(TAG, "setOnMapClickListener: not supported");
} }
@Override @Override
public void setOnMapLongClickListener(IOnMapLongClickListener listener) throws RemoteException { public void setOnMapLongClickListener(IOnMapLongClickListener listener) throws RemoteException {
Log.d(TAG, "setOnMapLongClickListener: not supported");
} }
@Override @Override
public void setOnMarkerClickListener(IOnMarkerClickListener listener) throws RemoteException { public void setOnMarkerClickListener(IOnMarkerClickListener listener) throws RemoteException {
Log.d(TAG, "setOnMarkerClickListener");
this.onMarkerClickListener = listener; this.onMarkerClickListener = listener;
} }
@Override @Override
public void setOnMarkerDragListener(IOnMarkerDragListener listener) throws RemoteException { public void setOnMarkerDragListener(IOnMarkerDragListener listener) throws RemoteException {
Log.d(TAG, "setOnMarkerDragListener");
this.onMarkerDragListener = listener; this.onMarkerDragListener = listener;
} }
@Override @Override
public void setOnInfoWindowClickListener(IOnInfoWindowClickListener listener) public void setOnInfoWindowClickListener(IOnInfoWindowClickListener listener)
throws RemoteException { throws RemoteException {
Log.d(TAG, "setOnInfoWindowClickListener: not supported");
} }
@Override @Override
public void setOnMyLocationChangeListener(IOnMyLocationChangeListener listener) public void setOnMyLocationChangeListener(IOnMyLocationChangeListener listener)
throws RemoteException { throws RemoteException {
Log.d(TAG, "setOnMyLocationChangeListener");
this.onMyLocationChangeListener = listener; this.onMyLocationChangeListener = listener;
} }
@Override @Override
public void setOnMyLocationButtonClickListener(IOnMyLocationButtonClickListener listener) public void setOnMyLocationButtonClickListener(IOnMyLocationButtonClickListener listener)
throws RemoteException { throws RemoteException {
Log.d(TAG, "setOnMyLocationButtonClickListener: not supported");
} }
@Override @Override
public void setOnMapLoadedCallback(final IOnMapLoadedCallback callback) throws RemoteException { public void setOnMapLoadedCallback(final IOnMapLoadedCallback callback) throws RemoteException {
Log.d(TAG, "not yet usable: setOnMapLoadedCallback"); Log.d(TAG, "setOnMapLoadedCallback");
new Handler(context.getMainLooper()).postDelayed(new Runnable() { new Handler(context.getMainLooper()).postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
Log.d(TAG, "Announce map loaded");
try { try {
callback.onMapLoaded(); callback.onMapLoaded();
} catch (RemoteException e) { } catch (RemoteException e) {

View File

@ -19,18 +19,23 @@ package org.microg.gms.maps;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Parcel;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.google.android.gms.dynamic.IObjectWrapper; import com.google.android.gms.dynamic.IObjectWrapper;
import com.google.android.gms.dynamic.ObjectWrapper; import com.google.android.gms.dynamic.ObjectWrapper;
import com.google.android.gms.maps.GoogleMapOptions; import com.google.android.gms.maps.GoogleMapOptions;
import com.google.android.gms.maps.internal.IGoogleMapDelegate; import com.google.android.gms.maps.internal.IGoogleMapDelegate;
import com.google.android.gms.maps.internal.IMapFragmentDelegate; import com.google.android.gms.maps.internal.IMapFragmentDelegate;
import com.google.android.gms.maps.internal.IOnMapReadyCallback;
public class MapFragmentImpl extends IMapFragmentDelegate.Stub { public class MapFragmentImpl extends IMapFragmentDelegate.Stub {
private static final String TAG = "GmsMapFragImpl";
private GoogleMapImpl map; private GoogleMapImpl map;
private GoogleMapOptions options; private GoogleMapOptions options;
@ -42,6 +47,7 @@ public class MapFragmentImpl extends IMapFragmentDelegate.Stub {
private GoogleMapImpl myMap() { private GoogleMapImpl myMap() {
if (map == null) { if (map == null) {
Log.d(TAG, "GoogleMap instance created");
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
map = new GoogleMapImpl(inflater.getContext(), options); map = new GoogleMapImpl(inflater.getContext(), options);
} }
@ -50,24 +56,34 @@ public class MapFragmentImpl extends IMapFragmentDelegate.Stub {
@Override @Override
public IGoogleMapDelegate getMap() throws RemoteException { public IGoogleMapDelegate getMap() throws RemoteException {
Log.d(TAG, "getMap");
return myMap(); return myMap();
} }
@Override @Override
public void onInflate(IObjectWrapper activity, GoogleMapOptions options, public void onInflate(IObjectWrapper activity, GoogleMapOptions options,
Bundle savedInstanceState) throws RemoteException { Bundle savedInstanceState) throws RemoteException {
Log.d("MapFragmentImpl", "onInflate"); if (options != null) this.options = options;
Log.d(TAG, "onInflate");
} }
@Override @Override
public void onCreate(Bundle savedInstanceState) throws RemoteException { public void onCreate(Bundle savedInstanceState) throws RemoteException {
Log.d(TAG, "onCreate");
//myMap().onCreate(savedInstanceState); //myMap().onCreate(savedInstanceState);
Log.d("MapFragmentImpl", "onCreate"); // TOOD: Certainly does not belong here and this way
Bundle mapState = savedInstanceState.getBundle("map_state");
if (mapState != null) {
mapState.setClassLoader(GoogleMapOptions.class.getClassLoader());
GoogleMapOptions options = mapState.getParcelable("MapOptions");
if (options != null) this.options = options;
}
} }
@Override @Override
public IObjectWrapper onCreateView(IObjectWrapper layoutInflater, IObjectWrapper container, public IObjectWrapper onCreateView(IObjectWrapper layoutInflater, IObjectWrapper container,
Bundle savedInstanceState) throws RemoteException { Bundle savedInstanceState) throws RemoteException {
Log.d(TAG, "onCreateView");
if (map == null) { if (map == null) {
LayoutInflater inflater = (LayoutInflater) ObjectWrapper.unwrap(layoutInflater); LayoutInflater inflater = (LayoutInflater) ObjectWrapper.unwrap(layoutInflater);
map = new GoogleMapImpl(inflater.getContext(), options); map = new GoogleMapImpl(inflater.getContext(), options);
@ -83,37 +99,62 @@ public class MapFragmentImpl extends IMapFragmentDelegate.Stub {
@Override @Override
public void onResume() throws RemoteException { public void onResume() throws RemoteException {
Log.d(TAG, "onResume");
myMap().onResume(); myMap().onResume();
} }
@Override @Override
public void onPause() throws RemoteException { public void onPause() throws RemoteException {
Log.d(TAG, "onPause");
myMap().onPause(); myMap().onPause();
} }
@Override @Override
public void onDestroyView() throws RemoteException { public void onDestroyView() throws RemoteException {
Log.d(TAG, "onDestroyView");
} }
@Override @Override
public void onDestroy() throws RemoteException { public void onDestroy() throws RemoteException {
Log.d(TAG, "onDestroy");
myMap().onDestroy(); myMap().onDestroy();
} }
@Override @Override
public void onLowMemory() throws RemoteException { public void onLowMemory() throws RemoteException {
Log.d(TAG, "onLowMemory");
} }
@Override @Override
public void onSaveInstanceState(Bundle outState) throws RemoteException { public void onSaveInstanceState(Bundle outState) throws RemoteException {
Log.d(TAG, "onSaveInstanceState: " + outState);
//myMap().onSaveInstanceState(outState); //myMap().onSaveInstanceState(outState);
} }
@Override @Override
public boolean isReady() throws RemoteException { public boolean isReady() throws RemoteException {
Log.d("MapFragmentImpl", "isReady"); Log.d(TAG, "isReady");
return map != null;
}
@Override
public void getMapAsync(final IOnMapReadyCallback callback) throws RemoteException {
new Handler(context.getMainLooper()).post(new Runnable() {
@Override
public void run() {
try {
callback.onMapReady(myMap());
} catch (RemoteException e) {
Log.w(TAG, e);
}
}
});
}
@Override
public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
if (super.onTransact(code, data, reply, flags)) return true;
Log.d(TAG, "onTransact [unknown]: " + code + ", " + data + ", " + flags);
return false; return false;
} }
} }

View File

@ -38,7 +38,6 @@ public class MapViewImpl extends IMapViewDelegate.Stub {
private GoogleMapOptions options; private GoogleMapOptions options;
private Context context; private Context context;
private IOnMapReadyCallback readyCallback; private IOnMapReadyCallback readyCallback;
private boolean isReady = false;
public MapViewImpl(Context context, GoogleMapOptions options) { public MapViewImpl(Context context, GoogleMapOptions options) {
this.context = context; this.context = context;
@ -47,6 +46,7 @@ public class MapViewImpl extends IMapViewDelegate.Stub {
private GoogleMapImpl myMap() { private GoogleMapImpl myMap() {
if (map == null) { if (map == null) {
Log.d(TAG, "GoogleMap instance created");
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
map = new GoogleMapImpl(inflater.getContext(), options); map = new GoogleMapImpl(inflater.getContext(), options);
} }
@ -55,6 +55,7 @@ public class MapViewImpl extends IMapViewDelegate.Stub {
@Override @Override
public IGoogleMapDelegate getMap() throws RemoteException { public IGoogleMapDelegate getMap() throws RemoteException {
Log.d(TAG, "getMap");
return myMap(); return myMap();
} }
@ -67,9 +68,6 @@ public class MapViewImpl extends IMapViewDelegate.Stub {
@Override @Override
public void onResume() throws RemoteException { public void onResume() throws RemoteException {
Log.d(TAG, "onResume"); Log.d(TAG, "onResume");
synchronized (this) {
isReady = true;
}
myMap().onResume(); myMap().onResume();
if (readyCallback != null) { if (readyCallback != null) {
@ -84,25 +82,24 @@ public class MapViewImpl extends IMapViewDelegate.Stub {
@Override @Override
public void onPause() throws RemoteException { public void onPause() throws RemoteException {
Log.d(TAG, "onPause");
myMap().onPause(); myMap().onPause();
synchronized (this) {
isReady = false;
}
} }
@Override @Override
public void onDestroy() throws RemoteException { public void onDestroy() throws RemoteException {
Log.d(TAG, "onDestroy");
myMap().onDestroy(); myMap().onDestroy();
} }
@Override @Override
public void onLowMemory() throws RemoteException { public void onLowMemory() throws RemoteException {
Log.d(TAG, "onLowMemory");
} }
@Override @Override
public void onSaveInstanceState(Bundle outState) throws RemoteException { public void onSaveInstanceState(Bundle outState) throws RemoteException {
Log.d(TAG, "onSaveInstanceState: " + outState);
} }
@Override @Override
@ -111,22 +108,19 @@ public class MapViewImpl extends IMapViewDelegate.Stub {
} }
@Override @Override
public synchronized void addOnMapReadyCallback(final IOnMapReadyCallback callback) throws RemoteException { public void getMapAsync(final IOnMapReadyCallback callback) throws RemoteException {
if (!isReady) { Log.d(TAG, "getMapAsync");
this.readyCallback = callback;
} else {
new Handler(context.getMainLooper()).post(new Runnable() { new Handler(context.getMainLooper()).post(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
callback.onMapReady(map); callback.onMapReady(myMap());
} catch (RemoteException e) { } catch (RemoteException e) {
Log.w(TAG, e); Log.w(TAG, e);
} }
} }
}); });
} }
}
@Override @Override
public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException { public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {

View File

@ -18,7 +18,10 @@ package org.microg.gms.maps.bitmap;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
public class ResourceBitmapDescriptor extends AbstractBitmapDescriptor { public class ResourceBitmapDescriptor extends AbstractBitmapDescriptor {
private int resourceId; private int resourceId;
@ -29,6 +32,23 @@ public class ResourceBitmapDescriptor extends AbstractBitmapDescriptor {
@Override @Override
public Bitmap generateBitmap(Context context) { public Bitmap generateBitmap(Context context) {
return BitmapFactory.decodeResource(context.getResources(), resourceId); return drawableToBitmap(context, ContextCompat.getDrawable(context.getApplicationContext(), resourceId));
}
public static Bitmap drawableToBitmap(Context context, Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
return DefaultBitmapDescriptor.DEFAULT_DESCRIPTOR.loadBitmap(context);
}
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
} }
} }