Add options menu

This commit is contained in:
Alex 2017-08-11 15:21:58 +03:00
parent c7b877aefc
commit 3ab0dee4b0
3 changed files with 132 additions and 3 deletions

View file

@ -17,6 +17,7 @@
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<RelativeLayout
android:id="@+id/snap_to_road_row"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="?attr/selectableItemBackground"
@ -151,6 +152,7 @@
android:background="?attr/dashboard_divider"/>
<RelativeLayout
android:id="@+id/clear_all_row"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="?attr/selectableItemBackground"

View file

@ -160,7 +160,54 @@ public class MeasurementToolFragment extends Fragment {
mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getActivity(), "options", Toast.LENGTH_SHORT).show();
OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment();
fragment.setOptionsOnClickListener(new OptionsBottomSheetDialogFragment.OptionsOnClickListener() {
@Override
public void snapToRoadOnCLick() {
SnapToRoadBottomSheetDialogFragment fragment = new SnapToRoadBottomSheetDialogFragment();
fragment.show(mapActivity.getSupportFragmentManager(), SnapToRoadBottomSheetDialogFragment.TAG);
}
@Override
public void saveAsNewSegmentOnClick() {
if (measurementLayer.getPointsCount() > 0) {
saveAsNewSegment(mapActivity);
} else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
}
}
@Override
public void saveAsNewTrackOnClick() {
if (measurementLayer.getPointsCount() > 0) {
saveAsGpxOnClick(mapActivity);
} else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
}
}
@Override
public void addToTheTrackOnClick() {
if (measurementLayer.getPointsCount() > 0) {
// showAddSegmentDialog(mapActivity);
} else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
}
}
@Override
public void clearAllOnClick() {
commandManager.execute(new ClearPointsCommand(measurementLayer));
if (pointsListOpened) {
hidePointsList();
}
disable(redoBtn, upDownBtn);
updateText();
saved = false;
}
});
fragment.setAddLineMode(newGpxLine != null);
fragment.show(mapActivity.getSupportFragmentManager(), OptionsBottomSheetDialogFragment.TAG);
}
});

View file

@ -15,6 +15,17 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
public final static String TAG = "OptionsBottomSheetDialogFragment";
private OptionsOnClickListener listener;
private boolean addLineMode;
public void setOptionsOnClickListener(OptionsOnClickListener listener) {
this.listener = listener;
}
public void setAddLineMode(boolean addLineMode) {
this.addLineMode = addLineMode;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -24,9 +35,65 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_options_bottom_sheet_dialog, null);
((ImageView) mainView.findViewById(R.id.snap_to_road_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_snap_to_road));
((ImageView) mainView.findViewById(R.id.save_as_new_track_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark));
((ImageView) mainView.findViewById(R.id.add_to_the_track_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_split_interval));
((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));
((ImageView) mainView.findViewById(R.id.add_to_the_track_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_split_interval));
} else {
mainView.findViewById(R.id.save_as_new_track_row).setVisibility(View.GONE);
mainView.findViewById(R.id.add_to_the_track_row).setVisibility(View.GONE);
mainView.findViewById(R.id.save_as_new_segment_row).setVisibility(View.VISIBLE);
((ImageView) mainView.findViewById(R.id.save_as_new_segment_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark));
}
mainView.findViewById(R.id.snap_to_road_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.snapToRoadOnCLick();
}
dismiss();
}
});
mainView.findViewById(R.id.clear_all_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.clearAllOnClick();
}
dismiss();
}
});
if (!addLineMode) {
mainView.findViewById(R.id.save_as_new_track_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.saveAsNewTrackOnClick();
}
dismiss();
}
});
mainView.findViewById(R.id.add_to_the_track_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.addToTheTrackOnClick();
}
dismiss();
}
});
} else {
mainView.findViewById(R.id.save_as_new_segment_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.saveAsNewSegmentOnClick();
}
dismiss();
}
});
}
mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -36,4 +103,17 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
return mainView;
}
interface OptionsOnClickListener {
void snapToRoadOnCLick();
void saveAsNewSegmentOnClick();
void saveAsNewTrackOnClick();
void addToTheTrackOnClick();
void clearAllOnClick();
}
}