[android] Fixed review notes : added controller

This commit is contained in:
Dmitry Donskoy 2018-06-29 14:54:24 +03:00 committed by Aleksandr Zatsepin
parent 2f61dd9dc1
commit 6258c690fb
26 changed files with 542 additions and 231 deletions

View file

@ -81,4 +81,7 @@
<attr name="titleDefault" format="reference"/>
<attr name="subTitleDefault" format="reference"/>
</declare-styleable>
<attr name="trafficMenuDisabled" format="reference"/>
<attr name="subwayMenuDisabled" format="reference"/>
</resources>

View file

@ -127,6 +127,8 @@
<item name="adChoicesIcon">@drawable/ic_ad_light</item>
<item name="saleIcon">@drawable/ic_deal_light</item>
<item name="nav_bg_subway">@drawable/bg_subway_light</item>
<item name="trafficMenuDisabled">@drawable/ic_traffic_menu_light_off</item>
<item name="subwayMenuDisabled">@drawable/ic_subway_menu_light_off</item>
</style>
<!-- Night theme -->
@ -257,5 +259,7 @@
<item name="adChoicesIcon">@drawable/ic_ad_dark</item>
<item name="saleIcon">@drawable/ic_deal_dark</item>
<item name="nav_bg_subway">@drawable/bg_subway_night</item>
<item name="trafficMenuDisabled">@drawable/ic_traffic_menu_dark_off</item>
<item name="subwayMenuDisabled">@drawable/ic_subway_menu_dark_off</item>
</style>
</resources>

View file

