Swap directions

This commit is contained in:
PavelRatushny 2017-12-19 13:05:01 +02:00
parent ed3cf2e1f8
commit 6cf3ac6463
4 changed files with 111 additions and 15 deletions

View file

@ -130,17 +130,37 @@
android:layout_marginRight="@dimen/list_header_text_left_margin" android:layout_marginRight="@dimen/list_header_text_left_margin"
android:src="@drawable/ic_action_arrow_drop_down"/> android:src="@drawable/ic_action_arrow_drop_down"/>
<View
android:id="@+id/from_layout_empty_view"
android:layout_width="@dimen/route_info_directions_margin"
android:layout_height="match_parent"/>
</LinearLayout> </LinearLayout>
<View <FrameLayout
android:layout_marginStart="@dimen/route_info_divider_margin"
android:layout_marginLeft="@dimen/route_info_divider_margin"
android:id="@+id/dividerFromDropDown"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="wrap_content">
android:background="@color/dashboard_divider_dark"
android:focusable="false"/> <View
android:layout_marginStart="@dimen/route_info_divider_margin"
android:layout_marginLeft="@dimen/route_info_divider_margin"
android:layout_marginRight="@dimen/route_info_directions_margin"
android:layout_marginEnd="@dimen/route_info_directions_margin"
android:id="@+id/dividerFromDropDown"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/dashboard_divider_dark"
android:focusable="false"/>
<View
android:id="@+id/divider_from_drop_down_empty"
android:layout_gravity="end"
android:layout_width="@dimen/route_info_directions_margin"
android:layout_height="1dp"
android:focusable="false"
android:background="@color/dashboard_divider_dark"/>
</FrameLayout>
<LinearLayout <LinearLayout
android:id="@+id/ViaLayout" android:id="@+id/ViaLayout"
@ -242,11 +262,17 @@
android:layout_marginRight="@dimen/list_header_text_left_margin" android:layout_marginRight="@dimen/list_header_text_left_margin"
android:src="@drawable/ic_action_arrow_drop_down"/> android:src="@drawable/ic_action_arrow_drop_down"/>
<View
android:id="@+id/to_layout_empty_view"
android:layout_width="@dimen/route_info_directions_margin"
android:layout_height="match_parent"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<ImageView <ImageView
android:id="@+id/swap_direction_image_view"
android:visibility="gone" android:visibility="gone"
android:paddingRight="@dimen/route_info_icon_padding_right" android:paddingRight="@dimen/route_info_icon_padding_right"
android:paddingLeft="@dimen/route_info_icon_padding_right" android:paddingLeft="@dimen/route_info_icon_padding_right"

View file

@ -131,17 +131,37 @@
android:layout_marginRight="@dimen/list_header_text_left_margin" android:layout_marginRight="@dimen/list_header_text_left_margin"
android:src="@drawable/ic_action_arrow_drop_down"/> android:src="@drawable/ic_action_arrow_drop_down"/>
<View
android:id="@+id/from_layout_empty_view"
android:layout_width="@dimen/route_info_directions_margin"
android:layout_height="match_parent"/>
</LinearLayout> </LinearLayout>
<View <FrameLayout
android:layout_marginStart="@dimen/route_info_divider_margin"
android:layout_marginLeft="@dimen/route_info_divider_margin"
android:id="@+id/dividerFromDropDown"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="wrap_content">
android:background="@color/dashboard_divider_dark"
android:focusable="false"/> <View
android:layout_marginStart="@dimen/route_info_divider_margin"
android:layout_marginLeft="@dimen/route_info_divider_margin"
android:layout_marginRight="@dimen/route_info_directions_margin"
android:layout_marginEnd="@dimen/route_info_directions_margin"
android:id="@+id/dividerFromDropDown"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/dashboard_divider_dark"
android:focusable="false"/>
<View
android:id="@+id/divider_from_drop_down_empty"
android:layout_gravity="end"
android:layout_width="@dimen/route_info_directions_margin"
android:layout_height="1dp"
android:focusable="false"
android:background="@color/dashboard_divider_dark"/>
</FrameLayout>
<LinearLayout <LinearLayout
android:id="@+id/ViaLayout" android:id="@+id/ViaLayout"
@ -247,12 +267,17 @@
android:layout_marginRight="@dimen/list_header_text_left_margin" android:layout_marginRight="@dimen/list_header_text_left_margin"
android:src="@drawable/ic_action_arrow_drop_down"/> android:src="@drawable/ic_action_arrow_drop_down"/>
<View
android:id="@+id/to_layout_empty_view"
android:layout_width="@dimen/route_info_directions_margin"
android:layout_height="match_parent"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<ImageView <ImageView
android:visibility="gone" android:id="@+id/swap_direction_image_view"
android:paddingRight="@dimen/route_info_icon_padding_right" android:paddingRight="@dimen/route_info_icon_padding_right"
android:paddingLeft="@dimen/route_info_icon_padding_right" android:paddingLeft="@dimen/route_info_icon_padding_right"
android:layout_gravity="end" android:layout_gravity="end"

View file

