Fix straight line

This commit is contained in:
Dima-1 2020-07-16 18:51:57 +03:00
parent a38921a095
commit 794d611f60
2 changed files with 27 additions and 17 deletions

View file

@ -571,6 +571,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
mapActivity.refreshMap();
SnapToRoadBottomSheetDialogFragment fragment = new SnapToRoadBottomSheetDialogFragment();
fragment.setListener(createSnapToRoadFragmentListener());
fragment.setShowStraightLine(true);
fragment.show(mapActivity.getSupportFragmentManager(), SnapToRoadBottomSheetDialogFragment.TAG);
}
}

View file

@ -2,6 +2,7 @@ package net.osmand.plus.measurementtool;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.Window;
@ -18,6 +19,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
@ -35,6 +37,7 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
private boolean portrait;
private boolean snapToRoadEnabled;
private boolean removeDefaultMode = true;
private boolean showStraightLine = false;
public void setListener(SnapToRoadFragmentListener listener) {
this.listener = listener;
@ -44,6 +47,10 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
this.removeDefaultMode = removeDefaultMode;
}
public void setShowStraightLine(boolean showStraightLine) {
this.showStraightLine = showStraightLine;
}
@Override
public void setupDialog(Dialog dialog, int style) {
super.setupDialog(dialog, style);
@ -78,10 +85,10 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
snapToRoadEnabled = true;
snapToRoadEnabled = false;
if (listener != null) {
ApplicationMode mode=null;
if((int)view.getTag()!= STRAIGHT_LINE_TAG) {
ApplicationMode mode = null;
if ((int) view.getTag() != STRAIGHT_LINE_TAG) {
mode = modes.get((int) view.getTag());
snapToRoadEnabled = true;
}
@ -91,23 +98,16 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
}
};
View row = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.list_item_icon_and_title, null);
((ImageView) row.findViewById(R.id.icon)).setImageDrawable(
app.getUIUtilities().getIcon(R.drawable.ic_action_split_interval, nightMode));
((TextView) row.findViewById(R.id.title)).setText(app.getText(R.string.routing_profile_straightline));
row.setOnClickListener(onClickListener);
row.setTag(STRAIGHT_LINE_TAG);
container.addView(row);
if (showStraightLine) {
Drawable icon = app.getUIUtilities().getIcon(R.drawable.ic_action_split_interval, nightMode);
addProfileView(container, onClickListener, STRAIGHT_LINE_TAG, icon,
app.getText(R.string.routing_profile_straightline));
}
for (int i = 0; i < modes.size(); i++) {
ApplicationMode mode = modes.get(i);
row = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.list_item_icon_and_title, null);
((ImageView) row.findViewById(R.id.icon)).setImageDrawable(
app.getUIUtilities().getIcon(mode.getIconRes(), mode.getIconColorInfo().getColor(nightMode)));
((TextView) row.findViewById(R.id.title)).setText(mode.toHumanString());
row.setOnClickListener(onClickListener);
row.setTag(i);
container.addView(row);
Drawable icon = app.getUIUtilities().getIcon(mode.getIconRes(), mode.getIconColorInfo().getColor(nightMode));
addProfileView(container, onClickListener, i, icon, mode.toHumanString());
}
if (!portrait) {
@ -125,6 +125,15 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
((View) mainView.getParent()).setBackgroundResource(0);
}
private void addProfileView(LinearLayout container, View.OnClickListener onClickListener, Object tag, Drawable icon, CharSequence title) {
View row = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.list_item_icon_and_title, null);
((ImageView) row.findViewById(R.id.icon)).setImageDrawable(icon);
((TextView) row.findViewById(R.id.title)).setText(title);
row.setOnClickListener(onClickListener);
row.setTag(tag);
container.addView(row);
}
@Override
public void onStart() {
super.onStart();