Merge pull request #4669 from osmandapp/add_marker_buttons

Change the button in the context menu of the marker
This commit is contained in:
Alexey 2017-11-01 13:37:34 +03:00 committed by GitHub
commit aaa9753785
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 169 additions and 35 deletions

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/osmand_orange"/>
</shape>
</item>
<item android:drawable="@drawable/ic_action_marker_passed"/>
</layer-list>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/map_widget_blue"/>
</shape>
</item>
<item android:drawable="@drawable/ic_action_marker_passed"/>
</layer-list>

View file

@ -166,18 +166,22 @@
<LinearLayout <LinearLayout
android:id="@+id/title_button_container" android:id="@+id/title_button_container"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minHeight="@dimen/context_menu_action_buttons_h"
android:layout_marginTop="@dimen/context_menu_buttons_top_margin" android:layout_marginTop="@dimen/context_menu_buttons_top_margin"
android:clickable="true" android:clickable="true"
android:orientation="horizontal" android:minHeight="@dimen/context_menu_action_buttons_h"
android:orientation="vertical"
android:paddingBottom="@dimen/context_menu_buttons_padding_bottom" android:paddingBottom="@dimen/context_menu_buttons_padding_bottom"
android:paddingLeft="62dp" android:paddingLeft="62dp"
android:paddingRight="2dp" android:paddingRight="2dp"
android:visibility="gone" android:visibility="gone"
tools:visibility="visible"> tools:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button <Button
android:id="@+id/title_button" android:id="@+id/title_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -197,9 +201,9 @@
android:layout_marginLeft="-4dp" android:layout_marginLeft="-4dp"
android:clickable="true" android:clickable="true"
android:gravity="center_vertical" android:gravity="center_vertical"
tools:text="— 00:26"
android:textColor="?android:textColorSecondary" android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"/> android:textSize="@dimen/default_desc_text_size"
tools:text="— 00:26"/>
<Button <Button
android:id="@+id/title_button_right" android:id="@+id/title_button_right"
@ -212,6 +216,28 @@
android:text="@string/shared_string_delete" android:text="@string/shared_string_delete"
android:textColor="?attr/contextMenuButtonColor" android:textColor="?attr/contextMenuButtonColor"
android:textSize="@dimen/default_desc_text_size"/> android:textSize="@dimen/default_desc_text_size"/>
</LinearLayout>
<View
android:id="@+id/title_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:background="?attr/dashboard_divider"
android:visibility="gone"
tools:visibility="visible"/>
<Button
android:id="@+id/subtitle_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="left|center_vertical"
android:paddingLeft="@dimen/context_menu_button_padding_x"
android:paddingRight="@dimen/context_menu_button_padding_x"
android:text="@string/recording_context_menu_play"
android:textColor="?attr/contextMenuButtonColor"
android:textSize="@dimen/default_desc_text_size"/>
</LinearLayout> </LinearLayout>

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). 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 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="show_on_top_bar">Show on Top Bar</string>
<string name="mark_passed">Mark passed</string>
<string name="import_gpx_file_description">can be imported as Favorites points, or as track file.</string> <string name="import_gpx_file_description">can be imported as Favorites points, or as track file.</string>
<string name="import_as_gpx">Import as GPX file</string> <string name="import_as_gpx">Import as GPX file</string>
<string name="import_as_favorites">Import as Favorites</string> <string name="import_as_favorites">Import as Favorites</string>

View file