@ -45,6 +45,7 @@ import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.FeatureId;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.maplayer.MapLayerCompositeController;
import com.mapswithme.maps.discovery.DiscoveryActivity;
import com.mapswithme.maps.discovery.DiscoveryFragment;
import com.mapswithme.maps.discovery.ItemType;
@ -81,15 +82,13 @@ import com.mapswithme.maps.settings.SettingsActivity;
import com.mapswithme.maps.settings.StoragePathManager;
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.ToggleMapLayerDialog;
import com.mapswithme.maps.maplayer.Mode;
import com.mapswithme.maps.maplayer.subway.OnSubwayModeSelectListener;
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.TrafficButton;
import com.mapswithme.maps.traffic.widget.TrafficButtonController;
import com.mapswithme.maps.maplayer.traffic.TrafficManager;
import com.mapswithme.maps.maplayer.traffic.widget.OnTrafficModeSelectListener;
import com.mapswithme.maps.maplayer.traffic.widget.TrafficButton;
import com.mapswithme.maps.widget.FadeView;
import com.mapswithme.maps.widget.menu.BaseMenu;
import com.mapswithme.maps.widget.menu.MainMenu;
@ -182,10 +181,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
@NonNull
private View mPositionChooser;
@SuppressWarnings("NullableProblems")
@NonNull
private ImageButton mSubwayBtn;
private RoutingPlanInplaceController mRoutingPlanInplaceController;
@Nullable
@ -199,12 +194,11 @@ public class MwmActivity extends BaseMwmFragmentActivity
@Nullable
private MyPositionButton mNavMyPosition;
private TrafficButton mTraffic;
@Nullable
private NavigationButtonsAnimationController mNavAnimationController;
@Nullable
private TrafficButtonController mTrafficButtonController;
@SuppressWarnings("NullableProblems")
@NonNull
private MapLayerCompositeController mToggleMapLayerController;
@Nullable
private SearchFilterController mFilterController;
@ -234,42 +228,13 @@ public class MwmActivity extends BaseMwmFragmentActivity
@Override
public void onSubwayModeSelected()
{
if (isOptionalMapLayerEnabled())
{
mTraffic.hideImmediately();
mSubwayBtn.setVisibility(View.VISIBLE);
mSubwayBtn.setSelected(true);
return;
}
onResetOptionalMapLayers();
mToggleMapLayerController.toggleMode(Mode.SUBWAY);
}
@Override
public void onTrafficModeSelected()
{
if (isOptionalMapLayerEnabled())
{
mTraffic.showImmediately();
mSubwayBtn.setSelected(false);
mSubwayBtn.setVisibility(View.GONE);
return;
}
onResetOptionalMapLayers();
}
private void onResetOptionalMapLayers()
{
SubwayManager.from(getApplicationContext()).setEnabled(false);
TrafficManager.INSTANCE.setEnabled(false);
mTraffic.hideImmediately();
mSubwayBtn.setVisibility(View.VISIBLE);
mSubwayBtn.setSelected(false);
}
private boolean isOptionalMapLayerEnabled()
{
return SubwayManager.from(getApplicationContext()).isEnabled()
|| TrafficManager.INSTANCE.isEnabled();
mToggleMapLayerController.toggleMode(Mode.TRAFFIC);
}
public interface LeftAnimationTrackListener
@ -768,33 +733,17 @@ public class MwmActivity extends BaseMwmFragmentActivity
View myPosition = frame.findViewById(R.id.my_position);
mNavMyPosition = new MyPositionButton(myPosition, mOnMyPositionClickListener);
initToggleMapLayerBtn(frame);
initToggleMapLayerController(frame);
mNavAnimationController = new NavigationButtonsAnimationController(
zoomIn, zoomOut, myPosition, getWindow().getDecorView().getRootView(), this);
}
private void initToggleMapLayerBtn(@NonNull View frame)
{
initTrafficBtn(frame);
initSubwayBtn(frame);
showToggleMapLayerBtn();
}
private void initTrafficBtn(@NonNull View frame)
private void initToggleMapLayerController(@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);
SubwayManager subway = SubwayManager.from(this);
mSubwayBtn.setSelected(subway.isEnabled());
mSubwayBtn.setOnClickListener(new OpenBottomDialogClickListener());
UiUtils.addStatusBarOffset(mSubwayBtn);
TrafficButton traffic = new TrafficButton(trafficBtn);
View subway = frame.findViewById(R.id.subway);
mToggleMapLayerController = new MapLayerCompositeController(traffic, subway, this);
}
public boolean closePlacePage()
@ -1421,8 +1370,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
RoutingController.get().attach(this);
if (MapFragment.nativeIsEngineCreated())
LocationHelper.INSTANCE.attach(this);
if (mTrafficButtonController != null)
TrafficManager.INSTANCE.attach(mTrafficButtonController);
mToggleMapLayerController.attachCore();
if (mNavigationController != null)
TrafficManager.INSTANCE.attach(mNavigationController);
mPlacePage.onActivityStarted();
@ -1437,8 +1385,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
LocationHelper.INSTANCE.detach(!isFinishing());
RoutingController.get().detach();
TrafficManager.INSTANCE.detachAll();
if (mTrafficButtonController != null)
mTrafficButtonController.destroy();
mToggleMapLayerController.detachCore();
mPlacePage.onActivityStopped();
}
@ -1633,7 +1580,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
mNavAnimationController.disappearZoomButtons();
if (mNavMyPosition != null)
mNavMyPosition.hide();
mTraffic.hide();
mToggleMapLayerController.hide();
}
else
{
@ -1650,7 +1597,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
appearMenuFrame(menu);
showNavMyPositionBtn();
showToggleMapLayerBtn();
mToggleMapLayerController.applyLastActiveMode();
}
private void showNavMyPositionBtn()
@ -1671,26 +1618,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
});
}
private void showToggleMapLayerBtn()
{
if (TrafficManager.INSTANCE.isEnabled())
showTrafficBtn();
else
showSubwayBtn();
}
private void showSubwayBtn()
{
Animations.appearSliding(mSubwayBtn, Animations.LEFT, null);
mTraffic.hideImmediately();
}
private void showTrafficBtn()
{
mTraffic.show();
mSubwayBtn.setVisibility(View.GONE);
}
@Override
public void onPreviewVisibilityChanged(boolean isVisible)
{
@ -2171,7 +2098,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
private void adjustTraffic(int offsetX, int offsetY)
{
mTraffic.setOffset(offsetX, offsetY);
mToggleMapLayerController.adjust(offsetX, offsetY);
}
@Override
@ -2390,7 +2317,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
&& (RoutingController.get().isPlanning() || RoutingController.get().isNavigating()))
{
if (UiUtils.isLandscape(this))
mTraffic.hide();
mToggleMapLayerController.hide();
else
mNavigationController.fadeOutSearchButtons();
}
@ -2730,18 +2657,4 @@ public class MwmActivity extends BaseMwmFragmentActivity
myPositionClick();
}
}
private class OpenBottomDialogClickListener implements View.OnClickListener
{
@Override
public void onClick(View v)
{
if (isOptionalMapLayerEnabled())
{
onResetOptionalMapLayers();
return;
}
ToggleMapLayerDialog.show(MwmActivity.this);
}
}
}

