Merge branch 'sasha_pasha_branch' of ssh://github.com/osmandapp/Osmand into sasha_pasha_branch

This commit is contained in:
PavelRatushny 2017-10-11 18:17:59 +03:00
commit 4820b3181a
7 changed files with 125 additions and 48 deletions

View file

@ -149,17 +149,23 @@
tools:background="@drawable/marker_circle_background_dark_with_inset"
tools:src="@drawable/ic_action_marker_passed"/>
<CheckBox
android:id="@+id/map_marker_check_box"
<FrameLayout
android:id="@+id/check_box_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:background="@null"
android:visibility="gone"
tools:visibility="visible"/>
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/map_marker_check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:visibility="gone"
tools:visibility="visible"/>
</FrameLayout>
</LinearLayout>
<View

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="route_calculated_toast">Route is calculated: Show map</string>
<string name="plan_route_no_markers_toast">You must add at least one marker to use this function.</string>
<string name="osn_modify_dialog_error">Exception occurred: note was not modified</string>
<string name="osn_modify_dialog_title">Modify note</string>
<string name="context_menu_item_modify_note">Modify OSM note</string>

View file

@ -16,6 +16,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.plus.LockableViewPager;
import net.osmand.plus.MapMarkersHelper;
@ -193,54 +194,70 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
@Override
public void sortByOnClick() {
OrderByBottomSheetDialogFragment fragment = new OrderByBottomSheetDialogFragment();
fragment.setListener(createOrderByFragmentListener());
fragment.show(mapActivity.getSupportFragmentManager(), OrderByBottomSheetDialogFragment.TAG);
if (mapActivity != null) {
OrderByBottomSheetDialogFragment fragment = new OrderByBottomSheetDialogFragment();
fragment.setListener(createOrderByFragmentListener());
fragment.show(mapActivity.getSupportFragmentManager(), OrderByBottomSheetDialogFragment.TAG);
}
}
@Override
public void showDirectionOnClick() {
ShowDirectionBottomSheetDialogFragment fragment = new ShowDirectionBottomSheetDialogFragment();
fragment.setListener(createShowDirectionFragmentListener());
fragment.show(mapActivity.getSupportFragmentManager(), ShowDirectionBottomSheetDialogFragment.TAG);
if (mapActivity != null) {
ShowDirectionBottomSheetDialogFragment fragment = new ShowDirectionBottomSheetDialogFragment();
fragment.setListener(createShowDirectionFragmentListener());
fragment.show(mapActivity.getSupportFragmentManager(), ShowDirectionBottomSheetDialogFragment.TAG);
}
}
@Override
public void coordinateInputOnClick() {
CoordinateInputDialogFragment.showInstance(mapActivity);
if (mapActivity != null) {
CoordinateInputDialogFragment.showInstance(mapActivity);
}
}
@Override
public void buildRouteOnClick() {
PlanRouteFragment.showInstance(mapActivity);
dismiss();
if (mapActivity != null) {
if (mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers().isEmpty()) {
Toast.makeText(mapActivity, getString(R.string.plan_route_no_markers_toast), Toast.LENGTH_SHORT).show();
} else {
PlanRouteFragment.showInstance(mapActivity);
dismiss();
}
}
}
@Override
public void saveAsNewTrackOnClick() {
SaveAsTrackBottomSheetDialogFragment fragment = new SaveAsTrackBottomSheetDialogFragment();
fragment.setListener(createSaveAsTrackFragmentListener());
fragment.show(mapActivity.getSupportFragmentManager(), SaveAsTrackBottomSheetDialogFragment.TAG);
if (mapActivity != null) {
SaveAsTrackBottomSheetDialogFragment fragment = new SaveAsTrackBottomSheetDialogFragment();
fragment.setListener(createSaveAsTrackFragmentListener());
fragment.show(mapActivity.getSupportFragmentManager(), SaveAsTrackBottomSheetDialogFragment.TAG);
}
}
@Override
public void moveAllToHistoryOnClick() {
final MapMarkersHelper helper = mapActivity.getMyApplication().getMapMarkersHelper();
final List<MapMarkersHelper.MapMarker> markers = new ArrayList<>(helper.getMapMarkers());
helper.moveAllActiveMarkersToHistory();
activeFragment.updateAdapter();
snackbar = Snackbar.make(viewPager, R.string.all_markers_moved_to_history, Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
helper.restoreMarkersFromHistory(markers);
activeFragment.updateAdapter();
}
});
View snackBarView = snackbar.getView();
TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action);
tv.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark));
snackbar.show();
if (mapActivity != null) {
final MapMarkersHelper helper = mapActivity.getMyApplication().getMapMarkersHelper();
final List<MapMarkersHelper.MapMarker> markers = new ArrayList<>(helper.getMapMarkers());
helper.moveAllActiveMarkersToHistory();
activeFragment.updateAdapter();
snackbar = Snackbar.make(viewPager, R.string.all_markers_moved_to_history, Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
helper.restoreMarkersFromHistory(markers);
activeFragment.updateAdapter();
}
});
View snackBarView = snackbar.getView();
TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action);
tv.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark));
snackbar.show();
}
}
};
}

View file