@ -795,6 +795,16 @@ public class MapMarkersHelper {
} }
} }
public void moveMarkerToTop(MapMarker marker) {
int i = mapMarkers.indexOf(marker);
if (i != -1 && mapMarkers.size() > 1) {
mapMarkers.remove(i);
mapMarkers.add(0, marker);
reorderActiveMarkersIfNeeded();
refresh();
}
}
public void moveMapMarker(MapMarker marker, LatLon latLon) { public void moveMapMarker(MapMarker marker, LatLon latLon) {
if (marker != null) { if (marker != null) {
LatLon point = new LatLon(latLon.getLatitude(), latLon.getLongitude()); LatLon point = new LatLon(latLon.getLatitude(), latLon.getLongitude());

View file

@ -1035,6 +1035,14 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
} }
} }
public TitleButtonController getLeftSubtitleButtonController() {
if (menuController != null) {
return menuController.getLeftSubtitleButtonController();
} else {
return null;
}
}
public TitleButtonController getLeftDownloadButtonController() { public TitleButtonController getLeftDownloadButtonController() {
if (menuController != null) { if (menuController != null) {
return menuController.getLeftDownloadButtonController(); return menuController.getLeftDownloadButtonController();

View file

@ -175,6 +175,18 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
} }
}); });
// Left subtitle button
final Button leftSubtitleButton = (Button) view.findViewById(R.id.subtitle_button);
leftSubtitleButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TitleButtonController leftSubtitleButtonController = menu.getLeftSubtitleButtonController();
if (leftSubtitleButtonController != null) {
leftSubtitleButtonController.buttonPressed();
}
}
});
// Left download button // Left download button
final Button leftDownloadButton = (Button) view.findViewById(R.id.download_button_left); final Button leftDownloadButton = (Button) view.findViewById(R.id.download_button_left);
leftDownloadButton.setOnClickListener(new View.OnClickListener() { leftDownloadButton.setOnClickListener(new View.OnClickListener() {
@ -686,14 +698,17 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
TitleButtonController leftTitleButtonController = menu.getLeftTitleButtonController(); TitleButtonController leftTitleButtonController = menu.getLeftTitleButtonController();
TitleButtonController rightTitleButtonController = menu.getRightTitleButtonController(); TitleButtonController rightTitleButtonController = menu.getRightTitleButtonController();
TitleButtonController topRightTitleButtonController = menu.getTopRightTitleButtonController(); TitleButtonController topRightTitleButtonController = menu.getTopRightTitleButtonController();
TitleButtonController leftSubtitleButtonController = menu.getLeftSubtitleButtonController();
TitleButtonController leftDownloadButtonController = menu.getLeftDownloadButtonController(); TitleButtonController leftDownloadButtonController = menu.getLeftDownloadButtonController();
TitleButtonController rightDownloadButtonController = menu.getRightDownloadButtonController(); TitleButtonController rightDownloadButtonController = menu.getRightDownloadButtonController();
TitleProgressController titleProgressController = menu.getTitleProgressController(); TitleProgressController titleProgressController = menu.getTitleProgressController();
// Title buttons // Title buttons
boolean showTitleButtonsContainer = (leftTitleButtonController != null || rightTitleButtonController != null); boolean showTitleButtonsContainer = (leftTitleButtonController != null || rightTitleButtonController != null);
boolean showTitleDivider = leftSubtitleButtonController != null;
final View titleButtonsContainer = view.findViewById(R.id.title_button_container); final View titleButtonsContainer = view.findViewById(R.id.title_button_container);
titleButtonsContainer.setVisibility(showTitleButtonsContainer ? View.VISIBLE : View.GONE); titleButtonsContainer.setVisibility(showTitleButtonsContainer ? View.VISIBLE : View.GONE);
view.findViewById(R.id.title_divider).setVisibility(showTitleDivider ? View.VISIBLE : View.GONE);
// Left title button // Left title button
final Button leftTitleButton = (Button) view.findViewById(R.id.title_button); final Button leftTitleButton = (Button) view.findViewById(R.id.title_button);
@ -705,7 +720,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
Drawable leftIcon = leftTitleButtonController.getLeftIcon(); Drawable leftIcon = leftTitleButtonController.getLeftIcon();
if (leftIcon != null) { if (leftIcon != null) {
leftTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null); leftTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
leftTitleButton.setCompoundDrawablePadding(dpToPx(4f)); leftTitleButton.setCompoundDrawablePadding(dpToPx(8f));
} }
if (leftTitleButtonController.needRightText) { if (leftTitleButtonController.needRightText) {
@ -727,7 +742,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
Drawable leftIcon = rightTitleButtonController.getLeftIcon(); Drawable leftIcon = rightTitleButtonController.getLeftIcon();
rightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null); rightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
rightTitleButton.setCompoundDrawablePadding(dpToPx(4f)); rightTitleButton.setCompoundDrawablePadding(dpToPx(8f));
} else { } else {
rightTitleButton.setVisibility(View.GONE); rightTitleButton.setVisibility(View.GONE);
} }
@ -740,11 +755,26 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
Drawable leftIcon = topRightTitleButtonController.getLeftIcon(); Drawable leftIcon = topRightTitleButtonController.getLeftIcon();
topRightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null); topRightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
topRightTitleButton.setCompoundDrawablePadding(dpToPx(4f)); topRightTitleButton.setCompoundDrawablePadding(dpToPx(8f));
} else { } else {
topRightTitleButton.setVisibility(View.GONE); topRightTitleButton.setVisibility(View.GONE);
} }
// Left subtitle button
final Button leftSubtitleButton = (Button) view.findViewById(R.id.subtitle_button);
if (leftSubtitleButtonController != null) {
leftSubtitleButton.setText(leftSubtitleButtonController.caption);
leftSubtitleButton.setVisibility(leftSubtitleButtonController.visible ? View.VISIBLE : View.GONE);
Drawable leftIcon = leftSubtitleButtonController.getLeftIcon();
if (leftIcon != null) {
leftSubtitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
leftSubtitleButton.setCompoundDrawablePadding(dpToPx(8f));
}
} else {
leftSubtitleButton.setVisibility(View.GONE);
}
// Download buttons // Download buttons
boolean showDownloadButtonsContainer = boolean showDownloadButtonsContainer =
((leftDownloadButtonController != null && leftDownloadButtonController.visible) ((leftDownloadButtonController != null && leftDownloadButtonController.visible)
@ -772,7 +802,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
Drawable leftIcon = leftDownloadButtonController.getLeftIcon(); Drawable leftIcon = leftDownloadButtonController.getLeftIcon();
if (leftIcon != null) { if (leftIcon != null) {
leftDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null); leftDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
leftDownloadButton.setCompoundDrawablePadding(dpToPx(4f)); leftDownloadButton.setCompoundDrawablePadding(dpToPx(8f));
} }
} else { } else {
leftDownloadButton.setVisibility(View.GONE); leftDownloadButton.setVisibility(View.GONE);
@ -786,7 +816,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
Drawable leftIcon = rightDownloadButtonController.getLeftIcon(); Drawable leftIcon = rightDownloadButtonController.getLeftIcon();
rightDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null); rightDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);
rightDownloadButton.setCompoundDrawablePadding(dpToPx(4f)); rightDownloadButton.setCompoundDrawablePadding(dpToPx(8f));
} else { } else {
rightDownloadButton.setVisibility(View.GONE); rightDownloadButton.setVisibility(View.GONE);
} }

