mirror of
https://github.com/TeamVanced/VancedMicroG
synced 2024-11-19 02:29:25 +01:00
Add Projection support
This commit is contained in:
parent
2c2574c6b0
commit
f7b9a6dc3a
@ -29,6 +29,9 @@ public class ObjectWrapper<T> extends IObjectWrapper.Stub {
|
||||
}
|
||||
|
||||
public static Object unwrap(IObjectWrapper obj) {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
if (obj instanceof ObjectWrapper) {
|
||||
return ((ObjectWrapper) obj).t;
|
||||
}
|
||||
|
@ -1,4 +1,11 @@
|
||||
package com.google.android.gms.maps.internal;
|
||||
|
||||
import com.google.android.gms.dynamic.IObjectWrapper;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.VisibleRegion;
|
||||
|
||||
interface IProjectionDelegate {
|
||||
LatLng fromScreenLocation(IObjectWrapper obj);
|
||||
IObjectWrapper toScreenLocation(in LatLng latLng);
|
||||
VisibleRegion getVisibleRegion();
|
||||
}
|
||||
|
@ -73,6 +73,10 @@ public class LatLng implements SafeParcelable {
|
||||
this(1, latitude, longitude);
|
||||
}
|
||||
|
||||
public LatLng(GeoPoint geoPoint) {
|
||||
this(((double) geoPoint.getLatitudeE6()) / 1E6, ((double) geoPoint.getLongitudeE6()) / 1E6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
long lat = Double.doubleToLongBits(latitude);
|
||||
|
@ -35,11 +35,18 @@ public class LatLngBounds implements SafeParcelable {
|
||||
public LatLng southWest;
|
||||
public LatLng northEast;
|
||||
|
||||
public LatLngBounds() {
|
||||
}
|
||||
public LatLngBounds(int versionCode, LatLng southWest, LatLng northEast) {
|
||||
this.versionCode = versionCode;
|
||||
this.southWest = southWest;
|
||||
this.northEast = northEast;
|
||||
}
|
||||
|
||||
private LatLngBounds(Parcel in) {
|
||||
int end = SafeReader.readStart(in);
|
||||
public LatLngBounds(LatLng southWest, LatLng northEast) {
|
||||
this(1, southWest, northEast);
|
||||
}
|
||||
|
||||
private LatLngBounds(Parcel in) {
|
||||
int end = SafeReader.readStart(in);
|
||||
while (in.dataPosition() < end) {
|
||||
int position = SafeReader.readSingleInt(in);
|
||||
switch (SafeReader.halfOf(position)) {
|
||||
|
3
src/com/google/android/gms/maps/model/VisibleRegion.aidl
Normal file
3
src/com/google/android/gms/maps/model/VisibleRegion.aidl
Normal file
@ -0,0 +1,3 @@
|
||||
package com.google.android.gms.maps.model;
|
||||
|
||||
parcelable VisibleRegion;
|
105
src/com/google/android/gms/maps/model/VisibleRegion.java
Normal file
105
src/com/google/android/gms/maps/model/VisibleRegion.java
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2014 μg Project Team
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.android.gms.maps.model;
|
||||
|
||||
import android.os.Parcel;
|
||||
import com.google.android.gms.common.safeparcel.SafeParcelable;
|
||||
import com.google.android.gms.common.safeparcel.SafeReader;
|
||||
import com.google.android.gms.common.safeparcel.SafeWriter;
|
||||
|
||||
public class VisibleRegion implements SafeParcelable {
|
||||
private int versionCode;
|
||||
|
||||
private LatLng nearLeft;
|
||||
private LatLng nearRight;
|
||||
private LatLng farLeft;
|
||||
private LatLng farRight;
|
||||
private LatLngBounds bounds;
|
||||
|
||||
public VisibleRegion(int versionCode, LatLng nearLeft, LatLng nearRight, LatLng farLeft, LatLng farRight, LatLngBounds bounds) {
|
||||
this.versionCode = versionCode;
|
||||
this.nearLeft = nearLeft;
|
||||
this.nearRight = nearRight;
|
||||
this.farLeft = farLeft;
|
||||
this.farRight = farRight;
|
||||
this.bounds = bounds;
|
||||
}
|
||||
|
||||
public VisibleRegion(LatLng nearLeft, LatLng nearRight, LatLng farLeft, LatLng farRight, LatLngBounds bounds) {
|
||||
this(1, nearLeft, nearRight, farLeft, farRight, bounds);
|
||||
}
|
||||
|
||||
public VisibleRegion(Parcel in) {
|
||||
int end = SafeReader.readStart(in);
|
||||
while (in.dataPosition() < end) {
|
||||
int position = SafeReader.readSingleInt(in);
|
||||
switch (SafeReader.halfOf(position)) {
|
||||
case 1:
|
||||
this.versionCode = SafeReader.readInt(in, position);
|
||||
break;
|
||||
case 2:
|
||||
this.nearLeft = SafeReader.readParcelable(in, position, LatLng.CREATOR);
|
||||
break;
|
||||
case 3:
|
||||
this.nearRight = SafeReader.readParcelable(in, position, LatLng.CREATOR);
|
||||
break;
|
||||
case 4:
|
||||
this.farLeft = SafeReader.readParcelable(in, position, LatLng.CREATOR);
|
||||
break;
|
||||
case 5:
|
||||
this.farRight = SafeReader.readParcelable(in, position, LatLng.CREATOR);
|
||||
break;
|
||||
case 6:
|
||||
this.bounds = SafeReader.readParcelable(in, position, LatLngBounds.CREATOR);
|
||||
break;
|
||||
default:
|
||||
SafeReader.skip(in, position);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (in.dataPosition() > end) {
|
||||
throw new SafeReader.ReadException("Overread allowed size end=" + end, in);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
int start = SafeWriter.writeStart(dest);
|
||||
SafeWriter.write(dest, 1, versionCode);
|
||||
SafeWriter.write(dest, 2, nearLeft, flags, false);
|
||||
SafeWriter.write(dest, 3, nearRight, flags, false);
|
||||
SafeWriter.write(dest, 4, farLeft, flags, false);
|
||||
SafeWriter.write(dest, 5, farRight, flags, false);
|
||||
SafeWriter.write(dest, 6, bounds, flags, false);
|
||||
SafeWriter.writeEnd(dest, start);
|
||||
}
|
||||
|
||||
public static Creator<VisibleRegion> CREATOR = new Creator<VisibleRegion>() {
|
||||
public VisibleRegion createFromParcel(Parcel source) {
|
||||
return new VisibleRegion(source);
|
||||
}
|
||||
|
||||
public VisibleRegion[] newArray(int size) {
|
||||
return new VisibleRegion[size];
|
||||
}
|
||||
};
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
package org.microg.gms.maps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
@ -48,11 +49,11 @@ public class GoogleMapImpl {
|
||||
private final ViewGroup view;
|
||||
private final GoogleMapOptions options;
|
||||
private final Delegate delegate = new Delegate();
|
||||
private final Projection projection = new Projection();
|
||||
private MapView mapView;
|
||||
private int mapType = 1;
|
||||
private Context context;
|
||||
private IOnMarkerClickListener markerClickListener;
|
||||
|
||||
public GoogleMapImpl(LayoutInflater inflater, GoogleMapOptions options) {
|
||||
context = inflater.getContext();
|
||||
this.view = new FrameLayout(context);
|
||||
@ -110,8 +111,7 @@ public class GoogleMapImpl {
|
||||
@Override
|
||||
public CameraPosition getCameraPosition() throws RemoteException {
|
||||
if (mapView == null) return null;
|
||||
LatLng center = new LatLng(mapView.getMapCenter().getLatitudeE6() / 1E6F, mapView.getMapCenter().getLongitudeE6() / 1E6F);
|
||||
return new CameraPosition(center, mapView.getZoomLevel(), 0, 0);
|
||||
return new CameraPosition(new LatLng(mapView.getMapCenter()), mapView.getZoomLevel(), 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -247,7 +247,7 @@ public class GoogleMapImpl {
|
||||
|
||||
@Override
|
||||
public IProjectionDelegate getProjection() throws RemoteException {
|
||||
return null;
|
||||
return projection;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -428,4 +428,28 @@ public class GoogleMapImpl {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class Projection extends IProjectionDelegate.Stub {
|
||||
|
||||
@Override
|
||||
public IObjectWrapper toScreenLocation(LatLng latLng) throws RemoteException {
|
||||
return ObjectWrapper.wrap(mapView.getProjection().toPixels(latLng.toGeoPoint(), null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LatLng fromScreenLocation(IObjectWrapper obj) throws RemoteException {
|
||||
Point point = (Point) ObjectWrapper.unwrap(obj);
|
||||
return new LatLng(mapView.getProjection().fromPixels(point.x, point.y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibleRegion getVisibleRegion() throws RemoteException {
|
||||
LatLng nearLeft = new LatLng(mapView.getProjection().fromPixels(0, mapView.getHeight()));
|
||||
LatLng nearRight = new LatLng(mapView.getProjection().fromPixels(mapView.getWidth(), mapView.getHeight()));
|
||||
LatLng farLeft = new LatLng(mapView.getProjection().fromPixels(0, 0));
|
||||
LatLng farRight = new LatLng(mapView.getProjection().fromPixels(mapView.getWidth(), 0));
|
||||
|
||||
return new VisibleRegion(nearLeft, nearRight, farLeft, farRight, new LatLngBounds(farRight, nearLeft));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user