Add some code

This commit is contained in:
Alexander Sytnyk 2017-07-31 12:18:14 +03:00
parent f015d51aca
commit adb190b359
6 changed files with 87 additions and 9 deletions

View file

@ -102,6 +102,7 @@
tools:src="@drawable/ic_action_redo_dark"/>
<Button
android:id="@+id/add_dot_button"
style="@style/DialogActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -707,7 +707,7 @@ public class MapActivityActions implements DialogProvider {
.add(R.id.bottomFragmentContainer, fragment, MeasurementToolFragment.TAG)
.addToBackStack(MeasurementToolFragment.TAG)
.commitAllowingStateLoss();
return false;
return true;
}
}).createItem());

View file

@ -28,6 +28,7 @@ import net.osmand.plus.R;
import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.measurementtool.MeasurementToolLayer;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.quickaction.QuickActionRegistry;
@ -88,6 +89,7 @@ public class MapActivityLayers {
private DownloadedRegionsLayer downloadedRegionsLayer;
private MapWidgetRegistry mapWidgetRegistry;
private QuickActionRegistry quickActionRegistry;
private MeasurementToolLayer measurementToolLayer;
private StateChangedListener<Integer> transparencyListener;
@ -148,6 +150,9 @@ public class MapActivityLayers {
// 4. favorites layer
mFavouritesLayer = new FavouritesLayer();
mapView.addLayer(mFavouritesLayer, 4);
// 4.6 measurement tool layer
measurementToolLayer = new MeasurementToolLayer();
mapView.addLayer(measurementToolLayer, 4.6f);
// 5. transport layer
transportStopsLayer = new TransportStopsLayer(activity);
mapView.addLayer(transportStopsLayer, 5);
@ -583,6 +588,10 @@ public class MapActivityLayers {
return mFavouritesLayer;
}
public MeasurementToolLayer getMeasurementToolLayer() {
return measurementToolLayer;
}
public MapTextLayer getMapTextLayer() {
return mapTextLayer;
}

View file

@ -3,6 +3,7 @@ package net.osmand.plus.measurementtool;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -17,16 +18,22 @@ public class MeasurementToolFragment extends Fragment {
public static final String TAG = "MeasurementToolFragment";
private MapActivity mapActivity;
private MeasurementToolLayer measurementLayer;
private boolean wasCollapseButtonVisible;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_measurement_tool, container, false);
MapActivity mapActivity = (MapActivity) getActivity();
mapActivity = (MapActivity) getActivity();
measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache();
final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
View mainView = view.findViewById(R.id.main_view);
View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_measurement_tool, null);
final View mainView = view.findViewById(R.id.main_view);
AndroidUtils.setBackground(mapActivity, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
((ImageView) mainView.findViewById(R.id.ruler_icon))
@ -38,6 +45,52 @@ public class MeasurementToolFragment extends Fragment {
((ImageView) mainView.findViewById(R.id.next_dot_icon))
.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_redo_dark));
enterMeasurementMode();
return view;
}
@Override
public void onDestroyView() {
super.onDestroyView();
exitMeasurementMode();
}
private void enterMeasurementMode() {
measurementLayer.setInMeasurementMode(true);
mapActivity.disableDrawer();
mark(View.INVISIBLE, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info,
R.id.map_route_info_button, R.id.map_menu_button, R.id.map_compass_button, R.id.map_layers_button,
R.id.map_search_button);
View collapseButton = mapActivity.findViewById(R.id.map_collapse_button);
if (collapseButton != null && collapseButton.getVisibility() == View.VISIBLE) {
wasCollapseButtonVisible = true;
collapseButton.setVisibility(View.INVISIBLE);
} else {
wasCollapseButtonVisible = false;
}
}
private void exitMeasurementMode() {
measurementLayer.setInMeasurementMode(false);
mapActivity.enableDrawer();
mark(View.VISIBLE, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info,
R.id.map_route_info_button, R.id.map_menu_button, R.id.map_compass_button, R.id.map_layers_button,
R.id.map_search_button);
View collapseButton = mapActivity.findViewById(R.id.map_collapse_button);
if (collapseButton != null && wasCollapseButtonVisible) {
collapseButton.setVisibility(View.VISIBLE);
}
}
private void mark(int status, int... widgets) {
for (int widget : widgets) {
View v = mapActivity.findViewById(widget);
if (v != null) {
v.setVisibility(status);
}
}
}
}

View file

@ -8,6 +8,16 @@ import net.osmand.plus.views.OsmandMapTileView;
public class MeasurementToolLayer extends OsmandMapLayer {
private boolean inMeasurementMode;
public boolean isInMeasurementMode() {
return inMeasurementMode;
}
public void setInMeasurementMode(boolean inMeasurementMode) {
this.inMeasurementMode = inMeasurementMode;
}
@Override
public void initLayer(OsmandMapTileView view) {

View file

@ -712,7 +712,7 @@ public class MapControlsLayer extends OsmandMapLayer {
((app.accessibilityEnabled() || (System.currentTimeMillis() - touchEvent < TIMEOUT_TO_SHOW_BUTTONS)) && routeFollowingMode);
updateMyLocation(rh, routeDialogOpened || trackDialogOpened);
boolean showButtons = (showRouteCalculationControls || !routeFollowingMode)
&& !isInChangeMarkerPositionMode() && !isInGpxDetailsMode();
&& !isInChangeMarkerPositionMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode();
//routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_gabout_dark : R.drawable.map_directions);
if (rh.isFollowingMode()) {
routePlanningBtn.setIconResId(R.drawable.map_start_navigation);
@ -729,13 +729,14 @@ public class MapControlsLayer extends OsmandMapLayer {
mapZoomIn.updateVisibility(!routeDialogOpened);
mapZoomOut.updateVisibility(!routeDialogOpened);
compassHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && shouldShowCompass());
compassHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && shouldShowCompass() &&
!isInMeasurementToolMode());
if (layersHud.setIconResId(settings.getApplicationMode().getMapIconId())) {
layersHud.update(app, isNight);
}
layersHud.updateVisibility(!routeDialogOpened && !trackDialogOpened);
quickSearchHud.updateVisibility(!routeDialogOpened && !trackDialogOpened);
layersHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && !isInMeasurementToolMode());
quickSearchHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && !isInMeasurementToolMode());
if (!routePlanningMode && !routeFollowingMode) {
if (mapView.isZooming()) {
@ -1127,6 +1128,10 @@ public class MapControlsLayer extends OsmandMapLayer {
return contextMenuLayer.isInGpxDetailsMode();
}
private boolean isInMeasurementToolMode() {
return mapActivity.getMapLayers().getMeasurementToolLayer().isInMeasurementMode();
}
public static View.OnLongClickListener getOnClickMagnifierListener(final OsmandMapTileView view) {
return new View.OnLongClickListener() {