View file

@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@ -98,6 +99,7 @@ public abstract class MenuController extends BaseMenuController {
protected TitleButtonController leftTitleButtonController; protected TitleButtonController leftTitleButtonController;
protected TitleButtonController rightTitleButtonController; protected TitleButtonController rightTitleButtonController;
protected TitleButtonController topRightTitleButtonController; protected TitleButtonController topRightTitleButtonController;
protected TitleButtonController leftSubtitleButtonController;
protected TitleButtonController leftDownloadButtonController; protected TitleButtonController leftDownloadButtonController;
protected TitleButtonController rightDownloadButtonController; protected TitleButtonController rightDownloadButtonController;
@ -321,6 +323,10 @@ public abstract class MenuController extends BaseMenuController {
return topRightTitleButtonController; return topRightTitleButtonController;
} }
public TitleButtonController getLeftSubtitleButtonController() {
return leftSubtitleButtonController;
}
public TitleButtonController getLeftDownloadButtonController() { public TitleButtonController getLeftDownloadButtonController() {
return leftDownloadButtonController; return leftDownloadButtonController;
} }
@ -495,10 +501,18 @@ public abstract class MenuController extends BaseMenuController {
public boolean needRightText = false; public boolean needRightText = false;
public String rightTextCaption = ""; public String rightTextCaption = "";
public boolean visible = true; public boolean visible = true;
public boolean needColorizeIcon = true;
public Drawable leftIcon;
public Drawable getLeftIcon() { public Drawable getLeftIcon() {
if (leftIcon != null) {
return leftIcon;
}
if (leftIconId != 0) { if (leftIconId != 0) {
if (needColorizeIcon) {
return getIcon(leftIconId, isLight() ? R.color.map_widget_blue : R.color.osmand_orange); return getIcon(leftIconId, isLight() ? R.color.map_widget_blue : R.color.osmand_orange);
}
return ContextCompat.getDrawable(getMapActivity(), leftIconId);
} else { } else {
return null; return null;
} }

View file

@ -1,8 +1,10 @@
package net.osmand.plus.mapcontextmenu.controllers; package net.osmand.plus.mapcontextmenu.controllers;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -21,6 +23,7 @@ public class MapMarkerMenuController extends MenuController {
this.mapMarker = mapMarker; this.mapMarker = mapMarker;
builder.setShowNearestWiki(true); builder.setShowNearestWiki(true);
final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper(); final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
leftTitleButtonController = new TitleButtonController() { leftTitleButtonController = new TitleButtonController() {
@Override @Override
public void buttonPressed() { public void buttonPressed() {
@ -28,8 +31,27 @@ public class MapMarkerMenuController extends MenuController {
getMapActivity().getContextMenu().close(); getMapActivity().getContextMenu().close();
} }
}; };
leftTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_remove); leftTitleButtonController.needColorizeIcon = false;
leftTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark; leftTitleButtonController.caption = getMapActivity().getString(R.string.mark_passed);
leftTitleButtonController.leftIconId = isLight() ? R.drawable.passed_icon_light : R.drawable.passed_icon_dark;
leftSubtitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
markersHelper.moveMarkerToTop(getMapMarker());
getMapActivity().getContextMenu().close();
}
};
leftSubtitleButtonController.caption = getMapActivity().getString(R.string.show_on_top_bar);
leftSubtitleButtonController.leftIcon = createShowOnTopbarIcon();
}
private Drawable createShowOnTopbarIcon() {
IconsCache ic = getMapActivity().getMyApplication().getIconsCache();
Drawable background = ic.getIcon(R.drawable.ic_action_device_top,
isLight() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark);
Drawable topbar = ic.getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue);
return new LayerDrawable(new Drawable[]{background, topbar});
} }
@Override @Override