View file

@ -25,8 +25,8 @@ import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.location.TrackRecorder;
import com.mapswithme.maps.routing.RoutingController;
import com.mapswithme.maps.sound.TtsPlayer;
import com.mapswithme.maps.subway.SubwayManager;
import com.mapswithme.maps.traffic.TrafficManager;
import com.mapswithme.maps.maplayer.subway.SubwayManager;
import com.mapswithme.maps.maplayer.traffic.TrafficManager;
import com.mapswithme.maps.ugc.UGC;
import com.mapswithme.util.Config;
import com.mapswithme.util.Counters;
@ -301,6 +301,7 @@ public class MwmApplication extends Application
LocationHelper.INSTANCE.initialize();
RoutingController.get().initialize();
TrafficManager.INSTANCE.initialize();
SubwayManager.from(this).initialize();
mFrameworkInitialized = true;
}

View file

@ -0,0 +1,7 @@
package com.mapswithme.maps.content;
public interface CoreDetachable
{
void attachCore();
void detachCore();
}

View file

@ -1,25 +1,28 @@
package com.mapswithme.maps.adapter;
package com.mapswithme.maps.maplayer;
import android.content.Context;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import com.mapswithme.maps.R;
import com.mapswithme.maps.subway.Mode;
import com.mapswithme.util.ThemeUtils;
public abstract class BottomSheetItem
{
@DrawableRes
private final int mEnabledStateDrawableResId;
@DrawableRes
private final int mDisabledStateDrawableResId;
@StringRes
private final int mTitleResId;
@NonNull
private final Mode mMode;
protected BottomSheetItem(int enabledStateDrawableResId,
int disabledStateDrawableResId,
int titleResId,
@NonNull Mode mode)
BottomSheetItem(@DrawableRes int enabledStateDrawableResId,
@DrawableRes int disabledStateDrawableResId,
@StringRes int titleResId,
@NonNull Mode mode)
{
mEnabledStateDrawableResId = enabledStateDrawableResId;
mDisabledStateDrawableResId = disabledStateDrawableResId;
@ -32,12 +35,6 @@ public abstract class BottomSheetItem
{
return mMode;
}
/*
boolean isSelected(@NonNull Context context);
void onSelected(@NonNull MwmActivity activity);
*/
@DrawableRes
public int getEnabledStateDrawable()
@ -64,22 +61,13 @@ public abstract class BottomSheetItem
super(drawableResId, disabledStateDrawableResId, R.string.button_layer_subway, Mode.SUBWAY);
}
public static BottomSheetItem makeInstance()
public static BottomSheetItem makeInstance(@NonNull Context mContext)
{
int disabled = getDisabledStateFromTheme(R.drawable.ic_subway_menu_dark_off,
R.drawable.ic_subway_menu_light_off);
int disabled = ThemeUtils.getResource(mContext, R.attr.subwayMenuDisabled);
return new Subway(R.drawable.ic_subway_menu_on, disabled);
}
}
private static int getDisabledStateFromTheme(int light, int dark)
{
return ThemeUtils.isNightTheme()
? light
: dark;
}
public static class Traffic extends BottomSheetItem
{
private Traffic(int drawableResId, int disabledStateDrawableResId)
@ -87,14 +75,11 @@ public abstract class BottomSheetItem
super(drawableResId, disabledStateDrawableResId, R.string.button_layer_traffic, Mode.TRAFFIC);
}
public static BottomSheetItem makeInstance()
public static BottomSheetItem makeInstance(@NonNull Context mContext)
{
int disabled = getDisabledStateFromTheme(R.drawable.ic_traffic_menu_dark_off,
R.drawable.ic_traffic_menu_light_off);
int disabled = ThemeUtils.getResource(mContext, R.attr.trafficMenuDisabled);
return new Traffic(R.drawable.ic_traffic_menu_on, disabled);
}
}
}

View file

