Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
a29c548608
7 changed files with 142 additions and 53 deletions
|
@ -111,41 +111,6 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi
|
||||||
public boolean drawInScreenPixels() {
|
public boolean drawInScreenPixels() {
|
||||||
return true;
|
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
|
@Override
|
||||||
public String getObjectDescription(Object o) {
|
public String getObjectDescription(Object o) {
|
||||||
|
|
|
@ -9,7 +9,9 @@ import android.text.util.Linkify;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -82,7 +84,7 @@ public class MenuBuilder {
|
||||||
firstRow = false;
|
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);
|
buildRow(view, getRowIcon(iconId), text, textColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,6 +149,48 @@ public class MenuBuilder {
|
||||||
rowBuilt();
|
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) {
|
public void addPlainMenuItem(int iconId, String text) {
|
||||||
plainMenuItems.add(new PlainMenuItem(iconId, 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) {
|
public int dpToPx(float dp) {
|
||||||
Resources r = app.getResources();
|
Resources r = app.getResources();
|
||||||
return (int) TypedValue.applyDimension(
|
return (int) TypedValue.applyDimension(
|
||||||
|
|
|
@ -20,7 +20,7 @@ import net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController;
|
||||||
import net.osmand.plus.mapcontextmenu.controllers.OsMoMenuController;
|
import net.osmand.plus.mapcontextmenu.controllers.OsMoMenuController;
|
||||||
import net.osmand.plus.mapcontextmenu.controllers.ParkingPositionMenuController;
|
import net.osmand.plus.mapcontextmenu.controllers.ParkingPositionMenuController;
|
||||||
import net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController;
|
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.mapcontextmenu.controllers.TargetPointMenuController;
|
||||||
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
|
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ public abstract class MenuController extends BaseMenuController {
|
||||||
} else if (object instanceof OsMoDevice) {
|
} else if (object instanceof OsMoDevice) {
|
||||||
menuController = new OsMoMenuController(app, mapActivity, (OsMoDevice) object);
|
menuController = new OsMoMenuController(app, mapActivity, (OsMoDevice) object);
|
||||||
} else if (object instanceof Recording) {
|
} else if (object instanceof Recording) {
|
||||||
menuController = new RecordingItemMenuController(app, mapActivity, (Recording) object);
|
menuController = new AudioVideoNoteMenuController(app, mapActivity, (Recording) object);
|
||||||
} else if (object instanceof LatLon) {
|
} else if (object instanceof LatLon) {
|
||||||
if (pointDescription.isParking()) {
|
if (pointDescription.isParking()) {
|
||||||
menuController = new ParkingPositionMenuController(app, mapActivity, pointDescription);
|
menuController = new ParkingPositionMenuController(app, mapActivity, pointDescription);
|
||||||
|
|
|
@ -34,11 +34,11 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
||||||
this.amenity = amenity;
|
this.amenity = amenity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildRow(View view, int iconId, String text, int textColor, boolean isWiki) {
|
private void buildRow(View view, int iconId, String text, int textColor, boolean isWiki, boolean needLinks) {
|
||||||
buildRow(view, getRowIcon(iconId), text, textColor, isWiki);
|
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();
|
boolean light = app.getSettings().isLightContent();
|
||||||
|
|
||||||
LinearLayout ll = new LinearLayout(view.getContext());
|
LinearLayout ll = new LinearLayout(view.getContext());
|
||||||
|
@ -74,8 +74,10 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
||||||
textView.setTextSize(16);
|
textView.setTextSize(16);
|
||||||
textView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_info_text_light : R.color.ctx_menu_info_text_dark));
|
textView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_info_text_light : R.color.ctx_menu_info_text_dark));
|
||||||
|
|
||||||
textView.setAutoLinkMask(Linkify.ALL);
|
if (needLinks) {
|
||||||
textView.setLinksClickable(true);
|
textView.setAutoLinkMask(Linkify.ALL);
|
||||||
|
textView.setLinksClickable(true);
|
||||||
|
}
|
||||||
textView.setEllipsize(TextUtils.TruncateAt.END);
|
textView.setEllipsize(TextUtils.TruncateAt.END);
|
||||||
if (isWiki) {
|
if (isWiki) {
|
||||||
textView.setMinLines(1);
|
textView.setMinLines(1);
|
||||||
|
@ -124,10 +126,12 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
||||||
int iconId;
|
int iconId;
|
||||||
Drawable icon = null;
|
Drawable icon = null;
|
||||||
int textColor = 0;
|
int textColor = 0;
|
||||||
boolean isWiki = false;
|
|
||||||
String key = e.getKey();
|
String key = e.getKey();
|
||||||
String vl = e.getValue();
|
String vl = e.getValue();
|
||||||
|
|
||||||
|
boolean isWiki = false;
|
||||||
|
boolean needLinks = !"population".equals(key);
|
||||||
|
|
||||||
if (amenity.getType().isWiki()) {
|
if (amenity.getType().isWiki()) {
|
||||||
if (!hasWiki) {
|
if (!hasWiki) {
|
||||||
iconId = R.drawable.ic_action_note_dark;
|
iconId = R.drawable.ic_action_note_dark;
|
||||||
|
@ -197,9 +201,9 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (icon != null) {
|
if (icon != null) {
|
||||||
buildRow(view, icon, vl, textColor, isWiki);
|
buildRow(view, icon, vl, textColor, isWiki, needLinks);
|
||||||
} else {
|
} else {
|
||||||
buildRow(view, iconId, vl, textColor, isWiki);
|
buildRow(view, iconId, vl, textColor, isWiki, needLinks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,10 +17,6 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
|
||||||
this.fav = fav;
|
this.fav = fav;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildRow(View view, int iconId, String text, int textColor) {
|
|
||||||
buildRow(view, getRowIcon(iconId), text, textColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean needBuildPlainMenuItems() {
|
protected boolean needBuildPlainMenuItems() {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -10,19 +10,20 @@ import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording;
|
import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording;
|
||||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||||
import net.osmand.plus.mapcontextmenu.MenuController;
|
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||||
|
import net.osmand.plus.mapcontextmenu.builders.AudioVideoNoteMenuBuilder;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class RecordingItemMenuController extends MenuController {
|
public class AudioVideoNoteMenuController extends MenuController {
|
||||||
private Recording recording;
|
private Recording recording;
|
||||||
|
|
||||||
private DateFormat dateFormat;
|
private DateFormat dateFormat;
|
||||||
private AudioVideoNotesPlugin plugin;
|
private AudioVideoNotesPlugin plugin;
|
||||||
|
|
||||||
public RecordingItemMenuController(OsmandApplication app, MapActivity mapActivity, final Recording recording) {
|
public AudioVideoNoteMenuController(OsmandApplication app, MapActivity mapActivity, final Recording recording) {
|
||||||
super(new MenuBuilder(app), mapActivity);
|
super(new AudioVideoNoteMenuBuilder(app, recording), mapActivity);
|
||||||
this.recording = recording;
|
this.recording = recording;
|
||||||
plugin = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class);
|
plugin = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class);
|
||||||
dateFormat = android.text.format.DateFormat.getMediumDateFormat(mapActivity);
|
dateFormat = android.text.format.DateFormat.getMediumDateFormat(mapActivity);
|
Loading…
Reference in a new issue