Add switch to action bar in snap to road mode
This commit is contained in:
parent
cb1352328b
commit
8f9035c935
6 changed files with 109 additions and 9 deletions
|
@ -478,6 +478,15 @@
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
osmand:typeface="@string/font_roboto_medium"/>
|
osmand:typeface="@string/font_roboto_medium"/>
|
||||||
|
|
||||||
|
<android.support.v7.widget.SwitchCompat
|
||||||
|
android:id="@+id/widget_top_bar_switch"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:paddingRight="16dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|
|
@ -56,7 +56,11 @@
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:layout_marginLeft="16dp"
|
android:layout_marginLeft="16dp"
|
||||||
android:layout_marginStart="16dp"/>
|
android:layout_marginStart="16dp"
|
||||||
|
android:background="@null"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false"
|
||||||
|
android:focusableInTouchMode="false"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -255,6 +255,15 @@
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
osmand:typeface="@string/font_roboto_medium"/>
|
osmand:typeface="@string/font_roboto_medium"/>
|
||||||
|
|
||||||
|
<android.support.v7.widget.SwitchCompat
|
||||||
|
android:id="@+id/widget_top_bar_switch"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:paddingRight="16dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|
|
@ -22,6 +22,7 @@ import android.view.ContextThemeWrapper;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
@ -101,6 +102,7 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
private int previousMapPosition;
|
private int previousMapPosition;
|
||||||
private NewGpxLine newGpxLine;
|
private NewGpxLine newGpxLine;
|
||||||
private boolean routePointsAdded;
|
private boolean routePointsAdded;
|
||||||
|
private boolean snapToRoadEnabled;
|
||||||
|
|
||||||
private boolean inMovePointMode;
|
private boolean inMovePointMode;
|
||||||
private boolean inAddPointAfterMode;
|
private boolean inAddPointAfterMode;
|
||||||
|
@ -209,15 +211,20 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment();
|
OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment();
|
||||||
|
fragment.setSnapToRoadEnabled(snapToRoadEnabled);
|
||||||
fragment.setOptionsOnClickListener(new OptionsBottomSheetDialogFragment.OptionsOnClickListener() {
|
fragment.setOptionsOnClickListener(new OptionsBottomSheetDialogFragment.OptionsOnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void snapToRoadOnCLick() {
|
public void snapToRoadOnCLick() {
|
||||||
previousToolBarTitle = toolBarController.getTitle();
|
if (!snapToRoadEnabled) {
|
||||||
toolBarController.setTitle(getString(R.string.snap_to_road));
|
previousToolBarTitle = toolBarController.getTitle();
|
||||||
mapActivity.refreshMap();
|
toolBarController.setTitle(getString(R.string.snap_to_road));
|
||||||
SnapToRoadBottomSheetDialogFragment fragment = new SnapToRoadBottomSheetDialogFragment();
|
mapActivity.refreshMap();
|
||||||
fragment.setListener(createSnapToRoadListener());
|
SnapToRoadBottomSheetDialogFragment fragment = new SnapToRoadBottomSheetDialogFragment();
|
||||||
fragment.show(mapActivity.getSupportFragmentManager(), SnapToRoadBottomSheetDialogFragment.TAG);
|
fragment.setListener(createSnapToRoadListener());
|
||||||
|
fragment.show(mapActivity.getSupportFragmentManager(), SnapToRoadBottomSheetDialogFragment.TAG);
|
||||||
|
} else {
|
||||||
|
disableSnapToRoadMode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -379,6 +386,15 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
toolBarController.setOnSwitchCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||||
|
if (!checked) {
|
||||||
|
disableSnapToRoadMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
mapActivity.showTopToolbar(toolBarController);
|
mapActivity.showTopToolbar(toolBarController);
|
||||||
|
|
||||||
adapter = new MeasurementToolAdapter(getMapActivity(), measurementLayer.getMeasurementPoints());
|
adapter = new MeasurementToolAdapter(getMapActivity(), measurementLayer.getMeasurementPoints());
|
||||||
|
@ -556,11 +572,27 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationModeItemClick(ApplicationMode mode) {
|
public void onApplicationModeItemClick(ApplicationMode mode) {
|
||||||
Toast.makeText(getActivity(), mode.toHumanString(getActivity()), Toast.LENGTH_SHORT).show();
|
toolBarController.setTopBarSwitchVisible(true);
|
||||||
|
toolBarController.setTopBarSwitchChecked(true);
|
||||||
|
snapToRoadEnabled = true;
|
||||||
|
MapActivity mapActivity = getMapActivity();
|
||||||
|
if (mapActivity != null) {
|
||||||
|
mapActivity.refreshMap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void disableSnapToRoadMode() {
|
||||||
|
MapActivity mapActivity = getMapActivity();
|
||||||
|
if (mapActivity != null) {
|
||||||
|
toolBarController.setTopBarSwitchVisible(false);
|
||||||
|
toolBarController.setTitle(previousToolBarTitle);
|
||||||
|
snapToRoadEnabled = false;
|
||||||
|
mapActivity.refreshMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void displayRoutePoints(MapActivity mapActivity) {
|
private void displayRoutePoints(MapActivity mapActivity) {
|
||||||
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
|
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.DrawableRes;
|
import android.support.annotation.DrawableRes;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v7.widget.SwitchCompat;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -28,6 +29,7 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
|
||||||
private boolean addLineMode;
|
private boolean addLineMode;
|
||||||
private boolean portrait;
|
private boolean portrait;
|
||||||
private boolean nightMode;
|
private boolean nightMode;
|
||||||
|
private boolean snapToRoadEnabled;
|
||||||
|
|
||||||
public void setOptionsOnClickListener(OptionsOnClickListener listener) {
|
public void setOptionsOnClickListener(OptionsOnClickListener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
|
@ -37,6 +39,10 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
|
||||||
this.addLineMode = addLineMode;
|
this.addLineMode = addLineMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSnapToRoadEnabled(boolean snapToRoadEnabled) {
|
||||||
|
this.snapToRoadEnabled = snapToRoadEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
@ -52,7 +58,13 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
|
||||||
if (nightMode) {
|
if (nightMode) {
|
||||||
((TextViewEx) mainView.findViewById(R.id.options_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark));
|
((TextViewEx) mainView.findViewById(R.id.options_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark));
|
||||||
}
|
}
|
||||||
((ImageView) mainView.findViewById(R.id.snap_to_road_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_snap_to_road));
|
if (snapToRoadEnabled) {
|
||||||
|
mainView.findViewById(R.id.snap_to_road_enabled_text_view).setVisibility(View.VISIBLE);
|
||||||
|
((SwitchCompat) mainView.findViewById(R.id.snap_to_road_switch)).setChecked(true);
|
||||||
|
}
|
||||||
|
((ImageView) mainView.findViewById(R.id.snap_to_road_icon)).setImageDrawable(snapToRoadEnabled
|
||||||
|
? getActiveIcon(R.drawable.ic_action_snap_to_road)
|
||||||
|
: getContentIcon(R.drawable.ic_action_snap_to_road));
|
||||||
((ImageView) mainView.findViewById(R.id.clear_all_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_reset_to_default_dark));
|
((ImageView) mainView.findViewById(R.id.clear_all_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_reset_to_default_dark));
|
||||||
if (!addLineMode) {
|
if (!addLineMode) {
|
||||||
((ImageView) mainView.findViewById(R.id.save_as_new_track_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark));
|
((ImageView) mainView.findViewById(R.id.save_as_new_track_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark));
|
||||||
|
@ -175,6 +187,10 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
|
||||||
return getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color);
|
return getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Drawable getActiveIcon(@DrawableRes int id) {
|
||||||
|
return getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance);
|
||||||
|
}
|
||||||
|
|
||||||
interface OptionsOnClickListener {
|
interface OptionsOnClickListener {
|
||||||
|
|
||||||
void snapToRoadOnCLick();
|
void snapToRoadOnCLick();
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package net.osmand.plus.views.mapwidgets;
|
package net.osmand.plus.views.mapwidgets;
|
||||||
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.support.v7.widget.SwitchCompat;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
@ -229,8 +231,11 @@ public class MapInfoWidgetsFactory {
|
||||||
int refreshBtnIconDarkId = R.drawable.ic_action_refresh_dark;
|
int refreshBtnIconDarkId = R.drawable.ic_action_refresh_dark;
|
||||||
int refreshBtnIconClrLightId = R.color.icon_color;
|
int refreshBtnIconClrLightId = R.color.icon_color;
|
||||||
int refreshBtnIconClrDarkId = 0;
|
int refreshBtnIconClrDarkId = 0;
|
||||||
|
|
||||||
boolean refreshBtnVisible = false;
|
boolean refreshBtnVisible = false;
|
||||||
boolean saveViewVisible = false;
|
boolean saveViewVisible = false;
|
||||||
|
protected boolean topBarSwitchVisible = false;
|
||||||
|
protected boolean topBarSwitchChecked = false;
|
||||||
|
|
||||||
int titleTextClrLightId = R.color.primary_text_light;
|
int titleTextClrLightId = R.color.primary_text_light;
|
||||||
int titleTextClrDarkId = R.color.primary_text_dark;
|
int titleTextClrDarkId = R.color.primary_text_dark;
|
||||||
|
@ -249,6 +254,7 @@ public class MapInfoWidgetsFactory {
|
||||||
OnClickListener onCloseButtonClickListener;
|
OnClickListener onCloseButtonClickListener;
|
||||||
OnClickListener onRefreshButtonClickListener;
|
OnClickListener onRefreshButtonClickListener;
|
||||||
OnClickListener onSaveViewClickListener;
|
OnClickListener onSaveViewClickListener;
|
||||||
|
OnCheckedChangeListener onSwitchCheckedChangeListener;
|
||||||
|
|
||||||
Runnable onCloseToolbarListener;
|
Runnable onCloseToolbarListener;
|
||||||
|
|
||||||
|
@ -331,6 +337,14 @@ public class MapInfoWidgetsFactory {
|
||||||
this.saveViewVisible = visible;
|
this.saveViewVisible = visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTopBarSwitchVisible(boolean visible) {
|
||||||
|
this.topBarSwitchVisible = visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTopBarSwitchChecked(boolean checked) {
|
||||||
|
this.topBarSwitchChecked = checked;
|
||||||
|
}
|
||||||
|
|
||||||
public void setTitleTextClrIds(int titleTextClrLightId, int titleTextClrDarkId) {
|
public void setTitleTextClrIds(int titleTextClrLightId, int titleTextClrDarkId) {
|
||||||
this.titleTextClrLightId = titleTextClrLightId;
|
this.titleTextClrLightId = titleTextClrLightId;
|
||||||
this.titleTextClrDarkId = titleTextClrDarkId;
|
this.titleTextClrDarkId = titleTextClrDarkId;
|
||||||
|
@ -357,6 +371,10 @@ public class MapInfoWidgetsFactory {
|
||||||
this.onSaveViewClickListener = onSaveViewClickListener;
|
this.onSaveViewClickListener = onSaveViewClickListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setOnSwitchCheckedChangeListener(OnCheckedChangeListener onSwitchCheckedChangeListener) {
|
||||||
|
this.onSwitchCheckedChangeListener = onSwitchCheckedChangeListener;
|
||||||
|
}
|
||||||
|
|
||||||
public void setOnRefreshButtonClickListener(OnClickListener onRefreshButtonClickListener) {
|
public void setOnRefreshButtonClickListener(OnClickListener onRefreshButtonClickListener) {
|
||||||
this.onRefreshButtonClickListener = onRefreshButtonClickListener;
|
this.onRefreshButtonClickListener = onRefreshButtonClickListener;
|
||||||
}
|
}
|
||||||
|
@ -369,6 +387,7 @@ public class MapInfoWidgetsFactory {
|
||||||
TextView titleView = view.getTitleView();
|
TextView titleView = view.getTitleView();
|
||||||
TextView descrView = view.getDescrView();
|
TextView descrView = view.getDescrView();
|
||||||
LinearLayout bottomViewLayout = view.getBottomViewLayout();
|
LinearLayout bottomViewLayout = view.getBottomViewLayout();
|
||||||
|
SwitchCompat switchCompat = view.getTopBarSwitch();
|
||||||
if (title != null) {
|
if (title != null) {
|
||||||
titleView.setText(title);
|
titleView.setText(title);
|
||||||
view.updateVisibility(titleView, true);
|
view.updateVisibility(titleView, true);
|
||||||
|
@ -388,6 +407,10 @@ public class MapInfoWidgetsFactory {
|
||||||
} else {
|
} else {
|
||||||
view.updateVisibility(bottomViewLayout, false);
|
view.updateVisibility(bottomViewLayout, false);
|
||||||
}
|
}
|
||||||
|
view.updateVisibility(switchCompat, topBarSwitchVisible);
|
||||||
|
if (topBarSwitchVisible) {
|
||||||
|
switchCompat.setChecked(topBarSwitchChecked);
|
||||||
|
}
|
||||||
if (view.getShadowView() != null) {
|
if (view.getShadowView() != null) {
|
||||||
view.getShadowView().setVisibility(View.VISIBLE);
|
view.getShadowView().setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
@ -408,6 +431,7 @@ public class MapInfoWidgetsFactory {
|
||||||
private ImageButton refreshButton;
|
private ImageButton refreshButton;
|
||||||
private ImageButton closeButton;
|
private ImageButton closeButton;
|
||||||
private TextView saveView;
|
private TextView saveView;
|
||||||
|
private SwitchCompat topBarSwitch;
|
||||||
private View shadowView;
|
private View shadowView;
|
||||||
private boolean nightMode;
|
private boolean nightMode;
|
||||||
|
|
||||||
|
@ -424,6 +448,7 @@ public class MapInfoWidgetsFactory {
|
||||||
titleView = (TextView) map.findViewById(R.id.widget_top_bar_title);
|
titleView = (TextView) map.findViewById(R.id.widget_top_bar_title);
|
||||||
saveView = (TextView) map.findViewById(R.id.widget_top_bar_save);
|
saveView = (TextView) map.findViewById(R.id.widget_top_bar_save);
|
||||||
descrView = (TextView) map.findViewById(R.id.widget_top_bar_description);
|
descrView = (TextView) map.findViewById(R.id.widget_top_bar_description);
|
||||||
|
topBarSwitch = (SwitchCompat) map.findViewById(R.id.widget_top_bar_switch);
|
||||||
shadowView = map.findViewById(R.id.widget_top_bar_shadow);
|
shadowView = map.findViewById(R.id.widget_top_bar_shadow);
|
||||||
updateVisibility(false);
|
updateVisibility(false);
|
||||||
}
|
}
|
||||||
|
@ -464,6 +489,10 @@ public class MapInfoWidgetsFactory {
|
||||||
return saveView;
|
return saveView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SwitchCompat getTopBarSwitch() {
|
||||||
|
return topBarSwitch;
|
||||||
|
}
|
||||||
|
|
||||||
public ImageButton getRefreshButton() {
|
public ImageButton getRefreshButton() {
|
||||||
return refreshButton;
|
return refreshButton;
|
||||||
}
|
}
|
||||||
|
@ -536,6 +565,7 @@ public class MapInfoWidgetsFactory {
|
||||||
closeButton.setOnClickListener(controller.onCloseButtonClickListener);
|
closeButton.setOnClickListener(controller.onCloseButtonClickListener);
|
||||||
refreshButton.setOnClickListener(controller.onRefreshButtonClickListener);
|
refreshButton.setOnClickListener(controller.onRefreshButtonClickListener);
|
||||||
saveView.setOnClickListener(controller.onSaveViewClickListener);
|
saveView.setOnClickListener(controller.onSaveViewClickListener);
|
||||||
|
topBarSwitch.setOnCheckedChangeListener(controller.onSwitchCheckedChangeListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateInfo() {
|
public void updateInfo() {
|
||||||
|
|
Loading…
Reference in a new issue