@ -41,6 +41,7 @@ public class MarkersPlanRouteContext {
private boolean progressBarVisible;
private boolean fragmentVisible;
private boolean markersListOpened;
private boolean adjustMapOnStart = true;
Map<Pair<WptPt, WptPt>, List<WptPt>> getSnappedToRoadPoints() {
return snappedToRoadPoints;
@ -90,12 +91,20 @@ public class MarkersPlanRouteContext {
this.markersListOpened = markersListOpened;
}
public boolean isAdjustMapOnStart() {
return adjustMapOnStart;
}
public void setAdjustMapOnStart(boolean adjustMapOnStart) {
this.adjustMapOnStart = adjustMapOnStart;
}
public MarkersPlanRouteContext(OsmandApplication app) {
this.app = app;
}
void cancelSnapToRoad() {
listener.hideProgressBar();
listener.hideProgressBar(true);
snapToRoadPairsToCalculate.clear();
if (calculationProgress != null) {
calculationProgress.isCancelled = true;
@ -245,7 +254,7 @@ public class MarkersPlanRouteContext {
app.runInUIThread(new Runnable() {
@Override
public void run() {
listener.hideProgressBar();
listener.hideProgressBar(false);
}
});
}
@ -261,7 +270,7 @@ public class MarkersPlanRouteContext {
void updateProgress(int progress);
void hideProgressBar();
void hideProgressBar(boolean canceled);
void refresh();

View file

@ -24,6 +24,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.AndroidUtils;
import net.osmand.Location;
@ -62,6 +63,7 @@ import java.util.ArrayList;
import java.util.List;
import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT;
import static net.osmand.plus.OsmandSettings.MIDDLE_TOP_CONSTANT;
public class PlanRouteFragment extends Fragment implements OsmAndLocationListener {
@ -108,9 +110,13 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
}
@Override
public void hideProgressBar() {
public void hideProgressBar(boolean canceled) {
mainView.findViewById(R.id.snap_to_road_progress_bar).setVisibility(View.GONE);
planRouteContext.setProgressBarVisible(false);
if (!canceled && portrait && planRouteContext.isMarkersListOpened()) {
Toast.makeText(mapActivity, getString(R.string.route_calculated_toast), Toast.LENGTH_SHORT).show();
showHideMarkersList();
}
}
@Override
@ -268,7 +274,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
private int toPosition;
@Override
public void onItemClick(View view) {
public void onCheckBoxClick(View view) {
int pos = markersRv.getChildAdapterPosition(view);
if (pos == RecyclerView.NO_POSITION) {
return;
@ -288,6 +294,22 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
planRouteContext.recreateSnapTrkSegment(false);
}
@Override
public void onItemClick(View v) {
int pos = markersRv.getChildAdapterPosition(v);
if (pos == RecyclerView.NO_POSITION) {
return;
}
Object item = adapter.getItem(pos);
if (item instanceof Location) {
Location loc = (Location) item;
moveMapToPosition(loc.getLatitude(), loc.getLongitude());
} else if (item instanceof MapMarker) {
MapMarker marker = (MapMarker) item;
moveMapToPosition(marker.getLatitude(), marker.getLongitude());
}
}
@Override
public void onDragStarted(RecyclerView.ViewHolder holder) {
fromPosition = holder.getAdapterPosition();
@ -398,6 +420,18 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
return iconsCache.getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance);
}
private void moveMapToPosition(double lat, double lon) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
OsmandMapTileView view = mapActivity.getMapView();
view.getAnimatedDraggingThread().startMoving(lat, lon, view.getZoom(), true);
if (planRouteContext.isMarkersListOpened()) {
planRouteContext.setAdjustMapOnStart(false);
showHideMarkersList();
}
}
}
private SnapToRoadFragmentListener createSnapToRoadFragmentListener() {
return new SnapToRoadFragmentListener() {
@Override
@ -581,12 +615,11 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
OsmandMapTileView tileView = mapActivity.getMapView();
previousMapPosition = tileView.getMapPosition();
if (!portrait) {
tileView.setMapPosition(LANDSCAPE_MIDDLE_RIGHT_CONSTANT);
}
tileView.setMapPosition(portrait ? MIDDLE_TOP_CONSTANT : LANDSCAPE_MIDDLE_RIGHT_CONSTANT);
selectedCount = mapActivity.getMyApplication().getMapMarkersHelper().getSelectedMarkersCount();
planRouteContext.recreateSnapTrkSegment(true);
planRouteContext.recreateSnapTrkSegment(planRouteContext.isAdjustMapOnStart());
planRouteContext.setAdjustMapOnStart(true);
mapActivity.refreshMap();
updateSelectButton();
}

View file

@ -25,6 +25,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
final View rightPointSpace;
final TextView description;
public final ImageButton optionsBtn;
final View checkBoxContainer;
final CheckBox checkBox;
final View divider;
final View bottomShadow;
@ -45,6 +46,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
rightPointSpace = view.findViewById(R.id.map_marker_right_point_space);
description = (TextView) view.findViewById(R.id.map_marker_description);
optionsBtn = (ImageButton) view.findViewById(R.id.map_marker_options_button);
checkBoxContainer = view.findViewById(R.id.check_box_container);
checkBox = (CheckBox) view.findViewById(R.id.map_marker_check_box);
divider = view.findViewById(R.id.divider);
bottomShadow = view.findViewById(R.id.bottom_shadow);

View file

@ -106,7 +106,13 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
holder.checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
listener.onItemClick(holder.itemView);
listener.onCheckBoxClick(holder.itemView);
}
});
holder.checkBoxContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
holder.checkBox.performClick();
}
});
holder.bottomShadow.setVisibility(lastMarkerItem ? View.VISIBLE : View.GONE);
@ -339,6 +345,8 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
public interface MapMarkersListAdapterListener {
void onCheckBoxClick(View view);
void onItemClick(View view);
void onDragStarted(RecyclerView.ViewHolder holder);