@ -0,0 +1,225 @@
package com.mapswithme.maps.maplayer;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import com.mapswithme.maps.maplayer.subway.SubwayMapLayerController;
import com.mapswithme.maps.maplayer.traffic.widget.TrafficButton;
import com.mapswithme.maps.maplayer.traffic.widget.TrafficButtonController;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
public class MapLayerCompositeController implements MapLayerController
{
@NonNull
private final AppCompatActivity mActivity;
@NonNull
private final Collection<ControllerAndMode> mChildrenEntries;
@NonNull
private ControllerAndMode mMasterEntry;
public MapLayerCompositeController(@NonNull TrafficButton traffic, @NonNull View subway,
@NonNull AppCompatActivity activity)
{
OpenBottomDialogClickListener listener = new OpenBottomDialogClickListener();
mActivity = activity;
mChildrenEntries = createEntries(traffic, subway, activity, listener);
mMasterEntry = getCurrentLayer();
toggleMode(mMasterEntry.mMode);
}
@NonNull
private static Collection<ControllerAndMode> createEntries(@NonNull TrafficButton traffic,
@NonNull View subway,
@NonNull AppCompatActivity activity,
@NonNull OpenBottomDialogClickListener dialogClickListener)
{
traffic.setOnclickListener(dialogClickListener);
TrafficButtonController trafficButtonController = new TrafficButtonController(traffic,
activity);
subway.setOnClickListener(dialogClickListener);
SubwayMapLayerController subwayMapLayerController = new SubwayMapLayerController(subway);
ControllerAndMode subwayPair = new ControllerAndMode(Mode.SUBWAY, subwayMapLayerController);
ControllerAndMode trafficPair = new ControllerAndMode(Mode.TRAFFIC, trafficButtonController);
Set<ControllerAndMode> entries = new LinkedHashSet<>();
entries.add(subwayPair);
entries.add(trafficPair);
return Collections.unmodifiableSet(entries);
}
public void toggleMode(@NonNull Mode mode)
{
toggleMode(mode, false);
}
public void toggleMode(@NonNull Mode mode, boolean animate)
{
setMasterController(mode);
showMasterController(animate);
boolean enabled = mode.isEnabled(mActivity);
if (enabled)
turnOn();
else
turnOff();
}
public void applyLastActiveMode()
{
toggleMode(mMasterEntry.mMode, true);
}
@Override
public void attachCore()
{
for (ControllerAndMode each : mChildrenEntries)
{
each.mController.attachCore();
}
}
@Override
public void detachCore()
{
for (ControllerAndMode each : mChildrenEntries)
{
each.mController.detachCore();
}
}
private void setMasterController(@NonNull Mode mode)
{
for (ControllerAndMode each : mChildrenEntries)
{
if (each.mMode == mode)
{
mMasterEntry = each;
}
else
{
each.mController.hideImmediately();
each.mMode.setEnabled(mActivity, false);
}
}
}
private void showMasterController(boolean animate)
{
if (animate)
mMasterEntry.mController.show();
else
mMasterEntry.mController.showImmediately();
}
@NonNull
private ControllerAndMode getCurrentLayer()
{
for (ControllerAndMode each : mChildrenEntries)
{
if (each.mMode.isEnabled(mActivity))
return each;
}
return mChildrenEntries.iterator().next();
}
@Override
public void turnOn()
{
mMasterEntry.mController.turnOn();
mMasterEntry.mMode.setEnabled(mActivity, true);
}
@Override
public void turnOff()
{
mMasterEntry.mController.turnOff();
mMasterEntry.mMode.setEnabled(mActivity, false);
}
@Override
public void show()
{
mMasterEntry.mController.show();
}
@Override
public void showImmediately()
{
mMasterEntry.mController.showImmediately();
}
@Override
public void hide()
{
mMasterEntry.mController.hide();
}
@Override
public void hideImmediately()
{
mMasterEntry.mController.hideImmediately();
}
@Override
public void adjust(int offsetX, int offsetY)
{
mMasterEntry.mController.adjust(offsetX, offsetY);
}
private void showDialog()
{
ToggleMapLayerDialog.show(mActivity);
}
private static class ControllerAndMode
{
@NonNull
private final Mode mMode;
@NonNull
private final MapLayerController mController;
ControllerAndMode(@NonNull Mode mode, @NonNull MapLayerController controller)
{
mMode = mode;
mController = controller;
}
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ControllerAndMode that = (ControllerAndMode) o;
return mMode == that.mMode;
}
@Override
public int hashCode()
{
return mMode.hashCode();
}
}
private class OpenBottomDialogClickListener implements View.OnClickListener
{
@Override
public void onClick(View v)
{
if (mMasterEntry.mMode.isEnabled(mActivity))
{
turnOff();
toggleMode(getCurrentLayer().mMode);
}
else
{
showDialog();
}
}
}
}

