[android] Added guides core

This commit is contained in:
Dmitry Donskoy 2020-04-24 01:49:19 +03:00 committed by Aleksandr Zatsepin
parent c064fc640d
commit 7d90525420
12 changed files with 196 additions and 3 deletions

View file

@ -54,6 +54,7 @@ set(
com/mapswithme/maps/editor/OsmOAuth.cpp
com/mapswithme/maps/Framework.cpp
com/mapswithme/maps/guides/Guides.cpp
com/mapswithme/maps/guides/GuidesManager.cpp
com/mapswithme/maps/isolines/IsolinesManager.cpp
com/mapswithme/maps/LightFramework.cpp
com/mapswithme/maps/LocationHelper.cpp

View file

@ -125,6 +125,7 @@ Framework::Framework()
m_work.GetTrafficManager().SetStateListener(bind(&Framework::TrafficStateChanged, this, _1));
m_work.GetTransitManager().SetStateListener(bind(&Framework::TransitSchemeStateChanged, this, _1));
m_work.GetIsolinesManager().SetStateListener(bind(&Framework::IsolinesSchemeStateChanged, this, _1));
m_work.GetGuidesManager().SetStateListener(bind(&Framework::GuidesSchemeStateChanged, this, _1));
m_work.GetPowerManager().Subscribe(this);
}
@ -176,6 +177,12 @@ void Framework::IsolinesSchemeStateChanged(IsolinesManager::IsolinesState state)
m_onIsolinesStateChangedFn(state);
}
void Framework::GuidesSchemeStateChanged(GuidesManager::GuidesState state)
{
if (m_onGuidesStateChangedFn)
m_onGuidesStateChangedFn(state);
}
bool Framework::DestroySurfaceOnDetach()
{
if (m_vulkanContextFactory)
@ -626,6 +633,11 @@ void Framework::SetIsolinesListener(IsolinesManager::IsolinesStateChangedFn cons
m_onIsolinesStateChangedFn = function;
}
void Framework::SetGuidesListener(GuidesManager::GuidesStateChangedFn const & function)
{
m_onGuidesStateChangedFn = function;
}
bool Framework::IsTrafficEnabled()
{
return m_work.GetTrafficManager().IsEnabled();
@ -1785,6 +1797,20 @@ Java_com_mapswithme_maps_Framework_nativeIsIsolinesLayerEnabled(JNIEnv * env, jc
return static_cast<jboolean>(frm()->LoadIsolinesEnabled());
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeSetGuidesLayerEnabled(JNIEnv * env, jclass, jboolean enabled)
{
auto const value = static_cast<bool>(enabled);
frm()->GetGuidesManager().SetEnabled(value);
frm()->SaveGuidesEnabled(value);
}
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_Framework_nativeIsGuidesLayerEnabled(JNIEnv * env, jclass)
{
return static_cast<jboolean>(frm()->LoadGuidesEnabled());
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_Framework_nativeSaveSettingSchemeEnabled(JNIEnv * env, jclass, jboolean enabled)
{

View file

@ -71,6 +71,7 @@ namespace android
void TrafficStateChanged(TrafficManager::TrafficState state);
void TransitSchemeStateChanged(TransitReadManager::TransitSchemeState state);
void IsolinesSchemeStateChanged(IsolinesManager::IsolinesState state);
void GuidesSchemeStateChanged(GuidesManager::GuidesState state);
void MyPositionModeChanged(location::EMyPositionMode mode, bool routingActive);
@ -81,6 +82,7 @@ namespace android
TrafficManager::TrafficStateChangedFn m_onTrafficStateChangedFn;
TransitReadManager::TransitStateChangedFn m_onTransitStateChangedFn;
IsolinesManager::IsolinesStateChangedFn m_onIsolinesStateChangedFn;
GuidesManager::GuidesStateChangedFn m_onGuidesStateChangedFn;
bool m_isChoosePositionMode;
@ -171,6 +173,8 @@ namespace android
void SetTrafficStateListener(TrafficManager::TrafficStateChangedFn const & fn);
void SetTransitSchemeListener(TransitReadManager::TransitStateChangedFn const & fn);
void SetIsolinesListener(IsolinesManager::IsolinesStateChangedFn const & fn);
void SetGuidesListener(GuidesManager::GuidesStateChangedFn const & fn);
bool IsTrafficEnabled();
void EnableTraffic();
void DisableTraffic();

View file

@ -0,0 +1,36 @@
#include <jni.h>
#include "com/mapswithme/maps/Framework.hpp"
#include "com/mapswithme/core/jni_helper.hpp"
#include "com/mapswithme/platform/Platform.hpp"
using namespace std::placeholders;
extern "C"
{
static void GuidesStateChanged(GuidesManager::GuidesState state,
std::shared_ptr<jobject> const & listener)
{
LOG(LINFO, (static_cast<int>(state)));
JNIEnv * env = jni::GetEnv();
env->CallVoidMethod(*listener,
jni::GetMethodID(env, *listener, "onStateChanged", "(I)V"),
static_cast<jint>(state));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_maplayer_Guides_GuidesManager_nativeAddListener(JNIEnv *env, jclass clazz, jobject listener)
{
CHECK(g_framework, ("Framework isn't created yet!"));
g_framework->SetGuidesListener(std::bind(&GuidesStateChanged,
std::placeholders::_1,
jni::make_global_ref(listener)));
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_maplayer_Guides_GuidesManager_nativeRemoveListener(JNIEnv * env, jclass clazz)
{
CHECK(g_framework, ("Framework isn't created yet!"));
g_framework->SetGuidesListener(nullptr);
}
}

View file

@ -442,6 +442,10 @@ public class Framework
public static native boolean nativeIsIsolinesLayerEnabled();
public static native void nativeSetGuidesLayerEnabled(boolean enabled);
public static native boolean nativeIsGuidesLayerEnabled();
@NonNull
public static native MapObject nativeDeleteBookmarkFromMapObject();

View file

@ -23,6 +23,7 @@ import com.mapswithme.maps.geofence.GeofenceRegistry;
import com.mapswithme.maps.geofence.GeofenceRegistryImpl;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.location.TrackRecorder;
import com.mapswithme.maps.maplayer.guides.GuidesManager;
import com.mapswithme.maps.maplayer.isolines.IsolinesManager;
import com.mapswithme.maps.maplayer.subway.SubwayManager;
import com.mapswithme.maps.maplayer.traffic.TrafficManager;
@ -64,6 +65,10 @@ public class MwmApplication extends Application implements AppBackgroundTracker.
@NonNull
private IsolinesManager mIsolinesManager;
@SuppressWarnings("NullableProblems")
@NonNull
private GuidesManager mGuidesManager;
private boolean mFrameworkInitialized;
private boolean mPlatformInitialized;
@ -191,6 +196,7 @@ public class MwmApplication extends Application implements AppBackgroundTracker.
mBackgroundTracker.addListener(mVisibleAppLaunchListener);
mSubwayManager = new SubwayManager(this);
mIsolinesManager = new IsolinesManager(this);
mGuidesManager = new GuidesManager(this);
mConnectivityListener = new ConnectivityJobScheduler(this);
mConnectivityListener.listen();
@ -292,6 +298,7 @@ public class MwmApplication extends Application implements AppBackgroundTracker.
TrafficManager.INSTANCE.initialize(null);
SubwayManager.from(this).initialize(null);
IsolinesManager.from(this).initialize(null);
GuidesManager.from(this).initialize(null);
mPurchaseOperationObservable.initialize(null);
mBackgroundTracker.addListener(this);
mFrameworkInitialized = true;
@ -418,6 +425,12 @@ public class MwmApplication extends Application implements AppBackgroundTracker.
nativeOnTransit(foreground);
}
@NonNull
public GuidesManager getGuidesManager()
{
return mGuidesManager;
}
private static class VisibleAppLaunchListener implements AppBackgroundTracker.OnVisibleAppLaunchListener
{
@Override

View file

@ -0,0 +1,9 @@
package com.mapswithme.maps.maplayer.guides;
import androidx.annotation.NonNull;
import com.mapswithme.maps.maplayer.isolines.IsolinesState;
public interface GuidesErrorDialogListener
{
void onStateChanged(@NonNull GuidesState type);
}

View file

@ -0,0 +1,75 @@
package com.mapswithme.maps.maplayer.guides;
import android.app.Application;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.base.Initializable;
import com.mapswithme.maps.maplayer.isolines.IsolinesErrorDialogListener;
import com.mapswithme.maps.maplayer.subway.OnIsolinesChangedListener;
public class GuidesManager implements Initializable<Void>
{
@NonNull
private final OnGuidesChangedListener mListener;
@NonNull
private final Application mApplication;
public GuidesManager(@NonNull Application application)
{
mApplication = application;
mListener = this::onStateChanged;
}
private void onStateChanged(int index)
{
GuidesState state = GuidesState.values()[index];
state.activate(mApplication);
}
public boolean isEnabled()
{
return Framework.nativeIsGuidesLayerEnabled();
}
private void registerListener()
{
nativeAddListener(mListener);
}
public void setEnabled(boolean isEnabled)
{
if (isEnabled == isEnabled())
return;
Framework.nativeSetGuidesLayerEnabled(isEnabled);
}
public void toggle()
{
setEnabled(!isEnabled());
}
@Override
public void initialize(@Nullable Void param)
{
registerListener();
}
@Override
public void destroy()
{
}
@NonNull
public static GuidesManager from(@NonNull Context context)
{
MwmApplication app = (MwmApplication) context.getApplicationContext();
return app.getGuidesManager();
}
private static native void nativeAddListener(@NonNull OnGuidesChangedListener listener);
}

View file

@ -0,0 +1,19 @@
package com.mapswithme.maps.maplayer.guides;
import android.content.Context;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.mapswithme.maps.R;
public enum GuidesState
{
DISABLED,
ENABLED,
NO_DATA,
NETWORK_ERROR;
public void activate(@NonNull Context context)
{
}
}

View file

@ -0,0 +1,6 @@
package com.mapswithme.maps.maplayer.guides;
public interface OnGuidesChangedListener
{
void onStateChanged(int index);
}

View file

@ -3031,9 +3031,9 @@ bool Framework::LoadGuidesEnabled()
return enabled;
}
void Framework::SaveGuidesEnabled(bool guidesEnabled)
void Framework::SaveGuidesEnabled(bool enabled)
{
settings::Set(kGuidesEnabledKey, guidesEnabled);
settings::Set(kGuidesEnabledKey, enabled);
}
void Framework::EnableChoosePositionMode(bool enable, bool enableBounds, bool applyPosition,

View file

@ -787,7 +787,7 @@ public:
void SaveIsolonesEnabled(bool enabled);
bool LoadGuidesEnabled();
void SaveGuidesEnabled(bool trafficEnabled);
void SaveGuidesEnabled(bool enabled);
dp::ApiVersion LoadPreferredGraphicsAPI();
void SavePreferredGraphicsAPI(dp::ApiVersion apiVersion);