Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9973d7d3 authored by Fynn Godau's avatar Fynn Godau
Browse files

Merge branch '914-lite-mode' into 'epic67-maps'

Lite Mode

See merge request !63
parents 91132f66 3f8f79f5
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ public final class GoogleMapOptions extends AutoSafeParcelable {
    @SafeParceled(11)
    private boolean rotateGesturesEnabled = true;
    @SafeParceled(12)
    private boolean liteMode = false;
    private int liteMode = 0;
    @SafeParceled(14)
    private boolean mapToobarEnabled = false;
    @SafeParceled(15)
@@ -79,8 +79,9 @@ public final class GoogleMapOptions extends AutoSafeParcelable {
        return boundsForCamera;
    }

    public Boolean getLiteMode() {
        return liteMode;
    public boolean getLiteMode() {
        // Is encoded as `-1` if null, `0` if false, `1` if true. The default is false.
        return liteMode == 1;
    }

    public Boolean getMapToolbarEnabled() {
+144 −0
Original line number Diff line number Diff line
package org.microg.gms.maps.mapbox

import android.content.Context
import android.location.Location
import android.os.Bundle
import android.util.DisplayMetrics
import android.util.Log
import com.google.android.gms.dynamic.IObjectWrapper
import com.google.android.gms.dynamic.ObjectWrapper
import com.google.android.gms.maps.internal.*
import org.microg.gms.maps.MapsConstants
import org.microg.gms.maps.mapbox.model.AbstractMarker
import org.microg.gms.maps.mapbox.model.DefaultInfoWindowAdapter
import org.microg.gms.maps.mapbox.model.InfoWindow
import org.microg.gms.maps.mapbox.utils.MapContext

fun getStyleUriByMapType(mapType: Int) = when (mapType) {
    MapsConstants.MAP_TYPE_SATELLITE -> "mapbox://styles/microg/cjxgloted25ap1ct4uex7m6hi"
    MapsConstants.MAP_TYPE_TERRAIN -> "mapbox://styles/mapbox/outdoors-v12"
    MapsConstants.MAP_TYPE_HYBRID -> "mapbox://styles/microg/cjxgloted25ap1ct4uex7m6hi"
    //MAP_TYPE_NONE, MAP_TYPE_NORMAL,
    else -> "mapbox://styles/microg/cjui4020201oo1fmca7yuwbor"
}

abstract class AbstractGoogleMap(context: Context) : IGoogleMapDelegate.Stub() {

    internal val mapContext = MapContext(context)

    val dpiFactor: Float
        get() = mapContext.resources.displayMetrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT

    internal var currentInfoWindow: InfoWindow? = null
    internal var infoWindowAdapter: IInfoWindowAdapter = DefaultInfoWindowAdapter(mapContext)
    internal var onInfoWindowClickListener: IOnInfoWindowClickListener? = null
    internal var onInfoWindowLongClickListener: IOnInfoWindowLongClickListener? = null
    internal var onInfoWindowCloseListener: IOnInfoWindowCloseListener? = null

    internal var mapClickListener: IOnMapClickListener? = null
    internal var mapLongClickListener: IOnMapLongClickListener? = null
    internal var markerClickListener: IOnMarkerClickListener? = null
    internal var circleClickListener: IOnCircleClickListener? = null


    internal abstract fun showInfoWindow(marker: AbstractMarker): Boolean

    override fun setOnInfoWindowClickListener(listener: IOnInfoWindowClickListener?) {
        onInfoWindowClickListener = listener
    }

    override fun setInfoWindowLongClickListener(listener: IOnInfoWindowLongClickListener) {
        onInfoWindowLongClickListener = listener
    }

    override fun setInfoWindowCloseListener(listener: IOnInfoWindowCloseListener) {
        onInfoWindowCloseListener = listener
    }

    override fun setInfoWindowAdapter(adapter: IInfoWindowAdapter?) {
        infoWindowAdapter = adapter ?: DefaultInfoWindowAdapter(mapContext)
    }

    override fun setOnMapClickListener(listener: IOnMapClickListener?) {
        mapClickListener = listener
    }

    override fun setOnMapLongClickListener(listener: IOnMapLongClickListener?) {
        mapLongClickListener = listener
    }

    override fun setOnMarkerClickListener(listener: IOnMarkerClickListener?) {
        markerClickListener = listener
    }

    override fun setCircleClickListener(listener: IOnCircleClickListener?) {
        circleClickListener = listener
    }

    override fun getMyLocation(): Location? {
        Log.d(TAG, "unimplemented Method: getMyLocation")
        return null
    }

    override fun setLocationSource(locationSource: ILocationSourceDelegate?) {
        Log.d(TAG, "unimplemented Method: setLocationSource")
    }

    override fun setOnMyLocationChangeListener(listener: IOnMyLocationChangeListener?) {
        Log.d(TAG, "unimplemented Method: setOnMyLocationChangeListener")
    }

    override fun setOnMyLocationButtonClickListener(listener: IOnMyLocationButtonClickListener?) {
        Log.d(TAG, "unimplemented Method: setOnMyLocationButtonClickListener")
    }

    override fun getTestingHelper(): IObjectWrapper {
        Log.d(TAG, "unimplemented Method: getTestingHelper")
        return ObjectWrapper.wrap(null)
    }

    override fun isBuildingsEnabled(): Boolean {
        Log.d(TAG, "unimplemented Method: isBuildingsEnabled")
        return false
    }

    override fun setBuildingsEnabled(buildings: Boolean) {
        Log.d(TAG, "unimplemented Method: setBuildingsEnabled")
    }

    override fun useViewLifecycleWhenInFragment(): Boolean {
        Log.d(TAG, "unimplemented Method: useViewLifecycleWhenInFragment")
        return false
    }

    override fun onEnterAmbient(bundle: Bundle?) {
        Log.d(TAG, "unimplemented Method: onEnterAmbient")
    }

    override fun onExitAmbient() {
        Log.d(TAG, "unimplemented Method: onExitAmbient")
    }

    override fun isTrafficEnabled(): Boolean {
        Log.d(TAG, "unimplemented Method: isTrafficEnabled")
        return false
    }

    override fun setTrafficEnabled(traffic: Boolean) {
        Log.d(TAG, "unimplemented Method: setTrafficEnabled")

    }

    override fun isIndoorEnabled(): Boolean {
        Log.d(TAG, "unimplemented Method: isIndoorEnabled")
        return false
    }

    override fun setIndoorEnabled(indoor: Boolean) {
        Log.d(TAG, "unimplemented Method: setIndoorEnabled")
    }

    companion object {
        val TAG = "GmsMapAbstract"
    }
}
 No newline at end of file
+6 −1
Original line number Diff line number Diff line
@@ -17,16 +17,21 @@
package org.microg.gms.maps.mapbox

import android.util.Log
import com.google.android.gms.maps.internal.IGoogleMapDelegate
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.camera.CameraUpdate
import com.mapbox.mapboxsdk.geometry.LatLngBounds
import com.mapbox.mapboxsdk.maps.MapboxMap
import java.util.*

internal class CameraBoundsWithSizeUpdate(val bounds: LatLngBounds, val width: Int, val height: Int, val padding: IntArray) : CameraUpdate {
internal class CameraBoundsWithSizeUpdate(val bounds: LatLngBounds, val width: Int, val height: Int, val padding: IntArray) : LiteModeCameraUpdate, CameraUpdate {

    constructor(bounds: LatLngBounds, width: Int, height: Int, paddingLeft: Int, paddingTop: Int = paddingLeft, paddingRight: Int = paddingLeft, paddingBottom: Int = paddingTop) : this(bounds, width, height, intArrayOf(paddingLeft, paddingTop, paddingRight, paddingBottom)) {}

    override fun getLiteModeCameraPosition(map: IGoogleMapDelegate) = null

    override fun getLiteModeCameraBounds() = bounds

    override fun getCameraPosition(map: MapboxMap): CameraPosition? {
        val padding = this.padding.clone()

+95 −12
Original line number Diff line number Diff line
@@ -17,11 +17,13 @@
package org.microg.gms.maps.mapbox

import android.graphics.Point
import android.graphics.PointF
import android.os.Parcel
import android.util.Log
import com.google.android.gms.dynamic.IObjectWrapper
import com.google.android.gms.dynamic.ObjectWrapper
import com.google.android.gms.maps.internal.ICameraUpdateFactoryDelegate
import com.google.android.gms.maps.internal.IGoogleMapDelegate
import com.google.android.gms.maps.model.CameraPosition
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.LatLngBounds
@@ -32,29 +34,40 @@ import org.microg.gms.maps.mapbox.utils.toMapbox

class CameraUpdateFactoryImpl : ICameraUpdateFactoryDelegate.Stub() {

    override fun zoomIn(): IObjectWrapper = ObjectWrapper.wrap(CameraUpdateFactory.zoomIn())
    override fun zoomOut(): IObjectWrapper = ObjectWrapper.wrap(CameraUpdateFactory.zoomOut())
    override fun zoomIn(): IObjectWrapper = ObjectWrapper.wrap(ZoomByCameraUpdate(1f))
    override fun zoomOut(): IObjectWrapper = ObjectWrapper.wrap(ZoomByCameraUpdate(-1f))

    override fun zoomTo(zoom: Float): IObjectWrapper =
            ObjectWrapper.wrap(CameraUpdateFactory.zoomTo(zoom.toDouble() - 1.0))
    override fun zoomTo(zoom: Float): IObjectWrapper = ObjectWrapper.wrap(ZoomToCameraUpdate(zoom))

    override fun zoomBy(zoomDelta: Float): IObjectWrapper =
            ObjectWrapper.wrap(CameraUpdateFactory.zoomBy(zoomDelta.toDouble()))
            ObjectWrapper.wrap(ZoomByCameraUpdate(zoomDelta)).also {
                Log.d(TAG, "zoomBy")
            }

    override fun zoomByWithFocus(zoomDelta: Float, x: Int, y: Int): IObjectWrapper =
            ObjectWrapper.wrap(CameraUpdateFactory.zoomBy(zoomDelta.toDouble(), Point(x, y)))
            ObjectWrapper.wrap(ZoomByWithFocusCameraUpdate(zoomDelta, x, y)).also {
                Log.d(TAG, "zoomByWithFocus")
            }

    override fun newCameraPosition(cameraPosition: CameraPosition): IObjectWrapper =
            ObjectWrapper.wrap(CameraUpdateFactory.newCameraPosition(cameraPosition.toMapbox()))
            ObjectWrapper.wrap(NewCameraPositionCameraUpdate(cameraPosition)).also {
                Log.d(TAG, "newCameraPosition")
            }

    override fun newLatLng(latLng: LatLng): IObjectWrapper =
            ObjectWrapper.wrap(CameraUpdateFactory.newLatLng(latLng.toMapbox()))
            ObjectWrapper.wrap(NewLatLngCameraUpdate(latLng)).also {
                Log.d(TAG, "newLatLng")
            }

    override fun newLatLngZoom(latLng: LatLng, zoom: Float): IObjectWrapper =
            ObjectWrapper.wrap(CameraUpdateFactory.newLatLngZoom(latLng.toMapbox(), zoom.toDouble() - 1.0))
            ObjectWrapper.wrap(NewLatLngZoomCameraUpdate(latLng, zoom)).also {
                Log.d(TAG, "newLatLngZoom")
            }

    override fun newLatLngBounds(bounds: LatLngBounds, padding: Int): IObjectWrapper =
            ObjectWrapper.wrap(CameraUpdateFactory.newLatLngBounds(bounds.toMapbox(), padding))
            ObjectWrapper.wrap(NewLatLngBoundsCameraUpdate(bounds, padding)).also {
                Log.d(TAG, "newLatLngBounds")
            }

    override fun scrollBy(x: Float, y: Float): IObjectWrapper {
        Log.d(TAG, "unimplemented Method: scrollBy")
@@ -62,7 +75,9 @@ class CameraUpdateFactoryImpl : ICameraUpdateFactoryDelegate.Stub() {
    }

    override fun newLatLngBoundsWithSize(bounds: LatLngBounds, width: Int, height: Int, padding: Int): IObjectWrapper =
        ObjectWrapper.wrap(CameraBoundsWithSizeUpdate(bounds.toMapbox(), width, height, padding))
        ObjectWrapper.wrap(CameraBoundsWithSizeUpdate(bounds.toMapbox(), width, height, padding)).also {
            Log.d(TAG, "newLatLngBoundsWithSize")
        }

    override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean =
            if (super.onTransact(code, data, reply, flags)) {
@@ -71,9 +86,11 @@ class CameraUpdateFactoryImpl : ICameraUpdateFactoryDelegate.Stub() {
                Log.d(TAG, "onTransact [unknown]: $code, $data, $flags"); false
            }

    private inner class NoCameraUpdate : CameraUpdate {
    private inner class NoCameraUpdate : CameraUpdate, LiteModeCameraUpdate {
        override fun getCameraPosition(mapboxMap: MapboxMap): com.mapbox.mapboxsdk.camera.CameraPosition? =
                mapboxMap.cameraPosition

        override fun getLiteModeCameraPosition(map: IGoogleMapDelegate): CameraPosition = map.cameraPosition
    }

    companion object {
@@ -81,4 +98,70 @@ class CameraUpdateFactoryImpl : ICameraUpdateFactoryDelegate.Stub() {
    }
}

interface LiteModeCameraUpdate {
    fun getLiteModeCameraPosition(map: IGoogleMapDelegate): CameraPosition?

    fun getLiteModeCameraBounds(): com.mapbox.mapboxsdk.geometry.LatLngBounds? = null
}

class ZoomToCameraUpdate(private val zoom: Float) : LiteModeCameraUpdate, CameraUpdate {
    override fun getLiteModeCameraPosition(map: IGoogleMapDelegate): CameraPosition =
        CameraPosition.Builder(map.cameraPosition).zoom(zoom).build()

    override fun getCameraPosition(mapboxMap: MapboxMap): com.mapbox.mapboxsdk.camera.CameraPosition? =
        CameraUpdateFactory.zoomTo(zoom.toDouble() - 1.0).getCameraPosition(mapboxMap)

}

class ZoomByCameraUpdate(private val delta: Float) : LiteModeCameraUpdate, CameraUpdate {
    override fun getLiteModeCameraPosition(map: IGoogleMapDelegate): CameraPosition =
        CameraPosition.Builder(map.cameraPosition).zoom(map.cameraPosition.zoom + delta).build()

    override fun getCameraPosition(mapboxMap: MapboxMap): com.mapbox.mapboxsdk.camera.CameraPosition? =
        CameraUpdateFactory.zoomBy(delta.toDouble()).getCameraPosition(mapboxMap)

}

class ZoomByWithFocusCameraUpdate(private val delta: Float, private val x: Int, private val y: Int) : LiteModeCameraUpdate,
    CameraUpdate {
    override fun getLiteModeCameraPosition(map: IGoogleMapDelegate): CameraPosition =
        CameraPosition.Builder(map.cameraPosition).zoom(map.cameraPosition.zoom + delta)
            .target(map.projection.fromScreenLocation(ObjectWrapper.wrap(PointF(x.toFloat(), y.toFloat())))).build()

    override fun getCameraPosition(mapboxMap: MapboxMap): com.mapbox.mapboxsdk.camera.CameraPosition? =
        CameraUpdateFactory.zoomBy(delta.toDouble(), Point(x, y)).getCameraPosition(mapboxMap)
}

class NewCameraPositionCameraUpdate(private val cameraPosition: CameraPosition) : LiteModeCameraUpdate, CameraUpdate {
    override fun getLiteModeCameraPosition(map: IGoogleMapDelegate): CameraPosition = this.cameraPosition

    override fun getCameraPosition(mapboxMap: MapboxMap): com.mapbox.mapboxsdk.camera.CameraPosition =
        this.cameraPosition.toMapbox()
}

class NewLatLngCameraUpdate(private val latLng: LatLng) : LiteModeCameraUpdate, CameraUpdate {
    override fun getLiteModeCameraPosition(map: IGoogleMapDelegate): CameraPosition =
        CameraPosition.Builder(map.cameraPosition).target(latLng).build()

    override fun getCameraPosition(mapboxMap: MapboxMap): com.mapbox.mapboxsdk.camera.CameraPosition? =
        CameraUpdateFactory.newLatLng(latLng.toMapbox()).getCameraPosition(mapboxMap)
}

class NewLatLngZoomCameraUpdate(private val latLng: LatLng, private val zoom: Float) : LiteModeCameraUpdate, CameraUpdate {
    override fun getLiteModeCameraPosition(map: IGoogleMapDelegate): CameraPosition =
        CameraPosition.Builder(map.cameraPosition).target(latLng).zoom(zoom).build()

    override fun getCameraPosition(mapboxMap: MapboxMap): com.mapbox.mapboxsdk.camera.CameraPosition? =
        CameraUpdateFactory.newLatLngZoom(latLng.toMapbox(), zoom - 1.0).getCameraPosition(mapboxMap)
}

class NewLatLngBoundsCameraUpdate(private val bounds: LatLngBounds, internal val padding: Int) : LiteModeCameraUpdate,
    CameraUpdate {

    override fun getLiteModeCameraPosition(map: IGoogleMapDelegate): CameraPosition? = null

    override fun getLiteModeCameraBounds() = bounds.toMapbox()

    override fun getCameraPosition(mapboxMap: MapboxMap): com.mapbox.mapboxsdk.camera.CameraPosition? =
        CameraUpdateFactory.newLatLngBounds(bounds.toMapbox(), padding).getCameraPosition(mapboxMap)
}
 No newline at end of file
+18 −146

File changed.

Preview size limit exceeded, changes collapsed.

Loading