View file

@ -0,0 +1,14 @@
package com.mapswithme.maps.maplayer;
import com.mapswithme.maps.content.CoreDetachable;
public interface MapLayerController extends CoreDetachable
{
void turnOn();
void turnOff();
void show();
void showImmediately();
void hide();
void hideImmediately();
void adjust(int offsetX, int offsetY);
}

View file

@ -0,0 +1,60 @@
package com.mapswithme.maps.maplayer;
import android.content.Context;
import android.support.annotation.NonNull;
import com.mapswithme.maps.maplayer.subway.SubwayManager;
import com.mapswithme.maps.maplayer.traffic.TrafficManager;
public enum Mode
{
TRAFFIC
{
@Override
public boolean isEnabled(@NonNull Context context)
{
return !SubwayManager.from(context).isEnabled()
&& TrafficManager.INSTANCE.isEnabled();
}
@Override
public void setEnabled(@NonNull Context context, boolean isEnabled)
{
TrafficManager.INSTANCE.setEnabled(isEnabled);
}
@Override
public void toggle(@NonNull Context context)
{
TrafficManager.INSTANCE.toggle();
SubwayManager.from(context).setEnabled(false);
}
},
SUBWAY
{
@Override
public boolean isEnabled(@NonNull Context context)
{
return SubwayManager.from(context).isEnabled();
}
@Override
public void setEnabled(@NonNull Context context, boolean isEnabled)
{
SubwayManager.from(context).setEnabled(isEnabled);
}
@Override
public void toggle(@NonNull Context context)
{
SubwayManager.from(context).toggle();
TrafficManager.INSTANCE.setEnabled(false);
}
};
public abstract boolean isEnabled(@NonNull Context context);
public abstract void setEnabled(@NonNull Context context, boolean isEnabled);
public abstract void toggle(@NonNull Context context);
}

View file

