mirror of
https://github.com/YTVanced/VancedMicroG
synced 2024-11-27 21:53:00 +00:00
Smaller fixes to Maps API
- Add support for getMapAsync in MapFragment - Add support for remote and vector resources
This commit is contained in:
parent
2e8857258c
commit
51b8d384a1
4 changed files with 98 additions and 38 deletions
|
@ -253,7 +253,7 @@ public class GoogleMapImpl extends IGoogleMapDelegate.Stub
|
|||
try {
|
||||
onCameraChangeListener.onCameraChange(cameraPosition);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -485,53 +485,58 @@ public class GoogleMapImpl extends IGoogleMapDelegate.Stub
|
|||
|
||||
@Override
|
||||
public void setOnCameraChangeListener(IOnCameraChangeListener listener) throws RemoteException {
|
||||
Log.d(TAG, "setOnCameraChangeListener");
|
||||
this.onCameraChangeListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnMapClickListener(IOnMapClickListener listener) throws RemoteException {
|
||||
|
||||
Log.d(TAG, "setOnMapClickListener: not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnMapLongClickListener(IOnMapLongClickListener listener) throws RemoteException {
|
||||
|
||||
Log.d(TAG, "setOnMapLongClickListener: not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnMarkerClickListener(IOnMarkerClickListener listener) throws RemoteException {
|
||||
Log.d(TAG, "setOnMarkerClickListener");
|
||||
this.onMarkerClickListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnMarkerDragListener(IOnMarkerDragListener listener) throws RemoteException {
|
||||
Log.d(TAG, "setOnMarkerDragListener");
|
||||
this.onMarkerDragListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnInfoWindowClickListener(IOnInfoWindowClickListener listener)
|
||||
throws RemoteException {
|
||||
|
||||
Log.d(TAG, "setOnInfoWindowClickListener: not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnMyLocationChangeListener(IOnMyLocationChangeListener listener)
|
||||
throws RemoteException {
|
||||
Log.d(TAG, "setOnMyLocationChangeListener");
|
||||
this.onMyLocationChangeListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnMyLocationButtonClickListener(IOnMyLocationButtonClickListener listener)
|
||||
throws RemoteException {
|
||||
|
||||
Log.d(TAG, "setOnMyLocationButtonClickListener: not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
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() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.d(TAG, "Announce map loaded");
|
||||
try {
|
||||
callback.onMapLoaded();
|
||||
} catch (RemoteException e) {
|
||||
|
|
|
@ -19,18 +19,23 @@ package org.microg.gms.maps;
|
|||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Parcel;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.google.android.gms.dynamic.IObjectWrapper;
|
||||
import com.google.android.gms.dynamic.ObjectWrapper;
|
||||
import com.google.android.gms.maps.GoogleMapOptions;
|
||||
import com.google.android.gms.maps.internal.IGoogleMapDelegate;
|
||||
import com.google.android.gms.maps.internal.IMapFragmentDelegate;
|
||||
import com.google.android.gms.maps.internal.IOnMapReadyCallback;
|
||||
|
||||
public class MapFragmentImpl extends IMapFragmentDelegate.Stub {
|
||||
private static final String TAG = "GmsMapFragImpl";
|
||||
|
||||
private GoogleMapImpl map;
|
||||
private GoogleMapOptions options;
|
||||
|
@ -42,6 +47,7 @@ public class MapFragmentImpl extends IMapFragmentDelegate.Stub {
|
|||
|
||||
private GoogleMapImpl myMap() {
|
||||
if (map == null) {
|
||||
Log.d(TAG, "GoogleMap instance created");
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
map = new GoogleMapImpl(inflater.getContext(), options);
|
||||
}
|
||||
|
@ -50,24 +56,34 @@ public class MapFragmentImpl extends IMapFragmentDelegate.Stub {
|
|||
|
||||
@Override
|
||||
public IGoogleMapDelegate getMap() throws RemoteException {
|
||||
Log.d(TAG, "getMap");
|
||||
return myMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInflate(IObjectWrapper activity, GoogleMapOptions options,
|
||||
Bundle savedInstanceState) throws RemoteException {
|
||||
Log.d("MapFragmentImpl", "onInflate");
|
||||
Bundle savedInstanceState) throws RemoteException {
|
||||
if (options != null) this.options = options;
|
||||
Log.d(TAG, "onInflate");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) throws RemoteException {
|
||||
Log.d(TAG, "onCreate");
|
||||
//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
|
||||
public IObjectWrapper onCreateView(IObjectWrapper layoutInflater, IObjectWrapper container,
|
||||
Bundle savedInstanceState) throws RemoteException {
|
||||
Bundle savedInstanceState) throws RemoteException {
|
||||
Log.d(TAG, "onCreateView");
|
||||
if (map == null) {
|
||||
LayoutInflater inflater = (LayoutInflater) ObjectWrapper.unwrap(layoutInflater);
|
||||
map = new GoogleMapImpl(inflater.getContext(), options);
|
||||
|
@ -83,37 +99,62 @@ public class MapFragmentImpl extends IMapFragmentDelegate.Stub {
|
|||
|
||||
@Override
|
||||
public void onResume() throws RemoteException {
|
||||
Log.d(TAG, "onResume");
|
||||
myMap().onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() throws RemoteException {
|
||||
Log.d(TAG, "onPause");
|
||||
myMap().onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() throws RemoteException {
|
||||
|
||||
Log.d(TAG, "onDestroyView");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() throws RemoteException {
|
||||
Log.d(TAG, "onDestroy");
|
||||
myMap().onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() throws RemoteException {
|
||||
|
||||
Log.d(TAG, "onLowMemory");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) throws RemoteException {
|
||||
Log.d(TAG, "onSaveInstanceState: " + outState);
|
||||
//myMap().onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,6 @@ public class MapViewImpl extends IMapViewDelegate.Stub {
|
|||
private GoogleMapOptions options;
|
||||
private Context context;
|
||||
private IOnMapReadyCallback readyCallback;
|
||||
private boolean isReady = false;
|
||||
|
||||
public MapViewImpl(Context context, GoogleMapOptions options) {
|
||||
this.context = context;
|
||||
|
@ -47,6 +46,7 @@ public class MapViewImpl extends IMapViewDelegate.Stub {
|
|||
|
||||
private GoogleMapImpl myMap() {
|
||||
if (map == null) {
|
||||
Log.d(TAG, "GoogleMap instance created");
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
map = new GoogleMapImpl(inflater.getContext(), options);
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ public class MapViewImpl extends IMapViewDelegate.Stub {
|
|||
|
||||
@Override
|
||||
public IGoogleMapDelegate getMap() throws RemoteException {
|
||||
Log.d(TAG, "getMap");
|
||||
return myMap();
|
||||
}
|
||||
|
||||
|
@ -67,9 +68,6 @@ public class MapViewImpl extends IMapViewDelegate.Stub {
|
|||
@Override
|
||||
public void onResume() throws RemoteException {
|
||||
Log.d(TAG, "onResume");
|
||||
synchronized (this) {
|
||||
isReady = true;
|
||||
}
|
||||
|
||||
myMap().onResume();
|
||||
if (readyCallback != null) {
|
||||
|
@ -84,25 +82,24 @@ public class MapViewImpl extends IMapViewDelegate.Stub {
|
|||
|
||||
@Override
|
||||
public void onPause() throws RemoteException {
|
||||
Log.d(TAG, "onPause");
|
||||
myMap().onPause();
|
||||
synchronized (this) {
|
||||
isReady = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() throws RemoteException {
|
||||
Log.d(TAG, "onDestroy");
|
||||
myMap().onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() throws RemoteException {
|
||||
|
||||
Log.d(TAG, "onLowMemory");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) throws RemoteException {
|
||||
|
||||
Log.d(TAG, "onSaveInstanceState: " + outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,21 +108,18 @@ public class MapViewImpl extends IMapViewDelegate.Stub {
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized void addOnMapReadyCallback(final IOnMapReadyCallback callback) throws RemoteException {
|
||||
if (!isReady) {
|
||||
this.readyCallback = callback;
|
||||
} else {
|
||||
new Handler(context.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
callback.onMapReady(map);
|
||||
} catch (RemoteException e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
public void getMapAsync(final IOnMapReadyCallback callback) throws RemoteException {
|
||||
Log.d(TAG, "getMapAsync");
|
||||
new Handler(context.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
callback.onMapReady(myMap());
|
||||
} catch (RemoteException e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,7 +18,10 @@ package org.microg.gms.maps.bitmap;
|
|||
|
||||
import android.content.Context;
|
||||
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 {
|
||||
private int resourceId;
|
||||
|
@ -29,6 +32,23 @@ public class ResourceBitmapDescriptor extends AbstractBitmapDescriptor {
|
|||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue