Change action bar title in snap to road mode
This commit is contained in:
parent
e2dcab77c6
commit
cb1352328b
3 changed files with 67 additions and 1 deletions
|
@ -31,6 +31,7 @@ import android.widget.Toast;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.GPXUtilities.Route;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
|
@ -44,6 +45,7 @@ import net.osmand.plus.activities.TrackActivity.NewGpxLine.LineType;
|
|||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.GpxUiHelper;
|
||||
import net.osmand.plus.measurementtool.SelectedPointMenuBottomSheetDialogFragment.SelectedPointOptionOnClickListener;
|
||||
import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment.SnapToRoadListener;
|
||||
import net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter;
|
||||
import net.osmand.plus.measurementtool.adapter.MeasurementToolItemTouchHelperCallback;
|
||||
import net.osmand.plus.measurementtool.command.AddPointCommand;
|
||||
|
@ -77,6 +79,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
private List<WptPt> measurementPoints = new LinkedList<>();
|
||||
private IconsCache iconsCache;
|
||||
private RecyclerView pointsRv;
|
||||
private String previousToolBarTitle = "";
|
||||
private MeasurementToolBarController toolBarController;
|
||||
private MeasurementToolAdapter adapter;
|
||||
private TextView distanceTv;
|
||||
|
@ -209,7 +212,11 @@ public class MeasurementToolFragment extends Fragment {
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -533,6 +540,27 @@ public class MeasurementToolFragment extends Fragment {
|
|||
};
|
||||
}
|
||||
|
||||
private SnapToRoadListener createSnapToRoadListener() {
|
||||
return new SnapToRoadListener() {
|
||||
|
||||
@Override
|
||||
public void onDestroyView(boolean snapToRoadEnabled) {
|
||||
if (!snapToRoadEnabled) {
|
||||
toolBarController.setTitle(previousToolBarTitle);
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.refreshMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationModeItemClick(ApplicationMode mode) {
|
||||
Toast.makeText(getActivity(), mode.toHumanString(getActivity()), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void displayRoutePoints(MapActivity mapActivity) {
|
||||
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
|
||||
|
||||
|
|
|
@ -30,8 +30,14 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
|
|||
|
||||
public static final String TAG = "SnapToRoadBottomSheetDialogFragment";
|
||||
|
||||
private SnapToRoadListener listener;
|
||||
private boolean nightMode;
|
||||
private boolean portrait;
|
||||
private boolean snapToRoadEnabled;
|
||||
|
||||
public void setListener(SnapToRoadListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
|
@ -56,10 +62,23 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
|
|||
LinearLayout navContainer = (LinearLayout) mainView.findViewById(R.id.navigation_types_container);
|
||||
final List<ApplicationMode> modes = new ArrayList<>(ApplicationMode.values(settings));
|
||||
modes.remove(ApplicationMode.DEFAULT);
|
||||
for (ApplicationMode mode : modes) {
|
||||
View.OnClickListener onClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
snapToRoadEnabled = true;
|
||||
if (listener != null) {
|
||||
listener.onApplicationModeItemClick(modes.get((int) view.getTag()));
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
for (int i = 0; i < modes.size(); i++) {
|
||||
ApplicationMode mode = modes.get(i);
|
||||
View row = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.list_item_icon_and_title, null);
|
||||
((ImageView) row.findViewById(R.id.icon)).setImageDrawable(getContentIcon(mode.getSmallIconDark()));
|
||||
((TextView) row.findViewById(R.id.title)).setText(mode.toHumanString(getContext()));
|
||||
row.setOnClickListener(onClickListener);
|
||||
row.setTag(i);
|
||||
navContainer.addView(row);
|
||||
}
|
||||
|
||||
|
@ -114,8 +133,23 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (listener != null) {
|
||||
listener.onDestroyView(snapToRoadEnabled);
|
||||
}
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Drawable getContentIcon(@DrawableRes int id) {
|
||||
return getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color);
|
||||
}
|
||||
|
||||
interface SnapToRoadListener {
|
||||
|
||||
void onDestroyView(boolean snapToRoadEnabled);
|
||||
|
||||
void onApplicationModeItemClick(ApplicationMode mode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -266,6 +266,10 @@ public class MapInfoWidgetsFactory {
|
|||
this.title = title;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setBottomView(View bottomView) {
|
||||
this.bottomView = bottomView;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue