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"
|
||||
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
|
||||
|
|
|
@ -56,7 +56,11 @@
|
|||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
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
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -255,6 +255,15 @@
|
|||
android:visibility="gone"
|
||||
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
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.view.ContextThemeWrapper;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
|
@ -101,6 +102,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
private int previousMapPosition;
|
||||
private NewGpxLine newGpxLine;
|
||||
private boolean routePointsAdded;
|
||||
private boolean snapToRoadEnabled;
|
||||
|
||||
private boolean inMovePointMode;
|
||||
private boolean inAddPointAfterMode;
|
||||
|
@ -209,15 +211,20 @@ public class MeasurementToolFragment extends Fragment {
|
|||
@Override
|
||||
public void onClick(View view) {
|
||||
OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment();
|
||||
fragment.setSnapToRoadEnabled(snapToRoadEnabled);
|
||||
fragment.setOptionsOnClickListener(new OptionsBottomSheetDialogFragment.OptionsOnClickListener() {
|
||||
@Override
|
||||
public void snapToRoadOnCLick() {
|
||||
previousToolBarTitle = toolBarController.getTitle();
|
||||
toolBarController.setTitle(getString(R.string.snap_to_road));
|
||||
mapActivity.refreshMap();
|
||||
SnapToRoadBottomSheetDialogFragment fragment = new SnapToRoadBottomSheetDialogFragment();
|
||||
fragment.setListener(createSnapToRoadListener());
|
||||
fragment.show(mapActivity.getSupportFragmentManager(), SnapToRoadBottomSheetDialogFragment.TAG);
|
||||
if (!snapToRoadEnabled) {
|
||||
previousToolBarTitle = toolBarController.getTitle();
|
||||
toolBarController.setTitle(getString(R.string.snap_to_road));
|
||||
mapActivity.refreshMap();
|
||||
SnapToRoadBottomSheetDialogFragment fragment = new SnapToRoadBottomSheetDialogFragment();
|
||||
fragment.setListener(createSnapToRoadListener());
|
||||
fragment.show(mapActivity.getSupportFragmentManager(), SnapToRoadBottomSheetDialogFragment.TAG);
|
||||
} else {
|
||||
disableSnapToRoadMode();
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
adapter = new MeasurementToolAdapter(getMapActivity(), measurementLayer.getMeasurementPoints());
|
||||
|
@ -556,11 +572,27 @@ public class MeasurementToolFragment extends Fragment {
|
|||
|
||||
@Override
|
||||
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) {
|
||||
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -28,6 +29,7 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
private boolean addLineMode;
|
||||
private boolean portrait;
|
||||
private boolean nightMode;
|
||||
private boolean snapToRoadEnabled;
|
||||
|
||||
public void setOptionsOnClickListener(OptionsOnClickListener listener) {
|
||||
this.listener = listener;
|
||||
|
@ -37,6 +39,10 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
this.addLineMode = addLineMode;
|
||||
}
|
||||
|
||||
public void setSnapToRoadEnabled(boolean snapToRoadEnabled) {
|
||||
this.snapToRoadEnabled = snapToRoadEnabled;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
@ -52,7 +58,13 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
if (nightMode) {
|
||||
((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));
|
||||
if (!addLineMode) {
|
||||
((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);
|
||||
}
|
||||
|
||||
private Drawable getActiveIcon(@DrawableRes int id) {
|
||||
return getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance);
|
||||
}
|
||||
|
||||
interface OptionsOnClickListener {
|
||||
|
||||
void snapToRoadOnCLick();
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package net.osmand.plus.views.mapwidgets;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
@ -229,8 +231,11 @@ public class MapInfoWidgetsFactory {
|
|||
int refreshBtnIconDarkId = R.drawable.ic_action_refresh_dark;
|
||||
int refreshBtnIconClrLightId = R.color.icon_color;
|
||||
int refreshBtnIconClrDarkId = 0;
|
||||
|
||||
boolean refreshBtnVisible = false;
|
||||
boolean saveViewVisible = false;
|
||||
protected boolean topBarSwitchVisible = false;
|
||||
protected boolean topBarSwitchChecked = false;
|
||||
|
||||
int titleTextClrLightId = R.color.primary_text_light;
|
||||
int titleTextClrDarkId = R.color.primary_text_dark;
|
||||
|
@ -249,6 +254,7 @@ public class MapInfoWidgetsFactory {
|
|||
OnClickListener onCloseButtonClickListener;
|
||||
OnClickListener onRefreshButtonClickListener;
|
||||
OnClickListener onSaveViewClickListener;
|
||||
OnCheckedChangeListener onSwitchCheckedChangeListener;
|
||||
|
||||
Runnable onCloseToolbarListener;
|
||||
|
||||
|
@ -331,6 +337,14 @@ public class MapInfoWidgetsFactory {
|
|||
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) {
|
||||
this.titleTextClrLightId = titleTextClrLightId;
|
||||
this.titleTextClrDarkId = titleTextClrDarkId;
|
||||
|
@ -357,6 +371,10 @@ public class MapInfoWidgetsFactory {
|
|||
this.onSaveViewClickListener = onSaveViewClickListener;
|
||||
}
|
||||
|
||||
public void setOnSwitchCheckedChangeListener(OnCheckedChangeListener onSwitchCheckedChangeListener) {
|
||||
this.onSwitchCheckedChangeListener = onSwitchCheckedChangeListener;
|
||||
}
|
||||
|
||||
public void setOnRefreshButtonClickListener(OnClickListener onRefreshButtonClickListener) {
|
||||
this.onRefreshButtonClickListener = onRefreshButtonClickListener;
|
||||
}
|
||||
|
@ -369,6 +387,7 @@ public class MapInfoWidgetsFactory {
|
|||
TextView titleView = view.getTitleView();
|
||||
TextView descrView = view.getDescrView();
|
||||
LinearLayout bottomViewLayout = view.getBottomViewLayout();
|
||||
SwitchCompat switchCompat = view.getTopBarSwitch();
|
||||
if (title != null) {
|
||||
titleView.setText(title);
|
||||
view.updateVisibility(titleView, true);
|
||||
|
@ -388,6 +407,10 @@ public class MapInfoWidgetsFactory {
|
|||
} else {
|
||||
view.updateVisibility(bottomViewLayout, false);
|
||||
}
|
||||
view.updateVisibility(switchCompat, topBarSwitchVisible);
|
||||
if (topBarSwitchVisible) {
|
||||
switchCompat.setChecked(topBarSwitchChecked);
|
||||
}
|
||||
if (view.getShadowView() != null) {
|
||||
view.getShadowView().setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
@ -408,6 +431,7 @@ public class MapInfoWidgetsFactory {
|
|||
private ImageButton refreshButton;
|
||||
private ImageButton closeButton;
|
||||
private TextView saveView;
|
||||
private SwitchCompat topBarSwitch;
|
||||
private View shadowView;
|
||||
private boolean nightMode;
|
||||
|
||||
|
@ -424,6 +448,7 @@ public class MapInfoWidgetsFactory {
|
|||
titleView = (TextView) map.findViewById(R.id.widget_top_bar_title);
|
||||
saveView = (TextView) map.findViewById(R.id.widget_top_bar_save);
|
||||
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);
|
||||
updateVisibility(false);
|
||||
}
|
||||
|
@ -464,6 +489,10 @@ public class MapInfoWidgetsFactory {
|
|||
return saveView;
|
||||
}
|
||||
|
||||
public SwitchCompat getTopBarSwitch() {
|
||||
return topBarSwitch;
|
||||
}
|
||||
|
||||
public ImageButton getRefreshButton() {
|
||||
return refreshButton;
|
||||
}
|
||||
|
@ -536,6 +565,7 @@ public class MapInfoWidgetsFactory {
|
|||
closeButton.setOnClickListener(controller.onCloseButtonClickListener);
|
||||
refreshButton.setOnClickListener(controller.onRefreshButtonClickListener);
|
||||
saveView.setOnClickListener(controller.onSaveViewClickListener);
|
||||
topBarSwitch.setOnCheckedChangeListener(controller.onSwitchCheckedChangeListener);
|
||||
}
|
||||
|
||||
public void updateInfo() {
|
||||
|
|
Loading…
Reference in a new issue