From e32243a56e7b80dbb52ce6a81cedd3ee95b7900e Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Tue, 8 Aug 2017 12:44:41 +0300 Subject: [PATCH] Add fabs on overview screen --- OsmAnd/res/layout/points_tree.xml | 3 +- OsmAnd/res/layout/track_segments_tree.xml | 107 ++++++++++++++++++ .../osmand/plus/activities/TrackActivity.java | 27 ++++- .../plus/myplaces/TrackPointFragment.java | 17 +-- .../plus/myplaces/TrackSegmentFragment.java | 64 ++++++++++- 5 files changed, 197 insertions(+), 21 deletions(-) create mode 100644 OsmAnd/res/layout/track_segments_tree.xml diff --git a/OsmAnd/res/layout/points_tree.xml b/OsmAnd/res/layout/points_tree.xml index 1b1e97e048..296e09695b 100644 --- a/OsmAnd/res/layout/points_tree.xml +++ b/OsmAnd/res/layout/points_tree.xml @@ -5,8 +5,7 @@ xmlns:osmand="http://schemas.android.com/apk/res-auto" android:id="@+id/MainLayout" android:layout_width="match_parent" - android:layout_height="match_parent" - android:orientation="vertical"> + android:layout_height="match_parent"> + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java index 3c27ce8e25..ff238d8b59 100644 --- a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java @@ -13,6 +13,8 @@ import android.view.MenuItem; import android.view.View; import net.osmand.AndroidUtils; +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXFile; @@ -21,11 +23,13 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.myplaces.SplitSegmentFragment; import net.osmand.plus.myplaces.TrackPointFragment; import net.osmand.plus.myplaces.TrackSegmentFragment; +import net.osmand.plus.views.AddGpxPointBottomSheetHelper; import net.osmand.plus.views.controls.PagerSlidingTabStrip; import java.io.File; @@ -39,6 +43,7 @@ public class TrackActivity extends TabActivity { public static final String OPEN_POINTS_TAB = "OPEN_POINTS_TAB"; public static final String CURRENT_RECORDING = "CURRENT_RECORDING"; protected List> fragList = new ArrayList<>(); + private OsmandApplication app; protected PagerSlidingTabStrip slidingTabLayout; private File file = null; private GPXFile gpxFile; @@ -56,7 +61,8 @@ public class TrackActivity extends TabActivity { @Override public void onCreate(Bundle icicle) { - ((OsmandApplication) getApplication()).applyTheme(this); + this.app = getMyApplication(); + app.applyTheme(this); super.onCreate(icicle); Intent intent = getIntent(); if (intent == null || (!intent.hasExtra(TRACK_FILE_NAME) && @@ -83,6 +89,25 @@ public class TrackActivity extends TabActivity { setContentView(R.layout.tab_content); } + public void addPoint(PointDescription pointDescription) { + Intent currentIntent = getIntent(); + if (currentIntent != null) { + currentIntent.putExtra(TrackActivity.OPEN_POINTS_TAB, true); + } + final OsmandSettings settings = app.getSettings(); + GPXFile gpx = getGpx(); + LatLon location = settings.getLastKnownMapLocation(); + if (gpx != null && location != null) { + settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), + settings.getLastKnownMapZoom(), + pointDescription, + false, + new AddGpxPointBottomSheetHelper.NewGpxPoint(gpx, pointDescription)); + + MapActivity.launchMapActivityMoveToTop(this); + } + } + protected void setGpxDataItem(GpxDataItem gpxDataItem) { this.gpxDataItem = gpxDataItem; } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index d4bd49e319..84e293891c 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -178,22 +178,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment { } private void addPoint(PointDescription pointDescription) { - Intent currentIntent = getTrackActivity().getIntent(); - if (currentIntent != null) { - currentIntent.putExtra(TrackActivity.OPEN_POINTS_TAB, true); - } - final OsmandSettings settings = app.getSettings(); - GPXFile gpx = getGpx(); - LatLon location = settings.getLastKnownMapLocation(); - if (gpx != null && location != null) { - settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), - settings.getLastKnownMapZoom(), - pointDescription, - false, - new NewGpxPoint(gpx, pointDescription)); - - MapActivity.launchMapActivityMoveToTop(getActivity()); - } + getTrackActivity().addPoint(pointDescription); } private void openMenu() { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index 4756a13fea..72537be686 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -17,6 +17,7 @@ import android.os.Handler; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.design.widget.FloatingActionButton; import android.support.v4.content.ContextCompat; import android.support.v4.view.MenuItemCompat; import android.support.v4.view.PagerAdapter; @@ -140,6 +141,12 @@ public class TrackSegmentFragment extends OsmAndListFragment { private Bitmap mapBitmap; private Bitmap mapTrackBitmap; private boolean chartClicked; + private boolean menuOpened = false; + private FloatingActionButton menuFab; + private FloatingActionButton waypointFab; + private View waypointTextLayout; + private FloatingActionButton routePointFab; + private View routePointTextLayout; @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -158,8 +165,7 @@ public class TrackSegmentFragment extends OsmAndListFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setHasOptionsMenu(true); - View view = getActivity().getLayoutInflater().inflate(R.layout.update_index, container, false); - view.findViewById(R.id.header_layout).setVisibility(View.GONE); + View view = getActivity().getLayoutInflater().inflate(R.layout.track_segments_tree, container, false); ListView listView = (ListView) view.findViewById(android.R.id.list); listView.setDivider(null); @@ -170,6 +176,38 @@ public class TrackSegmentFragment extends OsmAndListFragment { tv.setTextSize(24); listView.setEmptyView(tv); + menuFab = (FloatingActionButton) view.findViewById(R.id.menu_fab); + menuFab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (menuOpened) { + closeMenu(); + } else { + openMenu(); + } + } + }); + + waypointFab = (FloatingActionButton) view.findViewById(R.id.waypoint_fab); + waypointFab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_WPT, getString(R.string.add_waypoint)); + addPoint(pointDescription); + } + }); + waypointTextLayout = view.findViewById(R.id.waypoint_text_layout); + + routePointFab = (FloatingActionButton) view.findViewById(R.id.route_fab); + routePointFab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_RTE, getString(R.string.add_route_point)); + addPoint(pointDescription); + } + }); + routePointTextLayout = view.findViewById(R.id.route_text_layout); + paint = new Paint(); paint.setStyle(Paint.Style.STROKE); paint.setAntiAlias(true); @@ -188,6 +226,28 @@ public class TrackSegmentFragment extends OsmAndListFragment { return view; } + private void addPoint(PointDescription pointDescription) { + getTrackActivity().addPoint(pointDescription); + } + + private void openMenu() { + menuFab.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_action_remove_dark)); + waypointFab.setVisibility(View.VISIBLE); + waypointTextLayout.setVisibility(View.VISIBLE); + routePointFab.setVisibility(View.VISIBLE); + routePointTextLayout.setVisibility(View.VISIBLE); + menuOpened = true; + } + + private void closeMenu() { + menuFab.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_action_plus)); + waypointFab.setVisibility(View.GONE); + waypointTextLayout.setVisibility(View.GONE); + routePointFab.setVisibility(View.GONE); + routePointTextLayout.setVisibility(View.GONE); + menuOpened = false; + } + public TrackActivity getTrackActivity() { return (TrackActivity) getActivity(); }