@ -19,6 +19,7 @@ import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.ValueHolder; import net.osmand.ValueHolder;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
@ -258,10 +259,22 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
private void updateViaView(final View parentView) { private void updateViaView(final View parentView) {
String via = generateViaDescription(); String via = generateViaDescription();
View viaLayout = parentView.findViewById(R.id.ViaLayout); View viaLayout = parentView.findViewById(R.id.ViaLayout);
View fromLayoutEmptyView = parentView.findViewById(R.id.from_layout_empty_view);
View toLayoutEmptyView = parentView.findViewById(R.id.to_layout_empty_view);
View dividerFromDropDownEmpty = parentView.findViewById(R.id.divider_from_drop_down_empty);
ImageView swapDirectionView = (ImageView) parentView.findViewById(R.id.swap_direction_image_view);
if (via.length() == 0) { if (via.length() == 0) {
viaLayout.setVisibility(View.GONE); viaLayout.setVisibility(View.GONE);
parentView.findViewById(R.id.viaLayoutDivider).setVisibility(View.GONE); parentView.findViewById(R.id.viaLayoutDivider).setVisibility(View.GONE);
dividerFromDropDownEmpty.setVisibility(View.GONE);
fromLayoutEmptyView.setVisibility(View.VISIBLE);
toLayoutEmptyView.setVisibility(View.VISIBLE);
swapDirectionView.setVisibility(View.VISIBLE);
} else { } else {
fromLayoutEmptyView.setVisibility(View.GONE);
toLayoutEmptyView.setVisibility(View.GONE);
swapDirectionView.setVisibility(View.GONE);
dividerFromDropDownEmpty.setVisibility(View.VISIBLE);
viaLayout.setVisibility(View.VISIBLE); viaLayout.setVisibility(View.VISIBLE);
parentView.findViewById(R.id.viaLayoutDivider).setVisibility(View.VISIBLE); parentView.findViewById(R.id.viaLayoutDivider).setVisibility(View.VISIBLE);
((TextView) parentView.findViewById(R.id.ViaView)).setText(via); ((TextView) parentView.findViewById(R.id.ViaView)).setText(via);
@ -278,6 +291,36 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
ImageView viaIcon = (ImageView) parentView.findViewById(R.id.viaIcon); ImageView viaIcon = (ImageView) parentView.findViewById(R.id.viaIcon);
viaIcon.setImageDrawable(getIconOrig(R.drawable.list_intermediate)); viaIcon.setImageDrawable(getIconOrig(R.drawable.list_intermediate));
swapDirectionView.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_test_light,
isLight() ? R.color.route_info_control_icon_color_light : R.color.route_info_control_icon_color_dark));
AndroidUtils.setBackground(mapActivity, swapDirectionView, nightMode, R.drawable.dashboard_button_light, R.drawable.dashboard_button_dark);
swapDirectionView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
TargetPointsHelper targetPointsHelper = getTargets();
TargetPoint startPoint = targetPointsHelper.getPointToStart();
TargetPoint endPoint = targetPointsHelper.getPointToNavigate();
if (startPoint == null) {
Location loc = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
if (loc != null) {
startPoint = TargetPoint.createStartPoint(new LatLon(loc.getLatitude(), loc.getLongitude()),
new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION,
mapActivity.getString(R.string.shared_string_my_location)));
}
}
if (startPoint != null) {
targetPointsHelper.navigateToPoint(startPoint.point, false, -1, startPoint.getPointDescription(mapActivity));
targetPointsHelper.setStartPoint(endPoint.point, false, endPoint.getPointDescription(mapActivity));
targetPointsHelper.updateRouteAndRefresh(true);
updateFromIcon();
updateToIcon(parentView);
}
}
});
} }
private void updateToSpinner(final View parentView) { private void updateToSpinner(final View parentView) {

View file

@ -150,6 +150,8 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
R.color.route_info_divider_light, R.color.route_info_divider_dark); R.color.route_info_divider_light, R.color.route_info_divider_dark);
AndroidUtils.setBackground(ctx, mainView.findViewById(R.id.dividerFromDropDown), nightMode, AndroidUtils.setBackground(ctx, mainView.findViewById(R.id.dividerFromDropDown), nightMode,
R.color.route_info_divider_light, R.color.route_info_divider_dark); R.color.route_info_divider_light, R.color.route_info_divider_dark);
AndroidUtils.setBackground(ctx, mainView.findViewById(R.id.divider_from_drop_down_empty), nightMode,
R.color.route_info_divider_light, R.color.route_info_divider_dark);
AndroidUtils.setBackground(ctx, mainView.findViewById(R.id.viaLayoutDivider), nightMode, AndroidUtils.setBackground(ctx, mainView.findViewById(R.id.viaLayoutDivider), nightMode,
R.color.route_info_divider_light, R.color.route_info_divider_dark); R.color.route_info_divider_light, R.color.route_info_divider_dark);
AndroidUtils.setBackground(ctx, mainView.findViewById(R.id.dividerToDropDown), nightMode, AndroidUtils.setBackground(ctx, mainView.findViewById(R.id.dividerToDropDown), nightMode,