diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioNotesLayer.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioNotesLayer.java index 6d200d8ef8..7bce66dcc5 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioNotesLayer.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioNotesLayer.java @@ -110,41 +110,6 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi public boolean drawInScreenPixels() { return true; } - - @Override - public void populateObjectContextMenu(Object o, ContextMenuAdapter adapter) { - if (o instanceof Recording) { - final Recording r = (Recording) o; - OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() { - @Override - public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { - if (itemId == R.string.recording_context_menu_delete) { - deleteRecording(r); - } - return true; - } - - - }; - adapter.item(R.string.recording_context_menu_delete).iconColor(R.drawable.ic_action_delete_dark - ).listen(listener).reg(); - } - } - - private void deleteRecording(final Recording r) { - AccessibleAlertBuilder bld = new AccessibleAlertBuilder(activity); - bld.setMessage(R.string.recording_delete_confirm); - bld.setPositiveButton(R.string.shared_string_yes, new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - plugin.deleteRecording(r); - } - }); - bld.setNegativeButton(R.string.shared_string_no, null); - bld.show(); - - } @Override public String getObjectDescription(Object o) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index aa1cc77a0d..11de0249a9 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -9,7 +9,9 @@ import android.text.util.Linkify; import android.util.TypedValue; import android.view.Gravity; import android.view.View; +import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -82,7 +84,7 @@ public class MenuBuilder { firstRow = false; } - private void buildRow(View view, int iconId, String text, int textColor) { + protected void buildRow(View view, int iconId, String text, int textColor) { buildRow(view, getRowIcon(iconId), text, textColor); } @@ -147,6 +149,48 @@ public class MenuBuilder { rowBuilt(); } + protected void buildButtonRow(final View view, Drawable buttonIcon, String text, OnClickListener onClickListener) { + LinearLayout ll = new LinearLayout(view.getContext()); + ll.setOrientation(LinearLayout.HORIZONTAL); + LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + ll.setLayoutParams(llParams); + + // Empty + LinearLayout llIcon = new LinearLayout(view.getContext()); + llIcon.setOrientation(LinearLayout.HORIZONTAL); + llIcon.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(62f), isFirstRow() ? dpToPx(58f) - dpToPx(SHADOW_HEIGHT_BOTTOM_DP) : dpToPx(58f))); + llIcon.setGravity(Gravity.CENTER_VERTICAL); + ll.addView(llIcon); + + + // Button + LinearLayout llButton = new LinearLayout(view.getContext()); + llButton.setOrientation(LinearLayout.VERTICAL); + ll.addView(llButton); + + Button buttonView = new Button(view.getContext()); + buttonView.setBackgroundResource(resolveAttribute(view.getContext(), android.R.attr.selectableItemBackground)); + LinearLayout.LayoutParams llBtnParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + buttonView.setLayoutParams(llBtnParams); + buttonView.setPadding(dpToPx(10f), 0, dpToPx(10f), 0); + buttonView.setGravity(Gravity.START | Gravity.CENTER_VERTICAL); + //buttonView.setTextSize(view.getResources().getDimension(resolveAttribute(view.getContext(), R.dimen.default_desc_text_size))); + buttonView.setTextColor(view.getResources().getColor(resolveAttribute(view.getContext(), R.attr.contextMenuButtonColor))); + buttonView.setText(text); + + if (buttonIcon != null) { + buttonView.setCompoundDrawablesWithIntrinsicBounds(buttonIcon, null, null, null); + buttonView.setCompoundDrawablePadding(dpToPx(8f)); + } + + buttonView.setOnClickListener(onClickListener); + llButton.addView(buttonView); + + ((LinearLayout) view).addView(ll); + + rowBuilt(); + } + public void addPlainMenuItem(int iconId, String text) { plainMenuItems.add(new PlainMenuItem(iconId, text)); } @@ -167,6 +211,12 @@ public class MenuBuilder { } } + public int resolveAttribute(Context ctx, int attribute) { + TypedValue outValue = new TypedValue(); + ctx.getTheme().resolveAttribute(attribute, outValue, true); + return outValue.resourceId; + } + public int dpToPx(float dp) { Resources r = app.getResources(); return (int) TypedValue.applyDimension( diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index f360266bf8..7b027e6f51 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -20,7 +20,7 @@ import net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController; import net.osmand.plus.mapcontextmenu.controllers.OsMoMenuController; import net.osmand.plus.mapcontextmenu.controllers.ParkingPositionMenuController; import net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController; -import net.osmand.plus.mapcontextmenu.controllers.RecordingItemMenuController; +import net.osmand.plus.mapcontextmenu.controllers.AudioVideoNoteMenuController; import net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController; import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice; @@ -93,7 +93,7 @@ public abstract class MenuController extends BaseMenuController { } else if (object instanceof OsMoDevice) { menuController = new OsMoMenuController(app, mapActivity, (OsMoDevice) object); } else if (object instanceof Recording) { - menuController = new RecordingItemMenuController(app, mapActivity, (Recording) object); + menuController = new AudioVideoNoteMenuController(app, mapActivity, (Recording) object); } else if (object instanceof LatLon) { if (pointDescription.isParking()) { menuController = new ParkingPositionMenuController(app, mapActivity, pointDescription); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 0cb53dc06f..712ca451be 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -34,11 +34,11 @@ public class AmenityMenuBuilder extends MenuBuilder { this.amenity = amenity; } - private void buildRow(View view, int iconId, String text, int textColor, boolean isWiki) { - buildRow(view, getRowIcon(iconId), text, textColor, isWiki); + private void buildRow(View view, int iconId, String text, int textColor, boolean isWiki, boolean needLinks) { + buildRow(view, getRowIcon(iconId), text, textColor, isWiki, needLinks); } - protected void buildRow(final View view, Drawable icon, String text, int textColor, final boolean isWiki) { + protected void buildRow(final View view, Drawable icon, String text, int textColor, boolean isWiki, boolean needLinks) { boolean light = app.getSettings().isLightContent(); LinearLayout ll = new LinearLayout(view.getContext()); @@ -74,8 +74,10 @@ public class AmenityMenuBuilder extends MenuBuilder { textView.setTextSize(16); textView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_info_text_light : R.color.ctx_menu_info_text_dark)); - textView.setAutoLinkMask(Linkify.ALL); - textView.setLinksClickable(true); + if (needLinks) { + textView.setAutoLinkMask(Linkify.ALL); + textView.setLinksClickable(true); + } textView.setEllipsize(TextUtils.TruncateAt.END); if (isWiki) { textView.setMinLines(1); @@ -124,10 +126,12 @@ public class AmenityMenuBuilder extends MenuBuilder { int iconId; Drawable icon = null; int textColor = 0; - boolean isWiki = false; String key = e.getKey(); String vl = e.getValue(); + boolean isWiki = false; + boolean needLinks = !"population".equals(key); + if (amenity.getType().isWiki()) { if (!hasWiki) { iconId = R.drawable.ic_action_note_dark; @@ -197,9 +201,9 @@ public class AmenityMenuBuilder extends MenuBuilder { } if (icon != null) { - buildRow(view, icon, vl, textColor, isWiki); + buildRow(view, icon, vl, textColor, isWiki, needLinks); } else { - buildRow(view, iconId, vl, textColor, isWiki); + buildRow(view, iconId, vl, textColor, isWiki, needLinks); } } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AudioVideoNoteMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AudioVideoNoteMenuBuilder.java new file mode 100644 index 0000000000..7637d59440 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AudioVideoNoteMenuBuilder.java @@ -0,0 +1,73 @@ +package net.osmand.plus.mapcontextmenu.builders; + +import android.content.DialogInterface; +import android.view.View; +import android.view.View.OnClickListener; + +import net.osmand.access.AccessibleAlertBuilder; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.audionotes.AudioVideoNotesPlugin; +import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; +import net.osmand.plus.mapcontextmenu.MenuBuilder; +import net.osmand.util.Algorithms; + +import java.io.File; +import java.text.DateFormat; +import java.util.Date; + +public class AudioVideoNoteMenuBuilder extends MenuBuilder { + + private final Recording recording; + + public AudioVideoNoteMenuBuilder(OsmandApplication app, final Recording recording) { + super(app); + this.recording = recording; + } + + @Override + protected boolean needBuildPlainMenuItems() { + return false; + } + + @Override + public void build(View view) { + super.build(view); + + File file = recording.getFile(); + if (file != null) { + DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(view.getContext()); + DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(view.getContext()); + Date date = new Date(recording.getFile().lastModified()); + buildRow(view, R.drawable.ic_action_data, dateFormat.format(date) + " — " + timeFormat.format(date), 0); + } + + buildPlainMenuItems(view); + + buildButtonRow(view, null, view.getResources().getString(R.string.recording_context_menu_delete), new OnClickListener() { + @Override + public void onClick(View v) { + AccessibleAlertBuilder bld = new AccessibleAlertBuilder(v.getContext()); + bld.setMessage(R.string.recording_delete_confirm); + final View fView = v; + bld.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + AudioVideoNotesPlugin plugin = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class); + if (plugin != null) { + plugin.deleteRecording(recording); + if (fView.getContext() instanceof MapActivity) { + ((MapActivity)fView.getContext()).getContextMenu().close(); + } + } + } + }); + bld.setNegativeButton(R.string.shared_string_no, null); + bld.show(); + } + }); + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java index 5dde0ec160..bb48c679e3 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java @@ -17,10 +17,6 @@ public class FavouritePointMenuBuilder extends MenuBuilder { this.fav = fav; } - private void buildRow(View view, int iconId, String text, int textColor) { - buildRow(view, getRowIcon(iconId), text, textColor); - } - @Override protected boolean needBuildPlainMenuItems() { return false; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RecordingItemMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AudioVideoNoteMenuController.java similarity index 88% rename from OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RecordingItemMenuController.java rename to OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AudioVideoNoteMenuController.java index 83789c1cfa..187845ef56 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RecordingItemMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AudioVideoNoteMenuController.java @@ -10,19 +10,20 @@ import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; +import net.osmand.plus.mapcontextmenu.builders.AudioVideoNoteMenuBuilder; import java.io.File; import java.text.DateFormat; import java.util.Date; -public class RecordingItemMenuController extends MenuController { +public class AudioVideoNoteMenuController extends MenuController { private Recording recording; private DateFormat dateFormat; private AudioVideoNotesPlugin plugin; - public RecordingItemMenuController(OsmandApplication app, MapActivity mapActivity, final Recording recording) { - super(new MenuBuilder(app), mapActivity); + public AudioVideoNoteMenuController(OsmandApplication app, MapActivity mapActivity, final Recording recording) { + super(new AudioVideoNoteMenuBuilder(app, recording), mapActivity); this.recording = recording; plugin = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class); dateFormat = android.text.format.DateFormat.getMediumDateFormat(mapActivity);