@ -1,4 +1,4 @@
package com.mapswithme.maps.subway;
package com.mapswithme.maps.maplayer;
import android.app.Dialog;
import android.content.Context;
@ -20,10 +20,10 @@ import android.widget.ImageButton;
import android.widget.TextView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.adapter.BottomSheetItem;
import com.mapswithme.maps.adapter.SpanningLinearLayoutManager;
import com.mapswithme.maps.maplayer.subway.OnSubwayModeSelectListener;
import com.mapswithme.maps.widget.recycler.SpanningLinearLayoutManager;
import com.mapswithme.maps.bookmarks.OnItemClickListener;
import com.mapswithme.maps.traffic.widget.OnTrafficModeSelectListener;
import com.mapswithme.maps.maplayer.traffic.widget.OnTrafficModeSelectListener;
import java.util.Arrays;
import java.util.List;
@ -31,10 +31,6 @@ import java.util.Objects;
public class ToggleMapLayerDialog extends DialogFragment
{
@NonNull
@SuppressWarnings("NullableProblems")
private View mRoot;
@NonNull
@SuppressWarnings("NullableProblems")
private ModeAdapter mAdapter;
@ -45,27 +41,27 @@ public class ToggleMapLayerDialog extends DialogFragment
{
BottomSheetDialog dialog = new BottomSheetDialog(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
mRoot = inflater.inflate(R.layout.fragment_toggle_map_layer, null, false);
dialog.setContentView(mRoot);
initChildren();
View root = inflater.inflate(R.layout.fragment_toggle_map_layer, null, false);
dialog.setContentView(root);
initChildren(root);
return dialog;
}
private void initChildren()
private void initChildren(@NonNull View root)
{
initCloseBtn();
initRecycler();
initCloseBtn(root);
initRecycler(root);
}
private void initCloseBtn()
private void initCloseBtn(@NonNull View root)
{
View closeBtn = mRoot.findViewById(R.id.сlose_btn);
View closeBtn = root.findViewById(R.id.сlose_btn);
closeBtn.setOnClickListener(v -> dismiss());
}
private void initRecycler()
private void initRecycler(@NonNull View root)
{
RecyclerView recycler = mRoot.findViewById(R.id.recycler);
RecyclerView recycler = root.findViewById(R.id.recycler);
RecyclerView.LayoutManager layoutManager = new SpanningLinearLayoutManager(getContext(),
LinearLayoutManager.HORIZONTAL,
false);
@ -79,13 +75,13 @@ public class ToggleMapLayerDialog extends DialogFragment
{
SubwayItemClickListener subwayListener = new SubwayItemClickListener();
Pair<BottomSheetItem, OnItemClickListener<BottomSheetItem>> subway
= new Pair<>(BottomSheetItem.Subway.makeInstance(), subwayListener);
= new Pair<>(BottomSheetItem.Subway.makeInstance(getContext()), subwayListener);
TrafficItemClickListener trafficListener = new TrafficItemClickListener();
Pair<BottomSheetItem, OnItemClickListener<BottomSheetItem>> traffic
= new Pair<>(BottomSheetItem.Traffic.makeInstance(), trafficListener);
= new Pair<>(BottomSheetItem.Traffic.makeInstance(getContext()), trafficListener);
return Arrays.asList(subway, traffic);
return Arrays.asList(traffic, subway);
}
public static void show(@NonNull AppCompatActivity activity)
@ -185,6 +181,7 @@ public class ToggleMapLayerDialog extends DialogFragment
@Override
public final void onItemClick(@NonNull View v, @NonNull BottomSheetItem item)
{
item.getMode().toggle(getContext());
onItemClickInternal(v, item);
mAdapter.notifyDataSetChanged();
}

View file

@ -1,4 +1,4 @@
package com.mapswithme.maps.subway;
package com.mapswithme.maps.maplayer.subway;
public interface OnSubwayModeSelectListener
{

View file

@ -1,4 +1,4 @@
package com.mapswithme.maps.subway;
package com.mapswithme.maps.maplayer.subway;
import android.support.annotation.MainThread;
import android.support.annotation.NonNull;

View file

@ -1,13 +1,10 @@
package com.mapswithme.maps.subway;
package com.mapswithme.maps.maplayer.subway;
import android.content.Context;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import com.mapswithme.util.ThemeUtils;
public class SubwayManager
{
@ -23,11 +20,6 @@ public class SubwayManager
if (isEnabled == isEnabled())
return;
if (isEnabled)
addSchemeChangedListener(mSchemeChangedListener);
else
removeSchemeChangedListener(mSchemeChangedListener);
Framework.nativeSetTransitSchemeEnabled(isEnabled);
Framework.nativeSaveSettingSchemeEnabled(isEnabled);
}
@ -42,14 +34,14 @@ public class SubwayManager
setEnabled(!isEnabled());
}
public void addSchemeChangedListener(@NonNull OnTransitSchemeChangedListener listener)
public void initialize()
{
nativeAddListener(listener);
registryListener();
}
public void removeSchemeChangedListener(@NonNull OnTransitSchemeChangedListener listener)
private void registryListener()
{
nativeRemoveListener(listener);
nativeAddListener(mSchemeChangedListener);
}
@NonNull
@ -58,7 +50,7 @@ public class SubwayManager
MwmApplication app = (MwmApplication) context.getApplicationContext();
return app.getSubwayManager();
}
private static native void nativeAddListener(@NonNull OnTransitSchemeChangedListener listener);
private static native void nativeRemoveListener(@NonNull OnTransitSchemeChangedListener listener);
}

View file

@ -0,0 +1,77 @@
package com.mapswithme.maps.maplayer.subway;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import com.mapswithme.maps.maplayer.MapLayerController;
import com.mapswithme.util.Animations;
import com.mapswithme.util.UiUtils;
public class SubwayMapLayerController implements MapLayerController
{
@NonNull
private final View mSubwayBtn;
public SubwayMapLayerController(@NonNull View subwayBtn)
{
mSubwayBtn = subwayBtn;
UiUtils.addStatusBarOffset(mSubwayBtn);
}
@Override
public void turnOn()
{
mSubwayBtn.setSelected(true);
}
@Override
public void turnOff()
{
mSubwayBtn.setSelected(false);
}
@Override
public void show()
{
Animations.appearSliding(mSubwayBtn, Animations.LEFT, null);
}
@Override
public void showImmediately()
{
mSubwayBtn.setVisibility(View.VISIBLE);
}
@Override
public void hide()
{
Animations.disappearSliding(mSubwayBtn, Animations.LEFT, null);
}
@Override
public void hideImmediately()
{
mSubwayBtn.setVisibility(View.GONE);
}
@Override
public void adjust(int offsetX, int offsetY)
{
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) mSubwayBtn.getLayoutParams();
params.setMargins(offsetX, offsetY, 0, 0);
mSubwayBtn.setLayoutParams(params);
}
@Override
public void attachCore()
{
/* Do nothing by default */
}
@Override
public void detachCore()
{
/* Do nothing by default */
}
}

