[android] Added subway JNI, added subway res, optimized inteface and activity, modified SubwayManager
|
@ -63,6 +63,7 @@ set(
|
|||
com/mapswithme/maps/taxi/TaxiManager.cpp
|
||||
com/mapswithme/maps/TrackRecorder.cpp
|
||||
com/mapswithme/maps/TrafficState.cpp
|
||||
com/mapswithme/maps/subway/SubwayManager.cpp
|
||||
com/mapswithme/maps/ugc/UGC.cpp
|
||||
com/mapswithme/maps/UserMarkHelper.cpp
|
||||
com/mapswithme/maps/viator/Viator.cpp
|
||||
|
|
|
@ -93,6 +93,7 @@ Framework::Framework()
|
|||
, m_isChoosePositionMode(false)
|
||||
{
|
||||
m_work.GetTrafficManager().SetStateListener(bind(&Framework::TrafficStateChanged, this, _1));
|
||||
m_work.GetTransitManager().SetStateListener(bind(&Framework::TransitSchemeStateChanged, this, _1));
|
||||
}
|
||||
|
||||
void Framework::OnLocationError(int errorCode)
|
||||
|
@ -136,6 +137,12 @@ void Framework::TrafficStateChanged(TrafficManager::TrafficState state)
|
|||
m_onTrafficStateChangedFn(state);
|
||||
}
|
||||
|
||||
void Framework::TransitSchemeStateChanged(TransitReadManager::TransitSchemeState state)
|
||||
{
|
||||
if (m_onTransitStateChangedFn)
|
||||
m_onTransitStateChangedFn(state);
|
||||
}
|
||||
|
||||
bool Framework::CreateDrapeEngine(JNIEnv * env, jobject jSurface, int densityDpi, bool firstLaunch,
|
||||
bool launchByDeepLink)
|
||||
{
|
||||
|
@ -431,6 +438,11 @@ void Framework::SetTrafficStateListener(TrafficManager::TrafficStateChangedFn co
|
|||
m_onTrafficStateChangedFn = fn;
|
||||
}
|
||||
|
||||
void Framework::SetTransitSchemeListener(TransitReadManager::TransitStateChangedFn const & function)
|
||||
{
|
||||
m_onTransitStateChangedFn = function;
|
||||
}
|
||||
|
||||
bool Framework::IsTrafficEnabled()
|
||||
{
|
||||
return m_work.GetTrafficManager().IsEnabled();
|
||||
|
@ -1419,7 +1431,7 @@ Java_com_mapswithme_maps_Framework_nativeSetAutoZoomEnabled(JNIEnv * env, jclass
|
|||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_Framework_nativeSetTransitSchemeEnabled(JNIEnv * env, jclass, jboolean enabled)
|
||||
{
|
||||
frm()->EnableTransitScheme(static_cast<bool>(enabled));
|
||||
frm()->GetTransitManager().EnableTransitSchemeMode(static_cast<bool>(enabled));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
|
|
|
@ -64,6 +64,7 @@ namespace android
|
|||
std::map<gui::EWidget, gui::Position> m_guiPositions;
|
||||
|
||||
void TrafficStateChanged(TrafficManager::TrafficState state);
|
||||
void TransitSchemeStateChanged(TransitReadManager::TransitSchemeState state);
|
||||
|
||||
void MyPositionModeChanged(location::EMyPositionMode mode, bool routingActive);
|
||||
|
||||
|
@ -72,6 +73,7 @@ namespace android
|
|||
bool m_isCurrentModeInitialized;
|
||||
|
||||
TrafficManager::TrafficStateChangedFn m_onTrafficStateChangedFn;
|
||||
TransitReadManager::TransitStateChangedFn m_onTransitStateChangedFn;
|
||||
|
||||
bool m_isChoosePositionMode;
|
||||
|
||||
|
@ -165,6 +167,7 @@ namespace android
|
|||
void SwitchMyPositionNextMode();
|
||||
|
||||
void SetTrafficStateListener(TrafficManager::TrafficStateChangedFn const & fn);
|
||||
void SetTransitSchemeListener(TransitReadManager::TransitStateChangedFn const & fn);
|
||||
bool IsTrafficEnabled();
|
||||
void EnableTraffic();
|
||||
void DisableTraffic();
|
||||
|
|
32
android/jni/com/mapswithme/maps/subway/SubwayManager.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <jni.h>
|
||||
#include <android/jni/com/mapswithme/maps/Framework.hpp>
|
||||
#include "com/mapswithme/core/jni_helper.hpp"
|
||||
#include "com/mapswithme/platform/Platform.hpp"
|
||||
|
||||
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_subway_SubwayManager_nativeAddListener(JNIEnv *env, jclass clazz, jobject listener)
|
||||
{
|
||||
CHECK(g_framework, ("Framework isn't created yet!"));
|
||||
g_framework->SetTransitSchemeListener(std::bind(&TransitSchemeStateChanged,
|
||||
std::placeholders::_1,
|
||||
jni::make_global_ref(listener)));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_subway_SubwayManager_nativeRemoveListener(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
CHECK(g_framework, ("Framework isn't created yet!"));
|
||||
g_framework->SetTransitSchemeListener(TransitReadManager::TransitStateChangedFn());
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 467 B After Width: | Height: | Size: 442 B |
Before Width: | Height: | Size: 467 B After Width: | Height: | Size: 405 B |
Before Width: | Height: | Size: 359 B After Width: | Height: | Size: 348 B |
Before Width: | Height: | Size: 359 B After Width: | Height: | Size: 322 B |
Before Width: | Height: | Size: 587 B After Width: | Height: | Size: 565 B |
Before Width: | Height: | Size: 587 B After Width: | Height: | Size: 523 B |
Before Width: | Height: | Size: 823 B After Width: | Height: | Size: 792 B |
Before Width: | Height: | Size: 823 B After Width: | Height: | Size: 732 B |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1,002 B |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 936 B |
|
@ -5,5 +5,4 @@
|
|||
<item android:drawable="@drawable/subway_bg_light_pressed" android:state_pressed="true"/>
|
||||
<item android:drawable="@drawable/subway_bg_light_selected" android:state_selected="true"/>
|
||||
<item android:drawable="@drawable/subway_bg_light_default"/>
|
||||
|
||||
</selector>
|
||||
|
|
|
@ -6,5 +6,4 @@
|
|||
android:right="@dimen/margin_base_plus_quarter"
|
||||
android:top="@dimen/margin_base_plus_quarter"
|
||||
android:bottom="@dimen/margin_base_plus_quarter"/>
|
||||
|
||||
</layer-list>
|
||||
|
|
|
@ -6,5 +6,4 @@
|
|||
android:right="@dimen/margin_base_plus_quarter"
|
||||
android:top="@dimen/margin_base_plus_quarter"
|
||||
android:bottom="@dimen/margin_base_plus_quarter"/>
|
||||
|
||||
</layer-list>
|
||||
|
|
|
@ -5,5 +5,4 @@
|
|||
<item android:drawable="@drawable/subway_bg_night_pressed" android:state_pressed="true"/>
|
||||
<item android:drawable="@drawable/subway_bg_night_selected" android:state_selected="true"/>
|
||||
<item android:drawable="@drawable/subway_bg_night_default"/>
|
||||
|
||||
</selector>
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
android:paddingStart="@dimen/margin_base"
|
||||
android:paddingRight="@dimen/margin_base"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
app:layout_constraintHorizontal_weight="1"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"/>
|
||||
|
@ -37,7 +36,7 @@
|
|||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintRight_toLeftOf="@id/сlose_btn"
|
||||
android:visibility="visible"
|
||||
android:text="@string/edit"
|
||||
android:text="@string/layers_title"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"/>
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recycler"
|
|
@ -101,7 +101,6 @@
|
|||
<attr name="filterPropertyBackground" format="reference"/>
|
||||
<attr name="adChoicesIcon" format="reference"/>
|
||||
<attr name="saleIcon" format="reference"/>
|
||||
<attr name="toggleLayerBtn" format="reference"></attr>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="ThemeAttrs.NavButtons">
|
||||
|
|
|
@ -126,7 +126,6 @@
|
|||
<item name="filterPropertyBackground">@drawable/button_with_border</item>
|
||||
<item name="adChoicesIcon">@drawable/ic_ad_light</item>
|
||||
<item name="saleIcon">@drawable/ic_deal_light</item>
|
||||
<item name="toggleLayerBtn">@drawable/ic_layers_light_on</item>
|
||||
<item name="nav_bg_subway">@drawable/subway_bg_light</item>
|
||||
</style>
|
||||
|
||||
|
@ -257,7 +256,6 @@
|
|||
<item name="filterPropertyBackground">@drawable/button_with_border_night</item>
|
||||
<item name="adChoicesIcon">@drawable/ic_ad_dark</item>
|
||||
<item name="saleIcon">@drawable/ic_deal_dark</item>
|
||||
<item name="toggleLayerBtn">@drawable/ic_layers_dark_on</item>
|
||||
<item name="nav_bg_subway">@drawable/subway_bg_night</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
|
@ -25,7 +25,6 @@ import android.text.TextUtils;
|
|||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.Toast;
|
||||
|
@ -84,13 +83,13 @@ import com.mapswithme.maps.settings.UnitLocale;
|
|||
import com.mapswithme.maps.sound.TtsPlayer;
|
||||
import com.mapswithme.maps.subway.OnSubwayModeSelectListener;
|
||||
import com.mapswithme.maps.subway.SubwayManager;
|
||||
import com.mapswithme.maps.subway.SubwayTrafficToggleDialogFragment;
|
||||
import com.mapswithme.maps.subway.ToggleMapLayerDialog;
|
||||
import com.mapswithme.maps.taxi.TaxiInfo;
|
||||
import com.mapswithme.maps.taxi.TaxiManager;
|
||||
import com.mapswithme.maps.traffic.TrafficManager;
|
||||
import com.mapswithme.maps.traffic.widget.OnTrafficModeSelectListener;
|
||||
import com.mapswithme.maps.traffic.widget.TrafficMapLayerButton;
|
||||
import com.mapswithme.maps.traffic.widget.TrafficMapLayerBtnController;
|
||||
import com.mapswithme.maps.traffic.widget.TrafficButton;
|
||||
import com.mapswithme.maps.traffic.widget.TrafficButtonController;
|
||||
import com.mapswithme.maps.widget.FadeView;
|
||||
import com.mapswithme.maps.widget.menu.BaseMenu;
|
||||
import com.mapswithme.maps.widget.menu.MainMenu;
|
||||
|
@ -171,14 +170,24 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
|
||||
@Nullable
|
||||
private MapFragment mMapFragment;
|
||||
|
||||
@Nullable
|
||||
private PlacePageView mPlacePage;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private FadeView mFadeView;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private View mPositionChooser;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private ImageButton mSubwayBtn;
|
||||
|
||||
private RoutingPlanInplaceController mRoutingPlanInplaceController;
|
||||
|
||||
@Nullable
|
||||
private NavigationController mNavigationController;
|
||||
|
||||
|
@ -190,11 +199,11 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
|
||||
@Nullable
|
||||
private MyPositionButton mNavMyPosition;
|
||||
private TrafficMapLayerButton mTraffic;
|
||||
private TrafficButton mTraffic;
|
||||
@Nullable
|
||||
private NavigationButtonsAnimationController mNavAnimationController;
|
||||
@Nullable
|
||||
private TrafficMapLayerBtnController mTrafficMapLayerBtnController;
|
||||
private TrafficButtonController mTrafficButtonController;
|
||||
|
||||
@Nullable
|
||||
private SearchFilterController mFilterController;
|
||||
|
@ -232,7 +241,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
mSubwayBtn.setSelected(true);
|
||||
return;
|
||||
}
|
||||
onResetOptionalMapLayer();
|
||||
onResetOptionalMapLayers();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -245,10 +254,10 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
mSubwayBtn.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
onResetOptionalMapLayer();
|
||||
onResetOptionalMapLayers();
|
||||
}
|
||||
|
||||
private void onResetOptionalMapLayer()
|
||||
private void onResetOptionalMapLayers()
|
||||
{
|
||||
SubwayManager.from(getApplicationContext()).setEnabled(false);
|
||||
TrafficManager.INSTANCE.setEnabled(false);
|
||||
|
@ -759,20 +768,31 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
View myPosition = frame.findViewById(R.id.my_position);
|
||||
mNavMyPosition = new MyPositionButton(myPosition, mOnMyPositionClickListener);
|
||||
|
||||
ImageButton trafficBtn = frame.findViewById(R.id.traffic);
|
||||
OpenBottomDialogClickListener listener = new OpenBottomDialogClickListener();
|
||||
trafficBtn.setOnClickListener(listener);
|
||||
mTraffic = new TrafficMapLayerButton(trafficBtn);
|
||||
mTrafficMapLayerBtnController = new TrafficMapLayerBtnController(mTraffic, this);
|
||||
initToggleMapLayerBtn(frame);
|
||||
mNavAnimationController = new NavigationButtonsAnimationController(
|
||||
zoomIn, zoomOut, myPosition, getWindow().getDecorView().getRootView(), this);
|
||||
initSubwayBtn(frame);
|
||||
}
|
||||
|
||||
private void initSubwayBtn(View frame)
|
||||
private void initToggleMapLayerBtn(@NonNull View frame)
|
||||
{
|
||||
initTrafficBtn(frame);
|
||||
initSubwayBtn(frame);
|
||||
showToggleMapLayerBtn();
|
||||
}
|
||||
|
||||
private void initTrafficBtn(@NonNull View frame)
|
||||
{
|
||||
ImageButton trafficBtn = frame.findViewById(R.id.traffic);
|
||||
trafficBtn.setOnClickListener(new OpenBottomDialogClickListener());
|
||||
mTraffic = new TrafficButton(trafficBtn);
|
||||
mTrafficButtonController = new TrafficButtonController(mTraffic, this);
|
||||
}
|
||||
|
||||
private void initSubwayBtn(@NonNull View frame)
|
||||
{
|
||||
mSubwayBtn = frame.findViewById(R.id.subway);
|
||||
mSubwayBtn.setVisibility(View.VISIBLE);
|
||||
SubwayManager subway = SubwayManager.from(this);
|
||||
mSubwayBtn.setSelected(subway.isEnabled());
|
||||
mSubwayBtn.setOnClickListener(new OpenBottomDialogClickListener());
|
||||
UiUtils.addStatusBarOffset(mSubwayBtn);
|
||||
}
|
||||
|
@ -1401,8 +1421,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
RoutingController.get().attach(this);
|
||||
if (MapFragment.nativeIsEngineCreated())
|
||||
LocationHelper.INSTANCE.attach(this);
|
||||
if (mTrafficMapLayerBtnController != null)
|
||||
TrafficManager.INSTANCE.attach(mTrafficMapLayerBtnController);
|
||||
if (mTrafficButtonController != null)
|
||||
TrafficManager.INSTANCE.attach(mTrafficButtonController);
|
||||
if (mNavigationController != null)
|
||||
TrafficManager.INSTANCE.attach(mNavigationController);
|
||||
mPlacePage.onActivityStarted();
|
||||
|
@ -1417,8 +1437,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
LocationHelper.INSTANCE.detach(!isFinishing());
|
||||
RoutingController.get().detach();
|
||||
TrafficManager.INSTANCE.detachAll();
|
||||
if (mTrafficMapLayerBtnController != null)
|
||||
mTrafficMapLayerBtnController.destroy();
|
||||
if (mTrafficButtonController != null)
|
||||
mTrafficButtonController.destroy();
|
||||
mPlacePage.onActivityStopped();
|
||||
}
|
||||
|
||||
|
@ -1627,6 +1647,19 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
}
|
||||
|
||||
private void appearMenu(BaseMenu menu)
|
||||
{
|
||||
appearMenuFrame(menu);
|
||||
showNavMyPositionBtn();
|
||||
showToggleMapLayerBtn();
|
||||
}
|
||||
|
||||
private void showNavMyPositionBtn()
|
||||
{
|
||||
if (mNavMyPosition != null)
|
||||
mNavMyPosition.show();
|
||||
}
|
||||
|
||||
private void appearMenuFrame(@NonNull BaseMenu menu)
|
||||
{
|
||||
Animations.appearSliding(menu.getFrame(), Animations.BOTTOM, new Runnable()
|
||||
{
|
||||
|
@ -1636,23 +1669,26 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
adjustBottomWidgets(0);
|
||||
}
|
||||
});
|
||||
if (mNavMyPosition != null)
|
||||
mNavMyPosition.show();
|
||||
showToggleMapLayerBtn();
|
||||
}
|
||||
|
||||
private void showToggleMapLayerBtn()
|
||||
{
|
||||
if (TrafficManager.INSTANCE.isEnabled())
|
||||
{
|
||||
mTraffic.show();
|
||||
mSubwayBtn.setVisibility(View.GONE);
|
||||
}
|
||||
showTrafficBtn();
|
||||
else
|
||||
{
|
||||
mTraffic.hideImmediately();
|
||||
Animations.appearSliding(mSubwayBtn, Animations.LEFT, null);
|
||||
}
|
||||
showSubwayBtn();
|
||||
}
|
||||
|
||||
private void showSubwayBtn()
|
||||
{
|
||||
Animations.appearSliding(mSubwayBtn, Animations.LEFT, null);
|
||||
mTraffic.hideImmediately();
|
||||
}
|
||||
|
||||
private void showTrafficBtn()
|
||||
{
|
||||
mTraffic.show();
|
||||
mSubwayBtn.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2702,10 +2738,10 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
{
|
||||
if (isOptionalMapLayerEnabled())
|
||||
{
|
||||
onResetOptionalMapLayer();
|
||||
onResetOptionalMapLayers();
|
||||
return;
|
||||
}
|
||||
SubwayTrafficToggleDialogFragment.show(MwmActivity.this);
|
||||
ToggleMapLayerDialog.show(MwmActivity.this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,8 @@ public class MwmApplication extends Application
|
|||
private static MwmApplication sSelf;
|
||||
private SharedPreferences mPrefs;
|
||||
private AppBackgroundTracker mBackgroundTracker;
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private SubwayManager mSubwayManager;
|
||||
|
||||
private boolean mFrameworkInitialized;
|
||||
|
@ -120,6 +122,7 @@ public class MwmApplication extends Application
|
|||
}
|
||||
};
|
||||
|
||||
@NonNull
|
||||
public SubwayManager getSubwayManager()
|
||||
{
|
||||
return mSubwayManager;
|
||||
|
@ -193,7 +196,7 @@ public class MwmApplication extends Application
|
|||
|
||||
mBackgroundTracker = new AppBackgroundTracker();
|
||||
mBackgroundTracker.addListener(mVisibleAppLaunchListener);
|
||||
mSubwayManager = new SubwayManager();
|
||||
mSubwayManager = new SubwayManager(this);
|
||||
}
|
||||
|
||||
private void initCoreIndependentSdks()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.mapswithme.maps.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
|
@ -8,18 +9,19 @@ import android.view.ViewGroup;
|
|||
|
||||
public class SpanningLinearLayoutManager extends LinearLayoutManager
|
||||
{
|
||||
public SpanningLinearLayoutManager(Context context)
|
||||
public SpanningLinearLayoutManager(@NonNull Context context)
|
||||
{
|
||||
super(context);
|
||||
}
|
||||
|
||||
public SpanningLinearLayoutManager(Context context, int orientation, boolean reverseLayout)
|
||||
public SpanningLinearLayoutManager(@NonNull Context context, int orientation, boolean reverseLayout)
|
||||
{
|
||||
super(context, orientation, reverseLayout);
|
||||
}
|
||||
|
||||
public SpanningLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int
|
||||
defStyleRes)
|
||||
public SpanningLinearLayoutManager(@NonNull Context context,
|
||||
@NonNull AttributeSet attrs,
|
||||
int defStyleAttr, int defStyleRes)
|
||||
{
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
@ -31,24 +33,25 @@ public class SpanningLinearLayoutManager extends LinearLayoutManager
|
|||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.LayoutParams generateLayoutParams(Context c, AttributeSet attrs)
|
||||
public RecyclerView.LayoutParams generateLayoutParams(@NonNull Context c,
|
||||
@NonNull AttributeSet attrs)
|
||||
{
|
||||
return spanLayoutSize(super.generateLayoutParams(c, attrs));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp)
|
||||
public RecyclerView.LayoutParams generateLayoutParams(@NonNull ViewGroup.LayoutParams lp)
|
||||
{
|
||||
return spanLayoutSize(super.generateLayoutParams(lp));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkLayoutParams(RecyclerView.LayoutParams lp)
|
||||
public boolean checkLayoutParams(@NonNull RecyclerView.LayoutParams lp)
|
||||
{
|
||||
return super.checkLayoutParams(lp);
|
||||
}
|
||||
|
||||
private RecyclerView.LayoutParams spanLayoutSize(RecyclerView.LayoutParams layoutParams)
|
||||
private RecyclerView.LayoutParams spanLayoutSize(@NonNull RecyclerView.LayoutParams layoutParams)
|
||||
{
|
||||
if (getOrientation() == HORIZONTAL)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package com.mapswithme.maps.content;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class AbstractContextualListener
|
||||
{
|
||||
@NonNull
|
||||
private final WeakReference<MwmApplication> mApp;
|
||||
|
||||
public AbstractContextualListener(@NonNull MwmApplication app)
|
||||
{
|
||||
mApp = new WeakReference<>(app);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private WeakReference<MwmApplication> getAppReference()
|
||||
{
|
||||
return mApp;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MwmApplication getApp()
|
||||
{
|
||||
return getAppReference().get();
|
||||
}
|
||||
}
|
|
@ -8,23 +8,8 @@ import com.mapswithme.maps.traffic.TrafficItem;
|
|||
|
||||
public enum Mode
|
||||
{
|
||||
TRAFFIC(new TrafficItem())
|
||||
{
|
||||
@Override
|
||||
public void toggleLayerBtn(@NonNull AppCompatActivity activity, boolean isLayerEnabled)
|
||||
{
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
SUBWAY(new SubwayItem())
|
||||
{
|
||||
@Override
|
||||
public void toggleLayerBtn(@NonNull AppCompatActivity activity, boolean isLayerEnabled)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
TRAFFIC(new TrafficItem()),
|
||||
SUBWAY(new SubwayItem());
|
||||
|
||||
@NonNull
|
||||
private final BottomSheetItem mItem;
|
||||
|
@ -39,6 +24,4 @@ public enum Mode
|
|||
{
|
||||
return mItem;
|
||||
}
|
||||
|
||||
public abstract void toggleLayerBtn(@NonNull AppCompatActivity activity, boolean isLayerEnabled);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package com.mapswithme.maps.subway;
|
||||
|
||||
import android.support.annotation.MainThread;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.content.AbstractContextualListener;
|
||||
|
||||
public interface OnTransitSchemeChangedListener
|
||||
{
|
||||
@SuppressWarnings("unused")
|
||||
@MainThread
|
||||
void onTransitStateChanged(int type);
|
||||
|
||||
class Default extends AbstractContextualListener implements OnTransitSchemeChangedListener
|
||||
{
|
||||
public Default(@NonNull MwmApplication app)
|
||||
{
|
||||
super(app);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransitStateChanged(int index)
|
||||
{
|
||||
MwmApplication app = getApp();
|
||||
if (app == null)
|
||||
return;
|
||||
|
||||
TransitSchemeState state = TransitSchemeState.makeInstance(index);
|
||||
if (state != TransitSchemeState.NO_DATA)
|
||||
return;
|
||||
|
||||
Toast.makeText(app, R.string.subway_data_unavailable, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,11 +13,8 @@ class SubwayItem implements BottomSheetItem
|
|||
@Override
|
||||
public void onSelected(@NonNull MwmActivity activity)
|
||||
{
|
||||
SubwayManager subway = SubwayManager.from(activity);
|
||||
subway.toggle();
|
||||
if (subway.isEnabled())
|
||||
TrafficManager.INSTANCE.setEnabled(false);
|
||||
|
||||
SubwayManager.from(activity).toggle();
|
||||
TrafficManager.INSTANCE.setEnabled(false);
|
||||
activity.onSubwayModeSelected();
|
||||
}
|
||||
|
||||
|
@ -30,7 +27,7 @@ class SubwayItem implements BottomSheetItem
|
|||
@Override
|
||||
public int getTitleResId()
|
||||
{
|
||||
return R.string.about;
|
||||
return R.string.button_layer_subway;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,8 +11,45 @@ import com.mapswithme.util.ThemeUtils;
|
|||
|
||||
public class SubwayManager
|
||||
{
|
||||
public SubwayManager()
|
||||
@NonNull
|
||||
private final OnTransitSchemeChangedListener mSchemeChangedListener;
|
||||
|
||||
public SubwayManager(@NonNull MwmApplication application) {
|
||||
mSchemeChangedListener = new OnTransitSchemeChangedListener.Default(application);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean isEnabled)
|
||||
{
|
||||
if (isEnabled == isEnabled())
|
||||
return;
|
||||
|
||||
if (isEnabled)
|
||||
addSchemeChangedListener(mSchemeChangedListener);
|
||||
else
|
||||
removeSchemeChangedListener(mSchemeChangedListener);
|
||||
|
||||
Framework.nativeSetTransitSchemeEnabled(isEnabled);
|
||||
Framework.nativeSaveSettingSchemeEnabled(isEnabled);
|
||||
}
|
||||
|
||||
public boolean isEnabled()
|
||||
{
|
||||
return Framework.nativeIsTransitSchemeEnabled();
|
||||
}
|
||||
|
||||
public void toggle()
|
||||
{
|
||||
setEnabled(!isEnabled());
|
||||
}
|
||||
|
||||
public void addSchemeChangedListener(@NonNull OnTransitSchemeChangedListener listener)
|
||||
{
|
||||
nativeAddListener(listener);
|
||||
}
|
||||
|
||||
public void removeSchemeChangedListener(@NonNull OnTransitSchemeChangedListener listener)
|
||||
{
|
||||
nativeRemoveListener(listener);
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
|
@ -28,31 +65,18 @@ public class SubwayManager
|
|||
|
||||
private int getDisabledStateIcon()
|
||||
{
|
||||
return ThemeUtils.isNightTheme() ? R.drawable.ic_subway_menu_dark_off : R.drawable.ic_subway_menu_light_off;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean isEnabled)
|
||||
{
|
||||
if (isEnabled == isEnabled())
|
||||
return;
|
||||
|
||||
Framework.nativeSetTransitSchemeEnabled(isEnabled);
|
||||
Framework.nativeSaveSettingSchemeEnabled(isEnabled);
|
||||
}
|
||||
|
||||
public boolean isEnabled()
|
||||
{
|
||||
return Framework.nativeIsTransitSchemeEnabled();
|
||||
return ThemeUtils.isNightTheme()
|
||||
? R.drawable.ic_subway_menu_dark_off
|
||||
: R.drawable.ic_subway_menu_light_off;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static SubwayManager from(@NonNull Context context)
|
||||
{
|
||||
MwmApplication app = (MwmApplication) context.getApplicationContext();
|
||||
return app.getSubwayManager();
|
||||
}
|
||||
|
||||
public void toggle()
|
||||
{
|
||||
setEnabled(!isEnabled());
|
||||
}
|
||||
private static native void nativeAddListener(@NonNull OnTransitSchemeChangedListener listener);
|
||||
private static native void nativeRemoveListener(@NonNull OnTransitSchemeChangedListener listener);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,9 @@ import android.app.Dialog;
|
|||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.BottomSheetDialog;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
@ -23,8 +25,9 @@ import com.mapswithme.maps.bookmarks.OnItemClickListener;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class SubwayTrafficToggleDialogFragment extends android.support.v4.app.DialogFragment implements OnItemClickListener<Mode>
|
||||
public class ToggleMapLayerDialog extends DialogFragment implements OnItemClickListener<Mode>
|
||||
{
|
||||
@NonNull
|
||||
@SuppressWarnings("NullableProblems")
|
||||
|
@ -40,17 +43,26 @@ public class SubwayTrafficToggleDialogFragment extends android.support.v4.app.Di
|
|||
{
|
||||
BottomSheetDialog dialog = new BottomSheetDialog(getActivity());
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
mRoot = inflater.inflate(R.layout.fragment_subway_traffic_toggle, null, false);
|
||||
mRoot = inflater.inflate(R.layout.fragment_toggle_map_layer, null, false);
|
||||
dialog.setContentView(mRoot);
|
||||
initChildren();
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private void initChildren()
|
||||
{
|
||||
initCloseBtn();
|
||||
initRecycler();
|
||||
}
|
||||
|
||||
private void initCloseBtn()
|
||||
{
|
||||
View closeBtn = mRoot.findViewById(R.id.сlose_btn);
|
||||
closeBtn.setOnClickListener(v -> dismiss());
|
||||
}
|
||||
|
||||
private void initRecycler()
|
||||
{
|
||||
RecyclerView recycler = mRoot.findViewById(R.id.recycler);
|
||||
RecyclerView.LayoutManager layoutManager = new SpanningLinearLayoutManager(getContext(),
|
||||
LinearLayoutManager.HORIZONTAL,
|
||||
|
@ -60,9 +72,17 @@ public class SubwayTrafficToggleDialogFragment extends android.support.v4.app.Di
|
|||
recycler.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
public static void show(AppCompatActivity activity)
|
||||
@Override
|
||||
public void onItemClick(@NonNull View v, @NonNull Mode item)
|
||||
{
|
||||
SubwayTrafficToggleDialogFragment frag = new SubwayTrafficToggleDialogFragment();
|
||||
MwmActivity activity = (MwmActivity) getActivity();
|
||||
item.getItem().onSelected(activity);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public static void show(@NonNull AppCompatActivity activity)
|
||||
{
|
||||
ToggleMapLayerDialog frag = new ToggleMapLayerDialog();
|
||||
String tag = frag.getClass().getCanonicalName();
|
||||
FragmentManager fm = activity.getSupportFragmentManager();
|
||||
|
||||
|
@ -74,13 +94,6 @@ public class SubwayTrafficToggleDialogFragment extends android.support.v4.app.Di
|
|||
fm.executePendingTransactions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(@NonNull View v, @NonNull Mode item)
|
||||
{
|
||||
item.getItem().onSelected((MwmActivity)getActivity());
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private static class ModeAdapter extends RecyclerView.Adapter<ModeHolder>
|
||||
{
|
||||
@NonNull
|
||||
|
@ -120,7 +133,6 @@ public class SubwayTrafficToggleDialogFragment extends android.support.v4.app.Di
|
|||
return mModes.size();
|
||||
}
|
||||
}
|
||||
|
||||
private static class ModeHolder extends RecyclerView.ViewHolder
|
||||
{
|
||||
@NonNull
|
||||
|
@ -129,10 +141,10 @@ public class SubwayTrafficToggleDialogFragment extends android.support.v4.app.Di
|
|||
private final OnItemClickListener<Mode> mListener;
|
||||
@NonNull
|
||||
private final TextView mTitle;
|
||||
@NonNull
|
||||
@Nullable
|
||||
private Mode mItem;
|
||||
|
||||
public ModeHolder(@NonNull View root, @NonNull OnItemClickListener<Mode> listener)
|
||||
ModeHolder(@NonNull View root, @NonNull OnItemClickListener<Mode> listener)
|
||||
{
|
||||
super(root);
|
||||
mButton = root.findViewById(R.id.item_btn);
|
||||
|
@ -141,9 +153,15 @@ public class SubwayTrafficToggleDialogFragment extends android.support.v4.app.Di
|
|||
mButton.setOnClickListener(this::onItemClicked);
|
||||
}
|
||||
|
||||
private void onItemClicked(View v)
|
||||
@NonNull
|
||||
public Mode getItem()
|
||||
{
|
||||
mListener.onItemClick(v, mItem);
|
||||
return Objects.requireNonNull(mItem);
|
||||
}
|
||||
|
||||
private void onItemClicked(@NonNull View v)
|
||||
{
|
||||
mListener.onItemClick(v, getItem());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.mapswithme.maps.subway;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
public enum TransitSchemeState
|
||||
{
|
||||
DISABLED,
|
||||
ENABLED,
|
||||
NO_DATA;
|
||||
|
||||
@NonNull
|
||||
public static TransitSchemeState makeInstance(int index)
|
||||
{
|
||||
if (index < 0 || index >= TransitSchemeState.values().length)
|
||||
throw new IllegalArgumentException("No value for index = " + index);
|
||||
return TransitSchemeState.values()[index];
|
||||
}
|
||||
}
|
|
@ -20,10 +20,7 @@ public class TrafficItem implements BottomSheetItem
|
|||
public void onSelected(@NonNull MwmActivity activity)
|
||||
{
|
||||
TrafficManager.INSTANCE.toggle();
|
||||
SubwayManager subway = SubwayManager.from(activity);
|
||||
if (subway.isEnabled())
|
||||
subway.setEnabled(false);
|
||||
|
||||
SubwayManager.from(activity).setEnabled(false);
|
||||
activity.onTrafficModeSelected();
|
||||
}
|
||||
|
||||
|
@ -36,6 +33,6 @@ public class TrafficItem implements BottomSheetItem
|
|||
@Override
|
||||
public int getTitleResId()
|
||||
{
|
||||
return R.string.about;
|
||||
return R.string.button_layer_traffic;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ public enum TrafficManager
|
|||
|
||||
private int getEnabledStateIcon()
|
||||
{
|
||||
return R.drawable.ic_traffic_on;
|
||||
return R.drawable.ic_traffic_menu_on;
|
||||
}
|
||||
|
||||
private int getDisabledStateIcon()
|
||||
|
|
|
@ -4,8 +4,6 @@ import android.content.Context;
|
|||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
|
@ -17,21 +15,20 @@ import com.mapswithme.util.ThemeUtils;
|
|||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
||||
public class TrafficMapLayerButton
|
||||
public class TrafficButton
|
||||
{
|
||||
@NonNull
|
||||
private final AnimationDrawable mLoadingAnim;
|
||||
@NonNull
|
||||
private final ImageButton mTraffic;
|
||||
private final ImageButton mButton;
|
||||
|
||||
public TrafficMapLayerButton(@NonNull ImageButton trafficBtn)
|
||||
public TrafficButton(@NonNull ImageButton trafficBtn)
|
||||
{
|
||||
mTraffic = trafficBtn;
|
||||
mButton = trafficBtn;
|
||||
mLoadingAnim = getLoadingAnim(trafficBtn);
|
||||
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) trafficBtn.getLayoutParams();
|
||||
params.setMargins(0, UiUtils.getStatusBarHeight(trafficBtn.getContext()), 0, 0);
|
||||
trafficBtn.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -48,66 +45,66 @@ public class TrafficMapLayerButton
|
|||
void turnOff()
|
||||
{
|
||||
stopWaitingAnimation();
|
||||
mTraffic.setImageResource(ThemeUtils.isNightTheme() ? R.drawable.ic_traffic_off_night
|
||||
: R.drawable.ic_traffic_off);
|
||||
mButton.setImageResource(ThemeUtils.isNightTheme() ? R.drawable.ic_traffic_off_night
|
||||
: R.drawable.ic_traffic_off);
|
||||
}
|
||||
|
||||
void turnOn()
|
||||
{
|
||||
stopWaitingAnimation();
|
||||
mTraffic.setImageResource(ThemeUtils.isNightTheme() ? R.drawable.ic_traffic_on_night
|
||||
: R.drawable.ic_traffic_on);
|
||||
mButton.setImageResource(ThemeUtils.isNightTheme() ? R.drawable.ic_traffic_on_night
|
||||
: R.drawable.ic_traffic_on);
|
||||
}
|
||||
|
||||
void markAsOutdated()
|
||||
{
|
||||
stopWaitingAnimation();
|
||||
mTraffic.setImageResource(ThemeUtils.isNightTheme() ? R.drawable.ic_traffic_outdated_night
|
||||
: R.drawable.ic_traffic_outdated);
|
||||
mButton.setImageResource(ThemeUtils.isNightTheme() ? R.drawable.ic_traffic_outdated_night
|
||||
: R.drawable.ic_traffic_outdated);
|
||||
}
|
||||
|
||||
void startWaitingAnimation()
|
||||
{
|
||||
mTraffic.setImageDrawable(mLoadingAnim);
|
||||
AnimationDrawable anim = (AnimationDrawable) mTraffic.getDrawable();
|
||||
mButton.setImageDrawable(mLoadingAnim);
|
||||
AnimationDrawable anim = (AnimationDrawable) mButton.getDrawable();
|
||||
anim.start();
|
||||
}
|
||||
|
||||
private void stopWaitingAnimation()
|
||||
{
|
||||
Drawable drawable = mTraffic.getDrawable();
|
||||
Drawable drawable = mButton.getDrawable();
|
||||
if (drawable instanceof AnimationDrawable)
|
||||
{
|
||||
AnimationDrawable animation = (AnimationDrawable) drawable;
|
||||
animation.stop();
|
||||
mTraffic.setImageDrawable(null);
|
||||
mButton.setImageDrawable(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOffset(int offsetX, int offsetY)
|
||||
{
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mTraffic.getLayoutParams();
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mButton.getLayoutParams();
|
||||
params.setMargins(offsetX, offsetY, 0, 0);
|
||||
mTraffic.requestLayout();
|
||||
mButton.requestLayout();
|
||||
}
|
||||
|
||||
public void show()
|
||||
{
|
||||
Animations.appearSliding(mTraffic, Animations.LEFT, null);
|
||||
Animations.appearSliding(mButton, Animations.LEFT, null);
|
||||
}
|
||||
|
||||
public void hide()
|
||||
{
|
||||
Animations.disappearSliding(mTraffic, Animations.LEFT, null);
|
||||
Animations.disappearSliding(mButton, Animations.LEFT, null);
|
||||
}
|
||||
|
||||
public void hideImmediately()
|
||||
{
|
||||
mTraffic.setVisibility(View.GONE);
|
||||
mButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void showImmediately()
|
||||
{
|
||||
mTraffic.setVisibility(View.VISIBLE);
|
||||
mButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
|
@ -11,17 +11,17 @@ import android.widget.Toast;
|
|||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.traffic.TrafficManager;
|
||||
|
||||
public class TrafficMapLayerBtnController implements TrafficManager.TrafficCallback
|
||||
public class TrafficButtonController implements TrafficManager.TrafficCallback
|
||||
{
|
||||
@NonNull
|
||||
private final TrafficMapLayerButton mButton;
|
||||
private final TrafficButton mButton;
|
||||
@NonNull
|
||||
private final AppCompatActivity mActivity;
|
||||
@Nullable
|
||||
private Dialog mDialog;
|
||||
|
||||
public TrafficMapLayerBtnController(@NonNull TrafficMapLayerButton button,
|
||||
@NonNull AppCompatActivity activity)
|
||||
public TrafficButtonController(@NonNull TrafficButton button,
|
||||
@NonNull AppCompatActivity activity)
|
||||
{
|
||||
mButton = button;
|
||||
mActivity = activity;
|