[android] Added map layer error activation (disabled)

This commit is contained in:
Dmitry Donskoy 2020-01-21 17:23:47 +03:00 committed by Daria Volvenkova
parent bf9cb5036f
commit 34a8b5fe72
12 changed files with 186 additions and 78 deletions

View file

@ -69,6 +69,7 @@ set(
com/mapswithme/maps/taxi/TaxiManager.cpp
com/mapswithme/maps/TrackRecorder.cpp
com/mapswithme/maps/TrafficState.cpp
com/mapswithme/maps/isolines/IsolinesManager.cpp
com/mapswithme/maps/subway/SubwayManager.cpp
com/mapswithme/maps/ugc/UGC.cpp
com/mapswithme/maps/UserMarkHelper.cpp

View file

@ -609,6 +609,11 @@ void Framework::SetTransitSchemeListener(TransitReadManager::TransitStateChanged
m_onTransitStateChangedFn = function;
}
void Framework::SetIsolinesListener(TransitReadManager::TransitStateChangedFn const & function)
{
m_onIsolinesStateChangedFn = function;
}
bool Framework::IsTrafficEnabled()
{
return m_work.GetTrafficManager().IsEnabled();

View file

@ -78,6 +78,7 @@ namespace android
TrafficManager::TrafficStateChangedFn m_onTrafficStateChangedFn;
TransitReadManager::TransitStateChangedFn m_onTransitStateChangedFn;
TransitReadManager::TransitStateChangedFn m_onIsolinesStateChangedFn;
bool m_isChoosePositionMode;
@ -167,6 +168,7 @@ namespace android
void SetTrafficStateListener(TrafficManager::TrafficStateChangedFn const & fn);
void SetTransitSchemeListener(TransitReadManager::TransitStateChangedFn const & fn);
void SetIsolinesListener(TransitReadManager::TransitStateChangedFn const & fn);
bool IsTrafficEnabled();
void EnableTraffic();
void DisableTraffic();

View file

@ -0,0 +1,35 @@
#include <jni.h>
#include <android/jni/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 TransitSchemeStateChanged(TransitReadManager::TransitSchemeState state,
std::shared_ptr<jobject> const & listener)
{
JNIEnv * env = jni::GetEnv();
env->CallVoidMethod(*listener,
jni::GetMethodID(env, *listener, "onTransitStateChanged", "(I)V"),
static_cast<jint>(state));
}*/
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_maplayer_isolines_IsolinesManager_nativeAddListener(JNIEnv *env, jclass clazz, jobject listener)
{
CHECK(g_framework, ("Framework isn't created yet!"));
/* g_framework->SetIsolinesListener(std::bind(&TransitSchemeStateChanged,
std::placeholders::_1,
jni::make_global_ref(listener)));*/
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_maplayer_isolines_IsolinesManager_nativeRemoveListener(JNIEnv * env, jclass clazz)
{
CHECK(g_framework, ("Framework isn't created yet!"));
// g_framework->SetIsolinesListener(TransitReadManager::TransitStateChangedFn());
}
}

View file

@ -190,7 +190,7 @@ public class MwmApplication extends Application implements AppBackgroundTracker.
mBackgroundTracker = new AppBackgroundTracker();
mBackgroundTracker.addListener(mVisibleAppLaunchListener);
mSubwayManager = new SubwayManager(this);
mIsolinesManager = new IsolinesManager();
mIsolinesManager = new IsolinesManager(this);
mConnectivityListener = new ConnectivityJobScheduler(this);
mConnectivityListener.listen();

View file

@ -0,0 +1,44 @@
package com.mapswithme.maps.maplayer;
import androidx.annotation.NonNull;
public abstract class AbstractMapLayerListener
{
@NonNull
private final OnTransitSchemeChangedListener mSchemeChangedListener;
public AbstractMapLayerListener(@NonNull OnTransitSchemeChangedListener listener)
{
mSchemeChangedListener = listener;
}
public final void setEnabled(boolean isEnabled)
{
if (isEnabled == isEnabled())
return;
setEnabledInternal(isEnabled);
}
public final void toggle()
{
setEnabled(!isEnabled());
}
public final void initialize()
{
registerListener();
}
@NonNull
protected OnTransitSchemeChangedListener getSchemeChangedListener()
{
return mSchemeChangedListener;
}
public abstract boolean isEnabled();
protected abstract void setEnabledInternal(boolean isEnabled);
protected abstract void registerListener();
}

View file

@ -0,0 +1,10 @@
package com.mapswithme.maps.maplayer;
import androidx.annotation.MainThread;
public interface OnTransitSchemeChangedListener
{
@SuppressWarnings("unused")
@MainThread
void onTransitStateChanged(int type);
}

View file

@ -1,13 +1,39 @@
package com.mapswithme.maps.maplayer.isolines;
import android.app.Application;
import android.content.Context;
import androidx.annotation.NonNull;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.maplayer.AbstractMapLayerListener;
import com.mapswithme.maps.maplayer.OnTransitSchemeChangedListener;
public class IsolinesManager
public class IsolinesManager extends AbstractMapLayerListener
{
public IsolinesManager(@NonNull Application application)
{
super(new IsolinesStateChangedListener(application));
}
@Override
public boolean isEnabled()
{
return Framework.nativeIsIsolinesLayerEnabled();
}
@Override
protected void setEnabledInternal(boolean isEnabled)
{
Framework.nativeSetIsolinesLayerEnabled(isEnabled);
}
@Override
protected void registerListener()
{
nativeAddListener(getSchemeChangedListener());
}
@NonNull
public static IsolinesManager from(@NonNull Context context)
{
@ -15,21 +41,6 @@ public class IsolinesManager
return app.getIsolinesManager();
}
public boolean isEnabled()
{
return Framework.nativeIsIsolinesLayerEnabled();
}
public void setEnabled(boolean isEnabled)
{
if (isEnabled == isEnabled())
return;
Framework.nativeSetIsolinesLayerEnabled(isEnabled);
}
public void toggle()
{
setEnabled(!isEnabled());
}
private static native void nativeAddListener(@NonNull OnTransitSchemeChangedListener listener);
private static native void nativeRemoveListener(@NonNull OnTransitSchemeChangedListener listener);
}

View file

@ -0,0 +1,20 @@
package com.mapswithme.maps.maplayer.isolines;
import android.app.Application;
import androidx.annotation.NonNull;
import com.mapswithme.maps.content.AbstractContextualListener;
import com.mapswithme.maps.maplayer.OnTransitSchemeChangedListener;
class IsolinesStateChangedListener extends AbstractContextualListener implements OnTransitSchemeChangedListener
{
IsolinesStateChangedListener(@NonNull Application app)
{
super(app);
}
@Override
public void onTransitStateChanged(int type)
{
}
}

View file

@ -1,31 +0,0 @@
package com.mapswithme.maps.maplayer.subway;
import android.app.Application;
import android.content.Context;
import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import com.mapswithme.maps.content.AbstractContextualListener;
interface OnTransitSchemeChangedListener
{
@SuppressWarnings("unused")
@MainThread
void onTransitStateChanged(int type);
class Default extends AbstractContextualListener implements OnTransitSchemeChangedListener
{
public Default(@NonNull Application context)
{
super(context);
}
@Override
public void onTransitStateChanged(int index)
{
Context app = getContext();
TransitSchemeState state = TransitSchemeState.values()[index];
state.activate(app);
}
}
}

View file

@ -6,43 +6,29 @@ import androidx.annotation.NonNull;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.maplayer.AbstractMapLayerListener;
import com.mapswithme.maps.maplayer.OnTransitSchemeChangedListener;
public class SubwayManager
public class SubwayManager extends AbstractMapLayerListener
{
@NonNull
private final OnTransitSchemeChangedListener mSchemeChangedListener;
public SubwayManager(@NonNull Application application) {
mSchemeChangedListener = new OnTransitSchemeChangedListener.Default(application);
super(new SubwayStateChangedListener(application));
}
public void setEnabled(boolean isEnabled)
{
if (isEnabled == isEnabled())
return;
@Override
public boolean isEnabled() {
return Framework.nativeIsTransitSchemeEnabled();
}
@Override
protected void setEnabledInternal(boolean isEnabled) {
Framework.nativeSetTransitSchemeEnabled(isEnabled);
Framework.nativeSaveSettingSchemeEnabled(isEnabled);
}
public boolean isEnabled()
{
return Framework.nativeIsTransitSchemeEnabled();
}
public void toggle()
{
setEnabled(!isEnabled());
}
public void initialize()
{
registerListener();
}
private void registerListener()
{
nativeAddListener(mSchemeChangedListener);
@Override
protected void registerListener() {
nativeAddListener(getSchemeChangedListener());
}
@NonNull
@ -51,7 +37,7 @@ public class SubwayManager
MwmApplication app = (MwmApplication) context.getApplicationContext();
return app.getSubwayManager();
}
private static native void nativeAddListener(@NonNull OnTransitSchemeChangedListener listener);
private static native void nativeAddListener(@NonNull OnTransitSchemeChangedListener listener);
private static native void nativeRemoveListener(@NonNull OnTransitSchemeChangedListener listener);
}

View file

@ -0,0 +1,25 @@
package com.mapswithme.maps.maplayer.subway;
import android.app.Application;
import android.content.Context;
import androidx.annotation.NonNull;
import com.mapswithme.maps.content.AbstractContextualListener;
import com.mapswithme.maps.maplayer.OnTransitSchemeChangedListener;
public class SubwayStateChangedListener extends AbstractContextualListener implements OnTransitSchemeChangedListener
{
SubwayStateChangedListener(@NonNull Application context)
{
super(context);
}
@Override
public void onTransitStateChanged(int index)
{
Context app = getContext();
TransitSchemeState state = TransitSchemeState.values()[index];
state.activate(app);
}
}