View file

@ -1,4 +1,4 @@
package com.mapswithme.maps.subway;
package com.mapswithme.maps.maplayer.subway;
import android.support.annotation.NonNull;

View file

@ -1,4 +1,4 @@
package com.mapswithme.maps.traffic;
package com.mapswithme.maps.maplayer.traffic;
import android.support.annotation.MainThread;
import android.support.annotation.NonNull;
@ -38,19 +38,19 @@ public enum TrafficManager
{
checkInitialization();
if (mState == TrafficState.DISABLED)
enable();
else
if (isEnabled())
disable();
else
enable();
}
public void enable()
private void enable()
{
mLogger.d(mTag, "Enable traffic");
TrafficState.nativeEnable();
}
public void disable()
private void disable()
{
checkInitialization();
@ -107,6 +107,8 @@ public enum TrafficManager
public void setEnabled(boolean enabled)
{
checkInitialization();
if (isEnabled() == enabled)
return;

View file

@ -1,4 +1,4 @@
package com.mapswithme.maps.traffic;
package com.mapswithme.maps.maplayer.traffic;
import android.support.annotation.IntDef;
import android.support.annotation.MainThread;
@ -7,7 +7,7 @@ import android.support.annotation.NonNull;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
public final class TrafficState
final class TrafficState
{
interface StateChangeListener
{

View file

@ -1,4 +1,4 @@
package com.mapswithme.maps.traffic.widget;
package com.mapswithme.maps.maplayer.traffic.widget;
public interface OnTrafficModeSelectListener
{

View file

@ -1,4 +1,4 @@
package com.mapswithme.maps.traffic.widget;
package com.mapswithme.maps.maplayer.traffic.widget;
import android.content.Context;
import android.content.res.Resources;
@ -107,4 +107,9 @@ public class TrafficButton
{
mButton.setVisibility(View.VISIBLE);
}
public void setOnclickListener(View.OnClickListener onclickListener)
{
mButton.setOnClickListener(onclickListener);
}
}

View file

@ -1,27 +1,28 @@
package com.mapswithme.maps.traffic.widget;
package com.mapswithme.maps.maplayer.traffic.widget;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
import com.mapswithme.maps.R;
import com.mapswithme.maps.traffic.TrafficManager;
import com.mapswithme.maps.maplayer.MapLayerController;
import com.mapswithme.maps.maplayer.traffic.TrafficManager;
public class TrafficButtonController implements TrafficManager.TrafficCallback
public class TrafficButtonController implements TrafficManager.TrafficCallback, MapLayerController
{
@NonNull
private final TrafficButton mButton;
@NonNull
private final AppCompatActivity mActivity;
private final Activity mActivity;
@Nullable
private Dialog mDialog;
public TrafficButtonController(@NonNull TrafficButton button,
@NonNull AppCompatActivity activity)
@NonNull Activity activity)
{
mButton = button;
mActivity = activity;
@ -29,16 +30,70 @@ public class TrafficButtonController implements TrafficManager.TrafficCallback
@Override
public void onEnabled()
{
turnOn();
}
@Override
public void turnOn()
{
mButton.turnOn();
}
@Override
public void hideImmediately()
{
mButton.hideImmediately();
}
@Override
public void adjust(int offsetX, int offsetY)
{
mButton.setOffset(offsetX, offsetY);
}
@Override
public void attachCore()
{
TrafficManager.INSTANCE.attach(this);
}
@Override
public void detachCore()
{
destroy();
}
@Override
public void onDisabled()
{
turnOff();
}
@Override
public void turnOff()
{
mButton.turnOff();
}
@Override
public void show()
{
mButton.show();
}
@Override
public void showImmediately()
{
mButton.showImmediately();
}
@Override
public void hide()
{
mButton.hide();
}
@Override
public void onWaitingData()
{
@ -54,7 +109,7 @@ public class TrafficButtonController implements TrafficManager.TrafficCallback
@Override
public void onNoData(boolean notify)
{
mButton.turnOn();
turnOn();
if (notify)
Toast.makeText(mActivity, R.string.traffic_data_unavailable, Toast.LENGTH_SHORT).show();
}
@ -72,7 +127,7 @@ public class TrafficButtonController implements TrafficManager.TrafficCallback
@Override
public void onClick(DialogInterface dialog, int which)
{
TrafficManager.INSTANCE.disable();
TrafficManager.INSTANCE.setEnabled(false);
}
})
.setCancelable(true)
@ -81,7 +136,7 @@ public class TrafficButtonController implements TrafficManager.TrafficCallback
@Override
public void onCancel(DialogInterface dialog)
{
TrafficManager.INSTANCE.disable();
TrafficManager.INSTANCE.setEnabled(false);
}
});
mDialog = builder.show();
@ -96,7 +151,7 @@ public class TrafficButtonController implements TrafficManager.TrafficCallback
@Override
public void onExpiredData(boolean notify)
{
mButton.turnOn();
turnOn();
if (notify)
Toast.makeText(mActivity, R.string.traffic_update_maps_text, Toast.LENGTH_SHORT).show();
}
@ -104,7 +159,7 @@ public class TrafficButtonController implements TrafficManager.TrafficCallback
@Override
public void onExpiredApp(boolean notify)
{
mButton.turnOn();
turnOn();
if (notify)
Toast.makeText(mActivity, R.string.traffic_update_app, Toast.LENGTH_SHORT).show();
}

View file

@ -23,7 +23,7 @@ import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.settings.SettingsActivity;
import com.mapswithme.maps.sound.TtsPlayer;
import com.mapswithme.maps.traffic.TrafficManager;
import com.mapswithme.maps.maplayer.traffic.TrafficManager;
import com.mapswithme.maps.widget.FlatProgressView;
import com.mapswithme.maps.widget.menu.NavMenu;
import com.mapswithme.util.Animations;

View file

@ -1,28 +0,0 @@
package com.mapswithme.maps.subway;
import android.content.Context;
import android.support.annotation.NonNull;
import com.mapswithme.maps.traffic.TrafficManager;
public enum Mode
{
TRAFFIC
{
@Override
public boolean isEnabled(@NonNull Context context)
{
return TrafficManager.INSTANCE.isEnabled();
}
},
SUBWAY
{
@Override
public boolean isEnabled(@NonNull Context context)
{
return SubwayManager.from(context).isEnabled();
}
};
public abstract boolean isEnabled(@NonNull Context context);
}

View file

@ -11,7 +11,7 @@ import android.widget.ImageView;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.R;
import com.mapswithme.maps.sound.TtsPlayer;
import com.mapswithme.maps.traffic.TrafficManager;
import com.mapswithme.maps.maplayer.traffic.TrafficManager;
import com.mapswithme.maps.widget.RotateDrawable;
import com.mapswithme.util.Graphics;
import com.mapswithme.util.UiUtils;

View file

@ -1,4 +1,4 @@
package com.mapswithme.maps.adapter;
package com.mapswithme.maps.widget.recycler;
import android.content.Context;
import android.support.annotation.NonNull;

View file

@ -48,7 +48,7 @@ public final class UiUtils
public static final String PHRASE_SEPARATOR = "";
private static float sScreenDensity;
public static void addStatusBarOffset(View view)
public static void addStatusBarOffset(@NonNull View view)
{
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
params.setMargins(0, UiUtils.getStatusBarHeight(view.getContext()), 0, 0);

View file

@ -681,6 +681,5 @@ public class Utils
public interface Proc<T>
{
void invoke(@NonNull T param);
}
}